SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // A reader for a SUMO network's projection description 00010 /****************************************************************************/ 00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00013 /****************************************************************************/ 00014 // 00015 // This file is part of SUMO. 00016 // SUMO is free software: you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation, either version 3 of the License, or 00019 // (at your option) any later version. 00020 // 00021 /****************************************************************************/ 00022 00023 00024 // =========================================================================== 00025 // included modules 00026 // =========================================================================== 00027 #ifdef _MSC_VER 00028 #include <windows_config.h> 00029 #else 00030 #include <config.h> 00031 #endif 00032 00033 #include <string> 00034 #include <map> 00035 #include <fstream> 00036 #include <utils/options/OptionsCont.h> 00037 #include <utils/options/Option.h> 00038 #include <utils/common/StdDefs.h> 00039 #include <polyconvert/PCPolyContainer.h> 00040 #include <utils/common/RGBColor.h> 00041 #include <utils/geom/GeomHelper.h> 00042 #include <utils/geom/Boundary.h> 00043 #include <utils/geom/Position.h> 00044 #include <utils/geom/GeoConvHelper.h> 00045 #include <utils/xml/XMLSubSys.h> 00046 #include <utils/geom/GeomConvHelper.h> 00047 #include <utils/common/MsgHandler.h> 00048 #include <utils/common/FileHelpers.h> 00049 #include <utils/xml/SUMOXMLDefinitions.h> 00050 #include "PCNetProjectionLoader.h" 00051 00052 #ifdef CHECK_MEMORY_LEAKS 00053 #include <foreign/nvwa/debug_new.h> 00054 #endif // CHECK_MEMORY_LEAKS 00055 00056 00057 // =========================================================================== 00058 // method definitions 00059 // =========================================================================== 00060 // --------------------------------------------------------------------------- 00061 // static interface 00062 // --------------------------------------------------------------------------- 00063 void 00064 PCNetProjectionLoader::loadIfSet(OptionsCont& oc, 00065 Position& netOffset, Boundary& origNetBoundary, 00066 Boundary& convNetBoundary, 00067 std::string& projParameter) { 00068 if (!oc.isSet("net")) { 00069 return; 00070 } 00071 // check file 00072 std::string file = oc.getString("net"); 00073 if (!FileHelpers::exists(file)) { 00074 throw ProcessError("Could not open net-file '" + file + "'."); 00075 } 00076 // build handler and parser 00077 PCNetProjectionLoader handler(netOffset, origNetBoundary, convNetBoundary, projParameter); 00078 handler.setFileName(file); 00079 XMLPScanToken token; 00080 XERCES_CPP_NAMESPACE_QUALIFIER SAX2XMLReader* parser = XMLSubSys::getSAXReader(handler); 00081 PROGRESS_BEGIN_MESSAGE("Parsing network projection from '" + file + "'"); 00082 if (!parser->parseFirst(file.c_str(), token)) { 00083 delete parser; 00084 throw ProcessError("Can not read XML-file '" + handler.getFileName() + "'."); 00085 } 00086 // parse 00087 while (parser->parseNext(token) && !handler.hasReadAll()); 00088 // clean up 00089 PROGRESS_DONE_MESSAGE(); 00090 if (!handler.hasReadAll()) { 00091 throw ProcessError("Could not find projection parameter in net."); 00092 } 00093 delete parser; 00094 } 00095 00096 00097 00098 // --------------------------------------------------------------------------- 00099 // handler methods 00100 // --------------------------------------------------------------------------- 00101 PCNetProjectionLoader::PCNetProjectionLoader(Position& netOffset, 00102 Boundary& origNetBoundary, Boundary& convNetBoundary, 00103 std::string& projParameter) 00104 : SUMOSAXHandler("sumo-network"), myNetOffset(netOffset), 00105 myOrigNetBoundary(origNetBoundary), myConvNetBoundary(convNetBoundary), 00106 myProjParameter(projParameter), 00107 myFoundOffset(false), myFoundOrigNetBoundary(false), 00108 myFoundConvNetBoundary(false), myFoundProj(false) {} 00109 00110 00111 PCNetProjectionLoader::~PCNetProjectionLoader() {} 00112 00113 00114 void 00115 PCNetProjectionLoader::myStartElement(int element, 00116 const SUMOSAXAttributes& attrs) { 00117 if (element != SUMO_TAG_LOCATION) { 00118 return; 00119 } 00120 bool ok = true; 00121 PositionVector tmp = GeomConvHelper::parseShapeReporting( 00122 attrs.getOptStringReporting(SUMO_ATTR_NET_OFFSET, 0, ok, ""), 00123 attrs.getObjectType(), 0, ok, false); 00124 if (ok) { 00125 myNetOffset = tmp[0]; 00126 } 00127 myOrigNetBoundary = GeomConvHelper::parseBoundaryReporting( 00128 attrs.getOptStringReporting(SUMO_ATTR_ORIG_BOUNDARY, 0, ok, ""), 00129 attrs.getObjectType(), 0, ok); 00130 myConvNetBoundary = GeomConvHelper::parseBoundaryReporting( 00131 attrs.getOptStringReporting(SUMO_ATTR_CONV_BOUNDARY, 0, ok, ""), 00132 attrs.getObjectType(), 0, ok); 00133 myProjParameter = attrs.getOptStringReporting(SUMO_ATTR_ORIG_PROJ, 0, ok, ""); 00134 myFoundOffset = myFoundOrigNetBoundary = myFoundConvNetBoundary = myFoundProj = ok; 00135 } 00136 00137 00138 void 00139 PCNetProjectionLoader::myCharacters(int element, 00140 const std::string& chars) { 00141 UNUSED_PARAMETER(element); 00142 UNUSED_PARAMETER(chars); 00143 } 00144 00145 00146 bool 00147 PCNetProjectionLoader::hasReadAll() const { 00148 return myFoundOffset && myFoundOrigNetBoundary && myFoundConvNetBoundary && myFoundProj; 00149 } 00150 00151 00152 /****************************************************************************/ 00153