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-2022 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 
35 {}, {}, {}, {}, {}, {}, {}, {},
36 std::map<std::string, std::string>()),
37  myClosedEdge(nullptr),
38 myPermissions(0) {
39  // reset default values
40  resetDefaultValues();
41 }
42 
43 
44 GNEClosingReroute::GNEClosingReroute(GNEAdditional* rerouterIntervalParent, GNEEdge* closedEdge, SVCPermissions permissions) :
45  GNEAdditional(rerouterIntervalParent->getNet(), GLO_REROUTER_CLOSINGREROUTE, SUMO_TAG_CLOSING_REROUTE, "",
46 {}, {}, {}, {rerouterIntervalParent}, {}, {}, {}, {},
47 std::map<std::string, std::string>()),
48 myClosedEdge(closedEdge),
49 myPermissions(permissions) {
50  // update boundary of rerouter parent
51  rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);
52 }
53 
54 
56 
57 
58 void
62  if (getAttribute(SUMO_ATTR_ALLOW) != "authority") {
63  if (!getAttribute(SUMO_ATTR_ALLOW).empty()) {
65  } else {
67  }
68  }
69  device.closeTag();
70 }
71 
72 
75  // GNEClosingReroutes cannot be moved
76  return nullptr;
77 }
78 
79 
80 void
82  // update centering boundary (needed for centering)
84 }
85 
86 
89  // get rerouter parent position
90  Position signPosition = getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView();
91  // set position depending of indexes
92  signPosition.add(4.5 + 6.25, (getDrawPositionIndex() * -1) - getParentAdditionals().front()->getDrawPositionIndex() + 1, 0);
93  // return signPosition
94  return signPosition;
95 }
96 
97 
98 void
99 GNEClosingReroute::updateCenteringBoundary(const bool /*updateGrid*/) {
103 }
104 
105 
106 void
107 GNEClosingReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
108  // geometry of this element cannot be splitted
109 }
110 
111 
112 std::string
114  return getParentAdditionals().at(0)->getID();
115 }
116 
117 
118 void
120  // draw closing reroute as listed attribute
125 }
126 
127 
128 std::string
130  switch (key) {
131  case SUMO_ATTR_ID:
132  return getID();
133  case SUMO_ATTR_EDGE:
134  return myClosedEdge->getID();
135  case SUMO_ATTR_ALLOW:
137  case SUMO_ATTR_DISALLOW:
139  case GNE_ATTR_PARENT:
140  return getParentAdditionals().at(0)->getID();
141  case GNE_ATTR_SELECTED:
143  default:
144  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
145  }
146 }
147 
148 
149 double
151  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
152 }
153 
154 
155 void
156 GNEClosingReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
157  if (value == getAttribute(key)) {
158  return; //avoid needless changes, later logic relies on the fact that attributes have changed
159  }
160  switch (key) {
161  case SUMO_ATTR_ID:
162  case SUMO_ATTR_EDGE:
163  case SUMO_ATTR_ALLOW:
164  case SUMO_ATTR_DISALLOW:
165  case GNE_ATTR_SELECTED:
166  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
167  break;
168  default:
169  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
170  }
171 }
172 
173 
174 bool
175 GNEClosingReroute::isValid(SumoXMLAttr key, const std::string& value) {
176  switch (key) {
177  case SUMO_ATTR_ID:
178  return isValidAdditionalID(value);
179  case SUMO_ATTR_EDGE:
180  return (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr);
181  case SUMO_ATTR_ALLOW:
182  return canParseVehicleClasses(value);
183  case SUMO_ATTR_DISALLOW:
184  return canParseVehicleClasses(value);
185  case GNE_ATTR_SELECTED:
186  return Parameterised::areParametersValid(value);
187  default:
188  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
189  }
190 }
191 
192 
193 bool
195  return true;
196 }
197 
198 
199 std::string
201  return getTagStr();
202 }
203 
204 
205 std::string
207  return getTagStr() + ": " + myClosedEdge->getID();
208 }
209 
210 // ===========================================================================
211 // private
212 // ===========================================================================
213 
214 void
215 GNEClosingReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
216  switch (key) {
217  case SUMO_ATTR_ID:
218  // update microsimID
219  setMicrosimID(value);
220  break;
221  case SUMO_ATTR_EDGE:
223  break;
224  case SUMO_ATTR_ALLOW:
226  break;
227  case SUMO_ATTR_DISALLOW:
229  break;
230  case GNE_ATTR_SELECTED:
231  if (parse<bool>(value)) {
233  } else {
235  }
236  break;
237  default:
238  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
239  }
240 }
241 
242 
243 void
245  // nothing to do
246 }
247 
248 
249 void
250 GNEClosingReroute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
251  // nothing to do
252 }
253 
254 
255 /****************************************************************************/
@ GLO_REROUTER_CLOSINGREROUTE
a closing reroute
@ REROUTER_CLOSINGREROUTE
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_SELECTED
element is selected
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:77
void reset()
Resets the boundary.
Definition: Boundary.cpp:65
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
const std::string & getID() const
get ID
void drawListedAddtional(const GUIVisualizationSettings &s, const Position &parentPosition, const int offsetX, const int extraOffsetY, const RGBColor baseCol, const RGBColor textCol, GUITexture texture, const std::string text) const
draw listed additional
int getDrawPositionIndex() const
get draw position index (used in rerouters and VSS)
Boundary myAdditionalBoundary
Additional Boundary.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
SVCPermissions myPermissions
void updateGeometry()
update pre-computed geometry information
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
std::string getParentName() const
Returns the name of the parent object.
double getAttributeDouble(SumoXMLAttr key) const
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
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)
GNEMoveOperation * getMoveOperation()
get move operation
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
GNEClosingReroute(GNENet *net)
default constructor
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
Position getPositionInView() const
Returns position of additional in view.
~GNEClosingReroute()
destructor
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
move operation
move result
GNEEdge * retrieveEdge(const std::string &id, bool hardFail=true) const
get edge by id
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:125
const std::string & getID() const
get ID
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
Stores the information about how to visualize structures.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:125
static const RGBColor YELLOW
Definition: RGBColor.h:188
static const RGBColor RED
named colors
Definition: RGBColor.h:185