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