Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netimport/NIImporter_ITSUMO.h
169668 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 NIImporter_ITSUMO.h
15
/// @author Daniel Krajzewicz
16
/// @date 2011-09-16
17
///
18
// Importer for networks stored in ITSUMO format
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <string>
24
#include <map>
25
#include <netbuild/NBCapacity2Lanes.h>
26
#include <utils/xml/SUMOSAXHandler.h>
27
#include <utils/common/UtilExceptions.h>
28
29
30
// ===========================================================================
31
// class declarations
32
// ===========================================================================
33
class NBEdge;
34
class NBEdgeCont;
35
class NBNetBuilder;
36
class NBNode;
37
class NBNodeCont;
38
class NBTrafficLightLogicCont;
39
class NBTypeCont;
40
class OptionsCont;
41
42
43
// ===========================================================================
44
// class definitions
45
// ===========================================================================
46
/**
47
* @class NIImporter_ITSUMO
48
* @brief Importer for networks stored in ITSUMO format
49
*
50
*/
51
class NIImporter_ITSUMO {
52
public:
53
/** @brief Loads content of the optionally given ITSUMO network files
54
*
55
* If the option "itsumo-files" is set, the file(s) stored therein is read and
56
* the network definition stored therein is stored within the given network
57
* builder.
58
*
59
* If the option "itsumo-files" is not set, this method simply returns.
60
*
61
* @param[in] oc The options to use
62
* @param[in] nb The network builder to fill
63
*/
64
static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
65
66
67
private:
68
/**
69
* @class NodesHandler
70
* @brief A class which parses an ITSUMO file
71
*/
72
class Handler : public GenericSAXHandler {
73
public:
74
/** @brief Contructor
75
* @param[in] toFill The container to fill
76
*/
77
Handler(NBNetBuilder& toFill);
78
79
80
/// @brief Destructor
81
~Handler();
82
83
84
protected:
85
/// @name inherited from GenericSAXHandler
86
//@{
87
88
/** @brief Called on the opening of a tag;
89
*
90
* @param[in] element ID of the currently opened element
91
* @param[in] attrs Attributes within the currently opened element
92
* @exception ProcessError If something fails
93
* @see GenericSAXHandler::myStartElement
94
*/
95
void myStartElement(int element, const SUMOSAXAttributes& attrs);
96
97
98
/**
99
* @brief Callback method for characters to implement by derived classes
100
*
101
* Called by "endElement" (see there).
102
* @param[in] element The opened element, given as a int
103
* @param[in] chars The complete embedded character string
104
* @exceptions ProcessError These method may throw a ProcessError if something fails
105
*/
106
void myCharacters(int element, const std::string& chars);
107
108
109
/** @brief Callback method for a closing tag to implement by derived classes
110
*
111
* Called by "endElement" (see there).
112
* @param[in] element The closed element, given as a int
113
* @exceptions ProcessError These method may throw a ProcessError if something fails
114
*/
115
void myEndElement(int element);
116
//@}
117
118
119
private:
120
/// @brief The container to fill
121
NBNetBuilder& myNetBuilder;
122
123
/// @brief A temporary parameter map
124
Parameterised::Map myParameter;
125
126
127
struct Lane {
128
public:
129
Lane(const std::string& _id, int _idx, double _v)
130
: id(_id), index(_idx), v(_v) {}
131
std::string id;
132
int index;
133
double v;
134
};
135
136
std::vector<Lane> myCurrentLanes;
137
138
struct LaneSet {
139
public:
140
LaneSet(const std::string& _id, const std::vector<Lane>& _lanes, double _v, int _pos, NBNode* _from, NBNode* _to)
141
: id(_id), lanes(_lanes), v(_v), position(_pos), from(_from), to(_to) {}
142
std::string id;
143
std::vector<Lane> lanes;
144
double v;
145
int position;
146
NBNode* from;
147
NBNode* to;
148
};
149
150
std::map<std::string, LaneSet*> myLaneSets;
151
std::vector<LaneSet*> myCurrentLaneSets;
152
153
struct Section {
154
public:
155
Section(const std::string& _id, const std::vector<LaneSet*>& _laneSets)
156
: id(_id), laneSets(_laneSets) {}
157
std::string id;
158
std::vector<LaneSet*> laneSets;
159
};
160
161
std::vector<Section*> mySections;
162
163
164
private:
165
/** @brief invalidated copy constructor */
166
Handler(const Handler& s);
167
168
/** @brief invalidated assignment operator */
169
Handler& operator=(const Handler& s);
170
171
};
172
173
174
175
/**
176
* @enum ItsumoXMLTag
177
* @brief Numbers representing ITSUMO-XML - element names
178
* @see GenericSAXHandler
179
*/
180
enum ItsumoXMLTag {
181
ITSUMO_TAG_NOTHING = 0,
182
ITSUMO_TAG_SIMULATION,
183
ITSUMO_TAG_NETWORK_ID,
184
ITSUMO_TAG_NETWORK_NAME,
185
ITSUMO_TAG_NODES,
186
ITSUMO_TAG_NODE,
187
ITSUMO_TAG_NODE_ID,
188
ITSUMO_TAG_NODE_NAME,
189
ITSUMO_TAG_X_COORD,
190
ITSUMO_TAG_Y_COORD,
191
ITSUMO_TAG_SOURCES,
192
ITSUMO_TAG_SINKS,
193
ITSUMO_TAG_TRAFFIC_LIGHTS,
194
ITSUMO_TAG_STREETS,
195
ITSUMO_TAG_STREET,
196
ITSUMO_TAG_STREET_ID,
197
ITSUMO_TAG_STREET_NAME,
198
ITSUMO_TAG_SECTIONS,
199
ITSUMO_TAG_SECTION,
200
ITSUMO_TAG_SECTION_ID,
201
ITSUMO_TAG_SECTION_NAME,
202
ITSUMO_TAG_IS_PREFERENCIAL,
203
ITSUMO_TAG_DELIMITING_NODE,
204
ITSUMO_TAG_LANESETS,
205
ITSUMO_TAG_LANESET,
206
ITSUMO_TAG_LANESET_ID,
207
ITSUMO_TAG_LANESET_POSITION,
208
ITSUMO_TAG_START_NODE,
209
ITSUMO_TAG_END_NODE,
210
ITSUMO_TAG_TURNING_PROBABILITIES,
211
ITSUMO_TAG_DIRECTION,
212
ITSUMO_TAG_DESTINATION_LANESET,
213
ITSUMO_TAG_PROBABILITY,
214
ITSUMO_TAG_LANES,
215
ITSUMO_TAG_LANE,
216
ITSUMO_TAG_LANE_ID,
217
ITSUMO_TAG_LANE_POSITION,
218
ITSUMO_TAG_MAXIMUM_SPEED,
219
ITSUMO_TAG_DECELERATION_PROB
220
};
221
222
223
/**
224
* @enum ItsumoXMLAttr
225
* @brief Numbers representing MATSIM-XML - attributes
226
* @see GenericSAXHandler
227
*/
228
enum ItsumoXMLAttr {
229
ITSUMO_ATTR_NOTHING = 0
230
};
231
232
/// The names of MATSIM-XML elements (for passing to GenericSAXHandler)
233
static SequentialStringBijection::Entry itsumoTags[];
234
235
/// The names of MATSIM-XML attributes (for passing to GenericSAXHandler)
236
static SequentialStringBijection::Entry itsumoAttrs[];
237
238
239
};
240
241