Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEEdgeType.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-2026 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 "GNEEdgeType.h"
28#include "GNELaneType.h"
29#include "GNEEdgeTemplate.h"
30#include "GNELaneTemplate.h"
31
32// ===========================================================================
33// members methods
34// ===========================================================================
35
38 // create laneType
39 GNELaneType* laneType = new GNELaneType(this);
40 myLaneTypes.push_back(laneType);
41}
42
43
44GNEEdgeType::GNEEdgeType(GNENet* net, const std::string& ID) :
46 // create laneType
47 GNELaneType* laneType = new GNELaneType(this);
48 myLaneTypes.push_back(laneType);
49}
50
51
53 GNENetworkElement(edgeType->getNet(), edgeType->getID(), SUMO_TAG_TYPE),
56}
57
58
59GNEEdgeType::GNEEdgeType(GNENet* net, const std::string& ID, const NBTypeCont::EdgeTypeDefinition* edgeType) :
61 // create laneTypes
62 for (const auto& laneTypeDef : edgeType->laneTypeDefinitions) {
63 GNELaneType* laneType = new GNELaneType(this, laneTypeDef);
64 myLaneTypes.push_back(laneType);
65 }
66 // copy parameters
67 speed = edgeType->speed;
68 friction = edgeType->friction;
69 priority = edgeType->priority;
70 permissions = edgeType->permissions;
71 spreadType = edgeType->spreadType;
72 oneWay = edgeType->oneWay;
73 discard = edgeType->discard;
74 width = edgeType->width;
76 maxWidth = edgeType->maxWidth;
77 minWidth = edgeType->minWidth;
78 sidewalkWidth = edgeType->sidewalkWidth;
79 bikeLaneWidth = edgeType->bikeLaneWidth;
80 restrictions = edgeType->restrictions;
81 attrs = edgeType->attrs;
83}
84
85
88 return nullptr;
89}
90
91
94 return this;
95}
96
97
98const Parameterised*
100 return this;
101}
102
103
104void
106 // copy all edge attributes
117 // copy lane attributes
118 for (int i = 0; i < (int)edgeTemplate->getLaneTemplates().size(); i++) {
119 // get lane types
120 auto originalLaneType = edgeTemplate->getLaneTemplates().at(i);
121 auto laneType = myLaneTypes.at(i);
122 laneType->setAttribute(SUMO_ATTR_SPEED, originalLaneType->getAttribute(SUMO_ATTR_SPEED));
123 laneType->setAttribute(SUMO_ATTR_ALLOW, originalLaneType->getAttribute(SUMO_ATTR_ALLOW));
124 laneType->setAttribute(SUMO_ATTR_DISALLOW, originalLaneType->getAttribute(SUMO_ATTR_DISALLOW));
125 laneType->setAttribute(SUMO_ATTR_WIDTH, originalLaneType->getAttribute(SUMO_ATTR_WIDTH));
126 laneType->setAttribute(GNE_ATTR_PARAMETERS, originalLaneType->getAttribute(GNE_ATTR_PARAMETERS));
127 }
128}
129
130
132 // delete laneTypes
133 for (const auto& laneType : myLaneTypes) {
134 delete laneType;
135 }
136}
137
138
139const std::vector<GNELaneType*>&
141 return myLaneTypes;
142}
143
144
145int
147 for (int i = 0; i < (int)myLaneTypes.size(); i++) {
148 if (myLaneTypes.at(i) == laneType) {
149 return i;
150 }
151 }
152 return (int)myLaneTypes.size();
153}
154
155
156void
158 myLaneTypes.push_back(laneType);
159}
160
161
162void
164 if (index < (int)myLaneTypes.size()) {
165 myLaneTypes.erase(myLaneTypes.begin() + index);
166 } else {
167 throw ProcessError(TL("Invalid index"));
168 }
169}
170
171
172void
175
176
179 // currently unused
180 return Position(0, 0);
181}
182
183
184bool
186 return false;
187}
188
189
190bool
192 return false;
193}
194
195
196bool
198 return false;
199}
200
201
202bool
204 return false;
205}
206
207
208bool
210 return false;
211}
212
213
214bool
216 return false;
217}
218
219
220bool
222 return false;
223}
224
225
226bool
228 return false;
229}
230
231
234 return nullptr;
235}
236
237
240 return myNetworkElementContour.getContourBoundary();
241}
242
243
244void
245GNEEdgeType::updateCenteringBoundary(const bool /*updateGrid*/) {
246 // nothing to do
247}
248
249
250void
252 // nothing to draw
253}
254
255
256void
258 myNet->deleteNetworkElement(this, myNet->getUndoList());
259}
260
261
262void
266
267
268std::string
270 // get options
271 const auto& neteditOptions = OptionsCont::getOptions();
272 switch (key) {
273 case SUMO_ATTR_ID:
274 return getMicrosimID();
276 return toString(myLaneTypes.size());
277 case SUMO_ATTR_SPEED:
278 if (attrs.count(key) == 0) {
279 return toString(neteditOptions.getFloat("default.speed"));
280 } else {
281 return toString(speed);
282 }
284 if (attrs.count(key) == 0) {
285 return toString(neteditOptions.getFloat("default.friction"));
286 } else {
287 return toString(friction);
288 }
289 case SUMO_ATTR_ALLOW:
290 if ((permissions == SVCAll) || (permissions == -1)) {
291 return "all";
292 } else if (permissions == 0) {
293 return "";
294 } else {
296 }
298 if (permissions == 0) {
299 return "all";
300 } else if ((permissions == SVCAll) || (permissions == -1)) {
301 return "";
302 } else {
304 }
307 case SUMO_ATTR_WIDTH:
308 if (attrs.count(key) != 0) {
309 return toString(width);
310 } else {
311 return "default";
312 }
314 if (attrs.count(key) != 0) {
315 return toString(priority);
316 } else {
317 return toString(-1);
318 }
319 // non editable attributes
320 case SUMO_ATTR_ONEWAY:
321 return toString(oneWay);
323 return toString(discard);
327 return toString(maxWidth);
329 return toString(minWidth);
331 if (attrs.count(key) != 0) {
332 return toString(sidewalkWidth);
333 } else {
334 return "default";
335 }
337 if (attrs.count(key) != 0) {
338 return toString(bikeLaneWidth);
339 } else {
340 return "default";
341 }
342 default:
343 return getCommonAttribute(key);
344 }
345}
346
347
348double
352
353
358
359
364
365
366void
367GNEEdgeType::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/, GNEUndoList* /*undoList*/) {
368 throw InvalidArgument("EdgeType attributes cannot be edited here");
369}
370
371
372bool
373GNEEdgeType::isValid(SumoXMLAttr key, const std::string& value) {
374 switch (key) {
375 case SUMO_ATTR_ID:
376 return SUMOXMLDefinitions::isValidNetID(value) && (myNet->getAttributeCarriers()->retrieveEdgeType(value, false) == nullptr);
378 return canParse<int>(value) && (parse<double>(value) > 0);
379 case SUMO_ATTR_SPEED:
380 if (value.empty()) {
381 return true;
382 } else {
383 return canParse<double>(value) && (parse<double>(value) > 0);
384 }
385 case SUMO_ATTR_ALLOW:
387 if (value.empty()) {
388 return true;
389 } else {
391 }
394 case SUMO_ATTR_WIDTH:
397 if (value.empty() || (value == "-1") || (value == "default")) {
398 return true;
399 } else {
400 return canParse<double>(value);
401 }
403 return canParse<int>(value);
404 default:
405 return isCommonAttributeValid(key, value);
406 }
407}
408
409
410bool
412 const auto edgeTypeSelector = myNet->getViewParent()->getCreateEdgeFrame()->getEdgeTypeSelector();
413 switch (key) {
415 if (edgeTypeSelector->useDefaultEdgeTypeShort() || edgeTypeSelector->useDefaultEdgeType()) {
416 return edgeTypeSelector->isAddSidewalkEnabled();
417 } else {
418 return false;
419 }
421 if (edgeTypeSelector->useDefaultEdgeTypeShort() || edgeTypeSelector->useDefaultEdgeType()) {
422 return edgeTypeSelector->isAddBikelaneEnabled();
423 } else {
424 return false;
425 }
426 default:
427 return true;
428 }
429}
430
431// ===========================================================================
432// private
433// ===========================================================================
434
435void
437 switch (key) {
438 case SUMO_ATTR_ID: {
439 // update comboBox
440 myNet->getViewParent()->getCreateEdgeFrame()->getEdgeTypeSelector()->updateIDinComboBox(getID(), value);
441 // update ID
442 myNet->getAttributeCarriers()->updateEdgeTypeID(this, value);
443 break;
444 }
445 case SUMO_ATTR_NUMLANES: {
446 const int numLanes = parse<int>(value);
447 // add new lanes
448 while (numLanes > (int)myLaneTypes.size()) {
449 myLaneTypes.push_back(new GNELaneType(this));
450 }
451 // remove extra lanes
452 while (numLanes < (int)myLaneTypes.size()) {
453 delete myLaneTypes.back();
454 myLaneTypes.pop_back();
455 }
456 break;
457 }
458 case SUMO_ATTR_SPEED:
459 if (value.empty()) {
460 attrs.erase(key);
461 } else {
462 attrs.insert(key);
464 }
465 break;
467 if (value.empty()) {
468 attrs.erase(key);
469 } else {
470 attrs.insert(key);
472 }
473 break;
474 case SUMO_ATTR_ALLOW:
475 // parse permissions
477 // check attrs
478 if ((permissions == SVCAll) || (permissions == -1)) {
479 attrs.insert(SUMO_ATTR_ALLOW);
481 } else if (permissions == 0) {
482 attrs.erase(SUMO_ATTR_ALLOW);
484 } else {
485 attrs.insert(SUMO_ATTR_ALLOW);
487 }
488 // also change it in all lanes
489 for (auto& laneType : myLaneTypes) {
490 laneType->setAttribute(SUMO_ATTR_ALLOW, value);
491 }
492 break;
494 // parse invert permissions
496 // check attrs
497 if ((permissions == SVCAll) || (permissions == -1)) {
498 attrs.insert(SUMO_ATTR_ALLOW);
500 } else if (permissions == 0) {
501 attrs.erase(SUMO_ATTR_ALLOW);
503 } else {
504 attrs.insert(SUMO_ATTR_ALLOW);
506 }
507 // also change it in all lanes
508 for (auto& laneType : myLaneTypes) {
509 laneType->setAttribute(SUMO_ATTR_DISALLOW, value);
510 }
511 break;
514 break;
516 if (value.empty()) {
517 attrs.erase(key);
518 } else {
519 attrs.insert(key);
521 }
522 break;
523 case SUMO_ATTR_WIDTH:
524 if (value.empty() || (value == "-1") || (value == "default")) {
525 attrs.erase(key);
526 } else {
527 attrs.insert(key);
529 }
530 break;
532 if (value.empty() || (value == "-1") || (value == "default")) {
533 attrs.erase(key);
534 } else {
535 attrs.insert(key);
537 }
538 break;
540 if (value.empty() || (value == "-1") || (value == "default")) {
541 attrs.erase(key);
542 } else {
543 attrs.insert(key);
545 }
546 break;
548 if (value.empty()) {
549 attrs.erase(key);
550 } else {
551 attrs.insert(key);
553 }
554 break;
555 default:
557 break;
558 }
559 // update edge selector
560 if (myNet->getViewNet() && myNet->getViewParent()->getCreateEdgeFrame()->shown()) {
561 myNet->getViewParent()->getCreateEdgeFrame()->getEdgeTypeAttributes()->refreshAttributesEditor();
562 myNet->getViewParent()->getCreateEdgeFrame()->getLaneTypeSelector()->refreshLaneTypeSelector();
563 }
564}
565
566/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:304
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_TYPE
type (edge)
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_DISALLOW
@ SUMO_ATTR_ALLOW
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_WIDTHRESOLUTION
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_MINWIDTH
@ SUMO_ATTR_ONEWAY
@ SUMO_ATTR_PRIORITY
@ SUMO_ATTR_NUMLANES
@ SUMO_ATTR_SPREADTYPE
The information about how to spread the lanes from the given position.
@ SUMO_ATTR_BIKELANEWIDTH
@ SUMO_ATTR_SIDEWALKWIDTH
@ SUMO_ATTR_ID
@ SUMO_ATTR_DISCARD
@ SUMO_ATTR_MAXWIDTH
@ SUMO_ATTR_WIDTH
@ SUMO_ATTR_FRICTION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:49
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
double getCommonAttributeDouble(SumoXMLAttr key) const
const std::string getID() const override
get ID (all Attribute Carriers have one)
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)
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
const std::vector< GNELaneTemplate * > & getLaneTemplates() const
get vector with the lane templates of this edge
std::string getAttribute(SumoXMLAttr key) const override
std::vector< GNELaneType * > myLaneTypes
vector with laneTypes
void updateGeometry() override
update pre-computed geometry information
Position getPositionInView() const
Returns position of hierarchical element in view.
int getLaneTypeIndex(const GNELaneType *laneType) const
get laneType index
bool checkDrawRelatedContour() const override
check if draw related contour (cyan)
std::string getAttribute(SumoXMLAttr key) const override
double getAttributeDouble(SumoXMLAttr key) const override
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
bool checkDrawDeleteContourSmall() const override
check if draw delete contour small (pink/white)
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
Parameterised * getParameters() override
get parameters associated with this edgeType
void removeLaneType(const int index)
remove laneType
void copyTemplate(const GNEEdgeTemplate *edgeTemplate)
copy edge template
bool checkDrawFromContour() const override
check if draw from contour (green)
bool isAttributeEnabled(SumoXMLAttr key) const override
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own popup-menu.
bool checkDrawOverContour() const override
check if draw over contour (orange)
bool checkDrawMoveContour() const override
check if draw move contour (red)
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
bool checkDrawDeleteContour() const override
check if draw delete contour (pink/white)
bool isValid(SumoXMLAttr key, const std::string &value) override
Boundary getCenteringBoundary() const override
Returns the boundary to which the view shall be centered in order to show the object.
const std::vector< GNELaneType * > & getLaneTypes() const
get laneTypes
void addLaneType(GNELaneType *laneType)
add laneType
bool checkDrawSelectContour() const override
check if draw select contour (blue)
void updateGLObject() override
update GLObject (geometry, ID, etc.)
GNEEdgeType(GNENet *net)
default constructor
~GNEEdgeType()
Destructor.
void deleteGLObject() override
delete element
Position getAttributePosition(SumoXMLAttr key) const override
bool checkDrawToContour() const override
check if draw from contour (magenta)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this edgeType
GNEContour myNetworkElementContour
network element contour
GNENetworkElement(GNENet *net, SumoXMLTag tag)
Constructor for templates.
The popup menu of a globject.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
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.
Parameterised()
Default constructor.
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
static StringBijection< LaneSpreadFunction > LaneSpreadFunctions
lane spread functions
static bool isValidNetID(const std::string &value)
whether the given string is a valid id for a network element
edgeType definition
Definition NBTypeCont.h:93
int priority
The priority of an edge.
Definition NBTypeCont.h:117
double width
The width of lanes of edges of this edgeType [m].
Definition NBTypeCont.h:132
double minWidth
The minimum width for lanes of this edgeType [m].
Definition NBTypeCont.h:141
double speed
The maximal velocity on an edge in m/s.
Definition NBTypeCont.h:111
LaneSpreadFunction spreadType
lane spread type
Definition NBTypeCont.h:123
SVCPermissions permissions
List of vehicle edgeTypes that are allowed on this edge.
Definition NBTypeCont.h:120
double maxWidth
The maximum width for lanes of this edgeType [m].
Definition NBTypeCont.h:138
double widthResolution
The resolution for interpreting custom (noisy) lane widths of this edgeType [m].
Definition NBTypeCont.h:135
bool oneWay
Whether one-way traffic is mostly common for this edgeType (mostly unused).
Definition NBTypeCont.h:126
std::set< SumoXMLAttr > attrs
The attributes which have been set.
Definition NBTypeCont.h:155
double friction
The default friction on an edge.
Definition NBTypeCont.h:114
std::map< SUMOVehicleClass, double > restrictions
The vehicle class specific speed restrictions.
Definition NBTypeCont.h:152
std::vector< LaneTypeDefinition > laneTypeDefinitions
vector with LaneTypeDefinitions
Definition NBTypeCont.h:158
bool discard
Whether edges of this edgeType shall be discarded.
Definition NBTypeCont.h:129