SUMO - Simulation of Urban MObility
GUIJunctionWrapper.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // }
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <string>
36 #include <utility>
37 #ifdef HAVE_OSG
38 #include <osg/Geometry>
39 #endif
40 #include <microsim/MSLane.h>
41 #include <microsim/MSEdge.h>
42 #include <microsim/MSJunction.h>
43 #include <utils/geom/Position.h>
44 #include <microsim/MSNet.h>
47 #include <gui/GUIGlobals.h>
50 #include "GUIJunctionWrapper.h"
54 #include <utils/gui/div/GLHelper.h>
57 
58 #ifdef CHECK_MEMORY_LEAKS
59 #include <foreign/nvwa/debug_new.h>
60 #endif // CHECK_MEMORY_LEAKS
61 
62 //#define GUIJunctionWrapper_DEBUG_DRAW_NODE_SHAPE_VERTICES
63 
64 // ===========================================================================
65 // method definitions
66 // ===========================================================================
68  : GUIGlObject(GLO_JUNCTION, junction.getID()),
69  myJunction(junction) {
70  if (myJunction.getShape().size() == 0) {
72  myBoundary = Boundary(pos.x() - 1., pos.y() - 1., pos.x() + 1., pos.y() + 1.);
73  } else {
75  }
77 #ifdef HAVE_INTERNAL_LANES
78  myIsInner = dynamic_cast<MSInternalJunction*>(&myJunction) != 0;
79 #else
80  myIsInner = false;
81 #endif
82  myAmWaterway = myJunction.getIncoming().size() + myJunction.getOutgoing().size() > 0;
83  for (ConstMSEdgeVector::const_iterator it = myJunction.getIncoming().begin(); it != myJunction.getIncoming().end(); ++it) {
84  if (!(*it)->isInternal() && !isWaterway((*it)->getPermissions())) {
85  myAmWaterway = false;
86  break;
87  }
88  }
89  for (ConstMSEdgeVector::const_iterator it = myJunction.getOutgoing().begin(); it != myJunction.getOutgoing().end(); ++it) {
90  if (!(*it)->isInternal() && !isWaterway((*it)->getPermissions())) {
91  myAmWaterway = false;
92  break;
93  }
94  }
95 }
96 
97 
99 
100 
103  GUISUMOAbstractView& parent) {
104  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
105  buildPopupHeader(ret, app);
109  buildPositionCopyEntry(ret, false);
110  return ret;
111 }
112 
113 
117  return 0;
118 }
119 
120 
121 Boundary
123  Boundary b = myBoundary;
124  b.grow(1);
125  return b;
126 }
127 
128 
129 void
131  // check whether it is not too small
132  if (s.scale * myMaxSize < 1.) {
133  return;
134  }
135  if (!myIsInner && s.drawJunctionShape) {
136  glPushMatrix();
137  glPushName(getGlID());
138  const SUMOReal colorValue = getColorValue(s);
140 
141  // recognize full transparency and simply don't draw
142  GLfloat color[4];
143  glGetFloatv(GL_CURRENT_COLOR, color);
144  if (color[3] != 0) {
145  glTranslated(0, 0, getType());
146  if (s.scale * myMaxSize < 40.) {
148  } else {
150  }
151 #ifdef GUIJunctionWrapper_DEBUG_DRAW_NODE_SHAPE_VERTICES
153 #endif
154  }
155  glPopName();
156  glPopMatrix();
157  }
158  if (myIsInner) {
160  } else {
162  }
163 }
164 
165 
166 SUMOReal
168  switch (s.junctionColorer.getActive()) {
169  case 0:
170  if (myAmWaterway) {
171  return 1;
172  } else {
173  return 0;
174  }
175  case 1:
176  return gSelected.isSelected(getType(), getGlID()) ? 1 : 0;
177  case 2:
178  switch (myJunction.getType()) {
180  return 0;
182  return 1;
183  case NODETYPE_PRIORITY:
184  return 2;
186  return 3;
188  return 4;
190  return 5;
191  case NODETYPE_DISTRICT:
192  return 6;
193  case NODETYPE_NOJUNCTION:
194  return 7;
195  case NODETYPE_DEAD_END:
197  return 8;
198  case NODETYPE_UNKNOWN:
199  case NODETYPE_INTERNAL:
200  assert(false);
201  return 8;
203  return 9;
204  case NODETYPE_ZIPPER:
205  return 10;
207  return 11;
209  return 12;
210  }
211  default:
212  assert(false);
213  return 0;
214  }
215 }
216 
217 
218 #ifdef HAVE_OSG
219 void
220 GUIJunctionWrapper::updateColor(const GUIVisualizationSettings& s) {
221  const SUMOReal colorValue = getColorValue(s);
222  const RGBColor& col = s.junctionColorer.getScheme().getColor(colorValue);
223  osg::Vec4ubArray* colors = dynamic_cast<osg::Vec4ubArray*>(myGeom->getColorArray());
224  (*colors)[0].set(col.red(), col.green(), col.blue(), col.alpha());
225  myGeom->setColorArray(colors);
226 }
227 #endif
228 
229 
230 /****************************************************************************/
231 
GUIVisualizationTextSettings junctionName
SUMOReal getHeight() const
Returns the height of the boundary.
Definition: Boundary.cpp:142
SUMOReal getWidth() const
Returns the width of the boudary.
Definition: Boundary.cpp:136
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
static void debugVertices(const PositionVector &shape, SUMOReal size, SUMOReal layer=256)
draw vertex numbers for the given shape (in a random color)
Definition: GLHelper.cpp:518
Stores the information about how to visualize structures.
The base class for an intersection.
Definition: MSJunction.h:64
const PositionVector & getShape() const
Returns this junction&#39;s shape.
Definition: MSJunction.h:93
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
T MAX2(T a, T b)
Definition: StdDefs.h:75
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
static void drawFilledPoly(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:76
bool myAmWaterway
whether this junction has only waterways as incoming and outgoing edges
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
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.
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:123
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
SUMOReal myMaxSize
The maximum size (in either x-, or y-dimension) for determining whether to draw or not...
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:91
static void drawFilledPolyTesselated(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:95
GUIJunctionWrapper(MSJunction &junction)
Constructor.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:180
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:443
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
bool isWaterway(SVCPermissions permissions)
Returns whether an edge with the given permission is a waterway edge.
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.h:99
const T getColor(const SUMOReal value) const
GUIVisualizationTextSettings internalJunctionName
GUIColorer junctionColorer
The junction colorer.
SumoXMLNodeType getType() const
return the type of this Junction
Definition: MSJunction.h:122
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
SUMOReal getColorValue(const GUIVisualizationSettings &s) const
const ConstMSEdgeVector & getOutgoing() const
Definition: MSJunction.h:109
virtual ~GUIJunctionWrapper()
Destructor.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Boundary & grow(SUMOReal by)
extends the boundary by the given amount
Definition: Boundary.cpp:201
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
Boundary myBoundary
The represented junction&#39;s boundary.
The popup menu of a globject.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
MSJunction & myJunction
A reference to the represented junction.
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:83
#define SUMOReal
Definition: config.h:213
bool drawJunctionShape
whether the shape of the junction should be drawn
const ConstMSEdgeVector & getIncoming() const
Definition: MSJunction.h:105
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:75
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
GUISelectedStorage gSelected
A global holder of selected objects.
A window containing a gl-object&#39;s parameter.
bool myIsInner
whether this wraps an instance of MSInternalJunction
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
const Position & getPosition() const
Definition: MSJunction.cpp:67
a junction