Eclipse SUMO - Simulation of Urban MObility
GNEDestProbReroute.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 
26 #include <netedit/GNEViewNet.h>
27 #include <netedit/GNENet.h>
28 #include <netedit/GNEUndoList.h>
29 
30 #include "GNEDestProbReroute.h"
31 
32 // ===========================================================================
33 // member method definitions
34 // ===========================================================================
35 
37  GNEAdditional(rerouterIntervalDialog->getEditedAdditional(), rerouterIntervalDialog->getEditedAdditional()->getViewNet(), GLO_REROUTER, SUMO_TAG_DEST_PROB_REROUTE, "", false,
38 {}, {}, {}, {rerouterIntervalDialog->getEditedAdditional()}, {}, {}, {}, {}, {}, {}),
39 myNewEdgeDestination(rerouterIntervalDialog->getEditedAdditional()->getAdditionalParents().at(0)->getEdgeChildren().at(0)) {
40  // fill dest prob reroute interval with default values
42 }
43 
44 
45 GNEDestProbReroute::GNEDestProbReroute(GNEAdditional* rerouterIntervalParent, GNEEdge* newEdgeDestination, double probability):
46  GNEAdditional(rerouterIntervalParent, rerouterIntervalParent->getViewNet(), GLO_REROUTER, SUMO_TAG_DEST_PROB_REROUTE, "", false,
47 {}, {}, {}, {rerouterIntervalParent}, {}, {}, {}, {}, {}, {}),
48 myNewEdgeDestination(newEdgeDestination),
49 myProbability(probability) {
50 }
51 
52 
54 
55 
56 void
58  // This additional cannot be moved
59 }
60 
61 
62 void
64  // This additional cannot be moved
65 }
66 
67 void
69  // Currently this additional doesn't own a Geometry
70 }
71 
72 
75  return getAdditionalParents().at(0)->getPositionInView();
76 }
77 
78 
81  return getAdditionalParents().at(0)->getCenteringBoundary();
82 }
83 
84 
85 std::string
87  return getAdditionalParents().at(0)->getID();
88 }
89 
90 
91 void
93  // Currently This additional isn't drawn
94 }
95 
96 
97 std::string
99  switch (key) {
100  case SUMO_ATTR_ID:
101  return getAdditionalID();
102  case SUMO_ATTR_EDGE:
103  return myNewEdgeDestination->getID();
104  case SUMO_ATTR_PROB:
105  return toString(myProbability);
106  case GNE_ATTR_PARENT:
107  return getAdditionalParents().at(0)->getID();
108  case GNE_ATTR_GENERIC:
109  return getGenericParametersStr();
110  default:
111  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
112  }
113 }
114 
115 
116 void
117 GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
118  if (value == getAttribute(key)) {
119  return; //avoid needless changes, later logic relies on the fact that attributes have changed
120  }
121  switch (key) {
122  case SUMO_ATTR_ID:
123  case SUMO_ATTR_EDGE:
124  case SUMO_ATTR_PROB:
125  case GNE_ATTR_GENERIC:
126  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
127  break;
128  default:
129  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
130  }
131 }
132 
133 
134 bool
135 GNEDestProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
136  switch (key) {
137  case SUMO_ATTR_ID:
138  return isValidAdditionalID(value);
139  case SUMO_ATTR_EDGE:
140  return (myViewNet->getNet()->retrieveEdge(value, false) != nullptr);
141  case SUMO_ATTR_PROB:
142  return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
143  case GNE_ATTR_GENERIC:
144  return isGenericParametersValid(value);
145  default:
146  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
147  }
148 }
149 
150 
151 std::string
153  return getTagStr();
154 }
155 
156 
157 std::string
159  return getTagStr() + ": " + myNewEdgeDestination->getID();
160 }
161 
162 // ===========================================================================
163 // private
164 // ===========================================================================
165 
166 void
167 GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
168  switch (key) {
169  case SUMO_ATTR_ID:
170  changeAdditionalID(value);
171  break;
172  case SUMO_ATTR_EDGE:
174  break;
175  case SUMO_ATTR_PROB:
176  myProbability = parse<double>(value);
177  break;
178  case GNE_ATTR_GENERIC:
180  break;
181  default:
182  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
183  }
184 }
185 
186 /****************************************************************************/
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:1020
std::string getAttribute(SumoXMLAttr key) const
Dialog for edit rerouter intervals.
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
Stores the information about how to visualize structures.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
double myProbability
probability with which a vehicle will use the given edge as destination
GNEDestProbReroute(GNERerouterIntervalDialog *rerouterIntervalDialog)
constructor (Used in GNERerouterIntervalDialog)
GNEEdge * myNewEdgeDestination
id of new edge destination
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
void setDefaultValues()
change all attributes of additional with their default values (note: this cannot be undo) ...
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
Position getPositionInView() const
Returns position of additional in view.
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
friend class GNEChange_Attribute
declare friend class
const std::vector< GNEAdditional * > & getAdditionalParents() const
return vector of additionals that have as Parent this edge (For example, Calibrators) ...
a Rerouter
probability of destiny of a reroute
~GNEDestProbReroute()
destructor
const std::string getID() const
function to support debugging
void updateGeometry()
update pre-computed geometry information
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
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:47
const std::string & getTagStr() const
get tag assigned to this object in string format
std::string getParentName() const
Returns the name of the parent object.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::string getGenericParametersStr() const
return generic parameters in string format
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
parent of an additional element