SUMO - Simulation of Urban MObility
netconvert_main.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Main for NETCONVERT
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 #ifdef HAVE_VERSION_H
34 #include <version.h>
35 #endif
36 
37 #include <iostream>
38 #include <string>
39 #include <netimport/NIFrame.h>
40 #include <netimport/NILoader.h>
41 #include <netbuild/NBFrame.h>
42 #include <netbuild/NBNetBuilder.h>
43 #include <netwrite/NWFrame.h>
51 #include <utils/xml/XMLSubSys.h>
54 
55 
56 // ===========================================================================
57 // method definitions
58 // ===========================================================================
59 void
62  oc.addCallExample("-c <CONFIGURATION>", "generate net with options read from file");
63  oc.addCallExample("-n ./nodes.xml -e ./edges.xml -v -t ./owntypes.xml",
64  "generate net with given nodes, edges, and edge types doing verbose output");
65 
66  // insert options sub-topics
67  SystemFrame::addConfigurationOptions(oc); // this subtopic is filled here, too
68  oc.addOptionSubTopic("Input");
69  oc.addOptionSubTopic("Output");
71  oc.addOptionSubTopic("TLS Building");
72  oc.addOptionSubTopic("Ramp Guessing");
73  oc.addOptionSubTopic("Edge Removal");
74  oc.addOptionSubTopic("Unregulated Nodes");
75  oc.addOptionSubTopic("Processing");
76  oc.addOptionSubTopic("Building Defaults");
77  SystemFrame::addReportOptions(oc); // this subtopic is filled here, too
78 
80  NBFrame::fillOptions(false);
81  NWFrame::fillOptions(false);
83 }
84 
85 
86 bool
88  bool ok = NIFrame::checkOptions();
89  ok &= NBFrame::checkOptions();
90  ok &= NWFrame::checkOptions();
92  return ok;
93 }
94 
95 
96 /* -------------------------------------------------------------------------
97  * main
98  * ----------------------------------------------------------------------- */
99 int
100 main(int argc, char** argv) {
102  // give some application descriptions
103  oc.setApplicationDescription("Road network importer / builder for the road traffic simulation SUMO.");
104  oc.setApplicationName("netconvert", "SUMO netconvert Version " VERSION_STRING);
105  int ret = 0;
106  try {
107  XMLSubSys::init();
108  fillOptions();
109  OptionsIO::setArgs(argc, argv);
111  if (oc.processMetaOptions(argc < 2)) {
113  return 0;
114  }
115  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
117  if (!checkOptions()) {
118  throw ProcessError();
119  }
121  // build the projection
122  if (!GeoConvHelper::init(oc)) {
123  throw ProcessError("Could not build projection!");
124  }
125  NBNetBuilder nb;
126  nb.applyOptions(oc);
127  // load data
128  NILoader nl(nb);
129  nl.load(oc);
130  if (oc.getBool("ignore-errors")) {
132  }
133  // check whether any errors occured
134  if (MsgHandler::getErrorInstance()->wasInformed()) {
135  throw ProcessError();
136  }
137  nb.compute(oc);
138  // check whether any errors occured
139  if (MsgHandler::getErrorInstance()->wasInformed()) {
140  throw ProcessError();
141  }
142  NWFrame::writeNetwork(oc, nb);
143  } catch (const ProcessError& e) {
144  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
145  WRITE_ERROR(e.what());
146  }
147  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
148  ret = 1;
149 #ifndef _DEBUG
150  } catch (const std::exception& e) {
151  if (std::string(e.what()) != std::string("")) {
152  WRITE_ERROR(e.what());
153  }
154  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
155  ret = 1;
156  } catch (...) {
157  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
158  ret = 1;
159 #endif
160  }
163  // report about ending
164  if (ret == 0) {
165  std::cout << "Success." << std::endl;
166  }
167  return ret;
168 }
169 
170 
171 
172 /****************************************************************************/
173 
bool checkOptions()
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:54
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:49
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NWFrame.cpp:119
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NBFrame.cpp:436
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:72
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:65
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:56
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:47
int main(int argc, char **argv)
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:62
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
static void initRandGlobal(MTRand *which=0)
Reads the given random number options and initialises the random number generator in accordance...
Definition: RandHelper.cpp:64
void applyOptions(OptionsCont &oc)
Initialises the storage by applying given options.
Perfoms network import.
Definition: NILoader.h:59
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:80
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:289
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:154
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
Instance responsible for building networks.
Definition: NBNetBuilder.h:114
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:85
A storage for options typed value containers)
Definition: OptionsCont.h:99
void fillOptions()
static void fillOptions(bool forNetgen)
Inserts options used by the network converter.
Definition: NBFrame.cpp:56
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:59
void clear()
Clears information whether an error occured previously.
Definition: MsgHandler.cpp:145
static void initOutputOptions()
Definition: MsgHandler.cpp:193
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.