NILoader.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Perfoms network import
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 
00020 
00021 // ===========================================================================
00022 // included modules
00023 // ===========================================================================
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029 
00030 #include <string>
00031 #include <utils/common/UtilExceptions.h>
00032 #include <utils/common/MsgHandler.h>
00033 #include <utils/options/OptionsCont.h>
00034 #include <utils/options/Option.h>
00035 #include <utils/common/FileHelpers.h>
00036 #include <utils/common/StringUtils.h>
00037 #include <utils/common/ToString.h>
00038 #include <netbuild/NBTypeCont.h>
00039 #include <netbuild/NBNodeCont.h>
00040 #include <netbuild/NBEdgeCont.h>
00041 #include <netbuild/NBNetBuilder.h>
00042 #include <utils/xml/SUMOSAXHandler.h>
00043 #include <netimport/NIXMLEdgesHandler.h>
00044 #include <netimport/NIXMLNodesHandler.h>
00045 #include <netimport/NIXMLTypesHandler.h>
00046 #include <netimport/NIXMLConnectionsHandler.h>
00047 #include <netimport/NIImporter_DlrNavteq.h>
00048 #include <netimport/NIImporter_VISUM.h>
00049 #include <netimport/vissim/NIImporter_Vissim.h>
00050 #include <netimport/NIImporter_ArcView.h>
00051 #include <netimport/NIImporter_SUMO.h>
00052 #include <netimport/NIImporter_RobocupRescue.h>
00053 #include <netimport/NIImporter_OpenStreetMap.h>
00054 #include <netimport/NIImporter_OpenDrive.h>
00055 #include <utils/xml/XMLSubSys.h>
00056 #include "NILoader.h"
00057 #include <utils/common/TplConvert.h>
00058 #include <utils/geom/GeoConvHelper.h>
00059 
00060 #ifdef CHECK_MEMORY_LEAKS
00061 #include <foreign/nvwa/debug_new.h>
00062 #endif // CHECK_MEMORY_LEAKS
00063 
00064 
00065 // ===========================================================================
00066 // method definitions
00067 // ===========================================================================
00068 NILoader::NILoader(NBNetBuilder &nb) throw()
00069         : myNetBuilder(nb) {}
00070 
00071 
00072 NILoader::~NILoader() throw() {}
00073 
00074 
00075 void
00076 NILoader::load(OptionsCont &oc) {
00077     // build the projection
00078     if (!GeoConvHelper::init(oc)) {
00079         throw ProcessError("Could not build projection!");
00080     }
00081     // load types first
00082     NIXMLTypesHandler *handler =
00083         new NIXMLTypesHandler(myNetBuilder.getTypeCont());
00084     loadXMLType(handler, oc.getStringVector("xml-type-files"), "types");
00085     // try to load using different methods
00086     NIImporter_SUMO::loadNetwork(oc, myNetBuilder);
00087     NIImporter_RobocupRescue::loadNetwork(oc, myNetBuilder);
00088     NIImporter_OpenStreetMap::loadNetwork(oc, myNetBuilder);
00089     NIImporter_VISUM::loadNetwork(oc, myNetBuilder);
00090     NIImporter_ArcView::loadNetwork(oc, myNetBuilder);
00091     NIImporter_Vissim::loadNetwork(oc, myNetBuilder);
00092     NIImporter_DlrNavteq::loadNetwork(oc, myNetBuilder);
00093     NIImporter_OpenDrive::loadNetwork(oc, myNetBuilder);
00094     loadXML(oc);
00095     // check the loaded structures
00096     if (myNetBuilder.getNodeCont().size()==0) {
00097         throw ProcessError("No nodes loaded.");
00098     }
00099     if (myNetBuilder.getEdgeCont().size()==0) {
00100         throw ProcessError("No edges loaded.");
00101     }
00102     // report loaded structures
00103     WRITE_MESSAGE(" Import done:");
00104     if (myNetBuilder.getDistrictCont().size()>0) {
00105         WRITE_MESSAGE("   " + toString(myNetBuilder.getDistrictCont().size()) + " districts loaded.");
00106     }
00107     WRITE_MESSAGE("   " + toString(myNetBuilder.getNodeCont().size()) + " nodes loaded.");
00108     if (myNetBuilder.getTypeCont().size()>0) {
00109         WRITE_MESSAGE("   " + toString(myNetBuilder.getTypeCont().size()) + " types loaded.");
00110     }
00111     WRITE_MESSAGE("   " + toString(myNetBuilder.getEdgeCont().size()) + " edges loaded.");
00112     if (myNetBuilder.getEdgeCont().getNoEdgeSplits()>0) {
00113         WRITE_MESSAGE("The split of edges was performed "+ toString(myNetBuilder.getEdgeCont().getNoEdgeSplits()) + " times.");
00114     }
00115     if (GeoConvHelper::usingGeoProjection()) {
00116         WRITE_MESSAGE("Proj projection parameters used: '" + GeoConvHelper::getProjString() + "'.");
00117     }
00118 }
00119 
00120 
00121 /* -------------------------------------------------------------------------
00122  * file loading methods
00123  * ----------------------------------------------------------------------- */
00124 void
00125 NILoader::loadXML(OptionsCont &oc) {
00126     // load nodes
00127     loadXMLType(new NIXMLNodesHandler(myNetBuilder.getNodeCont(),
00128                                       myNetBuilder.getTLLogicCont(), oc),
00129                 oc.getStringVector("xml-node-files"), "nodes");
00130     // load the edges
00131     loadXMLType(new NIXMLEdgesHandler(myNetBuilder.getNodeCont(),
00132                                       myNetBuilder.getEdgeCont(),
00133                                       myNetBuilder.getTypeCont(),
00134                                       myNetBuilder.getDistrictCont(), oc),
00135                 oc.getStringVector("xml-edge-files"), "edges");
00136     // load the connections
00137     loadXMLType(new NIXMLConnectionsHandler(myNetBuilder.getEdgeCont()),
00138                 oc.getStringVector("xml-connection-files"), "connections");
00139 }
00140 
00141 
00143 void
00144 NILoader::loadXMLType(SUMOSAXHandler *handler, const std::vector<std::string> &files,
00145                       const std::string &type) {
00146     // build parser
00147     SAX2XMLReader* parser = XMLSubSys::getSAXReader(*handler);
00148     std::string exceptMsg = "";
00149     // start the parsing
00150     try {
00151         for (std::vector<std::string>::const_iterator file=files.begin(); file!=files.end(); ++file) {
00152             if (!FileHelpers::exists(*file)) {
00153                 MsgHandler::getErrorInstance()->inform("Could not open " + type + "-file '" + *file + "'.");
00154                 exceptMsg = "Process Error";
00155                 continue;
00156             }
00157             handler->setFileName(*file);
00158             MsgHandler::getMessageInstance()->beginProcessMsg("Parsing " + type + " from '" + *file + "'...");
00159             parser->parse(file->c_str());
00160             MsgHandler::getMessageInstance()->endProcessMsg("done.");
00161         }
00162     } catch (const XMLException& toCatch) {
00163         exceptMsg = TplConvert<XMLCh>::_2str(toCatch.getMessage())
00164                     + "\n  The " + type  + " could not be loaded from '" + handler->getFileName() + "'.";
00165     } catch (const ProcessError& toCatch) {
00166         exceptMsg = std::string(toCatch.what()) + "\n  The " + type  + " could not be loaded from '" + handler->getFileName() + "'.";
00167     } catch (...) {
00168         exceptMsg = "The " + type  + " could not be loaded from '" + handler->getFileName() + "'.";
00169     }
00170     delete parser;
00171     delete handler;
00172     if (exceptMsg != "") {
00173         throw ProcessError(exceptMsg);
00174     }
00175 }
00176 
00177 
00178 /****************************************************************************/

Generated on Wed May 5 00:06:34 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6