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>
24 #include <netedit/GNEViewParent.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  // create laneType
42  myLaneTypes.push_back(new GNELaneType(this));
43 }
44 
45 
47  GNENetworkElement(edgeType->getNet(), edgeType->getID(), GLO_EDGE, SUMO_TAG_TYPE, {}, {}, {}, {}, {}, {}, {}, {}),
48  Parameterised(edgeType->getParametersMap()),
50 }
51 
52 
54  GNENetworkElement(net, net->getAttributeCarriers()->generateEdgeTypeID(), GLO_EDGE, SUMO_TAG_TYPE, {}, {}, {}, {}, {}, {}, {}, {}) {
55  // create laneType
56  GNELaneType* laneType = new GNELaneType(this);
57  myLaneTypes.push_back(laneType);
58 }
59 
60 
61 GNEEdgeType::GNEEdgeType(GNENet* net, const std::string& ID, const NBTypeCont::EdgeTypeDefinition* edgeType) :
62  GNENetworkElement(net, ID, GLO_EDGE, SUMO_TAG_TYPE, {}, {}, {}, {}, {}, {}, {}, {}) {
63  // create laneTypes
64  for (const auto& laneTypeDef : edgeType->laneTypeDefinitions) {
65  GNELaneType* laneType = new GNELaneType(this, laneTypeDef);
66  myLaneTypes.push_back(laneType);
67  }
68  // copy parameters
69  speed = edgeType->speed;
70  priority = edgeType->priority;
71  permissions = edgeType->permissions;
72  spreadType = edgeType->spreadType;
73  oneWay = edgeType->oneWay;
74  discard = edgeType->discard;
75  width = edgeType->width;
76  widthResolution = edgeType->widthResolution;
77  maxWidth = edgeType->maxWidth;
78  minWidth = edgeType->minWidth;
79  sidewalkWidth = edgeType->sidewalkWidth;
80  bikeLaneWidth = edgeType->bikeLaneWidth;
81  restrictions = edgeType->restrictions;
82  attrs = edgeType->attrs;
83  laneTypeDefinitions = edgeType->laneTypeDefinitions;
84 }
85 
86 
87 void
89  // copy all edge attributes
95  if (canParse<double>(edgeTemplate->getAttribute(SUMO_ATTR_WIDTH))) {
97  }
100  // copy lane attributes
101  for (int i = 0; i < (int)edgeTemplate->getLaneTemplates().size(); i++) {
102  if (canParse<double>(edgeTemplate->getLaneTemplates().at(i)->getAttribute(SUMO_ATTR_SPEED))) {
103  myLaneTypes.at(i)->setAttribute(SUMO_ATTR_SPEED, edgeTemplate->getLaneTemplates().at(i)->getAttribute(SUMO_ATTR_SPEED));
104  }
105  myLaneTypes.at(i)->setAttribute(SUMO_ATTR_ALLOW, edgeTemplate->getLaneTemplates().at(i)->getAttribute(SUMO_ATTR_ALLOW));
106  myLaneTypes.at(i)->setAttribute(SUMO_ATTR_DISALLOW, edgeTemplate->getLaneTemplates().at(i)->getAttribute(SUMO_ATTR_DISALLOW));
107  if (canParse<double>(edgeTemplate->getLaneTemplates().at(i)->getAttribute(SUMO_ATTR_WIDTH))) {
108  myLaneTypes.at(i)->setAttribute(SUMO_ATTR_WIDTH, edgeTemplate->getLaneTemplates().at(i)->getAttribute(SUMO_ATTR_WIDTH));
109  }
110  myLaneTypes.at(i)->setAttribute(GNE_ATTR_PARAMETERS, edgeTemplate->getLaneTemplates().at(i)->getAttribute(GNE_ATTR_PARAMETERS));
111  }
112 }
113 
114 
116  // delete laneTypes
117  for (const auto& laneType : myLaneTypes) {
118  delete laneType;
119  }
120 }
121 
122 
123 const std::vector<GNELaneType*>&
125  return myLaneTypes;
126 }
127 
128 
129 int
131  for (int i = 0; i < (int)myLaneTypes.size(); i++) {
132  if (myLaneTypes.at(i) == laneType) {
133  return i;
134  }
135  }
136  return (int)myLaneTypes.size();
137 }
138 
139 
140 void
142  myLaneTypes.push_back(laneType);
143 }
144 
145 
146 void
147 GNEEdgeType::removeLaneType(const int index) {
148  if (index < (int)myLaneTypes.size()) {
149  myLaneTypes.erase(myLaneTypes.begin() + index);
150  } else {
151  throw ProcessError("Invalid index");
152  }
153 }
154 
155 
156 void
158 }
159 
160 
161 Position
163  // currently unused
164  return Position(0, 0);
165 }
166 
167 
170  return nullptr;
171 }
172 
173 
174 void
175 GNEEdgeType::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
176  // nothing to do
177 }
178 
179 
182  return nullptr;
183 }
184 
185 
186 double
188  return 1;
189 }
190 
191 
192 void
193 GNEEdgeType::updateCenteringBoundary(const bool /*updateGrid*/) {
194  // nothing to do
195 }
196 
197 
198 void
200  // nothing to draw
201 }
202 
203 
204 std::string
206  // get options
207  const OptionsCont& oc = OptionsCont::getOptions();
208  switch (key) {
209  case SUMO_ATTR_ID:
210  return getID();
211  case SUMO_ATTR_NUMLANES:
212  return toString(myLaneTypes.size());
213  case SUMO_ATTR_SPEED:
214  if (attrs.count(key) == 0) {
215  return toString(oc.getFloat("default.speed"));
216  } else {
217  return toString(speed);
218  }
219  case SUMO_ATTR_ALLOW:
220  if ((permissions == SVCAll) || (permissions == -1)) {
221  return "all";
222  } else if (permissions == 0) {
223  return "";
224  } else {
226  }
227  case SUMO_ATTR_DISALLOW:
228  if (permissions == 0) {
229  return "all";
230  } else if ((permissions == SVCAll) || (permissions == -1)) {
231  return "";
232  } else {
234  }
237  case SUMO_ATTR_WIDTH:
238  if (attrs.count(key) == 0) {
240  } else {
241  return toString(width);
242  }
243  case SUMO_ATTR_PRIORITY:
244  if (attrs.count(key) == 0) {
245  return toString(-1);
246  } else {
247  return toString(priority);
248  }
249  // non editable attributes
250  case SUMO_ATTR_ONEWAY:
251  return toString(oneWay);
252  case SUMO_ATTR_DISCARD:
253  return toString(discard);
255  return toString(widthResolution);
256  case SUMO_ATTR_MAXWIDTH:
257  return toString(maxWidth);
258  case SUMO_ATTR_MINWIDTH:
259  return toString(minWidth);
261  return toString(sidewalkWidth);
263  return toString(bikeLaneWidth);
264  // parameters
265  case GNE_ATTR_PARAMETERS:
266  return getParametersStr();
267  default:
268  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
269  }
270 }
271 
272 
273 void
274 GNEEdgeType::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/, GNEUndoList* /*undoList*/) {
275  throw InvalidArgument("EdgeType attributes cannot be edited here");
276 }
277 
278 
279 bool
280 GNEEdgeType::isValid(SumoXMLAttr key, const std::string& value) {
281  switch (key) {
282  case SUMO_ATTR_ID:
283  return SUMOXMLDefinitions::isValidNetID(value) && (myNet->getAttributeCarriers()->retrieveEdgeType(value, false) == nullptr);
284  case SUMO_ATTR_NUMLANES:
285  return canParse<int>(value) && (parse<double>(value) > 0);
286  case SUMO_ATTR_SPEED:
287  if (value.empty()) {
288  return true;
289  } else {
290  return canParse<double>(value) && (parse<double>(value) > 0);
291  }
292  case SUMO_ATTR_ALLOW:
293  case SUMO_ATTR_DISALLOW:
294  if (value.empty()) {
295  return true;
296  } else {
297  return canParseVehicleClasses(value);
298  }
301  case SUMO_ATTR_WIDTH:
302  if (value.empty() || (value == "-1")) {
303  return true;
304  } else {
305  return canParse<double>(value);
306  }
307  case SUMO_ATTR_PRIORITY:
308  return canParse<int>(value);
309  case GNE_ATTR_PARAMETERS:
310  return Parameterised::areParametersValid(value);
311  default:
312  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
313  }
314 }
315 
316 
317 bool
319  return true;
320 }
321 
322 
323 bool
325  return false;
326 }
327 
328 
329 const std::map<std::string, std::string>&
331  return getParametersMap();
332 }
333 
334 // ===========================================================================
335 // private
336 // ===========================================================================
337 
338 void
339 GNEEdgeType::setAttribute(SumoXMLAttr key, const std::string& value) {
340  switch (key) {
341  case SUMO_ATTR_ID: {
342  // update comboBox
344  // update ID
346  break;
347  }
348  case SUMO_ATTR_NUMLANES: {
349  const int numLanes = parse<int>(value);
350  // add new lanes
351  while (numLanes > (int)myLaneTypes.size()) {
352  myLaneTypes.push_back(new GNELaneType(this));
353  }
354  // remove extra lanes
355  while (numLanes < (int)myLaneTypes.size()) {
356  delete myLaneTypes.back();
357  myLaneTypes.pop_back();
358  }
359  break;
360  }
361  case SUMO_ATTR_SPEED:
362  if (value.empty()) {
363  attrs.erase(key);
364  } else {
365  attrs.insert(key);
366  speed = parse<double>(value);
367  }
368  break;
369  case SUMO_ATTR_ALLOW:
370  // parse permissions
372  // check attrs
373  if ((permissions == SVCAll) || (permissions == -1)) {
374  attrs.insert(SUMO_ATTR_ALLOW);
375  attrs.erase(SUMO_ATTR_DISALLOW);
376  } else if (permissions == 0) {
377  attrs.erase(SUMO_ATTR_ALLOW);
378  attrs.insert(SUMO_ATTR_DISALLOW);
379  } else {
380  attrs.insert(SUMO_ATTR_ALLOW);
381  attrs.insert(SUMO_ATTR_DISALLOW);
382  }
383  break;
384  case SUMO_ATTR_DISALLOW:
385  // parse invert permissions
387  // check attrs
388  if ((permissions == SVCAll) || (permissions == -1)) {
389  attrs.insert(SUMO_ATTR_ALLOW);
390  attrs.erase(SUMO_ATTR_DISALLOW);
391  } else if (permissions == 0) {
392  attrs.erase(SUMO_ATTR_ALLOW);
393  attrs.insert(SUMO_ATTR_DISALLOW);
394  } else {
395  attrs.insert(SUMO_ATTR_ALLOW);
396  attrs.insert(SUMO_ATTR_DISALLOW);
397  }
398  break;
401  break;
402  case SUMO_ATTR_DISCARD:
403  if (value.empty()) {
404  attrs.erase(key);
405  } else {
406  attrs.insert(key);
407  discard = parse<bool>(value);
408  }
409  break;
410  case SUMO_ATTR_WIDTH:
411  if (value.empty()) {
412  attrs.erase(key);
413  } else {
414  attrs.insert(key);
415  width = parse<double>(value);
416  }
417  break;
418  case SUMO_ATTR_PRIORITY:
419  if (value.empty()) {
420  attrs.erase(key);
421  } else {
422  attrs.insert(key);
423  priority = parse<int>(value);
424  }
425  break;
426  case GNE_ATTR_PARAMETERS:
427  setParametersStr(value);
428  break;
429  default:
430  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
431  }
432  // update edge selector
433  if (myNet->getViewNet()->getViewParent()->getCreateEdgeFrame()->shown()) {
436  }
437 }
438 
439 
440 void
441 GNEEdgeType::setMoveShape(const GNEMoveResult& /*moveResult*/) {
442  // nothing to do
443 }
444 
445 
446 void
447 GNEEdgeType::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
448  // nothing to do
449 }
450 
451 /****************************************************************************/
@ GLO_EDGE
an edge
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
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
void updateIDinComboBox(const std::string &oldID, const std::string &newID)
update id in comboBox
void refreshLaneTypeSelector()
refresh LaneTypeSelector
EdgeTypeSelector * getEdgeTypeSelector() const
get edgeType selector
GNEFrameAttributeModules::AttributesCreator * 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
Definition: GNEEdgeType.h:165
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.
int getLaneTypeIndex(const GNELaneType *laneType) const
get laneType index
bool isValid(SumoXMLAttr key, const std::string &value)
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:88
const std::map< std::string, std::string > & getACParametersMap() const
get parameters map
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
bool isAttributeComputed(SumoXMLAttr key) const
const std::vector< GNELaneType * > & getLaneTypes() const
get laneTypes
void addLaneType(GNELaneType *laneType)
add laneType
~GNEEdgeType()
Destructor.
std::string getAttribute(SumoXMLAttr key) const
void updateGeometry()
update pre-computed geometry information
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration asociated with this GLObject
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void refreshAttributesCreator()
refresh attribute creator
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
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:125
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
const std::string & getID() const
get ID
GNEViewParent * getViewParent() const
get the net object
GNECreateEdgeFrame * getCreateEdgeFrame() const
get frame for NETWORK_CREATEEDGE
The popup menu of a globject.
Stores the information about how to visualize structures.
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:349
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:58
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|....
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"
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".
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
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
bool hasString(const std::string &str) const
const std::string & getString(const T key) const
T get(const std::string &str) const
edgeType definition
Definition: NBTypeCont.h:90
int priority
The priority of an edge.
Definition: NBTypeCont.h:111
double width
The width of lanes of edges of this edgeType [m].
Definition: NBTypeCont.h:126
double minWidth
The minimum width for lanes of this edgeType [m].
Definition: NBTypeCont.h:135
double speed
The maximal velocity on an edge in m/s.
Definition: NBTypeCont.h:108
LaneSpreadFunction spreadType
lane spread type
Definition: NBTypeCont.h:117
SVCPermissions permissions
List of vehicle edgeTypes that are allowed on this edge.
Definition: NBTypeCont.h:114
double maxWidth
The maximum width for lanes of this edgeType [m].
Definition: NBTypeCont.h:132
double widthResolution
The resolution for interpreting custom (noisy) lane widths of this edgeType [m].
Definition: NBTypeCont.h:129
bool oneWay
Whether one-way traffic is mostly common for this edgeType (mostly unused)
Definition: NBTypeCont.h:120
std::set< SumoXMLAttr > attrs
The attributes which have been set.
Definition: NBTypeCont.h:149
bool discard
Whether edges of this edgeType shall be discarded.
Definition: NBTypeCont.h:123