LCOV - code coverage report
Current view: top level - src/netimport - NIImporter_SUMO.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 6 6 100.0 %
Date: 2024-05-02 15:31:40 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
       4             : // This program and the accompanying materials are made available under the
       5             : // terms of the Eclipse Public License 2.0 which is available at
       6             : // https://www.eclipse.org/legal/epl-2.0/
       7             : // This Source Code may also be made available under the following Secondary
       8             : // Licenses when the conditions for such availability set forth in the Eclipse
       9             : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10             : // or later which is available at
      11             : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12             : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13             : /****************************************************************************/
      14             : /// @file    NIImporter_SUMO.h
      15             : /// @author  Daniel Krajzewicz
      16             : /// @author  Jakob Erdmann
      17             : /// @author  Michael Behrisch
      18             : /// @date    Mon, 14.04.2008
      19             : ///
      20             : // Importer for networks stored in SUMO format
      21             : /****************************************************************************/
      22             : #pragma once
      23             : #include <config.h>
      24             : 
      25             : #include <string>
      26             : #include <map>
      27             : #include <utils/xml/SUMOSAXHandler.h>
      28             : #include <utils/geom/GeoConvHelper.h>
      29             : #include <utils/common/Parameterised.h>
      30             : #include <netbuild/NBLoadedSUMOTLDef.h>
      31             : #include "NIXMLTypesHandler.h"
      32             : 
      33             : 
      34             : // ===========================================================================
      35             : // class declarations
      36             : // ===========================================================================
      37             : class NBNetBuilder;
      38             : class NBEdge;
      39             : class OptionsCont;
      40             : 
      41             : 
      42             : // ===========================================================================
      43             : // class definitions
      44             : // ===========================================================================
      45             : /**
      46             :  * @class NIImporter_SUMO
      47             :  * @brief Importer for networks stored in SUMO format
      48             :  *
      49             :  */
      50             : class NIImporter_SUMO : public SUMOSAXHandler {
      51             : public:
      52             :     /** @brief Loads content of the optionally given SUMO file
      53             :      *
      54             :      * If the option "sumo-net-file" is set, the file stored therein is read and
      55             :      *  the network definition stored therein is stored within the given network
      56             :      *  builder.
      57             :      *
      58             :      * If the option "sumo-net-file" is not set, this method simply returns.
      59             :      *
      60             :      * The loading is done by parsing the network definition as an XML file
      61             :      *  using the SAXinterface and handling the incoming data via this class'
      62             :      *  methods.
      63             :      *
      64             :      * @param[in,out] oc The options to use (option no-internal-links may be modified)
      65             :      * @param[in] nb The network builder to fill
      66             :      */
      67             :     static void loadNetwork(OptionsCont& oc, NBNetBuilder& nb);
      68             : 
      69             :     /// begins the reading of a traffic lights logic
      70             :     static NBLoadedSUMOTLDef* initTrafficLightLogic(const SUMOSAXAttributes& attrs, NBLoadedSUMOTLDef* currentTL);
      71             : 
      72             :     /// adds a phase to the traffic lights logic currently build
      73             :     static void addPhase(const SUMOSAXAttributes& attrs, NBLoadedSUMOTLDef* currentTL);
      74             : 
      75             :     /// Parses network location description and registers it with GeoConveHelper::setLoaded
      76             :     static GeoConvHelper* loadLocation(const SUMOSAXAttributes& attrs, bool setLoaded = true);
      77             : 
      78             : protected:
      79             :     /** @brief Constructor
      80             :      * @param[in] nc The network builder to fill
      81             :      */
      82             :     NIImporter_SUMO(NBNetBuilder& nb);
      83             : 
      84             :     /// @brief Destructor
      85             :     ~NIImporter_SUMO();
      86             : 
      87             :     /// @name inherited from GenericSAXHandler
      88             :     //@{
      89             : 
      90             :     /** @brief Called on the opening of a tag;
      91             :      *
      92             :      * In dependence to the obtained type, an appropriate parsing
      93             :      *  method is called ("addEdge" if an edge encounters, f.e.).
      94             :      *
      95             :      * @param[in] element ID of the currently opened element
      96             :      * @param[in] attrs Attributes within the currently opened element
      97             :      * @exception ProcessError If something fails
      98             :      * @see GenericSAXHandler::myStartElement
      99             :      */
     100             :     void myStartElement(int element,
     101             :                         const SUMOSAXAttributes& attrs);
     102             : 
     103             : 
     104             :     /** @brief Called when a closing tag occurs
     105             :      *
     106             :      * @param[in] element ID of the currently opened element
     107             :      * @exception ProcessError If something fails
     108             :      * @see GenericSAXHandler::myEndElement
     109             :      */
     110             :     void myEndElement(int element);
     111             :     //@}
     112             : 
     113             : 
     114             : private:
     115             :     /// @brief load the network
     116             :     void _loadNetwork(OptionsCont& oc);
     117             : 
     118             :     /// @name Object instance parsing methods
     119             :     //@{
     120             : 
     121             :     /** @brief Parses an edge and stores the values in "myCurrentEdge"
     122             :      * @param[in] attrs The attributes to get the edge's values from
     123             :      */
     124             :     void addEdge(const SUMOSAXAttributes& attrs);
     125             : 
     126             : 
     127             :     /** @brief Parses a lane and stores the values in "myCurrentLane"
     128             :      * @param[in] attrs The attributes to get the lane's values from
     129             :      */
     130             :     void addLane(const SUMOSAXAttributes& attrs);
     131             : 
     132             :     /** @brief parses stop offsets for the current lane or edge
     133             :      * @param[in] attrs The attributes to get the stop offset sepcifics from
     134             :      */
     135             :     void addStopOffsets(const SUMOSAXAttributes& attrs, bool& ok);
     136             : 
     137             :     /** @brief Parses a junction and saves it in the node control
     138             :      * @param[in] attrs The attributes to get the junction's values from
     139             :      */
     140             :     void addJunction(const SUMOSAXAttributes& attrs);
     141             : 
     142             : 
     143             :     /** @brief Parses a reques and saves selected attributes in myCurrentJunction
     144             :      * @param[in] attrs The attributes to get the junction's values from
     145             :      */
     146             :     void addRequest(const SUMOSAXAttributes& attrs);
     147             : 
     148             : 
     149             :     /** @brief Parses a connection and saves it
     150             :      *    into the lane's definition stored in "myCurrentLane"
     151             :      * @param[in] attrs The attributes to get the connection from
     152             :      */
     153             :     void addConnection(const SUMOSAXAttributes& attrs);
     154             : 
     155             :     /** @brief Parses a prohibition and saves it
     156             :      * @param[in] attrs The attributes to get the connection from
     157             :      */
     158             :     void addProhibition(const SUMOSAXAttributes& attrs);
     159             : 
     160             :     /** @brief Parses a roundabout and stores it in myEdgeCont.
     161             :      * @param[in] attrs The attributes to get the roundabouts values from
     162             :      */
     163             :     void addRoundabout(const SUMOSAXAttributes& attrs);
     164             : 
     165             :     //@}
     166             : 
     167             : 
     168             : 
     169             : private:
     170             :     /**
     171             :      * @struct Connection
     172             :      * @brief A connection description.
     173             :      */
     174             :     class Connection final : public Parameterised {
     175             :     public:
     176             :         /// @brief The id of the target edge
     177             :         std::string toEdgeID;
     178             :         /// @brief The index of the target lane
     179             :         int toLaneIdx;
     180             :         /// @brief The id of the traffic light that controls this connection
     181             :         std::string tlID;
     182             :         /// @brief The index of this connection within the controlling traffic light
     183             :         int tlLinkIndex;
     184             :         int tlLinkIndex2;
     185             :         /// @brief Information about being definitely free to drive (on-ramps)
     186             :         bool mayDefinitelyPass;
     187             :         /* @brief Whether the junction must be kept clear coming from this connection
     188             :          * @note: The enum NBEdge::KeepClear is not needed here because data
     189             :          *        from a .net.xml is fully specified */
     190             :         bool keepClear;
     191             :         /// @brief custom position for internal junction on this connection
     192             :         double contPos;
     193             :         /// @brief custom foe visibility for connection
     194             :         double visibility;
     195             :         /// @brief custom permissions for connection
     196             :         SVCPermissions permissions;
     197             :         /// @brief custom lane changing permissions for connection
     198             :         SVCPermissions changeLeft;
     199             :         /// @brief custom lane changing permissions for connection
     200             :         SVCPermissions changeRight;
     201             :         /// @brief custom speed for connection
     202             :         double speed;
     203             :         /// @brief custom friction for connection
     204             :         double friction;
     205             :         /// @brief custom length for connection
     206             :         double customLength;
     207             :         /// @brief custom shape connection
     208             :         PositionVector customShape;
     209             :         /// @brief if set to true, This connection will not be TLS-controlled despite its node being controlled.
     210             :         bool uncontrolled;
     211             :         /// @brief Whether this connection is an indirect left turn
     212             :         bool indirectLeft;
     213             :         /// @brief optional edge type
     214             :         std::string edgeType;
     215             :     };
     216             : 
     217             : 
     218             :     /** @struct LaneAttrs
     219             :      * @brief Describes the values found in a lane's definition
     220             :      */
     221       91951 :     class LaneAttrs final : public Parameterised {
     222             :     public:
     223             :         /// @brief The maximum velocity allowed on this lane
     224             :         double maxSpeed;
     225             :         /// @brief The friction on this lane
     226             :         double friction;
     227             :         /// @brief This lane's shape (may be custom)
     228             :         PositionVector shape;
     229             :         /// @brief This lane's connections
     230             :         std::vector<Connection> connections;
     231             :         /// @brief This lane's allowed vehicle classes
     232             :         std::string allow;
     233             :         /// @brief This lane's disallowed vehicle classes
     234             :         std::string disallow;
     235             :         /// @brief This lane's vehicle classes allowed to change left
     236             :         std::string changeLeft;
     237             :         /// @brief This lane's vehicle classes allowed to change right
     238             :         std::string changeRight;
     239             :         /// @brief The width of this lane
     240             :         double width;
     241             :         /// @brief This lane's offset from the intersection
     242             :         double endOffset;
     243             :         /// @brief This lane's vehicle specific stop offsets
     244             :         StopOffset laneStopOffset;
     245             :         /// @brief Whether this lane is an acceleration lane
     246             :         bool accelRamp;
     247             :         /// @brief This lane's opposite lane
     248             :         std::string oppositeID;
     249             :         /// @brief Whether this lane has a custom shape
     250             :         bool customShape;
     251             :         /// @brief the type of this lane
     252             :         std::string type;
     253             :     };
     254             : 
     255             : 
     256             :     /** @struct EdgeAttrs
     257             :      * @brief Describes the values found in an edge's definition and this edge's lanes
     258             :      */
     259       75096 :     class EdgeAttrs final : public Parameterised {
     260             :     public:
     261             :         /// @brief This edge's id
     262             :         std::string id;
     263             :         /// @brief This edge's street name
     264             :         std::string streetName;
     265             :         /// @brief This edge's type
     266             :         std::string type;
     267             :         /// @brief This edge's function
     268             :         SumoXMLEdgeFunc func;
     269             :         /// @brief The node this edge starts at
     270             :         std::string fromNode;
     271             :         /// @brief The node this edge ends at
     272             :         std::string toNode;
     273             :         /// @brief This edges's shape
     274             :         PositionVector shape;
     275             :         /// @brief The length of the edge if set explicitly
     276             :         double length;
     277             :         /// @brief This edge's priority
     278             :         int priority;
     279             :         /// @brief The maximum velocity allowed on this edge (!!!)
     280             :         double maxSpeed;
     281             :         /// @brief The friction on this edge
     282             :         //double friction;
     283             :         /// @brief This edge's lanes
     284             :         std::vector<LaneAttrs*> lanes;
     285             :         /// @brief The built edge
     286             :         NBEdge* builtEdge;
     287             :         /// @brief The lane spread function
     288             :         LaneSpreadFunction lsf;
     289             :         /// @brief This edge's vehicle specific stop offsets (used for lanes, that do not have a specified stopOffset)
     290             :         StopOffset edgeStopOffset;
     291             :         /// @brief The position at the start of this edge (kilometrage/mileage)
     292             :         double distance;
     293             :         /// @brief the bidi edge
     294             :         std::string bidi;
     295             :     };
     296             : 
     297             : 
     298             :     /** @struct Prohibition
     299             :      * @brief Describes the values found in a prohibition
     300             :      */
     301             :     struct Prohibition {
     302             :         std::string prohibitorFrom;
     303             :         std::string prohibitorTo;
     304             :         std::string prohibitedFrom;
     305             :         std::string prohibitedTo;
     306             :     };
     307             : 
     308             :     /** @struct Crossing
     309             :      * @brief Describes a pedestrian crossing
     310             :      */
     311             :     struct Crossing : public Parameterised {
     312         140 :         Crossing(const std::string& _edgeID) :
     313         280 :             edgeID(_edgeID), customTLIndex(-1), customTLIndex2(-1) {}
     314             : 
     315             :         std::string edgeID;
     316             :         std::vector<std::string> crossingEdges;
     317             :         double width;
     318             :         bool priority;
     319             :         PositionVector customShape;
     320             :         int customTLIndex;
     321             :         int customTLIndex2;
     322             :     };
     323             : 
     324             :     /** @struct WalkingAreaParsedCustomShape
     325             :      * @brief Describes custom shape for a walking area during parsing
     326             :      */
     327           6 :     struct WalkingAreaParsedCustomShape {
     328             :         PositionVector shape;
     329             :         std::vector<std::string> fromEdges;
     330             :         std::vector<std::string> toEdges;
     331             :         std::vector<std::string> fromCrossed;
     332             :         std::vector<std::string> toCrossed;
     333             :         double width;
     334             :     };
     335             : 
     336             :     /** @struct JunctionAttrs
     337             :      * @brief Describes the values found in a junction
     338             :      */
     339        2224 :     struct JunctionAttrs {
     340             :         NBNode* node;
     341             :         // @the list of internal lanes corresponding to each link
     342             :         std::vector<std::string> intLanes;
     343             :         // @brief the complete response definition for all links
     344             :         std::vector<std::string> response;
     345             :     };
     346             : 
     347             :     /// @brief Loaded edge definitions
     348             :     std::map<std::string, EdgeAttrs*> myEdges;
     349             : 
     350             :     /// @brief Loaded prohibitions
     351             :     std::vector<Prohibition> myProhibitions;
     352             : 
     353             :     /// @brief The network builder to fill
     354             :     NBNetBuilder& myNetBuilder;
     355             : 
     356             :     /// @brief The node container to fill
     357             :     NBNodeCont& myNodeCont;
     358             : 
     359             :     /// @brief The node container to fill
     360             :     NBTrafficLightLogicCont& myTLLCont;
     361             : 
     362             :     /// @brief The handler for parsing edge types and restrictions
     363             :     NIXMLTypesHandler myTypesHandler;
     364             : 
     365             :     /// @brief The currently parsed edge's definition (to add loaded lanes to)
     366             :     EdgeAttrs* myCurrentEdge;
     367             : 
     368             :     /// @brief The currently parsed junction definition to help in reconstructing crossings
     369             :     JunctionAttrs myCurrentJunction;
     370             : 
     371             :     /// @brief The currently parsed lanes's definition (to add the shape to)
     372             :     LaneAttrs* myCurrentLane;
     373             : 
     374             :     /// @brief The currently parsed traffic light
     375             :     NBLoadedSUMOTLDef* myCurrentTL;
     376             : 
     377             :     /// @brief The coordinate transformation which was used to build the loaded network.
     378             :     GeoConvHelper* myLocation;
     379             : 
     380             :     /// @brief The pedestrian crossings found in the network
     381             :     std::map<std::string, std::vector<Crossing> > myPedestrianCrossings;
     382             : 
     383             :     /// @brief Map from walkingArea edge IDs to custom shapes
     384             :     std::map<std::string, WalkingAreaParsedCustomShape> myWACustomShapes;
     385             : 
     386             :     /// @brief element to receive parameters
     387             :     std::vector<Parameterised*> myLastParameterised;
     388             : 
     389             :     /// @brief the loaded network version
     390             :     MMVersion myNetworkVersion;
     391             : 
     392             :     /// @brief whether the loaded network contains internal lanes
     393             :     bool myHaveSeenInternalEdge;
     394             : 
     395             :     /// @brief whether the loaded network was built for lefthand traffic
     396             :     bool myAmLefthand;
     397             : 
     398             :     /// @brief whether the the written network should have a different "handedness" (LHT/RHT) than the loaded network
     399             :     bool myChangeLefthand;
     400             : 
     401             :     /// @brief the level of corner detail in the loaded network
     402             :     int myCornerDetail;
     403             : 
     404             :     /// @brief the level of geometry detail for internal lanes in the loaded network
     405             :     int myLinkDetail;
     406             : 
     407             :     /// @brief whether all lanes of an edge should have the same stop line
     408             :     bool myRectLaneCut;
     409             : 
     410             :     /// @brief whether walkingareas must be built
     411             :     bool myWalkingAreas;
     412             : 
     413             :     /// @brief whether turning speed was limited in the network
     414             :     double myLimitTurnSpeed;
     415             : 
     416             :     /// @brief whether foe-relationships where checked at lane-level
     417             :     bool myCheckLaneFoesAll;
     418             :     bool myCheckLaneFoesRoundabout;
     419             :     /// @brief whether some right-of-way checks at traffic light junctions should be disabled
     420             :     bool myTlsIgnoreInternalJunctionJam;
     421             :     /// @brief default spreadType defined in the network
     422             :     std::string myDefaultSpreadType;
     423             :     /// @brief overlap option for loaded network
     424             :     bool myGeomAvoidOverlap;
     425             :     /// @brief higherSpeed  option for loaded network
     426             :     bool myJunctionsHigherSpeed;
     427             :     /// @brief custom settings for internal junction computation
     428             :     double myInternalJunctionsVehicleWidth;
     429             :     /// @brief custom settings for junction shape computation
     430             :     bool myJunctionsMinimalShape;
     431             :     bool myJunctionsEndpointShape;
     432             : 
     433             :     /// @brief loaded roundabout edges
     434             :     std::vector<std::vector<std::string> > myRoundabouts;
     435             : 
     436             :     /// @brief list of node id with rail signals (no NBTrafficLightDefinition exists)
     437             :     std::set<std::string> myRailSignals;
     438             : 
     439             :     /// @brief list of parameter keys to discard
     440             :     std::set<std::string> myDiscardableParams;
     441             : 
     442             : private:
     443             : 
     444             :     /// @brief read position from the given attributes, attribute errors to id
     445             :     static Position readPosition(const SUMOSAXAttributes& attrs, const std::string& id, bool& ok);
     446             : 
     447             :     /** @brief parses connection string of a prohibition (very old school)
     448             :      * @param[in] attr The connection attribute
     449             :      * @param[out] from ID of the source edge
     450             :      * @param[out] to ID of the destination edge
     451             :      * @param[out] ok Whether parsing completed successfully
     452             :      */
     453             :     void parseProhibitionConnection(const std::string& attr, std::string& from, std::string& to, bool& ok);
     454             : };

Generated by: LCOV version 1.14