SUMO - Simulation of Urban MObility
GUIGlObject.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Base class for all objects that may be displayed within the openGL-gui
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <stack>
36 #include <utils/common/ToString.h>
46 #include <utils/gui/div/GLHelper.h>
47 #include "GUIGlObject.h"
48 #include "GUIGlObjectStorage.h"
49 
50 #ifdef CHECK_MEMORY_LEAKS
51 #include <foreign/nvwa/debug_new.h>
52 #endif // CHECK_MEMORY_LEAKS
53 
54 // ===========================================================================
55 // static members
56 // ===========================================================================
57 
59  {"network", GLO_NETWORK},
60  {"edge", GLO_EDGE},
61  {"lane", GLO_LANE},
62  {"junction", GLO_JUNCTION},
63  {"crossing", GLO_CROSSING},
64  {"tlLogic", GLO_TLLOGIC},
65  {"detector", GLO_DETECTOR},
66  {"trigger", GLO_TRIGGER},
67  {"additional", GLO_ADDITIONAL},
68  {"polygon", GLO_POLYGON},
69  {"poi", GLO_POI},
70  {"vehicle", GLO_VEHICLE},
71  {"person", GLO_PERSON},
72  {"container", GLO_CONTAINER},
73  {"undefined", GLO_MAX}
74 };
75 
76 
77 StringBijection<GUIGlObjectType> GUIGlObject::TypeNames(GUIGlObjectTypeNamesInitializer, GLO_MAX);
78 
79 // ===========================================================================
80 // method definitions
81 // ===========================================================================
82 
83 GUIGlObject::GUIGlObject(GUIGlObjectType type, const std::string& microsimID) :
84  myGLObjectType(type),
85  myMicrosimID(microsimID),
86  myPrefix(TypeNames.getString(type)) {
89 }
90 
91 
92 GUIGlObject::GUIGlObject(const std::string& prefix, GUIGlObjectType type, const std::string& microsimID) :
93  myGLObjectType(type),
94  myMicrosimID(microsimID),
95  myPrefix(prefix) {
98 }
99 
100 
102  for (std::set<GUIParameterTableWindow*>::iterator i = myParamWindows.begin(); i != myParamWindows.end(); ++i) {
103  (*i)->removeObject(this);
104  }
106 }
107 
108 
109 const std::string&
111  return myFullName;
112 }
113 
114 
115 const std::string&
118 }
119 
120 
121 GUIGlID
123  return myGlID;
124 }
125 
126 
129  UNUSED_PARAMETER(&app);
130  UNUSED_PARAMETER(&parent);
131  return 0;
132 }
133 
134 
135 const std::string&
137  return myMicrosimID;
138 }
139 
140 
141 void
142 GUIGlObject::setMicrosimID(const std::string& newID) {
143  myMicrosimID = newID;
145 }
146 
147 
150  return myGLObjectType;
151 }
152 
153 
154 void
156  UNUSED_PARAMETER(&s);
157  UNUSED_PARAMETER(parent);
158 };
159 
160 #ifdef HAVE_OSG
161 
162 osg::Node*
163 GUIGlObject::getNode() const {
164  return myOSGNode;
165 }
166 
167 
168 void
169 GUIGlObject::setNode(osg::Node* node) {
170  myOSGNode = node;
171 }
172 
173 #endif
174 
175 void
177  bool addSeparator) {
178  new MFXMenuHeader(ret, app.getBoldFont(), getFullName().c_str(), 0, 0, 0);
179  if (addSeparator) {
180  new FXMenuSeparator(ret);
181  }
182 }
183 
184 
185 void
187  new FXMenuCommand(ret, "Center", GUIIconSubSys::getIcon(ICON_RECENTERVIEW), ret, MID_CENTER);
188  if (addSeparator) {
189  new FXMenuSeparator(ret);
190  }
191 }
192 
193 
194 void
196  new FXMenuCommand(ret, "Copy name to clipboard", 0, ret, MID_COPY_NAME);
197  new FXMenuCommand(ret, "Copy typed name to clipboard", 0, ret, MID_COPY_TYPED_NAME);
198  if (addSeparator) {
199  new FXMenuSeparator(ret);
200  }
201 }
202 
203 
204 void
206  if (gSelected.isSelected(getType(), getGlID())) {
207  new FXMenuCommand(ret, "Remove From Selected", GUIIconSubSys::getIcon(ICON_FLAG_MINUS), ret, MID_REMOVESELECT);
208  } else {
209  new FXMenuCommand(ret, "Add To Selected", GUIIconSubSys::getIcon(ICON_FLAG_PLUS), ret, MID_ADDSELECT);
210  }
211  if (addSeparator) {
212  new FXMenuSeparator(ret);
213  }
214 }
215 
216 
217 void
219  new FXMenuCommand(ret, "Show Parameter", GUIIconSubSys::getIcon(ICON_APP_TABLE), ret, MID_SHOWPARS);
220  if (addSeparator) {
221  new FXMenuSeparator(ret);
222  }
223 }
224 
225 
226 void
228  new FXMenuCommand(ret, "Show Type Parameter", GUIIconSubSys::getIcon(ICON_APP_TABLE), ret, MID_SHOWTYPEPARS);
229  if (addSeparator) {
230  new FXMenuSeparator(ret);
231  }
232 }
233 
234 
235 void
237  new FXMenuCommand(ret, "Copy cursor position to clipboard", 0, ret, MID_COPY_CURSOR_POSITION);
238  if (GeoConvHelper::getFinal().usingGeoProjection()) {
239  new FXMenuCommand(ret, "Copy cursor geo-position to clipboard", 0, ret, MID_COPY_CURSOR_GEOPOSITION);
240  }
241  if (addSeparator) {
242  new FXMenuSeparator(ret);
243  }
244 }
245 
246 
247 void
249  new FXMenuCommand(ret, "Open Manipulator...", GUIIconSubSys::getIcon(ICON_MANIP), ret, MID_MANIP);
250  if (addSeparator) {
251  new FXMenuSeparator(ret);
252  }
253 }
254 
255 
256 void
258  myParamWindows.insert(t);
259 }
260 
261 
262 void
264  std::set<GUIParameterTableWindow*>::iterator i = myParamWindows.find(t);
265  if (i != myParamWindows.end()) {
266  myParamWindows.erase(i);
267  }
268 }
269 
270 
271 void
272 GUIGlObject::setPrefix(const std::string& prefix) {
273  myPrefix = prefix;
275 }
276 
277 
278 std::string
280  return myPrefix + ":" + getMicrosimID();
281 }
282 
283 
284 void
285 GUIGlObject::drawName(const Position& pos, const SUMOReal scale, const GUIVisualizationTextSettings& settings, const SUMOReal angle) const {
286  if (settings.show) {
287  GLHelper::drawText(getMicrosimID(), pos, GLO_MAX, settings.size / scale, settings.color, angle);
288  }
289 }
290 
291 /****************************************************************************/
292 
Copy cursor position - popup entry.
Definition: GUIAppEnum.h:237
a tl-logic
a lane speed trigger,
a polygon
Copy object name - popup entry.
Definition: GUIAppEnum.h:231
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
GUIGlObjectType
a vehicles
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:233
GUIGlID myGlID
The numerical id of the object.
Definition: GUIGlObject.h:248
std::string createFullName() const
create full name
const std::string & getFullName() const
Stores the information about how to visualize structures.
virtual void drawGLAdditional(GUISUMOAbstractView *const parent, const GUIVisualizationSettings &s) const
Draws additional, user-triggered visualisations.
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.
static void drawText(const std::string &text, const Position &pos, const SUMOReal layer, const SUMOReal size, const RGBColor &col=RGBColor::BLACK, const SUMOReal angle=0)
draw Text with given parameters
Definition: GLHelper.cpp:460
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
Add to selected items - menu entry.
Definition: GUIAppEnum.h:251
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.
GUIGlID getGlID() const
Returns the numerical id of the object.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
a container
Center view to object - popup entry.
Definition: GUIAppEnum.h:229
void removeParameterTable(GUIParameterTableWindow *w)
Lets this object know a parameter window showing the object&#39;s values was closed.
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:46
a person
std::string myMicrosimID
ID of GL object.
Definition: GUIGlObject.h:254
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
a tl-logic
virtual ~GUIGlObject()
Destructor.
void addParameterTable(GUIParameterTableWindow *w)
Remove from selected items - Menu Etry.
Definition: GUIAppEnum.h:253
FXFont * getBoldFont()
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
draw name of item
a detector
static std::string emptyString
An empty string.
Definition: StringUtils.h:84
const GUIGlObjectType myGLObjectType
The type of the object.
Definition: GUIGlObject.h:251
unsigned int GUIGlID
Definition: GUIGlObject.h:50
compound additional
void buildShowManipulatorPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the manipulator window.
Show object parameter - popup entry.
Definition: GUIAppEnum.h:241
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
Copy cursor geo-coordinate position - popup entry.
Definition: GUIAppEnum.h:239
static StringBijection< GUIGlObjectType > TypeNames
associates object types with strings
Definition: GUIGlObject.h:76
virtual const std::string & getParentName() const
Returns the name of the parent object (if any)
The popup menu of a globject.
an edge
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:277
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
The network - empty.
std::string myPrefix
prefix of GL Object
Definition: GUIGlObject.h:257
std::string myFullName
full name of GL Object
Definition: GUIGlObject.h:260
GUIGlID registerObject(GUIGlObject *object, const std::string &fullName)
Registers an object.
#define SUMOReal
Definition: config.h:214
empty max
GUIGlObject(GUIGlObjectType type, const std::string &microsimID)
Constructor.
Definition: GUIGlObject.cpp:83
std::set< GUIParameterTableWindow * > myParamWindows
Parameter table windows which refer to this object.
Definition: GUIGlObject.h:263
void setPrefix(const std::string &prefix)
usually names are prefixed by a type-specific string. this method can be used to change the default ...
GUISelectedStorage gSelected
A global holder of selected objects.
A window containing a gl-object&#39;s parameter.
Show object type parameter - popup entry.
Definition: GUIAppEnum.h:243
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
a junction
Open the object&#39;s manipulator.
Definition: GUIAppEnum.h:255