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 /****************************************************************************/
15 // A single line in a parameter window
16 /****************************************************************************/
17 #ifndef GUIParameterTableItem_h
18 #define GUIParameterTableItem_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
27 #include <fx.h>
29 #include <utils/common/ToString.h>
33 
34 
35 // ===========================================================================
36 // class definitions
37 // ===========================================================================
38 // ---------------------------------------------------------------------------
39 // GUIParameterTableItemInterface
40 // ---------------------------------------------------------------------------
57 public:
60 
61 
64 
66  virtual bool dynamic() const = 0;
67 
69  virtual void update() = 0;
70 
73 
75  virtual const std::string& getName() const = 0;
77 };
78 
79 
80 // ---------------------------------------------------------------------------
81 // GUIParameterTableItem
82 // ---------------------------------------------------------------------------
97 template<class T>
99 public:
110  GUIParameterTableItem(FXTable* table, unsigned pos, const std::string& name,
111  bool dynamic, ValueSource<T>* src) :
112  myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(src),
113  myValue(src->getValue()), myTable(table) {
114  init(dynamic, toString<T>(src->getValue()));
115  }
116 
128  GUIParameterTableItem(FXTable* table, unsigned pos, const std::string& name,
129  bool dynamic, T value) :
130  myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(0),
131  myValue(value), myTable(table) {
132  init(dynamic, toString<T>(value));
133  }
134 
137  delete mySource;
138  }
139 
148  void init(bool dynamic, std::string value) {
149  myTable->setItemText(myTablePosition, 0, myName.c_str());
150  myTable->setItemText(myTablePosition, 1, value.c_str());
151  if (dynamic) {
153  } else {
155  }
156  myTable->setItemJustify(myTablePosition, 2, FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
157  }
158 
160  bool dynamic() const {
161  return myAmDynamic;
162  }
163 
165  const std::string& getName() const {
166  return myName;
167  }
168 
176  void update() {
177  if (!dynamic() || mySource == 0) {
178  return;
179  }
180  T value = mySource->getValue();
181  if (value != myValue) {
182  myValue = value;
183  myTable->setItemText(myTablePosition, 1, toString<T>(myValue).c_str());
184  }
185  }
186 
189  if (mySource == 0) {
190  return 0;
191  }
192  return mySource->copy();
193  }
194 
197  if (mySource == 0) {
198  return 0;
199  }
200  return mySource->makedoubleReturningCopy();
201  }
202 
203 private:
206 
208  std::string myName;
209 
212 
215 
218 
220  FXTable* myTable;
221 };
222 
223 
224 #endif
225 
226 /****************************************************************************/
227 
GUIParameterTableItemInterface
Interface to a single line in a parameter window.
Definition: GUIParameterTableItem.h:56
ToString.h
GUIParameterTableItem::update
void update()
Resets the value if it's dynamic.
Definition: GUIParameterTableItem.h:176
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:188
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:196
GUIParameterTableItem::myTable
FXTable * myTable
The table this entry belongs to.
Definition: GUIParameterTableItem.h:220
ICON_NO
@ ICON_NO
Definition: GUIIcons.h:120
GUIIconSubSys::getIcon
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
Definition: GUIIconSubSys.cpp:609
GUIParameterTableItem::myTablePosition
FXint myTablePosition
The position within the table.
Definition: GUIParameterTableItem.h:211
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:165
GUIParameterTableItem
Instance of a single line in a parameter window.
Definition: GUIParameterTableItem.h:98
ICON_YES
@ ICON_YES
Definition: GUIIcons.h:119
GUIParameterTableItem::init
void init(bool dynamic, std::string value)
Initialises the line.
Definition: GUIParameterTableItem.h:148
GUIParameterTableItem::myAmDynamic
bool myAmDynamic
Information whether the value may change.
Definition: GUIParameterTableItem.h:205
GUIParameterTableItem::GUIParameterTableItem
GUIParameterTableItem(FXTable *table, unsigned pos, const std::string &name, bool dynamic, T value)
Constructor for non-changing (static) values.
Definition: GUIParameterTableItem.h:128
GUIIconSubSys.h
ValueSource.h
GUIParameterTableItem::myValue
T myValue
A backup of the value to avoid the redrawing when nothing has changed.
Definition: GUIParameterTableItem.h:217
GUIParameterTableItem::myName
std::string myName
The name of this value.
Definition: GUIParameterTableItem.h:208
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:214
config.h
GUIParameterTableItem::~GUIParameterTableItem
~GUIParameterTableItem()
Destructor.
Definition: GUIParameterTableItem.h:136
ValueSource< double >
GUIParameterTableItemInterface::~GUIParameterTableItemInterface
virtual ~GUIParameterTableItemInterface()
Destructor.
Definition: GUIParameterTableItem.h:59
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:110
GUIParameterTableItem::dynamic
bool dynamic() const
Returns the information whether this item may change over time.
Definition: GUIParameterTableItem.h:160