SUMO - Simulation of Urban MObility
GNEClosingLaneReroute.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 "GNEClosingLaneReroute.h"
32 #include "GNELane.h"
33 #include "GNEEdge.h"
34 #include "GNEUndoList.h"
35 #include "GNEChange_Attribute.h"
36 #include "GNERerouter.h"
37 #include "GNEViewNet.h"
38 #include "GNENet.h"
39 #include "GNERerouterInterval.h"
41 
42 
43 // ===========================================================================
44 // member method definitions
45 // ===========================================================================
46 
49  myRerouterIntervalParent(rerouterIntervalDialog->getEditedRerouterInterval()),
50  myClosedLane(rerouterIntervalDialog->getEditedRerouterInterval()->getRerouterParent()->getEdgeChilds().at(0)->getLanes().at(0)),
51  myAllowedVehicles(parseVehicleClasses(getDefaultValue<std::string>(SUMO_TAG_CLOSING_LANE_REROUTE, SUMO_ATTR_ALLOW))),
52  myDisallowedVehicles(parseVehicleClasses(getDefaultValue<std::string>(SUMO_TAG_CLOSING_LANE_REROUTE, SUMO_ATTR_DISALLOW))) {
53 }
54 
55 
56 GNEClosingLaneReroute::GNEClosingLaneReroute(GNERerouterInterval* rerouterIntervalParent, GNELane* closedLane, SVCPermissions allowedVehicles, SVCPermissions disallowedVehicles) :
58  myRerouterIntervalParent(rerouterIntervalParent),
59  myClosedLane(closedLane),
60  myAllowedVehicles(allowedVehicles),
61  myDisallowedVehicles(disallowedVehicles) {
62 }
63 
64 
66 
67 
68 void
70  // open closing reroute tag
71  device.openTag(getTag());
72  // write Lane ID
74  // write Allowed vehicles
76  // write disallowed vehicles
78  // close closing reroute tag
79  device.closeTag();
80 }
81 
82 
86 }
87 
88 
89 std::string
91  switch (key) {
92  case SUMO_ATTR_ID:
93  return myClosedLane->getID();
94  case SUMO_ATTR_ALLOW:
96  case SUMO_ATTR_DISALLOW:
98  default:
99  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
100  }
101 }
102 
103 
104 void
105 GNEClosingLaneReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
106  if (value == getAttribute(key)) {
107  return; //avoid needless changes, later logic relies on the fact that attributes have changed
108  }
109  switch (key) {
110  case SUMO_ATTR_ID:
111  case SUMO_ATTR_ALLOW:
112  case SUMO_ATTR_DISALLOW:
113  undoList->p_add(new GNEChange_Attribute(this, key, value));
114  break;
115  default:
116  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
117  }
118 }
119 
120 
121 bool
122 GNEClosingLaneReroute::isValid(SumoXMLAttr key, const std::string& value) {
123  switch (key) {
124  case SUMO_ATTR_ID:
125  return (myRerouterIntervalParent->getRerouterParent()->getViewNet()->getNet()->retrieveLane(value, false) != NULL);
126  case SUMO_ATTR_ALLOW:
127  return canParseVehicleClasses(value);
128  case SUMO_ATTR_DISALLOW:
129  return canParseVehicleClasses(value);
130  default:
131  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
132  }
133 }
134 
135 // ===========================================================================
136 // private
137 // ===========================================================================
138 
139 void
140 GNEClosingLaneReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
141  switch (key) {
142  case SUMO_ATTR_ID: {
144  break;
145  }
146  case SUMO_ATTR_ALLOW: {
148  break;
149  }
150  case SUMO_ATTR_DISALLOW: {
152  break;
153  }
154  default:
155  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
156  }
157 }
158 
159 /****************************************************************************/
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
SVCPermissions myDisallowedVehicles
codified disallowed vehicles
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
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:53
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
GNERerouterInterval * getRerouterIntervalParent() const
get rerouter interval parent
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
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in all GNEAttributeCarriers.
friend class GNEChange_Attribute
declare friend class
SVCPermissions myAllowedVehicles
codified allowed vehicles
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...
void writeClosingLaneReroute(OutputDevice &device) const
const std::string getID() const
function to support debugging
GNELane * myClosedLane
closed lane
bool isValid(SumoXMLAttr key, const std::string &value)
bool canParseVehicleClasses(const std::string &classes)
Checks whether the given string contains only known vehicle classes.
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
GNERerouterInterval * myRerouterIntervalParent
reference to rerouter interval parent
bool closeTag()
Closes the most recently opened tag.
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1000
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
GNEClosingLaneReroute(GNERerouterIntervalDialog *rerouterIntervalDialog)
constructor (Used in GNERerouterIntervalDialog)
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
SumoXMLTag getTag() const
get XML Tag assigned to this object