Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netwrite/NWWriter_SUMO.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 NWWriter_SUMO.h
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @author Leonhard Luecken
19
/// @date Tue, 04.05.2011
20
///
21
// Exporter writing networks using the SUMO format
22
/****************************************************************************/
23
#pragma once
24
#include <config.h>
25
26
#include <string>
27
#include <map>
28
#include <netbuild/NBEdge.h>
29
#include <utils/xml/SUMOSAXHandler.h>
30
#include <utils/common/UtilExceptions.h>
31
#include <netbuild/NBConnectionDefs.h>
32
33
34
// ===========================================================================
35
// class declarations
36
// ===========================================================================
37
class OutputDevice;
38
class OptionsCont;
39
class NBNetBuilder;
40
class NBTrafficLightLogic;
41
class NBTrafficLightLogicCont;
42
class NBNode;
43
class NBDistrict;
44
class NBEdgeControl;
45
46
47
// ===========================================================================
48
// class definitions
49
// ===========================================================================
50
/**
51
* @class NWWriter_SUMO
52
* @brief Exporter writing networks using the SUMO format
53
*
54
*/
55
class NWWriter_SUMO {
56
public:
57
58
enum ConnectionStyle {
59
SUMONET, // all connection information
60
PLAIN, // only edges and link indices
61
TLL // like plain but include tl information
62
};
63
64
/** @brief Writes the network into a SUMO-file
65
*
66
* @param[in] oc The options to use
67
* @param[in] nb The network builder to fill
68
*/
69
static void writeNetwork(const OptionsCont& oc, NBNetBuilder& nb);
70
71
72
/** @brief Writes connections outgoing from the given edge (also used in NWWriter_XML)
73
* @param[in] into The device to write the edge into
74
* @param[in] from The edge to write connections for
75
* @param[in] c The connection to write
76
* @param[in] includeInternal Whether information about inner-lanes used to cross the intersection shall be written
77
* @param[in] plain Whether only plain-xml output should be written (omit some attributes)
78
*/
79
static void writeConnection(OutputDevice& into, const NBEdge& from, const NBEdge::Connection& c,
80
bool includeInternal, ConnectionStyle style = SUMONET, bool geoAccuracy = false);
81
82
/// @brief writes the given prohibitions
83
static void writeProhibitions(OutputDevice& into, const NBConnectionProhibits& prohibitions);
84
85
/// @brief writes the traffic light logics to the given device
86
static void writeTrafficLights(OutputDevice& into, const NBTrafficLightLogicCont& tllCont);
87
88
/// @brief writes a single traffic light logic to the given device
89
static void writeTrafficLight(OutputDevice& into, const NBTrafficLightLogic* logic);
90
91
/** @brief Writes roundabouts
92
* @param[in] into The device to write the edge into
93
* @param[in] roundaboutes The roundabouts to write
94
* @param[in] ec The edge control to retrieve named edges from
95
*/
96
static void writeRoundabouts(OutputDevice& into, const std::set<EdgeSet>& roundabouts,
97
const NBEdgeCont& ec);
98
99
/** @brief Write a stopOffset element into output device
100
*/
101
static void writeStopOffsets(OutputDevice& into, const StopOffset& stopOffset);
102
103
/** @brief Writes a district
104
* @param[in] into The device to write the edge into
105
* @param[in] d The district
106
*/
107
static void writeDistrict(OutputDevice& into, const NBDistrict& d);
108
109
110
private:
111
/// @name Methods for writing network parts
112
/// @{
113
114
/** @brief Writes internal edges (<edge ... with id[0]==':') of the given node
115
* @param[in] into The device to write the edges into
116
* @param[in] n The node to write the edges of
117
* @return Whether an internal edge was written
118
*/
119
static bool writeInternalEdges(OutputDevice& into, const NBEdgeCont& ec, const NBNode& n);
120
121
122
/// @brief retrieve bidi edge id for internal corresponding to the given connection
123
static std::string getInternalBidi(const NBEdge* e, const NBEdge::Connection& k, double& length);
124
125
126
/** @brief Writes an edge (<edge ...)
127
* @param[in] into The device to write the edge into
128
* @param[in] e The edge to write
129
* @param[in] noNames Whether names shall be ignored
130
* @see writeLane()
131
*/
132
static void writeEdge(OutputDevice& into, const NBEdge& e, bool noNames, LaneSpreadFunction defaultSpread);
133
134
135
/** @brief Writes a lane (<lane ...) of an edge
136
* @param[in] into The device to write the edge into
137
* @param[in] lID The ID of the lane
138
* @param[in] origID The original ID of the edge in the input
139
* @param[in] length Lane's length
140
* @param[in] index The index of the lane within the edge
141
* @param[in] oppositeID The ID of the opposite lane for overtaking
142
* @param[in] accelRamp whether this lane is an acceleration lane
143
* @param[in] customShape whether this lane has a custom shape
144
*/
145
static void writeLane(OutputDevice& into, const std::string& lID,
146
double speed, double friction,
147
SVCPermissions permissions, SVCPermissions preferred,
148
SVCPermissions changeLeft, SVCPermissions changeRight,
149
double startOffset, double endOffset,
150
const StopOffset& stopOffset, double width, PositionVector shape,
151
const Parameterised* params, double length, int index,
152
const std::string& oppositeID, const std::string& type,
153
bool accelRamp = false,
154
bool customShape = false,
155
const PositionVector& outlineShape = PositionVector());
156
157
158
/** @brief Writes a junction (<junction ...)
159
* @param[in] into The device to write the edge into
160
* @param[in] n The junction/node to write
161
*/
162
static void writeJunction(OutputDevice& into, const NBNode& n);
163
164
165
/** @brief Writes internal junctions (<junction with id[0]==':' ...) of the given node
166
* @param[in] into The device to write the edge into
167
* @param[in] n The junction/node to write internal nodes for
168
*/
169
static bool writeInternalNodes(OutputDevice& into, const NBNode& n);
170
171
172
/** @brief Writes inner connections within the node
173
* @param[in] into The device to write the edge into
174
* @param[in] n The node to write inner links for
175
*/
176
static bool writeInternalConnections(OutputDevice& into, const NBNode& n);
177
178
179
/** @brief Writes a single internal connection
180
* @param[in] from The id of the from-edge
181
* @param[in] to The id of the to-edge
182
* @param[in] toLane The indexd of the to-lane
183
* @param[in] via The (optional) via edge
184
*/
185
static void writeInternalConnection(OutputDevice& into,
186
const std::string& from, const std::string& to,
187
int fromLane, int toLane, const std::string& via,
188
LinkDirection dir = LinkDirection::STRAIGHT,
189
const std::string& tlID = "",
190
int linkIndex = NBConnection::InvalidTlIndex,
191
bool minor = false,
192
double visibility = NBEdge::UNSPECIFIED_VISIBILITY_DISTANCE);
193
194
/// @brief writes a SUMOTime as int if possible, otherwise as a float
195
static std::string writeSUMOTime(SUMOTime time);
196
197
/// @brief the attribute value for a prohibition
198
static std::string prohibitionConnection(const NBConnection& c);
199
200
/** @brief Writes a roundabout
201
* @param[in] into The device to write the edge into
202
* @param[in] r The roundabout to write
203
* @param[in] ec The edge control to retrieve named edges from
204
*/
205
static void writeRoundabout(OutputDevice& into, const std::vector<std::string>& r,
206
const NBEdgeCont& ec);
207
208
/// @brief retrieve the id of the opposite direction internal lane if it exists
209
static std::string getOppositeInternalID(const NBEdgeCont& ec, const NBEdge* from, const NBEdge::Connection& con, double& oppositeLength);
210
211
};
212
213