SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
13 // Copyright (C) 2002-2014 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 // method definitions
65 // ===========================================================================
67  GUIGlObject& o, size_t noRows)
68  : FXMainWindow(app.getApp(), (o.getFullName() + " Parameter").c_str(),
69  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();
90  myObject->addParameterTable(this);
91  myLock.unlock();
92 }
93 
94 
97  myLock.lock();
98  for (std::vector<GUIParameterTableItemInterface*>::iterator i = myItems.begin(); i != myItems.end(); ++i) {
99  delete(*i);
100  }
101  if (myObject != 0) {
103  }
104  myLock.unlock();
105 }
106 
107 
108 void
111  myObject = 0;
112 }
113 
114 
115 long
117  updateTable();
118  update();
119  return 1;
120 }
121 
122 
123 long
125  return 1;
126 }
127 
128 
129 long
131  return 1;
132 }
133 
134 
135 long
137  FXSelector sel,
138  void* data) {
139  // check which value entry was pressed
140  myTable->onLeftBtnPress(sender, sel, data);
141  int row = myTable->getCurrentRow();
142  if (row == -1 || row >= (int)(myItems.size())) {
143  return 1;
144  }
146  if (!i->dynamic()) {
147  return 1;
148  }
149 
151  new FXMenuCommand(p, "Open in new Tracker", 0, p, MID_OPENTRACKER);
152  // set geometry
153  p->setX(static_cast<FXEvent*>(data)->root_x);
154  p->setY(static_cast<FXEvent*>(data)->root_y);
155  p->create();
156  // show
157  p->show();
158  return 1;
159 }
160 
161 
162 
163 void
164 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
165  ValueSource<unsigned>* src) {
167  myItems.push_back(i);
168 }
169 
170 
171 void
172 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
173  ValueSource<int>* src) {
175  myItems.push_back(i);
176 }
177 
178 
179 void
180 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
181  ValueSource<SUMOReal>* src) {
183  myItems.push_back(i);
184 }
185 
186 
187 void
188 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
189  std::string value) {
190  // T = SUMOReal is only a dummy type here
192  myItems.push_back(i);
193 }
194 
195 
196 void
197 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
198  SUMOReal value) {
200  myItems.push_back(i);
201 }
202 
203 
204 void
205 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
206  unsigned value) {
208  myItems.push_back(i);
209 }
210 
211 
212 void
213 GUIParameterTableWindow::mkItem(const char* name, bool dynamic,
214  int value) {
216  myItems.push_back(i);
217 }
218 
219 
220 void
223  if (myObject == 0) {
224  return;
225  }
226  for (std::vector<GUIParameterTableItemInterface*>::iterator i = myItems.begin(); i != myItems.end(); i++) {
227  (*i)->update();
228  }
229 }
230 
231 
232 void
234  myApplication->addChild(this, true);
235  create();
236  show();
237 }
238 
239 
240 
241 /****************************************************************************/
242 
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:265
A Simulation step was performed.
Definition: GUIAppEnum.h:263
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's values was closed.
void addChild(FXMDIChild *child, bool updateOnSimStep=true)
Adds a further child window to the list.
The Table.
Definition: GUIAppEnum.h:261
virtual ValueSource< SUMOReal > * getSUMORealSourceCopy() const =0
Returns a SUMOReal-typed copy of the value-source.
Interface to a single line in a parameter window.
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 cse 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:215
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's parameter.
static FXIcon * getIcon(GUIIcon which)
FXDEFMAP(GUIParameterTableWindow) GUIParameterTableWindowMap[]