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 /****************************************************************************/
16 // Main for NETCONVERT
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #ifdef HAVE_VERSION_H
26 #include <version.h>
27 #endif
28 
29 #include <iostream>
30 #include <string>
31 #include <netimport/NIFrame.h>
32 #include <netimport/NILoader.h>
33 #include <netbuild/NBFrame.h>
34 #include <netbuild/NBNetBuilder.h>
35 #include <netwrite/NWFrame.h>
43 #include <utils/xml/XMLSubSys.h>
46 
47 
48 // ===========================================================================
49 // method definitions
50 // ===========================================================================
51 void
54  oc.addCallExample("-c <CONFIGURATION>", "generate net with options read from file");
55  oc.addCallExample("-n ./nodes.xml -e ./edges.xml -v -t ./owntypes.xml",
56  "generate net with given nodes, edges, and edge types doing verbose output");
57 
58  // insert options sub-topics
59  SystemFrame::addConfigurationOptions(oc); // this subtopic is filled here, too
60  oc.addOptionSubTopic("Input");
61  oc.addOptionSubTopic("Output");
63  oc.addOptionSubTopic("Processing");
64  oc.addOptionSubTopic("Building Defaults");
65  oc.addOptionSubTopic("TLS Building");
66  oc.addOptionSubTopic("Ramp Guessing");
67  oc.addOptionSubTopic("Edge Removal");
68  oc.addOptionSubTopic("Unregulated Nodes");
69  oc.addOptionSubTopic("Junctions");
70  oc.addOptionSubTopic("Pedestrian");
71  oc.addOptionSubTopic("Bicycle");
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"));
113  if (oc.isDefault("aggregate-warnings")) {
114  oc.set("aggregate-warnings", "5");
115  }
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 occurred
134  if (MsgHandler::getErrorInstance()->wasInformed()) {
135  throw ProcessError();
136  }
137  nb.compute(oc);
138  // check whether any errors occurred
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 
DistributionCont::clear
static void clear()
delete all stored distributions
Definition: DistributionCont.cpp:69
OptionsCont::processMetaOptions
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
Definition: OptionsCont.cpp:557
SystemFrame::addConfigurationOptions
static void addConfigurationOptions(OptionsCont &oc)
Adds configuration options to the given container.
Definition: SystemFrame.cpp:39
NWFrame.h
SystemFrame::close
static void close()
Closes all of an applications subsystems.
Definition: SystemFrame.cpp:133
MsgHandler::initOutputOptions
static void initOutputOptions()
init output options
Definition: MsgHandler.cpp:216
NBNetBuilder
Instance responsible for building networks.
Definition: NBNetBuilder.h:109
fillOptions
void fillOptions()
Definition: netconvert_main.cpp:52
OptionsCont.h
OptionsCont::set
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
Definition: OptionsCont.cpp:241
MsgHandler.h
OptionsCont::getString
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Definition: OptionsCont.cpp:201
MsgHandler::inform
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:118
GeoConvHelper.h
OptionsCont::getBool
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Definition: OptionsCont.cpp:222
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:57
NWFrame::fillOptions
static void fillOptions(bool forNetgen)
Inserts options used by the network writer.
Definition: NWFrame.cpp:49
GeoConvHelper::init
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
Definition: GeoConvHelper.cpp:200
SystemFrame::addReportOptions
static void addReportOptions(OptionsCont &oc)
Adds reporting options to the given container.
Definition: SystemFrame.cpp:64
MsgHandler::clear
virtual void clear()
Clears information whether an error occurred previously.
Definition: MsgHandler.cpp:160
NIFrame::checkOptions
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NIFrame.cpp:329
checkOptions
bool checkOptions()
Definition: netconvert_main.cpp:84
NWFrame::writeNetwork
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network stored in the given net builder.
Definition: NWFrame.cpp:175
NWFrame::checkOptions
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NWFrame.cpp:126
NILoader
Perfoms network import.
Definition: NILoader.h:50
NBFrame::checkOptions
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NBFrame.cpp:591
OptionsCont::setApplicationName
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.
Definition: OptionsCont.cpp:481
SystemFrame.h
XMLSubSys::setValidation
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:58
NIFrame::fillOptions
static void fillOptions(bool forNetedit=false)
Inserts options used by the network importer and network building modules.
Definition: NIFrame.cpp:48
GeoConvHelper::addProjectionOptions
static void addProjectionOptions(OptionsCont &oc)
Adds projection options to the given container.
Definition: GeoConvHelper.cpp:248
OutputDevice.h
NBNetBuilder.h
ProcessError
Definition: UtilExceptions.h:39
NBNetBuilder::applyOptions
void applyOptions(OptionsCont &oc)
Initialises the storage by applying given options.
Definition: NBNetBuilder.cpp:65
UtilExceptions.h
XMLSubSys::init
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:47
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
NBFrame::fillOptions
static void fillOptions(bool forNetgen)
Inserts options used by the network converter.
Definition: NBFrame.cpp:48
OptionsCont::isDefault
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
Definition: OptionsCont.cpp:163
NILoader::load
void load(OptionsCont &oc)
Definition: NILoader.cpp:72
OptionsCont::addOptionSubTopic
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
Definition: OptionsCont.cpp:519
RandHelper::initRandGlobal
static void initRandGlobal(std::mt19937 *which=0)
Reads the given random number options and initialises the random number generator in accordance.
Definition: RandHelper.cpp:77
OptionsIO::getOptions
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:75
OptionsCont::setApplicationDescription
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
Definition: OptionsCont.cpp:489
NILoader.h
OptionsCont::addCallExample
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
Definition: OptionsCont.cpp:495
OptionsIO::setArgs
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:54
NBNetBuilder::compute
void compute(OptionsCont &oc, const std::set< std::string > &explicitTurnarounds=std::set< std::string >(), bool mayAddOrRemove=true)
Performs the network building steps.
Definition: NBNetBuilder.cpp:77
config.h
NBFrame.h
RandHelper::insertRandOptions
static void insertRandOptions()
Initialises the given options container with random number options.
Definition: RandHelper.cpp:45
RandHelper.h
SystemFrame::checkOptions
static bool checkOptions()
checks shared options and sets StdDefs
Definition: SystemFrame.cpp:120
MsgHandler::getErrorInstance
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:81
NIFrame.h
VERSION_STRING
#define VERSION_STRING
Definition: config.h:210
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:283
DistributionCont.h
OptionsIO.h
XMLSubSys.h
main
int main(int argc, char **argv)
Definition: netconvert_main.cpp:97