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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // A single line in a parameter window
17 /****************************************************************************/
18 #ifndef GUIParameterTableItem_h
19 #define GUIParameterTableItem_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <string>
28 #include <fx.h>
30 #include <utils/common/ToString.h>
34 
35 
36 // ===========================================================================
37 // class definitions
38 // ===========================================================================
39 // ---------------------------------------------------------------------------
40 // GUIParameterTableItemInterface
41 // ---------------------------------------------------------------------------
58 public:
61 
62 
65 
67  virtual bool dynamic() const = 0;
68 
70  virtual void update() = 0;
71 
73  virtual ValueSource<double>* getdoubleSourceCopy() const = 0;
74 
76  virtual const std::string& getName() const = 0;
78 };
79 
80 
81 // ---------------------------------------------------------------------------
82 // GUIParameterTableItem
83 // ---------------------------------------------------------------------------
98 template<class T>
100 public:
111  GUIParameterTableItem(FXTable* table, unsigned pos, const std::string& name,
112  bool dynamic, ValueSource<T>* src) :
113  myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(src),
114  myValue(src->getValue()), myTable(table) {
115  init(dynamic, toString<T>(src->getValue()));
116  }
117 
129  GUIParameterTableItem(FXTable* table, unsigned pos, const std::string& name,
130  bool dynamic, T value) :
131  myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(0),
132  myValue(value), myTable(table) {
133  init(dynamic, toString<T>(value));
134  }
135 
147  GUIParameterTableItem(FXTable* table, unsigned pos, const std::string& name,
148  bool dynamic, std::string value) :
149  myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos),
150  mySource(0), myValue(0), myTable(table) {
151  init(dynamic, value);
152  }
153 
156  delete mySource;
157  }
158 
167  void init(bool dynamic, std::string value) {
168  myTable->setItemText(myTablePosition, 0, myName.c_str());
169  myTable->setItemText(myTablePosition, 1, value.c_str());
170  if (dynamic) {
171  myTable->setItemIcon(myTablePosition, 2, GUIIconSubSys::getIcon(ICON_YES));
172  } else {
173  myTable->setItemIcon(myTablePosition, 2, GUIIconSubSys::getIcon(ICON_NO));
174  }
175  myTable->setItemJustify(myTablePosition, 2, FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
176  }
177 
179  bool dynamic() const {
180  return myAmDynamic;
181  }
182 
184  const std::string& getName() const {
185  return myName;
186  }
187 
195  void update() {
196  if (!dynamic() || mySource == 0) {
197  return;
198  }
199  T value = mySource->getValue();
200  if (value != myValue) {
201  myValue = value;
202  myTable->setItemText(myTablePosition, 1, toString<T>(myValue).c_str());
203  }
204  }
205 
208  if (mySource == 0) {
209  return 0;
210  }
211  return mySource->copy();
212  }
213 
216  if (mySource == 0) {
217  return 0;
218  }
219  return mySource->makedoubleReturningCopy();
220  }
221 
222 private:
225 
227  std::string myName;
228 
231 
234 
237 
239  FXTable* myTable;
240 };
241 
242 
243 #endif
244 
245 /****************************************************************************/
246 
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