Eclipse SUMO - Simulation of Urban MObility
GNEParkingAreaReroute.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 
24 
25 #include "GNEParkingAreaReroute.h"
26 #include <netedit/GNEUndoList.h>
27 #include <netedit/GNEViewNet.h>
28 #include <netedit/GNENet.h>
29 
30 // ===========================================================================
31 // member method definitions
32 // ===========================================================================
33 
35  GNEAdditional(rerouterIntervalDialog->getEditedAdditional(), rerouterIntervalDialog->getEditedAdditional()->getViewNet(), GLO_REROUTER, SUMO_TAG_PARKING_ZONE_REROUTE, "", false,
36 {}, {}, {}, {rerouterIntervalDialog->getEditedAdditional(), rerouterIntervalDialog->getEditedAdditional()->getViewNet()->getNet()->getAttributeCarriers().additionals.at(SUMO_TAG_PARKING_AREA).begin()->second}, {}, {}, {}, {}, {}, {}) {
37  // fill route type with default values
38  setDefaultValues();
39 }
40 
41 
42 GNEParkingAreaReroute::GNEParkingAreaReroute(GNEAdditional* rerouterIntervalParent, GNEAdditional* newParkingArea, double probability, bool visible):
43  GNEAdditional(rerouterIntervalParent, rerouterIntervalParent->getViewNet(), GLO_REROUTER, SUMO_TAG_PARKING_ZONE_REROUTE, "", false,
44 {}, {}, {}, {rerouterIntervalParent, newParkingArea}, {}, {}, {}, {}, {}, {}),
45 myProbability(probability),
46 myVisible(visible) {
47 }
48 
49 
51 
52 
53 void
55  // This additional cannot be moved
56 }
57 
58 
59 void
61  // This additional cannot be moved
62 }
63 
64 
65 void
67  // Currently this additional doesn't own a Geometry
68 }
69 
70 
73  return getParentAdditionals().at(0)->getPositionInView();
74 }
75 
76 
79  return getParentAdditionals().at(0)->getCenteringBoundary();
80 }
81 
82 
83 void
84 GNEParkingAreaReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetElement* /*originalElement*/, const GNENetElement* /*newElement*/, GNEUndoList* /*undoList*/) {
85  // geometry of this element cannot be splitted
86 }
87 
88 
89 std::string
91  return getParentAdditionals().at(0)->getID();
92 }
93 
94 
95 void
97  // Currently this additional isn't drawn
98 }
99 
100 
101 std::string
103  switch (key) {
104  case SUMO_ATTR_ID:
105  return getAdditionalID();
106  case SUMO_ATTR_PARKING:
107  return getParentAdditionals().at(1)->getID();
108  case SUMO_ATTR_PROB:
109  return toString(myProbability);
110  case SUMO_ATTR_VISIBLE:
111  return toString(myVisible);
112  case GNE_ATTR_PARENT:
113  return toString(getParentAdditionals().at(0)->getID());
114  case GNE_ATTR_PARAMETERS:
115  return getParametersStr();
116  default:
117  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
118  }
119 }
120 
121 
122 double
124  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
125 }
126 
127 
128 void
129 GNEParkingAreaReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
130  if (value == getAttribute(key)) {
131  return; //avoid needless changes, later logic relies on the fact that attributes have changed
132  }
133  switch (key) {
134  case SUMO_ATTR_ID:
135  case SUMO_ATTR_PARKING:
136  case SUMO_ATTR_PROB:
137  case SUMO_ATTR_VISIBLE:
138  case GNE_ATTR_PARAMETERS:
139  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
140  break;
141  default:
142  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
143  }
144 }
145 
146 
147 bool
148 GNEParkingAreaReroute::isValid(SumoXMLAttr key, const std::string& value) {
149  switch (key) {
150  case SUMO_ATTR_ID:
151  return isValidAdditionalID(value);
152  case SUMO_ATTR_PARKING:
153  return isValidAdditionalID(value) && (myViewNet->getNet()->retrieveAdditional(SUMO_TAG_PARKING_AREA, value, false) != nullptr);
154  case SUMO_ATTR_PROB:
155  return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
156  case SUMO_ATTR_VISIBLE:
157  return canParse<bool>(value);
158  case GNE_ATTR_PARAMETERS:
159  return Parameterised::areParametersValid(value);
160  default:
161  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
162  }
163 }
164 
165 
166 bool
168  return true;
169 }
170 
171 
172 std::string
174  return getTagStr();
175 }
176 
177 
178 std::string
180  return getTagStr() + ": " + getParentAdditionals().at(1)->getID();
181 }
182 
183 // ===========================================================================
184 // private
185 // ===========================================================================
186 
187 void
188 GNEParkingAreaReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
189  switch (key) {
190  case SUMO_ATTR_ID:
191  changeAdditionalID(value);
192  break;
193  case SUMO_ATTR_PARKING:
194  replaceParentAdditional(this, value, 1);
195  break;
196  case SUMO_ATTR_PROB:
197  myProbability = parse<double>(value);
198  break;
199  case SUMO_ATTR_VISIBLE:
200  myVisible = parse<bool>(value);
201  break;
202  case GNE_ATTR_PARAMETERS:
203  setParametersStr(value);
204  break;
205  default:
206  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
207  }
208 }
209 
210 /****************************************************************************/
GNENet::retrieveAdditional
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:2183
GNEParkingAreaReroute::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEParkingAreaReroute.cpp:78
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
GNEParkingAreaReroute.h
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
GNEParkingAreaReroute::myProbability
double myProbability
probability with which a vehicle will use the given edge as destination
Definition: GNEParkingAreaReroute.h:135
SUMO_ATTR_ID
@ SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
GNEAdditional::changeAdditionalID
void changeAdditionalID(const std::string &newID)
change ID of additional
Definition: GNEAdditional.cpp:502
GNEParkingAreaReroute::getHierarchyName
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEParkingAreaReroute.cpp:179
GNEParkingAreaReroute::splitEdgeGeometry
void splitEdgeGeometry(const double splitPosition, const GNENetElement *originalElement, const GNENetElement *newElement, GNEUndoList *undoList)
split geometry
Definition: GNEParkingAreaReroute.cpp:84
GNEAdditional::myViewNet
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
Definition: GNEAdditional.h:335
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
SUMO_TAG_PARKING_ZONE_REROUTE
@ SUMO_TAG_PARKING_ZONE_REROUTE
entry for an alternative parking zone
Definition: SUMOXMLDefinitions.h:198
GNEHierarchicalParentElements::getParentAdditionals
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
Definition: GNEHierarchicalParentElements.cpp:85
SUMO_ATTR_PROB
@ SUMO_ATTR_PROB
Definition: SUMOXMLDefinitions.h:629
GNEParkingAreaReroute::isAttributeEnabled
bool isAttributeEnabled(SumoXMLAttr key) const
Definition: GNEParkingAreaReroute.cpp:167
GNEParkingAreaReroute::getPopUpID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEParkingAreaReroute.cpp:173
GNEParkingAreaReroute::isValid
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEParkingAreaReroute.cpp:148
GNEViewNet.h
GNERerouterIntervalDialog.h
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:41
SUMO_TAG_PARKING_AREA
@ SUMO_TAG_PARKING_AREA
A parking area.
Definition: SUMOXMLDefinitions.h:107
GNE_ATTR_PARAMETERS
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
Definition: SUMOXMLDefinitions.h:989
GNEParkingAreaReroute::GNEParkingAreaReroute
GNEParkingAreaReroute(GNERerouterIntervalDialog *rerouterIntervalDialog)
constructor (Used in GNERerouterIntervalDialog)
Definition: GNEParkingAreaReroute.cpp:34
GNEParkingAreaReroute::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEParkingAreaReroute.cpp:96
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
GNEParkingAreaReroute::getAttributeDouble
double getAttributeDouble(SumoXMLAttr key) const
Definition: GNEParkingAreaReroute.cpp:123
GNENetElement
Definition: GNENetElement.h:43
GNEParkingAreaReroute::moveGeometry
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEParkingAreaReroute.cpp:54
GNEHierarchicalParentElements::replaceParentAdditional
void replaceParentAdditional(GNEShape *shapeTobeChanged, const std::string &newParentAdditionalID, int additionalParentIndex)
replace the parent additional of a shape
Definition: GNEHierarchicalParentElements.cpp:489
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
GNEParkingAreaReroute::getPositionInView
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEParkingAreaReroute.cpp:72
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
@ GLO_REROUTER
a Rerouter
Definition: GUIGlObjectTypes.h:85
SUMO_ATTR_VISIBLE
@ SUMO_ATTR_VISIBLE
Definition: SUMOXMLDefinitions.h:896
GNEParkingAreaReroute::setAttribute
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
Definition: GNEParkingAreaReroute.cpp:129
GNEParkingAreaReroute::commitGeometryMoving
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(....
Definition: GNEParkingAreaReroute.cpp:60
GNEParkingAreaReroute::getAttribute
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEParkingAreaReroute.cpp:102
SUMO_ATTR_PARKING
@ SUMO_ATTR_PARKING
Definition: SUMOXMLDefinitions.h:801
config.h
GNEParkingAreaReroute::~GNEParkingAreaReroute
~GNEParkingAreaReroute()
destructor
Definition: GNEParkingAreaReroute.cpp:50
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
GNEParkingAreaReroute::updateGeometry
void updateGeometry()
update pre-computed geometry information
Definition: GNEParkingAreaReroute.cpp:66
GNEParkingAreaReroute::myVisible
bool myVisible
enable or disable visibility of Parking Area Reroute
Definition: GNEParkingAreaReroute.h:138
GNEAdditional::isValidAdditionalID
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Definition: GNEAdditional.cpp:482
GNEParkingAreaReroute::getParentName
std::string getParentName() const
Returns the name of the parent object.
Definition: GNEParkingAreaReroute.cpp:90
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
GNEUndoList.h
GNE_ATTR_PARENT
@ GNE_ATTR_PARENT
parent of an additional element
Definition: SUMOXMLDefinitions.h:987