Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUIParameterTableItem.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
19// A single line in a parameter window
20/****************************************************************************/
21#pragma once
22#include <config.h>
23
24#include <string>
31
32
33// ===========================================================================
34// class definitions
35// ===========================================================================
36// ---------------------------------------------------------------------------
37// GUIParameterTableItemInterface
38// ---------------------------------------------------------------------------
55public:
58
59
62
64 virtual bool dynamic() const = 0;
65
67 virtual void update() = 0;
68
71
73 virtual const std::string& getName() const = 0;
75};
76
77
78// ---------------------------------------------------------------------------
79// GUIParameterTableItem
80// ---------------------------------------------------------------------------
95template<class T>
97public:
108 GUIParameterTableItem(FXTable* table, unsigned pos, const std::string& name,
109 bool dynamic, ValueSource<T>* src) :
110 myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(src),
111 myValue(src->getValue()), myTable(table) {
112 init(dynamic, toString<T>(src->getValue()));
113 }
114
126 GUIParameterTableItem(FXTable* table, unsigned pos, const std::string& name,
127 bool dynamic, T value) :
128 myAmDynamic(dynamic), myName(name), myTablePosition((FXint) pos), mySource(0),
129 myValue(value), myTable(table) {
130 init(dynamic, toString<T>(value));
131 }
132
135 delete mySource;
136 }
137
146 void init(bool dynamic, std::string value) {
147 myTable->setItemText(myTablePosition, 0, myName.c_str());
148 myTable->setItemText(myTablePosition, 1, value.c_str());
149 if (dynamic) {
150 if (getdoubleSourceCopy() == nullptr) {
152 } else {
154 }
155 } else {
157 }
158 const int lineBreaks = (int)std::count(value.begin(), value.end(), '\n');
159 if (lineBreaks > 0) {
160 myTable->setRowHeight(myTablePosition, myTable->getRowHeight(myTablePosition) * (lineBreaks + 1));
161 }
162 myTable->setItemJustify(myTablePosition, 2, FXTableItem::CENTER_X | FXTableItem::CENTER_Y);
163 }
164
166 bool dynamic() const {
167 return myAmDynamic;
168 }
169
171 const std::string& getName() const {
172 return myName;
173 }
174
182 void update() {
183 if (!dynamic() || mySource == 0) {
184 return;
185 }
186 T value = mySource->getValue();
187 if (value != myValue) {
188 myValue = value;
189 myTable->setItemText(myTablePosition, 1, toString<T>(myValue).c_str());
190 }
191 }
192
195 if (mySource == 0) {
196 return 0;
197 }
198 return mySource->copy();
199 }
200
203 if (mySource == 0) {
204 return 0;
205 }
207 }
208
209private:
212
214 std::string myName;
215
218
221
224
226 FXTable* myTable;
227};
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
Instance of a single line in a parameter window.
std::string myName
The name of this value.
void init(bool dynamic, std::string value)
Initialises the line.
const std::string & getName() const
Returns the name of this value.
FXint myTablePosition
The position within the table.
GUIParameterTableItem(FXTable *table, unsigned pos, const std::string &name, bool dynamic, ValueSource< T > *src)
Constructor for changing (dynamic) values.
ValueSource< T > * getSourceCopy() const
Returns a copy of the source if the value is dynamic.
ValueSource< double > * getdoubleSourceCopy() const
Returns a double-typed copy of the source if the value is dynamic.
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.
void update()
Resets the value if it's dynamic.
ValueSource< T > * mySource
The source to gain new values from; this source is==0 if the values are not dynamic.
FXTable * myTable
The table this entry belongs to.
T myValue
A backup of the value to avoid the redrawing when nothing has changed.
bool dynamic() const
Returns the information whether this item may change over time.
Interface to a single line in a parameter window.
virtual const std::string & getName() const =0
Returns the name of the value.
virtual ~GUIParameterTableItemInterface()
Destructor.
virtual void update()=0
Forces an update of the value.
virtual ValueSource< double > * getdoubleSourceCopy() const =0
Returns a double-typed copy of the value-source.
virtual bool dynamic() const =0
Returns the information whether the value changes over simulation time.
virtual ValueSource< double > * makedoubleReturningCopy() const =0
virtual T getValue() const =0