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    RONetHandler.h
11 /// @author  Daniel Krajzewicz
12 /// @author  Jakob Erdmann
13 /// @author  Michael Behrisch
14 /// @date    Sept 2002
15 /// @version $Id$
16 ///
17 // The handler that parses a SUMO-network for its usage in a router
18 /****************************************************************************/
19 #ifndef RONetHandler_h
20 #define RONetHandler_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <string>
29 #include <utils/xml/SUMOSAXHandler.h>
30 #include <utils/common/SUMOVehicleClass.h>
31 #include <utils/common/UtilExceptions.h>
32 
33 
34 // ===========================================================================
35 // class declarations
36 // ===========================================================================
37 class RONet;
38 class OptionsCont;
39 class ROEdge;
40 class ROAbstractEdgeBuilder;
41 
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
46 /**
47  * @class RONetHandler
48  * @brief The handler that parses a SUMO-network for its usage in a router
49  *
50  * SAX2-Handler for SUMO-network loading. As this class is used for both
51  *  the dua- and the jtrrouter, a reference to the edge builder is given.
52  */
53 class RONetHandler : public SUMOSAXHandler {
54 public:
55     /** @brief Constructor
56      *
57      * @param[in] net The network instance to fill
58      * @param[in] eb The abstract edge builder to use
59      */
60     RONetHandler(RONet& net, ROAbstractEdgeBuilder& eb, const bool ignoreInternal, const double minorPenalty);
61 
62 
63     /// @brief Destructor
64     virtual ~RONetHandler();
65 
66 
67 protected:
68     /// @name inherited from GenericSAXHandler
69     //@{
70 
71     /** @brief Called on the opening of a tag;
72      *
73      * @param[in] element ID of the currently opened element
74      * @param[in] attrs Attributes within the currently opened element
75      * @exception ProcessError If something fails
76      * @see GenericSAXHandler::myStartElement
77      */
78     virtual void myStartElement(int element, const SUMOSAXAttributes& attrs);
79 
80     /** @brief Called when a closing tag occurs
81      *
82      * @param[in] element ID of the currently opened element
83      * @exception ProcessError If something fails
84      * @see GenericSAXHandler::myEndElement
85      */
86     virtual void myEndElement(int element);
87     //@}
88 
89 protected:
90     /// @name called from myStartElement
91     //@{
92 
93     /** @brief Parses and builds an edge
94      *
95      * Parses attributes from an "edge"-element (id, from/to-nodes, function, etc.).
96      *  If the given nodes are not yet known, they are added to the network.
97      *  Uses the internal edge builder to build the edge and adds the edge
98      *  to the network.
99      *
100      * @param[in] attrs The attributes (of the "edge"-element) to parse
101      * @todo The edge is "built" first, then the nodes are added; should be done while constructing, probably a legacy issue
102      * @todo No exception?
103      */
104     void parseEdge(const SUMOSAXAttributes& attrs);
105 
106 
107     /** @brief Parses and builds a lane
108      *
109      * Parses attributes from an "lane"-element (speed, length, vehicle classes, etc.).
110      *  Builds a ROLane using these attributes (if they are valid) and adds it to the edge.
111      *
112      * @param[in] attrs The attributes (of the "lane"-element) to parse
113      * @todo No exception?
114      */
115     virtual void parseLane(const SUMOSAXAttributes& attrs);
116 
117 
118     /** @brief Parses a junction's position
119      *
120      * Parses the position of the junction. Sets it to the junction.
121      *
122      * @param[in] attrs The attributes (of the "lane"-element) to parse
123      * @todo In fact, the junction should be built given its position.
124      * @todo No exception?
125      */
126     void parseJunction(const SUMOSAXAttributes& attrs);
127 
128 
129     /** @begin Parses a connection
130      * Called on the occurence of a "connection" element
131      * @param[in] attrs The attributes (of the "connection"-element) to parse
132      */
133     void parseConnection(const SUMOSAXAttributes& attrs);
134 
135 
136     /** @begin Parses a stopping place
137      * Called on the occurence of a "busStop", "trainStop" or "containerStop" element
138      * @param[in] attrs The attributes to parse
139      * @param[in] element which kind of stop is to be parsed
140      */
141     void parseStoppingPlace(const SUMOSAXAttributes& attrs, const SumoXMLTag element);
142 
143 
144     /** @begin Parses an access point to a train stop
145      * Called on the occurence of an "access" element
146      * @param[in] attrs The attributes to parse
147      */
148     void parseAccess(const SUMOSAXAttributes& attrs);
149 
150 
151     /** @begin Parses a district and creates a pseudo edge for it
152      *
153      * Called on the occurence of a "district" element, this method
154      *  retrieves the id of the district and creates a district type
155      *  edge with this id.
156      *
157      * @param[in] attrs The attributes (of the "district"-element) to parse
158      * @exception ProcessError If an edge given in district@edges is not known
159      */
160     void parseDistrict(const SUMOSAXAttributes& attrs);
161 
162 
163     /** @begin Parses a district edge and connects it to the district
164      *
165      * Called on the occurence of a "dsource" or "dsink" element, this method
166      *  retrieves the id of the approachable edge. If this edge is known
167      *  and valid, the approaching edge is informed about it (by calling
168      *  "ROEdge::addFollower").
169      *
170      * @param[in] attrs The attributes to parse
171      * @param[in] isSource whether a "dsource or a "dsink" was given
172      * @todo No exception?
173      */
174     void parseDistrictEdge(const SUMOSAXAttributes& attrs, bool isSource);
175 
176     //@}
177 
178     /// Parses network location description
179     void setLocation(const SUMOSAXAttributes& attrs);
180 
181 protected:
182     /// @brief The net to store the information into
183     RONet& myNet;
184 
185     /// @brief The object used to build of edges of the desired type
186     ROAbstractEdgeBuilder& myEdgeBuilder;
187 
188     /// @brief whether to ignore junction internal edges
189     const bool myIgnoreInternal;
190 
191     /// @brief The name of the edge/node that is currently processed
192     std::string myCurrentName;
193 
194     /// The id of the currently processed edge type
195     std::string myCurrentTypeID;
196 
197     /// @brief The currently built edge
198     ROEdge* myCurrentEdge;
199 
200     /// @brief The currently built stopping place
201     SUMOVehicleParameter::Stop* myCurrentStoppingPlace;
202 
203     /// @brief temporary data for checking node initialisation after network parsing is finished
204     std::set<std::string> myUnseenNodeIDs;
205 
206     /// @brief time penalty for passing a minor link
207     const double myMinorPenalty;
208 
209 private:
210     /// @brief Invalidated copy constructor
211     RONetHandler(const RONetHandler& src);
212 
213     /// @brief Invalidated assignment operator
214     RONetHandler& operator=(const RONetHandler& src);
215 
216 };
217 
218 
219 #endif
220 
221 /****************************************************************************/
222 
223