|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A single line in a parameter window 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 #ifndef GUIParameterTableItem_h 00020 #define GUIParameterTableItem_h 00021 00022 00023 // =========================================================================== 00024 // included modules 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 // class definitions 00043 // =========================================================================== 00044 // --------------------------------------------------------------------------- 00045 // GUIParameterTableItemInterface 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 // GUIParameterTableItem 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, GUIIconSubSys::getIcon(ICON_YES)); 00198 } else { 00199 myTable->setItemIcon(myTablePosition, 2, GUIIconSubSys::getIcon(ICON_NO)); 00200 } 00201 myTable->setItemJustify(myTablePosition, 2, FXTableItem::CENTER_X|FXTableItem::CENTER_Y); 00202 } 00203 00204 00205 00210 bool dynamic() const throw() { 00211 return myAmDynamic; 00212 } 00213 00214 00219 const std::string& getName() const throw() { 00220 return myName; 00221 } 00222 00223 00231 void update() throw() { 00232 if (!dynamic()||mySource==0) { 00233 return; 00234 } 00235 T value = mySource->getValue(); 00236 if (value!=myValue) { 00237 myValue = value; 00238 myTable->setItemText(myTablePosition, 1, toString<T>(myValue).c_str()); 00239 } 00240 } 00241 00242 00247 ValueSource<T> *getSourceCopy() const throw() { 00248 if (mySource==0) { 00249 return 0; 00250 } 00251 return mySource->copy(); 00252 } 00253 00254 00259 ValueSource<SUMOReal> *getSUMORealSourceCopy() const throw() { 00260 if (mySource==0) { 00261 return 0; 00262 } 00263 return mySource->makeSUMORealReturningCopy(); 00264 } 00265 00266 00267 private: 00269 bool myAmDynamic; 00270 00272 std::string myName; 00273 00275 FXint myTablePosition; 00276 00278 ValueSource<T> *mySource; 00279 00281 T myValue; 00282 00284 FXTable* myTable; 00285 00286 }; 00287 00288 00289 #endif 00290 00291 /****************************************************************************/ 00292