Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEDestProbReroute.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
22#include <netedit/GNENet.h>
23
24#include "GNEDestProbReroute.h"
25
26// ===========================================================================
27// member method definitions
28// ===========================================================================
29
33 myNewEdgeDestination(nullptr),
34 myProbability(0) {
35}
36
37
38GNEDestProbReroute::GNEDestProbReroute(GNEAdditional* rerouterIntervalParent, GNEEdge* newEdgeDestination, double probability):
39 GNEAdditional(rerouterIntervalParent, SUMO_TAG_DEST_PROB_REROUTE, ""),
41 myNewEdgeDestination(newEdgeDestination),
42 myProbability(probability) {
43 // set parents
44 setParent<GNEAdditional*>(rerouterIntervalParent);
45 setParent<GNEEdge*>(newEdgeDestination);
46 // update boundary of rerouter parent
47 rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);
48}
49
50
52
53
56 return nullptr;
57}
58
59
62 return nullptr;
63}
64
65
66const Parameterised*
68 return nullptr;
69}
70
71
72void
75 // write common additional attributes
77 // write specific attributes
80 device.closeTag();
81}
82
83
84bool
86 return true;
87}
88
89
90std::string
92 return "";
93}
94
95
96void
98 // nothing to fix
99}
100
101
102bool
104 return false;
105}
106
107
108void
112
113
118
119
120void
122 // nothing to update
123}
124
125
126void
127GNEDestProbReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
128 // geometry of this element cannot be splitted
129}
130
131
132std::string
134 return getParentAdditionals().at(0)->getID();
135}
136
137
138void
144
145
146std::string
148 switch (key) {
149 case SUMO_ATTR_ID:
150 return getMicrosimID();
151 case SUMO_ATTR_EDGE:
152 return myNewEdgeDestination->getID();
153 case SUMO_ATTR_PROB:
154 return toString(myProbability);
155 case GNE_ATTR_PARENT:
156 return getParentAdditionals().at(0)->getID();
157 default:
158 return getCommonAttribute(key);
159 }
160}
161
162
163double
167
168
173
174
179
180
181void
182GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
183 if (value == getAttribute(key)) {
184 return; //avoid needless changes, later logic relies on the fact that attributes have changed
185 }
186 switch (key) {
187 case SUMO_ATTR_ID:
188 case SUMO_ATTR_EDGE:
189 case SUMO_ATTR_PROB:
190 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
191 break;
192 default:
193 setCommonAttribute(key, value, undoList);
194 break;
195 }
196}
197
198
199bool
200GNEDestProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
201 switch (key) {
202 case SUMO_ATTR_ID:
203 return isValidAdditionalID(value);
204 case SUMO_ATTR_EDGE:
205 return (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr);
206 case SUMO_ATTR_PROB:
207 return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
208 default:
209 return isCommonAttributeValid(key, value);
210 }
211}
212
213
214std::string
216 return getTagStr();
217}
218
219
220std::string
224
225// ===========================================================================
226// private
227// ===========================================================================
228
229void
230GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
231 switch (key) {
232 case SUMO_ATTR_ID:
233 // update microsimID
234 setAdditionalID(value);
235 break;
236 case SUMO_ATTR_EDGE:
238 break;
239 case SUMO_ATTR_PROB:
240 myProbability = parse<double>(value);
241 break;
242 default:
243 setCommonAttribute(key, value);
244 break;
245 }
246}
247
248/****************************************************************************/
@ REROUTER_DESTPROBREROUTE
@ SUMO_TAG_DEST_PROB_REROUTE
probability of destination of a reroute
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_EDGE
@ GNE_ATTR_PARENT
parent of an additional element
@ SUMO_ATTR_PROB
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
bool isValidAdditionalID(const std::string &value) const
check if a new additional ID is valid
void setAdditionalID(const std::string &newID)
set additional ID
void writeAdditionalAttributes(OutputDevice &device) const
write common additional attributes
void drawListedAdditional(const GUIVisualizationSettings &s, const RGBColor baseCol, const RGBColor textCol, GUITexture texture, const std::string text) const
draw listed additional
Position getListedPositionInView() const
get listed position in view
void updateGeometryListedAdditional()
update geometry of listed additional
const std::string getID() const
get ID (all Attribute Carriers have one)
double getCommonAttributeDouble(SumoXMLAttr key) const
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
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
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
bool checkDrawMoveContour() const override
check if draw move contour (red)
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
Position getAttributePosition(SumoXMLAttr key) const override
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
std::string getAttribute(SumoXMLAttr key) const override
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
void updateGeometry() override
update pre-computed geometry information
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
double myProbability
probability with which a vehicle will use the given edge as destination
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Position getPositionInView() const
Returns position of additional in view.
GNEDestProbReroute(GNENet *net)
constructor
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this destProbReroute
Parameterised * getParameters() override
get parameters associated with this destProbReroute
std::string getParentName() const
Returns the name of the parent object.
GNEEdge * myNewEdgeDestination
id of new edge destination
double getAttributeDouble(SumoXMLAttr key) const override
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
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
const GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
GNEEdge * retrieveEdge(const std::string &id, bool hardFail=true) const
get edge by id
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:144
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Stores the information about how to visualize structures.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
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.
static const RGBColor YELLOW
Definition RGBColor.h:191
static const RGBColor RED
named colors
Definition RGBColor.h:188