SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00008 // A single line in a parameter window 00009 /****************************************************************************/ 00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00012 /****************************************************************************/ 00013 // 00014 // This file is part of SUMO. 00015 // SUMO is free software: you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation, either version 3 of the License, or 00018 // (at your option) any later version. 00019 // 00020 /****************************************************************************/ 00021 #ifndef GUIParameterTableItem_h 00022 #define GUIParameterTableItem_h 00023 00024 00025 // =========================================================================== 00026 // included modules 00027 // =========================================================================== 00028 #ifdef _MSC_VER 00029 #include <windows_config.h> 00030 #else 00031 #include <config.h> 00032 #endif 00033 00034 #include <string> 00035 #include <fx.h> 00036 #include <utils/common/ValueSource.h> 00037 #include <utils/common/ToString.h> 00038 #include <utils/gui/div/GUIParam_PopupMenu.h> 00039 #include <utils/gui/images/GUIIconSubSys.h> 00040 #include <utils/gui/windows/GUIAppEnum.h> 00041 00042 00043 // =========================================================================== 00044 // class definitions 00045 // =========================================================================== 00046 // --------------------------------------------------------------------------- 00047 // GUIParameterTableItemInterface 00048 // --------------------------------------------------------------------------- 00064 class GUIParameterTableItemInterface { 00065 public: 00067 virtual ~GUIParameterTableItemInterface() {} 00068 00069 00072 00077 virtual bool dynamic() const = 0; 00078 00079 00082 virtual void update() = 0; 00083 00084 00089 virtual ValueSource<SUMOReal> *getSUMORealSourceCopy() const = 0; 00090 00091 00096 virtual const std::string& getName() const = 0; 00098 00099 }; 00100 00101 00102 // --------------------------------------------------------------------------- 00103 // GUIParameterTableItem 00104 // --------------------------------------------------------------------------- 00119 template<class T> 00120 class GUIParameterTableItem : public GUIParameterTableItemInterface { 00121 public: 00132 GUIParameterTableItem(FXTable* table, unsigned pos, 00133 const std::string& name, bool dynamic, 00134 ValueSource<T> *src) 00135 : myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(src), 00136 myValue(src->getValue()), myTable(table) { 00137 init(dynamic, toString<T>(src->getValue())); 00138 } 00139 00140 00152 GUIParameterTableItem(FXTable* table, unsigned pos, 00153 const std::string& name, bool dynamic, 00154 T value) 00155 : myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(0), 00156 myValue(value), myTable(table) { 00157 init(dynamic, toString<T>(value)); 00158 } 00159 00160 00172 GUIParameterTableItem(FXTable* table, unsigned pos, 00173 const std::string& name, bool dynamic, 00174 std::string value) 00175 : myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(0), 00176 myValue(0), myTable(table) { 00177 init(dynamic, value); 00178 } 00179 00180 00182 ~GUIParameterTableItem() { 00183 delete mySource; 00184 } 00185 00186 00195 void init(bool dynamic, std::string value) { 00196 myTable->setItemText(myTablePosition, 0, myName.c_str()); 00197 myTable->setItemText(myTablePosition, 1, value.c_str()); 00198 if (dynamic) { 00199 myTable->setItemIcon(myTablePosition, 2, GUIIconSubSys::getIcon(ICON_YES)); 00200 } else { 00201 myTable->setItemIcon(myTablePosition, 2, GUIIconSubSys::getIcon(ICON_NO)); 00202 } 00203 myTable->setItemJustify(myTablePosition, 2, FXTableItem::CENTER_X | FXTableItem::CENTER_Y); 00204 } 00205 00206 00207 00212 bool dynamic() const { 00213 return myAmDynamic; 00214 } 00215 00216 00221 const std::string& getName() const { 00222 return myName; 00223 } 00224 00225 00233 void update() { 00234 if (!dynamic() || mySource == 0) { 00235 return; 00236 } 00237 T value = mySource->getValue(); 00238 if (value != myValue) { 00239 myValue = value; 00240 myTable->setItemText(myTablePosition, 1, toString<T>(myValue).c_str()); 00241 } 00242 } 00243 00244 00249 ValueSource<T> *getSourceCopy() const { 00250 if (mySource == 0) { 00251 return 0; 00252 } 00253 return mySource->copy(); 00254 } 00255 00256 00261 ValueSource<SUMOReal> *getSUMORealSourceCopy() const { 00262 if (mySource == 0) { 00263 return 0; 00264 } 00265 return mySource->makeSUMORealReturningCopy(); 00266 } 00267 00268 00269 private: 00271 bool myAmDynamic; 00272 00274 std::string myName; 00275 00277 FXint myTablePosition; 00278 00280 ValueSource<T> *mySource; 00281 00283 T myValue; 00284 00286 FXTable* myTable; 00287 00288 }; 00289 00290 00291 #endif 00292 00293 /****************************************************************************/ 00294