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-2026 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
23#include <netedit/GNENet.h>
24
25#include "GNEDestProbReroute.h"
26
27// ===========================================================================
28// member method definitions
29// ===========================================================================
30
36
37
38GNEDestProbReroute::GNEDestProbReroute(GNEAdditional* rerouterIntervalParent, const std::string& 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 GNEEdge* realEdge = myNet->getAttributeCarriers()->retrieveEdge(newEdgeDestination, false);
46 if (realEdge) {
47 setParent<GNEEdge*>(realEdge);
48 // update boundary of rerouter parent
49 rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);
50 }
51}
52
53
55
56
59 return nullptr;
60}
61
62
65 return nullptr;
66}
67
68
69const Parameterised*
71 return nullptr;
72}
73
74
75void
78 // write common additional attributes
80 // write specific attributes
83 device.closeTag();
84}
85
86
87bool
89 return true;
90}
91
92
93std::string
95 return "";
96}
97
98
99void
101 // nothing to fix
102}
103
104
105bool
107 return false;
108}
109
110
111void
115
116
121
122
123void
125 // nothing to update
126}
127
128
129void
130GNEDestProbReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
131 // geometry of this element cannot be splitted
132}
133
134
135std::string
137 return getParentAdditionals().at(0)->getID();
138}
139
140
141void
147
148
149std::string
151 switch (key) {
152 case SUMO_ATTR_ID:
153 return getMicrosimID();
154 case SUMO_ATTR_EDGE:
156 case SUMO_ATTR_PROB:
157 return toString(myProbability);
158 case GNE_ATTR_PARENT:
159 return getParentAdditionals().at(0)->getID();
160 default:
161 return getCommonAttribute(key);
162 }
163}
164
165
166double
170
171
176
177
182
183
184void
185GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
186 if (value == getAttribute(key)) {
187 return; //avoid needless changes, later logic relies on the fact that attributes have changed
188 }
189 switch (key) {
190 case SUMO_ATTR_ID:
191 case SUMO_ATTR_EDGE:
192 case SUMO_ATTR_PROB:
193 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
194 break;
195 default:
196 setCommonAttribute(key, value, undoList);
197 break;
198 }
199}
200
201
202bool
203GNEDestProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
204 switch (key) {
205 case SUMO_ATTR_ID:
206 return isValidAdditionalID(value);
207 case SUMO_ATTR_EDGE:
208 return (value == "keepDestination"
209 || value == "terminateRoute"
210 || (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr));
211 case SUMO_ATTR_PROB:
212 return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
213 default:
214 return isCommonAttributeValid(key, value);
215 }
216}
217
218
219std::string
221 return getTagStr();
222}
223
224
225std::string
229
230// ===========================================================================
231// private
232// ===========================================================================
233
234void
235GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
236 switch (key) {
237 case SUMO_ATTR_ID:
238 // update microsimID
239 setAdditionalID(value);
240 break;
241 case SUMO_ATTR_EDGE:
242 myNewEdgeDestination = value;
243 break;
244 case SUMO_ATTR_PROB:
245 myProbability = parse<double>(value);
246 break;
247 default:
248 setCommonAttribute(key, value);
249 break;
250 }
251}
252
253/****************************************************************************/
@ 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:49
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
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
Position getPositionInView() const override
Returns position of additional in view.
bool checkDrawMoveContour() const override
check if draw move contour (red)
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
std::string getAdditionalProblem() const override
return a string with the current additional problem (must be reimplemented in all detector children)
void fixAdditionalProblem() override
fix additional problem (must be reimplemented in all detector children)
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
Position getAttributePosition(SumoXMLAttr key) const override
std::string getParentName() const override
Returns the name of the parent object.
std::string getAttribute(SumoXMLAttr key) const override
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
void updateGeometry() override
update pre-computed geometry information
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
void writeAdditional(OutputDevice &device) const override
write additional element into a xml file
bool isAdditionalValid() const override
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
double myProbability
probability with which a vehicle will use the given edge as destination
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
void updateCenteringBoundary(const bool updateGrid) override
update centering boundary (implies change in RTREE)
double getAttributeDouble(SumoXMLAttr key) const override
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
std::string myNewEdgeDestination
id of new edge destination
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
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:174
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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false)
writes a named attribute
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:195
static const RGBColor RED
named colors
Definition RGBColor.h:192