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 /****************************************************************************/
14 //
15 /****************************************************************************/
16 
17 // ===========================================================================
18 // included modules
19 // ===========================================================================
20 #include <config.h>
21 
25 #include <netedit/GNEViewNet.h>
26 #include <netedit/GNENet.h>
27 #include <netedit/GNEUndoList.h>
28 
29 #include "GNEDestProbReroute.h"
30 
31 // ===========================================================================
32 // member method definitions
33 // ===========================================================================
34 
36  GNEAdditional(rerouterIntervalDialog->getEditedAdditional(), rerouterIntervalDialog->getEditedAdditional()->getViewNet(), GLO_REROUTER, SUMO_TAG_DEST_PROB_REROUTE, "", false,
37 {}, {}, {}, {rerouterIntervalDialog->getEditedAdditional()}, {}, {}, {}, {}, {}, {}),
38 myNewEdgeDestination(rerouterIntervalDialog->getEditedAdditional()->getParentAdditionals().at(0)->getChildEdges().at(0)) {
39  // fill dest prob reroute interval with default values
40  setDefaultValues();
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 {}, {}, {}, {rerouterIntervalParent}, {}, {}, {}, {}, {}, {}),
47 myNewEdgeDestination(newEdgeDestination),
48 myProbability(probability) {
49 }
50 
51 
53 
54 
55 void
57  // This additional cannot be moved
58 }
59 
60 
61 void
63  // This additional cannot be moved
64 }
65 
66 void
68  // Currently this additional doesn't own a Geometry
69 }
70 
71 
74  return getParentAdditionals().at(0)->getPositionInView();
75 }
76 
77 
80  return getParentAdditionals().at(0)->getCenteringBoundary();
81 }
82 
83 
84 void
85 GNEDestProbReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetElement* /*originalElement*/, const GNENetElement* /*newElement*/, GNEUndoList* /*undoList*/) {
86  // geometry of this element cannot be splitted
87 }
88 
89 
90 std::string
92  return getParentAdditionals().at(0)->getID();
93 }
94 
95 
96 void
98  // Currently This additional isn't drawn
99 }
100 
101 
102 std::string
104  switch (key) {
105  case SUMO_ATTR_ID:
106  return getAdditionalID();
107  case SUMO_ATTR_EDGE:
108  return myNewEdgeDestination->getID();
109  case SUMO_ATTR_PROB:
110  return toString(myProbability);
111  case GNE_ATTR_PARENT:
112  return getParentAdditionals().at(0)->getID();
113  case GNE_ATTR_PARAMETERS:
114  return getParametersStr();
115  default:
116  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
117  }
118 }
119 
120 
121 double
123  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
124 }
125 
126 
127 void
128 GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
129  if (value == getAttribute(key)) {
130  return; //avoid needless changes, later logic relies on the fact that attributes have changed
131  }
132  switch (key) {
133  case SUMO_ATTR_ID:
134  case SUMO_ATTR_EDGE:
135  case SUMO_ATTR_PROB:
136  case GNE_ATTR_PARAMETERS:
137  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
138  break;
139  default:
140  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
141  }
142 }
143 
144 
145 bool
146 GNEDestProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
147  switch (key) {
148  case SUMO_ATTR_ID:
149  return isValidAdditionalID(value);
150  case SUMO_ATTR_EDGE:
151  return (myViewNet->getNet()->retrieveEdge(value, false) != nullptr);
152  case SUMO_ATTR_PROB:
153  return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
154  case GNE_ATTR_PARAMETERS:
155  return Parameterised::areParametersValid(value);
156  default:
157  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
158  }
159 }
160 
161 
162 bool
164  return true;
165 }
166 
167 
168 std::string
170  return getTagStr();
171 }
172 
173 
174 std::string
176  return getTagStr() + ": " + myNewEdgeDestination->getID();
177 }
178 
179 // ===========================================================================
180 // private
181 // ===========================================================================
182 
183 void
184 GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
185  switch (key) {
186  case SUMO_ATTR_ID:
187  changeAdditionalID(value);
188  break;
189  case SUMO_ATTR_EDGE:
191  break;
192  case SUMO_ATTR_PROB:
193  myProbability = parse<double>(value);
194  break;
195  case GNE_ATTR_PARAMETERS:
196  setParametersStr(value);
197  break;
198  default:
199  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
200  }
201 }
202 
203 /****************************************************************************/
GNEDestProbReroute::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEDestProbReroute.cpp:79
GNEDestProbReroute::myProbability
double myProbability
probability with which a vehicle will use the given edge as destination
Definition: GNEDestProbReroute.h:137
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
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1289
GNEDestProbReroute::setAttribute
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
Definition: GNEDestProbReroute.cpp:128
GNEDestProbReroute::isAttributeEnabled
bool isAttributeEnabled(SumoXMLAttr key) const
Definition: GNEDestProbReroute.cpp:163
GNEDestProbReroute::moveGeometry
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEDestProbReroute.cpp:56
SUMO_ATTR_EDGE
Definition: SUMOXMLDefinitions.h:423
GNEDestProbReroute::splitEdgeGeometry
void splitEdgeGeometry(const double splitPosition, const GNENetElement *originalElement, const GNENetElement *newElement, GNEUndoList *undoList)
split geometry
Definition: GNEDestProbReroute.cpp:85
GNEDestProbReroute::getAttribute
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEDestProbReroute.cpp:103
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
GNEAdditional::changeAdditionalID
void changeAdditionalID(const std::string &newID)
change ID of additional
Definition: GNEAdditional.cpp:502
GNEAdditional::myViewNet
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
Definition: GNEAdditional.h:335
GNEEdge
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:51
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
SUMO_TAG_DEST_PROB_REROUTE
probability of destiny of a reroute
Definition: SUMOXMLDefinitions.h:190
SUMO_ATTR_PROB
Definition: SUMOXMLDefinitions.h:629
GNEDestProbReroute::commitGeometryMoving
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(....
Definition: GNEDestProbReroute.cpp:62
GNEViewNet.h
GNERerouterIntervalDialog.h
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:41
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
GNEEdge.h
GNENetElement
Definition: GNENetElement.h:43
GNEDestProbReroute::getPositionInView
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEDestProbReroute.cpp:73
GNEDestProbReroute::getParentName
std::string getParentName() const
Returns the name of the parent object.
Definition: GNEDestProbReroute.cpp:91
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
GNEDestProbReroute::getHierarchyName
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEDestProbReroute.cpp:175
GNEDestProbReroute::getAttributeDouble
double getAttributeDouble(SumoXMLAttr key) const
Definition: GNEDestProbReroute.cpp:122
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
a Rerouter
Definition: GUIGlObjectTypes.h:85
GNEDestProbReroute.h
GNEDestProbReroute::getPopUpID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEDestProbReroute.cpp:169
GNEDestProbReroute::~GNEDestProbReroute
~GNEDestProbReroute()
destructor
Definition: GNEDestProbReroute.cpp:52
GNENet::retrieveEdge
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:1069
config.h
GNEDestProbReroute::updateGeometry
void updateGeometry()
update pre-computed geometry information
Definition: GNEDestProbReroute.cpp:67
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
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:372
GNEChange_Attribute.h
GNENet.h
GNERerouterIntervalDialog
Dialog for edit rerouter intervals.
Definition: GNERerouterIntervalDialog.h:49
GNEDestProbReroute::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEDestProbReroute.cpp:97
GNEUndoList.h
GNE_ATTR_PARENT
parent of an additional element
Definition: SUMOXMLDefinitions.h:987
GNEDestProbReroute::GNEDestProbReroute
GNEDestProbReroute(GNERerouterIntervalDialog *rerouterIntervalDialog)
constructor (Used in GNERerouterIntervalDialog)
Definition: GNEDestProbReroute.cpp:35
GNEDestProbReroute::myNewEdgeDestination
GNEEdge * myNewEdgeDestination
id of new edge destination
Definition: GNEDestProbReroute.h:134
GNEDestProbReroute::isValid
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEDestProbReroute.cpp:146