Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/gui/div/GUIParameterTableWindow.cpp
169684 views
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
/****************************************************************************/
14
/// @file GUIParameterTableWindow.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Laura Bieker
17
/// @author Michael Behrisch
18
/// @author Jakob Erdmann
19
/// @author Mirko Barthauer
20
/// @date Sept 2002
21
///
22
// The window that holds the table of an object's parameter
23
/****************************************************************************/
24
#include <config.h>
25
26
#include <string>
27
#include <utils/foxtools/fxheader.h>
28
#include "GUIParameterTableWindow.h"
29
#include <utils/gui/globjects/GUIGlObject.h>
30
#include <utils/common/MsgHandler.h>
31
#include <utils/common/ToString.h>
32
#include <utils/common/Parameterised.h>
33
#include <utils/gui/div/GUIParam_PopupMenu.h>
34
#include <utils/gui/windows/GUIAppEnum.h>
35
#include <utils/gui/windows/GUIMainWindow.h>
36
#include <utils/gui/images/GUIIconSubSys.h>
37
#include <utils/gui/tracker/GUIParameterTracker.h>
38
#include <utils/gui/div/GUIParameterTableItem.h>
39
#include <utils/gui/div/GUIDesigns.h>
40
41
42
// ===========================================================================
43
// FOX callback mapping
44
// ===========================================================================
45
FXDEFMAP(GUIParameterTableWindow) GUIParameterTableWindowMap[] = {
46
FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUIParameterTableWindow::onSimStep),
47
FXMAPFUNC(SEL_SELECTED, MID_TABLE, GUIParameterTableWindow::onTableSelected),
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
53
FXIMPLEMENT(GUIParameterTableWindow, FXMainWindow, GUIParameterTableWindowMap, ARRAYNUMBER(GUIParameterTableWindowMap))
54
55
// ===========================================================================
56
// static value definitions
57
// ===========================================================================
58
59
FXMutex GUIParameterTableWindow::myGlobalContainerLock;
60
std::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
69
GUIParameterTableWindow::GUIParameterTableWindow(GUIMainWindow& app, GUIGlObject& o, const std::string& title) :
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(GUIDesignBackgroundColorWhite);
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);
91
setIcon(GUIIconSubSys::getIcon(GUIIcon::APP_TABLE));
92
myLock.lock();
93
myObject->addParameterTable(this);
94
myLock.unlock();
95
FXMutexLock locker(myGlobalContainerLock);
96
myContainer.push_back(this);
97
// Table cannot be editable
98
myTable->setEditable(FALSE);
99
loadWindowPos();
100
}
101
#ifdef _MSC_VER
102
#pragma warning(pop)
103
#endif
104
105
GUIParameterTableWindow::~GUIParameterTableWindow() {
106
myApplication->removeChild(this);
107
myLock.lock();
108
for (std::vector<GUIParameterTableItemInterface*>::iterator i = myItems.begin(); i != myItems.end(); ++i) {
109
delete (*i);
110
}
111
if (myObject != nullptr) {
112
myObject->removeParameterTable(this);
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
123
void
124
GUIParameterTableWindow::removeObject(GUIGlObject* /*i*/) {
125
FXMutexLock locker(myLock);
126
myObject = nullptr;
127
}
128
129
130
long
131
GUIParameterTableWindow::onSimStep(FXObject*, FXSelector, void*) {
132
// table values are updated in GUINet::guiSimulationStep()
133
updateTable();
134
update();
135
return 1;
136
}
137
138
139
long
140
GUIParameterTableWindow::onTableSelected(FXObject*, FXSelector, void*) {
141
return 1;
142
}
143
144
145
long
146
GUIParameterTableWindow::onTableDeselected(FXObject*, FXSelector, void*) {
147
return 1;
148
}
149
150
long
151
GUIParameterTableWindow::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()) {
156
GUIParameterTableItemInterface* i = myItems[row];
157
if (i->dynamic() && i->getdoubleSourceCopy() != nullptr) {
158
// open tracker directly
159
const std::string trackerName = i->getName() + " of " + myObject->getFullName();
160
TrackerValueDesc* newTracked = new TrackerValueDesc(i->getName(), RGBColor::BLACK, myApplication->getCurrentSimTime(), myApplication->getTrackerInterval());
161
if (!GUIParameterTracker::addTrackedMultiplot(*myObject, i->getdoubleSourceCopy(), newTracked)) {
162
GUIParameterTracker* tr = new GUIParameterTracker(*myApplication, trackerName);
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
175
long
176
GUIParameterTableWindow::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
}
183
GUIParameterTableItemInterface* i = myItems[row];
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) {
193
GUIParam_PopupMenuInterface* p = new GUIParam_PopupMenuInterface(*myApplication, *this, *myObject, i->getName(), doubleSource);
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
206
void
207
GUIParameterTableWindow::mkItem(const char* name, bool dynamic, std::string value) {
208
myTable->insertRows((int)myItems.size() + 1);
209
GUIParameterTableItemInterface* i = new GUIParameterTableItem<std::string>(myTable, myCurrentPos++, name, dynamic, value);
210
myItems.push_back(i);
211
}
212
213
214
void
215
GUIParameterTableWindow::mkItem(const char* name, bool dynamic, double value) {
216
myTable->insertRows((int)myItems.size() + 1);
217
GUIParameterTableItemInterface* i = new GUIParameterTableItem<double>(myTable, myCurrentPos++, name, dynamic, value);
218
myItems.push_back(i);
219
}
220
221
222
void
223
GUIParameterTableWindow::mkItem(const char* name, bool dynamic, unsigned value) {
224
myTable->insertRows((int)myItems.size() + 1);
225
GUIParameterTableItemInterface* i = new GUIParameterTableItem<unsigned>(myTable, myCurrentPos++, name, dynamic, value);
226
myItems.push_back(i);
227
}
228
229
230
void
231
GUIParameterTableWindow::mkItem(const char* name, bool dynamic, int value) {
232
myTable->insertRows((int)myItems.size() + 1);
233
GUIParameterTableItemInterface* i = new GUIParameterTableItem<int>(myTable, myCurrentPos++, name, dynamic, value);
234
myItems.push_back(i);
235
}
236
237
238
void
239
GUIParameterTableWindow::mkItem(const char* name, bool dynamic, long long int value) {
240
myTable->insertRows((int)myItems.size() + 1);
241
GUIParameterTableItemInterface* i = new GUIParameterTableItem<long long int>(myTable, myCurrentPos++, name, dynamic, value);
242
myItems.push_back(i);
243
}
244
245
246
void
247
GUIParameterTableWindow::updateTable() {
248
FXMutexLock locker(myLock);
249
if (myObject == nullptr) {
250
return;
251
}
252
for (GUIParameterTableItemInterface* const item : myItems) {
253
item->update();
254
}
255
}
256
257
258
void
259
GUIParameterTableWindow::closeBuilding(const Parameterised* p) {
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
286
void
287
GUIParameterTableWindow::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) {
299
myTable->setFont(myApplication->getFallbackFont());
300
}
301
}
302
303
304
int
305
GUIParameterTableWindow::numParams(const GUIGlObject* obj) {
306
const Parameterised* p = dynamic_cast<const Parameterised*>(obj);
307
return p != nullptr ? (int)p->getParametersMap().size() : 0;
308
}
309
310
311
/****************************************************************************/
312
313