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-2023 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>
25#include <netedit/GNEUndoList.h>
28
29#include "GNEEdgeType.h"
30#include "GNELaneType.h"
31#include "GNEEdgeTemplate.h"
32#include "GNELaneTemplate.h"
33
34
35// ===========================================================================
36// members methods
37// ===========================================================================
38
40 GNENetworkElement(createEdgeFrame->getViewNet()->getNet(), "", GLO_EDGETYPE, SUMO_TAG_TYPE,
41 GUIIconSubSys::getIcon(GUIIcon::EDGETYPE), {}, {}, {}, {}, {}, {}) {
42 // create laneType
43 myLaneTypes.push_back(new GNELaneType(this));
44}
45
46
48 GNENetworkElement(edgeType->getNet(), edgeType->getID(), GLO_EDGETYPE, SUMO_TAG_TYPE,
49 GUIIconSubSys::getIcon(GUIIcon::EDGETYPE), {}, {}, {}, {}, {}, {}),
50 Parameterised(edgeType->getParametersMap()),
52}
53
54
56 GNENetworkElement(net, net->getAttributeCarriers()->generateEdgeTypeID(), GLO_EDGE, SUMO_TAG_TYPE,
57 GUIIconSubSys::getIcon(GUIIcon::EDGETYPE), {}, {}, {}, {}, {}, {}) {
58 // create laneType
59 GNELaneType* laneType = new GNELaneType(this);
60 myLaneTypes.push_back(laneType);
61}
62
63
64GNEEdgeType::GNEEdgeType(GNENet* net, const std::string& ID, const NBTypeCont::EdgeTypeDefinition* edgeType) :
65 GNENetworkElement(net, ID, GLO_EDGE, SUMO_TAG_TYPE, GUIIconSubSys::getIcon(GUIIcon::EDGETYPE), {}, {}, {}, {}, {}, {}) {
66 // create laneTypes
67 for (const auto& laneTypeDef : edgeType->laneTypeDefinitions) {
68 GNELaneType* laneType = new GNELaneType(this, laneTypeDef);
69 myLaneTypes.push_back(laneType);
70 }
71 // copy parameters
72 speed = edgeType->speed;
73 friction = edgeType->friction;
74 priority = edgeType->priority;
75 permissions = edgeType->permissions;
76 spreadType = edgeType->spreadType;
77 oneWay = edgeType->oneWay;
78 discard = edgeType->discard;
79 width = edgeType->width;
80 widthResolution = edgeType->widthResolution;
81 maxWidth = edgeType->maxWidth;
82 minWidth = edgeType->minWidth;
83 sidewalkWidth = edgeType->sidewalkWidth;
84 bikeLaneWidth = edgeType->bikeLaneWidth;
85 restrictions = edgeType->restrictions;
86 attrs = edgeType->attrs;
87 laneTypeDefinitions = edgeType->laneTypeDefinitions;
88}
89
90
91void
93 // copy all edge attributes
99 if (canParse<double>(edgeTemplate->getAttribute(SUMO_ATTR_WIDTH))) {
101 }
104 // copy lane attributes
105 for (int i = 0; i < (int)edgeTemplate->getLaneTemplates().size(); i++) {
106 if (canParse<double>(edgeTemplate->getLaneTemplates().at(i)->getAttribute(SUMO_ATTR_SPEED))) {
107 myLaneTypes.at(i)->setAttribute(SUMO_ATTR_SPEED, edgeTemplate->getLaneTemplates().at(i)->getAttribute(SUMO_ATTR_SPEED));
108 }
109 myLaneTypes.at(i)->setAttribute(SUMO_ATTR_ALLOW, edgeTemplate->getLaneTemplates().at(i)->getAttribute(SUMO_ATTR_ALLOW));
110 myLaneTypes.at(i)->setAttribute(SUMO_ATTR_DISALLOW, edgeTemplate->getLaneTemplates().at(i)->getAttribute(SUMO_ATTR_DISALLOW));
111 if (canParse<double>(edgeTemplate->getLaneTemplates().at(i)->getAttribute(SUMO_ATTR_WIDTH))) {
112 myLaneTypes.at(i)->setAttribute(SUMO_ATTR_WIDTH, edgeTemplate->getLaneTemplates().at(i)->getAttribute(SUMO_ATTR_WIDTH));
113 }
114 myLaneTypes.at(i)->setAttribute(GNE_ATTR_PARAMETERS, edgeTemplate->getLaneTemplates().at(i)->getAttribute(GNE_ATTR_PARAMETERS));
115 }
116}
117
118
120 // delete laneTypes
121 for (const auto& laneType : myLaneTypes) {
122 delete laneType;
123 }
124}
125
126
127const std::vector<GNELaneType*>&
129 return myLaneTypes;
130}
131
132
133int
135 for (int i = 0; i < (int)myLaneTypes.size(); i++) {
136 if (myLaneTypes.at(i) == laneType) {
137 return i;
138 }
139 }
140 return (int)myLaneTypes.size();
141}
142
143
144void
146 myLaneTypes.push_back(laneType);
147}
148
149
150void
152 if (index < (int)myLaneTypes.size()) {
153 myLaneTypes.erase(myLaneTypes.begin() + index);
154 } else {
155 throw ProcessError(TL("Invalid index"));
156 }
157}
158
159
160void
163
164
167 // currently unused
168 return Position(0, 0);
169}
170
171
174 return nullptr;
175}
176
177
178void
179GNEEdgeType::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
180 // nothing to do
181}
182
183
186 return nullptr;
187}
188
189
190void
191GNEEdgeType::updateCenteringBoundary(const bool /*updateGrid*/) {
192 // nothing to do
193}
194
195
196void
198 // nothing to draw
199}
200
201
202void
206
207
208void
212
213
214std::string
216 // get options
217 const auto& neteditOptions = OptionsCont::getOptions();
218 switch (key) {
219 case SUMO_ATTR_ID:
220 return getMicrosimID();
222 return toString(myLaneTypes.size());
223 case SUMO_ATTR_SPEED:
224 if (attrs.count(key) == 0) {
225 return toString(neteditOptions.getFloat("default.speed"));
226 } else {
227 return toString(speed);
228 }
230 if (attrs.count(key) == 0) {
231 return toString(neteditOptions.getFloat("default.friction"));
232 } else {
233 return toString(friction);
234 }
235 case SUMO_ATTR_ALLOW:
236 if ((permissions == SVCAll) || (permissions == -1)) {
237 return "all";
238 } else if (permissions == 0) {
239 return "";
240 } else {
242 }
244 if (permissions == 0) {
245 return "all";
246 } else if ((permissions == SVCAll) || (permissions == -1)) {
247 return "";
248 } else {
250 }
253 case SUMO_ATTR_WIDTH:
254 if (attrs.count(key) == 0) {
256 } else {
257 return toString(width);
258 }
260 if (attrs.count(key) == 0) {
261 return toString(-1);
262 } else {
263 return toString(priority);
264 }
265 // non editable attributes
266 case SUMO_ATTR_ONEWAY:
267 return toString(oneWay);
269 return toString(discard);
273 return toString(maxWidth);
275 return toString(minWidth);
277 return toString(sidewalkWidth);
279 return toString(bikeLaneWidth);
280 // parameters
282 return getParametersStr();
283 default:
284 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
285 }
286}
287
288
289void
290GNEEdgeType::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/, GNEUndoList* /*undoList*/) {
291 throw InvalidArgument("EdgeType attributes cannot be edited here");
292}
293
294
295bool
296GNEEdgeType::isValid(SumoXMLAttr key, const std::string& value) {
297 switch (key) {
298 case SUMO_ATTR_ID:
299 return SUMOXMLDefinitions::isValidNetID(value) && (myNet->getAttributeCarriers()->retrieveEdgeType(value, false) == nullptr);
301 return canParse<int>(value) && (parse<double>(value) > 0);
302 case SUMO_ATTR_SPEED:
303 if (value.empty()) {
304 return true;
305 } else {
306 return canParse<double>(value) && (parse<double>(value) > 0);
307 }
308 case SUMO_ATTR_ALLOW:
310 if (value.empty()) {
311 return true;
312 } else {
313 return canParseVehicleClasses(value);
314 }
317 case SUMO_ATTR_WIDTH:
320 if (value.empty() || (value == "-1")) {
321 return true;
322 } else {
323 return canParse<double>(value);
324 }
326 return canParse<int>(value);
329 default:
330 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
331 }
332}
333
334
339
340// ===========================================================================
341// private
342// ===========================================================================
343
344void
345GNEEdgeType::setAttribute(SumoXMLAttr key, const std::string& value) {
346 switch (key) {
347 case SUMO_ATTR_ID: {
348 // update comboBox
350 // update ID
352 break;
353 }
354 case SUMO_ATTR_NUMLANES: {
355 const int numLanes = parse<int>(value);
356 // add new lanes
357 while (numLanes > (int)myLaneTypes.size()) {
358 myLaneTypes.push_back(new GNELaneType(this));
359 }
360 // remove extra lanes
361 while (numLanes < (int)myLaneTypes.size()) {
362 delete myLaneTypes.back();
363 myLaneTypes.pop_back();
364 }
365 break;
366 }
367 case SUMO_ATTR_SPEED:
368 if (value.empty()) {
369 attrs.erase(key);
370 } else {
371 attrs.insert(key);
372 speed = parse<double>(value);
373 }
374 break;
376 if (value.empty()) {
377 attrs.erase(key);
378 } else {
379 attrs.insert(key);
380 friction = parse<double>(value);
381 }
382 break;
383 case SUMO_ATTR_ALLOW:
384 // parse permissions
386 // check attrs
387 if ((permissions == SVCAll) || (permissions == -1)) {
388 attrs.insert(SUMO_ATTR_ALLOW);
390 } else if (permissions == 0) {
391 attrs.erase(SUMO_ATTR_ALLOW);
393 } else {
394 attrs.insert(SUMO_ATTR_ALLOW);
396 }
397 // also change it in all lanes
398 for (auto& laneType : myLaneTypes) {
399 laneType->setAttribute(SUMO_ATTR_ALLOW, value);
400 }
401 break;
403 // parse invert permissions
405 // check attrs
406 if ((permissions == SVCAll) || (permissions == -1)) {
407 attrs.insert(SUMO_ATTR_ALLOW);
409 } else if (permissions == 0) {
410 attrs.erase(SUMO_ATTR_ALLOW);
412 } else {
413 attrs.insert(SUMO_ATTR_ALLOW);
415 }
416 // also change it in all lanes
417 for (auto& laneType : myLaneTypes) {
418 laneType->setAttribute(SUMO_ATTR_DISALLOW, value);
419 }
420 break;
423 break;
425 if (value.empty()) {
426 attrs.erase(key);
427 } else {
428 attrs.insert(key);
429 discard = parse<bool>(value);
430 }
431 break;
432 case SUMO_ATTR_WIDTH:
433 if (value.empty()) {
434 attrs.erase(key);
435 } else {
436 attrs.insert(key);
437 width = parse<double>(value);
438 }
439 break;
441 if (value.empty()) {
442 attrs.erase(key);
443 } else {
444 attrs.insert(key);
445 sidewalkWidth = parse<double>(value);
446 }
447 break;
449 if (value.empty()) {
450 attrs.erase(key);
451 } else {
452 attrs.insert(key);
453 bikeLaneWidth = parse<double>(value);
454 }
455 break;
457 if (value.empty()) {
458 attrs.erase(key);
459 } else {
460 attrs.insert(key);
461 priority = parse<int>(value);
462 }
463 break;
465 setParametersStr(value);
466 break;
467 default:
468 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
469 }
470 // update edge selector
471 if (myNet->getViewNet()->getViewParent()->getCreateEdgeFrame()->shown()) {
474 }
475}
476
477
478void
480 // nothing to do
481}
482
483
484void
485GNEEdgeType::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
486 // nothing to do
487}
488
489/****************************************************************************/
@ GLO_EDGETYPE
an edgeType
@ GLO_EDGE
an edge
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
#define TL(string)
Definition MsgHandler.h:287
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
const std::string getID() const
get ID (all Attribute Carriers have one)
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
void refreshAttributesCreator()
refresh attribute creator
void updateIDinComboBox(const std::string &oldID, const std::string &newID)
update id in comboBox
void refreshLaneTypeSelector()
refresh LaneTypeSelector
EdgeTypeSelector * getEdgeTypeSelector() const
get edgeType selector
GNEAttributesCreator * 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
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)
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
GNEMoveOperation * getMoveOperation()
get move operation
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList)
remove geometry point in the clicked position
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
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
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:325
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:120
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2030
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.
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition NBEdge.h:341
static OptionsCont & getOptions()
Retrieves the options.
An upper class for objects with additional parameters.
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|....
std::map< std::string, std::string > Map
parameters map
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"
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
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".
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
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
bool hasString(const std::string &str) const
T get(const std::string &str) const
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
bool discard
Whether edges of this edgeType shall be discarded.
Definition NBTypeCont.h:129