LCOV - code coverage report
Current view: top level - src/netload - NLHandler.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 11 11
Test Date: 2024-11-20 15:55:46 Functions: 33.3 % 3 1

            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    NLHandler.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Clemens Honomichl
      18              : /// @author  Michael Behrisch
      19              : /// @date    Sept 2002
      20              : ///
      21              : // The XML-Handler for network loading
      22              : /****************************************************************************/
      23              : #pragma once
      24              : #include <config.h>
      25              : 
      26              : #include <utils/geom/Boundary.h>
      27              : #include <utils/shapes/ShapeHandler.h>
      28              : #include <microsim/MSRouteHandler.h>
      29              : #include "NLDiscreteEventBuilder.h"
      30              : 
      31              : 
      32              : // ===========================================================================
      33              : // class declarations
      34              : // ===========================================================================
      35              : class NLContainer;
      36              : class NLDetectorBuilder;
      37              : class NLEdgeControlBuilder;
      38              : class NLJunctionControlBuilder;
      39              : class NLTriggerBuilder;
      40              : class MSTrafficLightLogic;
      41              : class MSRailSignal;
      42              : 
      43              : 
      44              : // ===========================================================================
      45              : // class definitions
      46              : // ===========================================================================
      47              : 
      48              : 
      49              : /**
      50              :  * @class NLShapeHandler
      51              :  * @brief The XML-Handler for shapes loading network loading
      52              :  *
      53              :  * This subclasses ShapeHandler with MSLane specific function
      54              :  */
      55              : class NLShapeHandler : public ShapeHandler {
      56              : public:
      57        28352 :     NLShapeHandler(const std::string& file, ShapeContainer& sc) :
      58        28352 :         ShapeHandler(file, sc) {}
      59              : 
      60              :     /// @brief Destructor
      61        28352 :     virtual ~NLShapeHandler() {}
      62              : 
      63              :     Position getLanePos(const std::string& poiID, const std::string& laneID, double lanePos, bool friendlyPos, double lanePosLat);
      64              : 
      65          673 :     virtual bool addLanePosParams() {
      66          673 :         return true;
      67              :     }
      68              : };
      69              : 
      70              : 
      71              : /**
      72              :  * @class NLHandler
      73              :  * @brief The XML-Handler for network loading
      74              :  *
      75              :  * The SAX2-handler responsible for parsing networks and routes to load.
      76              :  * This is an extension of the MSRouteHandler as routes and vehicles may also
      77              :  *  be loaded from network descriptions.
      78              :  */
      79              : class NLHandler : public MSRouteHandler {
      80              : public:
      81              :     /// @brief Definition of a lane vector
      82              :     typedef std::vector<MSLane*> LaneVector;
      83              : 
      84              : public:
      85              :     /** @brief Constructor
      86              :      *
      87              :      * @param[in] file Name of the parsed file
      88              :      * @param[in, out] net The network to fill
      89              :      * @param[in] detBuilder The detector builder to use
      90              :      * @param[in] triggerBuilder The trigger builder to use
      91              :      * @param[in] edgeBuilder The builder of edges to use
      92              :      * @param[in] junctionBuilder The builder of junctions to use
      93              :      */
      94              :     NLHandler(const std::string& file, MSNet& net,
      95              :               NLDetectorBuilder& detBuilder, NLTriggerBuilder& triggerBuilder,
      96              :               NLEdgeControlBuilder& edgeBuilder,
      97              :               NLJunctionControlBuilder& junctionBuilder);
      98              : 
      99              : 
     100              :     /// @brief Destructor
     101              :     virtual ~NLHandler();
     102              : 
     103              :     bool haveSeenInternalEdge() const {
     104         5472 :         return myHaveSeenInternalEdge;
     105              :     }
     106              : 
     107              :     bool hasJunctionHigherSpeeds() const {
     108        42335 :         return myHaveJunctionHigherSpeeds;
     109              :     }
     110              : 
     111              :     bool haveSeenDefaultLength() const {
     112         2870 :         return myHaveSeenDefaultLength;
     113              :     }
     114              : 
     115              :     bool haveSeenNeighs() const {
     116              :         return myHaveSeenNeighs;
     117              :     }
     118              : 
     119              :     bool haveSeenAdditionalSpeedRestrictions() const {
     120        28352 :         return myHaveSeenAdditionalSpeedRestrictions;
     121              :     }
     122              : 
     123              :     bool haveSeenMesoEdgeType() const {
     124         2800 :         return myHaveSeenMesoEdgeType;
     125              :     }
     126              : 
     127              :     MMVersion networkVersion() const {
     128       127067 :         return myNetworkVersion;
     129              :     }
     130              : 
     131              :     static Parameterised* addPredecessorConstraint(int element, const SUMOSAXAttributes& attrs, MSRailSignal* rs);
     132              : 
     133              : protected:
     134              :     /// @name inherited from GenericSAXHandler
     135              :     //@{
     136              : 
     137              :     /** @brief Called on the opening of a tag;
     138              :      *
     139              :      * @param[in] element ID of the currently opened element
     140              :      * @param[in] attrs Attributes within the currently opened element
     141              :      * @exception ProcessError If something fails
     142              :      * @see GenericSAXHandler::myStartElement
     143              :      * @todo Refactor/describe
     144              :      */
     145              :     virtual void myStartElement(int element,
     146              :                                 const SUMOSAXAttributes& attrs);
     147              : 
     148              : 
     149              :     /** @brief Called when a closing tag occurs
     150              :      *
     151              :      * @param[in] element ID of the currently opened element
     152              :      * @exception ProcessError If something fails
     153              :      * @see GenericSAXHandler::myEndElement
     154              :      * @todo Refactor/describe
     155              :      */
     156              :     virtual void myEndElement(int element);
     157              :     //@}
     158              : 
     159              : 
     160              : protected:
     161              :     void addParam(const SUMOSAXAttributes& attrs);
     162              : 
     163              :     /** @brief Builds an e1 detector using the given specification
     164              :      * @param[in] attrs The attributes that define the detector
     165              :      */
     166              :     virtual void addE1Detector(const SUMOSAXAttributes& attrs);
     167              : 
     168              :     /** @brief Builds an e1 detector using the given specification
     169              :      * @param[in] attrs The attributes that define the detector
     170              :      */
     171              :     virtual void addInstantE1Detector(const SUMOSAXAttributes& attrs);
     172              : 
     173              :     /** @brief Builds an e2 detector using the given specification
     174              :      * @param[in] attrs The attributes that define the detector
     175              :      */
     176              :     virtual void addE2Detector(const SUMOSAXAttributes& attrs);
     177              : 
     178              :     /** @brief Starts building of an e3 detector using the given specification
     179              :      * @param[in] attrs The attributes that define the detector
     180              :      */
     181              :     void beginE3Detector(const SUMOSAXAttributes& attrs);
     182              : 
     183              :     /** @brief Adds an entry to the currently processed e3 detector
     184              :      * @param[in] attrs The attributes that define the entry
     185              :      */
     186              :     void addE3Entry(const SUMOSAXAttributes& attrs);
     187              : 
     188              :     /** @brief Adds an exit to the currently processed e3 detector
     189              :      * @param[in] attrs The attributes that define the exit
     190              :      */
     191              :     void addE3Exit(const SUMOSAXAttributes& attrs);
     192              : 
     193              :     /// Builds of an e3 detector using collected values
     194              :     virtual void endE3Detector();
     195              : 
     196              :     /** @brief Builds a vtype-detector using the given specification
     197              :      * @param[in] attrs The attributes that define the detector
     198              :      */
     199              :     virtual void addVTypeProbeDetector(const SUMOSAXAttributes& attrs);
     200              : 
     201              :     /** @brief Builds a routeProbe-detector using the given specification
     202              :      * @param[in] attrs The attributes that define the detector
     203              :      */
     204              :     virtual void addRouteProbeDetector(const SUMOSAXAttributes& attrs);
     205              : 
     206              :     /** @brief Builds edge or lane base mean data collector using the given specification
     207              :      * @param[in] attrs The attributes that define the detector
     208              :      * @param[in] objecttype The type (lane/edge) of the parsed mean data definition
     209              :      */
     210              :     virtual void addEdgeLaneMeanData(const SUMOSAXAttributes& attrs, int objecttype);
     211              : 
     212              :     /** @brief Loads edge type specific meso parameters
     213              :      * @param[in] attrs The attributes that hold the parameters
     214              :      */
     215              :     virtual void addMesoEdgeType(const SUMOSAXAttributes& attrs);
     216              : 
     217              :     /** @brief Loads deadlock information for preparing additional rail signal checks
     218              :      * @param[in] attrs The attributes that hold the parameters
     219              :      */
     220              :     virtual void addDeadlock(const SUMOSAXAttributes& attrs);
     221              : 
     222              :     /// Closes the process of building an edge
     223              :     virtual void closeEdge();
     224              : 
     225              : private:
     226              :     /// begins the processing of an edge
     227              :     void beginEdgeParsing(const SUMOSAXAttributes& attrs);
     228              : 
     229              :     /// adds a lane to the previously opened edge
     230              :     void addLane(const SUMOSAXAttributes& attrs);
     231              : 
     232              :     ///  adds a request item to the current junction logic
     233              :     void addRequest(const SUMOSAXAttributes& attrs);
     234              : 
     235              :     /// begins the reading of a junction row logic
     236              :     void initJunctionLogic(const SUMOSAXAttributes& attrs);
     237              : 
     238              :     /// begins the reading of a traffic lights logic
     239              :     void initTrafficLightLogic(const SUMOSAXAttributes& attrs);
     240              : 
     241              :     /// adds a phase to the traffic lights logic currently build
     242              :     void addPhase(const SUMOSAXAttributes& attrs);
     243              : 
     244              :     /// adds a switching condition to the traffic lights logic currently build
     245              :     void addCondition(const SUMOSAXAttributes& attrs);
     246              : 
     247              :     /// adds a switching condition assignment to the traffic lights logic currently build
     248              :     void addAssignment(const SUMOSAXAttributes& attrs);
     249              : 
     250              :     /// adds a switching condition function to the traffic lights logic currently build
     251              :     void addFunction(const SUMOSAXAttributes& attrs);
     252              : 
     253              :     /// adds a switching condition function to the traffic lights logic currently build
     254              :     void closeFunction();
     255              : 
     256              :     /// opens a junction for processing
     257              :     virtual void openJunction(const SUMOSAXAttributes& attrs);
     258              : 
     259              :     void parseLanes(const std::string& junctionID, const std::string& def, std::vector<MSLane*>& into, bool& ok);
     260              : 
     261              :     /// adds a connection
     262              :     void addConnection(const SUMOSAXAttributes& attrs);
     263              : 
     264              :     void addConflict(const SUMOSAXAttributes& attrs);
     265              : 
     266              :     virtual void openWAUT(const SUMOSAXAttributes& attrs);
     267              :     void addWAUTSwitch(const SUMOSAXAttributes& attrs);
     268              :     void addWAUTJunction(const SUMOSAXAttributes& attrs);
     269              : 
     270              :     /// Parses network location description
     271              :     void setLocation(const SUMOSAXAttributes& attrs);
     272              : 
     273              :     /** @begin Parses a district and creates a pseudo edge for it
     274              :      *
     275              :      * Called on the occurrence of a "district" element, this method
     276              :      *  retrieves the id of the district and creates a district type
     277              :      *  edge with this id.
     278              :      *
     279              :      * @param[in] attrs The attributes (of the "district"-element) to parse
     280              :      * @exception ProcessError If an edge given in district@edges is not known
     281              :      */
     282              :     void addDistrict(const SUMOSAXAttributes& attrs);
     283              : 
     284              : 
     285              :     /** @begin Parses a district edge and connects it to the district
     286              :      *
     287              :      * Called on the occurrence of a "dsource" or "dsink" element, this method
     288              :      *  retrieves the id of the approachable edge. If this edge is known
     289              :      *  and valid, the approaching edge is informed about it.
     290              :      *
     291              :      * @param[in] attrs The attributes to parse
     292              :      * @param[in] isSource whether a "dsource or a "dsink" was given
     293              :      * @todo No exception?
     294              :      */
     295              :     void addDistrictEdge(const SUMOSAXAttributes& attrs, bool isSource);
     296              : 
     297              :     /** @begin Parses a roundabout and sets flags for the edges
     298              :      * @param[in] attrs The attributes to parse
     299              :      */
     300              :     void addRoundabout(const SUMOSAXAttributes& attrs);
     301              : 
     302              : 
     303              :     void closeWAUT();
     304              : 
     305              :     /// @brief Parses the given character into an enumeration typed link direction
     306              :     LinkDirection parseLinkDir(const std::string& dir);
     307              : 
     308              :     /// @brief Parses the given character into an enumeration typed link state
     309              :     LinkState parseLinkState(const std::string& state);
     310              : 
     311              : protected:
     312              :     /// @brief The net to fill (preinitialised)
     313              :     MSNet& myNet;
     314              : 
     315              :     /// @brief A builder for object actions
     316              :     NLDiscreteEventBuilder myActionBuilder;
     317              : 
     318              :     /// @brief Information whether the currently parsed edge is internal and not wished, here
     319              :     bool myCurrentIsInternalToSkip;
     320              : 
     321              : 
     322              :     /// @brief The detector builder to use
     323              :     NLDetectorBuilder& myDetectorBuilder;
     324              : 
     325              :     /// @brief The trigger builder to use
     326              :     NLTriggerBuilder& myTriggerBuilder;
     327              : 
     328              :     /// @brief The edge builder to use
     329              :     NLEdgeControlBuilder& myEdgeControlBuilder;
     330              : 
     331              :     /// @brief The junction builder to use
     332              :     NLJunctionControlBuilder& myJunctionControlBuilder;
     333              : 
     334              :     /// The id of the current district
     335              :     std::string myCurrentDistrictID;
     336              : 
     337              :     /// internal information whether a tls-logic is currently read
     338              :     bool myAmParsingTLLogicOrJunction;
     339              : 
     340              :     /// The id of the currently processed WAUT
     341              :     std::string myCurrentWAUTID;
     342              : 
     343              :     /// The id of the currently processed edge type
     344              :     std::string myCurrentTypeID;
     345              : 
     346              :     /// The network offset
     347              :     Position myNetworkOffset;
     348              : 
     349              :     /// The network's boundaries
     350              :     Boundary myOrigBoundary, myConvBoundary;
     351              : 
     352              :     bool myCurrentIsBroken;
     353              : 
     354              :     bool myHaveWarnedAboutInvalidTLType;
     355              : 
     356              :     Parameterised myLastEdgeParameters;
     357              :     std::vector<Parameterised*> myLastParameterised;
     358              : 
     359              :     /// @brief whether the loaded network contains internal lanes
     360              :     bool myHaveSeenInternalEdge;
     361              : 
     362              :     /// @brief Whether the network was built with higher speed on junctions
     363              :     bool myHaveJunctionHigherSpeeds;
     364              : 
     365              :     /// @brief whether the loaded network contains edges with default lengths
     366              :     bool myHaveSeenDefaultLength;
     367              : 
     368              :     /// @brief whether the loaded network contains explicit neighbor lanes
     369              :     bool myHaveSeenNeighs;
     370              : 
     371              :     /// @brief whether additional files contained type-specific speed limits
     372              :     bool myHaveSeenAdditionalSpeedRestrictions;
     373              : 
     374              :     /// @brief whether edge type specific meso paramters were loaded
     375              :     bool myHaveSeenMesoEdgeType;
     376              : 
     377              :     /// @brief the loaded network version
     378              :     MMVersion myNetworkVersion;
     379              : 
     380              :     /// @brief whether the location element was already loadee
     381              :     bool myNetIsLoaded;
     382              : 
     383              :     /// @brief rail signal for which constraints are being loaded
     384              :     MSRailSignal* myConstrainedSignal;
     385              : 
     386              :     /// @brief the link element for the connection currently being parsed
     387              :     MSLink* myCurrentLink = nullptr;
     388              : 
     389              :     /// @brief temporary data for building the junction graph after network parsing is finished
     390              :     typedef std::map<std::string, std::pair<std::string, std::string> > JunctionGraph;
     391              :     JunctionGraph myJunctionGraph;
     392              : 
     393              :     int myPreviousEdgeIdx = 0;
     394              : 
     395              : private:
     396              :     /** invalid copy constructor */
     397              :     NLHandler(const NLHandler& s);
     398              : 
     399              :     /** invalid assignment operator */
     400              :     NLHandler& operator=(const NLHandler& s);
     401              : 
     402              : };
        

Generated by: LCOV version 2.0-1