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