Eclipse 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-2019 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 <utils/geom/GeomHelper.h>
38 #include <microsim/MSNet.h>
43 #include <gui/GUIGlobals.h>
46 #include "GUIJunctionWrapper.h"
50 #include <utils/gui/div/GLHelper.h>
52 
53 //#define GUIJunctionWrapper_DEBUG_DRAW_NODE_SHAPE_VERTICES
54 
55 // ===========================================================================
56 // method definitions
57 // ===========================================================================
58 GUIJunctionWrapper::GUIJunctionWrapper(MSJunction& junction, const std::string& tllID):
59  GUIGlObject(GLO_JUNCTION, junction.getID()),
60  myJunction(junction),
61  myTLLID(tllID) {
62  if (myJunction.getShape().size() == 0) {
64  myBoundary = Boundary(pos.x() - 1., pos.y() - 1., pos.x() + 1., pos.y() + 1.);
65  } else {
67  }
70  myAmWaterway = myJunction.getIncoming().size() + myJunction.getOutgoing().size() > 0;
71  myAmRailway = myJunction.getIncoming().size() + myJunction.getOutgoing().size() > 0;
72  for (auto it = myJunction.getIncoming().begin(); it != myJunction.getIncoming().end() && (myAmWaterway || myAmRailway); ++it) {
73  if (!(*it)->isInternal()) {
74  if (!isWaterway((*it)->getPermissions())) {
75  myAmWaterway = false;
76  }
77  if (!isRailway((*it)->getPermissions())) {
78  myAmRailway = false;
79  }
80  }
81  }
82  for (auto it = myJunction.getOutgoing().begin(); it != myJunction.getOutgoing().end() && (myAmWaterway || myAmRailway); ++it) {
83  if (!(*it)->isInternal()) {
84  if (!isWaterway((*it)->getPermissions())) {
85  myAmWaterway = false;
86  }
87  if (!isRailway((*it)->getPermissions())) {
88  myAmRailway = false;
89  }
90  }
91  }
92 }
93 
94 
96 
97 
100  GUISUMOAbstractView& parent) {
101  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
102  buildPopupHeader(ret, app);
107  buildPositionCopyEntry(ret, false);
108  return ret;
109 }
110 
111 
115  new GUIParameterTableWindow(app, *this, 12 + (int)myJunction.getParametersMap().size());
116  // add items
117  ret->mkItem("type", false, toString(myJunction.getType()));
118  // close building
119  ret->closeBuilding(&myJunction);
120  return ret;
121 }
122 
123 
124 Boundary
126  Boundary b = myBoundary;
127  b.grow(1);
128  return b;
129 }
130 
131 
132 void
134  if (!myIsInternal && s.drawJunctionShape) {
135  // check whether it is not too small
136  const double exaggeration = s.junctionSize.getExaggeration(s, this, 4);
137  if (s.scale * exaggeration >= s.junctionSize.minSize) {
138  glPushMatrix();
139  glPushName(getGlID());
140  const double colorValue = getColorValue(s, s.junctionColorer.getActive());
141  const RGBColor color = s.junctionColorer.getScheme().getColor(colorValue);
142  GLHelper::setColor(color);
143 
144  // recognize full transparency and simply don't draw
145  if (color.alpha() != 0) {
147  shape.closePolygon();
148  if (exaggeration > 1) {
149  shape.scaleRelative(exaggeration);
150  }
151  glTranslated(0, 0, getType());
152  if (s.scale * myMaxSize < 40.) {
153  GLHelper::drawFilledPoly(shape, true);
154  } else {
156  }
157 #ifdef GUIJunctionWrapper_DEBUG_DRAW_NODE_SHAPE_VERTICES
158  GLHelper::debugVertices(shape, 80 / s.scale);
159 #endif
160  // make small junctions more visible when coloring by type
162  glTranslated(myJunction.getPosition().x(), myJunction.getPosition().y(), getType() + 0.05);
163  GLHelper::drawFilledCircle(2 * exaggeration, 12);
164  }
165  }
166  glPopName();
167  glPopMatrix();
168  }
169  }
170  if (myIsInternal) {
172  } else {
174  if (s.tlsPhaseIndex.show && myTLLID != "") {
176  const int index = active->getCurrentPhaseIndex();
177  const std::string& name = active->getCurrentPhaseDef().getName();
179  if (name != "") {
180  const Position offset = Position(0, 0.8 * s.tlsPhaseIndex.scaledSize(s.scale)).rotateAround2D(DEG2RAD(-s.angle), Position(0, 0));
182  }
183  }
184  }
185 }
186 
187 
188 double
189 GUIJunctionWrapper::getColorValue(const GUIVisualizationSettings& /* s */, int activeScheme) const {
190  switch (activeScheme) {
191  case 0:
192  if (myAmWaterway) {
193  return 1;
194  } else if (myAmRailway && MSNet::getInstance()->hasInternalLinks()) {
195  return 2;
196  } else {
197  return 0;
198  }
199  case 1:
200  return gSelected.isSelected(getType(), getGlID()) ? 1 : 0;
201  case 2:
202  switch (myJunction.getType()) {
204  return 0;
206  return 1;
207  case NODETYPE_PRIORITY:
208  return 2;
210  return 3;
212  return 4;
214  return 5;
215  case NODETYPE_DISTRICT:
216  return 6;
217  case NODETYPE_NOJUNCTION:
218  return 7;
219  case NODETYPE_DEAD_END:
221  return 8;
222  case NODETYPE_UNKNOWN:
223  case NODETYPE_INTERNAL:
224  assert(false);
225  return 8;
227  return 9;
228  case NODETYPE_ZIPPER:
229  return 10;
231  return 11;
233  return 12;
234  }
235  case 3:
236  return myJunction.getPosition().z();
237  default:
238  assert(false);
239  return 0;
240  }
241 }
242 
243 #ifdef HAVE_OSG
244 void
245 GUIJunctionWrapper::updateColor(const GUIVisualizationSettings& s) {
246  const double colorValue = getColorValue(s, s.junctionColorer.getActive());
247  const RGBColor& col = s.junctionColorer.getScheme().getColor(colorValue);
248  osg::Vec4ubArray* colors = dynamic_cast<osg::Vec4ubArray*>(myGeom->getColorArray());
249  (*colors)[0].set(col.red(), col.green(), col.blue(), col.alpha());
250  myGeom->setColorArray(colors);
251 }
252 #endif
253 
254 
255 /****************************************************************************/
256 
GUIVisualizationSizeSettings junctionSize
GUIVisualizationTextSettings junctionName
virtual const MSPhaseDefinition & getCurrentPhaseDef() const =0
Returns the definition of the current phase.
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.
GUIJunctionWrapper(MSJunction &junction, const std::string &tllID)
Constructor.
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:803
double y() const
Returns the y-position.
Definition: Position.h:62
static void drawTextSettings(const GUIVisualizationTextSettings &settings, const std::string &text, const Position &pos, const double scale, const double angle=0, const double layer=2048)
Definition: GLHelper.cpp:701
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.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
T MAX2(T a, T b)
Definition: StdDefs.h:80
double getWidth() const
Returns the width of the boudary (x-axis)
Definition: Boundary.cpp:155
bool myAmRailway
whether this junction has only railways as incoming and outgoing edges
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:82
virtual int getCurrentPhaseIndex() const =0
Returns the current index within the program.
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
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permission is a railway edge.
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:348
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:101
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:48
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
double minSize
The minimum size to draw this object.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
MSTrafficLightLogic * getActive(const std::string &id) const
Returns the active program of a named tls.
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:410
A list of positions.
double scaledSize(double scale, double constFactor=0.1) const
get scale size
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
#define DEG2RAD(x)
Definition: GeomHelper.h:38
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
GUIVisualizationTextSettings tlsPhaseIndex
void scaleRelative(double factor)
enlarges/shrinks the polygon by a factor based at the centroid
Boundary myBoundary
The represented junction&#39;s boundary.
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const
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.
The parent class for traffic light logics.
bool drawJunctionShape
whether the shape of the junction should be drawn
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
const std::string & getName() const
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
const std::string myTLLID
the associated traffic light or ""
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