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-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
21 // Base class for all objects that may be displayed within the openGL-gui
22 /****************************************************************************/
23 #include <config.h>
24 
25 #include <string>
26 #include <stack>
27 #include <utils/common/ToString.h>
37 #include <utils/gui/div/GLHelper.h>
40 
41 #include "GUIGlObject.h"
42 #include "GUIGlObjectStorage.h"
43 
44 // ===========================================================================
45 // static members
46 // ===========================================================================
47 
49  {"network", GLO_NETWORK},
50  //
51  {"networkElement", GLO_NETWORKELEMENT},
52  {"edge", GLO_EDGE},
53  {"lane", GLO_LANE},
54  {"junction", GLO_JUNCTION},
55  {"connection", GLO_CONNECTION},
56  {"crossing", GLO_CROSSING},
57  {"tlLogic", GLO_TLLOGIC},
58  {"type", GLO_TYPE},
59  //
60  {"parentChildLine", GLO_PARENTCHILDLINE},
61  //
62  {"additional", GLO_ADDITIONALELEMENT},
63  {"busStop", GLO_BUS_STOP},
64  {"access", GLO_ACCESS},
65  {"taz", GLO_TAZ},
66  {"containerStop", GLO_CONTAINER_STOP},
67  {"chargingStation", GLO_CHARGING_STATION},
68  {"overheadWireSegment", GLO_OVERHEAD_WIRE_SEGMENT},
69  {"parkingArea", GLO_PARKING_AREA},
70  {"parkingSpace", GLO_PARKING_SPACE},
71  {"e1Detector", GLO_E1DETECTOR},
72  {"e1DetectorME", GLO_E1DETECTOR_ME},
73  {"e1DetectorInstant", GLO_E1DETECTOR_INSTANT},
74  {"e2Detector", GLO_E2DETECTOR},
75  {"e3Detector", GLO_E3DETECTOR},
76  {"entryDetector", GLO_DET_ENTRY},
77  {"exitDetector", GLO_DET_EXIT},
78  {"rerouter", GLO_REROUTER},
79  {"rerouterInterval", GLO_REROUTER_INTERVAL},
80  {"closingreroute", GLO_REROUTER_CLOSINGREROUTE},
81  {"closingLaneReroute", GLO_REROUTER_CLOSINGLANEREROUTE},
82  {"parkingAreaReroute", GLO_REROUTER_PARKINGAREAREROUTE},
83  {"destProbReroute", GLO_REROUTER_DESTPROBREROUTE},
84  {"routeProbReroute", GLO_REROUTER_ROUTEPROBREROUTE},
85  {"rerouterEdge", GLO_REROUTER_EDGE},
86  {"variableSpeedSign", GLO_VSS},
87  {"variableSpeedSignStep", GLO_VSS_STEP},
88  {"calibrator", GLO_CALIBRATOR},
89  {"routeProbe", GLO_ROUTEPROBE},
90  {"vaporizer", GLO_VAPORIZER},
91  //
92  {"shape", GLO_SHAPE},
93  {"polygon", GLO_POLYGON},
94  {"poi", GLO_POI},
95  //
96  {"routeElement", GLO_ROUTEELEMENT},
97  {"vType", GLO_VTYPE},
98  //
99  {"route", GLO_ROUTE},
100  //
101  {"ride", GLO_RIDE},
102  {"walk", GLO_WALK},
103  {"personTrip", GLO_PERSONTRIP},
104  {"transport", GLO_TRANSPORT},
105  {"tranship", GLO_TRANSHIP},
106  //
107  {"stop", GLO_STOP},
108  {"stopPerson", GLO_STOP_PERSON},
109  {"stopContainer", GLO_STOP_CONTAINER},
110  //
111  {"vehicle", GLO_VEHICLE},
112  {"trip", GLO_TRIP},
113  {"flow", GLO_FLOW},
114  {"routeFlow", GLO_ROUTEFLOW},
115  //
116  {"container", GLO_CONTAINER},
117  {"containerFlow", GLO_CONTAINERFLOW},
118  //
119  {"person", GLO_PERSON},
120  {"personFlow", GLO_PERSONFLOW},
121  //
122  {"edgeData", GLO_EDGEDATA},
123  {"edgeRelData", GLO_EDGERELDATA},
124  {"TAZRelData", GLO_TAZRELDATA},
125  //
126  {"lockIcon", GLO_LOCKICON},
127  {"textName", GLO_TEXTNAME},
128  {"frontElement", GLO_DOTTEDCONTOUR_FRONT},
129  {"dottedContour", GLO_DOTTEDCONTOUR_INSPECTED},
130  {"temporalShape", GLO_TEMPORALSHAPE},
131  {"rectangleSelection", GLO_RECTANGLESELECTION},
132  {"testElement", GLO_TESTELEMENT},
133  //
134  {"undefined", GLO_MAX}
135 };
136 
137 
138 StringBijection<GUIGlObjectType> GUIGlObject::TypeNames(GUIGlObjectTypeNamesInitializer, GLO_MAX);
140 
141 // ===========================================================================
142 // method definitionsas
143 // ===========================================================================
144 
145 GUIGlObject::GUIGlObject(GUIGlObjectType type, const std::string& microsimID) :
146  myGLObjectType(type),
147  myMicrosimID(microsimID) {
148  // make sure that reserved GLO_ADDITIONALELEMENT isn't used
151  // register object
153 }
154 
155 
157  // remove all paramWindow related with this object
158  for (const auto& paramWindow : myParamWindows) {
159  paramWindow->removeObject(this);
160  }
161  // remove object from GLObjectValuePassConnector and GUIGlObjectStorage
164 }
165 
166 
167 const std::string&
169  return myFullName;
170 }
171 
172 
173 std::string
176 }
177 
178 
179 GUIGlID
181  return myGlID;
182 }
183 
184 
187  UNUSED_PARAMETER(&app);
188  UNUSED_PARAMETER(&parent);
189  return nullptr;
190 }
191 
192 
193 const std::string&
195  return myMicrosimID;
196 }
197 
198 const std::string
200  return "";
201 }
202 
203 void
204 GUIGlObject::setMicrosimID(const std::string& newID) {
205  // first remove objects from GUIGlObjectStorage
207  // set new microsimID and fullName
208  myMicrosimID = newID;
210  // register object again
212 }
213 
214 
217  return myGLObjectType;
218 }
219 
220 
221 void
223  UNUSED_PARAMETER(&s);
224  UNUSED_PARAMETER(parent);
225 }
226 
227 #ifdef HAVE_OSG
228 
229 osg::Node*
230 GUIGlObject::getNode() const {
231  return myOSGNode;
232 }
233 
234 
235 void
236 GUIGlObject::setNode(osg::Node* node) {
237  myOSGNode = node;
238 }
239 
240 #endif
241 
242 void
244  new MFXMenuHeader(ret, app.getBoldFont(), getFullName().c_str(), nullptr, nullptr, 0);
245  if (addSeparator) {
246  new FXMenuSeparator(ret);
247  }
248 }
249 
250 
251 void
254  if (addSeparator) {
255  new FXMenuSeparator(ret);
256  }
257 }
258 
259 
260 void
262  GUIDesigns::buildFXMenuCommand(ret, "Copy name to clipboard", nullptr, ret, MID_COPY_NAME);
263  GUIDesigns::buildFXMenuCommand(ret, "Copy typed name to clipboard", nullptr, ret, MID_COPY_TYPED_NAME);
264  if (addSeparator) {
265  new FXMenuSeparator(ret);
266  }
267 }
268 
269 
270 void
272  if (gSelected.isSelected(getType(), getGlID())) {
274  } else {
276  }
277  if (addSeparator) {
278  new FXMenuSeparator(ret);
279  }
280 }
281 
282 
283 void
286  if (addSeparator) {
287  new FXMenuSeparator(ret);
288  }
289 }
290 
291 
292 void
295  if (addSeparator) {
296  new FXMenuSeparator(ret);
297  }
298 }
299 
300 
301 void
303  GUIDesigns::buildFXMenuCommand(ret, "Copy cursor position to clipboard", nullptr, ret, MID_COPY_CURSOR_POSITION);
304  if (GeoConvHelper::getFinal().usingGeoProjection()) {
305  GUIDesigns::buildFXMenuCommand(ret, "Copy cursor geo-position to clipboard", nullptr, ret, MID_COPY_CURSOR_GEOPOSITION);
306  GUIDesigns::buildFXMenuCommand(ret, "Show cursor geo-position in GeoHack", nullptr, ret, MID_SHOW_GEOPOSITION_ONLINE);
307  }
308  if (addSeparator) {
309  new FXMenuSeparator(ret);
310  }
311 }
312 
313 
314 void
317  if (addSeparator) {
318  new FXMenuSeparator(ret);
319  }
320 }
321 
322 
323 void
325  myParamWindows.insert(t);
326 }
327 
328 
329 void
331  std::set<GUIParameterTableWindow*>::iterator i = myParamWindows.find(t);
332  if (i != myParamWindows.end()) {
333  myParamWindows.erase(i);
334  }
335 }
336 
337 
338 void
340  assert(ret);
341  // build header (<tag>:<ID>
342  buildPopupHeader(ret, app, false);
343  // build center
345  // build copy name
347  // build select/unselect
349  // build show parameters
350  buildShowParamsPopupEntry(ret, false);
351  // build copy cursor position to clipboard
352  buildPositionCopyEntry(ret, false);
353  // only show type if isn't empty
354  if (type != "") {
355  GUIDesigns::buildFXMenuCommand(ret, ("type: " + type + "").c_str(), nullptr, nullptr, 0);
356  new FXMenuSeparator(ret);
357  }
358 }
359 
360 
361 void
363  assert(ret);
364  // build header (<tag>:<ID>
365  buildPopupHeader(ret, app, false);
366  // build center
368  // build copy name
370  // build select/unselect
372  // build show parameters
373  buildShowParamsPopupEntry(ret, false);
374  // build copy cursor position to clipboard
375  buildPositionCopyEntry(ret, false);
376  // only show type if isn't empty
377  if (type != "") {
378  GUIDesigns::buildFXMenuCommand(ret, ("type: " + type + "").c_str(), nullptr, nullptr, 0);
379  new FXMenuSeparator(ret);
380  }
381 }
382 
383 
384 std::string
387 }
388 
389 
390 void
391 GUIGlObject::drawName(const Position& pos, const double scale, const GUIVisualizationTextSettings& settings, const double angle, bool forceShow) const {
392  if (settings.show(this) || forceShow) {
393  GLHelper::drawTextSettings(settings, getMicrosimID(), pos, scale, angle);
394  }
395 }
396 
397 
398 /****************************************************************************/
@ MID_MANIP
Open the object's manipulator.
Definition: GUIAppEnum.h:443
@ MID_ADDSELECT
Add to selected items - menu entry.
Definition: GUIAppEnum.h:439
@ MID_COPY_CURSOR_GEOPOSITION
Copy cursor geo-coordinate position - popup entry.
Definition: GUIAppEnum.h:419
@ MID_CENTER
Center view to object - popup entry.
Definition: GUIAppEnum.h:409
@ MID_SHOW_GEOPOSITION_ONLINE
Show the cursor geo-coordinate position online in GeoHack - popup entry.
Definition: GUIAppEnum.h:421
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:413
@ MID_COPY_CURSOR_POSITION
Copy cursor position - popup entry.
Definition: GUIAppEnum.h:417
@ MID_SHOWPARS
Show object parameter - popup entry.
Definition: GUIAppEnum.h:425
@ MID_COPY_NAME
Copy object name - popup entry.
Definition: GUIAppEnum.h:411
@ MID_SHOWTYPEPARS
Show object type parameter - popup entry.
Definition: GUIAppEnum.h:427
@ MID_REMOVESELECT
Remove from selected items - Menu Etry.
Definition: GUIAppEnum.h:441
unsigned int GUIGlID
Definition: GUIGlObject.h:40
GUIGlObjectType
@ GLO_EDGERELDATA
edge relation data
@ GLO_DET_EXIT
a DetExit detector
@ GLO_TAZRELDATA
TAZ relation data.
@ GLO_TEMPORALSHAPE
temporal shape (used in NETEDIT)
@ GLO_STOP_CONTAINER
a container stop
@ GLO_VTYPE
@bief vTypes
@ GLO_ROUTEELEMENT
reserved GLO type to pack all RouteElements (note: In this case the sorting of GLO_<element> is impor...
@ GLO_REROUTER_EDGE
a Rerouter over edge
@ GLO_TRIP
a trip
@ GLO_BUS_STOP
a busStop
@ GLO_REROUTER_DESTPROBREROUTE
a destiny probability reroute
@ GLO_TESTELEMENT
test element (used in NETEDIT)
@ GLO_DOTTEDCONTOUR_INSPECTED
dotted contour inspected element (used in NETEDIT)
@ GLO_E2DETECTOR
a E2 detector
@ GLO_DET_ENTRY
a DetEntry detector
@ GLO_TRANSHIP
a container tranship
@ GLO_ROUTEPROBE
a RouteProbe
@ GLO_E1DETECTOR
a E1 detector
@ GLO_ACCESS
a Acces
@ GLO_DOTTEDCONTOUR_FRONT
dotted contour front element (used in NETEDIT)
@ GLO_VAPORIZER
a Vaporizer
@ GLO_ROUTEFLOW
a routeFlow
@ GLO_WALK
a walk
@ GLO_CONTAINER_STOP
a containerStop
@ GLO_MAX
empty max
@ GLO_ROUTE
a route
@ GLO_CALIBRATOR
a Calibrator
@ GLO_JUNCTION
a junction
@ GLO_E3DETECTOR
a E3 detector
@ GLO_LANE
a lane
@ GLO_RIDE
a ride
@ GLO_FLOW
a flow
@ GLO_TYPE
an edge_type
@ GLO_CHARGING_STATION
a chargingStation
@ GLO_PARKING_AREA
a ParkingArea
@ GLO_VSS_STEP
a Variable Speed Sign step
@ GLO_TAZ
Traffic Assignment Zones (TAZs)
@ GLO_CONTAINER
a container
@ GLO_PARENTCHILDLINE
line between parent and childrens
@ GLO_EDGEDATA
edge data
@ GLO_CONNECTION
a connection
@ GLO_REROUTER_PARKINGAREAREROUTE
a parking area reroute
@ GLO_ADDITIONALELEMENT
reserved GLO type to pack all additionals elements
@ GLO_PERSONTRIP
a person trip
@ GLO_EDGE
an edge
@ GLO_VEHICLE
a vehicle
@ GLO_PERSON
a person
@ GLO_TRANSPORT
a container transport
@ GLO_STOP_PERSON
a person stop
@ GLO_NETWORK
The network - empty.
@ GLO_SHAPE
reserved GLO type to pack shapes
@ GLO_POI
a poi
@ GLO_REROUTER_CLOSINGLANEREROUTE
a closing lane reroute
@ GLO_RECTANGLESELECTION
rectangle selection shape (used in NETEDIT)
@ GLO_STOP
a stop
@ GLO_OVERHEAD_WIRE_SEGMENT
a segment of an overhead line
@ GLO_TEXTNAME
text element (used in NETEDIT)
@ GLO_NETWORKELEMENT
reserved GLO type to pack all network elements
@ GLO_REROUTER_CLOSINGREROUTE
a closing reroute
@ GLO_PARKING_SPACE
a ParkingSpace
@ GLO_CONTAINERFLOW
a person flow
@ GLO_POLYGON
a polygon
@ GLO_TLLOGIC
a tl-logic
@ GLO_E1DETECTOR_ME
a E1 detector
@ GLO_CROSSING
a tl-logic
@ GLO_REROUTER
a Rerouter
@ GLO_PERSONFLOW
a person flow
@ GLO_E1DETECTOR_INSTANT
a E1 detector
@ GLO_REROUTER_INTERVAL
a rerouter interval
@ GLO_REROUTER_ROUTEPROBREROUTE
a route probability reroute
@ GLO_VSS
a Variable Speed Sign
@ GLO_LOCKICON
Lock icon (used in NETEDIT)
GUISelectedStorage gSelected
A global holder of selected objects.
@ RECENTERVIEW
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:30
static void drawTextSettings(const GUIVisualizationTextSettings &settings, const std::string &text, const Position &pos, const double scale, const double angle=0, const double layer=2048, const int align=0)
Definition: GLHelper.cpp:640
static void removeObject(GUIGlObject &o)
Removes all instances that pass values from the object with the given id.
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel)
build menu command
Definition: GUIDesigns.cpp:42
The popup menu of a globject.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used,...
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
std::string myMicrosimID
ID of GL object.
Definition: GUIGlObject.h:259
std::string myFullName
full name of GL Object
Definition: GUIGlObject.h:262
void buildShowTypeParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the type parameter window.
void buildShowManipulatorPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the manipulator window.
const GUIGlObjectType myGLObjectType
The type of the object.
Definition: GUIGlObject.h:256
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
virtual GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window (optional)
virtual const std::string getOptionalName() const
Returns the name of the object (default "")
static const GUIGlID INVALID_ID
Definition: GUIGlObject.h:67
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
static StringBijection< GUIGlObjectType >::Entry GUIGlObjectTypeNamesInitializer[]
LinkStates (Currently unused)
Definition: GUIGlObject.h:279
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
const std::string & getFullName() const
GUIGlID myGlID
The numerical id of the object.
Definition: GUIGlObject.h:253
virtual std::string getParentName() const
Returns the name of the parent object (if any)
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
void addParameterTable(GUIParameterTableWindow *w)
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
static StringBijection< GUIGlObjectType > TypeNames
associates object types with strings
Definition: GUIGlObject.h:66
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
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
virtual ~GUIGlObject()
Destructor.
void removeParameterTable(GUIParameterTableWindow *w)
Lets this object know a parameter window showing the object's values was closed.
virtual void drawGLAdditional(GUISUMOAbstractView *const parent, const GUIVisualizationSettings &s) const
Draws additional, user-triggered visualisations.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
GUIGlObject(GUIGlObjectType type, const std::string &microsimID)
Constructor.
GUIGlID getGlID() const
Returns the numerical id of the object.
std::string createFullName() const
create full name
std::set< GUIParameterTableWindow * > myParamWindows
Parameter table windows which refer to this object.
Definition: GUIGlObject.h:265
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0, bool forceShow=false) const
draw name of item
GUIGlID registerObject(GUIGlObject *object, const std::string &fullName)
Registers an object.
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
bool remove(GUIGlID id)
Removes the named object from this container.
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
FXFont * getBoldFont()
get bold front
A window containing a gl-object's parameter.
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
Stores the information about how to visualize structures.
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
const std::string & getString(const T key) const
static std::string emptyString
An empty string.
Definition: StringUtils.h:84
bool show(const GUIGlObject *o) const
whether to show the text