Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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#include <netedit/GNEUndoList.h>
25
26#include "GNEDestProbReroute.h"
27
28// ===========================================================================
29// member method definitions
30// ===========================================================================
31
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, ""),
41 myNewEdgeDestination(newEdgeDestination),
42 myProbability(probability) {
43 // set parents
44 setParent<GNEAdditional*>(rerouterIntervalParent);
45 // update boundary of rerouter parent
46 rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);
47}
48
49
51
52
53void
60
61
62bool
64 return true;
65}
66
67
68std::string
70 return "";
71}
72
73
74void
76 // nothing to fix
77}
78
79
80bool
82 return false;
83}
84
85
88 // GNEDestProbReroutes cannot be moved
89 return nullptr;
90}
91
92
93void
95 // update centering boundary (needed for centering)
97}
98
99
102 // get rerouter parent position
103 Position signPosition = getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView();
104 // set position depending of indexes
105 signPosition.add(4.5 + 6.25, (getDrawPositionIndex() * -1) - getParentAdditionals().front()->getDrawPositionIndex() + 1, 0);
106 // return signPosition
107 return signPosition;
108}
109
110
111void
113 // nothing to update
114}
115
116
117void
118GNEDestProbReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
119 // geometry of this element cannot be splitted
120}
121
122
123std::string
125 return getParentAdditionals().at(0)->getID();
126}
127
128
129void
137
138
139std::string
141 switch (key) {
142 case SUMO_ATTR_ID:
143 return getMicrosimID();
144 case SUMO_ATTR_EDGE:
145 return myNewEdgeDestination->getID();
146 case SUMO_ATTR_PROB:
147 return toString(myProbability);
148 case GNE_ATTR_PARENT:
149 return getParentAdditionals().at(0)->getID();
150 default:
151 return getCommonAttribute(this, key);
152 }
153}
154
155
156double
158 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
159}
160
161
166
167
168void
169GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
170 if (value == getAttribute(key)) {
171 return; //avoid needless changes, later logic relies on the fact that attributes have changed
172 }
173 switch (key) {
174 case SUMO_ATTR_ID:
175 case SUMO_ATTR_EDGE:
176 case SUMO_ATTR_PROB:
177 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
178 break;
179 default:
180 setCommonAttribute(key, value, undoList);
181 break;
182 }
183}
184
185
186bool
187GNEDestProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
188 switch (key) {
189 case SUMO_ATTR_ID:
190 return isValidAdditionalID(value);
191 case SUMO_ATTR_EDGE:
192 return (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr);
193 case SUMO_ATTR_PROB:
194 return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
195 default:
196 return isCommonValid(key, value);
197 }
198}
199
200
201std::string
203 return getTagStr();
204}
205
206
207std::string
211
212// ===========================================================================
213// private
214// ===========================================================================
215
216void
217GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
218 switch (key) {
219 case SUMO_ATTR_ID:
220 // update microsimID
221 setAdditionalID(value);
222 break;
223 case SUMO_ATTR_EDGE:
225 break;
226 case SUMO_ATTR_PROB:
227 myProbability = parse<double>(value);
228 break;
229 default:
230 setCommonAttribute(this, key, value);
231 break;
232 }
233}
234
235
236void
238 // nothing to do
239}
240
241
242void
243GNEDestProbReroute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
244 // nothing to do
245}
246
247
248/****************************************************************************/
@ 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 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)
const std::string getID() const
get ID (all Attribute Carriers have one)
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
std::string getAttribute(SumoXMLAttr key) const
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
double getAttributeDouble(SumoXMLAttr key) const
GNEMoveOperation * getMoveOperation()
get move operation
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
const Parameterised::Map & getACParametersMap() const
get parameters map
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
double myProbability
probability with which a vehicle will use the given edge as destination
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Position getPositionInView() const
Returns position of additional in view.
GNEDestProbReroute(GNENet *net)
constructor
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
std::string getParentName() const
Returns the name of the parent object.
GNEEdge * myNewEdgeDestination
id of new edge destination
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
bool checkDrawMoveContour() const
check if draw move contour (red)
bool isAdditionalValid() const
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
void updateGeometry()
update pre-computed geometry information
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
const GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
move operation
move result
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:146
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.
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