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-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 // 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  {"netElement", GLO_NETELEMENT},
51  {"edge", GLO_EDGE},
52  {"lane", GLO_LANE},
53  {"junction", GLO_JUNCTION},
54  {"crossing", GLO_CROSSING},
55  {"connection", GLO_CONNECTION},
56  {"prohibition", GLO_PROHIBITION},
57  {"tlLogic", GLO_TLLOGIC},
58  {"additional", GLO_ADDITIONAL},
59  {"busStop", GLO_BUS_STOP},
60  {"access", GLO_ACCESS},
61  {"taz", GLO_TAZ},
62  {"containerStop", GLO_CONTAINER_STOP},
63  {"chargingStation", GLO_CHARGING_STATION},
64  {"parkingArea", GLO_PARKING_AREA},
65  {"parkingSpace", GLO_PARKING_SPACE},
66  {"e1Detector", GLO_E1DETECTOR},
67  {"e1DetectorME", GLO_E1DETECTOR_ME},
68  {"e1DetectorInstant", GLO_E1DETECTOR_INSTANT},
69  {"e2Detector", GLO_E2DETECTOR},
70  {"e3Detector", GLO_E3DETECTOR},
71  {"entryDetector", GLO_DET_ENTRY},
72  {"exitDetector", GLO_DET_EXIT},
73  {"rerouter", GLO_REROUTER},
74  {"rerouterEdge", GLO_REROUTER_EDGE},
75  {"variableSpeedSign", GLO_VSS},
76  {"calibrator", GLO_CALIBRATOR},
77  {"routeProbe", GLO_ROUTEPROBE},
78  {"vaporizer", GLO_VAPORIZER},
79  {"shape", GLO_SHAPE},
80  {"polygon", GLO_POLYGON},
81  {"poi", GLO_POI},
82  {"routeElement", GLO_ROUTEELEMENT},
83  {"vehicle", GLO_VEHICLE},
84  {"person", GLO_PERSON},
85  {"container", GLO_CONTAINER},
86  {"undefined", GLO_MAX}
87 };
88 
89 
90 StringBijection<GUIGlObjectType> GUIGlObject::TypeNames(GUIGlObjectTypeNamesInitializer, GLO_MAX);
92 
93 // ===========================================================================
94 // method definitionsas
95 // ===========================================================================
96 
97 GUIGlObject::GUIGlObject(GUIGlObjectType type, const std::string& microsimID) :
98  myGLObjectType(type),
99  myMicrosimID(microsimID) {
100  // make sure that reserved GLO_ADDITIONAL isn't used
101  assert(myGLObjectType != GLO_ADDITIONAL);
104 }
105 
106 
108  for (auto i : myParamWindows) {
109  i->removeObject(this);
110  }
113 }
114 
115 
116 const std::string&
118  return myFullName;
119 }
120 
121 
122 std::string
125 }
126 
127 
128 GUIGlID
130  return myGlID;
131 }
132 
133 
136  UNUSED_PARAMETER(&app);
137  UNUSED_PARAMETER(&parent);
138  return nullptr;
139 }
140 
141 
142 const std::string&
144  return myMicrosimID;
145 }
146 
147 
148 void
149 GUIGlObject::setMicrosimID(const std::string& newID) {
150  myMicrosimID = newID;
152 }
153 
154 
157  return myGLObjectType;
158 }
159 
160 
161 void
163  UNUSED_PARAMETER(&s);
164  UNUSED_PARAMETER(parent);
165 }
166 
167 #ifdef HAVE_OSG
168 
169 osg::Node*
170 GUIGlObject::getNode() const {
171  return myOSGNode;
172 }
173 
174 
175 void
176 GUIGlObject::setNode(osg::Node* node) {
177  myOSGNode = node;
178 }
179 
180 #endif
181 
182 void
184  new MFXMenuHeader(ret, app.getBoldFont(), getFullName().c_str(), nullptr, nullptr, 0);
185  if (addSeparator) {
186  new FXMenuSeparator(ret);
187  }
188 }
189 
190 
191 void
193  new FXMenuCommand(ret, "Center", GUIIconSubSys::getIcon(ICON_RECENTERVIEW), ret, MID_CENTER);
194  if (addSeparator) {
195  new FXMenuSeparator(ret);
196  }
197 }
198 
199 
200 void
202  new FXMenuCommand(ret, "Copy name to clipboard", nullptr, ret, MID_COPY_NAME);
203  new FXMenuCommand(ret, "Copy typed name to clipboard", nullptr, ret, MID_COPY_TYPED_NAME);
204  if (addSeparator) {
205  new FXMenuSeparator(ret);
206  }
207 }
208 
209 
210 void
212  if (gSelected.isSelected(getType(), getGlID())) {
213  new FXMenuCommand(ret, "Remove From Selected", GUIIconSubSys::getIcon(ICON_FLAG_MINUS), ret, MID_REMOVESELECT);
214  } else {
215  new FXMenuCommand(ret, "Add To Selected", GUIIconSubSys::getIcon(ICON_FLAG_PLUS), ret, MID_ADDSELECT);
216  }
217  if (addSeparator) {
218  new FXMenuSeparator(ret);
219  }
220 }
221 
222 
223 void
225  new FXMenuCommand(ret, "Show Parameter", GUIIconSubSys::getIcon(ICON_APP_TABLE), ret, MID_SHOWPARS);
226  if (addSeparator) {
227  new FXMenuSeparator(ret);
228  }
229 }
230 
231 
232 void
234  new FXMenuCommand(ret, "Show Type Parameter", GUIIconSubSys::getIcon(ICON_APP_TABLE), ret, MID_SHOWTYPEPARS);
235  if (addSeparator) {
236  new FXMenuSeparator(ret);
237  }
238 }
239 
240 
241 void
243  new FXMenuCommand(ret, "Copy cursor position to clipboard", nullptr, ret, MID_COPY_CURSOR_POSITION);
244  if (GeoConvHelper::getFinal().usingGeoProjection()) {
245  new FXMenuCommand(ret, "Copy cursor geo-position to clipboard", nullptr, ret, MID_COPY_CURSOR_GEOPOSITION);
246  }
247  if (addSeparator) {
248  new FXMenuSeparator(ret);
249  }
250 }
251 
252 
253 void
255  new FXMenuCommand(ret, "Open Manipulator...", GUIIconSubSys::getIcon(ICON_MANIP), ret, MID_MANIP);
256  if (addSeparator) {
257  new FXMenuSeparator(ret);
258  }
259 }
260 
261 
262 void
264  myParamWindows.insert(t);
265 }
266 
267 
268 void
270  std::set<GUIParameterTableWindow*>::iterator i = myParamWindows.find(t);
271  if (i != myParamWindows.end()) {
272  myParamWindows.erase(i);
273  }
274 }
275 
276 
277 void
279  assert(ret);
280  // build header (<tag>:<ID>
281  buildPopupHeader(ret, app, false);
282  // build center
284  // build copy name
286  // build select/unselect
288  // build show parameters
289  buildShowParamsPopupEntry(ret, false);
290  // build copy cursor position to clipboard
291  buildPositionCopyEntry(ret, false);
292  // only show type if isn't empty
293  if (type != "") {
294  new FXMenuCommand(ret, ("type: " + type + "").c_str(), nullptr, nullptr, 0);
295  new FXMenuSeparator(ret);
296  }
297 }
298 
299 
300 void
302  assert(ret);
303  // build header (<tag>:<ID>
304  buildPopupHeader(ret, app, false);
305  // build center
307  // build copy name
309  // build select/unselect
311  // build show parameters
312  buildShowParamsPopupEntry(ret, false);
313  // build copy cursor position to clipboard
314  buildPositionCopyEntry(ret, false);
315  // only show type if isn't empty
316  if (type != "") {
317  new FXMenuCommand(ret, ("type: " + type + "").c_str(), nullptr, nullptr, 0);
318  new FXMenuSeparator(ret);
319  }
320 }
321 
322 
323 std::string
326 }
327 
328 
329 void
330 GUIGlObject::drawName(const Position& pos, const double scale, const GUIVisualizationTextSettings& settings, const double angle) const {
331  if (settings.show) {
332  GLHelper::drawTextSettings(settings, getMicrosimID(), pos, scale, angle);
333  }
334 }
335 
336 /****************************************************************************/
337 
a prohibition
a containerStop
Copy object name - popup entry.
Definition: GUIAppEnum.h:230
a tl-logic
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:228
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:258
a E2 detector
a vehicles
GUIGlID myGlID
The numerical id of the object.
Definition: GUIGlObject.h:240
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:635
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:256
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:33
reserved GLO type to pack shapes
a E3 detector
a container
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:238
Show object parameter - popup entry.
Definition: GUIAppEnum.h:242
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:236
std::string myMicrosimID
ID of GL object.
Definition: GUIGlObject.h:246
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 RouteElments
a ParkingSpace
a Calibrator
a E1 detector
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:80
const GUIGlObjectType myGLObjectType
The type of the object.
Definition: GUIGlObject.h:243
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.
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
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:266
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:249
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:244
empty max
GUIGlObject(GUIGlObjectType type, const std::string &microsimID)
Constructor.
Definition: GUIGlObject.cpp:97
const std::string & getFullName() const
Add to selected items - menu entry.
Definition: GUIAppEnum.h:254
std::set< GUIParameterTableWindow * > myParamWindows
Parameter table windows which refer to this object.
Definition: GUIGlObject.h:252
GUISelectedStorage gSelected
A global holder of selected objects.
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:232
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