Eclipse 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-2019 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 /****************************************************************************/
17 // The window that holds the table of an object's parameter
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
27 #include <fx.h>
30 #include <utils/common/ToString.h>
37 
38 
39 // ===========================================================================
40 // FOX callback mapping
41 // ===========================================================================
42 FXDEFMAP(GUIParameterTableWindow) GUIParameterTableWindowMap[] = {
43  FXMAPFUNC(SEL_COMMAND, MID_SIMSTEP, GUIParameterTableWindow::onSimStep),
44  FXMAPFUNC(SEL_SELECTED, MID_TABLE, GUIParameterTableWindow::onTableSelected),
45  FXMAPFUNC(SEL_DESELECTED, MID_TABLE, GUIParameterTableWindow::onTableDeselected),
46  FXMAPFUNC(SEL_RIGHTBUTTONPRESS, MID_TABLE, GUIParameterTableWindow::onRightButtonPress),
47 };
48 
49 FXIMPLEMENT(GUIParameterTableWindow, FXMainWindow, GUIParameterTableWindowMap, ARRAYNUMBER(GUIParameterTableWindowMap))
50 
51 
52 // ===========================================================================
53 // static value definitions
54 // ===========================================================================
56 std::vector<GUIParameterTableWindow*> GUIParameterTableWindow::myContainer;
57 
58 // ===========================================================================
59 // method definitions
60 // ===========================================================================
62  FXMainWindow(app.getApp(), (o.getFullName() + " Parameter").c_str(), nullptr, nullptr, DECOR_ALL, 20, 20, 500, (FXint)((noRows + numParams(&o)) * 20 + 60)),
63  myObject(&o),
64  myApplication(&app),
65  myCurrentPos(0) {
66  noRows += numParams(&o);
67  myTable = new FXTable(this, this, MID_TABLE, TABLE_COL_SIZABLE | TABLE_ROW_SIZABLE | LAYOUT_FILL_X | LAYOUT_FILL_Y);
68  myTable->setVisibleRows((FXint)(noRows + 1));
69  myTable->setVisibleColumns(3);
70  myTable->setTableSize((FXint)(noRows + 1), 3);
71  myTable->setBackColor(FXRGB(255, 255, 255));
72  myTable->setColumnText(0, "Name");
73  myTable->setColumnText(1, "Value");
74  myTable->setColumnText(2, "Dynamic");
75  myTable->getRowHeader()->setWidth(0);
76  FXHeader* header = myTable->getColumnHeader();
77  header->setItemJustify(0, JUSTIFY_CENTER_X);
78  header->setItemSize(0, 240);
79  header->setItemJustify(1, JUSTIFY_CENTER_X);
80  header->setItemSize(1, 120);
81  header->setItemJustify(2, JUSTIFY_CENTER_X);
82  header->setItemSize(2, 60);
84  myLock.lock();
86  myLock.unlock();
87  FXMutexLock locker(myGlobalContainerLock);
88  myContainer.push_back(this);
89  // Table cannot be editable
90  myTable->setEditable(FALSE);
91 }
92 
93 
96  myLock.lock();
97  for (std::vector<GUIParameterTableItemInterface*>::iterator i = myItems.begin(); i != myItems.end(); ++i) {
98  delete (*i);
99  }
100  if (myObject != nullptr) {
102  }
103  myLock.unlock();
104  FXMutexLock locker(myGlobalContainerLock);
105  std::vector<GUIParameterTableWindow*>::iterator i = std::find(myContainer.begin(), myContainer.end(), this);
106  if (i != myContainer.end()) {
107  myContainer.erase(i);
108  }
109 }
110 
111 
112 void
114  FXMutexLock locker(myLock);
115  myObject = nullptr;
116 }
117 
118 
119 long
120 GUIParameterTableWindow::onSimStep(FXObject*, FXSelector, void*) {
121  // table values are updated in GUINet::guiSimulationStep()
122  updateTable();
123  update();
124  return 1;
125 }
126 
127 
128 long
129 GUIParameterTableWindow::onTableSelected(FXObject*, FXSelector, void*) {
130  return 1;
131 }
132 
133 
134 long
135 GUIParameterTableWindow::onTableDeselected(FXObject*, FXSelector, void*) {
136  return 1;
137 }
138 
139 
140 long
141 GUIParameterTableWindow::onRightButtonPress(FXObject* sender, FXSelector sel, void* eventData) {
142  // check which value entry was pressed
143  myTable->onLeftBtnPress(sender, sel, eventData);
144  int row = myTable->getCurrentRow();
145  if (row == -1 || row >= (int)(myItems.size())) {
146  return 1;
147  }
149  if (!i->dynamic()) {
150  return 1;
151  }
152  if (myObject == nullptr) {
153  return 1;
154  }
155 
156  ValueSource<double>* doubleSource = i->getdoubleSourceCopy();
157  if (doubleSource != nullptr) {
159  new FXMenuCommand(p, "Open in new Tracker", nullptr, p, MID_OPENTRACKER);
160  // set geometry
161  p->setX(static_cast<FXEvent*>(eventData)->root_x);
162  p->setY(static_cast<FXEvent*>(eventData)->root_y);
163  p->create();
164  // show
165  p->show();
166  }
167  return 1;
168 }
169 
170 
171 void
172 GUIParameterTableWindow::mkItem(const char* name, bool dynamic, std::string value) {
174  myItems.push_back(i);
175 }
176 
177 
178 void
179 GUIParameterTableWindow::mkItem(const char* name, bool dynamic, double value) {
181  myItems.push_back(i);
182 }
183 
184 
185 void
186 GUIParameterTableWindow::mkItem(const char* name, bool dynamic, unsigned value) {
188  myItems.push_back(i);
189 }
190 
191 
192 void
193 GUIParameterTableWindow::mkItem(const char* name, bool dynamic, int value) {
195  myItems.push_back(i);
196 }
197 
198 
199 void
200 GUIParameterTableWindow::mkItem(const char* name, bool dynamic, long long int value) {
202  myItems.push_back(i);
203 }
204 
205 
206 void
208  FXMutexLock locker(myLock);
209  if (myObject == nullptr) {
210  return;
211  }
212  for (std::vector<GUIParameterTableItemInterface*>::iterator i = myItems.begin(); i != myItems.end(); i++) {
213  (*i)->update();
214  }
215 }
216 
217 
218 void
220  // add generic paramters if available
221  if (p == nullptr) {
222  p = dynamic_cast<const Parameterised*>(myObject);
223  }
224  if (p != nullptr) {
225  const std::map<std::string, std::string>& map = p->getParametersMap();
226  for (std::map<std::string, std::string>::const_iterator it = map.begin(); it != map.end(); ++it) {
227  mkItem(("param:" + it->first).c_str(), false, it->second);
228  }
229  }
230  myApplication->addChild(this);
231  create();
232  show();
233 }
234 
235 
236 int
238  const Parameterised* p = dynamic_cast<const Parameterised*>(obj);
239  return p != nullptr ? (int)p->getParametersMap().size() : 0;
240 }
241 
242 
243 /****************************************************************************/
244 
GUIGlObject.h
GUIParameterTableItemInterface
Interface to a single line in a parameter window.
Definition: GUIParameterTableItem.h:56
ToString.h
GUIParameterTableWindow
A window containing a gl-object's parameter.
Definition: GUIParameterTableWindow.h:62
GUIGlObject::removeParameterTable
void removeParameterTable(GUIParameterTableWindow *w)
Lets this object know a parameter window showing the object's values was closed.
Definition: GUIGlObject.cpp:293
GUIParameterTableItemInterface::dynamic
virtual bool dynamic() const =0
Returns the information whether the value changes over simulation time.
Parameterised
An upper class for objects with additional parameters.
Definition: Parameterised.h:42
GUIParam_PopupMenuInterface
A popup-menu for dynamic patameter table entries.
Definition: GUIParam_PopupMenu.h:47
GUIParameterTableWindow.h
GUIParameterTableWindow::myTable
FXTable * myTable
The table to display the information in.
Definition: GUIParameterTableWindow.h:222
MID_TABLE
@ MID_TABLE
The Table.
Definition: GUIAppEnum.h:454
GUIParameterTableWindow::myApplication
GUIMainWindow * myApplication
The main application window.
Definition: GUIParameterTableWindow.h:225
GUIParam_PopupMenu.h
GUIParameterTableItem.h
FXDEFMAP
FXDEFMAP(GUIParameterTableWindow) GUIParameterTableWindowMap[]
GUIIconSubSys::getIcon
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
Definition: GUIIconSubSys.cpp:609
GUIParameterTableWindow::myContainer
static std::vector< GUIParameterTableWindow * > myContainer
The container of items that shall be updated.
Definition: GUIParameterTableWindow.h:215
GUIParameterTableWindow::numParams
static int numParams(const GUIGlObject *obj)
returns the number of parameters if obj is Parameterised and 0 otherwise
Definition: GUIParameterTableWindow.cpp:237
ICON_APP_TABLE
@ ICON_APP_TABLE
Definition: GUIIcons.h:113
GUIParameterTableWindow::closeBuilding
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
Definition: GUIParameterTableWindow.cpp:219
GUIMainWindow.h
GUIAppEnum.h
Parameterised::getParametersMap
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
Definition: Parameterised.cpp:106
GUIParameterTableWindow::onRightButtonPress
long onRightButtonPress(FXObject *, FXSelector, void *)
Shows a popup.
Definition: GUIParameterTableWindow.cpp:141
Parameterised.h
GUIParameterTableWindow::mkItem
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
Definition: GUIParameterTableWindow.h:108
MID_SIMSTEP
@ MID_SIMSTEP
A Simulation step was performed.
Definition: GUIAppEnum.h:456
update
GUIMainWindow::removeChild
void removeChild(FXMainWindow *child)
Definition: GUIMainWindow.cpp:115
GUIParameterTableItemInterface::getName
virtual const std::string & getName() const =0
Returns the name of the value.
GUIParameterTableWindow::onTableDeselected
long onTableDeselected(FXObject *, FXSelector, void *)
Does nothing.
Definition: GUIParameterTableWindow.cpp:135
GUIGlObject
Definition: GUIGlObject.h:65
GUIParameterTableWindow::GUIParameterTableWindow
GUIParameterTableWindow(GUIMainWindow &app, GUIGlObject &o, int noRows)
Constructor.
Definition: GUIParameterTableWindow.cpp:61
GUIParameterTableItem
Instance of a single line in a parameter window.
Definition: GUIParameterTableItem.h:98
GUIIconSubSys.h
GUIParameterTableWindow::updateTable
void updateTable()
Updates the table.
Definition: GUIParameterTableWindow.cpp:207
GUIParameterTableWindow::onTableSelected
long onTableSelected(FXObject *, FXSelector, void *)
Does nothing.
Definition: GUIParameterTableWindow.cpp:129
GUIParameterTableWindow::myItems
std::vector< GUIParameterTableItemInterface * > myItems
The list of table rows.
Definition: GUIParameterTableWindow.h:228
GUIParameterTableWindow::myObject
GUIGlObject * myObject
The object to get the information from.
Definition: GUIParameterTableWindow.h:219
GUIMainWindow
Definition: GUIMainWindow.h:46
GUIParameterTableWindow::myLock
FXMutex myLock
A lock assuring save updates in case of object deletion.
Definition: GUIParameterTableWindow.h:234
config.h
GUIParameterTableWindow::myGlobalContainerLock
static FXMutex myGlobalContainerLock
The mutex used to avoid concurrent updates of the instance container.
Definition: GUIParameterTableWindow.h:212
ValueSource< double >
GUIGlObject::addParameterTable
void addParameterTable(GUIParameterTableWindow *w)
Definition: GUIGlObject.cpp:287
GUIParameterTableItemInterface::getdoubleSourceCopy
virtual ValueSource< double > * getdoubleSourceCopy() const =0
Returns a double-typed copy of the value-source.
GUIParameterTableWindow::onSimStep
long onSimStep(FXObject *, FXSelector, void *)
Updates the table due to a simulation step.
Definition: GUIParameterTableWindow.cpp:120
GUIMainWindow::addChild
void addChild(FXMainWindow *child)
Definition: GUIMainWindow.cpp:107
MID_OPENTRACKER
@ MID_OPENTRACKER
A Tracker shall be opened.
Definition: GUIAppEnum.h:458
GUIParameterTableWindow::removeObject
void removeObject(GUIGlObject *const o)
Lets this window know the object shown is being deleted.
Definition: GUIParameterTableWindow.cpp:113
GUIParameterTableWindow::myCurrentPos
unsigned myCurrentPos
The index of the next row to add - used while building.
Definition: GUIParameterTableWindow.h:231
GUIParameterTableWindow::~GUIParameterTableWindow
~GUIParameterTableWindow()
Destructor.
Definition: GUIParameterTableWindow.cpp:94