Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNERouteProbReroute.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/GNEUndoList.h>
24#include <netedit/GNENet.h>
26
27#include "GNERouteProbReroute.h"
28
29// ===========================================================================
30// member method definitions
31// ===========================================================================
32
36
37
38GNERouteProbReroute::GNERouteProbReroute(GNEAdditional* rerouterIntervalParent, GNEDemandElement* route, double probability) :
39 GNEAdditional(rerouterIntervalParent, SUMO_TAG_ROUTE_PROB_REROUTE, ""),
40 myProbability(probability) {
41 // set parents
42 setParent<GNEAdditional*>(rerouterIntervalParent);
43 setParent<GNEDemandElement*>(route);
44 // update boundary of rerouter parent
45 rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);
46}
47
48
50
51
52void
59
60
61bool
63 return true;
64}
65
66
67std::string
71
72
73void
75 // nothing to fix
76}
77
78
79bool
81 return false;
82}
83
84
87 // GNERouteProbReroutes cannot be moved
88 return nullptr;
89}
90
91
92void
94 // update centering boundary (needed for centering)
96}
97
98
99void
101 // nothing to do
102}
103
104
107 // get rerouter parent position
108 Position signPosition = getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView();
109 // set position depending of indexes
110 signPosition.add(4.5 + 6.25, (getDrawPositionIndex() * -1) - getParentAdditionals().front()->getDrawPositionIndex() + 1, 0);
111 // return signPosition
112 return signPosition;
113}
114
115
116void
117GNERouteProbReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
118 // geometry of this element cannot be splitted
119}
120
121
122std::string
124 return getParentAdditionals().at(0)->getID();
125}
126
127
128void
136
137
138std::string
140 switch (key) {
141 case SUMO_ATTR_ID:
142 return getMicrosimID();
143 case SUMO_ATTR_ROUTE:
144 return getParentDemandElements().front()->getID();
145 case SUMO_ATTR_PROB:
146 return toString(myProbability);
147 case GNE_ATTR_PARENT:
148 return getParentAdditionals().at(0)->getID();
149 default:
150 return getCommonAttribute(this, key);
151 }
152}
153
154
155double
157 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
158}
159
160
165
166
167void
168GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
169 if (value == getAttribute(key)) {
170 return; //avoid needless changes, later logic relies on the fact that attributes have changed
171 }
172 switch (key) {
173 case SUMO_ATTR_ID:
174 case SUMO_ATTR_ROUTE:
175 case SUMO_ATTR_PROB:
176 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
177 break;
178 default:
179 setCommonAttribute(key, value, undoList);
180 break;
181 }
182}
183
184
185bool
186GNERouteProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
187 switch (key) {
188 case SUMO_ATTR_ID:
189 return isValidAdditionalID(value);
190 case SUMO_ATTR_ROUTE:
191 return (myNet->getAttributeCarriers()->retrieveDemandElements(NamespaceIDs::routes, value, false) == nullptr);
192 case SUMO_ATTR_PROB:
193 return canParse<double>(value);
194 default:
195 return isCommonValid(key, value);
196 }
197}
198
199
200std::string
202 return getTagStr();
203}
204
205
206std::string
208 return getTagStr() + ": " + getParentDemandElements().front()->getID();
209}
210
211// ===========================================================================
212// private
213// ===========================================================================
214
215void
216GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
217 switch (key) {
218 case SUMO_ATTR_ID:
219 // update microsimID
220 setAdditionalID(value);
221 break;
222 case SUMO_ATTR_ROUTE:
224 break;
225 case SUMO_ATTR_PROB:
226 myProbability = parse<double>(value);
227 break;
228 default:
229 setCommonAttribute(this, key, value);
230 break;
231 }
232}
233
234
235void
237 // nothing to do
238}
239
240
241void GNERouteProbReroute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
242 // nothing to do
243}
244
245
246/****************************************************************************/
@ REROUTER_ROUTEPROBREROUTE
@ SUMO_TAG_ROUTE_PROB_REROUTE
probability of route of a reroute
@ SUMO_TAG_ROUTE
description of a route
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_PARENT
parent of an additional element
@ SUMO_ATTR_PROB
@ SUMO_ATTR_ROUTE
@ 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 drawListedAdditional(const GUIVisualizationSettings &s, const Position &parentPosition, const double offsetX, const double extraOffsetY, const RGBColor baseCol, const RGBColor textCol, GUITexture texture, const std::string text) const
draw listed additional
void setAdditionalID(const std::string &newID)
set additional ID
int getDrawPositionIndex() const
get draw position index (used in rerouters and VSS)
void replaceDemandElementParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace demand element parent
std::string getCommonAttribute(const Parameterised *parameterised, 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
GNENet * myNet
pointer to net
bool isCommonValid(SumoXMLAttr key, const std::string &value) const
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
const GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const GNEHierarchicalContainerParents< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
move operation
move result
GNEDemandElement * retrieveDemandElements(const std::vector< SumoXMLTag > types, const std::string &id, bool hardFail=true) const
Returns the named demand element.
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:147
double myProbability
probability with which a vehicle will use the given edge as destination
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
bool isAdditionalValid() const
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
bool checkDrawMoveContour() const
check if draw move contour (red)
const Parameterised::Map & getACParametersMap() const
get parameters map
std::string getParentName() const
Returns the name of the parent object.
GNERouteProbReroute(GNENet *net)
default constructor
void updateGeometry()
update pre-computed geometry information
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
GNEMoveOperation * getMoveOperation()
get move operation
std::string getAttribute(SumoXMLAttr key) const
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
double getAttributeDouble(SumoXMLAttr key) const
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Position getPositionInView() const
Returns position of additional in view.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Stores the information about how to visualize structures.
static const std::vector< SumoXMLTag > routes
route namespace
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.
std::map< std::string, std::string > Map
parameters map
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
void add(const Position &pos)
Adds the given position to this one.
Definition Position.h:129
static const RGBColor YELLOW
Definition RGBColor.h:191
static const RGBColor RED
named colors
Definition RGBColor.h:188