|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A reader for a SUMO network's projection description 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 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 <map> 00032 #include <fstream> 00033 #include <utils/options/OptionsCont.h> 00034 #include <utils/options/Option.h> 00035 #include <utils/common/StdDefs.h> 00036 #include <polyconvert/PCPolyContainer.h> 00037 #include <utils/common/RGBColor.h> 00038 #include <utils/geom/GeomHelper.h> 00039 #include <utils/geom/Boundary.h> 00040 #include <utils/geom/Position.h> 00041 #include <utils/geom/GeoConvHelper.h> 00042 #include <utils/xml/XMLSubSys.h> 00043 #include <utils/geom/GeomConvHelper.h> 00044 #include <utils/common/MsgHandler.h> 00045 #include <utils/common/FileHelpers.h> 00046 #include <utils/xml/SUMOXMLDefinitions.h> 00047 #include "PCNetProjectionLoader.h" 00048 00049 #ifdef CHECK_MEMORY_LEAKS 00050 #include <foreign/nvwa/debug_new.h> 00051 #endif // CHECK_MEMORY_LEAKS 00052 00053 00054 // =========================================================================== 00055 // method definitions 00056 // =========================================================================== 00057 // --------------------------------------------------------------------------- 00058 // static interface 00059 // --------------------------------------------------------------------------- 00060 void 00061 PCNetProjectionLoader::loadIfSet(OptionsCont& oc, 00062 Position& netOffset, Boundary& origNetBoundary, 00063 Boundary& convNetBoundary, 00064 std::string& projParameter) throw(ProcessError) { 00065 if (!oc.isSet("net")) { 00066 return; 00067 } 00068 // check file 00069 std::string file = oc.getString("net"); 00070 if (!FileHelpers::exists(file)) { 00071 throw ProcessError("Could not open net-file '" + file + "'."); 00072 } 00073 // build handler and parser 00074 PCNetProjectionLoader handler(netOffset, origNetBoundary, convNetBoundary, projParameter); 00075 handler.setFileName(file); 00076 XMLPScanToken token; 00077 XERCES_CPP_NAMESPACE_QUALIFIER SAX2XMLReader* parser = XMLSubSys::getSAXReader(handler); 00078 PROGRESS_BEGIN_MESSAGE("Parsing network projection from '" + file + "'"); 00079 if (!parser->parseFirst(file.c_str(), token)) { 00080 delete parser; 00081 throw ProcessError("Can not read XML-file '" + handler.getFileName() + "'."); 00082 } 00083 // parse 00084 while (parser->parseNext(token) && !handler.hasReadAll()); 00085 // clean up 00086 PROGRESS_DONE_MESSAGE(); 00087 if (!handler.hasReadAll()) { 00088 throw ProcessError("Could not find projection parameter in net."); 00089 } 00090 delete parser; 00091 } 00092 00093 00094 00095 // --------------------------------------------------------------------------- 00096 // handler methods 00097 // --------------------------------------------------------------------------- 00098 PCNetProjectionLoader::PCNetProjectionLoader(Position& netOffset, 00099 Boundary& origNetBoundary, Boundary& convNetBoundary, 00100 std::string& projParameter) throw() 00101 : SUMOSAXHandler("sumo-network"), myNetOffset(netOffset), 00102 myOrigNetBoundary(origNetBoundary), myConvNetBoundary(convNetBoundary), 00103 myProjParameter(projParameter), 00104 myFoundOffset(false), myFoundOrigNetBoundary(false), 00105 myFoundConvNetBoundary(false), myFoundProj(false) {} 00106 00107 00108 PCNetProjectionLoader::~PCNetProjectionLoader() throw() {} 00109 00110 00111 void 00112 PCNetProjectionLoader::myStartElement(int element, 00113 const SUMOSAXAttributes& attrs) throw(ProcessError) { 00114 if (element!=SUMO_TAG_LOCATION) { 00115 return; 00116 } 00117 bool ok = true; 00118 PositionVector tmp = GeomConvHelper::parseShapeReporting( 00119 attrs.getOptStringReporting(SUMO_ATTR_NET_OFFSET, 0, ok, ""), 00120 attrs.getObjectType(), 0, ok, false); 00121 if (ok) { 00122 myNetOffset = tmp[0]; 00123 } 00124 myOrigNetBoundary = GeomConvHelper::parseBoundaryReporting( 00125 attrs.getOptStringReporting(SUMO_ATTR_ORIG_BOUNDARY, 0, ok, ""), 00126 attrs.getObjectType(), 0, ok); 00127 myConvNetBoundary = GeomConvHelper::parseBoundaryReporting( 00128 attrs.getOptStringReporting(SUMO_ATTR_CONV_BOUNDARY, 0, ok, ""), 00129 attrs.getObjectType(), 0, ok); 00130 myProjParameter = attrs.getOptStringReporting(SUMO_ATTR_ORIG_PROJ, 0, ok, ""); 00131 myFoundOffset = myFoundOrigNetBoundary = myFoundConvNetBoundary = myFoundProj = ok; 00132 } 00133 00134 00135 void 00136 PCNetProjectionLoader::myCharacters(int element, 00137 const std::string& chars) throw(ProcessError) { 00138 UNUSED_PARAMETER(element); 00139 UNUSED_PARAMETER(chars); 00140 } 00141 00142 00143 bool 00144 PCNetProjectionLoader::hasReadAll() const throw() { 00145 return myFoundOffset&&myFoundOrigNetBoundary&&myFoundConvNetBoundary&&myFoundProj; 00146 } 00147 00148 00149 /****************************************************************************/ 00150