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
41  setDefaultValues();
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 /****************************************************************************/
GNEDestProbReroute::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEDestProbReroute.cpp:80
GNEDestProbReroute::myProbability
double myProbability
probability with which a vehicle will use the given edge as destination
Definition: GNEDestProbReroute.h:124
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
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1187
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:117
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
GNEDestProbReroute::moveGeometry
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEDestProbReroute.cpp:57
SUMO_ATTR_EDGE
Definition: SUMOXMLDefinitions.h:424
GNEDestProbReroute::getAttribute
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEDestProbReroute.cpp:98
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:379
GNEAdditional::changeAdditionalID
void changeAdditionalID(const std::string &newID)
change ID of additional
Definition: GNEAdditional.cpp:604
GNEAdditional::myViewNet
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
Definition: GNEAdditional.h:365
GNEEdge
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
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
SUMO_TAG_DEST_PROB_REROUTE
probability of destiny of a reroute
Definition: SUMOXMLDefinitions.h:191
SUMO_ATTR_PROB
Definition: SUMOXMLDefinitions.h:627
GNEDestProbReroute::commitGeometryMoving
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(....
Definition: GNEDestProbReroute.cpp:63
GNEViewNet.h
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
GNEEdge.h
GNEDestProbReroute::getPositionInView
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEDestProbReroute.cpp:74
GNEDestProbReroute::getParentName
std::string getParentName() const
Returns the name of the parent object.
Definition: GNEDestProbReroute.cpp:86
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
GNE_ATTR_GENERIC
generic attribute
Definition: SUMOXMLDefinitions.h:986
GNEDestProbReroute::getHierarchyName
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEDestProbReroute.cpp:158
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
GNEDestProbReroute.h
GNEDestProbReroute::getPopUpID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEDestProbReroute.cpp:152
GNEDestProbReroute::~GNEDestProbReroute
~GNEDestProbReroute()
destructor
Definition: GNEDestProbReroute.cpp:53
GNENet::retrieveEdge
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:1020
config.h
GNEDestProbReroute::updateGeometry
void updateGeometry()
update pre-computed geometry information
Definition: GNEDestProbReroute.cpp:68
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
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:373
GNEChange_Attribute.h
GNENet.h
GNERerouterIntervalDialog
Dialog for edit rerouter intervals.
Definition: GNERerouterIntervalDialog.h:53
GNEDestProbReroute::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEDestProbReroute.cpp:92
GNEUndoList.h
GNE_ATTR_PARENT
parent of an additional element
Definition: SUMOXMLDefinitions.h:984
GNEDestProbReroute::GNEDestProbReroute
GNEDestProbReroute(GNERerouterIntervalDialog *rerouterIntervalDialog)
constructor (Used in GNERerouterIntervalDialog)
Definition: GNEDestProbReroute.cpp:36
GNEDestProbReroute::myNewEdgeDestination
GNEEdge * myNewEdgeDestination
id of new edge destination
Definition: GNEDestProbReroute.h:121
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:135