Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUIJunctionWrapper.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 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#include <microsim/MSLane.h>
29#include <microsim/MSEdge.h>
30#include <microsim/MSJunction.h>
31#include <utils/geom/Position.h>
33#include <microsim/MSNet.h>
38#include <gui/GUIGlobals.h>
41#include "GUIJunctionWrapper.h"
47
49
50// ===========================================================================
51// method definitions
52// ===========================================================================
53GUIJunctionWrapper::GUIJunctionWrapper(MSJunction& junction, const std::string& tllID):
54 GUIGlObject(GLO_JUNCTION, junction.getID(), GUIIconSubSys::getIcon(GUIIcon::JUNCTION)),
55 myJunction(junction),
56 myTesselation(junction.getID(), "", RGBColor::MAGENTA, junction.getShape(), false, true, 0),
57 myExaggeration(1),
58 myTLLID(tllID) {
59 if (myJunction.getShape().size() == 0) {
61 myBoundary = Boundary(pos.x() - 1., pos.y() - 1., pos.x() + 1., pos.y() + 1.);
62 } else {
64 }
69 myAmAirway = myJunction.getIncoming().size() + myJunction.getOutgoing().size() > 0;
70 for (auto it = myJunction.getIncoming().begin(); it != myJunction.getIncoming().end() && (myAmWaterway || myAmRailway); ++it) {
71 if (!(*it)->isInternal()) {
72 if (!isWaterway((*it)->getPermissions())) {
73 myAmWaterway = false;
74 }
75 if (!isRailway((*it)->getPermissions())) {
76 myAmRailway = false;
77 }
78 if (!isAirway((*it)->getPermissions())) {
79 myAmAirway = false;
80 }
81 }
82 }
83 for (auto it = myJunction.getOutgoing().begin(); it != myJunction.getOutgoing().end() && (myAmWaterway || myAmRailway); ++it) {
84 if (!(*it)->isInternal()) {
85 if (!isWaterway((*it)->getPermissions())) {
86 myAmWaterway = false;
87 }
88 if (!isRailway((*it)->getPermissions())) {
89 myAmRailway = false;
90 }
91 if (!isAirway((*it)->getPermissions())) {
92 myAmAirway = false;
93 }
94 }
95 }
97}
98
99
101
102
115
116
120 // add items
121 ret->mkItem(TL("type"), false, toString(myJunction.getType()));
122 ret->mkItem(TL("name"), false, myJunction.getName());
123 // close building
125 return ret;
126}
127
128
129double
133
134
138 const Position& p = myJunction.getPosition(true);
139 return Boundary(p.x() - 1, p.y() - 1, p.x() + 1, p.y() + 1);
140 }
142 b.grow(1);
143 return b;
144}
145
146const std::string
150
151void
153 const bool s2 = s.secondaryShape;
154 if (!myIsInternal && s.drawJunctionShape && !s2) {
155 // check whether it is not too small
156 const double exaggeration = getExaggeration(s);
157 if (s.scale * exaggeration >= s.junctionSize.minSize) {
160 const double colorValue = getColorValue(s, s.junctionColorer.getActive());
161 const RGBColor color = s.junctionColorer.getScheme().getColor(colorValue);
162 GLHelper::setColor(color);
163
164 // recognize full transparency and simply don't draw
165 if (color.alpha() != 0) {
166 if ((exaggeration > 1 || myExaggeration > 1) && exaggeration != myExaggeration) {
167 myExaggeration = exaggeration;
172 }
173 glTranslated(0, 0, getType());
174 if (s.scale * myMaxSize < 40.) {
176 } else {
178 }
179 // make small junctions more visible when coloring by type
181 glTranslated(myJunction.getPosition(s2).x(), myJunction.getPosition(s2).y(), getType() + 0.05);
182 GLHelper::drawFilledCircle(2 * exaggeration, 12);
183 }
184 }
187 if (s.geometryIndices.show(this)) {
189 }
190 }
191 }
192 if (myIsInternal) {
194 } else {
196 if (s.junctionName.show(this) && myJunction.getName() != "") {
198 }
199 if ((s.tlsPhaseIndex.show(this) || s.tlsPhaseName.show(this)) && myTLLID != "") {
201 if (s.tlsPhaseIndex.show(this)) {
202 const int index = active->getCurrentPhaseIndex();
204 }
205 if (s.tlsPhaseName.show(this)) {
206 const std::string& name = active->getCurrentPhaseDef().getName();
207 if (name != "") {
208 const Position offset = (s.tlsPhaseIndex.show(this) ?
210 : Position(0, 0));
212 }
213 }
214 }
215 }
216}
217
218
219double
220GUIJunctionWrapper::getColorValue(const GUIVisualizationSettings& /* s */, int activeScheme) const {
221 switch (activeScheme) {
222 case 0:
223 if (myAmWaterway) {
224 return 1;
225 } else if (myAmRailway && MSNet::getInstance()->hasInternalLinks()) {
226 return 2;
227 } else if (myAmAirway) {
228 return 3;
229 } else {
230 return 0;
231 }
232 case 1:
233 return gSelected.isSelected(getType(), getGlID()) ? 1 : 0;
234 case 2:
235 switch (myJunction.getType()) {
237 return 0;
239 return 1;
241 return 2;
243 return 3;
245 return 4;
247 return 5;
249 return 6;
251 return 7;
254 return 8;
257 assert(false);
258 return 8;
260 return 9;
262 return 10;
264 return 11;
266 return 12;
268 return 13;
269 default:
270 assert(false);
271 return 0;
272 }
273 case 3:
274 return myJunction.getPosition().z();
275 default:
276 assert(false);
277 return 0;
278 }
279}
280
281#ifdef HAVE_OSG
282void
283GUIJunctionWrapper::updateColor(const GUIVisualizationSettings& s) {
284 const double colorValue = getColorValue(s, s.junctionColorer.getActive());
285 const RGBColor& col = s.junctionColorer.getScheme().getColor(colorValue);
286 osg::Vec4ubArray* colors = dynamic_cast<osg::Vec4ubArray*>(myGeom->getColorArray());
287 (*colors)[0].set(col.red(), col.green(), col.blue(), col.alpha());
288 myGeom->setColorArray(colors);
289}
290#endif
291
292
293/****************************************************************************/
@ GLO_JUNCTION
a junction
GUISelectedStorage gSelected
A global holder of selected objects.
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
#define DEG2RAD(x)
Definition GeomHelper.h:35
#define TL(string)
Definition MsgHandler.h:305
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permissions is a (exclusive) railway edge.
bool isWaterway(SVCPermissions permissions)
Returns whether an edge with the given permissions is a waterway edge.
bool isAirway(SVCPermissions permissions)
Returns whether an edge with the given permissions is an airway edge.
T MAX2(T a, T b)
Definition StdDefs.h:86
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
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:340
double getHeight() const
Returns the height of the boundary (y-axis)
Definition Boundary.cpp:157
double getWidth() const
Returns the width of the boudary (x-axis)
Definition Boundary.cpp:151
static void drawFilledPoly(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition GLHelper.cpp:204
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:649
static void pushName(unsigned int name)
push Name
Definition GLHelper.cpp:140
static void drawFilledCircle(const double widradiusth, const int steps=8)
Draws a filled circle around (0,0)
Definition GLHelper.cpp:564
static void popMatrix()
pop matrix
Definition GLHelper.cpp:131
static void debugVertices(const PositionVector &shape, const GUIVisualizationTextSettings &settings, double scale, double layer=1024)
draw vertex numbers for the given shape (in a random color)
Definition GLHelper.cpp:939
static void popName()
pop Name
Definition GLHelper.cpp:149
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
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:773
The popup menu of a globject.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, const GUIMainWindow &app, bool addSeparator=true) const
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, bool forceShow=false) const
draw name of item
static bool gSecondaryShape
whether secondary shapes are currently being drawn
Definition GUIGlobals.h:49
bool myAmAirway
whether this junction has only airways as incoming and outgoing edges
double myMaxSize
The maximum size (in either x-, or y-dimension) for determining whether to draw or not.
TesselatedPolygon myTesselation
An object that stores the shape and its tesselation.
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.
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
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.
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 geometryIndices
GUIVisualizationTextSettings junctionID
double scale
information about a lane's width (temporary, used for a single view)
bool secondaryShape
whether secondary lane shape shall be drawn
GUIVisualizationTextSettings tlsPhaseName
GUIColorer junctionColorer
The junction colorer.
double angle
The current view rotation angle.
The base class for an intersection.
Definition MSJunction.h:58
SumoXMLNodeType getType() const
return the type of this Junction
Definition MSJunction.h:133
const ConstMSEdgeVector & getOutgoing() const
Definition MSJunction.h:114
const std::string & getName() const
return the junction name
Definition MSJunction.h:96
const Position & getPosition(bool secondaryShape=false) const
const PositionVector & getShape() const
Returns this junction's shape.
Definition MSJunction.h:91
const ConstMSEdgeVector & getIncoming() const
Definition MSJunction.h:108
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition MSNet.h:457
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:37
double x() const
Returns the x-position.
Definition Position.h:52
Position rotateAround2D(double rad, const Position &origin)
rotate this position by rad around origin and return the result
Definition Position.cpp:42
double z() const
Returns the z-position.
Definition Position.h:62
double y() const
Returns the y-position.
Definition Position.h:57
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.cpp:74
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition RGBColor.cpp:92
unsigned char green() const
Returns the green-amount of the color.
Definition RGBColor.cpp:80
unsigned char blue() const
Returns the blue-amount of the color.
Definition RGBColor.cpp:86
const PositionVector & getShape() const
Returns the shape of the polygon.
virtual void setShape(const PositionVector &shape)
Sets the shape of the polygon.
PositionVector & getShapeRef()
Return the exterior shape of the polygon.
std::vector< GLPrimitive > myTesselation
id of the display list for the cached tesselation
Definition GUIPolygon.h:72
void drawTesselation(const PositionVector &shape) const
perform the tesselation / drawing
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.
bool show(const GUIGlObject *o) const
whether to show the text
double scaledSize(double scale, double constFactor=0.1) const
get scale size