Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NWFrame.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2023 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/****************************************************************************/
20// Sets and checks options for netwrite
21/****************************************************************************/
22#include <config.h>
23
24#include <string>
32#include "NWFrame.h"
33#include "NWWriter_SUMO.h"
34#include "NWWriter_Amitran.h"
35#include "NWWriter_MATSim.h"
36#include "NWWriter_XML.h"
37#include "NWWriter_OpenDrive.h"
38#include "NWWriter_DlrNavteq.h"
39
40// ===========================================================================
41// static members
42// ===========================================================================
43
44// ===========================================================================
45// method definitions
46// ===========================================================================
47
48void
49NWFrame::fillOptions(OptionsCont& oc, bool forNetgen) {
50 // register options
51 oc.doRegister("output-file", 'o', new Option_FileName());
52 oc.addSynonyme("output-file", "sumo-output");
53 oc.addSynonyme("output-file", "output");
54 oc.addDescription("output-file", "Output", TL("The generated net will be written to FILE"));
55
56 oc.doRegister("plain-output-prefix", 'p', new Option_FileName());
57 oc.addSynonyme("plain-output-prefix", "plain-output");
58 oc.addSynonyme("plain-output-prefix", "plain");
59 oc.addDescription("plain-output-prefix", "Output", TL("Prefix of files to write plain xml nodes, edges and connections to"));
60
61 oc.doRegister("plain-output.lanes", new Option_Bool(false));
62 oc.addDescription("plain-output.lanes", "Output", TL("Write all lanes and their attributes even when they are not customized"));
63
64 oc.doRegister("junctions.join-output", new Option_FileName());
65 oc.addDescription("junctions.join-output", "Output",
66 "Writes information about joined junctions to FILE (can be loaded as additional node-file to reproduce joins");
67
68 oc.doRegister("prefix", new Option_String(""));
69 oc.addDescription("prefix", "Output", TL("Defines a prefix for edge and junction names"));
70
71#ifdef PROJ_API_FILE
72 if (!forNetgen) {
73 oc.doRegister("proj.plain-geo", new Option_Bool(false));
74 oc.addDescription("proj.plain-geo", "Projection", TL("Write geo coordinates in plain-xml"));
75 }
76#endif // PROJ_API_FILE
77
78 oc.doRegister("amitran-output", new Option_FileName());
79 oc.addDescription("amitran-output", "Output", TL("The generated net will be written to FILE using Amitran format"));
80
81 oc.doRegister("matsim-output", new Option_FileName());
82 oc.addDescription("matsim-output", "Output", TL("The generated net will be written to FILE using MATsim format"));
83
84 oc.doRegister("opendrive-output", new Option_FileName());
85 oc.addDescription("opendrive-output", "Output", TL("The generated net will be written to FILE using OpenDRIVE format"));
86
87 oc.doRegister("dlr-navteq-output", new Option_FileName());
88 oc.addDescription("dlr-navteq-output", "Output", TL("The generated net will be written to dlr-navteq files with the given PREFIX"));
89
90 oc.doRegister("dlr-navteq.precision", new Option_Integer(2));
91 oc.addDescription("dlr-navteq.precision", "Output", TL("The network coordinates are written with the specified level of output precision"));
92
93 oc.doRegister("output.street-names", new Option_Bool(false));
94 oc.addDescription("output.street-names", "Output", TL("Street names will be included in the output (if available)"));
95
96 oc.doRegister("output.original-names", new Option_Bool(false));
97 oc.addDescription("output.original-names", "Output", TL("Writes original names, if given, as parameter"));
98
99 oc.doRegister("street-sign-output", new Option_FileName());
100 oc.addDescription("street-sign-output", "Output", TL("Writes street signs as POIs to FILE"));
101
102 if (!forNetgen) {
103 oc.doRegister("ptstop-output", new Option_FileName());
104 oc.addDescription("ptstop-output", "Output", TL("Writes public transport stops to FILE"));
105 oc.doRegister("ptline-output", new Option_FileName());
106 oc.addDescription("ptline-output", "Output", TL("Writes public transport lines to FILE"));
107 oc.doRegister("ptline-clean-up", new Option_Bool(false));
108 oc.addDescription("ptline-clean-up", "Output", TL("Clean-up pt stops that are not served by any line"));
109
110 oc.doRegister("parking-output", new Option_FileName());
111 oc.addDescription("parking-output", "Output", TL("Writes parking areas to FILE"));
112
113 oc.doRegister("railway.topology.output", new Option_FileName());
114 oc.addDescription("railway.topology.output", "Output", TL("Analyze topology of the railway network"));
115
116 oc.doRegister("polygon-output", new Option_FileName());
117 oc.addSynonyme("polygon-output", "taz-output");
118 oc.addDescription("polygon-output", "Output", TL("Write shapes that are embedded in the network input and that are not supported by polyconvert (OpenDRIVE)"));
119 }
120
121 // register opendrive options
122 oc.doRegister("opendrive-output.straight-threshold", new Option_Float(0.00000001)); // matching the angular output precision in NWWriter_OpenDrive
123 oc.addDescription("opendrive-output.straight-threshold", "Output", TL("Builds parameterized curves whenever the angular change between straight segments exceeds FLOAT degrees"));
124
125 if (!forNetgen) {
126 oc.doRegister("opendrive-output.lefthand-left", new Option_Bool(false));
127 oc.addDescription("opendrive-output.lefthand-left", "Output", TL("Write lanes in lefthand networks on the left side (positive indices)"));
128
129 oc.doRegister("opendrive-output.shape-match-dist", new Option_Float(-1));
130 oc.addDescription("opendrive-output.shape-match-dist", "Output", TL("Match loaded shapes to the closest edge within FLOAT and export as road objects"));
131 }
132}
133
134
135bool
137 bool ok = true;
138 // check whether the output is valid and can be build
139 if (!oc.isSet("output-file")
140 && !oc.isSet("plain-output-prefix")
141 && !oc.isSet("amitran-output")
142 && !oc.isSet("matsim-output")
143 && !oc.isSet("opendrive-output")
144 && !oc.isSet("dlr-navteq-output")) {
145 std::string net = "net.net.xml";
146 if (oc.isSet("configuration-file")) {
147 net = FileHelpers::getConfigurationRelative(oc.getString("configuration-file"), net);
148 }
149 oc.setDefault("output-file", net);
150 }
151 // some outputs need internal lanes
152 if (oc.isSet("opendrive-output") && oc.getBool("no-internal-links")) {
153 WRITE_ERROR(TL("OpenDRIVE export needs internal links computation."));
154 ok = false;
155 }
156 if (oc.isSet("opendrive-output") && oc.isDefault("no-internal-links")) {
157 oc.setDefault("no-internal-links", "false");
158 }
159 if (oc.isSet("opendrive-output") && oc.isDefault("rectangular-lane-cut")) {
160 oc.setDefault("rectangular-lane-cut", "true");
161 }
162 if (oc.isSet("opendrive-output") && !oc.getBool("rectangular-lane-cut")) {
163 WRITE_WARNING(TL("OpenDRIVE cannot represent oblique lane cuts and should use option 'rectangular-lane-cut'."));
164 }
165 if (oc.isSet("dlr-navteq-output") && oc.isDefault("numerical-ids")) {
166 oc.setDefault("numerical-ids", "true");
167 }
168 if (oc.isSet("dlr-navteq-output") && oc.isDefault("osm.all-attributes")) {
169 oc.setDefault("osm.all-attributes", "true");
170 oc.setDefault("osm.extra-attributes", "bridge,tunnel,layer,postal_code");
171 }
172 if (oc.exists("ptline-output") && oc.isSet("ptline-output") && !oc.isSet("ptstop-output")) {
173 WRITE_ERROR(TL("public transport lines output requires 'ptstop-output' to be set"));
174 ok = false;
175 }
176 if (oc.exists("ptline-clean-up") && oc.getBool("ptline-clean-up") && !oc.isSet("ptline-output")) {
177 WRITE_WARNING(TL("'ptline-clean-up' only works in conjunction with 'ptline-output'. Ignoring invalid option."));
178 }
179
180 return ok;
181}
182
183
184void
186 const long before = PROGRESS_BEGIN_TIME_MESSAGE(TL("Writing network"));
192 NWWriter_XML::writeNetwork(oc, oc.isSet("plain-output-prefix") ? oc.getString("plain-output-prefix") : "", nb);
193 PROGRESS_TIME_MESSAGE(before);
194}
195
196
197void
199 dev.writeAttr(SUMO_ATTR_X, pos.x());
200 dev.writeAttr(SUMO_ATTR_Y, pos.y());
201 if (pos.z() != 0) {
202 dev.writeAttr(SUMO_ATTR_Z, pos.z());
203 }
204}
205
206/****************************************************************************/
#define WRITE_ERROR(msg)
Definition MsgHandler.h:279
#define WRITE_WARNING(msg)
Definition MsgHandler.h:270
#define PROGRESS_BEGIN_TIME_MESSAGE(msg)
Definition MsgHandler.h:276
#define TL(string)
Definition MsgHandler.h:287
#define PROGRESS_TIME_MESSAGE(before)
Definition MsgHandler.h:277
@ SUMO_ATTR_Y
@ SUMO_ATTR_Z
@ SUMO_ATTR_X
static std::string getConfigurationRelative(const std::string &configPath, const std::string &path)
Returns the second path as a relative path to the first file.
Instance responsible for building networks.
static void fillOptions(OptionsCont &oc, bool forNetgen)
Inserts options used by the network writer.
Definition NWFrame.cpp:49
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network stored in the given net builder.
Definition NWFrame.cpp:185
static void writePositionLong(const Position &pos, OutputDevice &dev)
Writes the given position to device in long format (one attribute per dimension)
Definition NWFrame.cpp:198
static bool checkOptions(OptionsCont &oc)
Checks set options for being valid.
Definition NWFrame.cpp:136
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a Amitran-file.
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into XML-files (nodes, edges, connections, traffic lights)
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a MATSim-file.
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a openDRIVE-file.
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a SUMO-file.
static void writeNetwork(const OptionsCont &oc, const std::string &prefix, NBNetBuilder &nb)
Writes the network into XML-files (nodes, edges, connections, traffic lights)
A storage for options typed value containers)
Definition OptionsCont.h:89
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
bool setDefault(const std::string &name, const std::string &value)
Sets the given value for the named option as new default value.
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double x() const
Returns the x-position.
Definition Position.h:55
double z() const
Returns the z-position.
Definition Position.h:65
double y() const
Returns the y-position.
Definition Position.h:60