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);
79 
80 // ===========================================================================
81 // method definitions
82 // ===========================================================================
83 
84 GUIGlObject::GUIGlObject(GUIGlObjectType type, const std::string& microsimID) :
85  myGLObjectType(type),
86  myMicrosimID(microsimID),
87  myPrefix(TypeNames.getString(type)) {
90 }
91 
92 
93 GUIGlObject::GUIGlObject(const std::string& prefix, GUIGlObjectType type, const std::string& microsimID) :
94  myGLObjectType(type),
95  myMicrosimID(microsimID),
96  myPrefix(prefix) {
99 }
100 
101 
103  for (std::set<GUIParameterTableWindow*>::iterator i = myParamWindows.begin(); i != myParamWindows.end(); ++i) {
104  (*i)->removeObject(this);
105  }
107 }
108 
109 
110 const std::string&
112  return myFullName;
113 }
114 
115 
116 const std::string&
119 }
120 
121 
122 GUIGlID
124  return myGlID;
125 }
126 
127 
130  UNUSED_PARAMETER(&app);
131  UNUSED_PARAMETER(&parent);
132  return 0;
133 }
134 
135 
136 const std::string&
138  return myMicrosimID;
139 }
140 
141 
142 void
143 GUIGlObject::setMicrosimID(const std::string& newID) {
144  myMicrosimID = newID;
146 }
147 
148 
151  return myGLObjectType;
152 }
153 
154 
155 void
157  UNUSED_PARAMETER(&s);
158  UNUSED_PARAMETER(parent);
159 }
160 
161 #ifdef HAVE_OSG
162 
163 osg::Node*
164 GUIGlObject::getNode() const {
165  return myOSGNode;
166 }
167 
168 
169 void
170 GUIGlObject::setNode(osg::Node* node) {
171  myOSGNode = node;
172 }
173 
174 #endif
175 
176 void
178  bool addSeparator) {
179  new MFXMenuHeader(ret, app.getBoldFont(), getFullName().c_str(), 0, 0, 0);
180  if (addSeparator) {
181  new FXMenuSeparator(ret);
182  }
183 }
184 
185 
186 void
188  new FXMenuCommand(ret, "Center", GUIIconSubSys::getIcon(ICON_RECENTERVIEW), ret, MID_CENTER);
189  if (addSeparator) {
190  new FXMenuSeparator(ret);
191  }
192 }
193 
194 
195 void
197  new FXMenuCommand(ret, "Copy name to clipboard", 0, ret, MID_COPY_NAME);
198  new FXMenuCommand(ret, "Copy typed name to clipboard", 0, ret, MID_COPY_TYPED_NAME);
199  if (addSeparator) {
200  new FXMenuSeparator(ret);
201  }
202 }
203 
204 
205 void
207  if (gSelected.isSelected(getType(), getGlID())) {
208  new FXMenuCommand(ret, "Remove From Selected", GUIIconSubSys::getIcon(ICON_FLAG_MINUS), ret, MID_REMOVESELECT);
209  } else {
210  new FXMenuCommand(ret, "Add To Selected", GUIIconSubSys::getIcon(ICON_FLAG_PLUS), ret, MID_ADDSELECT);
211  }
212  if (addSeparator) {
213  new FXMenuSeparator(ret);
214  }
215 }
216 
217 
218 void
220  new FXMenuCommand(ret, "Show Parameter", GUIIconSubSys::getIcon(ICON_APP_TABLE), ret, MID_SHOWPARS);
221  if (addSeparator) {
222  new FXMenuSeparator(ret);
223  }
224 }
225 
226 
227 void
229  new FXMenuCommand(ret, "Show Type Parameter", GUIIconSubSys::getIcon(ICON_APP_TABLE), ret, MID_SHOWTYPEPARS);
230  if (addSeparator) {
231  new FXMenuSeparator(ret);
232  }
233 }
234 
235 
236 void
238  new FXMenuCommand(ret, "Copy cursor position to clipboard", 0, ret, MID_COPY_CURSOR_POSITION);
239  if (GeoConvHelper::getFinal().usingGeoProjection()) {
240  new FXMenuCommand(ret, "Copy cursor geo-position to clipboard", 0, ret, MID_COPY_CURSOR_GEOPOSITION);
241  }
242  if (addSeparator) {
243  new FXMenuSeparator(ret);
244  }
245 }
246 
247 
248 void
250  new FXMenuCommand(ret, "Open Manipulator...", GUIIconSubSys::getIcon(ICON_MANIP), ret, MID_MANIP);
251  if (addSeparator) {
252  new FXMenuSeparator(ret);
253  }
254 }
255 
256 
257 void
259  myParamWindows.insert(t);
260 }
261 
262 
263 void
265  std::set<GUIParameterTableWindow*>::iterator i = myParamWindows.find(t);
266  if (i != myParamWindows.end()) {
267  myParamWindows.erase(i);
268  }
269 }
270 
271 
272 void
273 GUIGlObject::setPrefix(const std::string& prefix) {
274  myPrefix = prefix;
276 }
277 
278 
279 std::string
281  return myPrefix + ":" + getMicrosimID();
282 }
283 
284 
285 void
286 GUIGlObject::drawName(const Position& pos, const SUMOReal scale, const GUIVisualizationTextSettings& settings, const SUMOReal angle) const {
287  if (settings.show) {
288  GLHelper::drawText(getMicrosimID(), pos, GLO_MAX, settings.size / scale, settings.color, angle);
289  }
290 }
291 
292 /****************************************************************************/
293 
a tl-logic
a lane speed trigger,
Center view to object - popup entry.
Definition: GUIAppEnum.h:229
a polygon
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
GUIGlObjectType
a vehicles
GUIGlID myGlID
The numerical id of the object.
Definition: GUIGlObject.h:249
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.
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:233
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
Show object type parameter - popup entry.
Definition: GUIAppEnum.h:243
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:253
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
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)
Copy object name - popup entry.
Definition: GUIAppEnum.h:231
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:255
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
a tl-logic
virtual ~GUIGlObject()
Destructor.
void addParameterTable(GUIParameterTableWindow *w)
FXFont * getBoldFont()
Open the object&#39;s manipulator.
Definition: GUIAppEnum.h:255
Show object parameter - popup entry.
Definition: GUIAppEnum.h:241
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:252
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.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
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)
Add to selected items - menu entry.
Definition: GUIAppEnum.h:251
static const GUIGlID INVALID_ID
Definition: GUIGlObject.h:77
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:278
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:258
std::string myFullName
full name of GL Object
Definition: GUIGlObject.h:261
GUIGlID registerObject(GUIGlObject *object, const std::string &fullName)
Registers an object.
#define SUMOReal
Definition: config.h:213
Copy cursor geo-coordinate position - popup entry.
Definition: GUIAppEnum.h:239
empty max
GUIGlObject(GUIGlObjectType type, const std::string &microsimID)
Constructor.
Definition: GUIGlObject.cpp:84
std::set< GUIParameterTableWindow * > myParamWindows
Parameter table windows which refer to this object.
Definition: GUIGlObject.h:264
void setPrefix(const std::string &prefix)
usually names are prefixed by a type-specific string. this method can be used to change the default ...
Copy cursor position - popup entry.
Definition: GUIAppEnum.h:237
GUISelectedStorage gSelected
A global holder of selected objects.
A window containing a gl-object&#39;s parameter.
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