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>
45 
46 
47 // ===========================================================================
48 // FOX callback mapping
49 // ===========================================================================
50 FXDEFMAP(GUIParameterTableWindow) GUIParameterTableWindowMap[] = {
51  FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUIParameterTableWindow::onSimStep),
52  FXMAPFUNC(SEL_SELECTED, MID_TABLE, GUIParameterTableWindow::onTableSelected),
53  FXMAPFUNC(SEL_DESELECTED, MID_TABLE, GUIParameterTableWindow::onTableDeselected),
54  FXMAPFUNC(SEL_RIGHTBUTTONPRESS, MID_TABLE, GUIParameterTableWindow::onRightButtonPress),
55 };
56 
57 FXIMPLEMENT(GUIParameterTableWindow, FXMainWindow, GUIParameterTableWindowMap, ARRAYNUMBER(GUIParameterTableWindowMap))
58 
59 
60 // ===========================================================================
61 // static value definitions
62 // ===========================================================================
63 MFXMutex GUIParameterTableWindow::myGlobalContainerLock;
64 std::vector<GUIParameterTableWindow*> GUIParameterTableWindow::myContainer;
65 
66 // ===========================================================================
67 // method definitions
68 // ===========================================================================
70  FXMainWindow(app.getApp(), (o.getFullName() + " Parameter").c_str(), NULL, NULL, DECOR_ALL, 20, 20, 500, (FXint)((noRows + numParams(&o)) * 20 + 60)),
71  myObject(&o),
72  myApplication(&app),
73  myCurrentPos(0) {
74  noRows += numParams(&o);
75  myTable = new FXTable(this, this, MID_TABLE, TABLE_COL_SIZABLE | TABLE_ROW_SIZABLE | LAYOUT_FILL_X | LAYOUT_FILL_Y);
76  myTable->setVisibleRows((FXint)(noRows + 1));
77  myTable->setVisibleColumns(3);
78  myTable->setTableSize((FXint)(noRows + 1), 3);
79  myTable->setBackColor(FXRGB(255, 255, 255));
80  myTable->setColumnText(0, "Name");
81  myTable->setColumnText(1, "Value");
82  myTable->setColumnText(2, "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);
92  myLock.lock();
93  myObject->addParameterTable(this);
94  myLock.unlock();
95  AbstractMutex::ScopedLocker locker(myGlobalContainerLock);
96  myContainer.push_back(this);
97 }
98 
99 
101  myApplication->removeChild(this);
102  myLock.lock();
103  for (std::vector<GUIParameterTableItemInterface*>::iterator i = myItems.begin(); i != myItems.end(); ++i) {
104  delete(*i);
105  }
106  if (myObject != 0) {
108  }
109  myLock.unlock();
111  std::vector<GUIParameterTableWindow*>::iterator i = std::find(myContainer.begin(), myContainer.end(), this);
112  if (i != myContainer.end()) {
113  myContainer.erase(i);
114  }
115 }
116 
117 
118 void
121  myObject = 0;
122 }
123 
124 
125 long
126 GUIParameterTableWindow::onSimStep(FXObject*, FXSelector, void*) {
127  // table values are updated in GUINet::guiSimulationStep()
128  updateTable();
129  update();
130  return 1;
131 }
132 
133 
134 long
135 GUIParameterTableWindow::onTableSelected(FXObject*, FXSelector, void*) {
136  return 1;
137 }
138 
139 
140 long
141 GUIParameterTableWindow::onTableDeselected(FXObject*, FXSelector, void*) {
142  return 1;
143 }
144 
145 
146 long
148  FXSelector sel,
149  void* data) {
150  // check which value entry was pressed
151  myTable->onLeftBtnPress(sender, sel, data);
152  int row = myTable->getCurrentRow();
153  if (row == -1 || row >= (int)(myItems.size())) {
154  return 1;
155  }
157  if (!i->dynamic()) {
158  return 1;
159  }
160  if (myObject == 0) {
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<double>* 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 = double 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  double 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  // add generic paramters if available
257  if (p == 0) {
258  p = dynamic_cast<const Parameterised*>(myObject);
259  }
260  if (p != 0) {
261  const std::map<std::string, std::string>& map = p->getMap();
262  for (std::map<std::string, std::string>::const_iterator it = map.begin(); it != map.end(); ++it) {
263  mkItem(("param:" + it->first).c_str(), false, it->second);
264  }
265  }
266  myApplication->addChild(this, true);
267  create();
268  show();
269 }
270 
271 int
273  const Parameterised* p = dynamic_cast<const Parameterised*>(obj);
274  return p != 0 ? (int)p->getMap().size() : 0;
275 }
276 
277 
278 /****************************************************************************/
279 
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
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.
const std::map< std::string, std::string > & getMap() const
Returns the inner key/value map.
A popup-menu for dynamic patameter table entries.
GUIMainWindow * myApplication
The main application window.
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 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
static int numParams(const GUIGlObject *obj)
returns the number of parameters if obj is Parameterised and 0 otherwise
virtual const std::string & getName() const =0
Returns the name of the value.
A Simulation step was performed.
Definition: GUIAppEnum.h:293
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
An upper class for objects with additional parameters.
Definition: Parameterised.h:51
long onSimStep(FXObject *, FXSelector, void *)
Updates the table due to a simulation step.
void unlock()
release mutex lock
Definition: MFXMutex.cpp:94
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
void lock()
lock mutex
Definition: MFXMutex.cpp:84
GUIGlObject * myObject
The object to get the information from.
Instance of a single line in a parameter window.
A Tracker shall be opened.
Definition: GUIAppEnum.h:295
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.
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[]