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-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 // Main for NETCONVERT
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 #ifdef HAVE_VERSION_H
33 #include <version.h>
34 #endif
35 
36 #include <iostream>
37 #include <string>
38 #include <netimport/NIFrame.h>
39 #include <netimport/NILoader.h>
40 #include <netbuild/NBFrame.h>
41 #include <netbuild/NBNetBuilder.h>
42 #include <netwrite/NWFrame.h>
50 #include <utils/xml/XMLSubSys.h>
53 
54 
55 // ===========================================================================
56 // method definitions
57 // ===========================================================================
58 void
61  oc.addCallExample("-c <CONFIGURATION>", "generate net with options read from file");
62  oc.addCallExample("-n ./nodes.xml -e ./edges.xml -v -t ./owntypes.xml",
63  "generate net with given nodes, edges, and edge types doing verbose output");
64 
65  // insert options sub-topics
66  SystemFrame::addConfigurationOptions(oc); // this subtopic is filled here, too
67  oc.addOptionSubTopic("Input");
68  oc.addOptionSubTopic("Output");
70  oc.addOptionSubTopic("TLS Building");
71  oc.addOptionSubTopic("Ramp Guessing");
72  oc.addOptionSubTopic("Edge Removal");
73  oc.addOptionSubTopic("Unregulated Nodes");
74  oc.addOptionSubTopic("Processing");
75  oc.addOptionSubTopic("Building Defaults");
76  SystemFrame::addReportOptions(oc); // this subtopic is filled here, too
77 
79  NBFrame::fillOptions(false);
80  NWFrame::fillOptions(false);
82 }
83 
84 
85 bool
87  bool ok = NIFrame::checkOptions();
88  ok &= NBFrame::checkOptions();
89  ok &= NWFrame::checkOptions();
91  return ok;
92 }
93 
94 
95 /* -------------------------------------------------------------------------
96  * main
97  * ----------------------------------------------------------------------- */
98 int
99 main(int argc, char** argv) {
101  // give some application descriptions
102  oc.setApplicationDescription("Road network importer / builder for the road traffic simulation SUMO.");
103  oc.setApplicationName("netconvert", "SUMO netconvert Version " VERSION_STRING);
104  int ret = 0;
105  try {
106  XMLSubSys::init();
107  fillOptions();
108  OptionsIO::setArgs(argc, argv);
110  if (oc.processMetaOptions(argc < 2)) {
112  return 0;
113  }
114  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
116  if (!checkOptions()) {
117  throw ProcessError();
118  }
120  // build the projection
121  if (!GeoConvHelper::init(oc)) {
122  throw ProcessError("Could not build projection!");
123  }
124  NBNetBuilder nb;
125  nb.applyOptions(oc);
126  // load data
127  NILoader nl(nb);
128  nl.load(oc);
129  if (oc.getBool("ignore-errors")) {
131  }
132  // check whether any errors occured
133  if (MsgHandler::getErrorInstance()->wasInformed()) {
134  throw ProcessError();
135  }
136  nb.compute(oc);
137  // check whether any errors occured
138  if (MsgHandler::getErrorInstance()->wasInformed()) {
139  throw ProcessError();
140  }
141  NWFrame::writeNetwork(oc, nb);
142  } catch (const ProcessError& e) {
143  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
144  WRITE_ERROR(e.what());
145  }
146  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
147  ret = 1;
148 #ifndef _DEBUG
149  } catch (const std::exception& e) {
150  if (std::string(e.what()) != std::string("")) {
151  WRITE_ERROR(e.what());
152  }
153  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
154  ret = 1;
155  } catch (...) {
156  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
157  ret = 1;
158 #endif
159  }
162  // report about ending
163  if (ret == 0) {
164  std::cout << "Success." << std::endl;
165  }
166  return ret;
167 }
168 
169 
170 
171 /****************************************************************************/
172 
bool checkOptions()
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:53
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:75
static void insertRandOptions()
Initialises the given options container with random number options.
Definition: RandHelper.cpp:47
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NWFrame.cpp:131
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NBFrame.cpp:461
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:82
static void addReportOptions(OptionsCont &oc)
Adds reporting options to the given container.
Definition: SystemFrame.cpp:71
static void clear()
delete all stored distributions
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:64
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
static void fillOptions()
Inserts options used by the network importer and network building modules.
Definition: NIFrame.cpp:55
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static void close()
Closes all of an applications subsystems.
static void addConfigurationOptions(OptionsCont &oc)
Adds configuration options to the given container.
Definition: SystemFrame.cpp:46
int main(int argc, char **argv)
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:61
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
void applyOptions(OptionsCont &oc)
Initialises the storage by applying given options.
Perfoms network import.
Definition: NILoader.h:58
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
void load(OptionsCont &oc)
Definition: NILoader.cpp:79
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
static bool checkOptions()
checks shared options and sets StdDefs
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NIFrame.cpp:299
static void addProjectionOptions(OptionsCont &oc)
Adds projection options to the given container.
#define VERSION_STRING
Definition: config.h:210
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
Instance responsible for building networks.
Definition: NBNetBuilder.h:115
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:84
A storage for options typed value containers)
Definition: OptionsCont.h:98
void fillOptions()
static void initRandGlobal(std::mt19937 *which=0)
Reads the given random number options and initialises the random number generator in accordance...
Definition: RandHelper.cpp:76
static void fillOptions(bool forNetgen)
Inserts options used by the network converter.
Definition: NBFrame.cpp:55
void compute(OptionsCont &oc, const std::set< std::string > &explicitTurnarounds=std::set< std::string >(), bool mayAddOrRemove=true)
Performs the network building steps.
static void fillOptions(bool forNetgen)
Inserts options used by the network writer.
Definition: NWFrame.cpp:58
void clear()
Clears information whether an error occured previously.
Definition: MsgHandler.cpp:144
static void initOutputOptions()
Definition: MsgHandler.cpp:192
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.