Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GNERerouterSymbol.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/****************************************************************************/
18//
19/****************************************************************************/
20#include <config.h>
21
22#include <netedit/GNENet.h>
23#include <netedit/GNEViewNet.h>
26
27#include "GNERerouterSymbol.h"
28
29// ===========================================================================
30// member method definitions
31// ===========================================================================
32
36
37
39 GNEAdditional(rerouterParent, GNE_TAG_REROUTER_SYMBOL, "") {
40 // set parents
41 setParent<GNEEdge*>(edge);
42 setParent<GNEAdditional*>(rerouterParent);
43 // update centering boundary without updating grid
45}
46
47
50
51
54 // GNERerouterSymbols cannot be moved
55 return nullptr;
56}
57
58
59void
61 // noting to write
62}
63
64
65bool
67 return true;
68}
69
70
71std::string
73 return "";
74}
75
76
77void
79 // nothing to fix
80}
81
82
83bool
85 // get edit modes
86 const auto& editModes = myNet->getViewNet()->getEditModes();
87 // check if we're in move mode
88 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
90 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
91 // only move the first element
93 } else {
94 return false;
95 }
96}
97
98
99void
101 // clear geometries
102 mySymbolGeometries.clear();
103 // iterate over all lanes
104 NBEdge* nbe = getParentEdges().front()->getNBEdge();
105 for (const auto& lane : getParentEdges().front()->getChildLanes()) {
106 if ((nbe->getPermissions(lane->getIndex()) & ~SVC_PEDESTRIAN) == 0) {
107 continue;
108 }
109 // declare geometry
110 GUIGeometry symbolGeometry;
111 // update it with lane and pos over lane
112 symbolGeometry.updateGeometry(lane->getLaneShape(), lane->getLaneShape().length2D() - 6, 0);
113 // add in mySymbolGeometries
114 mySymbolGeometries.push_back(symbolGeometry);
115 }
116}
117
118
121 if (mySymbolGeometries.size() > 0) {
122 return mySymbolGeometries.front().getShape().getPolygonCenter();
123 } else {
125 }
126}
127
128
129void
131 // nothing to do
132}
133
134
135void
136GNERerouterSymbol::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/,
137 const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
138 // nothing to split
139}
140
141
142std::string
144 return getParentAdditionals().at(0)->getID();
145}
146
147
148void
150 // first check if additional has to be drawn
152 // Obtain exaggeration of the draw
153 const double rerouteExaggeration = s.addSize.getExaggeration(s, getParentAdditionals().front());
154 // get detail level
155 const auto d = s.getDetailLevel(rerouteExaggeration);
156 // draw geometry only if we'rent in drawForObjectUnderCursor mode
158 // draw rerouter symbol
159 drawRerouterSymbol(s, d, rerouteExaggeration);
160 // draw parent and child lines
162 // draw dotted contour
164 }
165 // calculate contour rectangle shape
166 for (const auto& symbolGeometry : mySymbolGeometries) {
167 myAdditionalContour.calculateContourRectangleShape(s, d, this, symbolGeometry.getShape().front(), 1, 3, getType(), 0, 3,
168 symbolGeometry.getShapeRotations().front() + 90, rerouteExaggeration, getParentEdges().front());
169 }
170 }
171}
172
173
174std::string
176 switch (key) {
177 case SUMO_ATTR_ID:
178 case SUMO_ATTR_EDGE:
179 return getParentEdges().front()->getID();
180 default:
181 return getCommonAttribute(nullptr, key);
182 }
183}
184
185
186double
188 return 0;
189}
190
191
196
197
198void
199GNERerouterSymbol::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
200 setCommonAttribute(key, value, undoList);
201}
202
203
204bool
205GNERerouterSymbol::isValid(SumoXMLAttr key, const std::string& value) {
206 return isCommonValid(key, value);
207}
208
209
210std::string
212 return getParentEdges().front()->getPopUpID();
213}
214
215
216std::string
218 return getParentEdges().front()->getID();
219}
220
221// ===========================================================================
222// private
223// ===========================================================================
224
225void
227 const double exaggeration) const {
228 // push layer matrix
230 // translate to front
231 getParentAdditionals().front()->drawInLayer(GLO_REROUTER);
232 // set color
233 RGBColor color;
236 } else {
237 color = RGBColor(255, 231, 0);
238 }
239 // draw rerouter symbol over all lanes
240 for (const auto& symbolGeometry : mySymbolGeometries) {
241 // push symbol matrix
243 // translate to position
244 glTranslated(symbolGeometry.getShape().front().x(), symbolGeometry.getShape().front().y(), 0);
245 // rotate over lane
246 GUIGeometry::rotateOverLane(symbolGeometry.getShapeRotations().front() + 90);
247 // scale
248 glScaled(exaggeration, exaggeration, 1);
249 // set color
250 GLHelper::setColor(color);
251 // set draw mode
252 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
253 glBegin(GL_TRIANGLES);
254 // base
255 glVertex2d(0 - 1.4, 0);
256 glVertex2d(0 - 1.4, 6);
257 glVertex2d(0 + 1.4, 6);
258 glVertex2d(0 + 1.4, 0);
259 glVertex2d(0 - 1.4, 0);
260 glVertex2d(0 + 1.4, 6);
261 glEnd();
262 // draw "U"
264 // set text color
265 RGBColor textColor;
268 } else {
269 textColor = RGBColor::BLACK;
270 }
271 // get probability
272 const std::string probability = toString(getParentAdditionals().front()->getAttributeDouble(SUMO_ATTR_PROB) * 100) + "%";
273 // draw U
274 GLHelper::drawText("U", Position(0, 2), .1, 3, textColor, 180);
275 // draw Probability
276 GLHelper::drawText(probability.c_str(), Position(0, 4), .1, 0.7, textColor, 180);
277 }
278 // pop symbol matrix
280 }
281 // pop layer matrix
283}
284
285
286void
287GNERerouterSymbol::setAttribute(SumoXMLAttr key, const std::string& value) {
288 setCommonAttribute(this, key, value);
289}
290
291
292void
294 // nothing to do
295}
296
297
298void
299GNERerouterSymbol::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
300 // nothing to do
301}
302
303/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ GLO_REROUTER
a Rerouter
@ SVC_PEDESTRIAN
pedestrian
@ GNE_TAG_REROUTER_SYMBOL
Rerouter Symbol.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_EDGE
@ SUMO_ATTR_PROB
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:649
static void popMatrix()
pop matrix
Definition GLHelper.cpp:131
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0, const int align=0, double width=-1)
Definition GLHelper.cpp:748
GNEContour myAdditionalContour
variable used for draw additional contours
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
std::string getCommonAttribute(const Parameterised *parameterised, SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
GNENet * myNet
pointer to net
bool isCommonValid(SumoXMLAttr key, const std::string &value) const
bool drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
draw dotted contours (basics, select, delete, inspect...)
void calculateContourRectangleShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const Position &pos, const double width, const double height, const double layer, const double offsetX, const double offsetY, const double rot, const double scale, const GUIGlObject *boundaryParent) const
calculate contour (for rectangled elements)
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
const GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const GNEHierarchicalContainerParents< GNEEdge * > & getParentEdges() const
get parent edges
move operation
move result
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2194
const Parameterised::Map & getACParametersMap() const
get parameters map
GNEMoveOperation * getMoveOperation()
get move operation
std::string getParentName() const
Returns the name (ID) of the parent object.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
std::vector< GUIGeometry > mySymbolGeometries
symbols geometries
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
bool checkDrawMoveContour() const
check if draw move contour (red)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
void drawRerouterSymbol(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double exaggeration) const
draw rerouter symbol
void updateGeometry()
update pre-computed geometry information
std::string getAttribute(SumoXMLAttr key) const
~GNERerouterSymbol()
Destructor.
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
bool isAdditionalValid() const
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
GNERerouterSymbol(GNENet *net)
default Constructor
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Position getPositionInView() const
Returns position of additional in view.
double getAttributeDouble(SumoXMLAttr key) const
const GUIGlObject * getGUIGlObjectFront() const
get front GUIGLObject or a pointer to nullptr
bool isCurrentlyMovingElements() const
check if an element is being moved
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
const GNEViewNetHelper::EditNetworkElementShapes & getEditNetworkElementShapes() const
get Edit Shape module
bool checkOverLockedElement(const GUIGlObject *GLObject, const bool isSelected) const
check if given element is locked (used for drawing select and delete contour)
const GNEViewNetHelper::ViewObjectsSelector & getViewObjectsSelector() const
get objects under cursor
static void rotateOverLane(const double rot)
rotate over lane (used by Lock icons, detector logos, etc.)
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape)
update entire geometry
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Stores the information about how to visualize structures.
GUIVisualizationSizeSettings addSize
bool checkDrawAdditional(Detail d, const bool selected) const
check if draw additionals
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
The representation of a single edge during network building.
Definition NBEdge.h:92
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition NBEdge.cpp:4469
Static storage of an output device and its base (abstract) implementation.
std::map< std::string, std::string > Map
parameters map
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
static const RGBColor BLACK
Definition RGBColor.h:196
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition RGBColor.cpp:200
bool showAdditionals() const
check if additionals has to be drawn
GNENetworkElement * getEditedNetworkElement() const
pointer to edited network element
static const RGBColor connectionColor
connection color
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double segmentWidth
width of dotted contour segments
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values