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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
22 // }
23 /****************************************************************************/
24 #include <config.h>
25 
26 #include <string>
27 #include <utility>
28 #ifdef HAVE_OSG
29 #ifdef _MSC_VER
30 #pragma warning(push)
31 #pragma warning(disable: 4275) // do not warn about the DLL interface for OSG
32 #endif
33 #include <osg/Geometry>
34 #ifdef _MSC_VER
35 #pragma warning(pop)
36 #endif
37 #endif
38 #include <microsim/MSLane.h>
39 #include <microsim/MSEdge.h>
40 #include <microsim/MSJunction.h>
41 #include <utils/geom/Position.h>
42 #include <utils/geom/GeomHelper.h>
43 #include <microsim/MSNet.h>
48 #include <gui/GUIGlobals.h>
51 #include "GUIJunctionWrapper.h"
55 #include <utils/gui/div/GLHelper.h>
57 
58 //#define GUIJunctionWrapper_DEBUG_DRAW_NODE_SHAPE_VERTICES
59 
60 // ===========================================================================
61 // method definitions
62 // ===========================================================================
63 GUIJunctionWrapper::GUIJunctionWrapper(MSJunction& junction, const std::string& tllID):
64  GUIGlObject(GLO_JUNCTION, junction.getID()),
65  myJunction(junction),
66  myTLLID(tllID) {
67  if (myJunction.getShape().size() == 0) {
69  myBoundary = Boundary(pos.x() - 1., pos.y() - 1., pos.x() + 1., pos.y() + 1.);
70  } else {
72  }
75  myAmWaterway = myJunction.getIncoming().size() + myJunction.getOutgoing().size() > 0;
76  myAmRailway = myJunction.getIncoming().size() + myJunction.getOutgoing().size() > 0;
77  for (auto it = myJunction.getIncoming().begin(); it != myJunction.getIncoming().end() && (myAmWaterway || myAmRailway); ++it) {
78  if (!(*it)->isInternal()) {
79  if (!isWaterway((*it)->getPermissions())) {
80  myAmWaterway = false;
81  }
82  if (!isRailway((*it)->getPermissions())) {
83  myAmRailway = false;
84  }
85  }
86  }
87  for (auto it = myJunction.getOutgoing().begin(); it != myJunction.getOutgoing().end() && (myAmWaterway || myAmRailway); ++it) {
88  if (!(*it)->isInternal()) {
89  if (!isWaterway((*it)->getPermissions())) {
90  myAmWaterway = false;
91  }
92  if (!isRailway((*it)->getPermissions())) {
93  myAmRailway = false;
94  }
95  }
96  }
97 }
98 
99 
101 
102 
105  GUISUMOAbstractView& parent) {
106  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
107  buildPopupHeader(ret, app);
112  buildPositionCopyEntry(ret, false);
113  return ret;
114 }
115 
116 
119  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
120  // add items
121  ret->mkItem("type", false, toString(myJunction.getType()));
122  ret->mkItem("name", false, myJunction.getName());
123  // close building
124  ret->closeBuilding(&myJunction);
125  return ret;
126 }
127 
128 
129 Boundary
131  Boundary b = myBoundary;
132  b.grow(1);
133  return b;
134 }
135 
136 const std::string
138  return myJunction.getName();
139 }
140 
141 void
143  if (!myIsInternal && s.drawJunctionShape) {
144  // check whether it is not too small
145  const double exaggeration = s.junctionSize.getExaggeration(s, this, 4);
146  if (s.scale * exaggeration >= s.junctionSize.minSize) {
147  glPushMatrix();
148  glPushName(getGlID());
149  const double colorValue = getColorValue(s, s.junctionColorer.getActive());
150  const RGBColor color = s.junctionColorer.getScheme().getColor(colorValue);
151  GLHelper::setColor(color);
152 
153  // recognize full transparency and simply don't draw
154  if (color.alpha() != 0) {
156  shape.closePolygon();
157  if (exaggeration > 1) {
158  shape.scaleRelative(exaggeration);
159  }
160  glTranslated(0, 0, getType());
161  if (s.scale * myMaxSize < 40.) {
162  GLHelper::drawFilledPoly(shape, true);
163  } else {
165  }
166 #ifdef GUIJunctionWrapper_DEBUG_DRAW_NODE_SHAPE_VERTICES
167  GLHelper::debugVertices(shape, 80 / s.scale);
168 #endif
169  // make small junctions more visible when coloring by type
171  glTranslated(myJunction.getPosition().x(), myJunction.getPosition().y(), getType() + 0.05);
172  GLHelper::drawFilledCircle(2 * exaggeration, 12);
173  }
174  }
175  glPopName();
176  glPopMatrix();
177  }
178  }
179  if (myIsInternal) {
181  } else {
183  if (s.junctionName.show && myJunction.getName() != "") {
185  }
186  if ((s.tlsPhaseIndex.show || s.tlsPhaseName.show) && myTLLID != "") {
188  if (s.tlsPhaseIndex.show) {
189  const int index = active->getCurrentPhaseIndex();
191  }
192  if (s.tlsPhaseName.show) {
193  const std::string& name = active->getCurrentPhaseDef().getName();
194  if (name != "") {
195  const Position offset = (s.tlsPhaseIndex.show ?
197  : Position(0, 0));
199  }
200  }
201  }
202  }
203 }
204 
205 
206 double
207 GUIJunctionWrapper::getColorValue(const GUIVisualizationSettings& /* s */, int activeScheme) const {
208  switch (activeScheme) {
209  case 0:
210  if (myAmWaterway) {
211  return 1;
212  } else if (myAmRailway && MSNet::getInstance()->hasInternalLinks()) {
213  return 2;
214  } else {
215  return 0;
216  }
217  case 1:
218  return gSelected.isSelected(getType(), getGlID()) ? 1 : 0;
219  case 2:
220  switch (myJunction.getType()) {
222  return 0;
224  return 1;
226  return 2;
228  return 3;
230  return 4;
232  return 5;
234  return 6;
236  return 7;
239  return 8;
242  assert(false);
243  return 8;
245  return 9;
247  return 10;
249  return 11;
251  return 12;
252  default:
253  assert(false);
254  return 0;
255  }
256  case 3:
257  return myJunction.getPosition().z();
258  default:
259  assert(false);
260  return 0;
261  }
262 }
263 
264 #ifdef HAVE_OSG
265 void
266 GUIJunctionWrapper::updateColor(const GUIVisualizationSettings& s) {
267  const double colorValue = getColorValue(s, s.junctionColorer.getActive());
268  const RGBColor& col = s.junctionColorer.getScheme().getColor(colorValue);
269  osg::Vec4ubArray* colors = dynamic_cast<osg::Vec4ubArray*>(myGeom->getColorArray());
270  (*colors)[0].set(col.red(), col.green(), col.blue(), col.alpha());
271  myGeom->setColorArray(colors);
272 }
273 #endif
274 
275 
276 /****************************************************************************/
@ GLO_JUNCTION
a junction
GUISelectedStorage gSelected
A global holder of selected objects.
#define DEG2RAD(x)
Definition: GeomHelper.h:35
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permission is a railway edge.
bool isWaterway(SVCPermissions permissions)
Returns whether an edge with the given permission is a waterway edge.
T MAX2(T a, T b)
Definition: StdDefs.h:79
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
double getHeight() const
Returns the height of the boundary (y-axis)
Definition: Boundary.cpp:159
double getWidth() const
Returns the width of the boudary (x-axis)
Definition: Boundary.cpp:153
static void drawFilledPoly(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:81
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:638
static void drawFilledPolyTesselated(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:100
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:347
static void drawTextSettings(const GUIVisualizationTextSettings &settings, const std::string &text, const Position &pos, const double scale, const double angle=0, const double layer=2048, const int align=0)
Definition: GLHelper.cpp:529
The popup menu of a globject.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used,...
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
GUIGlID getGlID() const
Returns the numerical id of the object.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
double myMaxSize
The maximum size (in either x-, or y-dimension) for determining whether to draw or not.
Boundary myBoundary
The represented junction's boundary.
const std::string myTLLID
the associated traffic light or ""
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const
const std::string getOptionalName() const
Returns the value for generic parameter 'name' or ''.
bool myAmRailway
whether this junction has only railways as incoming and outgoing edges
bool myIsInternal
whether this wraps an instance of MSInternalJunction
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
bool myAmWaterway
whether this junction has only waterways as incoming and outgoing edges
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
GUIJunctionWrapper(MSJunction &junction, const std::string &tllID)
Constructor.
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.
virtual ~GUIJunctionWrapper()
Destructor.
A window containing a gl-object's parameter.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
const T getColor(const double value) const
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
Stores the information about how to visualize structures.
GUIVisualizationTextSettings tlsPhaseIndex
GUIVisualizationTextSettings junctionName
GUIVisualizationSizeSettings junctionSize
GUIVisualizationTextSettings internalJunctionName
bool drawJunctionShape
whether the shape of the junction should be drawn
GUIVisualizationTextSettings junctionID
double scale
information about a lane's width (temporary, used for a single view)
GUIVisualizationTextSettings tlsPhaseName
GUIColorer junctionColorer
The junction colorer.
double angle
The current view rotation angle.
The base class for an intersection.
Definition: MSJunction.h:58
const ConstMSEdgeVector & getIncoming() const
Definition: MSJunction.h:105
const PositionVector & getShape() const
Returns this junction's shape.
Definition: MSJunction.h:88
const ConstMSEdgeVector & getOutgoing() const
Definition: MSJunction.h:111
SumoXMLNodeType getType() const
return the type of this Junction
Definition: MSJunction.h:130
const Position & getPosition() const
Definition: MSJunction.cpp:68
const std::string & getName() const
return the junction name
Definition: MSJunction.h:93
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:171
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:444
const std::string & getName() const
MSTrafficLightLogic * getActive(const std::string &id) const
Returns the active program of a named tls.
The parent class for traffic light logics.
virtual const MSPhaseDefinition & getCurrentPhaseDef() const =0
Returns the definition of the current phase.
virtual int getCurrentPhaseIndex() const =0
Returns the current index within the program.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
double x() const
Returns the x-position.
Definition: Position.h:54
Position rotateAround2D(double rad, const Position &origin)
rotate this position by rad around origin and return the result
Definition: Position.cpp:41
double z() const
Returns the z-position.
Definition: Position.h:64
double y() const
Returns the y-position.
Definition: Position.h:59
A list of positions.
void closePolygon()
ensures that the last position equals the first
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
void scaleRelative(double factor)
enlarges/shrinks the polygon by a factor based at the centroid
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:52
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.h:73
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:59
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:66
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
double minSize
The minimum size to draw this object.
double scaledSize(double scale, double constFactor=0.1) const
get scale size