Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GUIParameterTableWindow.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2002-2025 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/****************************************************************************/
22// The window that holds the table of an object's parameter
23/****************************************************************************/
24#include <config.h>
25
26#include <string>
40
41
42// ===========================================================================
43// FOX callback mapping
44// ===========================================================================
45FXDEFMAP(GUIParameterTableWindow) GUIParameterTableWindowMap[] = {
46 FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUIParameterTableWindow::onSimStep),
48 FXMAPFUNC(SEL_DESELECTED, MID_TABLE, GUIParameterTableWindow::onTableDeselected),
49 FXMAPFUNC(SEL_RIGHTBUTTONPRESS, MID_TABLE, GUIParameterTableWindow::onRightButtonPress),
50 FXMAPFUNC(SEL_LEFTBUTTONPRESS, MID_TABLE, GUIParameterTableWindow::onLeftBtnPress),
51};
52
53FXIMPLEMENT(GUIParameterTableWindow, FXMainWindow, GUIParameterTableWindowMap, ARRAYNUMBER(GUIParameterTableWindowMap))
54
55// ===========================================================================
56// static value definitions
57// ===========================================================================
58
60std::vector<GUIParameterTableWindow*> GUIParameterTableWindow::myContainer;
61
62// ===========================================================================
63// method definitions
64// ===========================================================================
65#ifdef _MSC_VER
66#pragma warning(push)
67#pragma warning(disable: 4355) // mask warning about "this" in initializers
68#endif
70 FXMainWindow(app.getApp(), ((title == "" ? o.getFullName() : title) + " parameter").c_str(), nullptr, nullptr, DECOR_ALL, 20, 40, 200, 500),
71 GUIPersistentWindowPos(this, "DIALOG_PARAMETERS", false, 20, 40),
72 myObject(&o),
73 myApplication(&app),
74 myTrackerY(50),
75 myCurrentPos(0) {
76 myTable = new FXTable(this, this, MID_TABLE, TABLE_COL_SIZABLE | TABLE_ROW_SIZABLE | LAYOUT_FILL_X | LAYOUT_FILL_Y);
77 myTable->setTableSize(1, 3);
78 myTable->setVisibleColumns(3);
79 myTable->setBackColor(FXRGB(255, 255, 255));
80 myTable->setColumnText(0, TL("Name"));
81 myTable->setColumnText(1, TL("Value"));
82 myTable->setColumnText(2, TL("Dynamic"));
83 myTable->getRowHeader()->setWidth(0);
84 FXHeader* header = myTable->getColumnHeader();
85 header->setItemJustify(0, JUSTIFY_CENTER_X);
86 header->setItemSize(0, 240);
87 header->setItemJustify(1, JUSTIFY_CENTER_X);
88 header->setItemSize(1, 120);
89 header->setItemJustify(2, JUSTIFY_CENTER_X);
90 header->setItemSize(2, 60);
92 myLock.lock();
94 myLock.unlock();
95 FXMutexLock locker(myGlobalContainerLock);
96 myContainer.push_back(this);
97 // Table cannot be editable
98 myTable->setEditable(FALSE);
100}
101#ifdef _MSC_VER
102#pragma warning(pop)
103#endif
104
107 myLock.lock();
108 for (std::vector<GUIParameterTableItemInterface*>::iterator i = myItems.begin(); i != myItems.end(); ++i) {
109 delete (*i);
110 }
111 if (myObject != nullptr) {
113 }
114 myLock.unlock();
115 FXMutexLock locker(myGlobalContainerLock);
116 std::vector<GUIParameterTableWindow*>::iterator i = std::find(myContainer.begin(), myContainer.end(), this);
117 if (i != myContainer.end()) {
118 myContainer.erase(i);
119 }
120}
121
122
123void
125 FXMutexLock locker(myLock);
126 myObject = nullptr;
127}
128
129
130long
131GUIParameterTableWindow::onSimStep(FXObject*, FXSelector, void*) {
132 // table values are updated in GUINet::guiSimulationStep()
133 updateTable();
134 update();
135 return 1;
136}
137
138
139long
140GUIParameterTableWindow::onTableSelected(FXObject*, FXSelector, void*) {
141 return 1;
142}
143
144
145long
146GUIParameterTableWindow::onTableDeselected(FXObject*, FXSelector, void*) {
147 return 1;
148}
149
150long
151GUIParameterTableWindow::onLeftBtnPress(FXObject* sender, FXSelector sel, void* eventData) {
152 FXEvent* e = (FXEvent*) eventData;
153 int row = myTable->rowAtY(e->win_y);
154 int col = myTable->colAtX(e->win_x);
155 if (col == 2 && row >= 0 && row < (int)myItems.size()) {
157 if (i->dynamic() && i->getdoubleSourceCopy() != nullptr) {
158 // open tracker directly
159 const std::string trackerName = i->getName() + " of " + myObject->getFullName();
163 tr->addTracked(*myObject, i->getdoubleSourceCopy(), newTracked);
164 tr->setX(getX() + getWidth() + 10);
165 tr->setY(myTrackerY);
166 tr->create();
167 tr->show();
168 myTrackerY = (myTrackerY + tr->getHeight() + 20) % getApp()->getRootWindow()->getHeight();
169 }
170 }
171 }
172 return FXMainWindow::onLeftBtnPress(sender, sel, eventData);
173}
174
175long
176GUIParameterTableWindow::onRightButtonPress(FXObject* /*sender*/, FXSelector /*sel*/, void* eventData) {
177 // check which value entry was pressed
178 FXEvent* e = (FXEvent*) eventData;
179 int row = myTable->rowAtY(e->win_y);
180 if (row == -1 || row >= (int)(myItems.size())) {
181 return 1;
182 }
184 if (!i->dynamic()) {
185 return 1;
186 }
187 if (myObject == nullptr) {
188 return 1;
189 }
190
191 ValueSource<double>* doubleSource = i->getdoubleSourceCopy();
192 if (doubleSource != nullptr) {
194 GUIDesigns::buildFXMenuCommand(p, TL("Open in new Tracker"), nullptr, p, MID_OPENTRACKER);
195 // set geometry
196 p->setX(static_cast<FXEvent*>(eventData)->root_x);
197 p->setY(static_cast<FXEvent*>(eventData)->root_y);
198 p->create();
199 // show
200 p->show();
201 }
202 return 1;
203}
204
205
206void
207GUIParameterTableWindow::mkItem(const char* name, bool dynamic, std::string value) {
208 myTable->insertRows((int)myItems.size() + 1);
210 myItems.push_back(i);
211}
212
213
214void
215GUIParameterTableWindow::mkItem(const char* name, bool dynamic, double value) {
216 myTable->insertRows((int)myItems.size() + 1);
218 myItems.push_back(i);
219}
220
221
222void
223GUIParameterTableWindow::mkItem(const char* name, bool dynamic, unsigned value) {
224 myTable->insertRows((int)myItems.size() + 1);
226 myItems.push_back(i);
227}
228
229
230void
231GUIParameterTableWindow::mkItem(const char* name, bool dynamic, int value) {
232 myTable->insertRows((int)myItems.size() + 1);
234 myItems.push_back(i);
235}
236
237
238void
239GUIParameterTableWindow::mkItem(const char* name, bool dynamic, long long int value) {
240 myTable->insertRows((int)myItems.size() + 1);
242 myItems.push_back(i);
243}
244
245
246void
248 FXMutexLock locker(myLock);
249 if (myObject == nullptr) {
250 return;
251 }
252 for (GUIParameterTableItemInterface* const item : myItems) {
253 item->update();
254 }
255}
256
257
258void
260 // add generic parameters if available
261 if (p == nullptr) {
262 p = dynamic_cast<const Parameterised*>(myObject);
263 }
264 if (p != nullptr) {
265 const Parameterised::Map& map = p->getParametersMap();
266 for (Parameterised::Map::const_iterator it = map.begin(); it != map.end(); ++it) {
267 mkItem(("param:" + it->first).c_str(), false, it->second);
268 }
269 }
270 const int rows = (int)myItems.size() + 1;
271 int h = rows * 20 + 40;
272 // adjust size in case there are higher (multi-line) rows
273 for (int i = 0; i < (int)myItems.size(); i++) {
274 h += MAX2(0, myTable->getRowHeight(i) - 20);
275 }
276 setHeight(h);
277 myTable->fitColumnsToContents(1);
278 setWidth(myTable->getContentWidth() + 40);
279 myTable->setVisibleRows(rows);
280 myApplication->addChild(this);
281 create();
282 show();
283}
284
285
286void
287GUIParameterTableWindow::checkFont(const std::string& text) {
288 bool missingChar = false;
289 FXString fxs(text.c_str());
290 for (FXint i = 0; i < fxs.length(); i = fxs.inc(i)) {
291 FXwchar wc = fxs.wc(i);
292 if (myTable->getFont()->hasChar(wc) != TRUE) {
293 missingChar = true;
294 break;
295 }
296 //std::cout << i << ": " << wc << " char:" << (char)(wc) << " has: " << (myTable->getFont()->hasChar(wc) == TRUE) << "\n";
297 }
298 if (missingChar) {
300 }
301}
302
303
304int
306 const Parameterised* p = dynamic_cast<const Parameterised*>(obj);
307 return p != nullptr ? (int)p->getParametersMap().size() : 0;
308}
309
310
311/****************************************************************************/
@ MID_TABLE
The Table.
Definition GUIAppEnum.h:539
@ MID_SIMSTEP
A Simulation step was performed.
Definition GUIAppEnum.h:541
@ MID_OPENTRACKER
A Tracker shall be opened.
Definition GUIAppEnum.h:543
FXDEFMAP(GUIParameterTableWindow) GUIParameterTableWindowMap[]
#define TL(string)
Definition MsgHandler.h:305
T MAX2(T a, T b)
Definition StdDefs.h:82
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel, const bool disable=false)
build menu command
const std::string & getFullName() const
Definition GUIGlObject.h:95
void addParameterTable(GUIParameterTableWindow *w)
void removeParameterTable(GUIParameterTableWindow *w)
Lets this object know a parameter window showing the object's values was closed.
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
virtual double getTrackerInterval() const =0
get tracker interval (must be implemented in all children)
virtual SUMOTime getCurrentSimTime() const =0
get current sim time (must be implemented in all children)
FXFont * getFallbackFont()
get fallback front
void removeChild(FXMainWindow *child)
removes the given child window from the list (FXMainWindow)
void addChild(FXMainWindow *child)
Adds a further child window to the list (FXMainWindow)
A popup-menu for dynamic patameter table entries.
Instance of a single line in a parameter window.
Interface to a single line in a parameter window.
virtual const std::string & getName() const =0
Returns the name 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.
A window containing a gl-object's parameter.
long onRightButtonPress(FXObject *, FXSelector, void *)
Shows a popup.
GUIMainWindow * myApplication
The main application window.
static FXMutex myGlobalContainerLock
The mutex used to avoid concurrent updates of the instance container.
void removeObject(GUIGlObject *const o)
Lets this window know the object shown is being deleted.
static int numParams(const GUIGlObject *obj)
returns the number of parameters if obj is Parameterised and 0 otherwise
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
int myTrackerY
y-position for opening new tracker window
long onLeftBtnPress(FXObject *, FXSelector, void *)
directly opens tracker when clicking on last column
long onTableSelected(FXObject *, FXSelector, void *)
Does nothing.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
FXMutex myLock
A lock assuring save updates in case of object deletion.
std::vector< GUIParameterTableItemInterface * > myItems
The list of table rows.
unsigned myCurrentPos
The index of the next row to add - used while building.
void checkFont(const std::string &text)
ensure that the font covers the given text
long onTableDeselected(FXObject *, FXSelector, void *)
Does nothing.
FXTable * myTable
The table to display the information in.
static std::vector< GUIParameterTableWindow * > myContainer
The container of items that shall be updated.
long onSimStep(FXObject *, FXSelector, void *)
Updates the table due to a simulation step.
GUIParameterTableWindow(GUIMainWindow &app, GUIGlObject &o, const std::string &title="")
Constructor.
void updateTable()
Updates the table.
GUIGlObject * myObject
The object to get the information from.
A window which displays the time line of one (or more) value(s)
void addTracked(GUIGlObject &o, ValueSource< double > *src, TrackerValueDesc *newTracked)
Adds a further time line to display.
void create()
Creates the window.
static bool addTrackedMultiplot(GUIGlObject &o, ValueSource< double > *src, TrackerValueDesc *newTracked)
all value source to multiplot trackers
Persists window position in the registry.
An upper class for objects with additional parameters.
std::map< std::string, std::string > Map
parameters map
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
static const RGBColor BLACK
Definition RGBColor.h:196
Representation of a timeline of floats with their names and moments.