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-2015 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  GUIGlObject& o, size_t noRows)
74  : FXMainWindow(app.getApp(), (o.getFullName() + " Parameter").c_str(),
75  NULL, NULL, DECOR_ALL, 20, 20, 500, (FXint)(noRows * 20 + 60)),
76  myObject(&o),
77  myApplication(&app), myCurrentPos(0) {
78  myTable = new FXTable(this, this, MID_TABLE, TABLE_COL_SIZABLE | TABLE_ROW_SIZABLE | LAYOUT_FILL_X | LAYOUT_FILL_Y);
79  myTable->setVisibleRows((FXint)(noRows + 1));
80  myTable->setVisibleColumns(3);
81  myTable->setTableSize((FXint)(noRows + 1), 3);
82  myTable->setBackColor(FXRGB(255, 255, 255));
83  myTable->setColumnText(0, "Name");
84  myTable->setColumnText(1, "Value");
85  myTable->setColumnText(2, "Dynamic");
86  myTable->getRowHeader()->setWidth(0);
87  FXHeader* header = myTable->getColumnHeader();
88  header->setItemJustify(0, JUSTIFY_CENTER_X);
89  header->setItemSize(0, 240);
90  header->setItemJustify(1, JUSTIFY_CENTER_X);
91  header->setItemSize(1, 120);
92  header->setItemJustify(2, JUSTIFY_CENTER_X);
93  header->setItemSize(2, 60);
95  myLock.lock();
96  myObject->addParameterTable(this);
97  myLock.unlock();
98  AbstractMutex::ScopedLocker locker(myGlobalContainerLock);
99  myContainer.push_back(this);
100 }
101 
102 
104  myApplication->removeChild(this);
105  myLock.lock();
106  for (std::vector<GUIParameterTableItemInterface*>::iterator i = myItems.begin(); i != myItems.end(); ++i) {
107  delete(*i);
108  }
109  if (myObject != 0) {
111  }
112  myLock.unlock();
114  std::vector<GUIParameterTableWindow*>::iterator i = std::find(myContainer.begin(), myContainer.end(), this);
115  if (i != myContainer.end()) {
116  myContainer.erase(i);
117  }
118 }
119 
120 
121 void
124  myObject = 0;
125 }
126 
127 
128 long
129 GUIParameterTableWindow::onSimStep(FXObject*, FXSelector, void*) {
130  // table values are updated in GUINet::guiSimulationStep()
131  updateTable();
132  update();
133  return 1;
134 }
135 
136 
137 long
138 GUIParameterTableWindow::onTableSelected(FXObject*, FXSelector, void*) {
139  return 1;
140 }
141 
142 
143 long
144 GUIParameterTableWindow::onTableDeselected(FXObject*, FXSelector, void*) {
145  return 1;
146 }
147 
148 
149 long
151  FXSelector sel,
152  void* data) {
153  // check which value entry was pressed
154  myTable->onLeftBtnPress(sender, sel, data);
155  int row = myTable->getCurrentRow();
156  if (row == -1 || row >= (int)(myItems.size())) {
157  return 1;
158  }
160  if (!i->dynamic()) {
161  return 1;
162  }
163 
165  new FXMenuCommand(p, "Open in new Tracker", 0, p, MID_OPENTRACKER);
166  // set geometry
167  p->setX(static_cast<FXEvent*>(data)->root_x);
168  p->setY(static_cast<FXEvent*>(data)->root_y);
169  p->create();
170  // show
171  p->show();
172  return 1;
173 }
174 
175 
176 
177 void
178 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
179  ValueSource<unsigned>* src) {
181  myItems.push_back(i);
182 }
183 
184 
185 void
186 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
187  ValueSource<int>* src) {
189  myItems.push_back(i);
190 }
191 
192 
193 void
194 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
195  ValueSource<SUMOReal>* src) {
197  myItems.push_back(i);
198 }
199 
200 
201 void
202 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
203  std::string value) {
204  // T = SUMOReal is only a dummy type here
206  myItems.push_back(i);
207 }
208 
209 
210 void
211 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
212  SUMOReal value) {
214  myItems.push_back(i);
215 }
216 
217 
218 void
219 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
220  unsigned value) {
222  myItems.push_back(i);
223 }
224 
225 
226 void
227 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
228  int value) {
230  myItems.push_back(i);
231 }
232 
233 
234 void
235 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
236  long long int value) {
238  myItems.push_back(i);
239 }
240 
241 
242 void
245  if (myObject == 0) {
246  return;
247  }
248  for (std::vector<GUIParameterTableItemInterface*>::iterator i = myItems.begin(); i != myItems.end(); i++) {
249  (*i)->update();
250  }
251 }
252 
253 
254 void
256  myApplication->addChild(this, true);
257  create();
258  show();
259 }
260 
261 
262 
263 /****************************************************************************/
264 
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.
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.
The Table.
Definition: GUIAppEnum.h:275
virtual ValueSource< SUMOReal > * getSUMORealSourceCopy() const =0
Returns a SUMOReal-typed copy of the value-source.
A Simulation step was performed.
Definition: GUIAppEnum.h:277
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.
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.
void lock()
lock mutex
Definition: MFXMutex.cpp:86
GUIGlObject * myObject
The object to get the information from.
#define SUMOReal
Definition: config.h:214
Instance of a single line in a parameter window.
A Tracker shall be opened.
Definition: GUIAppEnum.h:279
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)
FXDEFMAP(GUIParameterTableWindow) GUIParameterTableWindowMap[]