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
85void
87 // copy all edge attributes
98 // copy lane attributes
99 for (int i = 0; i < (int)edgeTemplate->getLaneTemplates().size(); i++) {
100 // get lane types
101 auto originalLaneType = edgeTemplate->getLaneTemplates().at(i);
102 auto laneType = myLaneTypes.at(i);
103 laneType->setAttribute(SUMO_ATTR_SPEED, originalLaneType->getAttribute(SUMO_ATTR_SPEED));
104 laneType->setAttribute(SUMO_ATTR_ALLOW, originalLaneType->getAttribute(SUMO_ATTR_ALLOW));
105 laneType->setAttribute(SUMO_ATTR_DISALLOW, originalLaneType->getAttribute(SUMO_ATTR_DISALLOW));
106 laneType->setAttribute(SUMO_ATTR_WIDTH, originalLaneType->getAttribute(SUMO_ATTR_WIDTH));
107 laneType->setAttribute(GNE_ATTR_PARAMETERS, originalLaneType->getAttribute(GNE_ATTR_PARAMETERS));
108 }
109}
110
111
113 // delete laneTypes
114 for (const auto& laneType : myLaneTypes) {
115 delete laneType;
116 }
117}
118
119
120const std::vector<GNELaneType*>&
122 return myLaneTypes;
123}
124
125
126int
128 for (int i = 0; i < (int)myLaneTypes.size(); i++) {
129 if (myLaneTypes.at(i) == laneType) {
130 return i;
131 }
132 }
133 return (int)myLaneTypes.size();
134}
135
136
137void
139 myLaneTypes.push_back(laneType);
140}
141
142
143void
145 if (index < (int)myLaneTypes.size()) {
146 myLaneTypes.erase(myLaneTypes.begin() + index);
147 } else {
148 throw ProcessError(TL("Invalid index"));
149 }
150}
151
152
153void
156
157
160 // currently unused
161 return Position(0, 0);
162}
163
164
165bool
167 return false;
168}
169
170
171bool
173 return false;
174}
175
176
177bool
179 return false;
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
215 return nullptr;
216}
217
218
219void
220GNEEdgeType::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
221 // nothing to do
222}
223
224
227 return nullptr;
228}
229
230
235
236
237void
238GNEEdgeType::updateCenteringBoundary(const bool /*updateGrid*/) {
239 // nothing to do
240}
241
242
243void
245 // nothing to draw
246}
247
248
249void
253
254
255void
259
260
261std::string
263 // get options
264 const auto& neteditOptions = OptionsCont::getOptions();
265 switch (key) {
266 case SUMO_ATTR_ID:
267 return getMicrosimID();
269 return toString(myLaneTypes.size());
270 case SUMO_ATTR_SPEED:
271 if (attrs.count(key) == 0) {
272 return toString(neteditOptions.getFloat("default.speed"));
273 } else {
274 return toString(speed);
275 }
277 if (attrs.count(key) == 0) {
278 return toString(neteditOptions.getFloat("default.friction"));
279 } else {
280 return toString(friction);
281 }
282 case SUMO_ATTR_ALLOW:
283 if ((permissions == SVCAll) || (permissions == -1)) {
284 return "all";
285 } else if (permissions == 0) {
286 return "";
287 } else {
289 }
291 if (permissions == 0) {
292 return "all";
293 } else if ((permissions == SVCAll) || (permissions == -1)) {
294 return "";
295 } else {
297 }
300 case SUMO_ATTR_WIDTH:
301 if (attrs.count(key) != 0) {
302 return toString(width);
303 } else {
304 return "default";
305 }
307 if (attrs.count(key) != 0) {
308 return toString(priority);
309 } else {
310 return toString(-1);
311 }
312 // non editable attributes
313 case SUMO_ATTR_ONEWAY:
314 return toString(oneWay);
316 return toString(discard);
320 return toString(maxWidth);
322 return toString(minWidth);
324 if (attrs.count(key) != 0) {
325 return toString(sidewalkWidth);
326 } else {
327 return "default";
328 }
330 if (attrs.count(key) != 0) {
331 return toString(bikeLaneWidth);
332 } else {
333 return "default";
334 }
335 default:
336 return getCommonAttribute(this, key);
337 }
338}
339
340
343 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
344}
345
346
347void
348GNEEdgeType::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/, GNEUndoList* /*undoList*/) {
349 throw InvalidArgument("EdgeType attributes cannot be edited here");
350}
351
352
353bool
354GNEEdgeType::isValid(SumoXMLAttr key, const std::string& value) {
355 switch (key) {
356 case SUMO_ATTR_ID:
357 return SUMOXMLDefinitions::isValidNetID(value) && (myNet->getAttributeCarriers()->retrieveEdgeType(value, false) == nullptr);
359 return canParse<int>(value) && (parse<double>(value) > 0);
360 case SUMO_ATTR_SPEED:
361 if (value.empty()) {
362 return true;
363 } else {
364 return canParse<double>(value) && (parse<double>(value) > 0);
365 }
366 case SUMO_ATTR_ALLOW:
368 if (value.empty()) {
369 return true;
370 } else {
371 return canParseVehicleClasses(value);
372 }
375 case SUMO_ATTR_WIDTH:
378 if (value.empty() || (value == "-1") || (value == "default")) {
379 return true;
380 } else {
381 return canParse<double>(value);
382 }
384 return canParse<int>(value);
385 default:
386 return isCommonValid(key, value);
387 }
388}
389
390
391bool
393 const auto edgeTypeSelector = myNet->getViewNet()->getViewParent()->getCreateEdgeFrame()->getEdgeTypeSelector();
394 switch (key) {
396 if (edgeTypeSelector->useDefaultEdgeTypeShort() || edgeTypeSelector->useDefaultEdgeType()) {
397 return edgeTypeSelector->isAddSidewalkEnabled();
398 } else {
399 return false;
400 }
402 if (edgeTypeSelector->useDefaultEdgeTypeShort() || edgeTypeSelector->useDefaultEdgeType()) {
403 return edgeTypeSelector->isAddBikelaneEnabled();
404 } else {
405 return false;
406 }
407 default:
408 return true;
409 }
410}
411
412
417
418// ===========================================================================
419// private
420// ===========================================================================
421
422void
423GNEEdgeType::setAttribute(SumoXMLAttr key, const std::string& value) {
424 switch (key) {
425 case SUMO_ATTR_ID: {
426 // update comboBox
428 // update ID
430 break;
431 }
432 case SUMO_ATTR_NUMLANES: {
433 const int numLanes = parse<int>(value);
434 // add new lanes
435 while (numLanes > (int)myLaneTypes.size()) {
436 myLaneTypes.push_back(new GNELaneType(this));
437 }
438 // remove extra lanes
439 while (numLanes < (int)myLaneTypes.size()) {
440 delete myLaneTypes.back();
441 myLaneTypes.pop_back();
442 }
443 break;
444 }
445 case SUMO_ATTR_SPEED:
446 if (value.empty()) {
447 attrs.erase(key);
448 } else {
449 attrs.insert(key);
450 speed = parse<double>(value);
451 }
452 break;
454 if (value.empty()) {
455 attrs.erase(key);
456 } else {
457 attrs.insert(key);
458 friction = parse<double>(value);
459 }
460 break;
461 case SUMO_ATTR_ALLOW:
462 // parse permissions
464 // check attrs
465 if ((permissions == SVCAll) || (permissions == -1)) {
466 attrs.insert(SUMO_ATTR_ALLOW);
468 } else if (permissions == 0) {
469 attrs.erase(SUMO_ATTR_ALLOW);
471 } else {
472 attrs.insert(SUMO_ATTR_ALLOW);
474 }
475 // also change it in all lanes
476 for (auto& laneType : myLaneTypes) {
477 laneType->setAttribute(SUMO_ATTR_ALLOW, value);
478 }
479 break;
481 // parse invert permissions
483 // check attrs
484 if ((permissions == SVCAll) || (permissions == -1)) {
485 attrs.insert(SUMO_ATTR_ALLOW);
487 } else if (permissions == 0) {
488 attrs.erase(SUMO_ATTR_ALLOW);
490 } else {
491 attrs.insert(SUMO_ATTR_ALLOW);
493 }
494 // also change it in all lanes
495 for (auto& laneType : myLaneTypes) {
496 laneType->setAttribute(SUMO_ATTR_DISALLOW, value);
497 }
498 break;
501 break;
503 if (value.empty()) {
504 attrs.erase(key);
505 } else {
506 attrs.insert(key);
507 discard = parse<bool>(value);
508 }
509 break;
510 case SUMO_ATTR_WIDTH:
511 if (value.empty() || (value == "-1") || (value == "default")) {
512 attrs.erase(key);
513 } else {
514 attrs.insert(key);
515 width = parse<double>(value);
516 }
517 break;
519 if (value.empty() || (value == "-1") || (value == "default")) {
520 attrs.erase(key);
521 } else {
522 attrs.insert(key);
523 sidewalkWidth = parse<double>(value);
524 }
525 break;
527 if (value.empty() || (value == "-1") || (value == "default")) {
528 attrs.erase(key);
529 } else {
530 attrs.insert(key);
531 bikeLaneWidth = parse<double>(value);
532 }
533 break;
535 if (value.empty()) {
536 attrs.erase(key);
537 } else {
538 attrs.insert(key);
539 priority = parse<int>(value);
540 }
541 break;
542 default:
543 setCommonAttribute(this, key, value);
544 break;
545 }
546 // update edge selector
547 if (myNet->getViewNet()->getViewParent()->getCreateEdgeFrame()->shown()) {
550 }
551}
552
553
554void
556 // nothing to do
557}
558
559
560void
561GNEEdgeType::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
562 // nothing to do
563}
564
565/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:305
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
const std::string getID() const
get ID (all Attribute Carriers have one)
std::string getCommonAttribute(const Parameterised *parameterised, 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
GNENet * myNet
pointer to net
bool isCommonValid(SumoXMLAttr key, const std::string &value) 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
std::string getAttribute(SumoXMLAttr key) const
const std::vector< GNELaneTemplate * > & getLaneTemplates() const
get vector with the lane templates of this edge
bool isAttributeEnabled(SumoXMLAttr key) const
std::vector< GNELaneType * > myLaneTypes
vector with laneTypes
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
GNEEdgeType(GNECreateEdgeFrame *createEdgeFrame)
Constructor for default edge (empty ID)
bool checkDrawFromContour() const
check if draw from contour (green)
bool checkDrawDeleteContour() const
check if draw delete contour (pink/white)
bool checkDrawMoveContour() const
check if draw move contour (red)
bool checkDrawRelatedContour() const
check if draw related contour (cyan)
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Position getPositionInView() const
Returns position of hierarchical element in view.
const Parameterised::Map & getACParametersMap() const
get parameters map
int getLaneTypeIndex(const GNELaneType *laneType) const
get laneType index
bool isValid(SumoXMLAttr key, const std::string &value)
void deleteGLObject()
delete element
PositionVector getAttributePositionVector(SumoXMLAttr key) const
bool checkDrawSelectContour() const
check if draw select contour (blue)
GNEMoveOperation * getMoveOperation()
get move operation
bool checkDrawToContour() const
check if draw from contour (magenta)
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList)
remove geometry point in the clicked position
bool checkDrawOverContour() const
check if draw over contour (orange)
bool checkDrawDeleteContourSmall() const
check if draw delete contour small (pink/white)
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void removeLaneType(const int index)
remove laneType
void copyTemplate(const GNEEdgeTemplate *edgeTemplate)
copy edge template
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
const std::vector< GNELaneType * > & getLaneTypes() const
get laneTypes
void addLaneType(GNELaneType *laneType)
add laneType
void updateGLObject()
update GLObject (geometry, ID, etc.)
~GNEEdgeType()
Destructor.
std::string getAttribute(SumoXMLAttr key) const
void updateGeometry()
update pre-computed geometry information
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
move operation
move result
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:373
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:147
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2195
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.
std::map< std::string, std::string > Map
parameters map
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
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