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 
46 // ===========================================================================
47 // FOX callback mapping
48 // ===========================================================================
49 FXDEFMAP(GUIParameterTableWindow) GUIParameterTableWindowMap[] = {
50  FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUIParameterTableWindow::onSimStep),
51  FXMAPFUNC(SEL_SELECTED, MID_TABLE, GUIParameterTableWindow::onTableSelected),
52  FXMAPFUNC(SEL_DESELECTED, MID_TABLE, GUIParameterTableWindow::onTableDeselected),
53  FXMAPFUNC(SEL_RIGHTBUTTONPRESS, MID_TABLE, GUIParameterTableWindow::onRightButtonPress),
54 };
55 
56 FXIMPLEMENT(GUIParameterTableWindow, FXMainWindow, GUIParameterTableWindowMap, ARRAYNUMBER(GUIParameterTableWindowMap))
57 
58 
59 // ===========================================================================
60 // static value definitions
61 // ===========================================================================
63 std::vector<GUIParameterTableWindow*> GUIParameterTableWindow::myContainer;
64 
65 // ===========================================================================
66 // method definitions
67 // ===========================================================================
69  FXMainWindow(app.getApp(), (o.getFullName() + " Parameter").c_str(), NULL, NULL, DECOR_ALL, 20, 20, 500, (FXint)(noRows * 20 + 60)),
70  myObject(&o),
71  myApplication(&app), myCurrentPos(0) {
72  myTable = new FXTable(this, this, MID_TABLE, TABLE_COL_SIZABLE | TABLE_ROW_SIZABLE | LAYOUT_FILL_X | LAYOUT_FILL_Y);
73  myTable->setVisibleRows((FXint)(noRows + 1));
74  myTable->setVisibleColumns(3);
75  myTable->setTableSize((FXint)(noRows + 1), 3);
76  myTable->setBackColor(FXRGB(255, 255, 255));
77  myTable->setColumnText(0, "Name");
78  myTable->setColumnText(1, "Value");
79  myTable->setColumnText(2, "Dynamic");
80  myTable->getRowHeader()->setWidth(0);
81  FXHeader* header = myTable->getColumnHeader();
82  header->setItemJustify(0, JUSTIFY_CENTER_X);
83  header->setItemSize(0, 240);
84  header->setItemJustify(1, JUSTIFY_CENTER_X);
85  header->setItemSize(1, 120);
86  header->setItemJustify(2, JUSTIFY_CENTER_X);
87  header->setItemSize(2, 60);
89  myLock.lock();
91  myLock.unlock();
93  myContainer.push_back(this);
94 }
95 
96 
99  myLock.lock();
100  for (std::vector<GUIParameterTableItemInterface*>::iterator i = myItems.begin(); i != myItems.end(); ++i) {
101  delete(*i);
102  }
103  if (myObject != 0) {
105  }
106  myLock.unlock();
108  std::vector<GUIParameterTableWindow*>::iterator i = std::find(myContainer.begin(), myContainer.end(), this);
109  if (i != myContainer.end()) {
110  myContainer.erase(i);
111  }
112 }
113 
114 
115 void
118  myObject = 0;
119 }
120 
121 
122 long
123 GUIParameterTableWindow::onSimStep(FXObject*, FXSelector, void*) {
124  // table values are updated in GUINet::guiSimulationStep()
125  updateTable();
126  update();
127  return 1;
128 }
129 
130 
131 long
132 GUIParameterTableWindow::onTableSelected(FXObject*, FXSelector, void*) {
133  return 1;
134 }
135 
136 
137 long
138 GUIParameterTableWindow::onTableDeselected(FXObject*, FXSelector, void*) {
139  return 1;
140 }
141 
142 
143 long
145  FXSelector sel,
146  void* data) {
147  // check which value entry was pressed
148  myTable->onLeftBtnPress(sender, sel, data);
149  int row = myTable->getCurrentRow();
150  if (row == -1 || row >= (int)(myItems.size())) {
151  return 1;
152  }
154  if (!i->dynamic()) {
155  return 1;
156  }
157  if (myObject == 0) {
158  return 1;
159  }
160 
162  new FXMenuCommand(p, "Open in new Tracker", 0, p, MID_OPENTRACKER);
163  // set geometry
164  p->setX(static_cast<FXEvent*>(data)->root_x);
165  p->setY(static_cast<FXEvent*>(data)->root_y);
166  p->create();
167  // show
168  p->show();
169  return 1;
170 }
171 
172 
173 
174 void
175 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
176  ValueSource<unsigned>* src) {
178  myItems.push_back(i);
179 }
180 
181 
182 void
183 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
184  ValueSource<int>* src) {
186  myItems.push_back(i);
187 }
188 
189 
190 void
191 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
192  ValueSource<double>* src) {
194  myItems.push_back(i);
195 }
196 
197 
198 void
199 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
200  std::string value) {
201  // T = double is only a dummy type here
203  myItems.push_back(i);
204 }
205 
206 
207 void
208 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
209  double value) {
211  myItems.push_back(i);
212 }
213 
214 
215 void
216 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
217  unsigned value) {
219  myItems.push_back(i);
220 }
221 
222 
223 void
224 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
225  int value) {
227  myItems.push_back(i);
228 }
229 
230 
231 void
232 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
233  long long int value) {
235  myItems.push_back(i);
236 }
237 
238 
239 void
242  if (myObject == 0) {
243  return;
244  }
245  for (std::vector<GUIParameterTableItemInterface*>::iterator i = myItems.begin(); i != myItems.end(); i++) {
246  (*i)->update();
247  }
248 }
249 
250 
251 void
253  myApplication->addChild(this, true);
254  create();
255  show();
256 }
257 
258 
259 
260 /****************************************************************************/
261 
void removeObject(GUIGlObject *const o)
Lets this window know the object shown is being deleted.
The Table.
Definition: GUIAppEnum.h:291
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.
virtual const std::string & getName() const =0
Returns the name of the value.
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.
void addParameterTable(GUIParameterTableWindow *w)
Interface to a single line in a parameter window.
A Tracker shall be opened.
Definition: GUIAppEnum.h:295
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:92
long onTableDeselected(FXObject *, FXSelector, void *)
Does nothing.
GUIParameterTableWindow()
FOX needs this.
MFXMutex myLock
A lock assuring save updates in case of object deletion.
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:71
virtual bool dynamic() const =0
Returns the information whether the value changes over simulation time.
virtual ValueSource< double > * getdoubleSourceCopy() const =0
Returns a double-typed copy of the value-source.
void lock()
lock mutex
Definition: MFXMutex.cpp:82
GUIGlObject * myObject
The object to get the information from.
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.
A Simulation step was performed.
Definition: GUIAppEnum.h:293
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[]