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-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 /****************************************************************************/
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 <utility>
36 #ifdef HAVE_OSG
37 #include <osg/Geometry>
38 #endif
39 #include <microsim/MSLane.h>
40 #include <microsim/MSEdge.h>
41 #include <microsim/MSJunction.h>
42 #include <utils/geom/Position.h>
43 #include <microsim/MSNet.h>
46 #include <gui/GUIGlobals.h>
49 #include "GUIJunctionWrapper.h"
53 #include <utils/gui/div/GLHelper.h>
55 
56 //#define GUIJunctionWrapper_DEBUG_DRAW_NODE_SHAPE_VERTICES
57 
58 // ===========================================================================
59 // method definitions
60 // ===========================================================================
62  : GUIGlObject(GLO_JUNCTION, junction.getID()),
63  myJunction(junction) {
64  if (myJunction.getShape().size() == 0) {
66  myBoundary = Boundary(pos.x() - 1., pos.y() - 1., pos.x() + 1., pos.y() + 1.);
67  } else {
69  }
72  myAmWaterway = myJunction.getIncoming().size() + myJunction.getOutgoing().size() > 0;
73  for (ConstMSEdgeVector::const_iterator it = myJunction.getIncoming().begin(); it != myJunction.getIncoming().end(); ++it) {
74  if (!(*it)->isInternal() && !isWaterway((*it)->getPermissions())) {
75  myAmWaterway = false;
76  break;
77  }
78  }
79  for (ConstMSEdgeVector::const_iterator it = myJunction.getOutgoing().begin(); it != myJunction.getOutgoing().end(); ++it) {
80  if (!(*it)->isInternal() && !isWaterway((*it)->getPermissions())) {
81  myAmWaterway = false;
82  break;
83  }
84  }
85 }
86 
87 
89 
90 
93  GUISUMOAbstractView& parent) {
94  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
95  buildPopupHeader(ret, app);
100  buildPositionCopyEntry(ret, false);
101  return ret;
102 }
103 
104 
108  new GUIParameterTableWindow(app, *this, 12 + (int)myJunction.getMap().size());
109  // add items
110  ret->mkItem("type", false, toString(myJunction.getType()));
111  // close building
112  ret->closeBuilding(&myJunction);
113  return ret;
114 }
115 
116 
117 Boundary
119  Boundary b = myBoundary;
120  b.grow(1);
121  return b;
122 }
123 
124 
125 void
127  // check whether it is not too small
128  if (s.scale * myMaxSize < 1.) {
129  return;
130  }
131  if (!myIsInternal && s.drawJunctionShape) {
132  glPushMatrix();
133  glPushName(getGlID());
134  const double colorValue = getColorValue(s);
136 
137  // recognize full transparency and simply don't draw
138  GLfloat color[4];
139  glGetFloatv(GL_CURRENT_COLOR, color);
140  const double exaggeration = s.junctionSize.getExaggeration(s);
141  if (color[3] != 0 && s.scale * exaggeration > s.junctionSize.minSize) {
143  shape.closePolygon();
144  if (exaggeration > 1) {
145  shape.scaleRelative(exaggeration);
146  }
147  glTranslated(0, 0, getType());
148  if (s.scale * myMaxSize < 40.) {
149  GLHelper::drawFilledPoly(shape, true);
150  } else {
152  }
153 #ifdef GUIJunctionWrapper_DEBUG_DRAW_NODE_SHAPE_VERTICES
154  GLHelper::debugVertices(shape, 80 / s.scale);
155 #endif
156  }
157  glPopName();
158  glPopMatrix();
159  }
160  if (myIsInternal) {
162  } else {
164  }
165 }
166 
167 
168 double
170  switch (s.junctionColorer.getActive()) {
171  case 0:
172  if (myAmWaterway) {
173  return 1;
174  } else {
175  return 0;
176  }
177  case 1:
178  return gSelected.isSelected(getType(), getGlID()) ? 1 : 0;
179  case 2:
180  switch (myJunction.getType()) {
182  return 0;
184  return 1;
185  case NODETYPE_PRIORITY:
186  return 2;
188  return 3;
190  return 4;
192  return 5;
193  case NODETYPE_DISTRICT:
194  return 6;
195  case NODETYPE_NOJUNCTION:
196  return 7;
197  case NODETYPE_DEAD_END:
199  return 8;
200  case NODETYPE_UNKNOWN:
201  case NODETYPE_INTERNAL:
202  assert(false);
203  return 8;
205  return 9;
206  case NODETYPE_ZIPPER:
207  return 10;
209  return 11;
211  return 12;
212  }
213  case 3:
214  return myJunction.getPosition().z();
215  default:
216  assert(false);
217  return 0;
218  }
219 }
220 
221 
222 #ifdef HAVE_OSG
223 void
224 GUIJunctionWrapper::updateColor(const GUIVisualizationSettings& s) {
225  const double colorValue = getColorValue(s);
226  const RGBColor& col = s.junctionColorer.getScheme().getColor(colorValue);
227  osg::Vec4ubArray* colors = dynamic_cast<osg::Vec4ubArray*>(myGeom->getColorArray());
228  (*colors)[0].set(col.red(), col.green(), col.blue(), col.alpha());
229  myGeom->setColorArray(colors);
230 }
231 #endif
232 
233 
234 /****************************************************************************/
235 
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:72
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:89
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:556
double y() const
Returns the y-position.
Definition: Position.h:67
double getColorValue(const GUIVisualizationSettings &s) const
double x() const
Returns the x-position.
Definition: Position.h:62
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:73
double getWidth() const
Returns the width of the boudary (x-axis)
Definition: Boundary.cpp:161
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:83
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:82
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
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:47
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:102
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:55
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:449
double minSize
The minimum size to draw this object.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
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:62
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.
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:167
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:75
const std::map< std::string, std::string > & getMap() const
Returns the inner key/value map.
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:68
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
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
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
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