SUMO - Simulation of Urban MObility
GUIParameterTableWindow.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // The window that holds the table of an object's parameter
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2002-2017 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <fx.h>
38 #include <utils/common/ToString.h>
44 
45 #ifdef CHECK_MEMORY_LEAKS
46 #include <foreign/nvwa/debug_new.h>
47 #endif // CHECK_MEMORY_LEAKS
48 
49 
50 // ===========================================================================
51 // FOX callback mapping
52 // ===========================================================================
53 FXDEFMAP(GUIParameterTableWindow) GUIParameterTableWindowMap[] = {
54  FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUIParameterTableWindow::onSimStep),
55  FXMAPFUNC(SEL_SELECTED, MID_TABLE, GUIParameterTableWindow::onTableSelected),
56  FXMAPFUNC(SEL_DESELECTED, MID_TABLE, GUIParameterTableWindow::onTableDeselected),
57  FXMAPFUNC(SEL_RIGHTBUTTONPRESS, MID_TABLE, GUIParameterTableWindow::onRightButtonPress),
58 };
59 
60 FXIMPLEMENT(GUIParameterTableWindow, FXMainWindow, GUIParameterTableWindowMap, ARRAYNUMBER(GUIParameterTableWindowMap))
61 
62 
63 // ===========================================================================
64 // static value definitions
65 // ===========================================================================
66 MFXMutex GUIParameterTableWindow::myGlobalContainerLock;
67 std::vector<GUIParameterTableWindow*> GUIParameterTableWindow::myContainer;
68 
69 // ===========================================================================
70 // method definitions
71 // ===========================================================================
73  FXMainWindow(app.getApp(), (o.getFullName() + " Parameter").c_str(), NULL, NULL, DECOR_ALL, 20, 20, 500, (FXint)(noRows * 20 + 60)),
74  myObject(&o),
75  myApplication(&app), myCurrentPos(0) {
76  myTable = new FXTable(this, this, MID_TABLE, TABLE_COL_SIZABLE | TABLE_ROW_SIZABLE | LAYOUT_FILL_X | LAYOUT_FILL_Y);
77  myTable->setVisibleRows((FXint)(noRows + 1));
78  myTable->setVisibleColumns(3);
79  myTable->setTableSize((FXint)(noRows + 1), 3);
80  myTable->setBackColor(FXRGB(255, 255, 255));
81  myTable->setColumnText(0, "Name");
82  myTable->setColumnText(1, "Value");
83  myTable->setColumnText(2, "Dynamic");
84  myTable->getRowHeader()->setWidth(0);
85  FXHeader* header = myTable->getColumnHeader();
86  header->setItemJustify(0, JUSTIFY_CENTER_X);
87  header->setItemSize(0, 240);
88  header->setItemJustify(1, JUSTIFY_CENTER_X);
89  header->setItemSize(1, 120);
90  header->setItemJustify(2, JUSTIFY_CENTER_X);
91  header->setItemSize(2, 60);
93  myLock.lock();
94  myObject->addParameterTable(this);
95  myLock.unlock();
96  AbstractMutex::ScopedLocker locker(myGlobalContainerLock);
97  myContainer.push_back(this);
98 }
99 
100 
102  myApplication->removeChild(this);
103  myLock.lock();
104  for (std::vector<GUIParameterTableItemInterface*>::iterator i = myItems.begin(); i != myItems.end(); ++i) {
105  delete(*i);
106  }
107  if (myObject != 0) {
109  }
110  myLock.unlock();
112  std::vector<GUIParameterTableWindow*>::iterator i = std::find(myContainer.begin(), myContainer.end(), this);
113  if (i != myContainer.end()) {
114  myContainer.erase(i);
115  }
116 }
117 
118 
119 void
122  myObject = 0;
123 }
124 
125 
126 long
127 GUIParameterTableWindow::onSimStep(FXObject*, FXSelector, void*) {
128  // table values are updated in GUINet::guiSimulationStep()
129  updateTable();
130  update();
131  return 1;
132 }
133 
134 
135 long
136 GUIParameterTableWindow::onTableSelected(FXObject*, FXSelector, void*) {
137  return 1;
138 }
139 
140 
141 long
142 GUIParameterTableWindow::onTableDeselected(FXObject*, FXSelector, void*) {
143  return 1;
144 }
145 
146 
147 long
149  FXSelector sel,
150  void* data) {
151  // check which value entry was pressed
152  myTable->onLeftBtnPress(sender, sel, data);
153  int row = myTable->getCurrentRow();
154  if (row == -1 || row >= (int)(myItems.size())) {
155  return 1;
156  }
158  if (!i->dynamic()) {
159  return 1;
160  }
161  if (myObject == 0) {
162  return 1;
163  }
164 
166  new FXMenuCommand(p, "Open in new Tracker", 0, p, MID_OPENTRACKER);
167  // set geometry
168  p->setX(static_cast<FXEvent*>(data)->root_x);
169  p->setY(static_cast<FXEvent*>(data)->root_y);
170  p->create();
171  // show
172  p->show();
173  return 1;
174 }
175 
176 
177 
178 void
179 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
180  ValueSource<unsigned>* src) {
182  myItems.push_back(i);
183 }
184 
185 
186 void
187 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
188  ValueSource<int>* src) {
190  myItems.push_back(i);
191 }
192 
193 
194 void
195 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
196  ValueSource<SUMOReal>* src) {
198  myItems.push_back(i);
199 }
200 
201 
202 void
203 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
204  std::string value) {
205  // T = SUMOReal is only a dummy type here
207  myItems.push_back(i);
208 }
209 
210 
211 void
212 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
213  SUMOReal value) {
215  myItems.push_back(i);
216 }
217 
218 
219 void
220 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
221  unsigned value) {
223  myItems.push_back(i);
224 }
225 
226 
227 void
228 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
229  int value) {
231  myItems.push_back(i);
232 }
233 
234 
235 void
236 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
237  long long int value) {
239  myItems.push_back(i);
240 }
241 
242 
243 void
246  if (myObject == 0) {
247  return;
248  }
249  for (std::vector<GUIParameterTableItemInterface*>::iterator i = myItems.begin(); i != myItems.end(); i++) {
250  (*i)->update();
251  }
252 }
253 
254 
255 void
257  myApplication->addChild(this, true);
258  create();
259  show();
260 }
261 
262 
263 
264 /****************************************************************************/
265 
void removeObject(GUIGlObject *const o)
Lets this window know the object shown is being deleted.
unsigned myCurrentPos
The index of the next row to add - used while building.
FXTable * myTable
The table to display the information in.
A popup-menu for dynamic patameter table entries.
GUIMainWindow * myApplication
The main application window.
A Tracker shall be opened.
Definition: GUIAppEnum.h:295
virtual bool dynamic() const =0
Returns the information whether the value changes over simulation time.
A Simulation step was performed.
Definition: GUIAppEnum.h:293
void updateTable()
Updates the table.
void removeParameterTable(GUIParameterTableWindow *w)
Lets this object know a parameter window showing the object&#39;s values was closed.
void addChild(FXMDIChild *child, bool updateOnSimStep=true)
Adds a further child window to the list.
static MFXMutex myGlobalContainerLock
The mutex used to avoid concurrent updates of the instance container.
The Table.
Definition: GUIAppEnum.h:291
virtual const std::string & getName() const =0
Returns the name of the value.
Interface to a single line in a parameter window.
static std::vector< GUIParameterTableWindow * > myContainer
The container of items that shall be updated.
long onRightButtonPress(FXObject *, FXSelector, void *)
Shows a popup.
void removeChild(FXMDIChild *child)
removes the given child window from the list
long onSimStep(FXObject *, FXSelector, void *)
Updates the table due to a simulation step.
void unlock()
release mutex lock
Definition: MFXMutex.cpp:96
long onTableDeselected(FXObject *, FXSelector, void *)
Does nothing.
MFXMutex myLock
A lock assuring save updates in case of object deletion.
virtual ValueSource< SUMOReal > * getSUMORealSourceCopy() const =0
Returns a SUMOReal-typed copy of the value-source.
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:71
void lock()
lock mutex
Definition: MFXMutex.cpp:86
GUIGlObject * myObject
The object to get the information from.
#define SUMOReal
Definition: config.h:208
Instance of a single line in a parameter window.
long onTableSelected(FXObject *, FXSelector, void *)
Does nothing.
std::vector< GUIParameterTableItemInterface * > myItems
The list of table rows.
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
void closeBuilding()
Closes the building of the table.
A window containing a gl-object&#39;s parameter.
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
FXDEFMAP(GUIParameterTableWindow) GUIParameterTableWindowMap[]