Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netimport/NIXMLPTHandler.h
169666 views
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
/****************************************************************************/
14
/// @file NIXMLPTHandler.h
15
/// @author Jakob Erdmann
16
/// @date Sat, 28 Jul 2018
17
///
18
// Importer for static public transport information
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <utils/common/SUMOVehicleClass.h>
24
#include <utils/geom/PositionVector.h>
25
#include <utils/xml/SUMOSAXHandler.h>
26
#include <netbuild/NBEdge.h>
27
#include <netbuild/NBEdgeCont.h>
28
29
30
// ===========================================================================
31
// class declarations
32
// ===========================================================================
33
class OptionsCont;
34
class NBNode;
35
class NBEdge;
36
class NBNodeCont;
37
class NBTypeCont;
38
class NBDistrictCont;
39
class NBTrafficLightLogicCont;
40
41
// ===========================================================================
42
// class definitions
43
// ===========================================================================
44
/**
45
* @class NIXMLPTHandler
46
* @brief Importer for network edges stored in XML
47
*
48
* This SAX-handler parses edge information and stores it in the given
49
* container.
50
* @todo revalidate node retrieval
51
* @todo One day, one should rethink the order of parsing. Now, the handler
52
* is able to load edges, using information from the types, first, and extending
53
* them by given information. In addition, if the read edge is already known,
54
* its values are also used. Then, defining vehicles allowed per lane, and
55
* additional edge split definitions add some further complexity. This all
56
* works somehow for most of our use cases, but it's definitely not as consistent
57
* that everything what seems to be possible would also work appropriately.
58
*/
59
class NIXMLPTHandler : public SUMOSAXHandler {
60
public:
61
/** @brief Constructor
62
* @param[in] nc The nodes container (for retrieval of referenced nodes)
63
* @param[in] ec The edges container (for insertion of build edges)
64
* @param[in] tc The types container (for retrieval of type defaults)
65
* @param[in] dc The districts container (needed if an edge must be split)
66
* @param[in] options The options to use while building edges
67
*/
68
NIXMLPTHandler(NBEdgeCont& ec, NBPTStopCont& sc, NBPTLineCont& lc);
69
70
71
/// @brief Destructor
72
~NIXMLPTHandler();
73
74
protected:
75
/// @name inherited from GenericSAXHandler
76
//@{
77
78
/** @brief Called on the opening of a tag;
79
*
80
* @param[in] element ID of the currently opened element
81
* @param[in] attrs Attributes within the currently opened element
82
* @exception ProcessError If something fails
83
* @see GenericSAXHandler::myStartElement
84
*/
85
void myStartElement(int element,
86
const SUMOSAXAttributes& attrs);
87
88
89
/** @brief Called when a closing tag occurs
90
*
91
* @param[in] element ID of the currently opened element
92
* @exception ProcessError If something fails
93
* @see GenericSAXHandler::myEndElement
94
*/
95
void myEndElement(int element);
96
//@}
97
98
99
private:
100
/** @brief Tries to parse the shape definition
101
*
102
* Returns the edge's geometry (may be empty if no one was defined).
103
* Writes an error message if an error occurred.
104
* @param[in] attrs The attributes to read the shape from
105
* @return The edge's shape
106
*/
107
PositionVector tryGetShape(const SUMOSAXAttributes& attrs);
108
109
110
/** @brief Tries to parse the spread type
111
*/
112
LaneSpreadFunction tryGetLaneSpread(const SUMOSAXAttributes& attrs);
113
114
115
/** @brief Sets from/to node information of the currently parsed edge
116
*
117
* If the nodes could be retrieved/built, they are set in myFromNode/myToNode,
118
* respectively, and true is returned. If not, false is returned.
119
* @param[in] attrs The SAX-attributes to parse the nodes from
120
* @return Whether valid nodes exist
121
*/
122
bool setNodes(const SUMOSAXAttributes& attrs);
123
124
125
private:
126
127
/// @brief The edges container (for retrieving referenced stop edge)
128
NBEdgeCont& myEdgeCont;
129
130
/// @brief The stop container (for loading of stops)
131
NBPTStopCont& myStopCont;
132
133
/// @brief The line container (for loading of lines)
134
NBPTLineCont& myLineCont;
135
136
/// @brief The currently processed stop
137
std::shared_ptr<NBPTStop> myCurrentStop;
138
139
/// @brief The currently processed line
140
NBPTLine* myCurrentLine;
141
142
/// @brief The currently processed stand-alone route
143
std::string myCurrentRouteID;
144
145
/// @brief the completion level of the current line
146
double myCurrentCompletion;
147
148
/// @brief element to receive parameters
149
std::vector<Parameterised*> myLastParameterised;
150
151
/// @brief stand-alone route information
152
std::map<std::string, std::vector<std::shared_ptr<NBPTStop> > > myRouteStops;
153
std::map<std::string, EdgeVector > myRouteEdges;
154
155
/// @brief whether the current stop should be discarded
156
bool myCurrentStopWasIgnored;
157
158
int myMissingBefore;
159
int myMissingAfter;
160
161
private:
162
163
/** @brief Parses an public transport stop
164
* @param[in] attrs The attributes to get the stops's values from
165
*/
166
void addPTStop(const SUMOSAXAttributes& attrs);
167
168
/** @brief Parses a route as port of a public transport line
169
* @param[in] attrs The attributes to get the routes's values from
170
*/
171
void addPTLineRoute(const SUMOSAXAttributes& attrs);
172
173
/** @brief Parses a stand-alone route when parsing implicit ptlines from
174
* routes and flows
175
* @param[in] attrs The attributes to get the routes's values from
176
*/
177
void addRoute(const SUMOSAXAttributes& attrs);
178
179
/** @brief Parses an public transport stop reference within a line element
180
* @param[in] attrs The attributes to get the stops's values from
181
*/
182
void addPTLineStop(const SUMOSAXAttributes& attrs);
183
184
/** @brief Parses an public transport stop reference within a route element
185
* @param[in] attrs The attributes to get the stops's values from
186
*/
187
void addRouteStop(const SUMOSAXAttributes& attrs);
188
189
/** @brief Parses an stop access definition
190
* @param[in] attrs The attributes to get the access's values from
191
*/
192
void addAccess(const SUMOSAXAttributes& attrs);
193
194
/** @brief Parses a public transport line
195
* @param[in] attrs The attributes to get the lines's values from
196
*/
197
void addPTLine(const SUMOSAXAttributes& attrs);
198
199
/** @brief Parses a public transport line
200
* @param[in] attrs The attributes to get the lines's values from
201
*/
202
void addPTLineFromFlow(const SUMOSAXAttributes& attrs);
203
204
205
private:
206
/** @brief invalid copy constructor */
207
NIXMLPTHandler(const NIXMLPTHandler& s);
208
209
/** @brief invalid assignment operator */
210
NIXMLPTHandler& operator=(const NIXMLPTHandler& s);
211
212
};
213
214