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-2023 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/****************************************************************************/
21// The window that holds the table of an object's parameter
22/****************************************************************************/
23#include <config.h>
24
25#include <string>
38
39
40// ===========================================================================
41// FOX callback mapping
42// ===========================================================================
43FXDEFMAP(GUIParameterTableWindow) GUIParameterTableWindowMap[] = {
44 FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUIParameterTableWindow::onSimStep),
46 FXMAPFUNC(SEL_DESELECTED, MID_TABLE, GUIParameterTableWindow::onTableDeselected),
47 FXMAPFUNC(SEL_RIGHTBUTTONPRESS, MID_TABLE, GUIParameterTableWindow::onRightButtonPress),
48 FXMAPFUNC(SEL_LEFTBUTTONPRESS, MID_TABLE, GUIParameterTableWindow::onLeftBtnPress),
49};
50
51FXIMPLEMENT(GUIParameterTableWindow, FXMainWindow, GUIParameterTableWindowMap, ARRAYNUMBER(GUIParameterTableWindowMap))
52
53
54// ===========================================================================
55// static value definitions
56// ===========================================================================
58std::vector<GUIParameterTableWindow*> GUIParameterTableWindow::myContainer;
59
60// ===========================================================================
61// method definitions
62// ===========================================================================
64 FXMainWindow(app.getApp(), ((title == "" ? o.getFullName() : title) + " Parameter").c_str(), nullptr, nullptr, DECOR_ALL, 20, 40, 200, 500),
65 GUIPersistentWindowPos(this, "DIALOG_PARAMETERS", false, 20, 40),
66 myObject(&o),
67 myApplication(&app),
68 myTrackerY(50),
69 myCurrentPos(0) {
70 myTable = new FXTable(this, this, MID_TABLE, TABLE_COL_SIZABLE | TABLE_ROW_SIZABLE | LAYOUT_FILL_X | LAYOUT_FILL_Y);
71 myTable->setTableSize(1, 3);
72 myTable->setVisibleColumns(3);
73 myTable->setBackColor(FXRGB(255, 255, 255));
74 myTable->setColumnText(0, "Name");
75 myTable->setColumnText(1, "Value");
76 myTable->setColumnText(2, "Dynamic");
77 myTable->getRowHeader()->setWidth(0);
78 FXHeader* header = myTable->getColumnHeader();
79 header->setItemJustify(0, JUSTIFY_CENTER_X);
80 header->setItemSize(0, 240);
81 header->setItemJustify(1, JUSTIFY_CENTER_X);
82 header->setItemSize(1, 120);
83 header->setItemJustify(2, JUSTIFY_CENTER_X);
84 header->setItemSize(2, 60);
86 myLock.lock();
88 myLock.unlock();
89 FXMutexLock locker(myGlobalContainerLock);
90 myContainer.push_back(this);
91 // Table cannot be editable
92 myTable->setEditable(FALSE);
94}
95
98 myLock.lock();
99 for (std::vector<GUIParameterTableItemInterface*>::iterator i = myItems.begin(); i != myItems.end(); ++i) {
100 delete (*i);
101 }
102 if (myObject != nullptr) {
104 }
105 myLock.unlock();
106 FXMutexLock locker(myGlobalContainerLock);
107 std::vector<GUIParameterTableWindow*>::iterator i = std::find(myContainer.begin(), myContainer.end(), this);
108 if (i != myContainer.end()) {
109 myContainer.erase(i);
110 }
111}
112
113
114void
116 FXMutexLock locker(myLock);
117 myObject = nullptr;
118}
119
120
121long
122GUIParameterTableWindow::onSimStep(FXObject*, FXSelector, void*) {
123 // table values are updated in GUINet::guiSimulationStep()
124 updateTable();
125 update();
126 return 1;
127}
128
129
130long
131GUIParameterTableWindow::onTableSelected(FXObject*, FXSelector, void*) {
132 return 1;
133}
134
135
136long
137GUIParameterTableWindow::onTableDeselected(FXObject*, FXSelector, void*) {
138 return 1;
139}
140
141long
142GUIParameterTableWindow::onLeftBtnPress(FXObject* sender, FXSelector sel, void* eventData) {
143 FXEvent* e = (FXEvent*) eventData;
144 int row = myTable->rowAtY(e->win_y);
145 int col = myTable->colAtX(e->win_x);
146 if (col == 2 && row >= 0 && row < (int)myItems.size()) {
148 if (i->dynamic() && i->getdoubleSourceCopy() != nullptr) {
149 // open tracker directly
150 const std::string trackerName = i->getName() + " from " + myObject->getFullName();
154 tr->addTracked(*myObject, i->getdoubleSourceCopy(), newTracked);
155 tr->setX(getX() + getWidth() + 10);
156 tr->setY(myTrackerY);
157 tr->create();
158 tr->show();
159 myTrackerY = (myTrackerY + tr->getHeight() + 20) % getApp()->getRootWindow()->getHeight();
160 }
161 }
162 }
163 return FXMainWindow::onLeftBtnPress(sender, sel, eventData);
164}
165
166long
167GUIParameterTableWindow::onRightButtonPress(FXObject* /*sender*/, FXSelector /*sel*/, void* eventData) {
168 // check which value entry was pressed
169 FXEvent* e = (FXEvent*) eventData;
170 int row = myTable->rowAtY(e->win_y);
171 if (row == -1 || row >= (int)(myItems.size())) {
172 return 1;
173 }
175 if (!i->dynamic()) {
176 return 1;
177 }
178 if (myObject == nullptr) {
179 return 1;
180 }
181
182 ValueSource<double>* doubleSource = i->getdoubleSourceCopy();
183 if (doubleSource != nullptr) {
185 GUIDesigns::buildFXMenuCommand(p, "Open in new Tracker", nullptr, p, MID_OPENTRACKER);
186 // set geometry
187 p->setX(static_cast<FXEvent*>(eventData)->root_x);
188 p->setY(static_cast<FXEvent*>(eventData)->root_y);
189 p->create();
190 // show
191 p->show();
192 }
193 return 1;
194}
195
196
197void
198GUIParameterTableWindow::mkItem(const char* name, bool dynamic, std::string value) {
199 myTable->insertRows((int)myItems.size() + 1);
201 myItems.push_back(i);
202}
203
204
205void
206GUIParameterTableWindow::mkItem(const char* name, bool dynamic, double value) {
207 myTable->insertRows((int)myItems.size() + 1);
209 myItems.push_back(i);
210}
211
212
213void
214GUIParameterTableWindow::mkItem(const char* name, bool dynamic, unsigned value) {
215 myTable->insertRows((int)myItems.size() + 1);
217 myItems.push_back(i);
218}
219
220
221void
222GUIParameterTableWindow::mkItem(const char* name, bool dynamic, int value) {
223 myTable->insertRows((int)myItems.size() + 1);
225 myItems.push_back(i);
226}
227
228
229void
230GUIParameterTableWindow::mkItem(const char* name, bool dynamic, long long int value) {
231 myTable->insertRows((int)myItems.size() + 1);
233 myItems.push_back(i);
234}
235
236
237void
239 FXMutexLock locker(myLock);
240 if (myObject == nullptr) {
241 return;
242 }
243 for (GUIParameterTableItemInterface* const item : myItems) {
244 item->update();
245 }
246}
247
248
249void
251 // add generic paramters if available
252 if (p == nullptr) {
253 p = dynamic_cast<const Parameterised*>(myObject);
254 }
255 if (p != nullptr) {
256 const Parameterised::Map& map = p->getParametersMap();
257 for (Parameterised::Map::const_iterator it = map.begin(); it != map.end(); ++it) {
258 mkItem(("param:" + it->first).c_str(), false, it->second);
259 }
260 }
261 const int rows = (int)myItems.size() + 1;
262 int h = rows * 20 + 40;
263 // adjust size in case there are higher (multi-line) rows
264 for (int i = 0; i < (int)myItems.size(); i++) {
265 h += MAX2(0, myTable->getRowHeight(i) - 20);
266 }
267 setHeight(h);
268 myTable->fitColumnsToContents(1);
269 setWidth(myTable->getContentWidth() + 40);
270 myTable->setVisibleRows(rows);
271 myApplication->addChild(this);
272 create();
273 show();
274}
275
276
277void
278GUIParameterTableWindow::checkFont(const std::string& text) {
279 bool missingChar = false;
280 FXString fxs(text.c_str());
281 for (FXint i = 0; i < fxs.length(); i = fxs.inc(i)) {
282 FXwchar wc = fxs.wc(i);
283 if (myTable->getFont()->hasChar(wc) != TRUE) {
284 missingChar = true;
285 break;
286 }
287 //std::cout << i << ": " << wc << " char:" << (char)(wc) << " has: " << (myTable->getFont()->hasChar(wc) == TRUE) << "\n";
288 }
289 if (missingChar) {
291 }
292}
293
294
295int
297 const Parameterised* p = dynamic_cast<const Parameterised*>(obj);
298 return p != nullptr ? (int)p->getParametersMap().size() : 0;
299}
300
301
302/****************************************************************************/
@ MID_TABLE
The Table.
Definition GUIAppEnum.h:532
@ MID_SIMSTEP
A Simulation step was performed.
Definition GUIAppEnum.h:534
@ MID_OPENTRACKER
A Tracker shall be opened.
Definition GUIAppEnum.h:536
FXDEFMAP(GUIParameterTableWindow) GUIParameterTableWindowMap[]
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)
build menu command
const std::string & getFullName() const
Definition GUIGlObject.h:92
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.