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 /****************************************************************************/
15 //
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
25 #include <netedit/GNEUndoList.h>
26 #include <netedit/GNEViewNet.h>
27 #include <netedit/GNENet.h>
28 
29 #include "GNERouteProbReroute.h"
30 
31 // ===========================================================================
32 // member method definitions
33 // ===========================================================================
34 
36  GNEAdditional(rerouterIntervalDialog->getEditedAdditional(), rerouterIntervalDialog->getEditedAdditional()->getViewNet(), GLO_REROUTER, SUMO_TAG_ROUTE_PROB_REROUTE, "", false,
37 {}, {}, {}, {rerouterIntervalDialog->getEditedAdditional()}, {}, {}, {}, {}, {}, {}) {
38  // if exist a reroute, set newRoute ID
39  if (rerouterIntervalDialog->getEditedAdditional()->getViewNet()->getNet()->getAttributeCarriers().demandElements.at(SUMO_TAG_ROUTE).size() > 0) {
40  myNewRouteId = rerouterIntervalDialog->getEditedAdditional()->getViewNet()->getNet()->getAttributeCarriers().demandElements.at(SUMO_TAG_ROUTE).begin()->first;
41  }
42  // fill route prob reroute interval with default values
43  setDefaultValues();
44 }
45 
46 
47 GNERouteProbReroute::GNERouteProbReroute(GNEAdditional* rerouterIntervalParent, const std::string& newRouteId, double probability) :
48  GNEAdditional(rerouterIntervalParent, rerouterIntervalParent->getViewNet(), GLO_REROUTER, SUMO_TAG_ROUTE_PROB_REROUTE, "", false,
49 {}, {}, {}, {rerouterIntervalParent}, {}, {}, {}, {}, {}, {}),
50 myNewRouteId(newRouteId),
51 myProbability(probability) {
52 }
53 
54 
56 
57 
58 void
60  // This additional cannot be moved
61 }
62 
63 
64 void
66  // This additional cannot be moved
67 }
68 
69 
70 void
72  // Currently this additional doesn't own a Geometry
73 }
74 
75 
78  return getAdditionalParents().at(0)->getPositionInView();
79 }
80 
81 
84  return getAdditionalParents().at(0)->getCenteringBoundary();
85 }
86 
87 
88 std::string
90  return getAdditionalParents().at(0)->getID();
91 }
92 
93 
94 void
96  // Currently This additional isn't drawn
97 }
98 
99 
100 std::string
102  switch (key) {
103  case SUMO_ATTR_ID:
104  return getAdditionalID();
105  case SUMO_ATTR_ROUTE:
106  return myNewRouteId;
107  case SUMO_ATTR_PROB:
108  return toString(myProbability);
109  case GNE_ATTR_PARENT:
110  return getAdditionalParents().at(0)->getID();
111  case GNE_ATTR_GENERIC:
112  return getGenericParametersStr();
113  default:
114  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
115  }
116 }
117 
118 
119 void
120 GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
121  if (value == getAttribute(key)) {
122  return; //avoid needless changes, later logic relies on the fact that attributes have changed
123  }
124  switch (key) {
125  case SUMO_ATTR_ID:
126  case SUMO_ATTR_ROUTE:
127  case SUMO_ATTR_PROB:
128  case GNE_ATTR_GENERIC:
129  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
130  break;
131  default:
132  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
133  }
134 }
135 
136 
137 bool
138 GNERouteProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
139  switch (key) {
140  case SUMO_ATTR_ID:
141  return isValidAdditionalID(value);
142  case SUMO_ATTR_ROUTE:
144  case SUMO_ATTR_PROB:
145  return canParse<double>(value);
146  case GNE_ATTR_GENERIC:
147  return isGenericParametersValid(value);
148  default:
149  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
150  }
151 }
152 
153 
154 std::string
156  return getTagStr();
157 }
158 
159 
160 std::string
162  return getTagStr() + ": " + myNewRouteId;
163 }
164 
165 // ===========================================================================
166 // private
167 // ===========================================================================
168 
169 void
170 GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
171  switch (key) {
172  case SUMO_ATTR_ID:
173  changeAdditionalID(value);
174  break;
175  case SUMO_ATTR_ROUTE:
176  myNewRouteId = value;
177  break;
178  case SUMO_ATTR_PROB:
179  myProbability = parse<double>(value);
180  break;
181  case GNE_ATTR_GENERIC:
183  break;
184  default:
185  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
186  }
187 }
188 
189 /****************************************************************************/
GNENet::getAttributeCarriers
const AttributeCarriers & getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:1014
GNEAdditional
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
GNEAdditional::setGenericParametersStr
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
Definition: GNEAdditional.cpp:704
GNEAdditional::getAdditionalID
const std::string & getAdditionalID() const
Definition: GNEAdditional.cpp:578
GNERouteProbReroute::getParentName
std::string getParentName() const
Returns the name of the parent object.
Definition: GNERouteProbReroute.cpp:89
GNERouteProbReroute::getHierarchyName
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNERouteProbReroute.cpp:161
GNERouteProbReroute::getAttribute
std::string getAttribute(SumoXMLAttr key) const
Definition: GNERouteProbReroute.cpp:101
GNERouteProbReroute::~GNERouteProbReroute
~GNERouteProbReroute()
destructor
Definition: GNERouteProbReroute.cpp:55
GNEAttributeCarrier::isGenericParametersValid
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
Definition: GNEAttributeCarrier.cpp:1354
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:379
GNEAdditional::changeAdditionalID
void changeAdditionalID(const std::string &newID)
change ID of additional
Definition: GNEAdditional.cpp:604
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:138
GNERouteProbReroute::updateGeometry
void updateGeometry()
update pre-computed geometry information
Definition: GNERouteProbReroute.cpp:71
GNEAdditional::myViewNet
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
Definition: GNEAdditional.h:365
GNERouteProbReroute::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNERouteProbReroute.cpp:95
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:132
GNEViewNet::getNet
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
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:120
GNERouteProbReroute::getPopUpID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNERouteProbReroute.cpp:155
GNERouteProbReroute::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNERouteProbReroute.cpp:83
SUMO_ATTR_PROB
Definition: SUMOXMLDefinitions.h:627
GNERouteProbReroute::GNERouteProbReroute
GNERouteProbReroute(GNERerouterIntervalDialog *rerouterIntervalDialog)
constructor (Used in GNERerouterIntervalDialog)
Definition: GNERouteProbReroute.cpp:35
GNEViewNet.h
SUMO_ATTR_ROUTE
Definition: SUMOXMLDefinitions.h:441
GNERerouterIntervalDialog.h
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
SUMO_TAG_ROUTE_PROB_REROUTE
probability of route of a reroute
Definition: SUMOXMLDefinitions.h:197
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:105
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
GNE_ATTR_GENERIC
generic attribute
Definition: SUMOXMLDefinitions.h:986
GNEHierarchicalElementParents::getAdditionalParents
const std::vector< GNEAdditional * > & getAdditionalParents() const
return vector of additionals that have as Parent this edge (For example, Calibrators)
Definition: GNEHierarchicalElementParents.cpp:86
InvalidArgument
Definition: UtilExceptions.h:57
GNEAdditional::getGenericParametersStr
std::string getGenericParametersStr() const
return generic parameters in string format
Definition: GNEAdditional.cpp:678
GLO_REROUTER
a Rerouter
Definition: GUIGlObjectTypes.h:86
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:970
GNERouteProbReroute::getPositionInView
Position getPositionInView() const
Returns position of additional in view.
Definition: GNERouteProbReroute.cpp:77
GNEAdditional::getViewNet
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
Definition: GNEAdditional.cpp:387
GNERouteProbReroute::myProbability
double myProbability
probability with which a vehicle will use the given edge as destination
Definition: GNERouteProbReroute.h:124
SUMO_TAG_ROUTE
begin/end of the description of a route
Definition: SUMOXMLDefinitions.h:126
config.h
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1165
GNEUndoList
Definition: GNEUndoList.h:49
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:346
GNEAdditional::isValidAdditionalID
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Definition: GNEAdditional.cpp:584
GNERouteProbReroute::myNewRouteId
std::string myNewRouteId
id of new route
Definition: GNERouteProbReroute.h:121
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:373
GNERouteProbReroute.h
GNERouteProbReroute::commitGeometryMoving
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(....
Definition: GNERouteProbReroute.cpp:65
GNEChange_Attribute.h
GNENet.h
GNERerouterIntervalDialog
Dialog for edit rerouter intervals.
Definition: GNERerouterIntervalDialog.h:53
GNERouteProbReroute::moveGeometry
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNERouteProbReroute.cpp:59
GNEUndoList.h
GNE_ATTR_PARENT
parent of an additional element
Definition: SUMOXMLDefinitions.h:984