LCOV - code coverage report
Current view: top level - src/netload - NLHandler.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 12 12
Test Date: 2025-12-06 15:35:27 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-2025 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        23532 :     NLShapeHandler(const std::string& file, ShapeContainer& sc) :
      58        23532 :         ShapeHandler(file, sc) {}
      59              : 
      60              :     /// @brief Destructor
      61        23532 :     virtual ~NLShapeHandler() {}
      62              : 
      63              :     Position getLanePos(const std::string& poiID, const std::string& laneID, double lanePos, bool friendlyPos, double lanePosLat);
      64              : 
      65          868 :     virtual bool addLanePosParams() {
      66          868 :         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         5930 :         return myHaveSeenInternalEdge;
     105              :     }
     106              : 
     107              :     bool hasJunctionHigherSpeeds() const {
     108        38567 :         return myHaveJunctionHigherSpeeds;
     109              :     }
     110              : 
     111              :     bool haveSeenDefaultLength() const {
     112         3166 :         return myHaveSeenDefaultLength;
     113              :     }
     114              : 
     115              :     bool haveSeenNeighs() const {
     116              :         return myHaveSeenNeighs;
     117              :     }
     118              : 
     119              :     bool haveSeenAdditionalSpeedRestrictions() const {
     120        23532 :         return myHaveSeenAdditionalSpeedRestrictions;
     121              :     }
     122              : 
     123              :     bool haveSeenMesoEdgeType() const {
     124         3030 :         return myHaveSeenMesoEdgeType;
     125              :     }
     126              : 
     127              :     bool haveSeenTLSParams() const {
     128         3010 :         return myHaveSeenTLSParams;
     129              :     }
     130              : 
     131              :     MMVersion networkVersion() const {
     132       116033 :         return myNetworkVersion;
     133              :     }
     134              : 
     135              :     static Parameterised* addPredecessorConstraint(int element, const SUMOSAXAttributes& attrs, MSRailSignal* rs);
     136              : 
     137              : protected:
     138              :     /// @name inherited from GenericSAXHandler
     139              :     //@{
     140              : 
     141              :     /** @brief Called on the opening of a tag;
     142              :      *
     143              :      * @param[in] element ID of the currently opened element
     144              :      * @param[in] attrs Attributes within the currently opened element
     145              :      * @exception ProcessError If something fails
     146              :      * @see GenericSAXHandler::myStartElement
     147              :      * @todo Refactor/describe
     148              :      */
     149              :     virtual void myStartElement(int element,
     150              :                                 const SUMOSAXAttributes& attrs);
     151              : 
     152              : 
     153              :     /** @brief Called when a closing tag occurs
     154              :      *
     155              :      * @param[in] element ID of the currently opened element
     156              :      * @exception ProcessError If something fails
     157              :      * @see GenericSAXHandler::myEndElement
     158              :      * @todo Refactor/describe
     159              :      */
     160              :     virtual void myEndElement(int element);
     161              :     //@}
     162              : 
     163              : 
     164              : protected:
     165              :     void addParam(const SUMOSAXAttributes& attrs);
     166              : 
     167              :     /** @brief Builds an e1 detector using the given specification
     168              :      * @param[in] attrs The attributes that define the detector
     169              :      */
     170              :     virtual void addE1Detector(const SUMOSAXAttributes& attrs);
     171              : 
     172              :     /** @brief Builds an e1 detector using the given specification
     173              :      * @param[in] attrs The attributes that define the detector
     174              :      */
     175              :     virtual void addInstantE1Detector(const SUMOSAXAttributes& attrs);
     176              : 
     177              :     /** @brief Builds an e2 detector using the given specification
     178              :      * @param[in] attrs The attributes that define the detector
     179              :      */
     180              :     virtual void addE2Detector(const SUMOSAXAttributes& attrs);
     181              : 
     182              :     /** @brief Starts building of an e3 detector using the given specification
     183              :      * @param[in] attrs The attributes that define the detector
     184              :      */
     185              :     void beginE3Detector(const SUMOSAXAttributes& attrs);
     186              : 
     187              :     /** @brief Adds an entry to the currently processed e3 detector
     188              :      * @param[in] attrs The attributes that define the entry
     189              :      */
     190              :     void addE3Entry(const SUMOSAXAttributes& attrs);
     191              : 
     192              :     /** @brief Adds an exit to the currently processed e3 detector
     193              :      * @param[in] attrs The attributes that define the exit
     194              :      */
     195              :     void addE3Exit(const SUMOSAXAttributes& attrs);
     196              : 
     197              :     /// Builds of an e3 detector using collected values
     198              :     virtual void endE3Detector();
     199              : 
     200              :     /** @brief Builds a vtype-detector using the given specification
     201              :      * @param[in] attrs The attributes that define the detector
     202              :      */
     203              :     virtual void addVTypeProbeDetector(const SUMOSAXAttributes& attrs);
     204              : 
     205              :     /** @brief Builds a routeProbe-detector using the given specification
     206              :      * @param[in] attrs The attributes that define the detector
     207              :      */
     208              :     virtual void addRouteProbeDetector(const SUMOSAXAttributes& attrs);
     209              : 
     210              :     /** @brief Builds edge or lane base mean data collector using the given specification
     211              :      * @param[in] attrs The attributes that define the detector
     212              :      * @param[in] objecttype The type (lane/edge) of the parsed mean data definition
     213              :      */
     214              :     virtual void addEdgeLaneMeanData(const SUMOSAXAttributes& attrs, int objecttype);
     215              : 
     216              :     /** @brief Loads edge type specific meso parameters
     217              :      * @param[in] attrs The attributes that hold the parameters
     218              :      */
     219              :     virtual void addMesoEdgeType(const SUMOSAXAttributes& attrs);
     220              : 
     221              :     /** @brief Loads deadlock information for preparing additional rail signal checks
     222              :      * @param[in] attrs The attributes that hold the parameters
     223              :      */
     224              :     virtual void addDeadlock(const SUMOSAXAttributes& attrs);
     225              : 
     226              :     /// Closes the process of building an edge
     227              :     virtual void closeEdge();
     228              : 
     229              : private:
     230              :     /// begins the processing of an edge
     231              :     void beginEdgeParsing(const SUMOSAXAttributes& attrs);
     232              : 
     233              :     /// adds a lane to the previously opened edge
     234              :     void addLane(const SUMOSAXAttributes& attrs);
     235              : 
     236              :     ///  adds a request item to the current junction logic
     237              :     void addRequest(const SUMOSAXAttributes& attrs);
     238              : 
     239              :     /// begins the reading of a junction row logic
     240              :     void initJunctionLogic(const SUMOSAXAttributes& attrs);
     241              : 
     242              :     /// begins the reading of a traffic lights logic
     243              :     void initTrafficLightLogic(const SUMOSAXAttributes& attrs);
     244              : 
     245              :     /// adds a phase to the traffic lights logic currently build
     246              :     void addPhase(const SUMOSAXAttributes& attrs);
     247              : 
     248              :     /// adds a switching condition to the traffic lights logic currently build
     249              :     void addCondition(const SUMOSAXAttributes& attrs);
     250              : 
     251              :     /// adds a switching condition assignment to the traffic lights logic currently build
     252              :     void addAssignment(const SUMOSAXAttributes& attrs);
     253              : 
     254              :     /// adds a switching condition function to the traffic lights logic currently build
     255              :     void addFunction(const SUMOSAXAttributes& attrs);
     256              : 
     257              :     /// adds a switching condition function to the traffic lights logic currently build
     258              :     void closeFunction();
     259              : 
     260              :     /// opens a junction for processing
     261              :     virtual void openJunction(const SUMOSAXAttributes& attrs);
     262              : 
     263              :     void parseLanes(const std::string& junctionID, const std::string& def, std::vector<MSLane*>& into, bool& ok);
     264              : 
     265              :     /// adds a connection
     266              :     void addConnection(const SUMOSAXAttributes& attrs);
     267              : 
     268              :     void addConflict(const SUMOSAXAttributes& attrs);
     269              : 
     270              :     virtual void openWAUT(const SUMOSAXAttributes& attrs);
     271              :     void addWAUTSwitch(const SUMOSAXAttributes& attrs);
     272              :     void addWAUTJunction(const SUMOSAXAttributes& attrs);
     273              : 
     274              :     /// Parses network location description
     275              :     void setLocation(const SUMOSAXAttributes& attrs);
     276              : 
     277              :     /** @begin Parses a district and creates a pseudo edge for it
     278              :      *
     279              :      * Called on the occurrence of a "district" element, this method
     280              :      *  retrieves the id of the district and creates a district type
     281              :      *  edge with this id.
     282              :      *
     283              :      * @param[in] attrs The attributes (of the "district"-element) to parse
     284              :      * @exception ProcessError If an edge given in district@edges is not known
     285              :      */
     286              :     void addDistrict(const SUMOSAXAttributes& attrs);
     287              : 
     288              : 
     289              :     /** @begin Parses a district edge and connects it to the district
     290              :      *
     291              :      * Called on the occurrence of a "dsource" or "dsink" element, this method
     292              :      *  retrieves the id of the approachable edge. If this edge is known
     293              :      *  and valid, the approaching edge is informed about it.
     294              :      *
     295              :      * @param[in] attrs The attributes to parse
     296              :      * @param[in] isSource whether a "dsource or a "dsink" was given
     297              :      * @todo No exception?
     298              :      */
     299              :     void addDistrictEdge(const SUMOSAXAttributes& attrs, bool isSource);
     300              : 
     301              :     /** @begin Parses a roundabout and sets flags for the edges
     302              :      * @param[in] attrs The attributes to parse
     303              :      */
     304              :     void addRoundabout(const SUMOSAXAttributes& attrs);
     305              : 
     306              : 
     307              :     void closeWAUT();
     308              : 
     309              :     /// @brief Parses the given character into an enumeration typed link direction
     310              :     LinkDirection parseLinkDir(const std::string& dir);
     311              : 
     312              :     /// @brief Parses the given character into an enumeration typed link state
     313              :     LinkState parseLinkState(const std::string& state);
     314              : 
     315              : protected:
     316              :     /// @brief The net to fill (preinitialised)
     317              :     MSNet& myNet;
     318              : 
     319              :     /// @brief A builder for object actions
     320              :     NLDiscreteEventBuilder myActionBuilder;
     321              : 
     322              :     /// @brief Information whether the currently parsed edge is internal and not wished, here
     323              :     bool myCurrentIsInternalToSkip;
     324              : 
     325              : 
     326              :     /// @brief The detector builder to use
     327              :     NLDetectorBuilder& myDetectorBuilder;
     328              : 
     329              :     /// @brief The trigger builder to use
     330              :     NLTriggerBuilder& myTriggerBuilder;
     331              : 
     332              :     /// @brief The edge builder to use
     333              :     NLEdgeControlBuilder& myEdgeControlBuilder;
     334              : 
     335              :     /// @brief The junction builder to use
     336              :     NLJunctionControlBuilder& myJunctionControlBuilder;
     337              : 
     338              :     /// The id of the current district
     339              :     std::string myCurrentDistrictID;
     340              : 
     341              :     /// internal information whether a tls-logic is currently read
     342              :     bool myAmParsingTLLogicOrJunction;
     343              : 
     344              :     /// The id of the currently processed WAUT
     345              :     std::string myCurrentWAUTID;
     346              : 
     347              :     /// The id of the currently processed edge type
     348              :     std::string myCurrentTypeID;
     349              : 
     350              :     /// The network offset
     351              :     Position myNetworkOffset;
     352              : 
     353              :     /// The network's boundaries
     354              :     Boundary myOrigBoundary, myConvBoundary;
     355              : 
     356              :     bool myCurrentIsBroken;
     357              : 
     358              :     bool myHaveWarnedAboutInvalidTLType;
     359              : 
     360              :     Parameterised myLastEdgeParameters;
     361              :     std::vector<Parameterised*> myLastParameterised;
     362              : 
     363              :     /// @brief whether the loaded network contains internal lanes
     364              :     bool myHaveSeenInternalEdge;
     365              : 
     366              :     /// @brief Whether the network was built with higher speed on junctions
     367              :     bool myHaveJunctionHigherSpeeds;
     368              : 
     369              :     /// @brief whether the loaded network contains edges with default lengths
     370              :     bool myHaveSeenDefaultLength;
     371              : 
     372              :     /// @brief whether the loaded network contains explicit neighbor lanes
     373              :     bool myHaveSeenNeighs;
     374              : 
     375              :     /// @brief whether additional files contained type-specific speed limits
     376              :     bool myHaveSeenAdditionalSpeedRestrictions;
     377              : 
     378              :     /// @brief whether edge type specific meso parameters were loaded
     379              :     bool myHaveSeenMesoEdgeType;
     380              :     /// @brief whether tls params were loaded
     381              :     bool myHaveSeenTLSParams;
     382              : 
     383              :     /// @brief the loaded network version
     384              :     MMVersion myNetworkVersion;
     385              : 
     386              :     /// @brief whether the location element was already loadee
     387              :     bool myNetIsLoaded;
     388              : 
     389              :     /// @brief rail signal for which constraints are being loaded
     390              :     MSRailSignal* myConstrainedSignal;
     391              : 
     392              :     /// @brief the link element for the connection currently being parsed
     393              :     MSLink* myCurrentLink = nullptr;
     394              : 
     395              :     /// @brief temporary data for building the junction graph after network parsing is finished
     396              :     typedef std::map<std::string, std::pair<std::string, std::string> > JunctionGraph;
     397              :     JunctionGraph myJunctionGraph;
     398              : 
     399              :     int myPreviousEdgeIdx = 0;
     400              : 
     401              : private:
     402              :     /** invalid copy constructor */
     403              :     NLHandler(const NLHandler& s);
     404              : 
     405              :     /** invalid assignment operator */
     406              :     NLHandler& operator=(const NLHandler& s);
     407              : 
     408              : };
        

Generated by: LCOV version 2.0-1