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-2024 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
35{}, {}, {}, {}, {}, {}) {
36 // reset default values
37 resetDefaultValues();
38}
39
40
42 GNEAdditional(rerouterParent->getNet(), GLO_REROUTER, GNE_TAG_REROUTER_SYMBOL, GUIIconSubSys::getIcon(GUIIcon::REROUTER), "",
43{}, {edge}, {}, {rerouterParent}, {}, {}) {
44 // update centering boundary without updating grid
45 updateCenteringBoundary(false);
46}
47
48
51
52
55 // GNERerouterSymbols cannot be moved
56 return nullptr;
57}
58
59
60void
62 // noting to write
63}
64
65
66bool
68 return true;
69}
70
71
72std::string
74 return "";
75}
76
77
78void
80 // nothing to fix
81}
82
83
84bool
86 // get edit modes
87 const auto& editModes = myNet->getViewNet()->getEditModes();
88 // check if we're in move mode
89 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
91 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
92 // only move the first element
94 } else {
95 return false;
96 }
97}
98
99
100void
102 // clear geometries
103 mySymbolGeometries.clear();
104 // iterate over all lanes
105 NBEdge* nbe = getParentEdges().front()->getNBEdge();
106 for (const auto& lane : getParentEdges().front()->getLanes()) {
107 if ((nbe->getPermissions(lane->getIndex()) & ~SVC_PEDESTRIAN) == 0) {
108 continue;
109 }
110 // declare geometry
111 GUIGeometry symbolGeometry;
112 // update it with lane and pos over lane
113 symbolGeometry.updateGeometry(lane->getLaneShape(), lane->getLaneShape().length2D() - 6, 0);
114 // add in mySymbolGeometries
115 mySymbolGeometries.push_back(symbolGeometry);
116 }
117}
118
119
122 if (mySymbolGeometries.size() > 0) {
123 return mySymbolGeometries.front().getShape().getPolygonCenter();
124 } else {
126 }
127}
128
129
130void
132 // nothing to do
133}
134
135
136void
137GNERerouterSymbol::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/,
138 const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
139 // nothing to split
140}
141
142
143std::string
145 return getParentAdditionals().at(0)->getID();
146}
147
148
149void
151 // first check if additional has to be drawn
153 // Obtain exaggeration of the draw
154 const double rerouteExaggeration = s.addSize.getExaggeration(s, getParentAdditionals().front());
155 // get detail level
156 const auto d = s.getDetailLevel(rerouteExaggeration);
157 // draw geometry only if we'rent in drawForObjectUnderCursor mode
159 // draw rerouter symbol
160 drawRerouterSymbol(s, d, rerouteExaggeration);
161 // draw parent and child lines
163 // draw dotted contour
165 }
166 // calculate contour rectangle shape
167 for (const auto& symbolGeometry : mySymbolGeometries) {
168 myAdditionalContour.calculateContourRectangleShape(s, d, this, symbolGeometry.getShape().front(), 1, 3, getType(), 0, 3,
169 symbolGeometry.getShapeRotations().front() + 90, rerouteExaggeration, getParentEdges().front());
170 }
171 }
172}
173
174
175std::string
177 switch (key) {
178 case SUMO_ATTR_ID:
179 case SUMO_ATTR_EDGE:
180 return getParentEdges().front()->getID();
181 default:
182 return getCommonAttribute(key);
183 }
184}
185
186
187double
189 throw InvalidArgument("Symbols cannot be edited");
190}
191
192
197
198
199void
200GNERerouterSymbol::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/, GNEUndoList* /*undoList*/) {
201 throw InvalidArgument("Symbols cannot be edited");
202}
203
204
205bool
206GNERerouterSymbol::isValid(SumoXMLAttr /*key*/, const std::string& /*value*/) {
207 throw InvalidArgument("Symbols cannot be edited");
208}
209
210
211std::string
213 return getParentEdges().front()->getPopUpID();
214}
215
216
217std::string
219 return getParentEdges().front()->getID();
220}
221
222// ===========================================================================
223// private
224// ===========================================================================
225
226void
228 const double exaggeration) const {
229 // push layer matrix
231 // translate to front
232 getParentAdditionals().front()->drawInLayer(GLO_REROUTER);
233 // set color
234 RGBColor color;
237 } else {
238 color = RGBColor(255, 231, 0);
239 }
240 // draw rerouter symbol over all lanes
241 for (const auto& symbolGeometry : mySymbolGeometries) {
242 // push symbol matrix
244 // translate to position
245 glTranslated(symbolGeometry.getShape().front().x(), symbolGeometry.getShape().front().y(), 0);
246 // rotate over lane
247 GUIGeometry::rotateOverLane(symbolGeometry.getShapeRotations().front() + 90);
248 // scale
249 glScaled(exaggeration, exaggeration, 1);
250 // set color
251 GLHelper::setColor(color);
252 // set draw mode
253 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
254 glBegin(GL_TRIANGLES);
255 // base
256 glVertex2d(0 - 1.4, 0);
257 glVertex2d(0 - 1.4, 6);
258 glVertex2d(0 + 1.4, 6);
259 glVertex2d(0 + 1.4, 0);
260 glVertex2d(0 - 1.4, 0);
261 glVertex2d(0 + 1.4, 6);
262 glEnd();
263 // draw "U"
265 // set text color
266 RGBColor textColor;
269 } else {
270 textColor = RGBColor::BLACK;
271 }
272 // get probability
273 const std::string probability = toString(getParentAdditionals().front()->getAttributeDouble(SUMO_ATTR_PROB) * 100) + "%";
274 // draw U
275 GLHelper::drawText("U", Position(0, 2), .1, 3, textColor, 180);
276 // draw Probability
277 GLHelper::drawText(probability.c_str(), Position(0, 4), .1, 0.7, textColor, 180);
278 }
279 // pop symbol matrix
281 }
282 // pop layer matrix
284}
285
286
287void
288GNERerouterSymbol::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/) {
289 throw InvalidArgument("Symbols cannot be edited");
290}
291
292
293void
295 // nothing to do
296}
297
298
299void
300GNERerouterSymbol::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
301 // nothing to do
302}
303
304/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ GLO_REROUTER
a Rerouter
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ 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:751
An Element which don't belong to GNENet but has influence in the simulation.
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)
static const Parameterised::Map PARAMETERS_EMPTY
empty parameter maps (used by ACs without parameters)
GNENet * myNet
pointer to net
std::string getCommonAttribute(SumoXMLAttr key) 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 std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const std::vector< 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:2163
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:4379
Static storage of an output device and its base (abstract) implementation.
std::map< std::string, std::string > Map
parameters 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:193
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