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-2017 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 // ===========================================================================
72 // method definitions
73 // ===========================================================================
75  : myNetBuilder(nb) {}
76 
78 
79 void
81  // load types first
82  NIXMLTypesHandler* handler =
84  if (!oc.isSet("type-files")) {
85  std::vector<std::string> files;
86  if (oc.isSet("osm-files")) {
87  files.push_back(osmTypemap);
88  }
89  if (oc.isSet("opendrive-files")) {
90  files.push_back(opendriveTypemap);
91  }
92  loadXMLType(handler, files, "types", true);
93  } else {
94  loadXMLType(handler, oc.getStringVector("type-files"), "types");
95  }
96  // try to load height data so it is ready for use by other importers
98  // try to load using different methods
109  if (oc.getBool("tls.discard-loaded") || oc.getBool("tls.discard-simple")) {
111  oc.getBool("tls.guess-signals"));
112  int removed = myNetBuilder.getTLLogicCont().getNumExtracted();
113  if (removed > 0) {
114  WRITE_MESSAGE(" Removed " + toString(removed) + " traffic lights before loading plain-XML");
115  }
116  }
117  loadXML(oc);
118  // check the loaded structures
119  if (myNetBuilder.getNodeCont().size() == 0) {
120  throw ProcessError("No nodes loaded.");
121  }
122  if (myNetBuilder.getEdgeCont().size() == 0) {
123  throw ProcessError("No edges loaded.");
124  }
125  // report loaded structures
126  WRITE_MESSAGE(" Import done:");
127  if (myNetBuilder.getDistrictCont().size() > 0) {
128  WRITE_MESSAGE(" " + toString(myNetBuilder.getDistrictCont().size()) + " districts loaded.");
129  }
130  WRITE_MESSAGE(" " + toString(myNetBuilder.getNodeCont().size()) + " nodes loaded.");
131  if (myNetBuilder.getTypeCont().size() > 0) {
132  WRITE_MESSAGE(" " + toString(myNetBuilder.getTypeCont().size()) + " types loaded.");
133  }
134  WRITE_MESSAGE(" " + toString(myNetBuilder.getEdgeCont().size()) + " edges loaded.");
137  "The split of edges was performed " + toString(myNetBuilder.getEdgeCont().getNoEdgeSplits()) + " times.");
138  }
139 
140  //TODO: uncomment the following lines + adapt tests! [Gregor March '17]
141 // if (myNetBuilder.getPTStopCont().size() > 0) {
142 // WRITE_MESSAGE(" " + toString(myNetBuilder.getPTStopCont().size()) + " pt stops loaded.");
143 // }
144  if (GeoConvHelper::getProcessing().usingGeoProjection()) {
145  WRITE_MESSAGE("Proj projection parameters used: '" + GeoConvHelper::getProcessing().getProjString() + "'.");
146  }
147 }
148 
149 /* -------------------------------------------------------------------------
150  * file loading methods
151  * ----------------------------------------------------------------------- */
152 void
154  // load nodes
157  oc.getStringVector("node-files"), "nodes");
158  // load the edges
164  oc),
165  oc.getStringVector("edge-files"), "edges");
166  if (!deprecatedVehicleClassesSeen.empty()) {
167  WRITE_WARNING("Deprecated vehicle class(es) '" + toString(deprecatedVehicleClassesSeen) + "' in input edge files.");
168  }
169  // 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 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 =
209  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 a reference to the type container.
Definition: NBNetBuilder.h:165
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:54
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:110
#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
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
~NILoader()
Destructor.
Definition: NILoader.cpp:77
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.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
int size() const
Returns the number of nodes stored in this container.
Definition: NBNodeCont.h:229
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:155
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:98
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:80
void loadXML(OptionsCont &oc)
Definition: NILoader.cpp:153
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 a reference to the node container.
Definition: NBNetBuilder.h:160
Instance responsible for building networks.
Definition: NBNetBuilder.h:114
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 a reference to the traffic light logics container.
Definition: NBNetBuilder.h:170
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:74
NBDistrictCont & getDistrictCont()
Returns a reference the districts container.
Definition: NBNetBuilder.h:175
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