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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 //
19 /****************************************************************************/
20 #include <config.h>
21 
23 
24 #include "GNEParkingAreaReroute.h"
25 #include <netedit/GNEUndoList.h>
26 #include <netedit/GNENet.h>
27 
28 // ===========================================================================
29 // member method definitions
30 // ===========================================================================
31 
32 GNEParkingAreaReroute::GNEParkingAreaReroute(GNEAdditional* rerouterIntervalParent, GNEAdditional* newParkingArea, double probability, bool visible):
33  GNEAdditional(rerouterIntervalParent->getNet(), GLO_REROUTER, SUMO_TAG_PARKING_ZONE_REROUTE, "", false,
34 {}, {}, {}, {rerouterIntervalParent, newParkingArea}, {}, {}, {}, {}),
35 myProbability(probability),
36 myVisible(visible) {
37  // update centering boundary without updating grid
38  updateCenteringBoundary(false);
39 }
40 
41 
43 
44 
46 GNEParkingAreaReroute::getMoveOperation(const double /*shapeOffset*/) {
47  // GNEParkingAreaReroutes cannot be moved
48  return nullptr;
49 }
50 
51 
52 void
54  // This additional doesn't own a geometry
55 }
56 
57 
58 void
60  // use boundary of parent element
61  myBoundary = getParentAdditionals().front()->getCenteringBoundary();
62 }
63 
64 
65 void
66 GNEParkingAreaReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
67  // geometry of this element cannot be splitted
68 }
69 
70 
71 std::string
73  return getParentAdditionals().at(0)->getID();
74 }
75 
76 
77 void
79  // Currently this additional isn't drawn
80 }
81 
82 
83 std::string
85  switch (key) {
86  case SUMO_ATTR_ID:
87  return getID();
88  case SUMO_ATTR_PARKING:
89  return getParentAdditionals().at(1)->getID();
90  case SUMO_ATTR_PROB:
91  return toString(myProbability);
92  case SUMO_ATTR_VISIBLE:
93  return toString(myVisible);
94  case GNE_ATTR_PARENT:
95  return toString(getParentAdditionals().at(0)->getID());
97  return getParametersStr();
98  default:
99  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
100  }
101 }
102 
103 
104 double
106  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
107 }
108 
109 
110 void
111 GNEParkingAreaReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
112  if (value == getAttribute(key)) {
113  return; //avoid needless changes, later logic relies on the fact that attributes have changed
114  }
115  switch (key) {
116  case SUMO_ATTR_ID:
117  case SUMO_ATTR_PARKING:
118  case SUMO_ATTR_PROB:
119  case SUMO_ATTR_VISIBLE:
120  case GNE_ATTR_PARAMETERS:
121  undoList->p_add(new GNEChange_Attribute(this, key, value));
122  break;
123  default:
124  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
125  }
126 }
127 
128 
129 bool
130 GNEParkingAreaReroute::isValid(SumoXMLAttr key, const std::string& value) {
131  switch (key) {
132  case SUMO_ATTR_ID:
133  return isValidAdditionalID(value);
134  case SUMO_ATTR_PARKING:
135  return isValidAdditionalID(value) && (myNet->retrieveAdditional(SUMO_TAG_PARKING_AREA, value, false) != nullptr);
136  case SUMO_ATTR_PROB:
137  return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
138  case SUMO_ATTR_VISIBLE:
139  return canParse<bool>(value);
140  case GNE_ATTR_PARAMETERS:
141  return Parameterised::areParametersValid(value);
142  default:
143  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
144  }
145 }
146 
147 
148 bool
150  return true;
151 }
152 
153 
154 std::string
156  return getTagStr();
157 }
158 
159 
160 std::string
162  return getTagStr() + ": " + getParentAdditionals().at(1)->getID();
163 }
164 
165 // ===========================================================================
166 // private
167 // ===========================================================================
168 
169 void
170 GNEParkingAreaReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
171  switch (key) {
172  case SUMO_ATTR_ID:
173  myNet->getAttributeCarriers()->updateID(this, value);
174  break;
175  case SUMO_ATTR_PARKING:
177  break;
178  case SUMO_ATTR_PROB:
179  myProbability = parse<double>(value);
180  break;
181  case SUMO_ATTR_VISIBLE:
182  myVisible = parse<bool>(value);
183  break;
184  case GNE_ATTR_PARAMETERS:
185  setParametersStr(value);
186  break;
187  default:
188  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
189  }
190 }
191 
192 
193 void
195  // nothing to do
196 }
197 
198 
199 void
200 GNEParkingAreaReroute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
201  // nothing to do
202 }
203 
204 
205 /****************************************************************************/
@ GLO_REROUTER
a Rerouter
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_TAG_PARKING_ZONE_REROUTE
entry for an alternative parking zone
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_PARKING
@ GNE_ATTR_PARENT
parent of an additional element
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_PROB
@ SUMO_ATTR_ID
@ SUMO_ATTR_VISIBLE
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const std::string & getID() const
get ID
void replaceAdditionalParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace additional parent
Boundary myBoundary
Additional Boundary.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
move operation
move result
void updateID(GNEAttributeCarrier *AC, const std::string newID)
update ID
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:2316
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
double myProbability
probability with which a vehicle will use the given edge as destination
GNEParkingAreaReroute(GNEAdditional *rerouterIntervalParent, GNEAdditional *newParkingArea, double probability, bool visible)
constructor
bool myVisible
enable or disable visibility of Parking Area Reroute
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
double getAttributeDouble(SumoXMLAttr key) const
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void updateGeometry()
update pre-computed geometry information
std::string getParentName() const
Returns the name of the parent object.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::string getAttribute(SumoXMLAttr key) const
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
bool isAttributeEnabled(SumoXMLAttr key) const
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
Stores the information about how to visualize structures.
static bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".