SUMO - Simulation of Urban MObility
NIImporter_SUMO.h
Go to the documentation of this file.
00001 /****************************************************************************/
00009 // Importer for networks stored in SUMO format
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 #ifndef NIImporter_SUMO_h
00023 #define NIImporter_SUMO_h
00024 
00025 
00026 // ===========================================================================
00027 // included modules
00028 // ===========================================================================
00029 #ifdef _MSC_VER
00030 #include <windows_config.h>
00031 #else
00032 #include <config.h>
00033 #endif
00034 
00035 #include <string>
00036 #include <map>
00037 #include <utils/xml/SUMOSAXHandler.h>
00038 #include <utils/geom/GeoConvHelper.h>
00039 #include <netbuild/NBLoadedSUMOTLDef.h>
00040 
00041 
00042 // ===========================================================================
00043 // class declarations
00044 // ===========================================================================
00045 class NBNetBuilder;
00046 class NBEdge;
00047 class OptionsCont;
00048 
00049 
00050 // ===========================================================================
00051 // class definitions
00052 // ===========================================================================
00058 class NIImporter_SUMO : public SUMOSAXHandler {
00059 public:
00075     static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
00076 
00078     static NBLoadedSUMOTLDef* initTrafficLightLogic(const SUMOSAXAttributes& attrs, NBLoadedSUMOTLDef* currentTL);
00079 
00081     static void addPhase(const SUMOSAXAttributes& attrs, NBLoadedSUMOTLDef* currentTL);
00082 
00084     static GeoConvHelper* loadLocation(const SUMOSAXAttributes& attrs);
00085 
00086 
00087 protected:
00091     NIImporter_SUMO(NBNetBuilder& nb);
00092 
00093 
00095     ~NIImporter_SUMO() ;
00096 
00097 
00098 
00100 
00101 
00112     void myStartElement(int element,
00113                         const SUMOSAXAttributes& attrs) ;
00114 
00115 
00123     void myCharacters(int element,
00124                       const std::string& chars) ;
00125 
00126 
00133     void myEndElement(int element) ;
00135 
00136 
00137 private:
00139     void _loadNetwork(const OptionsCont& oc);
00140 
00142 
00143 
00147     void addEdge(const SUMOSAXAttributes& attrs);
00148 
00149 
00153     void addLane(const SUMOSAXAttributes& attrs);
00154 
00155 
00159     void addJunction(const SUMOSAXAttributes& attrs);
00160 
00161 
00166     void addSuccEdge(const SUMOSAXAttributes& attrs);
00167 
00168 
00173     void addSuccLane(const SUMOSAXAttributes& attrs);
00174 
00179     void addConnection(const SUMOSAXAttributes& attrs);
00180 
00184     void addProhibition(const SUMOSAXAttributes& attrs);
00185 
00187 
00188 
00189 
00190 private:
00195     struct Connection {
00197         std::string toEdgeID;
00199         unsigned int toLaneIdx;
00201         std::string tlID;
00203         unsigned int tlLinkNo;
00205         bool mayDefinitelyPass;
00206     };
00207 
00208 
00212     struct LaneAttrs {
00214         SUMOReal maxSpeed;
00216         PositionVector shape;
00218         std::vector<Connection> connections;
00220         std::string allow;
00222         std::string disallow;
00224         SUMOReal width;
00226         SUMOReal offset;
00227     };
00228 
00229 
00233     struct EdgeAttrs {
00235         std::string id;
00237         std::string streetName;
00239         std::string type;
00241         std::string func;
00243         std::string fromNode;
00245         std::string toNode;
00247         PositionVector shape;
00249         SUMOReal length;
00251         int priority;
00253         SUMOReal maxSpeed;
00255         std::vector<LaneAttrs*> lanes;
00257         NBEdge* builtEdge;
00259         LaneSpreadFunction lsf;
00260     };
00261 
00262 
00266     struct Prohibition {
00267         std::string prohibitorFrom;
00268         std::string prohibitorTo;
00269         std::string prohibitedFrom;
00270         std::string prohibitedTo;
00271     };
00272 
00273 
00275     std::map<std::string, EdgeAttrs*> myEdges;
00276 
00278     std::vector<Prohibition> myProhibitions;
00279 
00281     NBNetBuilder& myNetBuilder;
00282 
00284     NBNodeCont& myNodeCont;
00285 
00287     NBTrafficLightLogicCont& myTLLCont;
00288 
00290     EdgeAttrs* myCurrentEdge;
00291 
00293     LaneAttrs* myCurrentLane;
00294 
00296     NBLoadedSUMOTLDef* myCurrentTL;
00297 
00299     GeoConvHelper* myLocation;
00300 
00302     bool mySuspectKeepShape;
00303 
00304     bool myHaveWarnedAboutDeprecatedSpreadType;
00305     bool myHaveWarnedAboutDeprecatedMaxSpeed;
00306 
00311     LaneAttrs* getLaneAttrsFromID(EdgeAttrs* edge, std::string lane_id);
00312 
00318     static void interpretLaneID(const std::string& lane_id, std::string& edge_id, unsigned int& index);
00319 
00325     static PositionVector reconstructEdgeShape(const EdgeAttrs* edge, const Position& from, const Position& to);
00326 
00328     static Position readPosition(const SUMOSAXAttributes& attrs, const std::string& id, bool& ok);
00329 
00336     void parseProhibitionConnection(const std::string& attr, std::string& from, std::string& to, bool& ok);
00337 };
00338 
00339 
00340 #endif
00341 
00342 /****************************************************************************/
00343 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines