1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file NIXMLTypesHandler.cpp
11 /// @author Daniel Krajzewicz
12 /// @author Jakob Erdmann
13 /// @author Michael Behrisch
14 /// @author Walter Bamberger
15 /// @date Tue, 20 Nov 2001
16 /// @version $Id$
17 ///
18 // Importer for edge type information stored in XML
19 /****************************************************************************/
20
21
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26
27 #include <string>
28 #include <iostream>
29 #include <xercesc/sax/HandlerBase.hpp>
30 #include <xercesc/sax/AttributeList.hpp>
31 #include <xercesc/sax/SAXParseException.hpp>
32 #include <xercesc/sax/SAXException.hpp>
33 #include <utils/xml/SUMOSAXHandler.h>
34 #include <utils/xml/SUMOXMLDefinitions.h>
35 #include <utils/common/StringUtils.h>
36 #include <utils/common/MsgHandler.h>
37 #include <utils/common/ToString.h>
38 #include <utils/common/SUMOVehicleClass.h>
39 #include <netbuild/NBEdge.h>
40 #include <netbuild/NBTypeCont.h>
41 #include "NIXMLTypesHandler.h"
42
43
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
NIXMLTypesHandler(NBTypeCont & tc)47 NIXMLTypesHandler::NIXMLTypesHandler(NBTypeCont& tc)
48 : SUMOSAXHandler("xml-types - file"),
49 myTypeCont(tc) {}
50
51
~NIXMLTypesHandler()52 NIXMLTypesHandler::~NIXMLTypesHandler() {}
53
54
55 void
myStartElement(int element,const SUMOSAXAttributes & attrs)56 NIXMLTypesHandler::myStartElement(int element,
57 const SUMOSAXAttributes& attrs) {
58 switch (element) {
59 case SUMO_TAG_TYPE: {
60 bool ok = true;
61 // get the id, report a warning if not given or empty...
62 myCurrentTypeID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
63 const char* const id = myCurrentTypeID.c_str();
64 const std::string defType = myTypeCont.knows(myCurrentTypeID) ? myCurrentTypeID : "";
65 const int priority = attrs.getOpt<int>(SUMO_ATTR_PRIORITY, id, ok, myTypeCont.getPriority(defType));
66 const int numLanes = attrs.getOpt<int>(SUMO_ATTR_NUMLANES, id, ok, myTypeCont.getNumLanes(defType));
67 const double speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, id, ok, myTypeCont.getSpeed(defType));
68 const std::string allowS = attrs.getOpt<std::string>(SUMO_ATTR_ALLOW, id, ok, "");
69 const std::string disallowS = attrs.getOpt<std::string>(SUMO_ATTR_DISALLOW, id, ok, "");
70 const bool oneway = attrs.getOpt<bool>(SUMO_ATTR_ONEWAY, id, ok, myTypeCont.getIsOneWay(defType));
71 const bool discard = attrs.getOpt<bool>(SUMO_ATTR_DISCARD, id, ok, false);
72 const double width = attrs.getOpt<double>(SUMO_ATTR_WIDTH, id, ok, myTypeCont.getWidth(defType));
73 const double sidewalkWidth = attrs.getOpt<double>(SUMO_ATTR_SIDEWALKWIDTH, id, ok, myTypeCont.getSidewalkWidth(defType));
74 const double bikeLaneWidth = attrs.getOpt<double>(SUMO_ATTR_BIKELANEWIDTH, id, ok, myTypeCont.getBikeLaneWidth(defType));
75 if (!ok) {
76 return;
77 }
78 // build the type
79 SVCPermissions permissions = myTypeCont.getPermissions(defType);
80 if (allowS != "" || disallowS != "") {
81 permissions = parseVehicleClasses(allowS, disallowS);
82 }
83 myTypeCont.insert(myCurrentTypeID, numLanes, speed, priority, permissions, width, oneway, sidewalkWidth, bikeLaneWidth);
84 if (discard) {
85 myTypeCont.markAsToDiscard(myCurrentTypeID);
86 }
87 SumoXMLAttr myAttrs[] = {SUMO_ATTR_PRIORITY, SUMO_ATTR_NUMLANES, SUMO_ATTR_SPEED,
88 SUMO_ATTR_ALLOW, SUMO_ATTR_DISALLOW, SUMO_ATTR_ONEWAY,
89 SUMO_ATTR_DISCARD, SUMO_ATTR_WIDTH, SUMO_ATTR_SIDEWALKWIDTH, SUMO_ATTR_BIKELANEWIDTH
90 };
91 for (int i = 0; i < 10; i++) {
92 if (attrs.hasAttribute(myAttrs[i])) {
93 myTypeCont.markAsSet(myCurrentTypeID, myAttrs[i]);
94 }
95 }
96 break;
97 }
98 case SUMO_TAG_RESTRICTION: {
99 bool ok = true;
100 const SUMOVehicleClass svc = getVehicleClassID(attrs.get<std::string>(SUMO_ATTR_VCLASS, myCurrentTypeID.c_str(), ok));
101 const double speed = attrs.get<double>(SUMO_ATTR_SPEED, myCurrentTypeID.c_str(), ok);
102 if (ok) {
103 myTypeCont.addRestriction(myCurrentTypeID, svc, speed);
104 }
105 break;
106 }
107 default:
108 break;
109 }
110 }
111
112
113
114 /****************************************************************************/
115
116