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-2018 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 
23 #include <utils/common/ToString.h>
27 #include <netedit/GNEUndoList.h>
28 #include <netedit/GNEViewNet.h>
29 #include <netedit/GNENet.h>
30 
31 #include "GNERouteProbReroute.h"
32 #include "GNERerouter.h"
33 
34 // ===========================================================================
35 // member method definitions
36 // ===========================================================================
37 
39  GNEAdditional(rerouterIntervalDialog->getEditedAdditional(), rerouterIntervalDialog->getEditedAdditional()->getViewNet(), GLO_REROUTER, SUMO_TAG_ROUTE_PROB_REROUTE, "", false) {
40  // if exist a reroute, set newRoute ID
41  if (rerouterIntervalDialog->getEditedAdditional()->getViewNet()->getNet()->getAdditionalByType(SUMO_TAG_ROUTE).size() > 0) {
42  myNewRouteId = rerouterIntervalDialog->getEditedAdditional()->getViewNet()->getNet()->getAdditionalByType(SUMO_TAG_ROUTE).begin()->first;
43  }
44  // fill route prob reroute interval with default values
46 }
47 
48 
49 GNERouteProbReroute::GNERouteProbReroute(GNEAdditional* rerouterIntervalParent, const std::string& newRouteId, double probability) :
50  GNEAdditional(rerouterIntervalParent, rerouterIntervalParent->getViewNet(), GLO_REROUTER, SUMO_TAG_ROUTE_PROB_REROUTE, "", false),
51  myNewRouteId(newRouteId),
52  myProbability(probability) {
53 }
54 
55 
57 
58 
59 void
61  // This additional cannot be moved
62 }
63 
64 
65 void
67  // This additional cannot be moved
68 }
69 
70 
71 void
73  // Currently this additional doesn't own a Geometry
74 }
75 
76 
80 }
81 
82 
83 std::string
86 }
87 
88 
89 void
91  // Currently This additional isn't drawn
92 }
93 
94 
95 std::string
97  switch (key) {
98  case SUMO_ATTR_ID:
99  return getAdditionalID();
100  case SUMO_ATTR_ROUTE:
101  return myNewRouteId;
102  case SUMO_ATTR_PROB:
103  return toString(myProbability);
104  case GNE_ATTR_PARENT:
105  return myFirstAdditionalParent->getID();
106  case GNE_ATTR_GENERIC:
107  return getGenericParametersStr();
108  default:
109  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
110  }
111 }
112 
113 
114 void
115 GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
116  if (value == getAttribute(key)) {
117  return; //avoid needless changes, later logic relies on the fact that attributes have changed
118  }
119  switch (key) {
120  case SUMO_ATTR_ID:
121  case SUMO_ATTR_ROUTE:
122  case SUMO_ATTR_PROB:
123  case GNE_ATTR_GENERIC:
124  undoList->p_add(new GNEChange_Attribute(this, key, value));
125  break;
126  default:
127  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
128  }
129 }
130 
131 
132 bool
133 GNERouteProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
134  switch (key) {
135  case SUMO_ATTR_ID:
136  return isValidAdditionalID(value);
137  case SUMO_ATTR_ROUTE:
139  case SUMO_ATTR_PROB:
140  return canParse<double>(value);
141  case GNE_ATTR_GENERIC:
142  return isGenericParametersValid(value);
143  default:
144  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
145  }
146 }
147 
148 
149 std::string
151  return toString(getTag());
152 }
153 
154 
155 std::string
157  return toString(getTag()) + ": " + 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  changeAdditionalID(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_GENERIC:
178  break;
179  default:
180  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
181  }
182 }
183 
184 /****************************************************************************/
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Position getPositionInView() const
Returns position of additional in view.
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Dialog for edit rerouter intervals.
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
Stores the information about how to visualize structures.
std::string myNewRouteId
id of new route
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
void setDefaultValues()
change all attributes of additional with their default values (note: this cannot be undo) ...
double myProbability
probability with which a vehicle will use the given edge as destination
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
begin/end of the description of a route
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
std::string getAttribute(SumoXMLAttr key) const
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
~GNERouteProbReroute()
destructor
friend class GNEChange_Attribute
declare friend class
std::string getParentName() const
Returns the name of the parent object.
probability of route of a reroute
a Rerouter
const std::string getID() const
function to support debugging
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:53
GNERouteProbReroute(GNERerouterIntervalDialog *rerouterIntervalDialog)
constructor (Used in GNERerouterIntervalDialog)
std::string getGenericParametersStr() const
return generic parameters in string format
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
GNENet * getNet() const
get the net object
GNEAdditional * getEditedAdditional() const
get edited Additional
const std::map< std::string, GNEAdditional * > & getAdditionalByType(SumoXMLTag type) const
get map with IDs and pointers to additionals
Definition: GNENet.cpp:1822
void updateGeometry(bool updateGrid)
update pre-computed geometry information
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
parent of an additional element
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
static bool isValidVehicleID(const std::string &value)
whether the given string is a valid id for a vehicle or flow
GNEAdditional * myFirstAdditionalParent
pointer to first Addititional parent
SumoXMLTag getTag() const
get XML Tag assigned to this object
virtual Position getPositionInView() const =0
Returns position of additional in view.