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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 //
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
29 #include <utils/common/ToString.h>
30 
31 #include "GNEClosingReroute.h"
32 #include "GNEEdge.h"
33 #include "GNEUndoList.h"
34 #include "GNEChange_Attribute.h"
35 #include "GNERerouter.h"
36 #include "GNEViewNet.h"
37 #include "GNENet.h"
38 #include "GNERerouterInterval.h"
40 
41 
42 // ===========================================================================
43 // member method definitions
44 // ===========================================================================
45 
48  myRerouterIntervalParent(rerouterIntervalDialog->getEditedRerouterInterval()),
49  myClosedEdge(rerouterIntervalDialog->getEditedRerouterInterval()->getRerouterParent()->getEdgeChilds().at(0)),
50  myAllowedVehicles(parseVehicleClasses(getDefaultValue<std::string>(SUMO_TAG_CLOSING_LANE_REROUTE, SUMO_ATTR_ALLOW))),
51  myDisallowedVehicles(parseVehicleClasses(getDefaultValue<std::string>(SUMO_TAG_CLOSING_LANE_REROUTE, SUMO_ATTR_DISALLOW))) {
52 }
53 
54 
55 GNEClosingReroute::GNEClosingReroute(GNERerouterInterval* rerouterIntervalParent, GNEEdge* closedEdge, SVCPermissions allowedVehicles, SVCPermissions disallowedVehicles) :
57  myRerouterIntervalParent(rerouterIntervalParent),
58  myClosedEdge(closedEdge),
59  myAllowedVehicles(allowedVehicles),
60  myDisallowedVehicles(disallowedVehicles) {
61 }
62 
63 
65 
66 
67 void
69  // open closing reroute tag
70  device.openTag(getTag());
71  // write Lane ID
73  // write Allowed vehicles
75  // write disallowed vehicles
77  // close closing reroute tag
78  device.closeTag();
79 }
80 
81 
85 }
86 
87 
88 std::string
90  switch (key) {
91  case SUMO_ATTR_ID:
92  return myClosedEdge->getID();
93  case SUMO_ATTR_ALLOW:
95  case SUMO_ATTR_DISALLOW:
97  default:
98  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
99  }
100 }
101 
102 
103 void
104 GNEClosingReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
105  if (value == getAttribute(key)) {
106  return; //avoid needless changes, later logic relies on the fact that attributes have changed
107  }
108  switch (key) {
109  case SUMO_ATTR_ID:
110  case SUMO_ATTR_ALLOW:
111  case SUMO_ATTR_DISALLOW:
112  undoList->p_add(new GNEChange_Attribute(this, key, value));
113  break;
114  default:
115  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
116  }
117 }
118 
119 
120 bool
121 GNEClosingReroute::isValid(SumoXMLAttr key, const std::string& value) {
122  switch (key) {
123  case SUMO_ATTR_ID:
124  return (myRerouterIntervalParent->getRerouterParent()->getViewNet()->getNet()->retrieveEdge(value, false) != NULL);
125  case SUMO_ATTR_ALLOW:
126  return canParseVehicleClasses(value);
127  case SUMO_ATTR_DISALLOW:
128  return canParseVehicleClasses(value);
129  default:
130  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
131  }
132 }
133 
134 // ===========================================================================
135 // private
136 // ===========================================================================
137 
138 void
139 GNEClosingReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
140  switch (key) {
141  case SUMO_ATTR_ID: {
143  break;
144  }
145  case SUMO_ATTR_ALLOW: {
147  break;
148  }
149  case SUMO_ATTR_DISALLOW: {
151  break;
152  }
153  default:
154  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
155  }
156 }
157 
158 /****************************************************************************/
std::string getVehicleClassNames(SVCPermissions permissions, bool expand)
Returns the ids of the given classes, divided using a &#39; &#39;.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:902
Dialog for edit rerouter intervals.
lane of a reroute of type closing
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
SVCPermissions myAllowedVehicles
codified allowed vehicles
SVCPermissions myDisallowedVehicles
codified disallowed vehicles
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
GNERerouterInterval * myRerouterIntervalParent
reference to rerouter interval parent
GNEClosingReroute(GNERerouterIntervalDialog *rerouterIntervalDialog)
constructor (Used in GNERerouterIntervalDialog)
bool isValid(SumoXMLAttr key, const std::string &value)
void writeClosingReroute(OutputDevice &device) const
write ClosingReroute
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
~GNEClosingReroute()
destructor
friend class GNEChange_Attribute
declare friend class
GNERerouter * getRerouterParent() const
get rerouter parent
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in all GNEAttributeCarriers.
const std::string getID() const
function to support debugging
GNEEdge * myClosedEdge
closed edge
bool canParseVehicleClasses(const std::string &classes)
Checks whether the given string contains only known vehicle classes.
reroute of type closing
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:56
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
GNENet * getNet() const
get the net object
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
GNERerouterInterval * getRerouterIntervalParent() const
get rerouter interval parent
SumoXMLTag getTag() const
get XML Tag assigned to this object