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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
14 //
15 /****************************************************************************/
16 
17 // ===========================================================================
18 // included modules
19 // ===========================================================================
20 #include <config.h>
21 
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.h>
26 #include <netedit/GNENet.h>
27 
28 #include "GNERouteProbReroute.h"
29 
30 // ===========================================================================
31 // member method definitions
32 // ===========================================================================
33 
35  GNEAdditional(rerouterIntervalDialog->getEditedAdditional(), rerouterIntervalDialog->getEditedAdditional()->getViewNet(), GLO_REROUTER, SUMO_TAG_ROUTE_PROB_REROUTE, "", false,
36 {}, {}, {}, {rerouterIntervalDialog->getEditedAdditional()}, {}, {}, {}, {}, {}, {}) {
37  // if exist a reroute, set newRoute ID
38  if (rerouterIntervalDialog->getEditedAdditional()->getViewNet()->getNet()->getAttributeCarriers().demandElements.at(SUMO_TAG_ROUTE).size() > 0) {
39  myNewRouteId = rerouterIntervalDialog->getEditedAdditional()->getViewNet()->getNet()->getAttributeCarriers().demandElements.at(SUMO_TAG_ROUTE).begin()->first;
40  }
41  // fill route prob reroute interval with default values
42  setDefaultValues();
43 }
44 
45 
46 GNERouteProbReroute::GNERouteProbReroute(GNEAdditional* rerouterIntervalParent, const std::string& newRouteId, double probability) :
47  GNEAdditional(rerouterIntervalParent, rerouterIntervalParent->getViewNet(), GLO_REROUTER, SUMO_TAG_ROUTE_PROB_REROUTE, "", false,
48 {}, {}, {}, {rerouterIntervalParent}, {}, {}, {}, {}, {}, {}),
49 myNewRouteId(newRouteId),
50 myProbability(probability) {
51 }
52 
53 
55 
56 
57 void
59  // This additional cannot be moved
60 }
61 
62 
63 void
65  // This additional cannot be moved
66 }
67 
68 
69 void
71  // Currently this additional doesn't own a Geometry
72 }
73 
74 
77  return getParentAdditionals().at(0)->getPositionInView();
78 }
79 
80 
83  return getParentAdditionals().at(0)->getCenteringBoundary();
84 }
85 
86 
87 void
88 GNERouteProbReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetElement* /*originalElement*/, const GNENetElement* /*newElement*/, GNEUndoList* /*undoList*/) {
89  // geometry of this element cannot be splitted
90 }
91 
92 
93 std::string
95  return getParentAdditionals().at(0)->getID();
96 }
97 
98 
99 void
101  // Currently This additional isn't drawn
102 }
103 
104 
105 std::string
107  switch (key) {
108  case SUMO_ATTR_ID:
109  return getAdditionalID();
110  case SUMO_ATTR_ROUTE:
111  return myNewRouteId;
112  case SUMO_ATTR_PROB:
113  return toString(myProbability);
114  case GNE_ATTR_PARENT:
115  return getParentAdditionals().at(0)->getID();
116  case GNE_ATTR_PARAMETERS:
117  return getParametersStr();
118  default:
119  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
120  }
121 }
122 
123 
124 double
126  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
127 }
128 
129 
130 void
131 GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
132  if (value == getAttribute(key)) {
133  return; //avoid needless changes, later logic relies on the fact that attributes have changed
134  }
135  switch (key) {
136  case SUMO_ATTR_ID:
137  case SUMO_ATTR_ROUTE:
138  case SUMO_ATTR_PROB:
139  case GNE_ATTR_PARAMETERS:
140  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
141  break;
142  default:
143  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
144  }
145 }
146 
147 
148 bool
149 GNERouteProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
150  switch (key) {
151  case SUMO_ATTR_ID:
152  return isValidAdditionalID(value);
153  case SUMO_ATTR_ROUTE:
155  case SUMO_ATTR_PROB:
156  return canParse<double>(value);
157  case GNE_ATTR_PARAMETERS:
158  return Parameterised::areParametersValid(value);
159  default:
160  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
161  }
162 }
163 
164 
165 bool
167  return true;
168 }
169 
170 
171 std::string
173  return getTagStr();
174 }
175 
176 
177 std::string
179  return getTagStr() + ": " + myNewRouteId;
180 }
181 
182 // ===========================================================================
183 // private
184 // ===========================================================================
185 
186 void
187 GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
188  switch (key) {
189  case SUMO_ATTR_ID:
190  changeAdditionalID(value);
191  break;
192  case SUMO_ATTR_ROUTE:
193  myNewRouteId = value;
194  break;
195  case SUMO_ATTR_PROB:
196  myProbability = parse<double>(value);
197  break;
198  case GNE_ATTR_PARAMETERS:
199  setParametersStr(value);
200  break;
201  default:
202  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
203  }
204 }
205 
206 /****************************************************************************/
GNENet::getAttributeCarriers
const AttributeCarriers & getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:1063
GNEAdditional
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
Parameterised::getParametersStr
std::string getParametersStr() const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
Definition: Parameterised.cpp:112
GNEAdditional::getAdditionalID
const std::string & getAdditionalID() const
Definition: GNEAdditional.cpp:476
GNERouteProbReroute::getParentName
std::string getParentName() const
Returns the name of the parent object.
Definition: GNERouteProbReroute.cpp:94
GNERouteProbReroute::getHierarchyName
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNERouteProbReroute.cpp:178
GNERouteProbReroute::getAttribute
std::string getAttribute(SumoXMLAttr key) const
Definition: GNERouteProbReroute.cpp:106
GNERouteProbReroute::~GNERouteProbReroute
~GNERouteProbReroute()
destructor
Definition: GNERouteProbReroute.cpp:54
SUMO_ATTR_ID
@ SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
GNEAdditional::changeAdditionalID
void changeAdditionalID(const std::string &newID)
change ID of additional
Definition: GNEAdditional.cpp:502
GNERouteProbReroute::isValid
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNERouteProbReroute.cpp:149
GNERouteProbReroute::getAttributeDouble
double getAttributeDouble(SumoXMLAttr key) const
Definition: GNERouteProbReroute.cpp:125
GNERouteProbReroute::updateGeometry
void updateGeometry()
update pre-computed geometry information
Definition: GNERouteProbReroute.cpp:70
GNEAdditional::myViewNet
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
Definition: GNEAdditional.h:335
GNERouteProbReroute::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNERouteProbReroute.cpp:100
GNEAttributeCarrier::GNEChange_Attribute
friend class GNEChange_Attribute
declare friend class
Definition: GNEAttributeCarrier.h:57
GNEUndoList::p_add
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
Definition: GNEUndoList.cpp:131
GNEViewNet::getNet
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:1014
GNEHierarchicalParentElements::getParentAdditionals
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
Definition: GNEHierarchicalParentElements.cpp:85
GNERouteProbReroute::setAttribute
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
Definition: GNERouteProbReroute.cpp:131
GNERouteProbReroute::getPopUpID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNERouteProbReroute.cpp:172
GNERouteProbReroute::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNERouteProbReroute.cpp:82
SUMO_ATTR_PROB
@ SUMO_ATTR_PROB
Definition: SUMOXMLDefinitions.h:629
GNERouteProbReroute::GNERouteProbReroute
GNERouteProbReroute(GNERerouterIntervalDialog *rerouterIntervalDialog)
constructor (Used in GNERerouterIntervalDialog)
Definition: GNERouteProbReroute.cpp:34
GNEViewNet.h
SUMO_ATTR_ROUTE
@ SUMO_ATTR_ROUTE
Definition: SUMOXMLDefinitions.h:440
GNERerouterIntervalDialog.h
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:41
GNERouteProbReroute::isAttributeEnabled
bool isAttributeEnabled(SumoXMLAttr key) const
Definition: GNERouteProbReroute.cpp:166
GNE_ATTR_PARAMETERS
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
Definition: SUMOXMLDefinitions.h:989
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
SUMO_TAG_ROUTE_PROB_REROUTE
@ SUMO_TAG_ROUTE_PROB_REROUTE
probability of route of a reroute
Definition: SUMOXMLDefinitions.h:196
GNENetElement
Definition: GNENetElement.h:43
GNENet::AttributeCarriers::demandElements
std::map< SumoXMLTag, std::map< std::string, GNEDemandElement * > > demandElements
map with the name and pointer to demand elements of net
Definition: GNENet.h:104
Parameterised::setParametersStr
void setParametersStr(const std::string &paramsString)
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
Definition: Parameterised.cpp:139
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
Parameterised::areParametersValid
static bool areParametersValid(const std::string &value, bool report=false)
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
Definition: Parameterised.cpp:166
InvalidArgument
Definition: UtilExceptions.h:56
GLO_REROUTER
@ GLO_REROUTER
a Rerouter
Definition: GUIGlObjectTypes.h:85
SUMOXMLDefinitions::isValidVehicleID
static bool isValidVehicleID(const std::string &value)
whether the given string is a valid id for a vehicle or flow
Definition: SUMOXMLDefinitions.cpp:973
GNERouteProbReroute::getPositionInView
Position getPositionInView() const
Returns position of additional in view.
Definition: GNERouteProbReroute.cpp:76
GNEAdditional::getViewNet
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
Definition: GNEAdditional.cpp:307
GNERouteProbReroute::myProbability
double myProbability
probability with which a vehicle will use the given edge as destination
Definition: GNERouteProbReroute.h:137
SUMO_TAG_ROUTE
@ SUMO_TAG_ROUTE
begin/end of the description of a route
Definition: SUMOXMLDefinitions.h:125
config.h
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1267
GNEUndoList
Definition: GNEUndoList.h:48
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:345
GNEAdditional::isValidAdditionalID
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Definition: GNEAdditional.cpp:482
GNERouteProbReroute::myNewRouteId
std::string myNewRouteId
id of new route
Definition: GNERouteProbReroute.h:134
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:372
GNERouteProbReroute.h
GNERouteProbReroute::commitGeometryMoving
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(....
Definition: GNERouteProbReroute.cpp:64
GNEChange_Attribute.h
GNENet.h
GNERouteProbReroute::splitEdgeGeometry
void splitEdgeGeometry(const double splitPosition, const GNENetElement *originalElement, const GNENetElement *newElement, GNEUndoList *undoList)
split geometry
Definition: GNERouteProbReroute.cpp:88
GNERerouterIntervalDialog
Dialog for edit rerouter intervals.
Definition: GNERerouterIntervalDialog.h:49
GNERouteProbReroute::moveGeometry
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNERouteProbReroute.cpp:58
GNEUndoList.h
GNE_ATTR_PARENT
@ GNE_ATTR_PARENT
parent of an additional element
Definition: SUMOXMLDefinitions.h:987