Eclipse 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-2019 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 
138  delete mySource;
139  }
140 
149  void init(bool dynamic, std::string value) {
150  myTable->setItemText(myTablePosition, 0, myName.c_str());
151  myTable->setItemText(myTablePosition, 1, value.c_str());
152  if (dynamic) {
154  } else {
156  }
157  myTable->setItemJustify(myTablePosition, 2, FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
158  }
159 
161  bool dynamic() const {
162  return myAmDynamic;
163  }
164 
166  const std::string& getName() const {
167  return myName;
168  }
169 
177  void update() {
178  if (!dynamic() || mySource == 0) {
179  return;
180  }
181  T value = mySource->getValue();
182  if (value != myValue) {
183  myValue = value;
184  myTable->setItemText(myTablePosition, 1, toString<T>(myValue).c_str());
185  }
186  }
187 
190  if (mySource == 0) {
191  return 0;
192  }
193  return mySource->copy();
194  }
195 
198  if (mySource == 0) {
199  return 0;
200  }
201  return mySource->makedoubleReturningCopy();
202  }
203 
204 private:
207 
209  std::string myName;
210 
213 
216 
219 
221  FXTable* myTable;
222 };
223 
224 
225 #endif
226 
227 /****************************************************************************/
228 
GUIParameterTableItemInterface
Interface to a single line in a parameter window.
Definition: GUIParameterTableItem.h:57
ToString.h
GUIParameterTableItem::update
void update()
Resets the value if it's dynamic.
Definition: GUIParameterTableItem.h:177
GUIParameterTableItemInterface::dynamic
virtual bool dynamic() const =0
Returns the information whether the value changes over simulation time.
GUIParameterTableItem::getSourceCopy
ValueSource< T > * getSourceCopy() const
Returns a copy of the source if the value is dynamic.
Definition: GUIParameterTableItem.h:189
GUIParam_PopupMenu.h
GUIParameterTableItem::getdoubleSourceCopy
ValueSource< double > * getdoubleSourceCopy() const
Returns a double-typed copy of the source if the value is dynamic.
Definition: GUIParameterTableItem.h:197
GUIParameterTableItem::myTable
FXTable * myTable
The table this entry belongs to.
Definition: GUIParameterTableItem.h:221
ICON_NO
Definition: GUIIcons.h:121
GUIIconSubSys::getIcon
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
Definition: GUIIconSubSys.cpp:602
GUIParameterTableItem::myTablePosition
FXint myTablePosition
The position within the table.
Definition: GUIParameterTableItem.h:212
GUIAppEnum.h
GUIParameterTableItemInterface::getName
virtual const std::string & getName() const =0
Returns the name of the value.
ValueSource::getValue
virtual T getValue() const =0
GUIParameterTableItem::getName
const std::string & getName() const
Returns the name of this value.
Definition: GUIParameterTableItem.h:166
GUIParameterTableItem
Instance of a single line in a parameter window.
Definition: GUIParameterTableItem.h:99
ICON_YES
Definition: GUIIcons.h:120
GUIParameterTableItem::init
void init(bool dynamic, std::string value)
Initialises the line.
Definition: GUIParameterTableItem.h:149
GUIParameterTableItem::myAmDynamic
bool myAmDynamic
Information whether the value may change.
Definition: GUIParameterTableItem.h:206
GUIParameterTableItem::GUIParameterTableItem
GUIParameterTableItem(FXTable *table, unsigned pos, const std::string &name, bool dynamic, T value)
Constructor for non-changing (static) values.
Definition: GUIParameterTableItem.h:129
GUIIconSubSys.h
ValueSource.h
GUIParameterTableItem::myValue
T myValue
A backup of the value to avoid the redrawing when nothing has changed.
Definition: GUIParameterTableItem.h:218
GUIParameterTableItem::myName
std::string myName
The name of this value.
Definition: GUIParameterTableItem.h:209
GUIParameterTableItem::mySource
ValueSource< T > * mySource
The source to gain new values from; this source is==0 if the values are not dynamic.
Definition: GUIParameterTableItem.h:215
config.h
GUIParameterTableItem::~GUIParameterTableItem
~GUIParameterTableItem()
Destructor.
Definition: GUIParameterTableItem.h:137
ValueSource< double >
GUIParameterTableItemInterface::~GUIParameterTableItemInterface
virtual ~GUIParameterTableItemInterface()
Destructor.
Definition: GUIParameterTableItem.h:60
GUIParameterTableItemInterface::getdoubleSourceCopy
virtual ValueSource< double > * getdoubleSourceCopy() const =0
Returns a double-typed copy of the value-source.
GUIParameterTableItemInterface::update
virtual void update()=0
Forces an update of the value.
GUIParameterTableItem::GUIParameterTableItem
GUIParameterTableItem(FXTable *table, unsigned pos, const std::string &name, bool dynamic, ValueSource< T > *src)
Constructor for changing (dynamic) values.
Definition: GUIParameterTableItem.h:111
GUIParameterTableItem::dynamic
bool dynamic() const
Returns the information whether this item may change over time.
Definition: GUIParameterTableItem.h:161