Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-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/****************************************************************************/
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// ===========================================================================
57// static value definitions
58// ===========================================================================
60std::vector<GUIParameterTableWindow*> GUIParameterTableWindow::myContainer;
61
62// ===========================================================================
63// method definitions
64// ===========================================================================
66 FXMainWindow(app.getApp(), ((title == "" ? o.getFullName() : title) + " Parameter").c_str(), nullptr, nullptr, DECOR_ALL, 20, 40, 200, 500),
67 GUIPersistentWindowPos(this, "DIALOG_PARAMETERS", false, 20, 40),
68 myObject(&o),
69 myApplication(&app),
70 myTrackerY(50),
71 myCurrentPos(0) {
72 myTable = new FXTable(this, this, MID_TABLE, TABLE_COL_SIZABLE | TABLE_ROW_SIZABLE | LAYOUT_FILL_X | LAYOUT_FILL_Y);
73 myTable->setTableSize(1, 3);
74 myTable->setVisibleColumns(3);
75 myTable->setBackColor(FXRGB(255, 255, 255));
76 myTable->setColumnText(0, TL("Name"));
77 myTable->setColumnText(1, TL("Value"));
78 myTable->setColumnText(2, TL("Dynamic"));
79 myTable->getRowHeader()->setWidth(0);
80 FXHeader* header = myTable->getColumnHeader();
81 header->setItemJustify(0, JUSTIFY_CENTER_X);
82 header->setItemSize(0, 240);
83 header->setItemJustify(1, JUSTIFY_CENTER_X);
84 header->setItemSize(1, 120);
85 header->setItemJustify(2, JUSTIFY_CENTER_X);
86 header->setItemSize(2, 60);
88 myLock.lock();
90 myLock.unlock();
91 FXMutexLock locker(myGlobalContainerLock);
92 myContainer.push_back(this);
93 // Table cannot be editable
94 myTable->setEditable(FALSE);
96}
97
100 myLock.lock();
101 for (std::vector<GUIParameterTableItemInterface*>::iterator i = myItems.begin(); i != myItems.end(); ++i) {
102 delete (*i);
103 }
104 if (myObject != nullptr) {
106 }
107 myLock.unlock();
108 FXMutexLock locker(myGlobalContainerLock);
109 std::vector<GUIParameterTableWindow*>::iterator i = std::find(myContainer.begin(), myContainer.end(), this);
110 if (i != myContainer.end()) {
111 myContainer.erase(i);
112 }
113}
114
115
116void
118 FXMutexLock locker(myLock);
119 myObject = nullptr;
120}
121
122
123long
124GUIParameterTableWindow::onSimStep(FXObject*, FXSelector, void*) {
125 // table values are updated in GUINet::guiSimulationStep()
126 updateTable();
127 update();
128 return 1;
129}
130
131
132long
133GUIParameterTableWindow::onTableSelected(FXObject*, FXSelector, void*) {
134 return 1;
135}
136
137
138long
139GUIParameterTableWindow::onTableDeselected(FXObject*, FXSelector, void*) {
140 return 1;
141}
142
143long
144GUIParameterTableWindow::onLeftBtnPress(FXObject* sender, FXSelector sel, void* eventData) {
145 FXEvent* e = (FXEvent*) eventData;
146 int row = myTable->rowAtY(e->win_y);
147 int col = myTable->colAtX(e->win_x);
148 if (col == 2 && row >= 0 && row < (int)myItems.size()) {
150 if (i->dynamic() && i->getdoubleSourceCopy() != nullptr) {
151 // open tracker directly
152 const std::string trackerName = i->getName() + " from " + myObject->getFullName();
156 tr->addTracked(*myObject, i->getdoubleSourceCopy(), newTracked);
157 tr->setX(getX() + getWidth() + 10);
158 tr->setY(myTrackerY);
159 tr->create();
160 tr->show();
161 myTrackerY = (myTrackerY + tr->getHeight() + 20) % getApp()->getRootWindow()->getHeight();
162 }
163 }
164 }
165 return FXMainWindow::onLeftBtnPress(sender, sel, eventData);
166}
167
168long
169GUIParameterTableWindow::onRightButtonPress(FXObject* /*sender*/, FXSelector /*sel*/, void* eventData) {
170 // check which value entry was pressed
171 FXEvent* e = (FXEvent*) eventData;
172 int row = myTable->rowAtY(e->win_y);
173 if (row == -1 || row >= (int)(myItems.size())) {
174 return 1;
175 }
177 if (!i->dynamic()) {
178 return 1;
179 }
180 if (myObject == nullptr) {
181 return 1;
182 }
183
184 ValueSource<double>* doubleSource = i->getdoubleSourceCopy();
185 if (doubleSource != nullptr) {
187 GUIDesigns::buildFXMenuCommand(p, TL("Open in new Tracker"), nullptr, p, MID_OPENTRACKER);
188 // set geometry
189 p->setX(static_cast<FXEvent*>(eventData)->root_x);
190 p->setY(static_cast<FXEvent*>(eventData)->root_y);
191 p->create();
192 // show
193 p->show();
194 }
195 return 1;
196}
197
198
199void
200GUIParameterTableWindow::mkItem(const char* name, bool dynamic, std::string value) {
201 myTable->insertRows((int)myItems.size() + 1);
203 myItems.push_back(i);
204}
205
206
207void
208GUIParameterTableWindow::mkItem(const char* name, bool dynamic, double value) {
209 myTable->insertRows((int)myItems.size() + 1);
211 myItems.push_back(i);
212}
213
214
215void
216GUIParameterTableWindow::mkItem(const char* name, bool dynamic, unsigned value) {
217 myTable->insertRows((int)myItems.size() + 1);
219 myItems.push_back(i);
220}
221
222
223void
224GUIParameterTableWindow::mkItem(const char* name, bool dynamic, int value) {
225 myTable->insertRows((int)myItems.size() + 1);
227 myItems.push_back(i);
228}
229
230
231void
232GUIParameterTableWindow::mkItem(const char* name, bool dynamic, long long int value) {
233 myTable->insertRows((int)myItems.size() + 1);
235 myItems.push_back(i);
236}
237
238
239void
241 FXMutexLock locker(myLock);
242 if (myObject == nullptr) {
243 return;
244 }
245 for (GUIParameterTableItemInterface* const item : myItems) {
246 item->update();
247 }
248}
249
250
251void
253 // add generic parameters if available
254 if (p == nullptr) {
255 p = dynamic_cast<const Parameterised*>(myObject);
256 }
257 if (p != nullptr) {
258 const Parameterised::Map& map = p->getParametersMap();
259 for (Parameterised::Map::const_iterator it = map.begin(); it != map.end(); ++it) {
260 mkItem(("param:" + it->first).c_str(), false, it->second);
261 }
262 }
263 const int rows = (int)myItems.size() + 1;
264 int h = rows * 20 + 40;
265 // adjust size in case there are higher (multi-line) rows
266 for (int i = 0; i < (int)myItems.size(); i++) {
267 h += MAX2(0, myTable->getRowHeight(i) - 20);
268 }
269 setHeight(h);
270 myTable->fitColumnsToContents(1);
271 setWidth(myTable->getContentWidth() + 40);
272 myTable->setVisibleRows(rows);
273 myApplication->addChild(this);
274 create();
275 show();
276}
277
278
279void
280GUIParameterTableWindow::checkFont(const std::string& text) {
281 bool missingChar = false;
282 FXString fxs(text.c_str());
283 for (FXint i = 0; i < fxs.length(); i = fxs.inc(i)) {
284 FXwchar wc = fxs.wc(i);
285 if (myTable->getFont()->hasChar(wc) != TRUE) {
286 missingChar = true;
287 break;
288 }
289 //std::cout << i << ": " << wc << " char:" << (char)(wc) << " has: " << (myTable->getFont()->hasChar(wc) == TRUE) << "\n";
290 }
291 if (missingChar) {
293 }
294}
295
296
297int
299 const Parameterised* p = dynamic_cast<const Parameterised*>(obj);
300 return p != nullptr ? (int)p->getParametersMap().size() : 0;
301}
302
303
304/****************************************************************************/
@ 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:315
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:94
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:193
Representation of a timeline of floats with their names and moments.