Eclipse SUMO - Simulation of Urban MObility
GNEClosingReroute.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 
22 #include "GNEClosingReroute.h"
24 
25 #include <netedit/GNEUndoList.h>
26 #include <netedit/GNENet.h>
27 
28 
29 // ===========================================================================
30 // member method definitions
31 // ===========================================================================
32 
33 GNEClosingReroute::GNEClosingReroute(GNEAdditional* rerouterIntervalParent, GNEEdge* closedEdge, SVCPermissions permissions) :
34  GNEAdditional(rerouterIntervalParent->getNet(), GLO_CALIBRATOR, SUMO_TAG_CLOSING_REROUTE, "", false,
35 {}, {}, {}, {rerouterIntervalParent}, {}, {}, {}, {}),
36 myClosedEdge(closedEdge),
37 myPermissions(permissions) {
38  // update centering boundary without updating grid
39  updateCenteringBoundary(false);
40 }
41 
42 
44 
45 
47 GNEClosingReroute::getMoveOperation(const double /* shapeOffset */) {
48  // GNEClosingReroutes cannot be moved
49  return nullptr;
50 }
51 
52 
53 void
55  // use geometry of rerouter parent
57 }
58 
59 
60 void
61 GNEClosingReroute::updateCenteringBoundary(const bool /*updateGrid*/) {
62  // use boundary of parent element
63  myBoundary = getParentAdditionals().front()->getCenteringBoundary();
64 }
65 
66 
67 void
68 GNEClosingReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
69  // geometry of this element cannot be splitted
70 }
71 
72 
73 std::string
75  return getParentAdditionals().at(0)->getID();
76 }
77 
78 
79 void
81  // Currently this additional isn't drawn
82 }
83 
84 
85 std::string
87  switch (key) {
88  case SUMO_ATTR_ID:
89  return getID();
90  case SUMO_ATTR_EDGE:
91  return myClosedEdge->getID();
92  case SUMO_ATTR_ALLOW:
94  case SUMO_ATTR_DISALLOW:
96  case GNE_ATTR_PARENT:
97  return getParentAdditionals().at(0)->getID();
99  return getParametersStr();
100  default:
101  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
102  }
103 }
104 
105 
106 double
108  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
109 }
110 
111 
112 void
113 GNEClosingReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
114  if (value == getAttribute(key)) {
115  return; //avoid needless changes, later logic relies on the fact that attributes have changed
116  }
117  switch (key) {
118  case SUMO_ATTR_ID:
119  case SUMO_ATTR_EDGE:
120  case SUMO_ATTR_ALLOW:
121  case SUMO_ATTR_DISALLOW:
122  case GNE_ATTR_PARAMETERS:
123  undoList->p_add(new GNEChange_Attribute(this, key, value));
124  break;
125  default:
126  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
127  }
128 }
129 
130 
131 bool
132 GNEClosingReroute::isValid(SumoXMLAttr key, const std::string& value) {
133  switch (key) {
134  case SUMO_ATTR_ID:
135  return isValidAdditionalID(value);
136  case SUMO_ATTR_EDGE:
137  return (myNet->retrieveEdge(value, false) != nullptr);
138  case SUMO_ATTR_ALLOW:
139  return canParseVehicleClasses(value);
140  case SUMO_ATTR_DISALLOW:
141  return canParseVehicleClasses(value);
142  case GNE_ATTR_PARAMETERS:
143  return Parameterised::areParametersValid(value);
144  default:
145  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
146  }
147 }
148 
149 
150 bool
152  return true;
153 }
154 
155 
156 std::string
158  return getTagStr();
159 }
160 
161 
162 std::string
164  return getTagStr() + ": " + myClosedEdge->getID();
165 }
166 
167 // ===========================================================================
168 // private
169 // ===========================================================================
170 
171 void
172 GNEClosingReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
173  switch (key) {
174  case SUMO_ATTR_ID:
175  myNet->getAttributeCarriers()->updateID(this, value);
176  break;
177  case SUMO_ATTR_EDGE:
178  myClosedEdge = myNet->retrieveEdge(value);
179  break;
180  case SUMO_ATTR_ALLOW:
182  break;
183  case SUMO_ATTR_DISALLOW:
185  break;
186  case GNE_ATTR_PARAMETERS:
187  setParametersStr(value);
188  break;
189  default:
190  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
191  }
192 }
193 
194 
195 void
197  // nothing to do
198 }
199 
200 
201 void
202 GNEClosingReroute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
203  // nothing to do
204 }
205 
206 
207 /****************************************************************************/
@ GLO_CALIBRATOR
a Calibrator
SVCPermissions invertPermissions(SVCPermissions permissions)
negate the given permissions and ensure that only relevant bits are set
const std::string & getVehicleClassNames(SVCPermissions permissions, bool expand)
Returns the ids of the given classes, divided using a ' '.
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
bool canParseVehicleClasses(const std::string &classes)
Checks whether the given string contains only known vehicle classes.
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ SUMO_TAG_CLOSING_REROUTE
reroute of type closing
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_DISALLOW
@ SUMO_ATTR_ALLOW
@ SUMO_ATTR_EDGE
@ GNE_ATTR_PARENT
parent of an additional element
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_ID
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
GNEGeometry::Geometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
Boundary myBoundary
Additional Boundary.
const GNEGeometry::Geometry & getAdditionalGeometry() const
obtain additional geometry
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
SVCPermissions myPermissions
void updateGeometry()
update pre-computed geometry information
GNEClosingReroute(GNEAdditional *rerouterIntervalParent, GNEEdge *closedEdge, SVCPermissions permissions)
parameter constructor
GNEEdge * myClosedEdge
closed edge
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
std::string getParentName() const
Returns the name of the parent object.
double getAttributeDouble(SumoXMLAttr key) const
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
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 splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
std::string getAttribute(SumoXMLAttr key) const
~GNEClosingReroute()
destructor
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:49
void updateGeometry(const PositionVector &shape, double startPos=-1, double endPos=-1, const Position &extraFirstPosition=Position::INVALID, const Position &extraLastPosition=Position::INVALID)
update geometry shape
Definition: GNEGeometry.cpp:81
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
move operation
move result
void updateID(GNEAttributeCarrier *AC, const std::string newID)
update ID
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true) const
get edge by id
Definition: GNENet.cpp:1141
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
const std::string & getID() const
get ID
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".