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  {"containerStop", GLO_CONTAINER_STOP},
62  {"chargingStation", GLO_CHARGING_STATION},
63  {"parkingArea", GLO_PARKING_AREA},
64  {"parkingSpace", GLO_PARKING_SPACE},
65  {"e1Detector", GLO_E1DETECTOR},
66  {"e1DetectorME", GLO_E1DETECTOR_ME},
67  {"e1DetectorInstant", GLO_E1DETECTOR_INSTANT},
68  {"e2Detector", GLO_E2DETECTOR},
69  {"e3Detector", GLO_E3DETECTOR},
70  {"entryDetector", GLO_DET_ENTRY},
71  {"exitDetector", GLO_DET_EXIT},
72  {"rerouter", GLO_REROUTER},
73  {"rerouterEdge", GLO_REROUTER_EDGE},
74  {"variableSpeedSign", GLO_VSS},
75  {"calibrator", GLO_CALIBRATOR},
76  {"routeProbe", GLO_ROUTEPROBE},
77  {"vaporizer", GLO_VAPORIZER},
78  {"shape", GLO_SHAPE},
79  {"polygon", GLO_POLYGON},
80  {"poi", GLO_POI},
81  {"routeElement", GLO_ROUTEELEMENT},
82  {"vehicle", GLO_VEHICLE},
83  {"person", GLO_PERSON},
84  {"container", GLO_CONTAINER},
85  {"undefined", GLO_MAX}
86 };
87 
88 
89 StringBijection<GUIGlObjectType> GUIGlObject::TypeNames(GUIGlObjectTypeNamesInitializer, GLO_MAX);
91 
92 // ===========================================================================
93 // method definitionsas
94 // ===========================================================================
95 
96 GUIGlObject::GUIGlObject(GUIGlObjectType type, const std::string& microsimID) :
97  myGLObjectType(type),
98  myMicrosimID(microsimID) {
99  // make sure that reserved GLO_ADDITIONAL isn't used
100  assert(myGLObjectType != GLO_ADDITIONAL);
103 }
104 
105 
107  for (auto i : myParamWindows) {
108  i->removeObject(this);
109  }
112 }
113 
114 
115 const std::string&
117  return myFullName;
118 }
119 
120 
121 std::string
124 }
125 
126 
127 GUIGlID
129  return myGlID;
130 }
131 
132 
135  UNUSED_PARAMETER(&app);
136  UNUSED_PARAMETER(&parent);
137  return 0;
138 }
139 
140 
141 const std::string&
143  return myMicrosimID;
144 }
145 
146 
147 void
148 GUIGlObject::setMicrosimID(const std::string& newID) {
149  myMicrosimID = newID;
151 }
152 
153 
156  return myGLObjectType;
157 }
158 
159 
160 void
162  UNUSED_PARAMETER(&s);
163  UNUSED_PARAMETER(parent);
164 }
165 
166 #ifdef HAVE_OSG
167 
168 osg::Node*
169 GUIGlObject::getNode() const {
170  return myOSGNode;
171 }
172 
173 
174 void
175 GUIGlObject::setNode(osg::Node* node) {
176  myOSGNode = node;
177 }
178 
179 #endif
180 
181 void
183  new MFXMenuHeader(ret, app.getBoldFont(), getFullName().c_str(), 0, 0, 0);
184  if (addSeparator) {
185  new FXMenuSeparator(ret);
186  }
187 }
188 
189 
190 void
192  new FXMenuCommand(ret, "Center", GUIIconSubSys::getIcon(ICON_RECENTERVIEW), ret, MID_CENTER);
193  if (addSeparator) {
194  new FXMenuSeparator(ret);
195  }
196 }
197 
198 
199 void
201  new FXMenuCommand(ret, "Copy name to clipboard", 0, ret, MID_COPY_NAME);
202  new FXMenuCommand(ret, "Copy typed name to clipboard", 0, ret, MID_COPY_TYPED_NAME);
203  if (addSeparator) {
204  new FXMenuSeparator(ret);
205  }
206 }
207 
208 
209 void
211  if (gSelected.isSelected(getType(), getGlID())) {
212  new FXMenuCommand(ret, "Remove From Selected", GUIIconSubSys::getIcon(ICON_FLAG_MINUS), ret, MID_REMOVESELECT);
213  } else {
214  new FXMenuCommand(ret, "Add To Selected", GUIIconSubSys::getIcon(ICON_FLAG_PLUS), ret, MID_ADDSELECT);
215  }
216  if (addSeparator) {
217  new FXMenuSeparator(ret);
218  }
219 }
220 
221 
222 void
224  new FXMenuCommand(ret, "Show Parameter", GUIIconSubSys::getIcon(ICON_APP_TABLE), ret, MID_SHOWPARS);
225  if (addSeparator) {
226  new FXMenuSeparator(ret);
227  }
228 }
229 
230 
231 void
233  new FXMenuCommand(ret, "Show Type Parameter", GUIIconSubSys::getIcon(ICON_APP_TABLE), ret, MID_SHOWTYPEPARS);
234  if (addSeparator) {
235  new FXMenuSeparator(ret);
236  }
237 }
238 
239 
240 void
242  new FXMenuCommand(ret, "Copy cursor position to clipboard", 0, ret, MID_COPY_CURSOR_POSITION);
243  if (GeoConvHelper::getFinal().usingGeoProjection()) {
244  new FXMenuCommand(ret, "Copy cursor geo-position to clipboard", 0, ret, MID_COPY_CURSOR_GEOPOSITION);
245  }
246  if (addSeparator) {
247  new FXMenuSeparator(ret);
248  }
249 }
250 
251 
252 void
254  new FXMenuCommand(ret, "Open Manipulator...", GUIIconSubSys::getIcon(ICON_MANIP), ret, MID_MANIP);
255  if (addSeparator) {
256  new FXMenuSeparator(ret);
257  }
258 }
259 
260 
261 void
263  myParamWindows.insert(t);
264 }
265 
266 
267 void
269  std::set<GUIParameterTableWindow*>::iterator i = myParamWindows.find(t);
270  if (i != myParamWindows.end()) {
271  myParamWindows.erase(i);
272  }
273 }
274 
275 
276 void
278  assert(ret);
279  // build header (<tag>:<ID>
280  buildPopupHeader(ret, app, false);
281  // build center
283  // build copy name
285  // build select/unselect
287  // build show parameters
288  buildShowParamsPopupEntry(ret, false);
289  // build copy cursor position to clipboard
290  buildPositionCopyEntry(ret, false);
291  // only show type if isn't empty
292  if (type != "") {
293  new FXMenuCommand(ret, ("type: " + type + "").c_str(), 0, 0, 0);
294  new FXMenuSeparator(ret);
295  }
296 }
297 
298 
299 void
301  assert(ret);
302  // build header (<tag>:<ID>
303  buildPopupHeader(ret, app, false);
304  // build center
306  // build copy name
308  // build select/unselect
310  // build show parameters
311  buildShowParamsPopupEntry(ret, false);
312  // build copy cursor position to clipboard
313  buildPositionCopyEntry(ret, false);
314  // only show type if isn't empty
315  if (type != "") {
316  new FXMenuCommand(ret, ("type: " + type + "").c_str(), 0, 0, 0);
317  new FXMenuSeparator(ret);
318  }
319 }
320 
321 
322 std::string
325 }
326 
327 
328 void
329 GUIGlObject::drawName(const Position& pos, const double scale, const GUIVisualizationTextSettings& settings, const double angle) const {
330  if (settings.show) {
331  GLHelper::drawText(getMicrosimID(), pos, GLO_MAX, settings.scaledSize(scale), settings.color, angle);
332  }
333 }
334 
335 /****************************************************************************/
336 
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:236
a Variable Speed Sign
a chargingStation
Stores the information about how to visualize structures.
a connection
const std::string & getString(const T key) const
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.
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0, int align=0, double width=-1)
Definition: GLHelper.cpp:611
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
double scaledSize(double scale, double constFactor=0.1) const
Copy cursor position - popup entry.
Definition: GUIAppEnum.h:236
std::string myMicrosimID
ID of GL object.
Definition: GUIGlObject.h:242
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:78
const GUIGlObjectType myGLObjectType
The type of the object.
Definition: GUIGlObject.h:239
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:262
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:245
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:96
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:248
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