Eclipse SUMO - Simulation of Urban MObility
NIXMLTypesHandler.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-2020 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>
27 #include <xercesc/sax/HandlerBase.hpp>
28 #include <xercesc/sax/AttributeList.hpp>
29 #include <xercesc/sax/SAXParseException.hpp>
30 #include <xercesc/sax/SAXException.hpp>
35 #include <utils/common/ToString.h>
37 #include <netbuild/NBEdge.h>
38 #include <netbuild/NBTypeCont.h>
39 #include "NIXMLTypesHandler.h"
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
46  : SUMOSAXHandler("xml-types - file"),
47  myTypeCont(tc) {}
48 
49 
51 
52 
53 void
55  switch (element) {
56  case SUMO_TAG_TYPE: {
57  bool ok = true;
58  // get the id, report a warning if not given or empty...
59  myCurrentTypeID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
60  const char* const id = myCurrentTypeID.c_str();
61  const std::string defType = myTypeCont.knows(myCurrentTypeID) ? myCurrentTypeID : "";
62  const int priority = attrs.getOpt<int>(SUMO_ATTR_PRIORITY, id, ok, myTypeCont.getEdgeTypePriority(defType));
63  const int numLanes = attrs.getOpt<int>(SUMO_ATTR_NUMLANES, id, ok, myTypeCont.getEdgeTypeNumLanes(defType));
64  const double speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, id, ok, myTypeCont.getEdgeTypeSpeed(defType));
65  const std::string allowS = attrs.getOpt<std::string>(SUMO_ATTR_ALLOW, id, ok, "");
66  const std::string disallowS = attrs.getOpt<std::string>(SUMO_ATTR_DISALLOW, id, ok, "");
67  const bool oneway = attrs.getOpt<bool>(SUMO_ATTR_ONEWAY, id, ok, myTypeCont.getEdgeTypeIsOneWay(defType));
68  const bool discard = attrs.getOpt<bool>(SUMO_ATTR_DISCARD, id, ok, false);
69  const double width = attrs.getOpt<double>(SUMO_ATTR_WIDTH, id, ok, myTypeCont.getEdgeTypeWidth(defType));
70  const double maxWidth = attrs.getOpt<double>(SUMO_ATTR_MAXWIDTH, id, ok, myTypeCont.getEdgeTypeMaxWidth(defType));
71  const double minWidth = attrs.getOpt<double>(SUMO_ATTR_MINWIDTH, id, ok, myTypeCont.getEdgeTypeMinWidth(defType));
72  const double widthResolution = attrs.getOpt<double>(SUMO_ATTR_WIDTHRESOLUTION, id, ok, myTypeCont.getEdgeTypeWidthResolution(defType));
73  const double sidewalkWidth = attrs.getOpt<double>(SUMO_ATTR_SIDEWALKWIDTH, id, ok, myTypeCont.getEdgeTypeSidewalkWidth(defType));
74  const double bikeLaneWidth = attrs.getOpt<double>(SUMO_ATTR_BIKELANEWIDTH, id, ok, myTypeCont.getEdgeTypeBikeLaneWidth(defType));
75  // continue if parsing parameter was ok
76  if (ok) {
77  // build the type
78  SVCPermissions permissions = myTypeCont.getEdgeTypePermissions(defType);
79  if (allowS != "" || disallowS != "") {
80  permissions = parseVehicleClasses(allowS, disallowS);
81  }
82  // insert edgeType in container
83  myTypeCont.insertEdgeType(myCurrentTypeID, numLanes, speed, priority, permissions, width, oneway, sidewalkWidth, bikeLaneWidth, widthResolution, maxWidth, minWidth);
84  // check if mark edgeType as discard
85  if (discard) {
87  }
88  // mark attributes as set
92  };
93  for (const auto& attr : myAttrs) {
94  if (attrs.hasAttribute(attr)) {
96  }
97  }
98  }
99  break;
100  }
101  case SUMO_TAG_LANETYPE: {
102  bool ok = true;
103  // use id of last inserted edge
104  const char* const edgeTypeId = myCurrentTypeID.c_str();
105  const int index = attrs.get<int>(SUMO_ATTR_INDEX, edgeTypeId, ok);
106  const std::string defType = myTypeCont.knows(myCurrentTypeID) ? myCurrentTypeID : "";
107  if (index >= myTypeCont.getEdgeTypeNumLanes(defType)) {
108  WRITE_ERROR("Invalid lane index " + toString(index) + " for edge type '" + defType + "' with " + toString(myTypeCont.getEdgeTypeNumLanes(defType)) + " lanes");
109  ok = false;
110  }
111  const double speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, edgeTypeId, ok, myTypeCont.getEdgeTypeSpeed(edgeTypeId));
112  const std::string allowS = attrs.getOpt<std::string>(SUMO_ATTR_ALLOW, edgeTypeId, ok, "");
113  const std::string disallowS = attrs.getOpt<std::string>(SUMO_ATTR_DISALLOW, edgeTypeId, ok, "");
114  const double width = attrs.getOpt<double>(SUMO_ATTR_WIDTH, edgeTypeId, ok, myTypeCont.getEdgeTypeWidth(defType));
115  // continue if parsing parameter was ok
116  if (ok) {
117  // build the type
118  SVCPermissions permissions = myTypeCont.getEdgeTypePermissions(defType);
119  if (allowS != "" || disallowS != "") {
120  permissions = parseVehicleClasses(allowS, disallowS);
121  }
122 
123  // insert laneType in container
124  myTypeCont.insertLaneType(myCurrentTypeID, index, speed, permissions, width, {});
125  // mark attributes as set
127  for (const auto& attr : myAttrs) {
128  if (attrs.hasAttribute(attr)) {
130  }
131  }
132  }
133  break;
134  }
135  case SUMO_TAG_RESTRICTION: {
136  bool ok = true;
137  const SUMOVehicleClass svc = getVehicleClassID(attrs.get<std::string>(SUMO_ATTR_VCLASS, myCurrentTypeID.c_str(), ok));
138  const double speed = attrs.get<double>(SUMO_ATTR_SPEED, myCurrentTypeID.c_str(), ok);
139  if (ok) {
141  }
142  break;
143  }
144  default:
145  break;
146  }
147 }
148 
149 
150 /****************************************************************************/
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:284
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...
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ SUMO_TAG_RESTRICTION
begin/end of the description of an edge restriction
@ SUMO_TAG_LANETYPE
lane type
@ SUMO_TAG_TYPE
type (edge)
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_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:44
A storage for available edgeTypes of edges.
Definition: NBTypeCont.h:52
double getEdgeTypeMaxWidth(const std::string &edgeType) const
Returns the maximum edge/lane widths of the given edgeType.
Definition: NBTypeCont.cpp:479
bool markEdgeTypeAsSet(const std::string &id, const SumoXMLAttr attr)
Marks an attribute of a edgeType as set.
Definition: NBTypeCont.cpp:287
bool markEdgeTypeAsToDiscard(const std::string &id)
Marks a edgeType as to be discarded.
Definition: NBTypeCont.cpp:276
double getEdgeTypeMinWidth(const std::string &edgeType) const
Returns the minimum edge/lane widths of the given edgeType.
Definition: NBTypeCont.cpp:484
double getEdgeTypeSpeed(const std::string &edgeType) const
Returns the maximal velocity for the given edgeType [m/s].
Definition: NBTypeCont.cpp:451
int getEdgeTypePriority(const std::string &edgeType) const
Returns the priority for the given edgeType.
Definition: NBTypeCont.cpp:457
int getEdgeTypeNumLanes(const std::string &edgeType) const
Returns the number of lanes for the given edgeType.
Definition: NBTypeCont.cpp:445
double getEdgeTypeWidth(const std::string &edgeType) const
Returns the lane width for the given edgeType [m].
Definition: NBTypeCont.cpp:501
SVCPermissions getEdgeTypePermissions(const std::string &edgeType) const
Returns allowed vehicle classes for the given edgeType.
Definition: NBTypeCont.cpp:495
double getEdgeTypeWidthResolution(const std::string &edgeType) const
Returns the resolution for interpreting edge/lane widths of the given edgeType.
Definition: NBTypeCont.cpp:474
void insertEdgeType(const std::string &id, int numLanes, double maxSpeed, int prio, SVCPermissions permissions, double width, bool oneWayIsDefault, double sidewalkWidth, double bikeLaneWidth, double widthResolution, double maxWidth, double minWidth)
Adds a edgeType into the list.
Definition: NBTypeCont.cpp:173
bool knows(const std::string &edgeType) const
Returns whether the named edgeType is in the container.
Definition: NBTypeCont.cpp:270
bool addEdgeTypeRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction to a edgeType.
Definition: NBTypeCont.cpp:298
double getEdgeTypeSidewalkWidth(const std::string &edgeType) const
Returns the lane width for a sidewalk to be added [m].
Definition: NBTypeCont.cpp:507
double getEdgeTypeBikeLaneWidth(const std::string &edgeType) const
Returns the lane width for a bike lane to be added [m].
Definition: NBTypeCont.cpp:513
bool getEdgeTypeIsOneWay(const std::string &edgeType) const
Returns whether edges are one-way per default for the given edgeType.
Definition: NBTypeCont.cpp:463
bool markLaneTypeAsSet(const std::string &id, int index, const SumoXMLAttr attr)
Marks an attribute of last laneType as set.
Definition: NBTypeCont.cpp:322
void insertLaneType(const std::string &edgeTypeID, int index, double maxSpeed, SVCPermissions permissions, double width, const std::set< SumoXMLAttr > &attrs)
Adds a laneType into the list.
Definition: NBTypeCont.cpp:210
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.
Encapsulated SAX-Attributes.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, 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.
SAX-handler base for SUMO-files.