Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNELaneType.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 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
21#include <netedit/GNENet.h>
26
27#include "GNELaneType.h"
28#include "GNEEdgeType.h"
29
30// ===========================================================================
31// members methods
32// ===========================================================================
33
35 GNENetworkElement(edgeTypeParent->getNet(), "", SUMO_TAG_LANETYPE),
36 myEdgeTypeParent(edgeTypeParent) {
37}
38
39
41 GNENetworkElement(edgeTypeParent->getNet(), "", SUMO_TAG_LANETYPE),
43 myEdgeTypeParent(edgeTypeParent) {
44}
45
46
49
50
53 return nullptr;
54}
55
56
59 return this;
60}
61
62
63const Parameterised*
65 return this;
66}
67
68
73
74
75void
76GNELaneType::copyLaneType(GNELaneType* originalLaneType, GNEUndoList* undoList) {
77 // copy speed
78 setAttribute(SUMO_ATTR_SPEED, originalLaneType->getAttribute(SUMO_ATTR_SPEED), undoList);
79 // copy allow (and disallow)
80 setAttribute(SUMO_ATTR_ALLOW, originalLaneType->getAttribute(SUMO_ATTR_ALLOW), undoList);
81 // copy width
82 setAttribute(SUMO_ATTR_WIDTH, originalLaneType->getAttribute(SUMO_ATTR_WIDTH), undoList);
83 // copy parameters
85}
86
87
88void
90 // nothing to do
91}
92
93
96 // currently unused
97 return Position(0, 0);
98}
99
100
101bool
103 return false;
104}
105
106
107bool
109 return false;
110}
111
112
113bool
115 return false;
116}
117
118
119bool
121 return false;
122}
123
124bool
126 return false;
127}
128
129
130bool
132 return false;
133}
134
135
136bool
138 return false;
139}
140
141
142bool
144 return false;
145}
146
147
150 return nullptr;
151}
152
153
156 return myNetworkElementContour.getContourBoundary();
157}
158
159
160void
161GNELaneType::updateCenteringBoundary(const bool /*updateGrid*/) {
162 // nothing to do
163}
164
165
166void
168 // nothing to draw
169}
170
171
172void
174 myNet->deleteNetworkElement(this, myNet->getViewNet()->getUndoList());
175}
176
177
178void
182
183
184std::string
186 switch (key) {
187 case SUMO_ATTR_ID:
188 return "lane: " + toString(myEdgeTypeParent->getLaneTypeIndex(this));
189 case SUMO_ATTR_SPEED:
190 if (attrs.count(key) == 0) {
191 return toString(OptionsCont::getOptions().getFloat("default.speed"));
192 } else {
193 return toString(speed);
194 }
195 case SUMO_ATTR_ALLOW:
196 if ((permissions == SVCAll) || (permissions == -1)) {
197 return "all";
198 } else if (permissions == 0) {
199 return "";
200 } else {
202 }
204 if (permissions == 0) {
205 return "all";
206 } else if ((permissions == SVCAll) || (permissions == -1)) {
207 return "";
208 } else {
210 }
211 case SUMO_ATTR_WIDTH:
212 if (attrs.count(key) == 0) {
213 return "default";
214 } else {
215 return toString(width);
216 }
218 if (attrs.count(key) == 0) {
219 return "";
220 } else {
221 return toString(width);
222 }
223 default:
224 return getCommonAttribute(key);
225 }
226}
227
228
229double
233
234
239
240
245
246
247void
248GNELaneType::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/, GNEUndoList* /*undoList*/) {
249 throw InvalidArgument("laneType attributes cannot be edited here");
250}
251
252
253bool
254GNELaneType::isValid(SumoXMLAttr key, const std::string& value) {
255 switch (key) {
256 case SUMO_ATTR_ID:
257 throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
258 case SUMO_ATTR_SPEED:
259 if (value.empty() || (value == "default")) {
260 return true;
261 } else {
262 return canParse<double>(value) && (parse<double>(value) > 0);
263 }
264 case SUMO_ATTR_ALLOW:
267 case SUMO_ATTR_WIDTH:
268 if (value.empty() || (value == "-1") || (value == "default")) {
269 return true;
270 } else {
271 return canParse<double>(value);
272 }
273 default:
274 return isCommonAttributeValid(key, value);
275 }
276}
277
278// ===========================================================================
279// private
280// ===========================================================================
281
282void
284 switch (key) {
285 case SUMO_ATTR_ID:
286 throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
287 case SUMO_ATTR_SPEED:
288 if (value.empty() || (value == "default")) {
289 attrs.erase(key);
290 } else {
291 attrs.insert(key);
293 }
294 break;
295 case SUMO_ATTR_ALLOW:
296 // parse permissions
298 // check attrs
299 if ((permissions == SVCAll) || (permissions == -1)) {
300 attrs.insert(SUMO_ATTR_ALLOW);
302 } else if (permissions == 0) {
303 attrs.erase(SUMO_ATTR_ALLOW);
305 } else {
306 attrs.insert(SUMO_ATTR_ALLOW);
308 }
309 break;
311 // parse invert permissions
313 // check attrs
314 if ((permissions == SVCAll) || (permissions == -1)) {
315 attrs.insert(SUMO_ATTR_ALLOW);
317 } else if (permissions == 0) {
318 attrs.erase(SUMO_ATTR_ALLOW);
320 } else {
321 attrs.insert(SUMO_ATTR_ALLOW);
323 }
324 break;
325 case SUMO_ATTR_WIDTH:
326 if (value.empty() || (value == "-1") || (value == "default")) {
327 attrs.erase(key);
328 } else {
329 attrs.insert(key);
331 }
332 break;
333 default:
335 break;
336 }
337 // update edge selector
338 if (myNet->getViewNet()->getViewParent()->getCreateEdgeFrame()->shown()) {
339 myNet->getViewNet()->getViewParent()->getCreateEdgeFrame()->getLaneTypeAttributes()->refreshAttributesEditor();
340 }
341}
342
343/****************************************************************************/
const std::string invalid_return< std::string >::value
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
@ SUMO_ATTR_FRICTION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
double getCommonAttributeDouble(SumoXMLAttr key) const
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc....
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
Position getCommonAttributePosition(SumoXMLAttr key) const
static bool canParse(const std::string &string)
true if a value of type T can be parsed from string
GNENet * myNet
pointer to net
GNENet * getNet() const
get pointer to net
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
std::string getCommonAttribute(SumoXMLAttr key) const
void updateGeometry() override
update pre-computed geometry information
bool checkDrawMoveContour() const override
check if draw move contour (red)
GNEEdgeType * myEdgeTypeParent
pointer to EdgeTypeParent
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
bool isValid(SumoXMLAttr key, const std::string &value) override
Parameterised * getParameters() override
get parameters associated with this laneType
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
Position getPositionInView() const
Returns position of hierarchical element in view.
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
bool checkDrawRelatedContour() const override
check if draw related contour (cyan)
bool checkDrawOverContour() const override
check if draw over contour (orange)
double getAttributeDouble(SumoXMLAttr key) const override
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this laneType
GNELaneType(GNEEdgeType *edgeTypeParent)
Constructor.
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
void copyLaneType(GNELaneType *originalLaneType, GNEUndoList *undoList)
copy values of given laneType in current laneType
bool checkDrawDeleteContour() const override
check if draw delete contour (pink/white)
bool checkDrawFromContour() const override
check if draw from contour (green)
void updateGLObject() override
update GLObject (geometry, ID, etc.)
Boundary getCenteringBoundary() const override
Returns the boundary to which the view shall be centered in order to show the object.
GNEEdgeType * getEdgeTypeParent() const
get edge type parent
bool checkDrawToContour() const override
check if draw from contour (magenta)
Position getAttributePosition(SumoXMLAttr key) const override
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own popup-menu.
bool checkDrawSelectContour() const override
check if draw select contour (blue)
bool checkDrawDeleteContourSmall() const override
check if draw delete contour small (pink/white)
~GNELaneType()
Destructor.
friend class GNEEdgeType
Definition GNELaneType.h:38
void deleteGLObject() override
delete element
std::string getAttribute(SumoXMLAttr key) const override
GNEContour myNetworkElementContour
network element contour
GNENetworkElement(GNENet *net, const std::string &id, SumoXMLTag tag)
Constructor.
The popup menu of a globject.
Stores the information about how to visualize structures.
A storage for available edgeTypes of edges.
Definition NBTypeCont.h:52
static OptionsCont & getOptions()
Retrieves the options.
An upper class for objects with additional parameters.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
laneType definition
Definition NBTypeCont.h:59
double speed
The maximal velocity on a lane in m/s.
Definition NBTypeCont.h:74
LaneTypeDefinition()
default Constructor
SVCPermissions permissions
List of vehicle edgeTypes that are allowed on this lane.
Definition NBTypeCont.h:80
std::set< SumoXMLAttr > attrs
The attributes which have been set.
Definition NBTypeCont.h:89
double width
lane width [m]
Definition NBTypeCont.h:83