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#include <config.h>
21
23#include <netedit/GNENet.h>
24
25#include "GNEDestProbReroute.h"
26
27// ===========================================================================
28// member method definitions
29// ===========================================================================
30
34 myNewEdgeDestination(nullptr),
35 myProbability(0) {
36}
37
38
39GNEDestProbReroute::GNEDestProbReroute(GNEAdditional* rerouterIntervalParent, GNEEdge* newEdgeDestination, double probability):
40 GNEAdditional(rerouterIntervalParent, SUMO_TAG_DEST_PROB_REROUTE, ""),
42 myNewEdgeDestination(newEdgeDestination),
43 myProbability(probability) {
44 // set parents
45 setParent<GNEAdditional*>(rerouterIntervalParent);
46 setParent<GNEEdge*>(newEdgeDestination);
47 // update boundary of rerouter parent
48 rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);
49}
50
51
53
54
57 return nullptr;
58}
59
60
63 return nullptr;
64}
65
66
67const Parameterised*
69 return nullptr;
70}
71
72
73void
76 // write common additional attributes
78 // write specific attributes
81 device.closeTag();
82}
83
84
85bool
87 return true;
88}
89
90
91std::string
93 return "";
94}
95
96
97void
99 // nothing to fix
100}
101
102
103bool
105 return false;
106}
107
108
109void
113
114
119
120
121void
123 // nothing to update
124}
125
126
127void
128GNEDestProbReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
129 // geometry of this element cannot be splitted
130}
131
132
133std::string
135 return getParentAdditionals().at(0)->getID();
136}
137
138
139void
145
146
147std::string
149 switch (key) {
150 case SUMO_ATTR_ID:
151 return getMicrosimID();
152 case SUMO_ATTR_EDGE:
153 return myNewEdgeDestination->getID();
154 case SUMO_ATTR_PROB:
155 return toString(myProbability);
156 case GNE_ATTR_PARENT:
157 return getParentAdditionals().at(0)->getID();
158 default:
159 return getCommonAttribute(key);
160 }
161}
162
163
164double
168
169
174
175
180
181
182void
183GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
184 if (value == getAttribute(key)) {
185 return; //avoid needless changes, later logic relies on the fact that attributes have changed
186 }
187 switch (key) {
188 case SUMO_ATTR_ID:
189 case SUMO_ATTR_EDGE:
190 case SUMO_ATTR_PROB:
191 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
192 break;
193 default:
194 setCommonAttribute(key, value, undoList);
195 break;
196 }
197}
198
199
200bool
201GNEDestProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
202 switch (key) {
203 case SUMO_ATTR_ID:
204 return isValidAdditionalID(value);
205 case SUMO_ATTR_EDGE:
206 return (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr);
207 case SUMO_ATTR_PROB:
208 return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
209 default:
210 return isCommonAttributeValid(key, value);
211 }
212}
213
214
215std::string
217 return getTagStr();
218}
219
220
221std::string
225
226// ===========================================================================
227// private
228// ===========================================================================
229
230void
231GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
232 switch (key) {
233 case SUMO_ATTR_ID:
234 // update microsimID
235 setAdditionalID(value);
236 break;
237 case SUMO_ATTR_EDGE:
239 break;
240 case SUMO_ATTR_PROB:
241 myProbability = parse<double>(value);
242 break;
243 default:
244 setCommonAttribute(key, value);
245 break;
246 }
247}
248
249/****************************************************************************/
@ 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
double getCommonAttributeDouble(SumoXMLAttr key) const
const std::string getID() const override
get ID (all Attribute Carriers have one)
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
GNEEdge * myNewEdgeDestination
id of new edge destination
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)
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