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-2020 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  {"edgeData", GLO_EDGEDATA},
61  {"edgeRelData", GLO_EDGERELDATA},
62  {"TAZRelData", GLO_TAZRELDATA},
63  //
64  {"additional", GLO_ADDITIONALELEMENT},
65  {"busStop", GLO_BUS_STOP},
66  {"access", GLO_ACCESS},
67  {"taz", GLO_TAZ},
68  {"containerStop", GLO_CONTAINER_STOP},
69  {"chargingStation", GLO_CHARGING_STATION},
70  {"overheadWireSegment", GLO_OVERHEAD_WIRE_SEGMENT},
71  {"parkingArea", GLO_PARKING_AREA},
72  {"parkingSpace", GLO_PARKING_SPACE},
73  {"e1Detector", GLO_E1DETECTOR},
74  {"e1DetectorME", GLO_E1DETECTOR_ME},
75  {"e1DetectorInstant", GLO_E1DETECTOR_INSTANT},
76  {"e2Detector", GLO_E2DETECTOR},
77  {"e3Detector", GLO_E3DETECTOR},
78  {"entryDetector", GLO_DET_ENTRY},
79  {"exitDetector", GLO_DET_EXIT},
80  {"rerouter", GLO_REROUTER},
81  {"rerouterEdge", GLO_REROUTER_EDGE},
82  {"variableSpeedSign", GLO_VSS},
83  {"calibrator", GLO_CALIBRATOR},
84  {"routeProbe", GLO_ROUTEPROBE},
85  {"vaporizer", GLO_VAPORIZER},
86  //
87  {"shape", GLO_SHAPE},
88  {"polygon", GLO_POLYGON},
89  {"poi", GLO_POI},
90  //
91  {"routeElement", GLO_ROUTEELEMENT},
92  {"vType", GLO_VTYPE},
93  //
94  {"route", GLO_ROUTE},
95  //
96  {"ride", GLO_RIDE},
97  {"walk", GLO_WALK},
98  {"personTrip", GLO_PERSONTRIP},
99  //
100  {"stop", GLO_STOP},
101  {"personStop", GLO_PERSONSTOP},
102  //
103  {"vehicle", GLO_VEHICLE},
104  {"trip", GLO_TRIP},
105  {"flow", GLO_FLOW},
106  {"routeFlow", GLO_ROUTEFLOW},
107  //
108  {"container", GLO_CONTAINER},
109  //
110  {"person", GLO_PERSON},
111  {"personFlow", GLO_PERSONFLOW},
112  //
113  {"textName", GLO_TEXTNAME},
114  {"frontElement", GLO_DOTTEDCONTOUR_FRONT},
115  {"dottedContour", GLO_DOTTEDCONTOUR_INSPECTED},
116  {"temporalShape", GLO_TEMPORALSHAPE},
117  {"rectangleSelection", GLO_RECTANGLESELECTION},
118  {"testElement", GLO_TESTELEMENT},
119  //
120  {"undefined", GLO_MAX}
121 };
122 
123 
124 StringBijection<GUIGlObjectType> GUIGlObject::TypeNames(GUIGlObjectTypeNamesInitializer, GLO_MAX);
126 
127 // ===========================================================================
128 // method definitionsas
129 // ===========================================================================
130 
131 GUIGlObject::GUIGlObject(GUIGlObjectType type, const std::string& microsimID) :
132  myGLObjectType(type),
133  myMicrosimID(microsimID) {
134  // make sure that reserved GLO_ADDITIONALELEMENT isn't used
137  // register object
139 }
140 
141 
143  // remove all paramWindow related with this object
144  for (const auto& paramWindow : myParamWindows) {
145  paramWindow->removeObject(this);
146  }
147  // remove object from GLObjectValuePassConnector and GUIGlObjectStorage
150 }
151 
152 
153 const std::string&
155  return myFullName;
156 }
157 
158 
159 std::string
162 }
163 
164 
165 GUIGlID
167  return myGlID;
168 }
169 
170 
173  UNUSED_PARAMETER(&app);
174  UNUSED_PARAMETER(&parent);
175  return nullptr;
176 }
177 
178 
179 const std::string&
181  return myMicrosimID;
182 }
183 
184 const std::string
186  return "";
187 }
188 
189 void
190 GUIGlObject::setMicrosimID(const std::string& newID) {
191  // first remove objects from GUIGlObjectStorage
193  // set new microsimID and fullName
194  myMicrosimID = newID;
196  // register object again
198 }
199 
200 
203  return myGLObjectType;
204 }
205 
206 
207 void
209  UNUSED_PARAMETER(&s);
210  UNUSED_PARAMETER(parent);
211 }
212 
213 #ifdef HAVE_OSG
214 
215 osg::Node*
216 GUIGlObject::getNode() const {
217  return myOSGNode;
218 }
219 
220 
221 void
222 GUIGlObject::setNode(osg::Node* node) {
223  myOSGNode = node;
224 }
225 
226 #endif
227 
228 void
230  new MFXMenuHeader(ret, app.getBoldFont(), getFullName().c_str(), nullptr, nullptr, 0);
231  if (addSeparator) {
232  new FXMenuSeparator(ret);
233  }
234 }
235 
236 
237 void
240  if (addSeparator) {
241  new FXMenuSeparator(ret);
242  }
243 }
244 
245 
246 void
248  GUIDesigns::buildFXMenuCommand(ret, "Copy name to clipboard", nullptr, ret, MID_COPY_NAME);
249  GUIDesigns::buildFXMenuCommand(ret, "Copy typed name to clipboard", nullptr, ret, MID_COPY_TYPED_NAME);
250  if (addSeparator) {
251  new FXMenuSeparator(ret);
252  }
253 }
254 
255 
256 void
258  if (gSelected.isSelected(getType(), getGlID())) {
260  } else {
262  }
263  if (addSeparator) {
264  new FXMenuSeparator(ret);
265  }
266 }
267 
268 
269 void
272  if (addSeparator) {
273  new FXMenuSeparator(ret);
274  }
275 }
276 
277 
278 void
281  if (addSeparator) {
282  new FXMenuSeparator(ret);
283  }
284 }
285 
286 
287 void
289  GUIDesigns::buildFXMenuCommand(ret, "Copy cursor position to clipboard", nullptr, ret, MID_COPY_CURSOR_POSITION);
290  if (GeoConvHelper::getFinal().usingGeoProjection()) {
291  GUIDesigns::buildFXMenuCommand(ret, "Copy cursor geo-position to clipboard", nullptr, ret, MID_COPY_CURSOR_GEOPOSITION);
292  }
293  if (addSeparator) {
294  new FXMenuSeparator(ret);
295  }
296 }
297 
298 
299 void
302  if (addSeparator) {
303  new FXMenuSeparator(ret);
304  }
305 }
306 
307 
308 void
310  myParamWindows.insert(t);
311 }
312 
313 
314 void
316  std::set<GUIParameterTableWindow*>::iterator i = myParamWindows.find(t);
317  if (i != myParamWindows.end()) {
318  myParamWindows.erase(i);
319  }
320 }
321 
322 
323 void
325  assert(ret);
326  // build header (<tag>:<ID>
327  buildPopupHeader(ret, app, false);
328  // build center
330  // build copy name
332  // build select/unselect
334  // build show parameters
335  buildShowParamsPopupEntry(ret, false);
336  // build copy cursor position to clipboard
337  buildPositionCopyEntry(ret, false);
338  // only show type if isn't empty
339  if (type != "") {
340  GUIDesigns::buildFXMenuCommand(ret, ("type: " + type + "").c_str(), nullptr, nullptr, 0);
341  new FXMenuSeparator(ret);
342  }
343 }
344 
345 
346 void
348  assert(ret);
349  // build header (<tag>:<ID>
350  buildPopupHeader(ret, app, false);
351  // build center
353  // build copy name
355  // build select/unselect
357  // build show parameters
358  buildShowParamsPopupEntry(ret, false);
359  // build copy cursor position to clipboard
360  buildPositionCopyEntry(ret, false);
361  // only show type if isn't empty
362  if (type != "") {
363  GUIDesigns::buildFXMenuCommand(ret, ("type: " + type + "").c_str(), nullptr, nullptr, 0);
364  new FXMenuSeparator(ret);
365  }
366 }
367 
368 
369 std::string
372 }
373 
374 
375 void
376 GUIGlObject::drawName(const Position& pos, const double scale, const GUIVisualizationTextSettings& settings, const double angle) const {
377  if (settings.show) {
378  GLHelper::drawTextSettings(settings, getMicrosimID(), pos, scale, angle);
379  }
380 }
381 
382 
383 /****************************************************************************/
@ MID_MANIP
Open the object's manipulator.
Definition: GUIAppEnum.h:431
@ MID_ADDSELECT
Add to selected items - menu entry.
Definition: GUIAppEnum.h:427
@ MID_COPY_CURSOR_GEOPOSITION
Copy cursor geo-coordinate position - popup entry.
Definition: GUIAppEnum.h:409
@ MID_CENTER
Center view to object - popup entry.
Definition: GUIAppEnum.h:399
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:403
@ MID_COPY_CURSOR_POSITION
Copy cursor position - popup entry.
Definition: GUIAppEnum.h:407
@ MID_SHOWPARS
Show object parameter - popup entry.
Definition: GUIAppEnum.h:413
@ MID_COPY_NAME
Copy object name - popup entry.
Definition: GUIAppEnum.h:401
@ MID_SHOWTYPEPARS
Show object type parameter - popup entry.
Definition: GUIAppEnum.h:415
@ MID_REMOVESELECT
Remove from selected items - Menu Etry.
Definition: GUIAppEnum.h:429
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_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
@ GLO_TRIP
a trip
@ GLO_BUS_STOP
a busStop
@ 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_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_TAZ
Traffic Assignment Zones (TAZs)
@ GLO_CONTAINER
a container
@ GLO_EDGEDATA
edge data
@ GLO_CONNECTION
a connection
@ 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_NETWORK
The network - empty.
@ GLO_SHAPE
reserved GLO type to pack shapes
@ GLO_POI
a poi
@ 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_PARKING_SPACE
a ParkingSpace
@ GLO_POLYGON
a polygon
@ GLO_TLLOGIC
a tl-logic
@ GLO_E1DETECTOR_ME
a E1 detector
@ GLO_CROSSING
a tl-logic
@ GLO_PERSONSTOP
a person stop
@ GLO_REROUTER
a Rerouter
@ GLO_PERSONFLOW
a person flow
@ GLO_E1DETECTOR_INSTANT
a E1 detector
@ GLO_VSS
a Variable Speed Sign
GUISelectedStorage gSelected
A global holder of selected objects.
@ RECENTERVIEW
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:29
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:529
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:40
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:255
std::string myFullName
full name of GL Object
Definition: GUIGlObject.h:258
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:252
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:275
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:249
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.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
std::string createFullName() const
create full name
std::set< GUIParameterTableWindow * > myParamWindows
Parameter table windows which refer to this object.
Definition: GUIGlObject.h:261
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:36
const std::string & getString(const T key) const
static std::string emptyString
An empty string.
Definition: StringUtils.h:80