Eclipse SUMO - Simulation of Urban MObility
GNELaneType.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-2024 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>
27 
28 #include "GNELaneType.h"
29 #include "GNEEdgeType.h"
30 
31 
32 // ===========================================================================
33 // members methods
34 // ===========================================================================
35 
37  GNENetworkElement(edgeTypeParent->getNet(), "", GLO_LANETYPE, SUMO_TAG_LANETYPE, GUIIconSubSys::getIcon(GUIIcon::LANETYPE), {}, {}, {}, {}, {}, {}),
38 myEdgeTypeParent(edgeTypeParent) {
39 }
40 
41 
43  GNENetworkElement(edgeTypeParent->getNet(), "", GLO_LANETYPE, SUMO_TAG_LANETYPE, GUIIconSubSys::getIcon(GUIIcon::LANETYPE), {}, {}, {}, {}, {}, {}),
45 myEdgeTypeParent(edgeTypeParent) {
46 }
47 
48 
50 }
51 
52 
55  return myEdgeTypeParent;
56 }
57 
58 
59 void
60 GNELaneType::copyLaneType(GNELaneType* originalLaneType, GNEUndoList* undoList) {
61  // copy speed
62  setAttribute(SUMO_ATTR_SPEED, originalLaneType->getAttribute(SUMO_ATTR_SPEED), undoList);
63  // copy allow (and disallow)
64  setAttribute(SUMO_ATTR_ALLOW, originalLaneType->getAttribute(SUMO_ATTR_ALLOW), undoList);
65  // copy width
66  setAttribute(SUMO_ATTR_WIDTH, originalLaneType->getAttribute(SUMO_ATTR_WIDTH), undoList);
67  // copy parameters
69 }
70 
71 
72 void
74  // nothing to do
75 }
76 
77 
80  // currently unused
81  return Position(0, 0);
82 }
83 
84 
85 bool
87  return false;
88 }
89 
90 
91 bool
93  return false;
94 }
95 
96 
97 bool
99  return false;
100 }
101 
102 
103 bool
105  return false;
106 }
107 
108 bool
110  return false;
111 }
112 
113 
114 bool
116  return false;
117 }
118 
119 
120 bool
122  return false;
123 }
124 
125 
128  return nullptr;
129 }
130 
131 
132 void
133 GNELaneType::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
134  // nothing to do
135 }
136 
137 
140  return nullptr;
141 }
142 
143 
144 Boundary
147 }
148 
149 
150 void
151 GNELaneType::updateCenteringBoundary(const bool /*updateGrid*/) {
152  // nothing to do
153 }
154 
155 
156 void
158  // nothing to draw
159 }
160 
161 
162 void
165 }
166 
167 
168 void
170  updateGeometry();
171 }
172 
173 
174 std::string
176  switch (key) {
177  case SUMO_ATTR_ID:
178  return "lane: " + toString(myEdgeTypeParent->getLaneTypeIndex(this));
179  case SUMO_ATTR_SPEED:
180  if (attrs.count(key) == 0) {
181  return toString(OptionsCont::getOptions().getFloat("default.speed"));
182  } else {
183  return toString(speed);
184  }
185  case SUMO_ATTR_ALLOW:
186  if ((permissions == SVCAll) || (permissions == -1)) {
187  return "all";
188  } else if (permissions == 0) {
189  return "";
190  } else {
192  }
193  case SUMO_ATTR_DISALLOW:
194  if (permissions == 0) {
195  return "all";
196  } else if ((permissions == SVCAll) || (permissions == -1)) {
197  return "";
198  } else {
200  }
201  case SUMO_ATTR_WIDTH:
202  if (attrs.count(key) == 0) {
203  return "default";
204  } else {
205  return toString(width);
206  }
207  case SUMO_ATTR_FRICTION:
208  if (attrs.count(key) == 0) {
209  return "";
210  } else {
211  return toString(width);
212  }
213  case GNE_ATTR_PARAMETERS:
214  return getParametersStr();
215  default:
216  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
217  }
218 }
219 
220 
221 void
222 GNELaneType::setAttribute(SumoXMLAttr /*key*/, const std::string& /*value*/, GNEUndoList* /*undoList*/) {
223  throw InvalidArgument("laneType attributes cannot be edited here");
224 }
225 
226 
227 bool
228 GNELaneType::isValid(SumoXMLAttr key, const std::string& value) {
229  switch (key) {
230  case SUMO_ATTR_ID:
231  throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
232  case SUMO_ATTR_SPEED:
233  if (value.empty() || (value == "default")) {
234  return true;
235  } else {
236  return canParse<double>(value) && (parse<double>(value) > 0);
237  }
238  case SUMO_ATTR_ALLOW:
239  case SUMO_ATTR_DISALLOW:
240  return canParseVehicleClasses(value);
241  case SUMO_ATTR_WIDTH:
242  if (value.empty() || (value == "-1") || (value == "default")) {
243  return true;
244  } else {
245  return canParse<double>(value);
246  }
247  case GNE_ATTR_PARAMETERS:
248  return Parameterised::areParametersValid(value);
249  default:
250  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
251  }
252 }
253 
254 
255 const Parameterised::Map&
257  return getParametersMap();
258 }
259 
260 // ===========================================================================
261 // private
262 // ===========================================================================
263 
264 void
265 GNELaneType::setAttribute(SumoXMLAttr key, const std::string& value) {
266  switch (key) {
267  case SUMO_ATTR_ID:
268  throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
269  case SUMO_ATTR_SPEED:
270  if (value.empty() || (value == "default")) {
271  attrs.erase(key);
272  } else {
273  attrs.insert(key);
274  speed = parse<double>(value);
275  }
276  break;
277  case SUMO_ATTR_ALLOW:
278  // parse permissions
280  // check attrs
281  if ((permissions == SVCAll) || (permissions == -1)) {
282  attrs.insert(SUMO_ATTR_ALLOW);
283  attrs.erase(SUMO_ATTR_DISALLOW);
284  } else if (permissions == 0) {
285  attrs.erase(SUMO_ATTR_ALLOW);
286  attrs.insert(SUMO_ATTR_DISALLOW);
287  } else {
288  attrs.insert(SUMO_ATTR_ALLOW);
289  attrs.insert(SUMO_ATTR_DISALLOW);
290  }
291  break;
292  case SUMO_ATTR_DISALLOW:
293  // parse invert permissions
295  // check attrs
296  if ((permissions == SVCAll) || (permissions == -1)) {
297  attrs.insert(SUMO_ATTR_ALLOW);
298  attrs.erase(SUMO_ATTR_DISALLOW);
299  } else if (permissions == 0) {
300  attrs.erase(SUMO_ATTR_ALLOW);
301  attrs.insert(SUMO_ATTR_DISALLOW);
302  } else {
303  attrs.insert(SUMO_ATTR_ALLOW);
304  attrs.insert(SUMO_ATTR_DISALLOW);
305  }
306  break;
307  case SUMO_ATTR_WIDTH:
308  if (value.empty() || (value == "-1") || (value == "default")) {
309  attrs.erase(key);
310  } else {
311  attrs.insert(key);
312  width = parse<double>(value);
313  }
314  break;
315  case GNE_ATTR_PARAMETERS:
316  setParametersStr(value);
317  break;
318  default:
319  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
320  }
321  // update edge selector
322  if (myNet->getViewNet()->getViewParent()->getCreateEdgeFrame()->shown()) {
324  }
325 }
326 
327 
328 void
329 GNELaneType::setMoveShape(const GNEMoveResult& /*moveResult*/) {
330  // nothing to do
331 }
332 
333 
334 void
335 GNELaneType::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
336  // nothing to do
337 }
338 
339 /****************************************************************************/
@ GLO_LANETYPE
a laneType
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_LANETYPE
lane type
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_DISALLOW
@ SUMO_ATTR_ALLOW
@ SUMO_ATTR_SPEED
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_ID
@ 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 & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
void refreshAttributesCreator()
refresh attribute creator
Boundary getContourBoundary() const
get contour boundary
Definition: GNEContour.cpp:59
GNEAttributesCreator * getLaneTypeAttributes() const
get laneType attributes
int getLaneTypeIndex(const GNELaneType *laneType) const
get laneType index
bool checkDrawDeleteContour() const
check if draw delete contour (pink/white)
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList)
remove geometry point in the clicked position
GNEEdgeType * myEdgeTypeParent
pointer to EdgeTypeParent
Definition: GNELaneType.h:160
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
bool checkDrawOverContour() const
check if draw over contour (orange)
Position getPositionInView() const
Returns position of hierarchical element in view.
Definition: GNELaneType.cpp:79
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
void updateGeometry()
update pre-computed geometry information
Definition: GNELaneType.cpp:73
bool checkDrawMoveContour() const
check if draw move contour (red)
bool isValid(SumoXMLAttr key, const std::string &value)
bool checkDrawRelatedContour() const
check if draw related contour (cyan)
Definition: GNELaneType.cpp:98
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
std::string getAttribute(SumoXMLAttr key) const
void deleteGLObject()
delete element
const Parameterised::Map & getACParametersMap() const
get parameters map
GNELaneType(GNEEdgeType *edgeTypeParent)
Constructor.
Definition: GNELaneType.cpp:36
void copyLaneType(GNELaneType *originalLaneType, GNEUndoList *undoList)
copy values of given laneType in current laneType
Definition: GNELaneType.cpp:60
GNEMoveOperation * getMoveOperation()
get move operation
GNEEdgeType * getEdgeTypeParent() const
get edge type parent
Definition: GNELaneType.cpp:54
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
bool checkDrawSelectContour() const
check if draw select contour (blue)
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
~GNELaneType()
Destructor.
Definition: GNELaneType.cpp:49
bool checkDrawToContour() const
check if draw from contour (magenta)
Definition: GNELaneType.cpp:92
void updateGLObject()
update GLObject (geometry, ID, etc.)
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
bool checkDrawFromContour() const
check if draw from contour (green)
Definition: GNELaneType.cpp:86
move operation
move result
void deleteNetworkElement(GNENetworkElement *networkElement, GNEUndoList *undoList)
delete network element
Definition: GNENet.cpp:328
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2055
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.
Stores the information about how to visualize structures.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:60
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
laneType definition
Definition: NBTypeCont.h:59
double speed
The maximal velocity on a lane in m/s.
Definition: NBTypeCont.h:74
SVCPermissions permissions
List of vehicle edgeTypes that are allowed on this lane.
Definition: NBTypeCont.h:80
std::set< SumoXMLAttr > attrs
The attributes which have been set.
Definition: NBTypeCont.h:89
double width
lane width [m]
Definition: NBTypeCont.h:83