SUMO - Simulation of Urban MObility
GUIJunctionWrapper.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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
19 // }
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <string>
29 #include <utility>
30 #ifdef HAVE_OSG
31 #include <osg/Geometry>
32 #endif
33 #include <microsim/MSLane.h>
34 #include <microsim/MSEdge.h>
35 #include <microsim/MSJunction.h>
36 #include <utils/geom/Position.h>
37 #include <microsim/MSNet.h>
40 #include <gui/GUIGlobals.h>
43 #include "GUIJunctionWrapper.h"
47 #include <utils/gui/div/GLHelper.h>
49 
50 //#define GUIJunctionWrapper_DEBUG_DRAW_NODE_SHAPE_VERTICES
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
56  : GUIGlObject(GLO_JUNCTION, junction.getID()),
57  myJunction(junction) {
58  if (myJunction.getShape().size() == 0) {
60  myBoundary = Boundary(pos.x() - 1., pos.y() - 1., pos.x() + 1., pos.y() + 1.);
61  } else {
63  }
66  myAmWaterway = myJunction.getIncoming().size() + myJunction.getOutgoing().size() > 0;
67  for (ConstMSEdgeVector::const_iterator it = myJunction.getIncoming().begin(); it != myJunction.getIncoming().end(); ++it) {
68  if (!(*it)->isInternal() && !isWaterway((*it)->getPermissions())) {
69  myAmWaterway = false;
70  break;
71  }
72  }
73  for (ConstMSEdgeVector::const_iterator it = myJunction.getOutgoing().begin(); it != myJunction.getOutgoing().end(); ++it) {
74  if (!(*it)->isInternal() && !isWaterway((*it)->getPermissions())) {
75  myAmWaterway = false;
76  break;
77  }
78  }
79 }
80 
81 
83 
84 
87  GUISUMOAbstractView& parent) {
88  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
89  buildPopupHeader(ret, app);
94  buildPositionCopyEntry(ret, false);
95  return ret;
96 }
97 
98 
102  new GUIParameterTableWindow(app, *this, 12 + (int)myJunction.getParametersMap().size());
103  // add items
104  ret->mkItem("type", false, toString(myJunction.getType()));
105  // close building
106  ret->closeBuilding(&myJunction);
107  return ret;
108 }
109 
110 
111 Boundary
113  Boundary b = myBoundary;
114  b.grow(1);
115  return b;
116 }
117 
118 
119 void
121  if (!myIsInternal && s.drawJunctionShape) {
122  // check whether it is not too small
123  const double exaggeration = s.junctionSize.getExaggeration(s, this, 4);
124  if (s.scale * exaggeration >= s.junctionSize.minSize) {
125  glPushMatrix();
126  glPushName(getGlID());
127  const double colorValue = getColorValue(s);
129 
130  // recognize full transparency and simply don't draw
131  GLfloat color[4];
132  glGetFloatv(GL_CURRENT_COLOR, color);
133  if (color[3] != 0) {
135  shape.closePolygon();
136  if (exaggeration > 1) {
137  shape.scaleRelative(exaggeration);
138  }
139  glTranslated(0, 0, getType());
140  if (s.scale * myMaxSize < 40.) {
141  GLHelper::drawFilledPoly(shape, true);
142  } else {
144  }
145 #ifdef GUIJunctionWrapper_DEBUG_DRAW_NODE_SHAPE_VERTICES
146  GLHelper::debugVertices(shape, 80 / s.scale);
147 #endif
148  // make small junctions more visible when coloring by type
150  glTranslated(myJunction.getPosition().x(), myJunction.getPosition().y(), getType() + 0.05);
151  GLHelper::drawFilledCircle(2 * exaggeration, 12);
152  }
153  }
154  glPopName();
155  glPopMatrix();
156  }
157  }
158  if (myIsInternal) {
160  } else {
162  }
163 }
164 
165 
166 double
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  case 3:
212  return myJunction.getPosition().z();
213  default:
214  assert(false);
215  return 0;
216  }
217 }
218 
219 
220 #ifdef HAVE_OSG
221 void
222 GUIJunctionWrapper::updateColor(const GUIVisualizationSettings& s) {
223  const double colorValue = getColorValue(s);
224  const RGBColor& col = s.junctionColorer.getScheme().getColor(colorValue);
225  osg::Vec4ubArray* colors = dynamic_cast<osg::Vec4ubArray*>(myGeom->getColorArray());
226  (*colors)[0].set(col.red(), col.green(), col.blue(), col.alpha());
227  myGeom->setColorArray(colors);
228 }
229 #endif
230 
231 
232 /****************************************************************************/
233 
GUIVisualizationSizeSettings junctionSize
GUIVisualizationTextSettings junctionName
double scale
information about a lane&#39;s width (temporary, used for a single view)
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
double z() const
Returns the z-position.
Definition: Position.h:67
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:84
Stores the information about how to visualize structures.
The base class for an intersection.
Definition: MSJunction.h:61
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:736
double y() const
Returns the y-position.
Definition: Position.h:62
double getColorValue(const GUIVisualizationSettings &s) const
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
double x() const
Returns the x-position.
Definition: Position.h:57
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:76
double getWidth() const
Returns the width of the boudary (x-axis)
Definition: Boundary.cpp:155
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:78
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:77
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
bool myAmWaterway
whether this junction has only waterways as incoming and outgoing edges
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:344
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:42
bool myIsInternal
whether this wraps an instance of MSInternalJunction
static void drawFilledPolyTesselated(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:97
GUIJunctionWrapper(MSJunction &junction)
Constructor.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:573
double minSize
The minimum size to draw this object.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
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:102
const Position & getPosition() const
Definition: MSJunction.cpp:69
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:301
GUIColorer junctionColorer
The junction colorer.
double angle
The current view rotation angle.
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:108
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:161
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:70
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.
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
GUIGlID getGlID() const
Returns the numerical id of the object.
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:63
bool drawJunctionShape
whether the shape of the junction should be drawn
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
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:90
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
SumoXMLNodeType getType() const
return the type of this Junction
Definition: MSJunction.h:127
a junction