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
31#ifdef _MSC_VER
32#pragma warning(push)
33#pragma warning(disable: 4355) // mask warning about "this" in initializers
34#endif
40
41
42GNEDestProbReroute::GNEDestProbReroute(GNEAdditional* rerouterIntervalParent, const std::string& newEdgeDestination, double probability):
43 GNEAdditional(rerouterIntervalParent, SUMO_TAG_DEST_PROB_REROUTE, ""),
45 myNewEdgeDestination(newEdgeDestination),
46 myProbability(probability) {
47 // set parents
48 setParent<GNEAdditional*>(rerouterIntervalParent);
49 GNEEdge* realEdge = myNet->getAttributeCarriers()->retrieveEdge(newEdgeDestination, false);
50 if (realEdge) {
51 setParent<GNEEdge*>(realEdge);
52 // update boundary of rerouter parent
53 rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);
54 }
55}
56#ifdef _MSC_VER
57#pragma warning(pop)
58#endif
59
60
62
63
66 return nullptr;
67}
68
69
72 return nullptr;
73}
74
75
76const Parameterised*
78 return nullptr;
79}
80
81
82void
85 // write common additional attributes
87 // write specific attributes
90 device.closeTag();
91}
92
93
94bool
96 return true;
97}
98
99
100std::string
102 return "";
103}
104
105
106void
108 // nothing to fix
109}
110
111
112bool
114 return false;
115}
116
117
118void
122
123
128
129
130void
132 // nothing to update
133}
134
135
136void
137GNEDestProbReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
138 // geometry of this element cannot be splitted
139}
140
141
142std::string
144 return getParentAdditionals().at(0)->getID();
145}
146
147
148void
154
155
156std::string
158 switch (key) {
159 case SUMO_ATTR_ID:
160 return getMicrosimID();
161 case SUMO_ATTR_EDGE:
163 case SUMO_ATTR_PROB:
164 return toString(myProbability);
165 case GNE_ATTR_PARENT:
166 return getParentAdditionals().at(0)->getID();
167 default:
168 return getCommonAttribute(key);
169 }
170}
171
172
173double
177
178
183
184
189
190
191void
192GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
193 if (value == getAttribute(key)) {
194 return; //avoid needless changes, later logic relies on the fact that attributes have changed
195 }
196 switch (key) {
197 case SUMO_ATTR_ID:
198 case SUMO_ATTR_EDGE:
199 case SUMO_ATTR_PROB:
200 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
201 break;
202 default:
203 setCommonAttribute(key, value, undoList);
204 break;
205 }
206}
207
208
209bool
210GNEDestProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
211 switch (key) {
212 case SUMO_ATTR_ID:
213 return isValidAdditionalID(value);
214 case SUMO_ATTR_EDGE:
215 return (value == "keepDestination"
216 || value == "terminateRoute"
217 || (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr));
218 case SUMO_ATTR_PROB:
219 return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
220 default:
221 return isCommonAttributeValid(key, value);
222 }
223}
224
225
226std::string
228 return getTagStr();
229}
230
231
232std::string
236
237// ===========================================================================
238// private
239// ===========================================================================
240
241void
242GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
243 switch (key) {
244 case SUMO_ATTR_ID:
245 // update microsimID
246 setAdditionalID(value);
247 break;
248 case SUMO_ATTR_EDGE:
249 myNewEdgeDestination = value;
250 break;
251 case SUMO_ATTR_PROB:
252 myProbability = parse<double>(value);
253 break;
254 default:
255 setCommonAttribute(key, value);
256 break;
257 }
258}
259
260/****************************************************************************/
@ 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