SUMO - Simulation of Urban MObility
GUIParameterTableWindow.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // The window that holds the table of an object's parameter
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <fx.h>
37 #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 + numParams(&o)) * 20 + 60)),
70  myObject(&o),
71  myApplication(&app),
72  myCurrentPos(0) {
73  noRows += numParams(&o);
74  myTable = new FXTable(this, this, MID_TABLE, TABLE_COL_SIZABLE | TABLE_ROW_SIZABLE | LAYOUT_FILL_X | LAYOUT_FILL_Y);
75  myTable->setVisibleRows((FXint)(noRows + 1));
76  myTable->setVisibleColumns(3);
77  myTable->setTableSize((FXint)(noRows + 1), 3);
78  myTable->setBackColor(FXRGB(255, 255, 255));
79  myTable->setColumnText(0, "Name");
80  myTable->setColumnText(1, "Value");
81  myTable->setColumnText(2, "Dynamic");
82  myTable->getRowHeader()->setWidth(0);
83  FXHeader* header = myTable->getColumnHeader();
84  header->setItemJustify(0, JUSTIFY_CENTER_X);
85  header->setItemSize(0, 240);
86  header->setItemJustify(1, JUSTIFY_CENTER_X);
87  header->setItemSize(1, 120);
88  header->setItemJustify(2, JUSTIFY_CENTER_X);
89  header->setItemSize(2, 60);
91  myLock.lock();
93  myLock.unlock();
95  myContainer.push_back(this);
96  // Table cannot be editable
97  myTable->setEditable(FALSE);
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
148 GUIParameterTableWindow::onRightButtonPress(FXObject* sender, FXSelector sel, void* eventData) {
149  // check which value entry was pressed
150  myTable->onLeftBtnPress(sender, sel, eventData);
151  int row = myTable->getCurrentRow();
152  if (row == -1 || row >= (int)(myItems.size())) {
153  return 1;
154  }
156  if (!i->dynamic()) {
157  return 1;
158  }
159  if (myObject == 0) {
160  return 1;
161  }
162 
164  new FXMenuCommand(p, "Open in new Tracker", 0, p, MID_OPENTRACKER);
165  // set geometry
166  p->setX(static_cast<FXEvent*>(eventData)->root_x);
167  p->setY(static_cast<FXEvent*>(eventData)->root_y);
168  p->create();
169  // show
170  p->show();
171  return 1;
172 }
173 
174 
175 void
176 GUIParameterTableWindow::mkItem(const char* name, bool dynamic, ValueSource<unsigned>* src) {
178  myItems.push_back(i);
179 }
180 
181 
182 void
183 GUIParameterTableWindow::mkItem(const char* name, bool dynamic, ValueSource<int>* src) {
185  myItems.push_back(i);
186 }
187 
188 
189 void
190 GUIParameterTableWindow::mkItem(const char* name, bool dynamic, ValueSource<double>* src) {
192  myItems.push_back(i);
193 }
194 
195 
196 void
197 GUIParameterTableWindow::mkItem(const char* name, bool dynamic, std::string value) {
198  // T = double is only a dummy type here
200  myItems.push_back(i);
201 }
202 
203 
204 void
205 GUIParameterTableWindow::mkItem(const char* name, bool dynamic, double value) {
207  myItems.push_back(i);
208 }
209 
210 
211 void
212 GUIParameterTableWindow::mkItem(const char* name, bool dynamic, unsigned value) {
214  myItems.push_back(i);
215 }
216 
217 
218 void
219 GUIParameterTableWindow::mkItem(const char* name, bool dynamic, int value) {
221  myItems.push_back(i);
222 }
223 
224 
225 void
226 GUIParameterTableWindow::mkItem(const char* name, bool dynamic, long long int value) {
228  myItems.push_back(i);
229 }
230 
231 
232 void
235  if (myObject == 0) {
236  return;
237  }
238  for (std::vector<GUIParameterTableItemInterface*>::iterator i = myItems.begin(); i != myItems.end(); i++) {
239  (*i)->update();
240  }
241 }
242 
243 
244 void
246  // add generic paramters if available
247  if (p == 0) {
248  p = dynamic_cast<const Parameterised*>(myObject);
249  }
250  if (p != 0) {
251  const std::map<std::string, std::string>& map = p->getMap();
252  for (std::map<std::string, std::string>::const_iterator it = map.begin(); it != map.end(); ++it) {
253  mkItem(("param:" + it->first).c_str(), false, it->second);
254  }
255  }
256  myApplication->addChild(this, true);
257  create();
258  show();
259 }
260 
261 
262 int
264  const Parameterised* p = dynamic_cast<const Parameterised*>(obj);
265  return p != 0 ? (int)p->getMap().size() : 0;
266 }
267 
268 
269 /****************************************************************************/
270 
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.
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.
static int numParams(const GUIGlObject *obj)
returns the number of parameters if obj is Parameterised and 0 otherwise
void addParameterTable(GUIParameterTableWindow *w)
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:50
long onSimStep(FXObject *, FXSelector, void *)
Updates the table due to a simulation step.
void unlock()
release mutex lock
Definition: MFXMutex.cpp:93
A Tracker shall be opened.
Definition: GUIAppEnum.h:292
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:70
const std::map< std::string, std::string > & getMap() const
Returns the inner key/value map.
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:83
GUIGlObject * myObject
The object to get the information from.
A Simulation step was performed.
Definition: GUIAppEnum.h:290
Instance of a single line in a parameter window.
The Table.
Definition: GUIAppEnum.h:288
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[]