Eclipse SUMO - Simulation of Urban MObility
netconvert_main.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-2022 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 // Main for NETCONVERT
21 /****************************************************************************/
22 #include <config.h>
23 
24 #ifdef HAVE_VERSION_H
25 #include <version.h>
26 #endif
27 
28 #include <iostream>
29 #include <string>
30 #include <netimport/NIFrame.h>
31 #include <netimport/NILoader.h>
32 #include <netbuild/NBFrame.h>
33 #include <netbuild/NBNetBuilder.h>
34 #include <netwrite/NWFrame.h>
42 #include <utils/xml/XMLSubSys.h>
45 
46 
47 // ===========================================================================
48 // method definitions
49 // ===========================================================================
50 void
53  oc.addCallExample("-c <CONFIGURATION>", "generate net with options read from file");
54  oc.addCallExample("-n ./nodes.xml -e ./edges.xml -v -t ./owntypes.xml",
55  "generate net with given nodes, edges, and edge types doing verbose output");
56 
57  // insert options sub-topics
58  SystemFrame::addConfigurationOptions(oc); // this subtopic is filled here, too
59  oc.addOptionSubTopic("Input");
60  oc.addOptionSubTopic("Output");
62  oc.addOptionSubTopic("Processing");
63  oc.addOptionSubTopic("Building Defaults");
64  oc.addOptionSubTopic("TLS Building");
65  oc.addOptionSubTopic("Ramp Guessing");
66  oc.addOptionSubTopic("Edge Removal");
67  oc.addOptionSubTopic("Unregulated Nodes");
68  oc.addOptionSubTopic("Junctions");
69  oc.addOptionSubTopic("Pedestrian");
70  oc.addOptionSubTopic("Bicycle");
71  oc.addOptionSubTopic("Railway");
72  oc.addOptionSubTopic("Formats");
73 
75  NBFrame::fillOptions(false);
76  NWFrame::fillOptions(false);
78 }
79 
80 
81 bool
83  bool ok = NIFrame::checkOptions();
84  ok &= NBFrame::checkOptions();
85  ok &= NWFrame::checkOptions();
87  return ok;
88 }
89 
90 
91 /* -------------------------------------------------------------------------
92  * main
93  * ----------------------------------------------------------------------- */
94 int
95 main(int argc, char** argv) {
97  // give some application descriptions
98  oc.setApplicationDescription("Network importer / builder for the microscopic, multi-modal traffic simulation SUMO.");
99  oc.setApplicationName("netconvert", "Eclipse SUMO netconvert Version " VERSION_STRING);
100  int ret = 0;
101  try {
102  XMLSubSys::init();
103  fillOptions();
104  OptionsIO::setArgs(argc, argv);
106  if (oc.processMetaOptions(argc < 2)) {
108  return 0;
109  }
110  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"), "never");
111  if (oc.isDefault("aggregate-warnings")) {
112  oc.set("aggregate-warnings", "5");
113  }
115  if (!checkOptions()) {
116  throw ProcessError();
117  }
119  // build the projection
120  if (!GeoConvHelper::init(oc)) {
121  throw ProcessError("Could not build projection!");
122  }
123  NBNetBuilder nb;
124  nb.applyOptions(oc);
125  // load data
126  NILoader nl(nb);
127  nl.load(oc);
128  // flush aggregated errors and optionally ignore them
129  MsgHandler::getErrorInstance()->clear(oc.getBool("ignore-errors"));
130  // check whether any errors occurred
131  if (MsgHandler::getErrorInstance()->wasInformed()) {
132  throw ProcessError();
133  }
134  nb.compute(oc);
135  // check whether any errors occurred
136  if (MsgHandler::getErrorInstance()->wasInformed()) {
137  throw ProcessError();
138  }
139  // report
141  NWFrame::writeNetwork(oc, nb);
142  } catch (const ProcessError& e) {
145  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
146  WRITE_ERROR(e.what());
147  }
148  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
149  ret = 1;
150 #ifndef _DEBUG
151  } catch (const std::exception& e) {
154  if (std::string(e.what()) != std::string("")) {
155  WRITE_ERROR(e.what());
156  }
157  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
158  ret = 1;
159  } catch (...) {
162  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
163  ret = 1;
164 #endif
165  }
168  // report about ending
169  if (ret == 0) {
170  std::cout << "Success." << std::endl;
171  }
172  return ret;
173 }
174 
175 
176 /****************************************************************************/
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:288
static void clear()
delete all stored distributions
static void addProjectionOptions(OptionsCont &oc)
Adds projection options to the given container.
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:117
static void initOutputOptions()
init output options
Definition: MsgHandler.cpp:228
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:67
virtual void clear(bool resetInformed=true)
Clears information whether an error occurred previously and print aggregated message summary.
Definition: MsgHandler.cpp:162
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NBFrame.cpp:670
static void fillOptions(bool forNetgen)
Inserts options used by the network converter.
Definition: NBFrame.cpp:47
Instance responsible for building networks.
Definition: NBNetBuilder.h:107
void applyOptions(OptionsCont &oc)
Initialises the storage by applying given options.
void compute(OptionsCont &oc, const std::set< std::string > &explicitTurnarounds=std::set< std::string >(), bool mayAddOrRemove=true)
Performs the network building steps.
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:153
void printBuiltNodesStatistics() const
Prints statistics about built nodes.
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NIFrame.cpp:368
static void fillOptions(bool forNetedit=false)
Inserts options used by the network importer and network building modules.
Definition: NIFrame.cpp:47
Perfoms network import.
Definition: NILoader.h:48
void load(OptionsCont &oc)
Definition: NILoader.cpp:70
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network stored in the given net builder.
Definition: NWFrame.cpp:174
static void fillOptions(bool forNetgen)
Inserts options used by the network writer.
Definition: NWFrame.cpp:48
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NWFrame.cpp:125
A storage for options typed value containers)
Definition: OptionsCont.h:89
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:58
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:85
static void insertRandOptions()
Initialises the given options container with random number options.
Definition: RandHelper.cpp:43
static void initRandGlobal(SumoRNG *which=nullptr)
Reads the given random number options and initialises the random number generator in accordance.
Definition: RandHelper.cpp:75
static void close()
Closes all of an applications subsystems.
static void addConfigurationOptions(OptionsCont &oc)
Adds configuration options to the given container.
Definition: SystemFrame.cpp:38
static bool checkOptions()
checks shared options and sets StdDefs
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme, const std::string &routeValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:65
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:54
bool checkOptions()
void fillOptions()
int main(int argc, char **argv)