LCOV - code coverage report
Current view: top level - src/netimport - NIXMLEdgesHandler.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 2 2
Test Date: 2024-12-21 15:45:41 Functions: - 0 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    NIXMLEdgesHandler.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @author  Leonhard Luecken
      19              : /// @date    Tue, 20 Nov 2001
      20              : ///
      21              : // Importer for network edges stored in XML
      22              : /****************************************************************************/
      23              : #pragma once
      24              : #include <config.h>
      25              : 
      26              : #include <utils/common/SUMOVehicleClass.h>
      27              : #include <utils/geom/PositionVector.h>
      28              : #include <utils/xml/SUMOSAXHandler.h>
      29              : #include <netbuild/NBEdge.h>
      30              : #include <netbuild/NBEdgeCont.h>
      31              : 
      32              : 
      33              : // ===========================================================================
      34              : // class declarations
      35              : // ===========================================================================
      36              : class OptionsCont;
      37              : class NBNode;
      38              : class NBEdge;
      39              : class NBNodeCont;
      40              : class NBTypeCont;
      41              : class NBDistrictCont;
      42              : class NBTrafficLightLogicCont;
      43              : 
      44              : // ===========================================================================
      45              : // class definitions
      46              : // ===========================================================================
      47              : /**
      48              :  * @class NIXMLEdgesHandler
      49              :  * @brief Importer for network edges stored in XML
      50              :  *
      51              :  * This SAX-handler parses edge information and stores it in the given
      52              :  *  container.
      53              :  * @todo revalidate node retrieval
      54              :  * @todo One day, one should rethink the order of parsing. Now, the handler
      55              :  *  is able to load edges, using information from the types, first, and extending
      56              :  *  them by given information. In addition, if the read edge is already known,
      57              :  *  its values are also used. Then, defining vehicles allowed per lane, and
      58              :  *  additional edge split definitions add some further complexity. This all
      59              :  *  works somehow for most of our use cases, but it's definitely not as consistent
      60              :  *  that everything what seems to be possible would also work appropriately.
      61              :  */
      62              : class NIXMLEdgesHandler : public SUMOSAXHandler {
      63              : public:
      64              :     /** @brief Constructor
      65              :      * @param[in] nc The nodes container (for retrieval of referenced nodes)
      66              :      * @param[in] ec The edges container (for insertion of build edges)
      67              :      * @param[in] tc The types container (for retrieval of type defaults)
      68              :      * @param[in] dc The districts container (needed if an edge must be split)
      69              :      * @param[in] options The options to use while building edges
      70              :      */
      71              :     NIXMLEdgesHandler(NBNodeCont& nc, NBEdgeCont& ec,
      72              :                       NBTypeCont& tc, NBDistrictCont& dc,
      73              :                       NBTrafficLightLogicCont& tlc,
      74              :                       OptionsCont& options);
      75              : 
      76              : 
      77              :     /// @brief Destructor
      78              :     ~NIXMLEdgesHandler();
      79              : 
      80              : protected:
      81              :     /// @name inherited from GenericSAXHandler
      82              :     //@{
      83              : 
      84              :     /** @brief Called on the opening of a tag;
      85              :      *
      86              :      * @param[in] element ID of the currently opened element
      87              :      * @param[in] attrs Attributes within the currently opened element
      88              :      * @exception ProcessError If something fails
      89              :      * @see GenericSAXHandler::myStartElement
      90              :      */
      91              :     void myStartElement(int element,
      92              :                         const SUMOSAXAttributes& attrs);
      93              : 
      94              : 
      95              :     /** @brief Called when a closing tag occurs
      96              :      *
      97              :      * @param[in] element ID of the currently opened element
      98              :      * @exception ProcessError If something fails
      99              :      * @see GenericSAXHandler::myEndElement
     100              :      */
     101              :     void myEndElement(int element);
     102              :     //@}
     103              : 
     104              : 
     105              : private:
     106              :     /** @brief Tries to parse the shape definition
     107              :      *
     108              :      * Returns the edge's geometry (may be empty if no one was defined).
     109              :      * Writes an error message if an error occurred.
     110              :      * @param[in] attrs The attributes to read the shape from
     111              :      * @return The edge's shape
     112              :      */
     113              :     PositionVector tryGetShape(const SUMOSAXAttributes& attrs);
     114              : 
     115              : 
     116              :     /** @brief Tries to parse the spread type
     117              :      */
     118              :     LaneSpreadFunction tryGetLaneSpread(const SUMOSAXAttributes& attrs);
     119              : 
     120              : 
     121              :     /** @brief Sets from/to node information of the currently parsed edge
     122              :      *
     123              :      * If the nodes could be retrieved/built, they are set in myFromNode/myToNode,
     124              :      *  respectively, and true is returned. If not, false is returned.
     125              :      * @param[in] attrs The SAX-attributes to parse the nodes from
     126              :      * @return Whether valid nodes exist
     127              :      */
     128              :     bool setNodes(const SUMOSAXAttributes& attrs);
     129              : 
     130              : 
     131              : private:
     132              :     /// @brief A reference to the program's options
     133              :     OptionsCont& myOptions;
     134              : 
     135              : 
     136              :     /// @name Currently parsed edge's values
     137              :     /// @{
     138              : 
     139              :     /// @brief The current edge's id
     140              :     std::string myCurrentID;
     141              : 
     142              :     /// @brief The current edge's maximum speed
     143              :     double myCurrentSpeed;
     144              : 
     145              :     /// @brief The current edge's friction
     146              :     double myCurrentFriction;
     147              : 
     148              :     /// @brief The current edge's priority
     149              :     int myCurrentPriority;
     150              : 
     151              :     /// @brief The current edge's number of lanes
     152              :     int myCurrentLaneNo;
     153              : 
     154              :     /// @brief The current edge's lane width
     155              :     double myCurrentWidth;
     156              : 
     157              :     /// @brief The current edge's offset till the destination node
     158              :     double myCurrentEndOffset;
     159              : 
     160              :     /// @brief The current edge's street name
     161              :     std::string myCurrentStreetName;
     162              : 
     163              :     /// @brief The current edge's type
     164              :     std::string myCurrentType;
     165              : 
     166              :     /// @brief The nodes the edge starts and ends at
     167              :     NBNode* myFromNode, *myToNode;
     168              : 
     169              :     /// @brief The current edge's length
     170              :     double myLength;
     171              : 
     172              :     /// @brief The shape of the edge
     173              :     PositionVector myShape;
     174              : 
     175              :     /// @brief Information about how to spread the lanes
     176              :     LaneSpreadFunction myLanesSpread;
     177              : 
     178              :     /// @brief Information about lane permissions
     179              :     SVCPermissions myPermissions;
     180              : 
     181              :     /// @brief Whether the edge shape shall be kept at reinitilization
     182              :     bool myReinitKeepEdgeShape;
     183              : 
     184              :     /// @brief The width of the sidewalk that shall be added to the current edge
     185              :     double mySidewalkWidth;
     186              : 
     187              :     /// @brief The width of the bike lane that shall be added to the current edge
     188              :     double myBikeLaneWidth;
     189              : 
     190              :     /// @}
     191              : 
     192              : 
     193              :     /// @brief Whether this edge definition is an update of a previously inserted edge
     194              :     bool myIsUpdate;
     195              : 
     196              : 
     197              :     /// @name Used instance containers (access to nodes, edges, types, etc.)
     198              :     /// @{
     199              : 
     200              :     /// @brief The nodes container (for retrieval of referenced nodes)
     201              :     NBNodeCont& myNodeCont;
     202              : 
     203              :     /// @brief The edges container (for insertion of build edges)
     204              :     NBEdgeCont& myEdgeCont;
     205              : 
     206              :     /// @brief The types container (for retrieval of type defaults)
     207              :     NBTypeCont& myTypeCont;
     208              : 
     209              :     /// @brief The districts container (needed if an edge must be split)
     210              :     NBDistrictCont& myDistrictCont;
     211              : 
     212              :     /** @brief The traffic lights container to add built tls to (when
     213              :      * invalidating tls because of splits) */
     214              :     NBTrafficLightLogicCont& myTLLogicCont;
     215              :     /// @}
     216              : 
     217              : 
     218              :     /// @brief The currently processed edge
     219              :     NBEdge* myCurrentEdge;
     220              : 
     221              :     /// @brief The currently processed lane index
     222              :     int myCurrentLaneIndex;
     223              : 
     224              :     /// @brief The list of this edge's splits
     225              :     std::vector<NBEdgeCont::Split> mySplits;
     226              : 
     227              :     /** @class split_by_pos_finder
     228              :      * @brief Finds a split at the given position
     229              :      */
     230              :     class split_by_pos_finder {
     231              :     public:
     232              :         /// @brief Constructor
     233              :         explicit split_by_pos_finder(double pos)
     234          199 :             : myPosition(pos) { }
     235              : 
     236              :         /// @brief Comparing operator
     237              :         bool operator()(const NBEdgeCont::Split& e) {
     238           93 :             return e.pos == myPosition;
     239              :         }
     240              : 
     241              :     private:
     242              :         /// @brief The position to search for
     243              :         double myPosition;
     244              : 
     245              :     };
     246              : 
     247              : 
     248              :     /// @brief Information whether at least one edge's attributes were overwritten
     249              :     bool myHaveReportedAboutOverwriting;
     250              : 
     251              :     /// @brief Information whether at least one edge's type was changed
     252              :     bool myHaveReportedAboutTypeOverride;
     253              : 
     254              :     bool myHaveWarnedAboutDeprecatedLaneId;
     255              : 
     256              :     /// @brief Whether the edge shape shall be kept generally
     257              :     const bool myKeepEdgeShape;
     258              : 
     259              :     /// @brief element to receive parameters
     260              :     std::vector<Parameterised*> myLastParameterised;
     261              : 
     262              :     /// @brief The coordinate transformation which was used compute the node coordinates
     263              :     GeoConvHelper* myLocation = nullptr;
     264              : 
     265              : private:
     266              : 
     267              :     /** @brief Parses an edge and stores the values in "myCurrentEdge"
     268              :      * @param[in] attrs The attributes to get the edge's values from
     269              :      */
     270              :     void addEdge(const SUMOSAXAttributes& attrs);
     271              : 
     272              :     /** @brief parses delete tag and deletes the specified edge or lane
     273              :      * @param[in] attrs The attributes to get the edge id and the optional lane index from
     274              :      */
     275              :     void deleteEdge(const SUMOSAXAttributes& attrs);
     276              : 
     277              :     /** @brief Parses a lane and modifies myCurrentEdge according to the given
     278              :      * attribures
     279              :      * @param[in] attrs The attributes to get the lanes's values from
     280              :      */
     281              :     void addLane(const SUMOSAXAttributes& attrs);
     282              : 
     283              :     /** @brief Parses a split and stores it in mySplits. Splits are executed Upon reading the end
     284              :      * tag of an edge
     285              :      * @param[in] attrs The attributes to get the splits's values from
     286              :      */
     287              :     void addSplit(const SUMOSAXAttributes& attrs);
     288              : 
     289              :     /** @brief Parses a roundabout and stores it in myEdgeCont.
     290              :      * @param[in] attrs The attributes to get the roundabouts values from
     291              :      */
     292              :     void addRoundabout(const SUMOSAXAttributes& attrs);
     293              : 
     294              : 
     295              : private:
     296              :     /** @brief invalid copy constructor */
     297              :     NIXMLEdgesHandler(const NIXMLEdgesHandler& s);
     298              : 
     299              :     /** @brief invalid assignment operator */
     300              :     NIXMLEdgesHandler& operator=(const NIXMLEdgesHandler& s);
     301              : 
     302              : };
        

Generated by: LCOV version 2.0-1