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-2018 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 /****************************************************************************/
17 // Main for NETCONVERT
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #ifdef HAVE_VERSION_H
27 #include <version.h>
28 #endif
29 
30 #include <iostream>
31 #include <string>
32 #include <netimport/NIFrame.h>
33 #include <netimport/NILoader.h>
34 #include <netbuild/NBFrame.h>
35 #include <netbuild/NBNetBuilder.h>
36 #include <netwrite/NWFrame.h>
44 #include <utils/xml/XMLSubSys.h>
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
52 void
55  oc.addCallExample("-c <CONFIGURATION>", "generate net with options read from file");
56  oc.addCallExample("-n ./nodes.xml -e ./edges.xml -v -t ./owntypes.xml",
57  "generate net with given nodes, edges, and edge types doing verbose output");
58 
59  // insert options sub-topics
60  SystemFrame::addConfigurationOptions(oc); // this subtopic is filled here, too
61  oc.addOptionSubTopic("Input");
62  oc.addOptionSubTopic("Output");
64  oc.addOptionSubTopic("Processing");
65  oc.addOptionSubTopic("Building Defaults");
66  oc.addOptionSubTopic("TLS Building");
67  oc.addOptionSubTopic("Ramp Guessing");
68  oc.addOptionSubTopic("Edge Removal");
69  oc.addOptionSubTopic("Unregulated Nodes");
70  oc.addOptionSubTopic("Junctions");
71  oc.addOptionSubTopic("Pedestrian");
72  oc.addOptionSubTopic("Railway");
73  oc.addOptionSubTopic("Formats");
74  SystemFrame::addReportOptions(oc); // this subtopic is filled here, too
75 
77  NBFrame::fillOptions(false);
78  NWFrame::fillOptions(false);
80 }
81 
82 
83 bool
85  bool ok = NIFrame::checkOptions();
86  ok &= NBFrame::checkOptions();
87  ok &= NWFrame::checkOptions();
89  return ok;
90 }
91 
92 
93 /* -------------------------------------------------------------------------
94  * main
95  * ----------------------------------------------------------------------- */
96 int
97 main(int argc, char** argv) {
99  // give some application descriptions
100  oc.setApplicationDescription("Network importer / builder for the microscopic, multi-modal traffic simulation SUMO.");
101  oc.setApplicationName("netconvert", "Eclipse SUMO netconvert Version " VERSION_STRING);
102  int ret = 0;
103  try {
104  XMLSubSys::init();
105  fillOptions();
106  OptionsIO::setArgs(argc, argv);
108  if (oc.processMetaOptions(argc < 2)) {
110  return 0;
111  }
112  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
114  if (!checkOptions()) {
115  throw ProcessError();
116  }
118  // build the projection
119  if (!GeoConvHelper::init(oc)) {
120  throw ProcessError("Could not build projection!");
121  }
122  NBNetBuilder nb;
123  nb.applyOptions(oc);
124  // load data
125  NILoader nl(nb);
126  nl.load(oc);
127  if (oc.getBool("ignore-errors")) {
129  }
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  NWFrame::writeNetwork(oc, nb);
140  } catch (const ProcessError& e) {
141  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
142  WRITE_ERROR(e.what());
143  }
144  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
145  ret = 1;
146 #ifndef _DEBUG
147  } catch (const std::exception& e) {
148  if (std::string(e.what()) != std::string("")) {
149  WRITE_ERROR(e.what());
150  }
151  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
152  ret = 1;
153  } catch (...) {
154  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
155  ret = 1;
156 #endif
157  }
160  // report about ending
161  if (ret == 0) {
162  std::cout << "Success." << std::endl;
163  }
164  return ret;
165 }
166 
167 
168 
169 /****************************************************************************/
170 
bool checkOptions()
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:48
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:76
static void insertRandOptions()
Initialises the given options container with random number options.
Definition: RandHelper.cpp:43
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NWFrame.cpp:125
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NBFrame.cpp:536
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:76
static void addReportOptions(OptionsCont &oc)
Adds reporting options to the given container.
Definition: SystemFrame.cpp:65
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:59
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:49
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:40
int main(int argc, char **argv)
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:55
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
void applyOptions(OptionsCont &oc)
Initialises the storage by applying given options.
Perfoms network import.
Definition: NILoader.h:52
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:74
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:322
static void addProjectionOptions(OptionsCont &oc)
Adds projection options to the given container.
#define VERSION_STRING
Definition: config.h:207
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network stored in the given net builder.
Definition: NWFrame.cpp:174
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:247
Instance responsible for building networks.
Definition: NBNetBuilder.h:109
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:113
A storage for options typed value containers)
Definition: OptionsCont.h:92
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:72
static void fillOptions(bool forNetgen)
Inserts options used by the network converter.
Definition: NBFrame.cpp:49
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:52
void clear()
Clears information whether an error occurred previously.
Definition: MsgHandler.cpp:173
static void initOutputOptions()
init output options
Definition: MsgHandler.cpp:239
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.