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-2017 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 // ===========================================================================
51 // static members
52 // ===========================================================================
53 
55  {"network", GLO_NETWORK},
56  {"edge", GLO_EDGE},
57  {"lane", GLO_LANE},
58  {"junction", GLO_JUNCTION},
59  {"crossing", GLO_CROSSING},
60  {"connection", GLO_CONNECTION},
61  {"prohibition", GLO_PROHIBITION},
62  {"tlLogic", GLO_TLLOGIC},
63  {"detector", GLO_DETECTOR},
64  {"trigger", GLO_TRIGGER},
65  {"additional", GLO_ADDITIONAL},
66  {"polygon", GLO_POLYGON},
67  {"poi", GLO_POI},
68  {"vehicle", GLO_VEHICLE},
69  {"person", GLO_PERSON},
70  {"container", GLO_CONTAINER},
71  {"undefined", GLO_MAX}
72 };
73 
74 
75 StringBijection<GUIGlObjectType> GUIGlObject::TypeNames(GUIGlObjectTypeNamesInitializer, GLO_MAX);
77 
78 // ===========================================================================
79 // method definitions
80 // ===========================================================================
81 
82 GUIGlObject::GUIGlObject(GUIGlObjectType type, const std::string& microsimID) :
83  myGLObjectType(type),
84  myMicrosimID(microsimID),
85  myPrefix(TypeNames.getString(type)) {
88 }
89 
90 
91 GUIGlObject::GUIGlObject(const std::string& prefix, GUIGlObjectType type, const std::string& microsimID) :
92  myGLObjectType(type),
93  myMicrosimID(microsimID),
94  myPrefix(prefix) {
97 }
98 
99 
101  for (std::set<GUIParameterTableWindow*>::iterator i = myParamWindows.begin(); i != myParamWindows.end(); ++i) {
102  (*i)->removeObject(this);
103  }
105 }
106 
107 
108 const std::string&
110  return myFullName;
111 }
112 
113 
114 const std::string&
117 }
118 
119 
120 GUIGlID
122  return myGlID;
123 }
124 
125 
128  UNUSED_PARAMETER(&app);
129  UNUSED_PARAMETER(&parent);
130  return 0;
131 }
132 
133 
134 const std::string&
136  return myMicrosimID;
137 }
138 
139 
140 void
141 GUIGlObject::setMicrosimID(const std::string& newID) {
142  myMicrosimID = newID;
144 }
145 
146 
149  return myGLObjectType;
150 }
151 
152 
153 void
155  UNUSED_PARAMETER(&s);
156  UNUSED_PARAMETER(parent);
157 }
158 
159 #ifdef HAVE_OSG
160 
161 osg::Node*
162 GUIGlObject::getNode() const {
163  return myOSGNode;
164 }
165 
166 
167 void
168 GUIGlObject::setNode(osg::Node* node) {
169  myOSGNode = node;
170 }
171 
172 #endif
173 
174 void
176  bool addSeparator) {
177  new MFXMenuHeader(ret, app.getBoldFont(), getFullName().c_str(), 0, 0, 0);
178  if (addSeparator) {
179  new FXMenuSeparator(ret);
180  }
181 }
182 
183 
184 void
186  new FXMenuCommand(ret, "Center", GUIIconSubSys::getIcon(ICON_RECENTERVIEW), ret, MID_CENTER);
187  if (addSeparator) {
188  new FXMenuSeparator(ret);
189  }
190 }
191 
192 
193 void
195  new FXMenuCommand(ret, "Copy name to clipboard", 0, ret, MID_COPY_NAME);
196  new FXMenuCommand(ret, "Copy typed name to clipboard", 0, ret, MID_COPY_TYPED_NAME);
197  if (addSeparator) {
198  new FXMenuSeparator(ret);
199  }
200 }
201 
202 
203 void
205  if (gSelected.isSelected(getType(), getGlID())) {
206  new FXMenuCommand(ret, "Remove From Selected", GUIIconSubSys::getIcon(ICON_FLAG_MINUS), ret, MID_REMOVESELECT);
207  } else {
208  new FXMenuCommand(ret, "Add To Selected", GUIIconSubSys::getIcon(ICON_FLAG_PLUS), ret, MID_ADDSELECT);
209  }
210  if (addSeparator) {
211  new FXMenuSeparator(ret);
212  }
213 }
214 
215 
216 void
218  new FXMenuCommand(ret, "Show Parameter", GUIIconSubSys::getIcon(ICON_APP_TABLE), ret, MID_SHOWPARS);
219  if (addSeparator) {
220  new FXMenuSeparator(ret);
221  }
222 }
223 
224 
225 void
227  new FXMenuCommand(ret, "Show Type Parameter", GUIIconSubSys::getIcon(ICON_APP_TABLE), ret, MID_SHOWTYPEPARS);
228  if (addSeparator) {
229  new FXMenuSeparator(ret);
230  }
231 }
232 
233 
234 void
236  new FXMenuCommand(ret, "Copy cursor position to clipboard", 0, ret, MID_COPY_CURSOR_POSITION);
237  if (GeoConvHelper::getFinal().usingGeoProjection()) {
238  new FXMenuCommand(ret, "Copy cursor geo-position to clipboard", 0, ret, MID_COPY_CURSOR_GEOPOSITION);
239  }
240  if (addSeparator) {
241  new FXMenuSeparator(ret);
242  }
243 }
244 
245 
246 void
248  new FXMenuCommand(ret, "Open Manipulator...", GUIIconSubSys::getIcon(ICON_MANIP), ret, MID_MANIP);
249  if (addSeparator) {
250  new FXMenuSeparator(ret);
251  }
252 }
253 
254 
255 void
257  myParamWindows.insert(t);
258 }
259 
260 
261 void
263  std::set<GUIParameterTableWindow*>::iterator i = myParamWindows.find(t);
264  if (i != myParamWindows.end()) {
265  myParamWindows.erase(i);
266  }
267 }
268 
269 
270 void
271 GUIGlObject::setPrefix(const std::string& prefix) {
272  myPrefix = prefix;
274 }
275 
276 
277 std::string
279  return myPrefix + ":" + getMicrosimID();
280 }
281 
282 
283 void
284 GUIGlObject::drawName(const Position& pos, const double scale, const GUIVisualizationTextSettings& settings, const double angle) const {
285  if (settings.show) {
286  GLHelper::drawText(getMicrosimID(), pos, GLO_MAX, settings.size / scale, settings.color, angle);
287  }
288 }
289 
290 /****************************************************************************/
291 
a prohibition
a tl-logic
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
a lane speed trigger,
Center view to object - popup entry.
Definition: GUIAppEnum.h:231
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.
a connection
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:235
Show object type parameter - popup entry.
Definition: GUIAppEnum.h:245
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:255
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:40
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:233
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:257
Show object parameter - popup entry.
Definition: GUIAppEnum.h:243
a detector
static std::string emptyString
An empty string.
Definition: StringUtils.h:85
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:253
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.
Copy cursor geo-coordinate position - popup entry.
Definition: GUIAppEnum.h:241
empty max
GUIGlObject(GUIGlObjectType type, const std::string &microsimID)
Constructor.
Definition: GUIGlObject.cpp:82
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)
draw Text with given parameters
Definition: GLHelper.cpp:455
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:239
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