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-2017 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 //#define GUIJunctionWrapper_DEBUG_DRAW_NODE_SHAPE_VERTICES
59 
60 // ===========================================================================
61 // method definitions
62 // ===========================================================================
64  : GUIGlObject(GLO_JUNCTION, junction.getID()),
65  myJunction(junction) {
66  if (myJunction.getShape().size() == 0) {
68  myBoundary = Boundary(pos.x() - 1., pos.y() - 1., pos.x() + 1., pos.y() + 1.);
69  } else {
71  }
73  myIsInner = dynamic_cast<MSInternalJunction*>(&myJunction) != 0;
74  myAmWaterway = myJunction.getIncoming().size() + myJunction.getOutgoing().size() > 0;
75  for (ConstMSEdgeVector::const_iterator it = myJunction.getIncoming().begin(); it != myJunction.getIncoming().end(); ++it) {
76  if (!(*it)->isInternal() && !isWaterway((*it)->getPermissions())) {
77  myAmWaterway = false;
78  break;
79  }
80  }
81  for (ConstMSEdgeVector::const_iterator it = myJunction.getOutgoing().begin(); it != myJunction.getOutgoing().end(); ++it) {
82  if (!(*it)->isInternal() && !isWaterway((*it)->getPermissions())) {
83  myAmWaterway = false;
84  break;
85  }
86  }
87 }
88 
89 
91 
92 
95  GUISUMOAbstractView& parent) {
96  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
97  buildPopupHeader(ret, app);
101  buildPositionCopyEntry(ret, false);
102  return ret;
103 }
104 
105 
109  return 0;
110 }
111 
112 
113 Boundary
115  Boundary b = myBoundary;
116  b.grow(1);
117  return b;
118 }
119 
120 
121 void
123  // check whether it is not too small
124  if (s.scale * myMaxSize < 1.) {
125  return;
126  }
127  if (!myIsInner && s.drawJunctionShape) {
128  glPushMatrix();
129  glPushName(getGlID());
130  const double colorValue = getColorValue(s);
132 
133  // recognize full transparency and simply don't draw
134  GLfloat color[4];
135  glGetFloatv(GL_CURRENT_COLOR, color);
136  const double exaggeration = s.junctionSize.getExaggeration(s);
137  if (color[3] != 0 && s.scale * exaggeration > s.junctionSize.minSize) {
139  shape.closePolygon();
140  if (exaggeration > 1) {
141  shape.scaleRelative(exaggeration);
142  }
143  glTranslated(0, 0, getType());
144  if (s.scale * myMaxSize < 40.) {
145  GLHelper::drawFilledPoly(shape, true);
146  } else {
148  }
149 #ifdef GUIJunctionWrapper_DEBUG_DRAW_NODE_SHAPE_VERTICES
150  GLHelper::debugVertices(shape, 80 / s.scale);
151 #endif
152  }
153  glPopName();
154  glPopMatrix();
155  }
156  if (myIsInner) {
158  } else {
160  }
161 }
162 
163 
164 double
166  switch (s.junctionColorer.getActive()) {
167  case 0:
168  if (myAmWaterway) {
169  return 1;
170  } else {
171  return 0;
172  }
173  case 1:
174  return gSelected.isSelected(getType(), getGlID()) ? 1 : 0;
175  case 2:
176  switch (myJunction.getType()) {
178  return 0;
180  return 1;
181  case NODETYPE_PRIORITY:
182  return 2;
184  return 3;
186  return 4;
188  return 5;
189  case NODETYPE_DISTRICT:
190  return 6;
191  case NODETYPE_NOJUNCTION:
192  return 7;
193  case NODETYPE_DEAD_END:
195  return 8;
196  case NODETYPE_UNKNOWN:
197  case NODETYPE_INTERNAL:
198  assert(false);
199  return 8;
201  return 9;
202  case NODETYPE_ZIPPER:
203  return 10;
205  return 11;
207  return 12;
208  }
209  default:
210  assert(false);
211  return 0;
212  }
213 }
214 
215 
216 #ifdef HAVE_OSG
217 void
218 GUIJunctionWrapper::updateColor(const GUIVisualizationSettings& s) {
219  const double colorValue = getColorValue(s);
220  const RGBColor& col = s.junctionColorer.getScheme().getColor(colorValue);
221  osg::Vec4ubArray* colors = dynamic_cast<osg::Vec4ubArray*>(myGeom->getColorArray());
222  (*colors)[0].set(col.red(), col.green(), col.blue(), col.alpha());
223  myGeom->setColorArray(colors);
224 }
225 #endif
226 
227 
228 /****************************************************************************/
229 
GUIVisualizationSizeSettings junctionSize
GUIVisualizationTextSettings junctionName
double scale
information about a lane&#39;s width (temporary, used for a single view)
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.h:99
Stores the information about how to visualize structures.
The base class for an intersection.
Definition: MSJunction.h:64
static void debugVertices(const PositionVector &shape, double size, double layer=256)
draw vertex numbers for the given shape (in a random color)
Definition: GLHelper.cpp:528
double y() const
Returns the y-position.
Definition: Position.h:68
double getColorValue(const GUIVisualizationSettings &s) const
double x() const
Returns the x-position.
Definition: Position.h:63
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
T MAX2(T a, T b)
Definition: StdDefs.h:70
double getWidth() const
Returns the width of the boudary (x-axis)
Definition: Boundary.cpp:162
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:72
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:91
bool myAmWaterway
whether this junction has only waterways as incoming and outgoing edges
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.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
static void drawFilledPolyTesselated(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:91
GUIJunctionWrapper(MSJunction &junction)
Constructor.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:439
double minSize
The minimum size to draw this object.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
bool isWaterway(SVCPermissions permissions)
Returns whether an edge with the given permission is a waterway edge.
const ConstMSEdgeVector & getIncoming() const
Definition: MSJunction.h:105
const Position & getPosition() const
Definition: MSJunction.cpp:63
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
GUIVisualizationTextSettings internalJunctionName
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:234
GUIColorer junctionColorer
The junction colorer.
const T getColor(const double value) const
virtual ~GUIJunctionWrapper()
Destructor.
double myMaxSize
The maximum size (in either x-, or y-dimension) for determining whether to draw or not...
const ConstMSEdgeVector & getOutgoing() const
Definition: MSJunction.h:109
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
double getHeight() const
Returns the height of the boundary (y-axis)
Definition: Boundary.cpp:168
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:83
void scaleRelative(double factor)
enlarges/shrinks the polygon by a factor based at the centroid
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.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
MSJunction & myJunction
A reference to the represented junction.
GUIGlID getGlID() const
Returns the numerical id of the object.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:75
bool drawJunctionShape
whether the shape of the junction should be drawn
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
void closePolygon()
ensures that the last position equals the first
GUISelectedStorage gSelected
A global holder of selected objects.
A window containing a gl-object&#39;s parameter.
const PositionVector & getShape() const
Returns this junction&#39;s shape.
Definition: MSJunction.h:93
bool myIsInner
whether this wraps an instance of MSInternalJunction
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
SumoXMLNodeType getType() const
return the type of this Junction
Definition: MSJunction.h:128
a junction