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-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 
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  myNewEdgeDestination(rerouterIntervalDialog->getEditedAdditional()->getFirstAdditionalParent()->getEdgeChilds().at(0)) {
39  // fill dest prob reroute interval with default values
41 }
42 
43 
44 GNEDestProbReroute::GNEDestProbReroute(GNEAdditional* rerouterIntervalParent, GNEEdge* newEdgeDestination, double probability):
45  GNEAdditional(rerouterIntervalParent, rerouterIntervalParent->getViewNet(), GLO_REROUTER, SUMO_TAG_DEST_PROB_REROUTE, "", false),
46  myNewEdgeDestination(newEdgeDestination),
47  myProbability(probability) {
48 }
49 
50 
52 
53 
54 void
56  // This additional cannot be moved
57 }
58 
59 
60 void
62  // This additional cannot be moved
63 }
64 
65 void
66 GNEDestProbReroute::updateGeometry(bool /*updateGrid*/) {
67  // Currently this additional doesn't own a Geometry
68 }
69 
70 
74 }
75 
76 
77 std::string
80 }
81 
82 
83 void
85  // Currently This additional isn't drawn
86 }
87 
88 
89 std::string
91  switch (key) {
92  case SUMO_ATTR_ID:
93  return getAdditionalID();
94  case SUMO_ATTR_EDGE:
95  return myNewEdgeDestination->getID();
96  case SUMO_ATTR_PROB:
97  return toString(myProbability);
98  case GNE_ATTR_PARENT:
100  case GNE_ATTR_GENERIC:
101  return getGenericParametersStr();
102  default:
103  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
104  }
105 }
106 
107 
108 void
109 GNEDestProbReroute::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_EDGE:
116  case SUMO_ATTR_PROB:
117  case GNE_ATTR_GENERIC:
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 GNEDestProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
128  switch (key) {
129  case SUMO_ATTR_ID:
130  return isValidAdditionalID(value);
131  case SUMO_ATTR_EDGE:
132  return (myViewNet->getNet()->retrieveEdge(value, false) != nullptr);
133  case SUMO_ATTR_PROB:
134  return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
135  case GNE_ATTR_GENERIC:
136  return isGenericParametersValid(value);
137  default:
138  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
139  }
140 }
141 
142 
143 std::string
145  return getTagStr();
146 }
147 
148 
149 std::string
151  return getTagStr() + ": " + myNewEdgeDestination->getID();
152 }
153 
154 // ===========================================================================
155 // private
156 // ===========================================================================
157 
158 void
159 GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
160  switch (key) {
161  case SUMO_ATTR_ID:
162  changeAdditionalID(value);
163  break;
164  case SUMO_ATTR_EDGE:
166  break;
167  case SUMO_ATTR_PROB:
168  myProbability = parse<double>(value);
169  break;
170  case GNE_ATTR_GENERIC:
172  break;
173  default:
174  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
175  }
176 }
177 
178 /****************************************************************************/
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:900
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
returns Additional ID
Stores the information about how to visualize structures.
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(...)
void updateGeometry(bool updateGrid)
update pre-computed geometry information
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
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:49
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
a Rerouter
probability of destiny of a reroute
~GNEDestProbReroute()
destructor
const std::string getID() const
function to support debugging
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:48
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
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
parent of an additional element
GNEAdditional * myFirstAdditionalParent
pointer to first Additional parent
virtual Position getPositionInView() const =0
Returns position of additional in view.