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-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 /****************************************************************************/
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEViewNet.h>
24 #include <netedit/GNEViewParent.h>
26 
27 
28 #include "GNELaneType.h"
29 #include "GNEEdgeType.h"
30 
31 
32 // ===========================================================================
33 // members methods
34 // ===========================================================================
35 
37  GNENetworkElement(edgeTypeParent->getNet(), "", GLO_LANE, SUMO_TAG_LANETYPE, {}, {}, {}, {}, {}, {}, {}, {}),
38 myEdgeTypeParent(edgeTypeParent) {
39 }
40 
41 
43  GNENetworkElement(edgeTypeParent->getNet(), "", GLO_LANE, SUMO_TAG_LANETYPE, {}, {}, {}, {}, {}, {}, {}, {}),
45 myEdgeTypeParent(edgeTypeParent) {
46 }
47 
48 
50 }
51 
52 
55  return myEdgeTypeParent;
56 }
57 
58 
59 void
60 GNELaneType::copyLaneType(GNELaneType* originalLaneType, GNEUndoList* undoList) {
61  // copy speed
62  setAttribute(SUMO_ATTR_SPEED, originalLaneType->getAttribute(SUMO_ATTR_SPEED), undoList);
63  // copy allow (and disallow)
64  setAttribute(SUMO_ATTR_ALLOW, originalLaneType->getAttribute(SUMO_ATTR_ALLOW), undoList);
65  // copy width
66  setAttribute(SUMO_ATTR_WIDTH, originalLaneType->getAttribute(SUMO_ATTR_WIDTH), undoList);
67  // copy parameters
69 }
70 
71 
72 void
74  // nothing to do
75 }
76 
77 
80  // currently unused
81  return Position(0, 0);
82 }
83 
84 
87  return nullptr;
88 }
89 
90 
91 void
92 GNELaneType::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
93  // nothing to do
94 }
95 
96 
99  return nullptr;
100 }
101 
102 
103 double
105  return 1;
106 }
107 
108 
109 void
110 GNELaneType::updateCenteringBoundary(const bool /*updateGrid*/) {
111  // nothing to do
112 }
113 
114 
115 void
117  // nothing to draw
118 }
119 
120 
121 std::string
123  switch (key) {
124  case SUMO_ATTR_ID:
125  return "lane: " + toString(myEdgeTypeParent->getLaneTypeIndex(this));
126  case SUMO_ATTR_SPEED:
127  if (attrs.count(key) == 0) {
128  return "";
129  } else {
130  return toString(speed);
131  }
132  case SUMO_ATTR_ALLOW:
133  if ((permissions == SVCAll) || (permissions == -1)) {
134  return "all";
135  } else if (permissions == 0) {
136  return "";
137  } else {
139  }
140  case SUMO_ATTR_DISALLOW:
141  if (permissions == 0) {
142  return "all";
143  } else if ((permissions == SVCAll) || (permissions == -1)) {
144  return "";
145  } else {
147  }
148  case SUMO_ATTR_WIDTH:
149  if (attrs.count(key) == 0) {
150  return "";
151  } else {
152  return toString(width);
153  }
154  case GNE_ATTR_PARAMETERS:
155  return getParametersStr();
156  default:
157  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
158  }
159 }
160 
161 
162 void
163 GNELaneType::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/, GNEUndoList* /*undoList*/) {
164  throw InvalidArgument("laneType attributes cannot be edited here");
165 }
166 
167 
168 bool
169 GNELaneType::isValid(SumoXMLAttr key, const std::string& value) {
170  switch (key) {
171  case SUMO_ATTR_ID:
172  throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
173  case SUMO_ATTR_SPEED:
174  return canParse<double>(value) && (parse<double>(value) > 0);
175  case SUMO_ATTR_ALLOW:
176  case SUMO_ATTR_DISALLOW:
177  return canParseVehicleClasses(value);
178  case SUMO_ATTR_WIDTH:
179  return canParse<double>(value) && ((parse<double>(value) >= -1) || (parse<double>(value) == NBEdge::UNSPECIFIED_WIDTH));
180  case GNE_ATTR_PARAMETERS:
181  return Parameterised::areParametersValid(value);
182  default:
183  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
184  }
185 }
186 
187 
188 bool
190  return true;
191 }
192 
193 
194 bool
196  return false;
197 }
198 
199 
200 const std::map<std::string, std::string>&
202  return getParametersMap();
203 }
204 
205 // ===========================================================================
206 // private
207 // ===========================================================================
208 
209 void
210 GNELaneType::setAttribute(SumoXMLAttr key, const std::string& value) {
211  switch (key) {
212  case SUMO_ATTR_ID:
213  throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
214  case SUMO_ATTR_SPEED:
215  if (value.empty()) {
216  attrs.erase(key);
217  } else {
218  attrs.insert(key);
219  speed = parse<double>(value);
220  }
221  break;
222  case SUMO_ATTR_ALLOW:
223  // parse permissions
225  // check attrs
226  if ((permissions == SVCAll) || (permissions == -1)) {
227  attrs.insert(SUMO_ATTR_ALLOW);
228  attrs.erase(SUMO_ATTR_DISALLOW);
229  } else if (permissions == 0) {
230  attrs.erase(SUMO_ATTR_ALLOW);
231  attrs.insert(SUMO_ATTR_DISALLOW);
232  } else {
233  attrs.insert(SUMO_ATTR_ALLOW);
234  attrs.insert(SUMO_ATTR_DISALLOW);
235  }
236  break;
237  case SUMO_ATTR_DISALLOW:
238  // parse invert permissions
240  // check attrs
241  if ((permissions == SVCAll) || (permissions == -1)) {
242  attrs.insert(SUMO_ATTR_ALLOW);
243  attrs.erase(SUMO_ATTR_DISALLOW);
244  } else if (permissions == 0) {
245  attrs.erase(SUMO_ATTR_ALLOW);
246  attrs.insert(SUMO_ATTR_DISALLOW);
247  } else {
248  attrs.insert(SUMO_ATTR_ALLOW);
249  attrs.insert(SUMO_ATTR_DISALLOW);
250  }
251  break;
252  case SUMO_ATTR_WIDTH:
253  if (value.empty()) {
254  attrs.erase(key);
255  } else {
256  attrs.insert(key);
257  width = parse<double>(value);
258  }
259  break;
260  case GNE_ATTR_PARAMETERS:
261  setParametersStr(value);
262  break;
263  default:
264  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
265  }
266  // update edge selector
267  if (myNet->getViewNet()->getViewParent()->getCreateEdgeFrame()->shown()) {
269  }
270 }
271 
272 
273 void
274 GNELaneType::setMoveShape(const GNEMoveResult& /*moveResult*/) {
275  // nothing to do
276 }
277 
278 
279 void
280 GNELaneType::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
281  // nothing to do
282 }
283 
284 /****************************************************************************/
@ GLO_LANE
a lane
const SVCPermissions SVCAll
all VClasses are allowed
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:46
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
GNEFrameAttributeModules::AttributesCreator * getLaneTypeAttributes() const
get laneType attributes
int getLaneTypeIndex(const GNELaneType *laneType) const
get laneType index
void refreshAttributesCreator()
refresh attribute creator
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList)
remove geometry point in the clicked position
Definition: GNELaneType.cpp:92
GNEEdgeType * myEdgeTypeParent
pointer to EdgeTypeParent
Definition: GNELaneType.h:135
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Position getPositionInView() const
Returns position of hierarchical element in view.
Definition: GNELaneType.cpp:79
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
void updateGeometry()
update pre-computed geometry information
Definition: GNELaneType.cpp:73
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:36
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:60
bool isAttributeEnabled(SumoXMLAttr key) const
bool isAttributeComputed(SumoXMLAttr key) const
GNEMoveOperation * getMoveOperation()
get move operation
Definition: GNELaneType.cpp:86
GNEEdgeType * getEdgeTypeParent() const
get edge type parent
Definition: GNELaneType.cpp:54
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration asociated with this GLObject
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GNELaneType.cpp:98
~GNELaneType()
Destructor.
Definition: GNELaneType.cpp:49
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
move operation
move result
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
GNEViewParent * getViewParent() const
get the net object
GNECreateEdgeFrame * getCreateEdgeFrame() const
get frame for NETWORK_CREATEEDGE
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:349
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|....
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:37
laneType definition
Definition: NBTypeCont.h:59
double speed
The maximal velocity on a lane in m/s.
Definition: NBTypeCont.h:74
SVCPermissions permissions
List of vehicle edgeTypes that are allowed on this lane.
Definition: NBTypeCont.h:77
std::set< SumoXMLAttr > attrs
The attributes which have been set.
Definition: NBTypeCont.h:86
double width
lane width [m]
Definition: NBTypeCont.h:80