Eclipse SUMO - Simulation of Urban MObility
GUIGlObject.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-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 /****************************************************************************/
18 // Base class for all objects that may be displayed within the openGL-gui
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <string>
28 #include <stack>
29 #include <utils/common/ToString.h>
39 #include <utils/gui/div/GLHelper.h>
41 #include "GUIGlObject.h"
42 #include "GUIGlObjectStorage.h"
43 
44 // ===========================================================================
45 // static members
46 // ===========================================================================
47 
49  {"network", GLO_NETWORK},
50  //
51  {"netElement", GLO_NETELEMENT},
52  {"edge", GLO_EDGE},
53  {"lane", GLO_LANE},
54  {"junction", GLO_JUNCTION},
55  {"crossing", GLO_CROSSING},
56  {"connection", GLO_CONNECTION},
57  {"tlLogic", GLO_TLLOGIC},
58  //
59  {"additional", GLO_ADDITIONAL},
60  {"busStop", GLO_BUS_STOP},
61  {"access", GLO_ACCESS},
62  {"taz", GLO_TAZ},
63  {"containerStop", GLO_CONTAINER_STOP},
64  {"chargingStation", GLO_CHARGING_STATION},
65  {"parkingArea", GLO_PARKING_AREA},
66  {"parkingSpace", GLO_PARKING_SPACE},
67  {"e1Detector", GLO_E1DETECTOR},
68  {"e1DetectorME", GLO_E1DETECTOR_ME},
69  {"e1DetectorInstant", GLO_E1DETECTOR_INSTANT},
70  {"e2Detector", GLO_E2DETECTOR},
71  {"e3Detector", GLO_E3DETECTOR},
72  {"entryDetector", GLO_DET_ENTRY},
73  {"exitDetector", GLO_DET_EXIT},
74  {"rerouter", GLO_REROUTER},
75  {"rerouterEdge", GLO_REROUTER_EDGE},
76  {"variableSpeedSign", GLO_VSS},
77  {"calibrator", GLO_CALIBRATOR},
78  {"routeProbe", GLO_ROUTEPROBE},
79  {"vaporizer", GLO_VAPORIZER},
80  //
81  {"shape", GLO_SHAPE},
82  {"polygon", GLO_POLYGON},
83  {"poi", GLO_POI},
84  //
85  {"routeElement", GLO_ROUTEELEMENT},
86  {"vType", GLO_VTYPE},
87  //
88  {"route", GLO_ROUTE},
89  {"embeddedRoute", GLO_EMBEDDEDROUTE},
90  //
91  {"ride", GLO_RIDE},
92  {"walk", GLO_WALK},
93  {"personTrip", GLO_PERSONTRIP},
94  //
95  {"stop", GLO_STOP},
96  {"personStop", GLO_PERSONSTOP},
97  //
98  {"vehicle", GLO_VEHICLE},
99  {"trip", GLO_TRIP},
100  {"flow", GLO_FLOW},
101  {"routeFlow", GLO_ROUTEFLOW},
102  //
103  {"container", GLO_CONTAINER},
104  //
105  {"person", GLO_PERSON},
106  {"personFlow", GLO_PERSONFLOW},
107  {"undefined", GLO_MAX}
108 };
109 
110 
111 StringBijection<GUIGlObjectType> GUIGlObject::TypeNames(GUIGlObjectTypeNamesInitializer, GLO_MAX);
113 
114 // ===========================================================================
115 // method definitionsas
116 // ===========================================================================
117 
118 GUIGlObject::GUIGlObject(GUIGlObjectType type, const std::string& microsimID) :
119  myGLObjectType(type),
120  myMicrosimID(microsimID) {
121  // make sure that reserved GLO_ADDITIONAL isn't used
122  assert(myGLObjectType != GLO_ADDITIONAL);
125 }
126 
127 
129  for (auto i : myParamWindows) {
130  i->removeObject(this);
131  }
134 }
135 
136 
137 const std::string&
139  return myFullName;
140 }
141 
142 
143 std::string
146 }
147 
148 
149 GUIGlID
151  return myGlID;
152 }
153 
154 
157  UNUSED_PARAMETER(&app);
158  UNUSED_PARAMETER(&parent);
159  return nullptr;
160 }
161 
162 
163 const std::string&
165  return myMicrosimID;
166 }
167 
168 const std::string
170  return "";
171 }
172 
173 void
174 GUIGlObject::setMicrosimID(const std::string& newID) {
175  myMicrosimID = newID;
177 }
178 
179 
182  return myGLObjectType;
183 }
184 
185 
186 void
188  UNUSED_PARAMETER(&s);
189  UNUSED_PARAMETER(parent);
190 }
191 
192 #ifdef HAVE_OSG
193 
194 osg::Node*
195 GUIGlObject::getNode() const {
196  return myOSGNode;
197 }
198 
199 
200 void
201 GUIGlObject::setNode(osg::Node* node) {
202  myOSGNode = node;
203 }
204 
205 #endif
206 
207 void
209  new MFXMenuHeader(ret, app.getBoldFont(), getFullName().c_str(), nullptr, nullptr, 0);
210  if (addSeparator) {
211  new FXMenuSeparator(ret);
212  }
213 }
214 
215 
216 void
218  new FXMenuCommand(ret, "Center", GUIIconSubSys::getIcon(ICON_RECENTERVIEW), ret, MID_CENTER);
219  if (addSeparator) {
220  new FXMenuSeparator(ret);
221  }
222 }
223 
224 
225 void
227  new FXMenuCommand(ret, "Copy name to clipboard", nullptr, ret, MID_COPY_NAME);
228  new FXMenuCommand(ret, "Copy typed name to clipboard", nullptr, ret, MID_COPY_TYPED_NAME);
229  if (addSeparator) {
230  new FXMenuSeparator(ret);
231  }
232 }
233 
234 
235 void
237  if (gSelected.isSelected(getType(), getGlID())) {
238  new FXMenuCommand(ret, "Remove From Selected", GUIIconSubSys::getIcon(ICON_FLAG_MINUS), ret, MID_REMOVESELECT);
239  } else {
240  new FXMenuCommand(ret, "Add To Selected", GUIIconSubSys::getIcon(ICON_FLAG_PLUS), ret, MID_ADDSELECT);
241  }
242  if (addSeparator) {
243  new FXMenuSeparator(ret);
244  }
245 }
246 
247 
248 void
250  new FXMenuCommand(ret, "Show Parameter", GUIIconSubSys::getIcon(ICON_APP_TABLE), ret, MID_SHOWPARS);
251  if (addSeparator) {
252  new FXMenuSeparator(ret);
253  }
254 }
255 
256 
257 void
259  new FXMenuCommand(ret, "Show Type Parameter", GUIIconSubSys::getIcon(ICON_APP_TABLE), ret, MID_SHOWTYPEPARS);
260  if (addSeparator) {
261  new FXMenuSeparator(ret);
262  }
263 }
264 
265 
266 void
268  new FXMenuCommand(ret, "Copy cursor position to clipboard", nullptr, ret, MID_COPY_CURSOR_POSITION);
269  if (GeoConvHelper::getFinal().usingGeoProjection()) {
270  new FXMenuCommand(ret, "Copy cursor geo-position to clipboard", nullptr, ret, MID_COPY_CURSOR_GEOPOSITION);
271  }
272  if (addSeparator) {
273  new FXMenuSeparator(ret);
274  }
275 }
276 
277 
278 void
280  new FXMenuCommand(ret, "Open Manipulator...", GUIIconSubSys::getIcon(ICON_MANIP), ret, MID_MANIP);
281  if (addSeparator) {
282  new FXMenuSeparator(ret);
283  }
284 }
285 
286 
287 void
289  myParamWindows.insert(t);
290 }
291 
292 
293 void
295  std::set<GUIParameterTableWindow*>::iterator i = myParamWindows.find(t);
296  if (i != myParamWindows.end()) {
297  myParamWindows.erase(i);
298  }
299 }
300 
301 
302 void
304  assert(ret);
305  // build header (<tag>:<ID>
306  buildPopupHeader(ret, app, false);
307  // build center
309  // build copy name
311  // build select/unselect
313  // build show parameters
314  buildShowParamsPopupEntry(ret, false);
315  // build copy cursor position to clipboard
316  buildPositionCopyEntry(ret, false);
317  // only show type if isn't empty
318  if (type != "") {
319  new FXMenuCommand(ret, ("type: " + type + "").c_str(), nullptr, nullptr, 0);
320  new FXMenuSeparator(ret);
321  }
322 }
323 
324 
325 void
327  assert(ret);
328  // build header (<tag>:<ID>
329  buildPopupHeader(ret, app, false);
330  // build center
332  // build copy name
334  // build select/unselect
336  // build show parameters
337  buildShowParamsPopupEntry(ret, false);
338  // build copy cursor position to clipboard
339  buildPositionCopyEntry(ret, false);
340  // only show type if isn't empty
341  if (type != "") {
342  new FXMenuCommand(ret, ("type: " + type + "").c_str(), nullptr, nullptr, 0);
343  new FXMenuSeparator(ret);
344  }
345 }
346 
347 
348 std::string
351 }
352 
353 
354 void
355 GUIGlObject::drawName(const Position& pos, const double scale, const GUIVisualizationTextSettings& settings, const double angle) const {
356  if (settings.show) {
357  GLHelper::drawTextSettings(settings, getMicrosimID(), pos, scale, angle);
358  }
359 }
360 
361 /****************************************************************************/
362 
a person stop
a containerStop
Copy object name - popup entry.
Definition: GUIAppEnum.h:369
a tl-logic
a person flow
void buildShapePopupOptions(GUIMainWindow &app, GUIGLObjectPopupMenu *ret, const std::string &type)
build basic shape popup options. Used to unify pop-ups menu in netedit and SUMO-GUI ...
Center view to object - popup entry.
Definition: GUIAppEnum.h:367
a polygon
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
GUIGlObjectType
Open the object&#39;s manipulator.
Definition: GUIAppEnum.h:399
a E2 detector
GUIGlID myGlID
The numerical id of the object.
Definition: GUIGlObject.h:243
a Variable Speed Sign
a chargingStation
Stores the information about how to visualize structures.
a connection
const std::string & getString(const T key) const
static void drawTextSettings(const GUIVisualizationTextSettings &settings, const std::string &text, const Position &pos, const double scale, const double angle=0, const double layer=2048)
Definition: GLHelper.cpp:701
bool remove(GUIGlID id)
Removes the named object from this container.
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
Remove from selected items - Menu Etry.
Definition: GUIAppEnum.h:397
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used, also builds an entry for copying the geo-position.
void buildShowTypeParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the type parameter window.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:32
reserved GLO type to pack shapes
a E3 detector
a person trip
void removeParameterTable(GUIParameterTableWindow *w)
Lets this object know a parameter window showing the object&#39;s values was closed.
Copy cursor geo-coordinate position - popup entry.
Definition: GUIAppEnum.h:377
Show object parameter - popup entry.
Definition: GUIAppEnum.h:381
virtual std::string getParentName() const
Returns the name of the parent object (if any)
a Vaporizer
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
a busStop
virtual GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window (optional)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
Copy cursor position - popup entry.
Definition: GUIAppEnum.h:375
std::string myMicrosimID
ID of GL object.
Definition: GUIGlObject.h:249
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
a tl-logic
virtual ~GUIGlObject()
Destructor.
void addParameterTable(GUIParameterTableWindow *w)
FXFont * getBoldFont()
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
a Rerouter
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
reserved GLO type to pack all RouteElements (note: In this case the sorting of GLO_<element> is impor...
a ParkingSpace
a Calibrator
a E1 detector
virtual const std::string getOptionalName() const
Returns the name of the object (default "")
static void removeObject(GUIGlObject &o)
Removes all instances that pass values from the object with the given id.
static std::string emptyString
An empty string.
Definition: StringUtils.h:79
const GUIGlObjectType myGLObjectType
The type of the object.
Definition: GUIGlObject.h:246
unsigned int GUIGlID
Definition: GUIGlObject.h:43
reserved GLO type to pack all additionals
void buildShowManipulatorPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the manipulator window.
a embedded route
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
a RouteProbe
a DetEntry detector
static StringBijection< GUIGlObjectType > TypeNames
associates object types with strings
Definition: GUIGlObject.h:69
a E1 detector
a routeFlow
static const GUIGlID INVALID_ID
Definition: GUIGlObject.h:70
The popup menu of a globject.
an edge
a ParkingArea
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
static StringBijection< GUIGlObjectType >::Entry GUIGlObjectTypeNamesInitializer[]
LinkStates (Currently unused)
Definition: GUIGlObject.h:269
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
The network - empty.
std::string myFullName
full name of GL Object
Definition: GUIGlObject.h:252
GUIGlID getGlID() const
Returns the numerical id of the object.
GUIGlID registerObject(GUIGlObject *object, const std::string &fullName)
Registers an object.
Show object type parameter - popup entry.
Definition: GUIAppEnum.h:383
empty max
GUIGlObject(GUIGlObjectType type, const std::string &microsimID)
Constructor.
const std::string & getFullName() const
Add to selected items - menu entry.
Definition: GUIAppEnum.h:395
std::set< GUIParameterTableWindow * > myParamWindows
Parameter table windows which refer to this object.
Definition: GUIGlObject.h:255
GUISelectedStorage gSelected
A global holder of selected objects.
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:371
void buildAdditionalsPopupOptions(GUIMainWindow &app, GUIGLObjectPopupMenu *ret, const std::string &type)
build basic additional popup options. Used to unify pop-ups menu in netedit and SUMO-GUI ...
A window containing a gl-object&#39;s parameter.
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
a DetExit detector
virtual void drawGLAdditional(GUISUMOAbstractView *const parent, const GUIVisualizationSettings &s) const
Draws additional, user-triggered visualisations.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
std::string createFullName() const
create full name
reserved GLO type to pack all netElements
a junction