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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Sets and checks options for netwrite
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
33 #include <utils/options/Option.h>
37 #include <utils/common/SysUtils.h>
39 #include <netbuild/NBNetBuilder.h>
40 #include "NWFrame.h"
41 #include "NWWriter_SUMO.h"
42 #include "NWWriter_Amitran.h"
43 #include "NWWriter_MATSim.h"
44 #include "NWWriter_XML.h"
45 #include "NWWriter_OpenDrive.h"
46 #include "NWWriter_DlrNavteq.h"
47 
48 // ===========================================================================
49 // static members
50 // ===========================================================================
51 const std::string NWFrame::MAJOR_VERSION = "0.27";
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
57 void
58 NWFrame::fillOptions(bool forNetgen) {
60  // register options
61  oc.doRegister("output-file", 'o', new Option_FileName());
62  oc.addSynonyme("output-file", "sumo-output");
63  oc.addSynonyme("output-file", "output");
64  oc.addDescription("output-file", "Output", "The generated net will be written to FILE");
65 
66  oc.doRegister("plain-output-prefix", new Option_FileName());
67  oc.addSynonyme("plain-output-prefix", "plain-output");
68  oc.addSynonyme("plain-output-prefix", "plain");
69  oc.addDescription("plain-output-prefix", "Output", "Prefix of files to write plain xml nodes, edges and connections to");
70 
71  oc.doRegister("junctions.join-output", new Option_FileName());
72  oc.addDescription("junctions.join-output", "Output",
73  "Writes information about joined junctions to FILE (can be loaded as additional node-file to reproduce joins");
74 
75 #ifdef HAVE_PROJ
76  if (!forNetgen) {
77  oc.doRegister("proj.plain-geo", new Option_Bool(false));
78  oc.addDescription("proj.plain-geo", "Projection", "Write geo coordinates in plain-xml");
79  }
80 #endif // HAVE_PROJ
81 
82  oc.doRegister("amitran-output", new Option_FileName());
83  oc.addDescription("amitran-output", "Output", "The generated net will be written to FILE using Amitran format");
84 
85  oc.doRegister("matsim-output", new Option_FileName());
86  oc.addDescription("matsim-output", "Output", "The generated net will be written to FILE using MATsim format");
87 
88  oc.doRegister("opendrive-output", new Option_FileName());
89  oc.addDescription("opendrive-output", "Output", "The generated net will be written to FILE using OpenDRIVE format");
90 
91  oc.doRegister("dlr-navteq-output", new Option_FileName());
92  oc.addDescription("dlr-navteq-output", "Output", "The generated net will be written to dlr-navteq files with the given PREFIX");
93 
94  oc.doRegister("dlr-navteq.precision", new Option_Integer(2));
95  oc.addDescription("dlr-navteq.precision", "Output", "The network coordinates are written with the specified level of output precision");
96 
97  oc.doRegister("output.street-names", new Option_Bool(false));
98  oc.addDescription("output.street-names", "Output", "Street names will be included in the output (if available)");
99 
100  oc.doRegister("output.original-names", new Option_Bool(false));
101  oc.addDescription("output.original-names", "Output", "Writes original names, if given, as parameter");
102 
103  oc.doRegister("street-sign-output", new Option_FileName());
104  oc.addDescription("street-sign-output", "Output", "Writes street signs as POIs to FILE");
105 
106  if (!forNetgen) {
107  oc.doRegister("ptstop-output", new Option_FileName());
108  oc.addDescription("ptstop-output", "Output", "Writes public transport stops to FILE");
109  oc.doRegister("ptline-output", new Option_FileName());
110  oc.addDescription("ptline-output", "Output", "Writes public transport lines to FILE");
111  oc.doRegister("ptline-clean-up", new Option_Bool(false));
112  oc.addDescription("ptline-clean-up", "Output", "Clean-up pt stops that are not served by any line");
113 
114  oc.doRegister("parking-output", new Option_FileName());
115  oc.addDescription("parking-output", "Output", "Writes parking areas to FILE");
116 
117  oc.doRegister("osm.stop-output.footway-access-distance", new Option_Float(150.f));
118  oc.addDescription("osm.stop-output.footway-access-distance", "Output", "The search radius for finding suitable road accesses for rail stops");
119 
120  oc.doRegister("osm.stop-output.footway-max-accesses", new Option_Integer(5));
121  oc.addDescription("osm.stop-output.footway-max-accesses", "Output", "The maximum roud accesses registered per rail stops");
122  }
123 
124  // register opendrive options
125  oc.doRegister("opendrive-output.straight-threshold", new Option_Float(0.00000001)); // matching the angular output precision in NWWriter_OpenDrive
126  oc.addDescription("opendrive-output.straight-threshold", "Output", "Builds parameterized curves whenever the angular change between straight segments exceeds FLOAT degrees");
127 }
128 
129 
130 bool
133  bool ok = true;
134  // check whether the output is valid and can be build
135  if (!oc.isSet("output-file")
136  && !oc.isSet("plain-output-prefix")
137  && !oc.isSet("amitran-output")
138  && !oc.isSet("matsim-output")
139  && !oc.isSet("opendrive-output")
140  && !oc.isSet("dlr-navteq-output")) {
141  std::string net = "net.net.xml";
142  if (oc.isSet("configuration-file")) {
143  net = FileHelpers::getConfigurationRelative(oc.getString("configuration-file"), net);
144  }
145  oc.setDefault("output-file", net);
146  }
147  // some outputs need internal lanes
148  if (oc.isSet("opendrive-output") && oc.getBool("no-internal-links")) {
149  WRITE_ERROR("OpenDRIVE export needs internal links computation.");
150  ok = false;
151  }
152  if (oc.isSet("opendrive-output") && oc.isDefault("no-internal-links")) {
153  oc.set("no-internal-links", "false");
154  }
155  if (oc.isSet("opendrive-output") && oc.isDefault("rectangular-lane-cut")) {
156  oc.set("rectangular-lane-cut", "true");
157  }
158  if (oc.isSet("opendrive-output") && !oc.getBool("rectangular-lane-cut")) {
159  WRITE_WARNING("OpenDRIVE cannot represent oblique lane cuts and should use option 'rectangular-lane-cut'.");
160  }
161  if (oc.isSet("dlr-navteq-output") && oc.isDefault("numerical-ids")) {
162  oc.set("numerical-ids", "true");
163  }
164  if (oc.isSet("dlr-navteq-output") && oc.isDefault("osm.all-attributes")) {
165  oc.set("osm.all-attributes", "true");
166  }
167  if (oc.exists("ptline-output") && oc.isSet("ptline-output") && !oc.isSet("ptstop-output")) {
168  WRITE_ERROR("public transport lines output requires 'ptstop-output' to be set");
169  ok = false;
170  }
171  if (oc.exists("ptline-clean-up") && oc.getBool("ptline-clean-up") && !oc.isSet("ptline-output")) {
172  WRITE_WARNING("'ptline-clean-up' only works in conjunction with 'ptline-output'. Ignoring invalid option.");
173  }
174 
175  return ok;
176 }
177 
178 
179 void
181  long before = SysUtils::getCurrentMillis();
182  PROGRESS_BEGIN_MESSAGE("Writing network");
189  PROGRESS_TIME_MESSAGE(before);
190 }
191 
192 
193 void
195  dev.writeAttr(SUMO_ATTR_X, pos.x());
196  dev.writeAttr(SUMO_ATTR_Y, pos.y());
197  if (pos.z() != 0) {
198  dev.writeAttr(SUMO_ATTR_Z, pos.z());
199  }
200 }
201 
202 /****************************************************************************/
203 
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:81
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NWFrame.cpp:131
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:81
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a Amitran-file.
double z() const
Returns the z-position.
Definition: Position.h:72
double y() const
Returns the y-position.
Definition: Position.h:67
double x() const
Returns the x-position.
Definition: Position.h:62
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
#define PROGRESS_TIME_MESSAGE(before)
Definition: MsgHandler.h:203
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a SUMO-file.
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a openDRIVE-file.
bool setDefault(const std::string &name, const std::string &value)
Sets the given value for the named option as new default value.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool exists(const std::string &name) const
Returns the information whether the named option is known.
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:201
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into XML-files (nodes, edges, connections, traffic lights)
static void writePositionLong(const Position &pos, OutputDevice &dev)
Writes the given position to device in long format (one attribute per dimension)
Definition: NWFrame.cpp:194
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 stored in the given net builder.
Definition: NWFrame.cpp:180
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
An integer-option.
Definition: Option.h:312
Instance responsible for building networks.
Definition: NBNetBuilder.h:115
A storage for options typed value containers)
Definition: OptionsCont.h:98
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
static void fillOptions(bool forNetgen)
Inserts options used by the network writer.
Definition: NWFrame.cpp:58
static long getCurrentMillis()
Returns the current time in milliseconds.
Definition: SysUtils.cpp:45
static const std::string MAJOR_VERSION
The version number for written files.
Definition: NWFrame.h:68
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a MATSim-file.