Eclipse SUMO - Simulation of Urban MObility
GUIParameterTableWindow.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2002-2022 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(), (o.getFullName() + " Parameter").c_str(), nullptr, nullptr, DECOR_ALL, 20, 20, 200, 500),
65 myObject(&o),
66 myApplication(&app),
67 myTrackerY(50),
68 myCurrentPos(0) {
69 myTable = new FXTable(this, this, MID_TABLE, TABLE_COL_SIZABLE | TABLE_ROW_SIZABLE | LAYOUT_FILL_X | LAYOUT_FILL_Y);
70 myTable->setTableSize(1, 3);
71 myTable->setVisibleColumns(3);
72 myTable->setBackColor(FXRGB(255, 255, 255));
73 myTable->setColumnText(0, "Name");
74 myTable->setColumnText(1, "Value");
75 myTable->setColumnText(2, "Dynamic");
76 myTable->getRowHeader()->setWidth(0);
77 FXHeader* header = myTable->getColumnHeader();
78 header->setItemJustify(0, JUSTIFY_CENTER_X);
79 header->setItemSize(0, 240);
80 header->setItemJustify(1, JUSTIFY_CENTER_X);
81 header->setItemSize(1, 120);
82 header->setItemJustify(2, JUSTIFY_CENTER_X);
83 header->setItemSize(2, 60);
85 myLock.lock();
87 myLock.unlock();
88 FXMutexLock locker(myGlobalContainerLock);
89 myContainer.push_back(this);
90 // Table cannot be editable
91 myTable->setEditable(FALSE);
92}
93
96 myLock.lock();
97 for (std::vector<GUIParameterTableItemInterface*>::iterator i = myItems.begin(); i != myItems.end(); ++i) {
98 delete (*i);
99 }
100 if (myObject != nullptr) {
102 }
103 myLock.unlock();
104 FXMutexLock locker(myGlobalContainerLock);
105 std::vector<GUIParameterTableWindow*>::iterator i = std::find(myContainer.begin(), myContainer.end(), this);
106 if (i != myContainer.end()) {
107 myContainer.erase(i);
108 }
109}
110
111
112void
114 FXMutexLock locker(myLock);
115 myObject = nullptr;
116}
117
118
119long
120GUIParameterTableWindow::onSimStep(FXObject*, FXSelector, void*) {
121 // table values are updated in GUINet::guiSimulationStep()
122 updateTable();
123 update();
124 return 1;
125}
126
127
128long
129GUIParameterTableWindow::onTableSelected(FXObject*, FXSelector, void*) {
130 return 1;
131}
132
133
134long
135GUIParameterTableWindow::onTableDeselected(FXObject*, FXSelector, void*) {
136 return 1;
137}
138
139long
140GUIParameterTableWindow::onLeftBtnPress(FXObject* sender, FXSelector sel, void* eventData) {
141 FXEvent* e = (FXEvent*) eventData;
142 int row = myTable->rowAtY(e->win_y);
143 int col = myTable->colAtX(e->win_x);
144 if (col == 2 && row >= 0 && row < (int)myItems.size()) {
146 if (i->dynamic() && i->getdoubleSourceCopy() != nullptr) {
147 // open tracker directly
148 const std::string trackerName = i->getName() + " from " + myObject->getFullName();
152 tr->addTracked(*myObject, i->getdoubleSourceCopy(), newTracked);
153 tr->setX(getX() + getWidth() + 10);
154 tr->setY(myTrackerY);
155 tr->create();
156 tr->show();
157 myTrackerY = (myTrackerY + tr->getHeight() + 20) % getApp()->getRootWindow()->getHeight();
158 }
159 }
160 }
161 return FXMainWindow::onLeftBtnPress(sender, sel, eventData);
162}
163
164long
165GUIParameterTableWindow::onRightButtonPress(FXObject* /*sender*/, FXSelector /*sel*/, void* eventData) {
166 // check which value entry was pressed
167 FXEvent* e = (FXEvent*) eventData;
168 int row = myTable->rowAtY(e->win_y);
169 if (row == -1 || row >= (int)(myItems.size())) {
170 return 1;
171 }
173 if (!i->dynamic()) {
174 return 1;
175 }
176 if (myObject == nullptr) {
177 return 1;
178 }
179
180 ValueSource<double>* doubleSource = i->getdoubleSourceCopy();
181 if (doubleSource != nullptr) {
183 GUIDesigns::buildFXMenuCommand(p, "Open in new Tracker", nullptr, p, MID_OPENTRACKER);
184 // set geometry
185 p->setX(static_cast<FXEvent*>(eventData)->root_x);
186 p->setY(static_cast<FXEvent*>(eventData)->root_y);
187 p->create();
188 // show
189 p->show();
190 }
191 return 1;
192}
193
194
195void
196GUIParameterTableWindow::mkItem(const char* name, bool dynamic, std::string value) {
197 myTable->insertRows((int)myItems.size() + 1);
199 myItems.push_back(i);
200}
201
202
203void
204GUIParameterTableWindow::mkItem(const char* name, bool dynamic, double value) {
205 myTable->insertRows((int)myItems.size() + 1);
207 myItems.push_back(i);
208}
209
210
211void
212GUIParameterTableWindow::mkItem(const char* name, bool dynamic, unsigned value) {
213 myTable->insertRows((int)myItems.size() + 1);
215 myItems.push_back(i);
216}
217
218
219void
220GUIParameterTableWindow::mkItem(const char* name, bool dynamic, int value) {
221 myTable->insertRows((int)myItems.size() + 1);
223 myItems.push_back(i);
224}
225
226
227void
228GUIParameterTableWindow::mkItem(const char* name, bool dynamic, long long int value) {
229 myTable->insertRows((int)myItems.size() + 1);
231 myItems.push_back(i);
232}
233
234
235void
237 FXMutexLock locker(myLock);
238 if (myObject == nullptr) {
239 return;
240 }
241 for (GUIParameterTableItemInterface* const item : myItems) {
242 item->update();
243 }
244}
245
246
247void
249 // add generic paramters if available
250 if (p == nullptr) {
251 p = dynamic_cast<const Parameterised*>(myObject);
252 }
253 if (p != nullptr) {
254 const Parameterised::Map& map = p->getParametersMap();
255 for (Parameterised::Map::const_iterator it = map.begin(); it != map.end(); ++it) {
256 mkItem(("param:" + it->first).c_str(), false, it->second);
257 }
258 }
259 const int rows = (int)myItems.size() + 1;
260 int h = rows * 20 + 40;
261 // adjust size in case there are higher (multi-line) rows
262 for (int i = 0; i < (int)myItems.size(); i++) {
263 h += MAX2(0, myTable->getRowHeight(i) - 20);
264 }
265 setHeight(h);
266 myTable->fitColumnsToContents(1);
267 setWidth(myTable->getContentWidth() + 40);
268 myTable->setVisibleRows(rows);
269 myApplication->addChild(this);
270 create();
271 show();
272}
273
274
275void
276GUIParameterTableWindow::checkFont(const std::string& text) {
277 bool missingChar = false;
278 FXString fxs(text.c_str());
279 for (FXint i = 0; i < fxs.length(); i = fxs.inc(i)) {
280 FXwchar wc = fxs.wc(i);
281 if (myTable->getFont()->hasChar(wc) != TRUE) {
282 missingChar = true;
283 break;
284 }
285 //std::cout << i << ": " << wc << " char:" << (char)(wc) << " has: " << (myTable->getFont()->hasChar(wc) == TRUE) << "\n";
286 }
287 if (missingChar) {
289 }
290}
291
292
293int
295 const Parameterised* p = dynamic_cast<const Parameterised*>(obj);
296 return p != nullptr ? (int)p->getParametersMap().size() : 0;
297}
298
299
300/****************************************************************************/
@ MID_TABLE
The Table.
Definition: GUIAppEnum.h:530
@ MID_SIMSTEP
A Simulation step was performed.
Definition: GUIAppEnum.h:532
@ MID_OPENTRACKER
A Tracker shall be opened.
Definition: GUIAppEnum.h:534
FXDEFMAP(GUIParameterTableWindow) GUIParameterTableWindowMap[]
T MAX2(T a, T b)
Definition: StdDefs.h:77
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel)
build menu command
Definition: GUIDesigns.cpp:42
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.
GUIParameterTableWindow(GUIMainWindow &app, GUIGlObject &o)
Constructor.
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.
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
An upper class for objects with additional parameters.
Definition: Parameterised.h:41
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
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.