Eclipse SUMO - Simulation of Urban MObility
GNELaneType.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 /****************************************************************************/
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEUndoList.h>
26 
27 #include "GNELaneType.h"
28 #include "GNEEdgeType.h"
29 
30 
31 // ===========================================================================
32 // members methods
33 // ===========================================================================
34 
36  GNENetworkElement(edgeTypeParent->getNet(), "", GLO_LANE, SUMO_TAG_LANETYPE, {}, {}, {}, {}, {}, {}, {}, {}),
37  myEdgeTypeParent(edgeTypeParent) {
38 }
39 
40 
42  GNENetworkElement(edgeTypeParent->getNet(), "", GLO_LANE, SUMO_TAG_LANETYPE, {}, {}, {}, {}, {}, {}, {}, {}),
43  myEdgeTypeParent(edgeTypeParent) {
44  // copy parameters
45  speed = laneType.speed;
46  permissions = laneType.permissions;
47  width = laneType.width;
48  attrs = laneType.attrs;
49 }
50 
51 
53 }
54 
55 
58  return myEdgeTypeParent;
59 }
60 
61 
62 void
63 GNELaneType::copyLaneType(GNELaneType* originalLaneType, GNEUndoList* undoList) {
64  // copy speed
65  setAttribute(SUMO_ATTR_SPEED, originalLaneType->getAttribute(SUMO_ATTR_SPEED), undoList);
66  // copy allow (and disallow)
67  setAttribute(SUMO_ATTR_ALLOW, originalLaneType->getAttribute(SUMO_ATTR_ALLOW), undoList);
68  // copy width
69  setAttribute(SUMO_ATTR_WIDTH, originalLaneType->getAttribute(SUMO_ATTR_WIDTH), undoList);
70  // copy parameters
72 }
73 
74 
75 void
77  // nothing to do
78 }
79 
80 
83  // currently unused
84  return Position(0, 0);
85 }
86 
87 
89 GNELaneType::getMoveOperation(const double /*shapeOffset*/) {
90  return nullptr;
91 }
92 
93 
94 void
95 GNELaneType::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
96  // nothing to do
97 }
98 
99 
102  return nullptr;
103 }
104 
105 
106 void
107 GNELaneType::updateCenteringBoundary(const bool /*updateGrid*/) {
108  // nothing to do
109 }
110 
111 
112 void
114  // nothing to draw
115 }
116 
117 
118 std::string
120  switch (key) {
121  case SUMO_ATTR_ID:
123  case SUMO_ATTR_SPEED:
124  if (attrs.count(key) == 0) {
125  return "";
126  } else {
127  return toString(speed);
128  }
129  case SUMO_ATTR_ALLOW:
130  if (attrs.count(SUMO_ATTR_DISALLOW) == 0) {
131  return "";
132  } else {
134  }
135  case SUMO_ATTR_DISALLOW:
136  if (attrs.count(SUMO_ATTR_DISALLOW) == 0) {
137  return "";
138  } else {
140  }
141  case SUMO_ATTR_WIDTH:
142  if (attrs.count(key) == 0) {
143  return "";
144  } else {
145  return toString(width);
146  }
147  case GNE_ATTR_PARAMETERS:
148  return getParametersStr();
149  default:
150  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
151  }
152 }
153 
154 
155 void
156 GNELaneType::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
157  switch (key) {
158  case SUMO_ATTR_ID:
159  throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
160  case SUMO_ATTR_SPEED:
161  case SUMO_ATTR_ALLOW:
162  case SUMO_ATTR_DISALLOW:
163  case SUMO_ATTR_WIDTH:
164  case GNE_ATTR_PARAMETERS:
165  undoList->p_add(new GNEChange_Attribute(this, key, value));
166  break;
167  default:
168  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
169  }
170 }
171 
172 
173 bool
174 GNELaneType::isValid(SumoXMLAttr key, const std::string& value) {
175  switch (key) {
176  case SUMO_ATTR_ID:
177  throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
178  case SUMO_ATTR_SPEED:
179  return canParse<double>(value) && (parse<double>(value) > 0);
180  case SUMO_ATTR_ALLOW:
181  case SUMO_ATTR_DISALLOW:
182  return canParseVehicleClasses(value);
183  case SUMO_ATTR_WIDTH:
184  return canParse<double>(value) && ((parse<double>(value) >= -1) || (parse<double>(value) == NBEdge::UNSPECIFIED_WIDTH));
185  case GNE_ATTR_PARAMETERS:
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 const std::map<std::string, std::string>&
201  return getParametersMap();
202 }
203 
204 // ===========================================================================
205 // private
206 // ===========================================================================
207 
208 void
209 GNELaneType::setAttribute(SumoXMLAttr key, const std::string& value) {
210  switch (key) {
211  case SUMO_ATTR_ID:
212  throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
213  case SUMO_ATTR_SPEED:
214  if (value.empty()) {
215  attrs.erase(key);
216  } else {
217  attrs.insert(key);
218  speed = parse<double>(value);
219  }
220  break;
221  case SUMO_ATTR_ALLOW:
222  if (value.empty()) {
223  attrs.erase(SUMO_ATTR_DISALLOW);
224  } else {
225  attrs.insert(SUMO_ATTR_DISALLOW);
227  }
228  break;
229  case SUMO_ATTR_DISALLOW:
230  if (value.empty()) {
231  attrs.erase(SUMO_ATTR_DISALLOW);
232  } else {
233  attrs.insert(SUMO_ATTR_DISALLOW);
235  }
236  break;
237  case SUMO_ATTR_WIDTH:
238  if (value.empty()) {
239  attrs.erase(key);
240  } else {
241  attrs.insert(key);
242  width = parse<double>(value);
243  }
244  break;
245  case GNE_ATTR_PARAMETERS:
246  setParametersStr(value);
247  break;
248  default:
249  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
250  }
251 }
252 
253 
254 void
255 GNELaneType::setMoveShape(const GNEMoveResult& /*moveResult*/) {
256  // nothing to do
257 }
258 
259 
260 void
261 GNELaneType::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
262  // nothing to do
263 }
264 
265 /****************************************************************************/
@ GLO_LANE
a lane
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.
@ SUMO_TAG_LANETYPE
lane type
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_DISALLOW
@ SUMO_ATTR_ALLOW
@ SUMO_ATTR_SPEED
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_ID
@ SUMO_ATTR_WIDTH
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
int getLaneTypeIndex(const GNELaneType *laneType) const
get laneType index
Definition: GNEEdgeType.cpp:93
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList)
remove geometry point in the clicked position
Definition: GNELaneType.cpp:95
GNEEdgeType * myEdgeTypeParent
pointer to EdgeTypeParent
Definition: GNELaneType.h:128
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Position getPositionInView() const
Returns position of hierarchical element in view.
Definition: GNELaneType.cpp:82
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
void updateGeometry()
update pre-computed geometry information
Definition: GNELaneType.cpp:76
bool isValid(SumoXMLAttr key, const std::string &value)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
std::string getAttribute(SumoXMLAttr key) const
GNELaneType(GNEEdgeType *edgeTypeParent)
Constructor.
Definition: GNELaneType.cpp:35
const std::map< std::string, std::string > & getACParametersMap() const
get parameters map
void copyLaneType(GNELaneType *originalLaneType, GNEUndoList *undoList)
copy values of given laneType in current laneType
Definition: GNELaneType.cpp:63
bool isAttributeEnabled(SumoXMLAttr key) const
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
Definition: GNELaneType.cpp:89
GNEEdgeType * getEdgeTypeParent() const
get edge type parent
Definition: GNELaneType.cpp:57
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
~GNELaneType()
Destructor.
Definition: GNELaneType.cpp:52
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
move operation
move result
const std::string & getID() const
get ID
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
The popup menu of a globject.
Stores the information about how to visualize structures.
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:324
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".
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
laneType definition
Definition: NBTypeCont.h:56
double speed
The maximal velocity on a lane in m/s.
Definition: NBTypeCont.h:64
SVCPermissions permissions
List of vehicle edgeTypes that are allowed on this lane.
Definition: NBTypeCont.h:67
std::set< SumoXMLAttr > attrs
The attributes which have been set.
Definition: NBTypeCont.h:76
double width
lane width [m]
Definition: NBTypeCont.h:70