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 
DistributionCont::clear
static void clear()
delete all stored distributions
Definition: DistributionCont.cpp:70
OptionsCont::processMetaOptions
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
Definition: OptionsCont.cpp:561
SystemFrame::addConfigurationOptions
static void addConfigurationOptions(OptionsCont &oc)
Adds configuration options to the given container.
Definition: SystemFrame.cpp:40
NWFrame.h
SystemFrame::close
static void close()
Closes all of an applications subsystems.
Definition: SystemFrame.cpp:131
MsgHandler::initOutputOptions
static void initOutputOptions()
init output options
Definition: MsgHandler.cpp:208
NBNetBuilder
Instance responsible for building networks.
Definition: NBNetBuilder.h:110
fillOptions
void fillOptions()
Definition: netconvert_main.cpp:53
OptionsCont.h
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:202
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:223
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
NWFrame::fillOptions
static void fillOptions(bool forNetgen)
Inserts options used by the network writer.
Definition: NWFrame.cpp:50
GeoConvHelper::init
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
Definition: GeoConvHelper.cpp:201
SystemFrame::addReportOptions
static void addReportOptions(OptionsCont &oc)
Adds reporting options to the given container.
Definition: SystemFrame.cpp:65
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:330
checkOptions
bool checkOptions()
Definition: netconvert_main.cpp:85
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:52
NBFrame::checkOptions
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NBFrame.cpp:577
OptionsCont::setApplicationName
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.
Definition: OptionsCont.cpp:485
SystemFrame.h
XMLSubSys::setValidation
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:59
NIFrame::fillOptions
static void fillOptions(bool forNetedit=false)
Inserts options used by the network importer and network building modules.
Definition: NIFrame.cpp:49
GeoConvHelper::addProjectionOptions
static void addProjectionOptions(OptionsCont &oc)
Adds projection options to the given container.
Definition: GeoConvHelper.cpp:249
OutputDevice.h
NBNetBuilder.h
ProcessError
Definition: UtilExceptions.h:40
NBNetBuilder::applyOptions
void applyOptions(OptionsCont &oc)
Initialises the storage by applying given options.
Definition: NBNetBuilder.cpp:66
UtilExceptions.h
XMLSubSys::init
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:48
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:90
NBFrame::fillOptions
static void fillOptions(bool forNetgen)
Inserts options used by the network converter.
Definition: NBFrame.cpp:49
NILoader::load
void load(OptionsCont &oc)
Definition: NILoader.cpp:75
OptionsCont::addOptionSubTopic
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
Definition: OptionsCont.cpp:523
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:72
OptionsIO::getOptions
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:76
OptionsCont::setApplicationDescription
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
Definition: OptionsCont.cpp:493
NILoader.h
OptionsCont::addCallExample
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
Definition: OptionsCont.cpp:499
OptionsIO::setArgs
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:55
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:78
config.h
NBFrame.h
RandHelper::insertRandOptions
static void insertRandOptions()
Initialises the given options container with random number options.
Definition: RandHelper.cpp:43
RandHelper.h
SystemFrame::checkOptions
static bool checkOptions()
checks shared options and sets StdDefs
Definition: SystemFrame.cpp:118
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:207
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:245
DistributionCont.h
OptionsIO.h
XMLSubSys.h
main
int main(int argc, char **argv)
Definition: netconvert_main.cpp:98