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-2023 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
43
44
47 // GNERerouterSymbols cannot be moved
48 return nullptr;
49}
50
51
52void
54 // noting to write
55}
56
57
58bool
60 return true;
61}
62
63
64std::string
66 return "";
67}
68
69
70void
72 // nothing to fix
73}
74
75
76void
78 // clear geometries
79 mySymbolGeometries.clear();
80 // iterate over all lanes
81 NBEdge* nbe = getParentEdges().front()->getNBEdge();
82 for (const auto& lane : getParentEdges().front()->getLanes()) {
83 if ((nbe->getPermissions(lane->getIndex()) & ~SVC_PEDESTRIAN) == 0) {
84 continue;
85 }
86 // declare geometry
87 GUIGeometry symbolGeometry;
88 // update it with lane and pos over lane
89 symbolGeometry.updateGeometry(lane->getLaneShape(), lane->getLaneShape().length2D() - 6, 0);
90 // add in mySymbolGeometries
91 mySymbolGeometries.push_back(symbolGeometry);
92 }
93}
94
95
98 if (mySymbolGeometries.size() > 0) {
99 return mySymbolGeometries.front().getShape().getPolygonCenter();
100 } else {
102 }
103}
104
105
106void
109 // add center
111 // grow
113}
114
115
116void
117GNERerouterSymbol::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/,
118 const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
119 // nothing to split
120}
121
122
123std::string
125 return getParentAdditionals().at(0)->getID();
126}
127
128
129void
131 // Obtain exaggeration of the draw
132 const double rerouteExaggeration = s.addSize.getExaggeration(s, getParentAdditionals().front());
133 // first check if additional has to be drawn
134 if (s.drawAdditionals(rerouteExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
135 // draw parent and child lines
137 // Start drawing adding an gl identificator (except in Move mode)
140 }
141 // push layer matrix
143 // translate to front
145 // set color
146 RGBColor color;
149 } else {
150 color = RGBColor(255, 231, 0);
151 }
152 // avoid draw invisible elements
153 if (color.alpha() != 0) {
154 // draw rerouter symbol over all lanes
155 for (const auto& symbolGeometry : mySymbolGeometries) {
156 // push symbol matrix
158 // translate to position
159 glTranslated(symbolGeometry.getShape().front().x(), symbolGeometry.getShape().front().y(), 0);
160 // rotate over lane
161 GUIGeometry::rotateOverLane(symbolGeometry.getShapeRotations().front() + 90);
162 // scale
163 glScaled(rerouteExaggeration, rerouteExaggeration, 1);
164 // set color
165 GLHelper::setColor(color);
166 // set draw mode
167 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
168 glBegin(GL_TRIANGLES);
169 // base
170 glVertex2d(0 - 1.4, 0);
171 glVertex2d(0 - 1.4, 6);
172 glVertex2d(0 + 1.4, 6);
173 glVertex2d(0 + 1.4, 0);
174 glVertex2d(0 - 1.4, 0);
175 glVertex2d(0 + 1.4, 6);
176 glEnd();
177 // draw "U"
179 // set text color
180 RGBColor textColor;
183 } else {
184 textColor = RGBColor::BLACK;
185 }
186 // get probability
187 const std::string probability = toString(getParentAdditionals().front()->getAttributeDouble(SUMO_ATTR_PROB) * 100) + "%";
188 // draw U
189 GLHelper::drawText("U", Position(0, 2), .1, 3, textColor, 180);
190 // draw Probability
191 GLHelper::drawText(probability.c_str(), Position(0, 4), .1, 0.7, textColor, 180);
192 }
193 // pop symbol matrix
195 }
196 // pop layer matrix
198 // Pop name
201 }
202 }
203 // check if dotted contour has to be drawn
205 // iterate over symbol geometries
206 for (const auto& symbolGeometry : mySymbolGeometries) {
207 GUIDottedGeometry::drawDottedSquaredShape(s, GUIDottedGeometry::DottedContourType::INSPECT, symbolGeometry.getShape().front(), 1, 3, 0, 3, symbolGeometry.getShapeRotations().front() + 90, rerouteExaggeration);
208 }
209 }
211 // iterate over symbol geometries
212 for (const auto& symbolGeometry : mySymbolGeometries) {
213 GUIDottedGeometry::drawDottedSquaredShape(s, GUIDottedGeometry::DottedContourType::FRONT, symbolGeometry.getShape().front(), 1, 3, 0, 3, symbolGeometry.getShapeRotations().front() + 90, rerouteExaggeration);
214 }
215 }
216 }
217}
218
219
220std::string
222 switch (key) {
223 case SUMO_ATTR_ID:
224 case SUMO_ATTR_EDGE:
225 return getParentEdges().front()->getID();
226 default:
227 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
228 }
229}
230
231
232double
234 throw InvalidArgument("Symbols cannot be edited");
235}
236
237
242
243
244void
245GNERerouterSymbol::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/, GNEUndoList* /*undoList*/) {
246 throw InvalidArgument("Symbols cannot be edited");
247}
248
249
250bool
251GNERerouterSymbol::isValid(SumoXMLAttr /*key*/, const std::string& /*value*/) {
252 throw InvalidArgument("Symbols cannot be edited");
253}
254
255
256std::string
258 return getParentEdges().front()->getPopUpID();
259}
260
261
262std::string
264 return getParentEdges().front()->getID();
265}
266
267// ===========================================================================
268// private
269// ===========================================================================
270
271void
272GNERerouterSymbol::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/) {
273 throw InvalidArgument("Symbols cannot be edited");
274}
275
276
277void
279 // nothing to do
280}
281
282
283void
284GNERerouterSymbol::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
285 // nothing to do
286}
287
288/****************************************************************************/
@ 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.
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:2030
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.
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 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 writed into XML (must be reimplemented in all detector chi...
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.
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 GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
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
GUIGlID getGlID() const
Returns the numerical id of the object.
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:4232
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.
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition RGBColor.cpp:92
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