Eclipse SUMO - Simulation of Urban MObility
GNEEdgeType.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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_EDGE, 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_EDGE, 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("Invalid index");
156 }
157}
158
159
160void
162}
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
190double
192 return 1;
193}
194
195
196void
197GNEEdgeType::updateCenteringBoundary(const bool /*updateGrid*/) {
198 // nothing to do
199}
200
201
202void
204 // nothing to draw
205}
206
207
208void
211}
212
213
214void
217}
218
219
220std::string
222 // get options
224 switch (key) {
225 case SUMO_ATTR_ID:
226 return getMicrosimID();
228 return toString(myLaneTypes.size());
229 case SUMO_ATTR_SPEED:
230 if (attrs.count(key) == 0) {
231 return toString(oc.getFloat("default.speed"));
232 } else {
233 return toString(speed);
234 }
236 if (attrs.count(key) == 0) {
237 return toString(oc.getFloat("default.friction"));
238 } else {
239 return toString(friction);
240 }
241 case SUMO_ATTR_ALLOW:
242 if ((permissions == SVCAll) || (permissions == -1)) {
243 return "all";
244 } else if (permissions == 0) {
245 return "";
246 } else {
248 }
250 if (permissions == 0) {
251 return "all";
252 } else if ((permissions == SVCAll) || (permissions == -1)) {
253 return "";
254 } else {
256 }
259 case SUMO_ATTR_WIDTH:
260 if (attrs.count(key) == 0) {
262 } else {
263 return toString(width);
264 }
266 if (attrs.count(key) == 0) {
267 return toString(-1);
268 } else {
269 return toString(priority);
270 }
271 // non editable attributes
272 case SUMO_ATTR_ONEWAY:
273 return toString(oneWay);
275 return toString(discard);
279 return toString(maxWidth);
281 return toString(minWidth);
283 return toString(sidewalkWidth);
285 return toString(bikeLaneWidth);
286 // parameters
288 return getParametersStr();
289 default:
290 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
291 }
292}
293
294
295void
296GNEEdgeType::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/, GNEUndoList* /*undoList*/) {
297 throw InvalidArgument("EdgeType attributes cannot be edited here");
298}
299
300
301bool
302GNEEdgeType::isValid(SumoXMLAttr key, const std::string& value) {
303 switch (key) {
304 case SUMO_ATTR_ID:
305 return SUMOXMLDefinitions::isValidNetID(value) && (myNet->getAttributeCarriers()->retrieveEdgeType(value, false) == nullptr);
307 return canParse<int>(value) && (parse<double>(value) > 0);
308 case SUMO_ATTR_SPEED:
309 if (value.empty()) {
310 return true;
311 } else {
312 return canParse<double>(value) && (parse<double>(value) > 0);
313 }
314 case SUMO_ATTR_ALLOW:
316 if (value.empty()) {
317 return true;
318 } else {
319 return canParseVehicleClasses(value);
320 }
323 case SUMO_ATTR_WIDTH:
324 if (value.empty() || (value == "-1")) {
325 return true;
326 } else {
327 return canParse<double>(value);
328 }
330 return canParse<int>(value);
333 default:
334 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
335 }
336}
337
338
341 return getParametersMap();
342}
343
344// ===========================================================================
345// private
346// ===========================================================================
347
348void
349GNEEdgeType::setAttribute(SumoXMLAttr key, const std::string& value) {
350 switch (key) {
351 case SUMO_ATTR_ID: {
352 // update comboBox
354 // update ID
356 break;
357 }
358 case SUMO_ATTR_NUMLANES: {
359 const int numLanes = parse<int>(value);
360 // add new lanes
361 while (numLanes > (int)myLaneTypes.size()) {
362 myLaneTypes.push_back(new GNELaneType(this));
363 }
364 // remove extra lanes
365 while (numLanes < (int)myLaneTypes.size()) {
366 delete myLaneTypes.back();
367 myLaneTypes.pop_back();
368 }
369 break;
370 }
371 case SUMO_ATTR_SPEED:
372 if (value.empty()) {
373 attrs.erase(key);
374 } else {
375 attrs.insert(key);
376 speed = parse<double>(value);
377 }
378 break;
380 if (value.empty()) {
381 attrs.erase(key);
382 } else {
383 attrs.insert(key);
384 friction = parse<double>(value);
385 }
386 break;
387 case SUMO_ATTR_ALLOW:
388 // parse permissions
390 // check attrs
391 if ((permissions == SVCAll) || (permissions == -1)) {
392 attrs.insert(SUMO_ATTR_ALLOW);
394 } else if (permissions == 0) {
395 attrs.erase(SUMO_ATTR_ALLOW);
397 } else {
398 attrs.insert(SUMO_ATTR_ALLOW);
400 }
401 // also change it in all lanes
402 for (auto& laneType : myLaneTypes) {
403 laneType->setAttribute(SUMO_ATTR_ALLOW, value);
404 }
405 break;
407 // parse invert permissions
409 // check attrs
410 if ((permissions == SVCAll) || (permissions == -1)) {
411 attrs.insert(SUMO_ATTR_ALLOW);
413 } else if (permissions == 0) {
414 attrs.erase(SUMO_ATTR_ALLOW);
416 } else {
417 attrs.insert(SUMO_ATTR_ALLOW);
419 }
420 // also change it in all lanes
421 for (auto& laneType : myLaneTypes) {
422 laneType->setAttribute(SUMO_ATTR_DISALLOW, value);
423 }
424 break;
427 break;
429 if (value.empty()) {
430 attrs.erase(key);
431 } else {
432 attrs.insert(key);
433 discard = parse<bool>(value);
434 }
435 break;
436 case SUMO_ATTR_WIDTH:
437 if (value.empty()) {
438 attrs.erase(key);
439 } else {
440 attrs.insert(key);
441 width = parse<double>(value);
442 }
443 break;
445 if (value.empty()) {
446 attrs.erase(key);
447 } else {
448 attrs.insert(key);
449 priority = parse<int>(value);
450 }
451 break;
453 setParametersStr(value);
454 break;
455 default:
456 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
457 }
458 // update edge selector
459 if (myNet->getViewNet()->getViewParent()->getCreateEdgeFrame()->shown()) {
462 }
463}
464
465
466void
468 // nothing to do
469}
470
471
472void
473GNEEdgeType::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
474 // nothing to do
475}
476
477/****************************************************************************/
@ GLO_EDGE
an edge
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
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
Definition: GNEEdgeType.h:161
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
GNEEdgeType(GNECreateEdgeFrame *createEdgeFrame)
Constructor for default edge (empty ID)
Definition: GNEEdgeType.cpp:39
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
Definition: GNEEdgeType.cpp:92
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
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
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:334
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:132
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
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.
Definition: GUIGlObject.h:141
Stores the information about how to visualize structures.
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:357
A storage for options typed value containers)
Definition: OptionsCont.h:89
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:59
An upper class for objects with additional parameters.
Definition: Parameterised.h:41
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
Definition: Parameterised.h:45
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