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-2023 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>
25
26#include "GNERouteProbReroute.h"
27
28// ===========================================================================
29// member method definitions
30// ===========================================================================
31
34 GUIIconSubSys::getIcon(GUIIcon::ROUTEPROBREROUTE), "", {}, {}, {}, {}, {}, {}),
35myProbability(0) {
36 // reset default values
38}
39
40
41GNERouteProbReroute::GNERouteProbReroute(GNEAdditional* rerouterIntervalParent, GNEDemandElement* route, double probability) :
43 GUIIconSubSys::getIcon(GUIIcon::ROUTEPROBREROUTE), "", {}, {}, {}, {rerouterIntervalParent}, {route}, {}),
44myProbability(probability) {
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
72
73
74void
76 // nothing to fix
77}
78
79
82 // GNERouteProbReroutes cannot be moved
83 return nullptr;
84}
85
86
87void
89 // update centering boundary (needed for centering)
91}
92
93
94void
100
101
104 // get rerouter parent position
105 Position signPosition = getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView();
106 // set position depending of indexes
107 signPosition.add(4.5 + 6.25, (getDrawPositionIndex() * -1) - getParentAdditionals().front()->getDrawPositionIndex() + 1, 0);
108 // return signPosition
109 return signPosition;
110}
111
112
113void
114GNERouteProbReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
115 // geometry of this element cannot be splitted
116}
117
118
119std::string
121 return getParentAdditionals().at(0)->getID();
122}
123
124
125void
133
134
135std::string
137 switch (key) {
138 case SUMO_ATTR_ID:
139 return getMicrosimID();
140 case SUMO_ATTR_ROUTE:
141 return getParentDemandElements().front()->getID();
142 case SUMO_ATTR_PROB:
143 return toString(myProbability);
144 case GNE_ATTR_PARENT:
145 return getParentAdditionals().at(0)->getID();
148 default:
149 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
150 }
151}
152
153
154double
156 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
157}
158
159
164
165
166void
167GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
168 if (value == getAttribute(key)) {
169 return; //avoid needless changes, later logic relies on the fact that attributes have changed
170 }
171 switch (key) {
172 case SUMO_ATTR_ID:
173 case SUMO_ATTR_ROUTE:
174 case SUMO_ATTR_PROB:
176 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
177 break;
178 default:
179 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
180 }
181}
182
183
184bool
185GNERouteProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
186 switch (key) {
187 case SUMO_ATTR_ID:
188 return isValidAdditionalID(value);
189 case SUMO_ATTR_ROUTE:
190 return (myNet->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_ROUTE, value, false) != nullptr);
191 case SUMO_ATTR_PROB:
192 return canParse<double>(value);
194 return canParse<bool>(value);
195 default:
196 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
197 }
198}
199
200
201std::string
203 return getTagStr();
204}
205
206
207std::string
209 return getTagStr() + ": " + getParentDemandElements().front()->getID();
210}
211
212// ===========================================================================
213// private
214// ===========================================================================
215
216void
217GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
218 switch (key) {
219 case SUMO_ATTR_ID:
220 // update microsimID
221 setMicrosimID(value);
222 break;
223 case SUMO_ATTR_ROUTE:
225 break;
226 case SUMO_ATTR_PROB:
227 myProbability = parse<double>(value);
228 break;
230 if (parse<bool>(value)) {
232 } else {
234 }
235 break;
236 default:
237 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
238 }
239}
240
241
242void
244 // nothing to do
245}
246
247
248void GNERouteProbReroute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
249 // nothing to do
250}
251
252
253/****************************************************************************/
@ 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
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition Boundary.cpp:78
void reset()
Resets the boundary.
Definition Boundary.cpp:66
Boundary & grow(double by)
extends the boundary by the given amount
Definition Boundary.cpp:300
An Element which don't belong to GNENet but has influence in the simulation.
void drawListedAddtional(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
int getDrawPositionIndex() const
get draw position index (used in rerouters and VSS)
Boundary myAdditionalBoundary
Additional Boundary.
void replaceDemandElementParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace demand element parent
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
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
An Element which don't belong to GNENet but has influence in the simulation.
const std::vector< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
move operation
move result
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, 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:120
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 writed into XML (must be reimplemented in all detector chi...
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)
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
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
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
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:125
static const RGBColor YELLOW
Definition RGBColor.h:188
static const RGBColor RED
named colors
Definition RGBColor.h:185