SUMO - Simulation of Urban MObility
NILoader.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // Perfoms network import
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <string>
39 #include <utils/options/Option.h>
42 #include <utils/common/ToString.h>
47 #include <utils/xml/XMLSubSys.h>
48 #include <netbuild/NBTypeCont.h>
49 #include <netbuild/NBNodeCont.h>
50 #include <netbuild/NBEdgeCont.h>
52 #include <netbuild/NBNetBuilder.h>
68 #include "typemap.h"
69 #include "NILoader.h"
70 
71 #ifdef CHECK_MEMORY_LEAKS
72 #include <foreign/nvwa/debug_new.h>
73 #endif // CHECK_MEMORY_LEAKS
74 
75 
76 // ===========================================================================
77 // method definitions
78 // ===========================================================================
80  : myNetBuilder(nb) {}
81 
82 
84 
85 
86 void
88  // load types first
89  NIXMLTypesHandler* handler =
91  if (!oc.isSet("type-files")) {
92  std::vector<std::string> files;
93  if (oc.isSet("osm-files")) {
94  files.push_back(osmTypemap);
95  }
96  if (oc.isSet("opendrive-files")) {
97  files.push_back(opendriveTypemap);
98  }
99  loadXMLType(handler, files, "types", true);
100  } else {
101  loadXMLType(handler, oc.getStringVector("type-files"), "types");
102  }
103  // try to load height data so it is ready for use by other importers
105  // try to load using different methods
116  if (oc.getBool("tls.discard-loaded") || oc.getBool("tls.discard-simple")) {
118  oc.getBool("tls.guess-signals"));
119  int removed = myNetBuilder.getTLLogicCont().getNumExtracted();
120  if (removed > 0) {
121  WRITE_MESSAGE(" Removed " + toString(removed) + " traffic lights before loading plain-XML");
122  }
123  }
124  loadXML(oc);
125  // check the loaded structures
126  if (myNetBuilder.getNodeCont().size() == 0) {
127  throw ProcessError("No nodes loaded.");
128  }
129  if (myNetBuilder.getEdgeCont().size() == 0) {
130  throw ProcessError("No edges loaded.");
131  }
132  // report loaded structures
133  WRITE_MESSAGE(" Import done:");
134  if (myNetBuilder.getDistrictCont().size() > 0) {
135  WRITE_MESSAGE(" " + toString(myNetBuilder.getDistrictCont().size()) + " districts loaded.");
136  }
137  WRITE_MESSAGE(" " + toString(myNetBuilder.getNodeCont().size()) + " nodes loaded.");
138  if (myNetBuilder.getTypeCont().size() > 0) {
139  WRITE_MESSAGE(" " + toString(myNetBuilder.getTypeCont().size()) + " types loaded.");
140  }
141  WRITE_MESSAGE(" " + toString(myNetBuilder.getEdgeCont().size()) + " edges loaded.");
143  WRITE_MESSAGE("The split of edges was performed " + toString(myNetBuilder.getEdgeCont().getNoEdgeSplits()) + " times.");
144  }
145  if (GeoConvHelper::getProcessing().usingGeoProjection()) {
146  WRITE_MESSAGE("Proj projection parameters used: '" + GeoConvHelper::getProcessing().getProjString() + "'.");
147  }
148 }
149 
150 
151 /* -------------------------------------------------------------------------
152  * file loading methods
153  * ----------------------------------------------------------------------- */
154 void
156  // load nodes
159  oc.getStringVector("node-files"), "nodes");
160  // load the edges
166  oc),
167  oc.getStringVector("edge-files"), "edges");
168  if (!deprecatedVehicleClassesSeen.empty()) {
169  WRITE_WARNING("Deprecated vehicle class(es) '" + toString(deprecatedVehicleClassesSeen) + "' in input edge files.");
170  }
171  // load the connections
173  oc.getStringVector("connection-files"), "connections");
174  // load traffic lights (needs to come last, references loaded edges and connections)
177  oc.getStringVector("tllogic-files"), "traffic lights");
178 }
179 
180 
181 void
182 NILoader::loadXMLType(SUMOSAXHandler* handler, const std::vector<std::string>& files,
183  const std::string& type, const bool stringParse) {
184  // build parser
185  std::string exceptMsg = "";
186  // start the parsing
187  try {
188  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
189  if (stringParse) {
190  handler->setFileName("built in type map");
191  SUMOSAXReader* reader = XMLSubSys::getSAXReader(*handler);
192  reader->parseString(*file);
193  delete reader;
194  continue;
195  }
196  if (!FileHelpers::isReadable(*file)) {
197  WRITE_ERROR("Could not open " + type + "-file '" + *file + "'.");
198  exceptMsg = "Process Error";
199  continue;
200  }
201  PROGRESS_BEGIN_MESSAGE("Parsing " + type + " from '" + *file + "'");
202  XMLSubSys::runParser(*handler, *file);
204  }
205  } catch (const XERCES_CPP_NAMESPACE::XMLException& toCatch) {
206  exceptMsg = TplConvert::_2str(toCatch.getMessage())
207  + "\n The " + type + " could not be loaded from '" + handler->getFileName() + "'.";
208  } catch (const ProcessError& toCatch) {
209  exceptMsg = std::string(toCatch.what()) + "\n The " + type + " could not be loaded from '" + handler->getFileName() + "'.";
210  } catch (...) {
211  exceptMsg = "The " + type + " could not be loaded from '" + handler->getFileName() + "'.";
212  }
213  delete handler;
214  if (exceptMsg != "") {
215  throw ProcessError(exceptMsg);
216  }
217 }
218 
219 /****************************************************************************/
Importer for network edges stored in XML.
std::set< std::string > deprecatedVehicleClassesSeen
NBTypeCont & getTypeCont()
Returns the type container.
Definition: NBNetBuilder.h:169
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:58
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
Definition: GeoConvHelper.h:98
const std::string & getFileName() const
returns the current file name
Importer for edge connections stored in XML.
const std::string osmTypemap
Definition: typemap.h:38
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given ArcView Shape files.
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given dlr-navteq (aka Elmar-fomat) folder.
SAX-reader encapsulation containing binary reader.
Definition: SUMOSAXReader.h:58
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
void parseString(std::string content)
SAX-handler base for SUMO-files.
int getNoEdgeSplits() const
Returns the number of edge splits.
Definition: NBEdgeCont.h:297
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything&#39;s ok.
Definition: XMLSubSys.cpp:114
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads network definition from the assigned option and stores it in the given network builder...
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given OSM file.
void loadXMLType(SUMOSAXHandler *handler, const std::vector< std::string > &files, const std::string &type, const bool stringParse=false)
Definition: NILoader.cpp:182
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
~NILoader()
Destructor.
Definition: NILoader.cpp:83
static void loadIfSet(OptionsCont &oc)
loads heigh map data if any loading options are set
void setFileName(const std::string &name)
Sets the current file name.
Importer for network nodes stored in XML.
int size() const
Returns the number of known nodes.
Definition: NBNodeCont.h:271
NBEdgeCont & getEdgeCont()
Returns the edge container.
Definition: NBNetBuilder.h:153
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given SUMO file.
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given RoboCup Rescue League files.
static SUMOSAXReader * getSAXReader(SUMOSAXHandler &handler)
Builds a reader and assigns the handler to it.
Definition: XMLSubSys.cpp:102
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:202
void load(OptionsCont &oc)
Definition: NILoader.cpp:87
void loadXML(OptionsCont &oc)
Definition: NILoader.cpp:155
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
int size() const
Returns the number of districts inside the container.
const std::string opendriveTypemap
Definition: typemap.h:1
static void loadNetwork(OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given SUMO file.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
Importer for edge type information stored in XML.
NBNodeCont & getNodeCont()
Returns the node container.
Definition: NBNetBuilder.h:161
Instance responsible for building networks.
Definition: NBNetBuilder.h:112
int size() const
Returns the number of edges.
Definition: NBEdgeCont.h:282
int getNumExtracted() const
return the number of extracted traffic light definitions
A storage for options typed value containers)
Definition: OptionsCont.h:99
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads network definition from the assigned option and stores it in the given network builder...
NBTrafficLightLogicCont & getTLLogicCont()
Returns the traffic light logics container.
Definition: NBNetBuilder.h:177
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given ITSUMO network files.
void discardTrafficLights(NBTrafficLightLogicCont &tlc, bool geometryLike, bool guessSignals)
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given MATSIM network files.
NBNetBuilder & myNetBuilder
The network builder to fill with loaded data.
Definition: NILoader.h:87
Importer for edge connections stored in XML.
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:203
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
NILoader(NBNetBuilder &nb)
Constructor.
Definition: NILoader.cpp:79
NBDistrictCont & getDistrictCont()
Returns the districts container.
Definition: NBNetBuilder.h:185
static std::string _2str(const int var)
convert int to string
Definition: TplConvert.h:57
int size() const
Returns the number of known types.
Definition: NBTypeCont.h:104