SUMO - Simulation of Urban MObility
NILoader.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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
21 // Perfoms network import
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 // ===========================================================================
71 // method definitions
72 // ===========================================================================
74  : myNetBuilder(nb) {}
75 
77 
78 void
80  // load types first
81  NIXMLTypesHandler* handler =
83  if (!oc.isSet("type-files")) {
84  std::vector<std::string> files;
85  if (oc.isSet("osm-files")) {
86  files.push_back(osmTypemap);
87  }
88  if (oc.isSet("opendrive-files")) {
89  files.push_back(opendriveTypemap);
90  }
91  loadXMLType(handler, files, "types", true);
92  } else {
93  loadXMLType(handler, oc.getStringVector("type-files"), "types");
94  }
95  // try to load height data so it is ready for use by other importers
97  // try to load using different methods
108  if (oc.getBool("tls.discard-loaded") || oc.getBool("tls.discard-simple")) {
110  oc.getBool("tls.guess-signals"));
111  int removed = myNetBuilder.getTLLogicCont().getNumExtracted();
112  if (removed > 0) {
113  WRITE_MESSAGE(" Removed " + toString(removed) + " traffic lights before loading plain-XML");
114  }
115  }
116  loadXML(oc);
117  // check the loaded structures
118  if (myNetBuilder.getNodeCont().size() == 0) {
119  throw ProcessError("No nodes loaded.");
120  }
121  if (myNetBuilder.getEdgeCont().size() == 0) {
122  throw ProcessError("No edges loaded.");
123  }
124  // report loaded structures
125  WRITE_MESSAGE(" Import done:");
126  if (myNetBuilder.getDistrictCont().size() > 0) {
127  WRITE_MESSAGE(" " + toString(myNetBuilder.getDistrictCont().size()) + " districts loaded.");
128  }
129  WRITE_MESSAGE(" " + toString(myNetBuilder.getNodeCont().size()) + " nodes loaded.");
130  if (myNetBuilder.getTypeCont().size() > 0) {
131  WRITE_MESSAGE(" " + toString(myNetBuilder.getTypeCont().size()) + " types loaded.");
132  }
133  WRITE_MESSAGE(" " + toString(myNetBuilder.getEdgeCont().size()) + " edges loaded.");
136  "The split of edges was performed " + toString(myNetBuilder.getEdgeCont().getNoEdgeSplits()) + " times.");
137  }
138 
139  //TODO: uncomment the following lines + adapt tests! [Gregor March '17]
140 // if (myNetBuilder.getPTStopCont().size() > 0) {
141 // WRITE_MESSAGE(" " + toString(myNetBuilder.getPTStopCont().size()) + " pt stops loaded.");
142 // }
143  if (GeoConvHelper::getProcessing().usingGeoProjection()) {
144  WRITE_MESSAGE("Proj projection parameters used: '" + GeoConvHelper::getProcessing().getProjString() + "'.");
145  }
146 }
147 
148 /* -------------------------------------------------------------------------
149  * file loading methods
150  * ----------------------------------------------------------------------- */
151 void
153  // load nodes
156  oc.getStringVector("node-files"), "nodes");
157  // load the edges
163  oc),
164  oc.getStringVector("edge-files"), "edges");
165  if (!deprecatedVehicleClassesSeen.empty()) {
166  WRITE_WARNING("Deprecated vehicle class(es) '" + toString(deprecatedVehicleClassesSeen) + "' in input edge files.");
167  }
168  // 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 void
180 NILoader::loadXMLType(SUMOSAXHandler* handler, const std::vector<std::string>& files,
181  const std::string& type, const bool stringParse) {
182  // build parser
183  std::string exceptMsg = "";
184  // start the parsing
185  try {
186  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
187  if (stringParse) {
188  handler->setFileName("built in type map");
189  SUMOSAXReader* reader = XMLSubSys::getSAXReader(*handler);
190  reader->parseString(*file);
191  delete reader;
192  continue;
193  }
194  if (!FileHelpers::isReadable(*file)) {
195  WRITE_ERROR("Could not open " + type + "-file '" + *file + "'.");
196  exceptMsg = "Process Error";
197  continue;
198  }
199  PROGRESS_BEGIN_MESSAGE("Parsing " + type + " from '" + *file + "'");
200  XMLSubSys::runParser(*handler, *file);
202  }
203  } catch (const XERCES_CPP_NAMESPACE::XMLException& toCatch) {
204  exceptMsg = TplConvert::_2str(toCatch.getMessage())
205  + "\n The " + type + " could not be loaded from '" + handler->getFileName() + "'.";
206  } catch (const ProcessError& toCatch) {
207  exceptMsg =
208  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::set< std::string > deprecatedVehicleClassesSeen
NBTypeCont & getTypeCont()
Returns a reference to the type container.
Definition: NBNetBuilder.h:166
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:53
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
Definition: GeoConvHelper.h:90
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:57
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:109
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
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:180
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
~NILoader()
Destructor.
Definition: NILoader.cpp:76
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:55
int size() const
Returns the number of nodes stored in this container.
Definition: NBNodeCont.h:243
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:156
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:97
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:201
void load(OptionsCont &oc)
Definition: NILoader.cpp:79
void loadXML(OptionsCont &oc)
Definition: NILoader.cpp:152
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:205
Importer for edge type information stored in XML.
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:161
Instance responsible for building networks.
Definition: NBNetBuilder.h:115
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:98
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:171
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:86
Importer for edge connections stored in XML.
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:202
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:200
NILoader(NBNetBuilder &nb)
Constructor.
Definition: NILoader.cpp:73
NBDistrictCont & getDistrictCont()
Returns a reference the districts container.
Definition: NBNetBuilder.h:176
static std::string _2str(const int var)
convert int to string
Definition: TplConvert.h:56
int size() const
Returns the number of known types.
Definition: NBTypeCont.h:103