GUIParameterTableItem.h
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GUIParameterTableItem_h
00020 #define GUIParameterTableItem_h
00021
00022
00023
00024
00025
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031
00032 #include <string>
00033 #include <fx.h>
00034 #include <utils/common/ValueSource.h>
00035 #include <utils/common/ToString.h>
00036 #include <utils/gui/div/GUIParam_PopupMenu.h>
00037 #include <utils/gui/images/GUIIconSubSys.h>
00038 #include <utils/gui/windows/GUIAppEnum.h>
00039
00040
00041
00042
00043
00044
00045
00046
00062 class GUIParameterTableItemInterface {
00063 public:
00065 virtual ~GUIParameterTableItemInterface() throw() {}
00066
00067
00070
00075 virtual bool dynamic() const throw() = 0;
00076
00077
00080 virtual void update() throw() = 0;
00081
00082
00087 virtual ValueSource<SUMOReal> *getSUMORealSourceCopy() const throw() = 0;
00088
00089
00094 virtual const std::string &getName() const throw() = 0;
00096
00097 };
00098
00099
00100
00101
00102
00117 template<class T>
00118 class GUIParameterTableItem : public GUIParameterTableItemInterface {
00119 public:
00130 GUIParameterTableItem(FXTable *table, unsigned pos,
00131 const std::string &name, bool dynamic,
00132 ValueSource<T> *src) throw()
00133 : myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(src),
00134 myValue(src->getValue()), myTable(table) {
00135 init(dynamic, toString<T>(src->getValue()));
00136 }
00137
00138
00150 GUIParameterTableItem(FXTable *table, unsigned pos,
00151 const std::string &name, bool dynamic,
00152 T value) throw()
00153 : myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(0),
00154 myValue(value), myTable(table) {
00155 init(dynamic, toString<T>(value));
00156 }
00157
00158
00170 GUIParameterTableItem(FXTable *table, unsigned pos,
00171 const std::string &name, bool dynamic,
00172 std::string value) throw()
00173 : myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(0),
00174 myValue(0), myTable(table) {
00175 init(dynamic, value);
00176 }
00177
00178
00180 ~GUIParameterTableItem() throw() {
00181 delete mySource;
00182 }
00183
00184
00193 void init(bool dynamic, std::string value) throw() {
00194 myTable->setItemText(myTablePosition, 0, myName.c_str());
00195 myTable->setItemText(myTablePosition, 1, value.c_str());
00196 if (dynamic) {
00197 myTable->setItemIcon(myTablePosition, 2,
00198 GUIIconSubSys::getIcon(ICON_YES));
00199 } else {
00200 myTable->setItemIcon(myTablePosition, 2,
00201 GUIIconSubSys::getIcon(ICON_NO));
00202 }
00203 myTable->setItemJustify(myTablePosition, 2,
00204 FXTableItem::CENTER_X|FXTableItem::CENTER_Y);
00205 }
00206
00207
00208
00213 bool dynamic() const throw() {
00214 return myAmDynamic;
00215 }
00216
00217
00222 const std::string &getName() const throw() {
00223 return myName;
00224 }
00225
00226
00234 void update() throw() {
00235 if (!dynamic()||mySource==0) {
00236 return;
00237 }
00238 T value = mySource->getValue();
00239 if (value!=myValue) {
00240 myValue = value;
00241 myTable->setItemText(myTablePosition, 1, toString<T>(myValue).c_str());
00242 }
00243 }
00244
00245
00250 ValueSource<T> *getSourceCopy() const throw() {
00251 if (mySource==0) {
00252 return 0;
00253 }
00254 return mySource->copy();
00255 }
00256
00257
00262 ValueSource<SUMOReal> *getSUMORealSourceCopy() const throw() {
00263 if (mySource==0) {
00264 return 0;
00265 }
00266 return mySource->makeSUMORealReturningCopy();
00267 }
00268
00269
00270 private:
00272 bool myAmDynamic;
00273
00275 std::string myName;
00276
00278 FXint myTablePosition;
00279
00281 ValueSource<T> *mySource;
00282
00284 T myValue;
00285
00287 FXTable *myTable;
00288
00289 };
00290
00291
00292 #endif
00293
00294
00295