SUMO - Simulation of Urban MObility
GUIParameterTableItem.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // A single line in a parameter window
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 #ifndef GUIParameterTableItem_h
22 #define GUIParameterTableItem_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <fx.h>
37 #include <utils/common/ToString.h>
41 
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
46 // ---------------------------------------------------------------------------
47 // GUIParameterTableItemInterface
48 // ---------------------------------------------------------------------------
65 public:
68 
69 
72 
77  virtual bool dynamic() const = 0;
78 
79 
82  virtual void update() = 0;
83 
84 
89  virtual ValueSource<SUMOReal>* getSUMORealSourceCopy() const = 0;
90 
91 
96  virtual const std::string& getName() const = 0;
98 
99 };
100 
101 
102 // ---------------------------------------------------------------------------
103 // GUIParameterTableItem
104 // ---------------------------------------------------------------------------
119 template<class T>
121 public:
132  GUIParameterTableItem(FXTable* table, unsigned pos,
133  const std::string& name, bool dynamic,
134  ValueSource<T>* src)
135  : myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(src),
136  myValue(src->getValue()), myTable(table) {
137  init(dynamic, toString<T>(src->getValue()));
138  }
139 
140 
152  GUIParameterTableItem(FXTable* table, unsigned pos,
153  const std::string& name, bool dynamic,
154  T value)
155  : myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(0),
156  myValue(value), myTable(table) {
157  init(dynamic, toString<T>(value));
158  }
159 
160 
172  GUIParameterTableItem(FXTable* table, unsigned pos,
173  const std::string& name, bool dynamic,
174  std::string value)
175  : myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(0),
176  myValue(0), myTable(table) {
177  init(dynamic, value);
178  }
179 
180 
183  delete mySource;
184  }
185 
186 
195  void init(bool dynamic, std::string value) {
196  myTable->setItemText(myTablePosition, 0, myName.c_str());
197  myTable->setItemText(myTablePosition, 1, value.c_str());
198  if (dynamic) {
199  myTable->setItemIcon(myTablePosition, 2, GUIIconSubSys::getIcon(ICON_YES));
200  } else {
201  myTable->setItemIcon(myTablePosition, 2, GUIIconSubSys::getIcon(ICON_NO));
202  }
203  myTable->setItemJustify(myTablePosition, 2, FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
204  }
205 
206 
207 
212  bool dynamic() const {
213  return myAmDynamic;
214  }
215 
216 
221  const std::string& getName() const {
222  return myName;
223  }
224 
225 
233  void update() {
234  if (!dynamic() || mySource == 0) {
235  return;
236  }
237  T value = mySource->getValue();
238  if (value != myValue) {
239  myValue = value;
240  myTable->setItemText(myTablePosition, 1, toString<T>(myValue).c_str());
241  }
242  }
243 
244 
250  if (mySource == 0) {
251  return 0;
252  }
253  return mySource->copy();
254  }
255 
256 
262  if (mySource == 0) {
263  return 0;
264  }
265  return mySource->makeSUMORealReturningCopy();
266  }
267 
268 
269 private:
272 
274  std::string myName;
275 
278 
281 
284 
286  FXTable* myTable;
287 
288 };
289 
290 
291 #endif
292 
293 /****************************************************************************/
294 
const std::string & getName() const
Returns the name of this value.
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.
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.
virtual ValueSource< SUMOReal > * getSUMORealSourceCopy() const =0
Returns a SUMOReal-typed copy of the value-source.
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< SUMOReal > * getSUMORealSourceCopy() const
Returns a SUMOReal-typed copy of the source if the value is dynamic.
ValueSource< T > * mySource
The source to gain new values from; this source is==0 if the values are not dynamic.
~GUIParameterTableItem()
Destructor.
virtual bool dynamic() const =0
Returns the information whether the value changes over simulation time.
bool dynamic() const
Returns the information whether this item may change.
virtual ValueSource< SUMOReal > * makeSUMORealReturningCopy() const =0
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
ValueSource< T > * getSourceCopy() const
Returns a copy of the source if the value is dynamic.