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-2015 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>
44 #include <netwrite/NWFrame.h>
51 #include <utils/xml/XMLSubSys.h>
54 
55 #ifdef CHECK_MEMORY_LEAKS
56 #include <foreign/nvwa/debug_new.h>
57 #endif // CHECK_MEMORY_LEAKS
58 
59 
60 // ===========================================================================
61 // method definitions
62 // ===========================================================================
63 void
66  oc.addCallExample("-c <CONFIGURATION>", "generate net with options read from file");
67  oc.addCallExample("-n ./nodes.xml -e ./edges.xml -v -t ./owntypes.xml",
68  "generate net with given nodes, edges, and edge types doing verbose output");
69 
70  // insert options sub-topics
71  SystemFrame::addConfigurationOptions(oc); // this subtopic is filled here, too
72  oc.addOptionSubTopic("Input");
73  oc.addOptionSubTopic("Output");
75  oc.addOptionSubTopic("TLS Building");
76  oc.addOptionSubTopic("Ramp Guessing");
77  oc.addOptionSubTopic("Edge Removal");
78  oc.addOptionSubTopic("Unregulated Nodes");
79  oc.addOptionSubTopic("Processing");
80  oc.addOptionSubTopic("Building Defaults");
81  SystemFrame::addReportOptions(oc); // this subtopic is filled here, too
82 
84  NBFrame::fillOptions(false);
85  NWFrame::fillOptions(false);
87 }
88 
89 
90 bool
92  bool ok = NIFrame::checkOptions();
93  ok &= NBFrame::checkOptions();
94  ok &= NWFrame::checkOptions();
95  return ok;
96 }
97 
98 
99 /* -------------------------------------------------------------------------
100  * main
101  * ----------------------------------------------------------------------- */
102 int
103 main(int argc, char** argv) {
105  // give some application descriptions
106  oc.setApplicationDescription("Road network importer / builder for the road traffic simulation SUMO.");
107  oc.setApplicationName("netconvert", "SUMO netconvert Version " + getBuildName(VERSION_STRING));
108  int ret = 0;
109  try {
110  XMLSubSys::init();
111  fillOptions();
112  OptionsIO::getOptions(true, argc, argv);
113  if (oc.processMetaOptions(argc < 2)) {
115  return 0;
116  }
117  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
119  if (!checkOptions()) {
120  throw ProcessError();
121  }
123  // build the projection
124  if (!GeoConvHelper::init(oc)) {
125  throw ProcessError("Could not build projection!");
126  }
127  NBNetBuilder nb;
128  nb.applyOptions(oc);
129  // load data
130  NILoader nl(nb);
131  nl.load(oc);
132  if (oc.getBool("ignore-errors")) {
134  }
135  // check whether any errors occured
136  if (MsgHandler::getErrorInstance()->wasInformed()) {
137  throw ProcessError();
138  }
139  nb.compute(oc);
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:58
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
static void insertRandOptions()
Initialises the given options container with random number options.
Definition: RandHelper.cpp:53
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NWFrame.cpp:110
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NBFrame.cpp:362
static void addReportOptions(OptionsCont &oc)
Adds reporting options to the given container.
Definition: SystemFrame.cpp:74
static void getOptions(bool loadConfig, int argc=0, char **argv=0)
Parses the command line arguments and loads the configuration optionally.
Definition: OptionsIO.cpp:64
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:69
void compute(OptionsCont &oc, const std::set< std::string > &explicitTurnarounds=std::set< std::string >(), bool removeElements=true)
Performs the network building steps.
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 fillOptions()
Inserts options used by the network importer and network building modules.
Definition: NIFrame.cpp:59
static void close()
Closes all of an applications subsystems.
static void addConfigurationOptions(OptionsCont &oc)
Adds configuration options to the given container.
Definition: SystemFrame.cpp:50
int main(int argc, char **argv)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
static void initRandGlobal(MTRand *which=0)
Reads the given random number options and initialises the random number generator in accordance...
Definition: RandHelper.cpp:68
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.
const std::string getBuildName(const std::string &version)
attach some build flags to the version string
Definition: StdDefs.cpp:88
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
void load(OptionsCont &oc)
Definition: NILoader.cpp:85
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
static void clear()
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NIFrame.cpp:279
static void addProjectionOptions(OptionsCont &oc)
Adds projection options to the given container.
#define VERSION_STRING
Definition: config.h:230
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network stored in the given net builder.
Definition: NWFrame.cpp:132
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
Instance responsible for building networks.
Definition: NBNetBuilder.h:113
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:89
A storage for options typed value containers)
Definition: OptionsCont.h:108
void fillOptions()
static void fillOptions(bool forNetgen)
Inserts options used by the network converter.
Definition: NBFrame.cpp:61
static void fillOptions(bool forNetgen)
Inserts options used by the network writer.
Definition: NWFrame.cpp:62
void clear()
Clears information whether an error occured previously.
Definition: MsgHandler.cpp:149
static void initOutputOptions()
Definition: MsgHandler.cpp:197
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.