Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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
21#include <netedit/GNENet.h>
23
24#include "GNERerouterSymbol.h"
25
26// ===========================================================================
27// member method definitions
28// ===========================================================================
29
31 GNEAdditional("", net, "", GNE_TAG_REROUTER_SYMBOL, ""),
32 mySymbolContours(new std::vector<GNEContour*>()) {
33}
34
35
37 GNEAdditional(rerouterParent, GNE_TAG_REROUTER_SYMBOL, ""),
38 mySymbolContours(new std::vector<GNEContour*>()) {
39 // set parents
40 setParent<GNEEdge*>(edge);
41 setParent<GNEAdditional*>(rerouterParent);
42 // update centering boundary without updating grid
44}
45
46
48 for (auto it = mySymbolContours->begin(); it != mySymbolContours->end(); it++) {
49 delete *it;
50 }
51 delete mySymbolContours;
52}
53
54
57 return nullptr;
58}
59
60
63 return nullptr;
64}
65
66
67const Parameterised*
69 return nullptr;
70}
71
72
73void
75 // noting to write
76}
77
78
79bool
81 return true;
82}
83
84
85std::string
87 return "";
88}
89
90
91void
93 // nothing to fix
94}
95
96
97bool
99 // get edit modes
100 const auto& editModes = myNet->getViewNet()->getEditModes();
101 // check if we're in move mode
102 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
104 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
105 // only move the first element
107 } else {
108 return false;
109 }
110}
111
112
113void
115 // clear geometries
116 mySymbolGeometries.clear();
117 // iterate over all lanes
118 NBEdge* nbe = getParentEdges().front()->getNBEdge();
119 // clear all contours
120 for (auto it = mySymbolContours->begin(); it != mySymbolContours->end(); it++) {
121 delete *it;
122 }
123 // clear all edge geometries
124 mySymbolGeometries.clear();
125 mySymbolContours->clear();
126 for (const auto& lane : getParentEdges().front()->getChildLanes()) {
127 if ((nbe->getPermissions(lane->getIndex()) & ~SVC_PEDESTRIAN) == 0) {
128 continue;
129 }
130 // declare geometry
131 GUIGeometry symbolGeometry;
132 // update it with lane and pos over lane
133 symbolGeometry.updateGeometry(lane->getLaneShape(), lane->getLaneShape().length2D() - 6, 0);
134 // add in mySymbolGeometries
135 mySymbolGeometries.push_back(symbolGeometry);
136 // also add a new contour
137 mySymbolContours->push_back(new GNEContour());
138 // use last symbol geometry as additional geometry
140 }
141}
142
143
148
149
150void
152 // nothing to do
153}
154
155
156void
157GNERerouterSymbol::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/,
158 const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
159 // nothing to split
160}
161
162
163std::string
165 return getParentAdditionals().at(0)->getID();
166}
167
168
169void
171 // first check if additional has to be drawn
173 // Obtain exaggeration of the draw
174 const double rerouteExaggeration = s.addSize.getExaggeration(s, getParentAdditionals().front());
175 // get detail level
176 const auto d = s.getDetailLevel(rerouteExaggeration);
177 // draw geometry only if we'rent in drawForObjectUnderCursor mode
179 // draw rerouter symbol
180 drawRerouterSymbol(s, d, rerouteExaggeration);
181 // draw parent and child lines
183 // draw dotted contour
184 for (const auto symbolContour : *mySymbolContours) {
185 symbolContour->drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
186 }
187 }
188 // calculate contour rectangle shape
189 for (int i = 0; i < (int)mySymbolContours->size(); i++) {
190 mySymbolContours->at(i)->calculateContourRectangleShape(s, d, this, mySymbolGeometries.at(i).getShape().front(), 1, 3, getType(), 0, 3,
191 mySymbolGeometries.at(i).getShapeRotations().front() + 90, rerouteExaggeration, getParentEdges().front());
192 }
193 }
194}
195
196
197std::string
199 switch (key) {
200 case SUMO_ATTR_ID:
201 case SUMO_ATTR_EDGE:
202 return getParentEdges().front()->getID();
203 default:
204 return getCommonAttribute(key);
205 }
206}
207
208
209double
213
214
219
220
225
226
227void
228GNERerouterSymbol::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
229 setCommonAttribute(key, value, undoList);
230}
231
232
233bool
234GNERerouterSymbol::isValid(SumoXMLAttr key, const std::string& value) {
235 return isCommonAttributeValid(key, value);
236}
237
238
239std::string
241 return getParentEdges().front()->getPopUpID();
242}
243
244
245std::string
247 return getParentEdges().front()->getID();
248}
249
250// ===========================================================================
251// private
252// ===========================================================================
253
254void
256 const double exaggeration) const {
257 // push layer matrix
259 // translate to front
260 getParentAdditionals().front()->drawInLayer(GLO_REROUTER);
261 // set color
262 RGBColor color;
265 } else {
266 color = RGBColor(255, 231, 0);
267 }
268 // draw rerouter symbol over all lanes
269 for (const auto& symbolGeometry : mySymbolGeometries) {
270 // push symbol matrix
272 // translate to position
273 glTranslated(symbolGeometry.getShape().front().x(), symbolGeometry.getShape().front().y(), 0);
274 // rotate over lane
275 GUIGeometry::rotateOverLane(symbolGeometry.getShapeRotations().front() + 90);
276 // scale
277 glScaled(exaggeration, exaggeration, 1);
278 // set color
279 GLHelper::setColor(color);
280 // set draw mode
281 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
282 glBegin(GL_TRIANGLES);
283 // base
284 glVertex2d(0 - 1.4, 0);
285 glVertex2d(0 - 1.4, 6);
286 glVertex2d(0 + 1.4, 6);
287 glVertex2d(0 + 1.4, 0);
288 glVertex2d(0 - 1.4, 0);
289 glVertex2d(0 + 1.4, 6);
290 glEnd();
291 // draw "U"
293 // set text color
294 RGBColor textColor;
297 } else {
298 textColor = RGBColor::BLACK;
299 }
300 // get probability
301 const std::string probability = toString(getParentAdditionals().front()->getAttributeDouble(SUMO_ATTR_PROB) * 100) + "%";
302 // draw U
303 GLHelper::drawText("U", Position(0, 2), .1, 3, textColor, 180);
304 // draw Probability
305 GLHelper::drawText(probability.c_str(), Position(0, 4), .1, 0.7, textColor, 180);
306 }
307 // pop symbol matrix
309 }
310 // pop layer matrix
312}
313
314
315void
316GNERerouterSymbol::setAttribute(SumoXMLAttr key, const std::string& value) {
317 setCommonAttribute(key, value);
318}
319
320/****************************************************************************/
@ 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:742
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
double getCommonAttributeDouble(SumoXMLAttr key) const
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
Position getCommonAttributePosition(SumoXMLAttr key) const
GNENet * myNet
pointer to net
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
std::string getCommonAttribute(SumoXMLAttr key) const
const GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const GNEHierarchicalContainerParents< GNEEdge * > & getParentEdges() const
get parent edges
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
std::string getAttribute(SumoXMLAttr key) const override
std::string getParentName() const
Returns the name (ID) of the parent object.
std::vector< GUIGeometry > mySymbolGeometries
symbols geometries
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
Parameterised * getParameters() override
get parameters associated with this rerouterSymbol
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 setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
void updateGeometry() override
update pre-computed geometry information
Position getAttributePosition(SumoXMLAttr key) const override
~GNERerouterSymbol()
Destructor.
bool checkDrawMoveContour() const override
check if draw move contour (red)
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...
bool isValid(SumoXMLAttr key, const std::string &value) override
double getAttributeDouble(SumoXMLAttr key) const override
GNERerouterSymbol(GNENet *net)
default Constructor
std::vector< GNEContour * > * mySymbolContours
symbol contours
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this rerouterSymbol
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
Position getPositionInView() const
Returns position of additional in view.
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:4540
Static storage of an output device and its base (abstract) implementation.
An upper class for objects with additional parameters.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
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
Definition json.hpp:4471
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