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  {"connection", GLO_CONNECTION},
65  {"prohibition", GLO_PROHIBITION},
66  {"tlLogic", GLO_TLLOGIC},
67  {"detector", GLO_DETECTOR},
68  {"trigger", GLO_TRIGGER},
69  {"additional", GLO_ADDITIONAL},
70  {"polygon", GLO_POLYGON},
71  {"poi", GLO_POI},
72  {"vehicle", GLO_VEHICLE},
73  {"person", GLO_PERSON},
74  {"container", GLO_CONTAINER},
75  {"undefined", GLO_MAX}
76 };
77 
78 
79 StringBijection<GUIGlObjectType> GUIGlObject::TypeNames(GUIGlObjectTypeNamesInitializer, GLO_MAX);
81 
82 // ===========================================================================
83 // method definitions
84 // ===========================================================================
85 
86 GUIGlObject::GUIGlObject(GUIGlObjectType type, const std::string& microsimID) :
87  myGLObjectType(type),
88  myMicrosimID(microsimID),
89  myPrefix(TypeNames.getString(type)) {
92 }
93 
94 
95 GUIGlObject::GUIGlObject(const std::string& prefix, GUIGlObjectType type, const std::string& microsimID) :
96  myGLObjectType(type),
97  myMicrosimID(microsimID),
98  myPrefix(prefix) {
101 }
102 
103 
105  for (std::set<GUIParameterTableWindow*>::iterator i = myParamWindows.begin(); i != myParamWindows.end(); ++i) {
106  (*i)->removeObject(this);
107  }
109 }
110 
111 
112 const std::string&
114  return myFullName;
115 }
116 
117 
118 const std::string&
121 }
122 
123 
124 GUIGlID
126  return myGlID;
127 }
128 
129 
132  UNUSED_PARAMETER(&app);
133  UNUSED_PARAMETER(&parent);
134  return 0;
135 }
136 
137 
138 const std::string&
140  return myMicrosimID;
141 }
142 
143 
144 void
145 GUIGlObject::setMicrosimID(const std::string& newID) {
146  myMicrosimID = newID;
148 }
149 
150 
153  return myGLObjectType;
154 }
155 
156 
157 void
159  UNUSED_PARAMETER(&s);
160  UNUSED_PARAMETER(parent);
161 }
162 
163 #ifdef HAVE_OSG
164 
165 osg::Node*
166 GUIGlObject::getNode() const {
167  return myOSGNode;
168 }
169 
170 
171 void
172 GUIGlObject::setNode(osg::Node* node) {
173  myOSGNode = node;
174 }
175 
176 #endif
177 
178 void
180  bool addSeparator) {
181  new MFXMenuHeader(ret, app.getBoldFont(), getFullName().c_str(), 0, 0, 0);
182  if (addSeparator) {
183  new FXMenuSeparator(ret);
184  }
185 }
186 
187 
188 void
190  new FXMenuCommand(ret, "Center", GUIIconSubSys::getIcon(ICON_RECENTERVIEW), ret, MID_CENTER);
191  if (addSeparator) {
192  new FXMenuSeparator(ret);
193  }
194 }
195 
196 
197 void
199  new FXMenuCommand(ret, "Copy name to clipboard", 0, ret, MID_COPY_NAME);
200  new FXMenuCommand(ret, "Copy typed name to clipboard", 0, ret, MID_COPY_TYPED_NAME);
201  if (addSeparator) {
202  new FXMenuSeparator(ret);
203  }
204 }
205 
206 
207 void
209  if (gSelected.isSelected(getType(), getGlID())) {
210  new FXMenuCommand(ret, "Remove From Selected", GUIIconSubSys::getIcon(ICON_FLAG_MINUS), ret, MID_REMOVESELECT);
211  } else {
212  new FXMenuCommand(ret, "Add To Selected", GUIIconSubSys::getIcon(ICON_FLAG_PLUS), ret, MID_ADDSELECT);
213  }
214  if (addSeparator) {
215  new FXMenuSeparator(ret);
216  }
217 }
218 
219 
220 void
222  new FXMenuCommand(ret, "Show Parameter", GUIIconSubSys::getIcon(ICON_APP_TABLE), ret, MID_SHOWPARS);
223  if (addSeparator) {
224  new FXMenuSeparator(ret);
225  }
226 }
227 
228 
229 void
231  new FXMenuCommand(ret, "Show Type Parameter", GUIIconSubSys::getIcon(ICON_APP_TABLE), ret, MID_SHOWTYPEPARS);
232  if (addSeparator) {
233  new FXMenuSeparator(ret);
234  }
235 }
236 
237 
238 void
240  new FXMenuCommand(ret, "Copy cursor position to clipboard", 0, ret, MID_COPY_CURSOR_POSITION);
241  if (GeoConvHelper::getFinal().usingGeoProjection()) {
242  new FXMenuCommand(ret, "Copy cursor geo-position to clipboard", 0, ret, MID_COPY_CURSOR_GEOPOSITION);
243  }
244  if (addSeparator) {
245  new FXMenuSeparator(ret);
246  }
247 }
248 
249 
250 void
252  new FXMenuCommand(ret, "Open Manipulator...", GUIIconSubSys::getIcon(ICON_MANIP), ret, MID_MANIP);
253  if (addSeparator) {
254  new FXMenuSeparator(ret);
255  }
256 }
257 
258 
259 void
261  myParamWindows.insert(t);
262 }
263 
264 
265 void
267  std::set<GUIParameterTableWindow*>::iterator i = myParamWindows.find(t);
268  if (i != myParamWindows.end()) {
269  myParamWindows.erase(i);
270  }
271 }
272 
273 
274 void
275 GUIGlObject::setPrefix(const std::string& prefix) {
276  myPrefix = prefix;
278 }
279 
280 
281 std::string
283  return myPrefix + ":" + getMicrosimID();
284 }
285 
286 
287 void
288 GUIGlObject::drawName(const Position& pos, const SUMOReal scale, const GUIVisualizationTextSettings& settings, const SUMOReal angle) const {
289  if (settings.show) {
290  GLHelper::drawText(getMicrosimID(), pos, GLO_MAX, settings.size / scale, settings.color, angle);
291  }
292 }
293 
294 /****************************************************************************/
295 
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
draw name of item
a prohibition
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
Stores the information about how to visualize structures.
a connection
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.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
a container
void removeParameterTable(GUIParameterTableWindow *w)
Lets this object know a parameter window showing the object&#39;s values was closed.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
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
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
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
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...
virtual const std::string & getParentName() const
Returns the name of the parent object (if any)
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 getGlID() const
Returns the numerical id of the object.
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:86
const std::string & getFullName() const
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
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
a junction