Eclipse SUMO - Simulation of Urban MObility
GNERouteProbReroute.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2020 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 
32 GNERouteProbReroute::GNERouteProbReroute(GNEAdditional* rerouterIntervalParent, const std::string& newRouteId, double probability) :
33  GNEAdditional(rerouterIntervalParent->getNet(), GLO_REROUTER, SUMO_TAG_ROUTE_PROB_REROUTE, "", false,
34 {}, {}, {}, {rerouterIntervalParent}, {}, {}, {}, {}),
35 myNewRouteId(newRouteId),
36 myProbability(probability) {
37  // update centering boundary without updating grid
38  updateCenteringBoundary(false);
39 }
40 
41 
43 
44 
46 GNERouteProbReroute::getMoveOperation(const double /*shapeOffset*/) {
47  // GNERouteProbReroutes cannot be moved
48  return nullptr;
49 }
50 
51 
52 void
54  // This additional doesn't own a geometry
55 }
56 
57 
58 void
60  // use boundary of parent element
61  myBoundary = getParentAdditionals().front()->getCenteringBoundary();
62 }
63 
64 
65 void
66 GNERouteProbReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
67  // geometry of this element cannot be splitted
68 }
69 
70 
71 std::string
73  return getParentAdditionals().at(0)->getID();
74 }
75 
76 
77 void
79  // Currently This additional isn't drawn
80 }
81 
82 
83 std::string
85  switch (key) {
86  case SUMO_ATTR_ID:
87  return getID();
88  case SUMO_ATTR_ROUTE:
89  return myNewRouteId;
90  case SUMO_ATTR_PROB:
91  return toString(myProbability);
92  case GNE_ATTR_PARENT:
93  return getParentAdditionals().at(0)->getID();
95  return getParametersStr();
96  default:
97  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
98  }
99 }
100 
101 
102 double
104  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
105 }
106 
107 
108 void
109 GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
110  if (value == getAttribute(key)) {
111  return; //avoid needless changes, later logic relies on the fact that attributes have changed
112  }
113  switch (key) {
114  case SUMO_ATTR_ID:
115  case SUMO_ATTR_ROUTE:
116  case SUMO_ATTR_PROB:
117  case GNE_ATTR_PARAMETERS:
118  undoList->p_add(new GNEChange_Attribute(this, key, value));
119  break;
120  default:
121  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
122  }
123 }
124 
125 
126 bool
127 GNERouteProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
128  switch (key) {
129  case SUMO_ATTR_ID:
130  return isValidAdditionalID(value);
131  case SUMO_ATTR_ROUTE:
133  case SUMO_ATTR_PROB:
134  return canParse<double>(value);
135  case GNE_ATTR_PARAMETERS:
136  return Parameterised::areParametersValid(value);
137  default:
138  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
139  }
140 }
141 
142 
143 bool
145  return true;
146 }
147 
148 
149 std::string
151  return getTagStr();
152 }
153 
154 
155 std::string
157  return getTagStr() + ": " + myNewRouteId;
158 }
159 
160 // ===========================================================================
161 // private
162 // ===========================================================================
163 
164 void
165 GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
166  switch (key) {
167  case SUMO_ATTR_ID:
168  myNet->getAttributeCarriers()->updateID(this, value);
169  break;
170  case SUMO_ATTR_ROUTE:
171  myNewRouteId = value;
172  break;
173  case SUMO_ATTR_PROB:
174  myProbability = parse<double>(value);
175  break;
176  case GNE_ATTR_PARAMETERS:
177  setParametersStr(value);
178  break;
179  default:
180  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
181  }
182 }
183 
184 
185 void
187  // nothing to do
188 }
189 
190 
191 void GNERouteProbReroute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
192  // nothing to do
193 }
194 
195 
196 /****************************************************************************/
@ GLO_REROUTER
a Rerouter
@ SUMO_TAG_ROUTE_PROB_REROUTE
probability of route of a reroute
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_PARENT
parent of an additional element
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_PROB
@ SUMO_ATTR_ROUTE
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const std::string & getID() const
get ID
Boundary myBoundary
Additional Boundary.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
move operation
move result
void updateID(GNEAttributeCarrier *AC, const std::string newID)
update ID
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
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
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
std::string getParentName() const
Returns the name of the parent object.
void updateGeometry()
update pre-computed geometry information
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
GNERouteProbReroute(GNEAdditional *rerouterIntervalParent, const std::string &newRouteId, double probability)
constructor
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
double getAttributeDouble(SumoXMLAttr key) const
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
std::string myNewRouteId
id of new route
bool isAttributeEnabled(SumoXMLAttr key) const
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
Stores the information about how to visualize structures.
static bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
static bool isValidVehicleID(const std::string &value)
whether the given string is a valid id for a vehicle or flow