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-2019 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("Bicycle");
73  oc.addOptionSubTopic("Railway");
74  oc.addOptionSubTopic("Formats");
75  SystemFrame::addReportOptions(oc); // this subtopic is filled here, too
76 
78  NBFrame::fillOptions(false);
79  NWFrame::fillOptions(false);
81 }
82 
83 
84 bool
86  bool ok = NIFrame::checkOptions();
87  ok &= NBFrame::checkOptions();
88  ok &= NWFrame::checkOptions();
90  return ok;
91 }
92 
93 
94 /* -------------------------------------------------------------------------
95  * main
96  * ----------------------------------------------------------------------- */
97 int
98 main(int argc, char** argv) {
100  // give some application descriptions
101  oc.setApplicationDescription("Network importer / builder for the microscopic, multi-modal traffic simulation SUMO.");
102  oc.setApplicationName("netconvert", "Eclipse SUMO netconvert Version " VERSION_STRING);
103  int ret = 0;
104  try {
105  XMLSubSys::init();
106  fillOptions();
107  OptionsIO::setArgs(argc, argv);
109  if (oc.processMetaOptions(argc < 2)) {
111  return 0;
112  }
113  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
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  if (oc.getBool("ignore-errors")) {
130  }
131  // check whether any errors occurred
132  if (MsgHandler::getErrorInstance()->wasInformed()) {
133  throw ProcessError();
134  }
135  nb.compute(oc);
136  // check whether any errors occurred
137  if (MsgHandler::getErrorInstance()->wasInformed()) {
138  throw ProcessError();
139  }
140  NWFrame::writeNetwork(oc, nb);
141  } catch (const ProcessError& e) {
142  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
143  WRITE_ERROR(e.what());
144  }
145  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
146  ret = 1;
147 #ifndef _DEBUG
148  } catch (const std::exception& e) {
149  if (std::string(e.what()) != std::string("")) {
150  WRITE_ERROR(e.what());
151  }
152  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
153  ret = 1;
154  } catch (...) {
155  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
156  ret = 1;
157 #endif
158  }
161  // report about ending
162  if (ret == 0) {
163  std::cout << "Success." << std::endl;
164  }
165  return ret;
166 }
167 
168 
169 
170 /****************************************************************************/
171 
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:81
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:126
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NBFrame.cpp:577
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 fillOptions(bool forNetedit=false)
Inserts options used by the network importer and network building modules.
Definition: NIFrame.cpp:49
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.
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:75
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:330
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:175
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:245
Instance responsible for building networks.
Definition: NBNetBuilder.h:110
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:118
A storage for options typed value containers)
Definition: OptionsCont.h:90
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:50
virtual void clear()
Clears information whether an error occurred previously.
Definition: MsgHandler.cpp:160
static void initOutputOptions()
init output options
Definition: MsgHandler.cpp:208
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.