SUMO - Simulation of Urban MObility
NWFrame.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Sets and checks options for netwrite
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <utils/options/Option.h>
38 #include <utils/common/SysUtils.h>
40 #include <netbuild/NBNetBuilder.h>
41 #include "NWFrame.h"
42 #include "NWWriter_SUMO.h"
43 #include "NWWriter_Amitran.h"
44 #include "NWWriter_MATSim.h"
45 #include "NWWriter_XML.h"
46 #include "NWWriter_OpenDrive.h"
47 #include "NWWriter_DlrNavteq.h"
48 
49 // ===========================================================================
50 // static members
51 // ===========================================================================
52 const std::string NWFrame::MAJOR_VERSION = "0.27";
53 
54 
55 // ===========================================================================
56 // method definitions
57 // ===========================================================================
58 void
59 NWFrame::fillOptions(bool forNetgen) {
61  // register options
62  oc.doRegister("output-file", 'o', new Option_FileName());
63  oc.addSynonyme("output-file", "sumo-output");
64  oc.addSynonyme("output-file", "output");
65  oc.addDescription("output-file", "Output", "The generated net will be written to FILE");
66 
67  oc.doRegister("plain-output-prefix", new Option_FileName());
68  oc.addSynonyme("plain-output-prefix", "plain-output");
69  oc.addSynonyme("plain-output-prefix", "plain");
70  oc.addDescription("plain-output-prefix", "Output", "Prefix of files to write plain xml nodes, edges and connections to");
71 
72  oc.doRegister("junctions.join-output", new Option_FileName());
73  oc.addDescription("junctions.join-output", "Output",
74  "Writes information about joined junctions to FILE (can be loaded as additional node-file to reproduce joins");
75 
76 #ifdef HAVE_PROJ
77  if (!forNetgen) {
78  oc.doRegister("proj.plain-geo", new Option_Bool(false));
79  oc.addDescription("proj.plain-geo", "Projection", "Write geo coordinates in plain-xml");
80  }
81 #endif // HAVE_PROJ
82 
83  oc.doRegister("amitran-output", new Option_FileName());
84  oc.addDescription("amitran-output", "Output", "The generated net will be written to FILE using Amitran format");
85 
86  oc.doRegister("matsim-output", new Option_FileName());
87  oc.addDescription("matsim-output", "Output", "The generated net will be written to FILE using MATsim format");
88 
89  oc.doRegister("opendrive-output", new Option_FileName());
90  oc.addDescription("opendrive-output", "Output", "The generated net will be written to FILE using OpenDRIVE format");
91 
92  oc.doRegister("dlr-navteq-output", new Option_FileName());
93  oc.addDescription("dlr-navteq-output", "Output", "The generated net will be written to dlr-navteq files with the given PREFIX");
94 
95  oc.doRegister("dlr-navteq.precision", new Option_Integer(2));
96  oc.addDescription("dlr-navteq.precision", "Output", "The network coordinates are written with the specified level of output precision");
97 
98  oc.doRegister("output.street-names", new Option_Bool(false));
99  oc.addDescription("output.street-names", "Output", "Street names will be included in the output (if available)");
100 
101  oc.doRegister("output.original-names", new Option_Bool(false));
102  oc.addDescription("output.original-names", "Output", "Writes original names, if given, as parameter");
103 
104  oc.doRegister("street-sign-output", new Option_FileName());
105  oc.addDescription("street-sign-output", "Output", "Writes street signs as POIs to FILE");
106 
107  if (!forNetgen) {
108  oc.doRegister("ptstop-output", new Option_FileName());
109  oc.addDescription("ptstop-output", "Output", "Writes public transport stops to FILE");
110  }
111 
112  // register opendrive options
113  oc.doRegister("opendrive-output.straight-threshold", new Option_Float(0.00000001)); // matching the angular output precision in NWWriter_OpenDrive
114  oc.addDescription("opendrive-output.straight-threshold", "Output", "Builds parameterized curves whenever the angular change between straight segments exceeds FLOAT degrees");
115 }
116 
117 
118 bool
121  bool ok = true;
122  // check whether the output is valid and can be build
123  if (!oc.isSet("output-file")
124  && !oc.isSet("plain-output-prefix")
125  && !oc.isSet("amitran-output")
126  && !oc.isSet("matsim-output")
127  && !oc.isSet("opendrive-output")
128  && !oc.isSet("dlr-navteq-output")) {
129  std::string net = "net.net.xml";
130  if (oc.isSet("configuration-file")) {
131  net = FileHelpers::getConfigurationRelative(oc.getString("configuration-file"), net);
132  }
133  oc.setDefault("output-file", net);
134  }
135  // some outputs need internal lanes
136  if (oc.isSet("opendrive-output") && oc.getBool("no-internal-links")) {
137  WRITE_ERROR("OpenDRIVE export needs internal links computation.");
138  ok = false;
139  }
140  if (oc.isSet("opendrive-output") && oc.isDefault("rectangular-lane-cut")) {
141  oc.set("rectangular-lane-cut", "true");
142  }
143  if (oc.isSet("opendrive-output") && !oc.getBool("rectangular-lane-cut")) {
144  WRITE_WARNING("OpenDRIVE cannot represent oblique lane cuts and should use option 'rectangular-lane-cut'.");
145  }
146  if (oc.isSet("dlr-navteq-output") && oc.isDefault("numerical-ids")) {
147  oc.set("numerical-ids", "true");
148  }
149  return ok;
150 }
151 
152 
153 void
155  long before = SysUtils::getCurrentMillis();
156  PROGRESS_BEGIN_MESSAGE("Writing network");
163  PROGRESS_TIME_MESSAGE(before);
164 }
165 
166 
167 void
169  dev.writeAttr(SUMO_ATTR_X, pos.x());
170  dev.writeAttr(SUMO_ATTR_Y, pos.y());
171  if (pos.z() != 0) {
172  dev.writeAttr(SUMO_ATTR_Z, pos.z());
173  }
174 }
175 
176 /****************************************************************************/
177 
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:82
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NWFrame.cpp:119
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:82
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:73
double y() const
Returns the y-position.
Definition: Position.h:68
double x() const
Returns the x-position.
Definition: Position.h:63
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:200
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
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:204
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:46
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:202
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:168
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:154
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
An integer-option.
Definition: Option.h:313
Instance responsible for building networks.
Definition: NBNetBuilder.h:114
A storage for options typed value containers)
Definition: OptionsCont.h:99
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
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:59
static long getCurrentMillis()
Returns the current time in milliseconds.
Definition: SysUtils.cpp:46
static const std::string MAJOR_VERSION
The version number for written files.
Definition: NWFrame.h:69
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a MATSim-file.