SUMO - Simulation of Urban MObility
GUIParameterTableItem.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // A single line in a parameter window
19 /****************************************************************************/
20 #ifndef GUIParameterTableItem_h
21 #define GUIParameterTableItem_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <fx.h>
36 #include <utils/common/ToString.h>
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
45 // ---------------------------------------------------------------------------
46 // GUIParameterTableItemInterface
47 // ---------------------------------------------------------------------------
64 public:
67 
68 
71 
73  virtual bool dynamic() const = 0;
74 
76  virtual void update() = 0;
77 
79  virtual ValueSource<double>* getdoubleSourceCopy() const = 0;
80 
82  virtual const std::string& getName() const = 0;
84 };
85 
86 
87 // ---------------------------------------------------------------------------
88 // GUIParameterTableItem
89 // ---------------------------------------------------------------------------
104 template<class T>
106 public:
117  GUIParameterTableItem(FXTable* table, unsigned pos, const std::string& name,
118  bool dynamic, ValueSource<T>* src) :
119  myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(src),
120  myValue(src->getValue()), myTable(table) {
121  init(dynamic, toString<T>(src->getValue()));
122  }
123 
135  GUIParameterTableItem(FXTable* table, unsigned pos, const std::string& name,
136  bool dynamic, T value) :
137  myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(0),
138  myValue(value), myTable(table) {
139  init(dynamic, toString<T>(value));
140  }
141 
153  GUIParameterTableItem(FXTable* table, unsigned pos, const std::string& name,
154  bool dynamic, std::string value) :
155  myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos),
156  mySource(0), myValue(0), myTable(table) {
157  init(dynamic, value);
158  }
159 
162  delete mySource;
163  }
164 
173  void init(bool dynamic, std::string value) {
174  myTable->setItemText(myTablePosition, 0, myName.c_str());
175  myTable->setItemText(myTablePosition, 1, value.c_str());
176  if (dynamic) {
177  myTable->setItemIcon(myTablePosition, 2, GUIIconSubSys::getIcon(ICON_YES));
178  } else {
179  myTable->setItemIcon(myTablePosition, 2, GUIIconSubSys::getIcon(ICON_NO));
180  }
181  myTable->setItemJustify(myTablePosition, 2, FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
182  }
183 
185  bool dynamic() const {
186  return myAmDynamic;
187  }
188 
190  const std::string& getName() const {
191  return myName;
192  }
193 
201  void update() {
202  if (!dynamic() || mySource == 0) {
203  return;
204  }
205  T value = mySource->getValue();
206  if (value != myValue) {
207  myValue = value;
208  myTable->setItemText(myTablePosition, 1, toString<T>(myValue).c_str());
209  }
210  }
211 
214  if (mySource == 0) {
215  return 0;
216  }
217  return mySource->copy();
218  }
219 
222  if (mySource == 0) {
223  return 0;
224  }
225  return mySource->makedoubleReturningCopy();
226  }
227 
228 private:
231 
233  std::string myName;
234 
237 
240 
243 
245  FXTable* myTable;
246 };
247 
248 
249 #endif
250 
251 /****************************************************************************/
252 
GUIParameterTableItem(FXTable *table, unsigned pos, const std::string &name, bool dynamic, std::string value)
Constructor for string-typed, non-changing (static) values.
void init(bool dynamic, std::string value)
Initialises the line.
virtual void update()=0
Forces an update of the value.
T myValue
A backup of the value to avoid the redrawing when nothing has changed.
FXTable * myTable
The table this entry belongs to.
void update()
Resets the value if it&#39;s dynamic.
virtual const std::string & getName() const =0
Returns the name of the value.
ValueSource< T > * getSourceCopy() const
Returns a copy of the source if the value is dynamic.
GUIParameterTableItem(FXTable *table, unsigned pos, const std::string &name, bool dynamic, ValueSource< T > *src)
Constructor for changing (dynamic) values.
FXint myTablePosition
The position within the table.
bool myAmDynamic
Information whether the value may change.
GUIParameterTableItem(FXTable *table, unsigned pos, const std::string &name, bool dynamic, T value)
Constructor for non-changing (static) values.
Interface to a single line in a parameter window.
ValueSource< double > * getdoubleSourceCopy() const
Returns a double-typed copy of the source if the value is dynamic.
bool dynamic() const
Returns the information whether this item may change over time.
virtual ValueSource< double > * makedoubleReturningCopy() const =0
ValueSource< T > * mySource
The source to gain new values from; this source is==0 if the values are not dynamic.
const std::string & getName() const
Returns the name of this value.
~GUIParameterTableItem()
Destructor.
virtual bool dynamic() const =0
Returns the information whether the value changes over simulation time.
virtual ValueSource< double > * getdoubleSourceCopy() const =0
Returns a double-typed copy of the value-source.
Instance of a single line in a parameter window.
std::string myName
The name of this value.
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
virtual ~GUIParameterTableItemInterface()
Destructor.
virtual T getValue() const =0