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-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 "GNEEdgeType.h"
28#include "GNELaneType.h"
29#include "GNEEdgeTemplate.h"
30#include "GNELaneTemplate.h"
31
32// ===========================================================================
33// members methods
34// ===========================================================================
35
37 GNENetworkElement(createEdgeFrame->getViewNet()->getNet(), "", SUMO_TAG_TYPE) {
38 // create laneType
39 myLaneTypes.push_back(new GNELaneType(this));
40}
41
42
44 GNENetworkElement(edgeType->getNet(), edgeType->getID(), SUMO_TAG_TYPE),
45 Parameterised(edgeType->getParametersMap()),
46 NBTypeCont::EdgeTypeDefinition(edgeType) {
47}
48
49
51 GNENetworkElement(net, net->getAttributeCarriers()->generateEdgeTypeID(), SUMO_TAG_TYPE) {
52 // create laneType
53 GNELaneType* laneType = new GNELaneType(this);
54 myLaneTypes.push_back(laneType);
55}
56
57
58GNEEdgeType::GNEEdgeType(GNENet* net, const std::string& ID, const NBTypeCont::EdgeTypeDefinition* edgeType) :
60 // create laneTypes
61 for (const auto& laneTypeDef : edgeType->laneTypeDefinitions) {
62 GNELaneType* laneType = new GNELaneType(this, laneTypeDef);
63 myLaneTypes.push_back(laneType);
64 }
65 // copy parameters
66 speed = edgeType->speed;
67 friction = edgeType->friction;
68 priority = edgeType->priority;
69 permissions = edgeType->permissions;
70 spreadType = edgeType->spreadType;
71 oneWay = edgeType->oneWay;
72 discard = edgeType->discard;
73 width = edgeType->width;
75 maxWidth = edgeType->maxWidth;
76 minWidth = edgeType->minWidth;
77 sidewalkWidth = edgeType->sidewalkWidth;
78 bikeLaneWidth = edgeType->bikeLaneWidth;
79 restrictions = edgeType->restrictions;
80 attrs = edgeType->attrs;
82}
83
84
87 return nullptr;
88}
89
90
93 return this;
94}
95
96
97const Parameterised*
99 return this;
100}
101
102
103void
105 // copy all edge attributes
116 // copy lane attributes
117 for (int i = 0; i < (int)edgeTemplate->getLaneTemplates().size(); i++) {
118 // get lane types
119 auto originalLaneType = edgeTemplate->getLaneTemplates().at(i);
120 auto laneType = myLaneTypes.at(i);
121 laneType->setAttribute(SUMO_ATTR_SPEED, originalLaneType->getAttribute(SUMO_ATTR_SPEED));
122 laneType->setAttribute(SUMO_ATTR_ALLOW, originalLaneType->getAttribute(SUMO_ATTR_ALLOW));
123 laneType->setAttribute(SUMO_ATTR_DISALLOW, originalLaneType->getAttribute(SUMO_ATTR_DISALLOW));
124 laneType->setAttribute(SUMO_ATTR_WIDTH, originalLaneType->getAttribute(SUMO_ATTR_WIDTH));
125 laneType->setAttribute(GNE_ATTR_PARAMETERS, originalLaneType->getAttribute(GNE_ATTR_PARAMETERS));
126 }
127}
128
129
131 // delete laneTypes
132 for (const auto& laneType : myLaneTypes) {
133 delete laneType;
134 }
135}
136
137
138const std::vector<GNELaneType*>&
140 return myLaneTypes;
141}
142
143
144int
146 for (int i = 0; i < (int)myLaneTypes.size(); i++) {
147 if (myLaneTypes.at(i) == laneType) {
148 return i;
149 }
150 }
151 return (int)myLaneTypes.size();
152}
153
154
155void
157 myLaneTypes.push_back(laneType);
158}
159
160
161void
163 if (index < (int)myLaneTypes.size()) {
164 myLaneTypes.erase(myLaneTypes.begin() + index);
165 } else {
166 throw ProcessError(TL("Invalid index"));
167 }
168}
169
170
171void
174
175
178 // currently unused
179 return Position(0, 0);
180}
181
182
183bool
185 return false;
186}
187
188
189bool
191 return false;
192}
193
194
195bool
197 return false;
198}
199
200
201bool
203 return false;
204}
205
206
207bool
209 return false;
210}
211
212
213bool
215 return false;
216}
217
218
219bool
221 return false;
222}
223
224
225bool
227 return false;
228}
229
230
233 return nullptr;
234}
235
236
241
242
243void
244GNEEdgeType::updateCenteringBoundary(const bool /*updateGrid*/) {
245 // nothing to do
246}
247
248
249void
251 // nothing to draw
252}
253
254
255void
259
260
261void
265
266
267std::string
269 // get options
270 const auto& neteditOptions = OptionsCont::getOptions();
271 switch (key) {
272 case SUMO_ATTR_ID:
273 return getMicrosimID();
275 return toString(myLaneTypes.size());
276 case SUMO_ATTR_SPEED:
277 if (attrs.count(key) == 0) {
278 return toString(neteditOptions.getFloat("default.speed"));
279 } else {
280 return toString(speed);
281 }
283 if (attrs.count(key) == 0) {
284 return toString(neteditOptions.getFloat("default.friction"));
285 } else {
286 return toString(friction);
287 }
288 case SUMO_ATTR_ALLOW:
289 if ((permissions == SVCAll) || (permissions == -1)) {
290 return "all";
291 } else if (permissions == 0) {
292 return "";
293 } else {
295 }
297 if (permissions == 0) {
298 return "all";
299 } else if ((permissions == SVCAll) || (permissions == -1)) {
300 return "";
301 } else {
303 }
306 case SUMO_ATTR_WIDTH:
307 if (attrs.count(key) != 0) {
308 return toString(width);
309 } else {
310 return "default";
311 }
313 if (attrs.count(key) != 0) {
314 return toString(priority);
315 } else {
316 return toString(-1);
317 }
318 // non editable attributes
319 case SUMO_ATTR_ONEWAY:
320 return toString(oneWay);
322 return toString(discard);
326 return toString(maxWidth);
328 return toString(minWidth);
330 if (attrs.count(key) != 0) {
331 return toString(sidewalkWidth);
332 } else {
333 return "default";
334 }
336 if (attrs.count(key) != 0) {
337 return toString(bikeLaneWidth);
338 } else {
339 return "default";
340 }
341 default:
342 return getCommonAttribute(key);
343 }
344}
345
346
347double
351
352
357
358
363
364
365void
366GNEEdgeType::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/, GNEUndoList* /*undoList*/) {
367 throw InvalidArgument("EdgeType attributes cannot be edited here");
368}
369
370
371bool
372GNEEdgeType::isValid(SumoXMLAttr key, const std::string& value) {
373 switch (key) {
374 case SUMO_ATTR_ID:
375 return SUMOXMLDefinitions::isValidNetID(value) && (myNet->getAttributeCarriers()->retrieveEdgeType(value, false) == nullptr);
377 return canParse<int>(value) && (parse<double>(value) > 0);
378 case SUMO_ATTR_SPEED:
379 if (value.empty()) {
380 return true;
381 } else {
382 return canParse<double>(value) && (parse<double>(value) > 0);
383 }
384 case SUMO_ATTR_ALLOW:
386 if (value.empty()) {
387 return true;
388 } else {
389 return canParseVehicleClasses(value);
390 }
393 case SUMO_ATTR_WIDTH:
396 if (value.empty() || (value == "-1") || (value == "default")) {
397 return true;
398 } else {
399 return canParse<double>(value);
400 }
402 return canParse<int>(value);
403 default:
404 return isCommonAttributeValid(key, value);
405 }
406}
407
408
409bool
411 const auto edgeTypeSelector = myNet->getViewNet()->getViewParent()->getCreateEdgeFrame()->getEdgeTypeSelector();
412 switch (key) {
414 if (edgeTypeSelector->useDefaultEdgeTypeShort() || edgeTypeSelector->useDefaultEdgeType()) {
415 return edgeTypeSelector->isAddSidewalkEnabled();
416 } else {
417 return false;
418 }
420 if (edgeTypeSelector->useDefaultEdgeTypeShort() || edgeTypeSelector->useDefaultEdgeType()) {
421 return edgeTypeSelector->isAddBikelaneEnabled();
422 } else {
423 return false;
424 }
425 default:
426 return true;
427 }
428}
429
430// ===========================================================================
431// private
432// ===========================================================================
433
434void
435GNEEdgeType::setAttribute(SumoXMLAttr key, const std::string& value) {
436 switch (key) {
437 case SUMO_ATTR_ID: {
438 // update comboBox
440 // update ID
442 break;
443 }
444 case SUMO_ATTR_NUMLANES: {
445 const int numLanes = parse<int>(value);
446 // add new lanes
447 while (numLanes > (int)myLaneTypes.size()) {
448 myLaneTypes.push_back(new GNELaneType(this));
449 }
450 // remove extra lanes
451 while (numLanes < (int)myLaneTypes.size()) {
452 delete myLaneTypes.back();
453 myLaneTypes.pop_back();
454 }
455 break;
456 }
457 case SUMO_ATTR_SPEED:
458 if (value.empty()) {
459 attrs.erase(key);
460 } else {
461 attrs.insert(key);
462 speed = parse<double>(value);
463 }
464 break;
466 if (value.empty()) {
467 attrs.erase(key);
468 } else {
469 attrs.insert(key);
470 friction = parse<double>(value);
471 }
472 break;
473 case SUMO_ATTR_ALLOW:
474 // parse permissions
476 // check attrs
477 if ((permissions == SVCAll) || (permissions == -1)) {
478 attrs.insert(SUMO_ATTR_ALLOW);
480 } else if (permissions == 0) {
481 attrs.erase(SUMO_ATTR_ALLOW);
483 } else {
484 attrs.insert(SUMO_ATTR_ALLOW);
486 }
487 // also change it in all lanes
488 for (auto& laneType : myLaneTypes) {
489 laneType->setAttribute(SUMO_ATTR_ALLOW, value);
490 }
491 break;
493 // parse invert permissions
495 // check attrs
496 if ((permissions == SVCAll) || (permissions == -1)) {
497 attrs.insert(SUMO_ATTR_ALLOW);
499 } else if (permissions == 0) {
500 attrs.erase(SUMO_ATTR_ALLOW);
502 } else {
503 attrs.insert(SUMO_ATTR_ALLOW);
505 }
506 // also change it in all lanes
507 for (auto& laneType : myLaneTypes) {
508 laneType->setAttribute(SUMO_ATTR_DISALLOW, value);
509 }
510 break;
513 break;
515 if (value.empty()) {
516 attrs.erase(key);
517 } else {
518 attrs.insert(key);
519 discard = parse<bool>(value);
520 }
521 break;
522 case SUMO_ATTR_WIDTH:
523 if (value.empty() || (value == "-1") || (value == "default")) {
524 attrs.erase(key);
525 } else {
526 attrs.insert(key);
527 width = parse<double>(value);
528 }
529 break;
531 if (value.empty() || (value == "-1") || (value == "default")) {
532 attrs.erase(key);
533 } else {
534 attrs.insert(key);
535 sidewalkWidth = parse<double>(value);
536 }
537 break;
539 if (value.empty() || (value == "-1") || (value == "default")) {
540 attrs.erase(key);
541 } else {
542 attrs.insert(key);
543 bikeLaneWidth = parse<double>(value);
544 }
545 break;
547 if (value.empty()) {
548 attrs.erase(key);
549 } else {
550 attrs.insert(key);
551 priority = parse<int>(value);
552 }
553 break;
554 default:
555 setCommonAttribute(key, value);
556 break;
557 }
558 // update edge selector
559 if (myNet->getViewNet()->getViewParent()->getCreateEdgeFrame()->shown()) {
562 }
563}
564
565/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:304
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:46
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)
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
Position getCommonAttributePosition(SumoXMLAttr key) const
GNENet * myNet
pointer to net
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
std::string getCommonAttribute(SumoXMLAttr key) const
void refreshAttributesEditor()
refresh attribute editor
Boundary getContourBoundary() const
get contour boundary
void updateIDinComboBox(const std::string &oldID, const std::string &newID)
update id in comboBox
bool isAddSidewalkEnabled() const
check if add sidewalk check button is enabled
void refreshLaneTypeSelector()
refresh LaneTypeSelector
EdgeTypeSelector * getEdgeTypeSelector() const
get edgeType selector
GNEAttributesEditor * getEdgeTypeAttributes() const
get edgeType attributes
LaneTypeSelector * getLaneTypeSelector()
get lane type selector
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
GNEEdgeType(GNECreateEdgeFrame *createEdgeFrame)
Constructor for default edge (empty ID)
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()
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
GNEEdgeType * retrieveEdgeType(const std::string &id, bool hardFail=true) const
get edge type by id
void updateEdgeTypeID(GNEEdgeType *edgeType, const std::string &newID)
update edgeType ID in container
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
void deleteNetworkElement(GNENetworkElement *networkElement, GNEUndoList *undoList)
delete network element
Definition GNENet.cpp:370
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:144
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
GNEContour myNetworkElementContour
network element contour
GNEViewParent * getViewParent() const
get the net object
GNEUndoList * getUndoList() const
get the undoList object
GNECreateEdgeFrame * getCreateEdgeFrame() const
get frame for NETWORK_CREATEEDGE
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.
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
const std::string & getString(const T key) const
get string
bool hasString(const std::string &str) const
check if the given string exist
T get(const std::string &str) const
get key
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