Eclipse SUMO - Simulation of Urban MObility
GNERerouterSymbol.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-2022 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
34 GNEAdditional(rerouterParent->getNet(), GLO_REROUTER, GNE_TAG_REROUTER_SYMBOL, GUIIconSubSys::getIcon(GUIIcon::REROUTER), "",
35{}, {edge}, {}, {rerouterParent}, {}, {}) {
36 // update centering boundary without updating grid
37 updateCenteringBoundary(false);
38}
39
40
42}
43
44
47 // GNERerouterSymbols cannot be moved
48 return nullptr;
49}
50
51
52void
54 // noting to write
55}
56
57
58void
60 // clear geometries
61 mySymbolGeometries.clear();
62 // iterate over all lanes
63 NBEdge* nbe = getParentEdges().front()->getNBEdge();
64 for (const auto& lane : getParentEdges().front()->getLanes()) {
65 if ((nbe->getPermissions(lane->getIndex()) & ~SVC_PEDESTRIAN) == 0) {
66 continue;
67 }
68 // declare geometry
69 GUIGeometry symbolGeometry;
70 // update it with lane and pos over lane
71 symbolGeometry.updateGeometry(lane->getLaneShape(), lane->getLaneShape().length2D() - 6, 0);
72 // add in mySymbolGeometries
73 mySymbolGeometries.push_back(symbolGeometry);
74 }
75}
76
77
80 if (mySymbolGeometries.size() > 0) {
81 return mySymbolGeometries.front().getShape().getPolygonCenter();
82 } else {
84 }
85}
86
87
88void
91 // add center
93 // grow
95}
96
97
98void
99GNERerouterSymbol::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/,
100 const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
101 // nothing to split
102}
103
104
105std::string
107 return getParentAdditionals().at(0)->getID();
108}
109
110
111void
113 // Obtain exaggeration of the draw
114 const double rerouteExaggeration = s.addSize.getExaggeration(s, getParentAdditionals().front());
115 // first check if additional has to be drawn
116 if (s.drawAdditionals(rerouteExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
117 // draw parent and child lines
119 // Start drawing adding an gl identificator (except in Move mode)
122 }
123 // push layer matrix
125 // translate to front
127 // draw rerouter symbol over all lanes
128 for (const auto& symbolGeometry : mySymbolGeometries) {
129 // push symbol matrix
131 // translate to position
132 glTranslated(symbolGeometry.getShape().front().x(), symbolGeometry.getShape().front().y(), 0);
133 // rotate over lane
134 GUIGeometry::rotateOverLane(symbolGeometry.getShapeRotations().front() + 90);
135 // scale
136 glScaled(rerouteExaggeration, rerouteExaggeration, 1);
137 // set color
140 } else {
141 glColor3d(1, .8f, 0);
142 }
143 // set draw mode
144 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
145 glBegin(GL_TRIANGLES);
146 // base
147 glVertex2d(0 - 1.4, 0);
148 glVertex2d(0 - 1.4, 6);
149 glVertex2d(0 + 1.4, 6);
150 glVertex2d(0 + 1.4, 0);
151 glVertex2d(0 - 1.4, 0);
152 glVertex2d(0 + 1.4, 6);
153 glEnd();
154 // draw "U"
156 // set text color
157 RGBColor textColor;
160 } else {
161 textColor = RGBColor::BLACK;
162 }
163 // get probability
164 const std::string probability = toString(getParentAdditionals().front()->getAttributeDouble(SUMO_ATTR_PROB) * 100) + "%";
165 // draw U
166 GLHelper::drawText("U", Position(0, 2), .1, 3, textColor, 180);
167 // draw Probability
168 GLHelper::drawText(probability.c_str(), Position(0, 4), .1, 0.7, textColor, 180);
169 }
170 // pop symbol matrix
172 }
173 // pop layer matrix
175 // Pop name
178 }
179 // check if dotted contour has to be drawn
181 // iterate over symbol geometries
182 for (const auto& symbolGeometry : mySymbolGeometries) {
183 GUIDottedGeometry::drawDottedSquaredShape(s, GUIDottedGeometry::DottedContourType::INSPECT, symbolGeometry.getShape().front(), 1, 3, 0, 3, symbolGeometry.getShapeRotations().front() + 90, rerouteExaggeration);
184 }
185 }
187 // iterate over symbol geometries
188 for (const auto& symbolGeometry : mySymbolGeometries) {
189 GUIDottedGeometry::drawDottedSquaredShape(s, GUIDottedGeometry::DottedContourType::FRONT, symbolGeometry.getShape().front(), 1, 3, 0, 3, symbolGeometry.getShapeRotations().front() + 90, rerouteExaggeration);
190 }
191 }
192 }
193}
194
195
196std::string
198 switch (key) {
199 case SUMO_ATTR_ID:
200 case SUMO_ATTR_EDGE:
201 return getParentEdges().front()->getID();
202 default:
203 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
204 }
205}
206
207
208double
210 throw InvalidArgument("Symbols cannot be edited");
211}
212
213
216 return PARAMETERS_EMPTY;
217}
218
219
220void
221GNERerouterSymbol::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/, GNEUndoList* /*undoList*/) {
222 throw InvalidArgument("Symbols cannot be edited");
223}
224
225
226bool
227GNERerouterSymbol::isValid(SumoXMLAttr /*key*/, const std::string& /*value*/) {
228 throw InvalidArgument("Symbols cannot be edited");
229}
230
231
232std::string
234 return getParentEdges().front()->getPopUpID();
235}
236
237
238std::string
240 return getParentEdges().front()->getID();
241}
242
243// ===========================================================================
244// private
245// ===========================================================================
246
247void
248GNERerouterSymbol::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/) {
249 throw InvalidArgument("Symbols cannot be edited");
250}
251
252
253void
255 // nothing to do
256}
257
258
259void
260GNERerouterSymbol::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
261 // nothing to do
262}
263
264/****************************************************************************/
@ 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
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:78
void reset()
Resets the boundary.
Definition: Boundary.cpp:66
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:300
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:583
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:139
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void popName()
pop Name
Definition: GLHelper.cpp:148
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
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:685
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:48
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
Boundary myAdditionalBoundary
Additional Boundary.
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
const std::string & getTagStr() const
get tag assigned to this object in string format
static const Parameterised::Map PARAMETERS_EMPTY
empty parameter maps (used by ACs without parameters)
GNENet * myNet
pointer to net
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
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
const Parameterised::Map & getACParametersMap() const
get parameters map
GNEMoveOperation * getMoveOperation()
get move operation
std::string getParentName() const
Returns the name of the parent object (if any)
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.
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 updateGeometry()
update pre-computed geometry information
std::string getAttribute(SumoXMLAttr key) const
~GNERerouterSymbol()
Destructor.
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
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
GNERerouterSymbol(GNEAdditional *rerouterParent, GNEEdge *edge)
Constructor.
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 GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:656
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:632
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
static void drawDottedSquaredShape(const GUIVisualizationSettings &s, const DottedContourType type, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double exaggeration)
draw dotted squared contour (used by additionals and demand elements)
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
Definition: GUIGeometry.cpp:58
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:102
Stores the information about how to visualize structures.
GUIVisualizationSizeSettings addSize
bool drawForPositionSelection
whether drawing is performed for the purpose of selecting objects with a single click
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
GUIVisualizationColorSettings colorSettings
color 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:4137
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
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
NetworkEditMode networkEditMode
the current Network edit mode
static const RGBColor connectionColor
connection color
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values