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-2024 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
35 GUIIconSubSys::getIcon(GUIIcon::ROUTEPROBREROUTE), "", {}, {}, {}, {}, {}, {}),
36myProbability(0) {
37 // reset default values
39}
40
41
42GNERouteProbReroute::GNERouteProbReroute(GNEAdditional* rerouterIntervalParent, GNEDemandElement* route, double probability) :
44 GUIIconSubSys::getIcon(GUIIcon::ROUTEPROBREROUTE), "", {}, {}, {}, {rerouterIntervalParent}, {route}, {}),
45myProbability(probability) {
46 // update boundary of rerouter parent
47 rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);
48}
49
50
52
53
54void
61
62
63bool
65 return true;
66}
67
68
69std::string
73
74
75void
77 // nothing to fix
78}
79
80
81bool
83 return false;
84}
85
86
89 // GNERouteProbReroutes cannot be moved
90 return nullptr;
91}
92
93
94void
96 // update centering boundary (needed for centering)
98}
99
100
101void
103 // nothing to do
104}
105
106
109 // get rerouter parent position
110 Position signPosition = getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView();
111 // set position depending of indexes
112 signPosition.add(4.5 + 6.25, (getDrawPositionIndex() * -1) - getParentAdditionals().front()->getDrawPositionIndex() + 1, 0);
113 // return signPosition
114 return signPosition;
115}
116
117
118void
119GNERouteProbReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
120 // geometry of this element cannot be splitted
121}
122
123
124std::string
126 return getParentAdditionals().at(0)->getID();
127}
128
129
130void
138
139
140std::string
142 switch (key) {
143 case SUMO_ATTR_ID:
144 return getMicrosimID();
145 case SUMO_ATTR_ROUTE:
146 return getParentDemandElements().front()->getID();
147 case SUMO_ATTR_PROB:
148 return toString(myProbability);
149 case GNE_ATTR_PARENT:
150 return getParentAdditionals().at(0)->getID();
153 default:
154 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
155 }
156}
157
158
159double
161 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
162}
163
164
169
170
171void
172GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
173 if (value == getAttribute(key)) {
174 return; //avoid needless changes, later logic relies on the fact that attributes have changed
175 }
176 switch (key) {
177 case SUMO_ATTR_ID:
178 case SUMO_ATTR_ROUTE:
179 case SUMO_ATTR_PROB:
181 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
182 break;
183 default:
184 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
185 }
186}
187
188
189bool
190GNERouteProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
191 switch (key) {
192 case SUMO_ATTR_ID:
193 return isValidAdditionalID(value);
194 case SUMO_ATTR_ROUTE:
195 return (myNet->getAttributeCarriers()->retrieveDemandElements(NamespaceIDs::routes, value, false) == nullptr);
196 case SUMO_ATTR_PROB:
197 return canParse<double>(value);
199 return canParse<bool>(value);
200 default:
201 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
202 }
203}
204
205
206std::string
208 return getTagStr();
209}
210
211
212std::string
214 return getTagStr() + ": " + getParentDemandElements().front()->getID();
215}
216
217// ===========================================================================
218// private
219// ===========================================================================
220
221void
222GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
223 switch (key) {
224 case SUMO_ATTR_ID:
225 // update microsimID
226 setAdditionalID(value);
227 break;
228 case SUMO_ATTR_ROUTE:
230 break;
231 case SUMO_ATTR_PROB:
232 myProbability = parse<double>(value);
233 break;
235 if (parse<bool>(value)) {
237 } else {
239 }
240 break;
241 default:
242 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
243 }
244}
245
246
247void
249 // nothing to do
250}
251
252
253void GNERouteProbReroute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
254 // nothing to do
255}
256
257
258/****************************************************************************/
@ GLO_REROUTER_ROUTEPROBREROUTE
a route probability reroute
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ ROUTEPROBREROUTE
@ REROUTER_ROUTEPROBREROUTE
@ SUMO_TAG_ROUTE_PROB_REROUTE
probability of route of a reroute
@ SUMO_TAG_ROUTE
begin/end of the description of a route
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_PARENT
parent of an additional element
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_PROB
@ SUMO_ATTR_ROUTE
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
An Element which don't belong to GNENet but has influence in the simulation.
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
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
static const Parameterised::Map PARAMETERS_EMPTY
empty parameter maps (used by ACs without parameters)
void resetDefaultValues()
reset attribute carrier to their default values
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
const std::vector< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
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:127
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
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:132
static const RGBColor YELLOW
Definition RGBColor.h:188
static const RGBColor RED
named colors
Definition RGBColor.h:185