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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
18 // The window that holds the table of an object's parameter
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <string>
28 #include <fx.h>
31 #include <utils/common/ToString.h>
38 
39 
40 // ===========================================================================
41 // FOX callback mapping
42 // ===========================================================================
43 FXDEFMAP(GUIParameterTableWindow) GUIParameterTableWindowMap[] = {
44  FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUIParameterTableWindow::onSimStep),
45  FXMAPFUNC(SEL_SELECTED, MID_TABLE, GUIParameterTableWindow::onTableSelected),
46  FXMAPFUNC(SEL_DESELECTED, MID_TABLE, GUIParameterTableWindow::onTableDeselected),
47  FXMAPFUNC(SEL_RIGHTBUTTONPRESS, MID_TABLE, GUIParameterTableWindow::onRightButtonPress),
48 };
49 
50 FXIMPLEMENT(GUIParameterTableWindow, FXMainWindow, GUIParameterTableWindowMap, ARRAYNUMBER(GUIParameterTableWindowMap))
51 
52 
53 // ===========================================================================
54 // static value definitions
55 // ===========================================================================
57 std::vector<GUIParameterTableWindow*> GUIParameterTableWindow::myContainer;
58 
59 // ===========================================================================
60 // method definitions
61 // ===========================================================================
63  FXMainWindow(app.getApp(), (o.getFullName() + " Parameter").c_str(), nullptr, nullptr, DECOR_ALL, 20, 20, 500, (FXint)((noRows + numParams(&o)) * 20 + 60)),
64  myObject(&o),
65  myApplication(&app),
66  myCurrentPos(0) {
67  noRows += numParams(&o);
68  myTable = new FXTable(this, this, MID_TABLE, TABLE_COL_SIZABLE | TABLE_ROW_SIZABLE | LAYOUT_FILL_X | LAYOUT_FILL_Y);
69  myTable->setVisibleRows((FXint)(noRows + 1));
70  myTable->setVisibleColumns(3);
71  myTable->setTableSize((FXint)(noRows + 1), 3);
72  myTable->setBackColor(FXRGB(255, 255, 255));
73  myTable->setColumnText(0, "Name");
74  myTable->setColumnText(1, "Value");
75  myTable->setColumnText(2, "Dynamic");
76  myTable->getRowHeader()->setWidth(0);
77  FXHeader* header = myTable->getColumnHeader();
78  header->setItemJustify(0, JUSTIFY_CENTER_X);
79  header->setItemSize(0, 240);
80  header->setItemJustify(1, JUSTIFY_CENTER_X);
81  header->setItemSize(1, 120);
82  header->setItemJustify(2, JUSTIFY_CENTER_X);
83  header->setItemSize(2, 60);
85  myLock.lock();
87  myLock.unlock();
89  myContainer.push_back(this);
90  // Table cannot be editable
91  myTable->setEditable(FALSE);
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 != nullptr) {
103  }
104  myLock.unlock();
106  std::vector<GUIParameterTableWindow*>::iterator i = std::find(myContainer.begin(), myContainer.end(), this);
107  if (i != myContainer.end()) {
108  myContainer.erase(i);
109  }
110 }
111 
112 
113 void
116  myObject = nullptr;
117 }
118 
119 
120 long
121 GUIParameterTableWindow::onSimStep(FXObject*, FXSelector, void*) {
122  // table values are updated in GUINet::guiSimulationStep()
123  updateTable();
124  update();
125  return 1;
126 }
127 
128 
129 long
130 GUIParameterTableWindow::onTableSelected(FXObject*, FXSelector, void*) {
131  return 1;
132 }
133 
134 
135 long
136 GUIParameterTableWindow::onTableDeselected(FXObject*, FXSelector, void*) {
137  return 1;
138 }
139 
140 
141 long
142 GUIParameterTableWindow::onRightButtonPress(FXObject* sender, FXSelector sel, void* eventData) {
143  // check which value entry was pressed
144  myTable->onLeftBtnPress(sender, sel, eventData);
145  int row = myTable->getCurrentRow();
146  if (row == -1 || row >= (int)(myItems.size())) {
147  return 1;
148  }
150  if (!i->dynamic()) {
151  return 1;
152  }
153  if (myObject == nullptr) {
154  return 1;
155  }
156 
158  new FXMenuCommand(p, "Open in new Tracker", nullptr, p, MID_OPENTRACKER);
159  // set geometry
160  p->setX(static_cast<FXEvent*>(eventData)->root_x);
161  p->setY(static_cast<FXEvent*>(eventData)->root_y);
162  p->create();
163  // show
164  p->show();
165  return 1;
166 }
167 
168 
169 void
170 GUIParameterTableWindow::mkItem(const char* name, bool dynamic, std::string value) {
171  // T = double is only a dummy type here
173  myItems.push_back(i);
174 }
175 
176 
177 void
178 GUIParameterTableWindow::mkItem(const char* name, bool dynamic, double value) {
180  myItems.push_back(i);
181 }
182 
183 
184 void
185 GUIParameterTableWindow::mkItem(const char* name, bool dynamic, unsigned value) {
187  myItems.push_back(i);
188 }
189 
190 
191 void
192 GUIParameterTableWindow::mkItem(const char* name, bool dynamic, int value) {
194  myItems.push_back(i);
195 }
196 
197 
198 void
199 GUIParameterTableWindow::mkItem(const char* name, bool dynamic, long long int value) {
201  myItems.push_back(i);
202 }
203 
204 
205 void
208  if (myObject == nullptr) {
209  return;
210  }
211  for (std::vector<GUIParameterTableItemInterface*>::iterator i = myItems.begin(); i != myItems.end(); i++) {
212  (*i)->update();
213  }
214 }
215 
216 
217 void
219  // add generic paramters if available
220  if (p == nullptr) {
221  p = dynamic_cast<const Parameterised*>(myObject);
222  }
223  if (p != nullptr) {
224  const std::map<std::string, std::string>& map = p->getParametersMap();
225  for (std::map<std::string, std::string>::const_iterator it = map.begin(); it != map.end(); ++it) {
226  mkItem(("param:" + it->first).c_str(), false, it->second);
227  }
228  }
229  myApplication->addChild(this);
230  create();
231  show();
232 }
233 
234 
235 int
237  const Parameterised* p = dynamic_cast<const Parameterised*>(obj);
238  return p != nullptr ? (int)p->getParametersMap().size() : 0;
239 }
240 
241 
242 /****************************************************************************/
243 
A Tracker shall be opened.
Definition: GUIAppEnum.h:296
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.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
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.
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.
An upper class for objects with additional parameters.
Definition: Parameterised.h:44
long onSimStep(FXObject *, FXSelector, void *)
Updates the table due to a simulation step.
void unlock()
release mutex lock
Definition: MFXMutex.cpp:87
long onTableDeselected(FXObject *, FXSelector, void *)
Does nothing.
void removeChild(FXMainWindow *child)
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:59
virtual bool dynamic() const =0
Returns the information whether the value changes over simulation time.
A Simulation step was performed.
Definition: GUIAppEnum.h:294
virtual ValueSource< double > * getdoubleSourceCopy() const =0
Returns a double-typed copy of the value-source.
void lock()
lock mutex
Definition: MFXMutex.cpp:77
GUIGlObject * myObject
The object to get the information from.
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
Instance of a single line in a parameter window.
void addChild(FXMainWindow *child)
long onTableSelected(FXObject *, FXSelector, void *)
Does nothing.
std::vector< GUIParameterTableItemInterface * > myItems
The list of table rows.
A window containing a gl-object&#39;s parameter.
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
The Table.
Definition: GUIAppEnum.h:292
FXDEFMAP(GUIParameterTableWindow) GUIParameterTableWindowMap[]