Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NIXMLTypesHandler.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/****************************************************************************/
21// Importer for edge type information stored in XML
22/****************************************************************************/
23#include <config.h>
24
25#include <string>
26#include <iostream>
34#include <netbuild/NBEdge.h>
35#include <netbuild/NBTypeCont.h>
36#include "NIXMLTypesHandler.h"
37
38
39// ===========================================================================
40// method definitions
41// ===========================================================================
45
46
48
49
50void
52 switch (element) {
53 case SUMO_TAG_TYPE: {
54 bool ok = true;
55 // get the id, report a warning if not given or empty...
56 myCurrentTypeID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
57 const char* const id = myCurrentTypeID.c_str();
58 const std::string defType = myTypeCont.knows(myCurrentTypeID) ? myCurrentTypeID : "";
59 const int priority = attrs.getOpt<int>(SUMO_ATTR_PRIORITY, id, ok, myTypeCont.getEdgeTypePriority(defType));
60 const int numLanes = attrs.getOpt<int>(SUMO_ATTR_NUMLANES, id, ok, myTypeCont.getEdgeTypeNumLanes(defType));
61 const double speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, id, ok, myTypeCont.getEdgeTypeSpeed(defType));
62 const std::string allowS = attrs.getOpt<std::string>(SUMO_ATTR_ALLOW, id, ok, "");
63 const std::string disallowS = attrs.getOpt<std::string>(SUMO_ATTR_DISALLOW, id, ok, "");
64 const std::string spreadTypeS = attrs.getOpt<std::string>(SUMO_ATTR_SPREADTYPE, id, ok, OptionsCont::getOptions().getString("default.spreadtype"));
65 const bool oneway = attrs.getOpt<bool>(SUMO_ATTR_ONEWAY, id, ok, myTypeCont.getEdgeTypeIsOneWay(defType));
66 const bool discard = attrs.getOpt<bool>(SUMO_ATTR_DISCARD, id, ok, false);
67 const double width = attrs.getOpt<double>(SUMO_ATTR_WIDTH, id, ok, myTypeCont.getEdgeTypeWidth(defType));
68 const double maxWidth = attrs.getOpt<double>(SUMO_ATTR_MAXWIDTH, id, ok, myTypeCont.getEdgeTypeMaxWidth(defType));
69 const double minWidth = attrs.getOpt<double>(SUMO_ATTR_MINWIDTH, id, ok, myTypeCont.getEdgeTypeMinWidth(defType));
70 const double widthResolution = attrs.getOpt<double>(SUMO_ATTR_WIDTHRESOLUTION, id, ok, myTypeCont.getEdgeTypeWidthResolution(defType));
71 const double sidewalkWidth = attrs.getOpt<double>(SUMO_ATTR_SIDEWALKWIDTH, id, ok, myTypeCont.getEdgeTypeSidewalkWidth(defType));
72 const double bikeLaneWidth = attrs.getOpt<double>(SUMO_ATTR_BIKELANEWIDTH, id, ok, myTypeCont.getEdgeTypeBikeLaneWidth(defType));
73 // continue if parsing parameter was ok
74 if (ok) {
75 // build the type
76 SVCPermissions permissions = myTypeCont.getEdgeTypePermissions(defType);
77 if (allowS != "" || disallowS != "") {
78 permissions = parseVehicleClasses(allowS, disallowS);
79 }
80 // get spreadType
82 // check if spreadType is valid
83 if (SUMOXMLDefinitions::LaneSpreadFunctions.hasString(spreadTypeS)) {
84 spreadType = SUMOXMLDefinitions::LaneSpreadFunctions.get(spreadTypeS);
85 } else {
86 WRITE_ERRORF(TL("Invalid lane spread type '%'. Using default 'right'"), spreadTypeS);
87 }
88 // insert edgeType in container
89 myTypeCont.insertEdgeType(myCurrentTypeID, numLanes, speed, priority, permissions, spreadType, width,
90 oneway, sidewalkWidth, bikeLaneWidth, widthResolution, maxWidth, minWidth);
91 // check if mark edgeType as discard
92 if (discard) {
93 myTypeCont.markEdgeTypeAsToDiscard(myCurrentTypeID);
94 }
95 // mark attributes as set
99 };
100 for (const auto& attr : myAttrs) {
101 if (attrs.hasAttribute(attr)) {
102 myTypeCont.markEdgeTypeAsSet(myCurrentTypeID, attr);
103 }
104 }
105 }
106 break;
107 }
108 case SUMO_TAG_LANETYPE: {
109 bool ok = true;
110 // use id of last inserted edge
111 const char* const edgeTypeId = myCurrentTypeID.c_str();
112 const int index = attrs.get<int>(SUMO_ATTR_INDEX, edgeTypeId, ok);
113 const std::string defType = myTypeCont.knows(myCurrentTypeID) ? myCurrentTypeID : "";
114 if (index >= myTypeCont.getEdgeTypeNumLanes(defType)) {
115 WRITE_ERRORF(TL("Invalid lane index % for edge type '%' with % lanes"), toString(index), defType, toString(myTypeCont.getEdgeTypeNumLanes(defType)));
116 ok = false;
117 }
118 const double speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, edgeTypeId, ok, myTypeCont.getEdgeTypeSpeed(edgeTypeId));
119 const std::string allowS = attrs.getOpt<std::string>(SUMO_ATTR_ALLOW, edgeTypeId, ok, "");
120 const std::string disallowS = attrs.getOpt<std::string>(SUMO_ATTR_DISALLOW, edgeTypeId, ok, "");
121 const double width = attrs.getOpt<double>(SUMO_ATTR_WIDTH, edgeTypeId, ok, myTypeCont.getEdgeTypeWidth(defType));
122 // continue if parsing parameter was ok
123 if (ok) {
124 // build the type
125 SVCPermissions permissions = myTypeCont.getEdgeTypePermissions(defType);
126 if (allowS != "" || disallowS != "") {
127 permissions = parseVehicleClasses(allowS, disallowS);
128 }
129
130 // insert laneType in container
131 myTypeCont.insertLaneType(myCurrentTypeID, index, speed, permissions, width, {});
132 // mark attributes as set
134 for (const auto& attr : myAttrs) {
135 if (attrs.hasAttribute(attr)) {
136 myTypeCont.markLaneTypeAsSet(myCurrentTypeID, index, attr);
137 }
138 }
139 }
140 break;
141 }
143 bool ok = true;
144 const SUMOVehicleClass svc = getVehicleClassID(attrs.get<std::string>(SUMO_ATTR_VCLASS, myCurrentTypeID.c_str(), ok));
145 const double speed = attrs.get<double>(SUMO_ATTR_SPEED, myCurrentTypeID.c_str(), ok);
146 if (ok) {
147 myTypeCont.addEdgeTypeRestriction(myCurrentTypeID, svc, speed);
148 }
149 break;
150 }
151 default:
152 break;
153 }
154}
155
156
157/****************************************************************************/
#define WRITE_ERRORF(...)
Definition MsgHandler.h:296
#define TL(string)
Definition MsgHandler.h:304
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SUMO_TAG_RESTRICTION
begin/end of the description of an edge restriction
@ SUMO_TAG_LANETYPE
lane type
@ SUMO_TAG_TYPE
type (edge)
LaneSpreadFunction
Numbers representing special SUMO-XML-attribute values Information how the edge's lateral offset shal...
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_DISALLOW
@ SUMO_ATTR_ALLOW
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_WIDTHRESOLUTION
@ SUMO_ATTR_MINWIDTH
@ SUMO_ATTR_ONEWAY
@ SUMO_ATTR_PRIORITY
@ SUMO_ATTR_NUMLANES
@ SUMO_ATTR_INDEX
@ SUMO_ATTR_SPREADTYPE
The information about how to spread the lanes from the given position.
@ SUMO_ATTR_BIKELANEWIDTH
@ SUMO_ATTR_VCLASS
@ 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
A storage for available edgeTypes of edges.
Definition NBTypeCont.h:52
NIXMLTypesHandler(NBTypeCont &tc)
Constructor.
NBTypeCont & myTypeCont
The type container to fill.
~NIXMLTypesHandler()
Destructor.
std::string myCurrentTypeID
The currently parsed type.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag; Parses edge type information.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String).
static OptionsCont & getOptions()
Retrieves the options.
Encapsulated SAX-Attributes.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue=T(), bool report=true) const
Tries to read given attribute assuming it is an int.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
SUMOSAXHandler(const std::string &file="", const std::string &expectedRoot="")
Constructor.
static StringBijection< LaneSpreadFunction > LaneSpreadFunctions
lane spread functions