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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // Base class for all objects that may be displayed within the openGL-gui
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <stack>
35 #include <utils/common/ToString.h>
45 #include <utils/gui/div/GLHelper.h>
46 #include "GUIGlObject.h"
47 #include "GUIGlObjectStorage.h"
48 
49 // ===========================================================================
50 // static members
51 // ===========================================================================
52 
54  {"network", GLO_NETWORK},
55  {"edge", GLO_EDGE},
56  {"lane", GLO_LANE},
57  {"junction", GLO_JUNCTION},
58  {"crossing", GLO_CROSSING},
59  {"connection", GLO_CONNECTION},
60  {"prohibition", GLO_PROHIBITION},
61  {"tlLogic", GLO_TLLOGIC},
62  {"detector", GLO_DETECTOR},
63  {"trigger", GLO_TRIGGER},
64  {"additional", GLO_ADDITIONAL},
65  {"polygon", GLO_POLYGON},
66  {"poi", GLO_POI},
67  {"vehicle", GLO_VEHICLE},
68  {"person", GLO_PERSON},
69  {"container", GLO_CONTAINER},
70  {"undefined", GLO_MAX}
71 };
72 
73 
74 StringBijection<GUIGlObjectType> GUIGlObject::TypeNames(GUIGlObjectTypeNamesInitializer, GLO_MAX);
76 
77 // ===========================================================================
78 // method definitions
79 // ===========================================================================
80 
81 GUIGlObject::GUIGlObject(GUIGlObjectType type, const std::string& microsimID) :
82  myGLObjectType(type),
83  myMicrosimID(microsimID),
84  myPrefix(TypeNames.getString(type)) {
87 }
88 
89 
90 GUIGlObject::GUIGlObject(const std::string& prefix, GUIGlObjectType type, const std::string& microsimID) :
91  myGLObjectType(type),
92  myMicrosimID(microsimID),
93  myPrefix(prefix) {
96 }
97 
98 
100  for (std::set<GUIParameterTableWindow*>::iterator i = myParamWindows.begin(); i != myParamWindows.end(); ++i) {
101  (*i)->removeObject(this);
102  }
104 }
105 
106 
107 const std::string&
109  return myFullName;
110 }
111 
112 
113 const std::string&
116 }
117 
118 
119 GUIGlID
121  return myGlID;
122 }
123 
124 
127  UNUSED_PARAMETER(&app);
128  UNUSED_PARAMETER(&parent);
129  return 0;
130 }
131 
132 
133 const std::string&
135  return myMicrosimID;
136 }
137 
138 
139 void
140 GUIGlObject::setMicrosimID(const std::string& newID) {
141  myMicrosimID = newID;
143 }
144 
145 
148  return myGLObjectType;
149 }
150 
151 
152 void
154  UNUSED_PARAMETER(&s);
155  UNUSED_PARAMETER(parent);
156 }
157 
158 #ifdef HAVE_OSG
159 
160 osg::Node*
161 GUIGlObject::getNode() const {
162  return myOSGNode;
163 }
164 
165 
166 void
167 GUIGlObject::setNode(osg::Node* node) {
168  myOSGNode = node;
169 }
170 
171 #endif
172 
173 void
175  bool addSeparator) {
176  new MFXMenuHeader(ret, app.getBoldFont(), getFullName().c_str(), 0, 0, 0);
177  if (addSeparator) {
178  new FXMenuSeparator(ret);
179  }
180 }
181 
182 
183 void
185  new FXMenuCommand(ret, "Center", GUIIconSubSys::getIcon(ICON_RECENTERVIEW), ret, MID_CENTER);
186  if (addSeparator) {
187  new FXMenuSeparator(ret);
188  }
189 }
190 
191 
192 void
194  new FXMenuCommand(ret, "Copy name to clipboard", 0, ret, MID_COPY_NAME);
195  new FXMenuCommand(ret, "Copy typed name to clipboard", 0, ret, MID_COPY_TYPED_NAME);
196  if (addSeparator) {
197  new FXMenuSeparator(ret);
198  }
199 }
200 
201 
202 void
204  if (gSelected.isSelected(getType(), getGlID())) {
205  new FXMenuCommand(ret, "Remove From Selected", GUIIconSubSys::getIcon(ICON_FLAG_MINUS), ret, MID_REMOVESELECT);
206  } else {
207  new FXMenuCommand(ret, "Add To Selected", GUIIconSubSys::getIcon(ICON_FLAG_PLUS), ret, MID_ADDSELECT);
208  }
209  if (addSeparator) {
210  new FXMenuSeparator(ret);
211  }
212 }
213 
214 
215 void
217  new FXMenuCommand(ret, "Show Parameter", GUIIconSubSys::getIcon(ICON_APP_TABLE), ret, MID_SHOWPARS);
218  if (addSeparator) {
219  new FXMenuSeparator(ret);
220  }
221 }
222 
223 
224 void
226  new FXMenuCommand(ret, "Show Type Parameter", GUIIconSubSys::getIcon(ICON_APP_TABLE), ret, MID_SHOWTYPEPARS);
227  if (addSeparator) {
228  new FXMenuSeparator(ret);
229  }
230 }
231 
232 
233 void
235  new FXMenuCommand(ret, "Copy cursor position to clipboard", 0, ret, MID_COPY_CURSOR_POSITION);
236  if (GeoConvHelper::getFinal().usingGeoProjection()) {
237  new FXMenuCommand(ret, "Copy cursor geo-position to clipboard", 0, ret, MID_COPY_CURSOR_GEOPOSITION);
238  }
239  if (addSeparator) {
240  new FXMenuSeparator(ret);
241  }
242 }
243 
244 
245 void
247  new FXMenuCommand(ret, "Open Manipulator...", GUIIconSubSys::getIcon(ICON_MANIP), ret, MID_MANIP);
248  if (addSeparator) {
249  new FXMenuSeparator(ret);
250  }
251 }
252 
253 
254 void
256  myParamWindows.insert(t);
257 }
258 
259 
260 void
262  std::set<GUIParameterTableWindow*>::iterator i = myParamWindows.find(t);
263  if (i != myParamWindows.end()) {
264  myParamWindows.erase(i);
265  }
266 }
267 
268 
269 void
270 GUIGlObject::setPrefix(const std::string& prefix) {
271  myPrefix = prefix;
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
324  return myPrefix + ":" + getMicrosimID();
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.size / scale, settings.color, angle);
332  }
333 }
334 
335 /****************************************************************************/
336 
a prohibition
Show object parameter - popup entry.
Definition: GUIAppEnum.h:240
a tl-logic
a lane speed trigger,
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 ...
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:254
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.
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:487
Center view to object - popup entry.
Definition: GUIAppEnum.h:226
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.
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
Remove from selected items - Menu Etry.
Definition: GUIAppEnum.h:252
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)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
a person
std::string myMicrosimID
ID of GL object.
Definition: GUIGlObject.h:260
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
a tl-logic
virtual ~GUIGlObject()
Destructor.
Definition: GUIGlObject.cpp:99
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
Copy object name - popup entry.
Definition: GUIAppEnum.h:228
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Copy cursor geo-coordinate position - popup entry.
Definition: GUIAppEnum.h:236
a detector
Show object type parameter - popup entry.
Definition: GUIAppEnum.h:242
static std::string emptyString
An empty string.
Definition: StringUtils.h:84
const GUIGlObjectType myGLObjectType
The type of the object.
Definition: GUIGlObject.h:257
unsigned int GUIGlID
Definition: GUIGlObject.h:49
compound additional
void buildShowManipulatorPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the manipulator window.
Open the object&#39;s manipulator.
Definition: GUIAppEnum.h:254
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:75
static const GUIGlID INVALID_ID
Definition: GUIGlObject.h:76
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:283
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)
Copy cursor position - popup entry.
Definition: GUIAppEnum.h:234
The network - empty.
std::string myPrefix
prefix of GL Object
Definition: GUIGlObject.h:263
std::string myFullName
full name of GL Object
Definition: GUIGlObject.h:266
GUIGlID getGlID() const
Returns the numerical id of the object.
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:230
GUIGlID registerObject(GUIGlObject *object, const std::string &fullName)
Registers an object.
empty max
GUIGlObject(GUIGlObjectType type, const std::string &microsimID)
Constructor.
Definition: GUIGlObject.cpp:81
const std::string & getFullName() const
std::set< GUIParameterTableWindow * > myParamWindows
Parameter table windows which refer to this object.
Definition: GUIGlObject.h:269
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.
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
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
Add to selected items - menu entry.
Definition: GUIAppEnum.h:250