/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file NIXMLPTHandler.h14/// @author Jakob Erdmann15/// @date Sat, 28 Jul 201816///17// Importer for static public transport information18/****************************************************************************/19#pragma once20#include <config.h>2122#include <utils/common/SUMOVehicleClass.h>23#include <utils/geom/PositionVector.h>24#include <utils/xml/SUMOSAXHandler.h>25#include <netbuild/NBEdge.h>26#include <netbuild/NBEdgeCont.h>272829// ===========================================================================30// class declarations31// ===========================================================================32class OptionsCont;33class NBNode;34class NBEdge;35class NBNodeCont;36class NBTypeCont;37class NBDistrictCont;38class NBTrafficLightLogicCont;3940// ===========================================================================41// class definitions42// ===========================================================================43/**44* @class NIXMLPTHandler45* @brief Importer for network edges stored in XML46*47* This SAX-handler parses edge information and stores it in the given48* container.49* @todo revalidate node retrieval50* @todo One day, one should rethink the order of parsing. Now, the handler51* is able to load edges, using information from the types, first, and extending52* them by given information. In addition, if the read edge is already known,53* its values are also used. Then, defining vehicles allowed per lane, and54* additional edge split definitions add some further complexity. This all55* works somehow for most of our use cases, but it's definitely not as consistent56* that everything what seems to be possible would also work appropriately.57*/58class NIXMLPTHandler : public SUMOSAXHandler {59public:60/** @brief Constructor61* @param[in] nc The nodes container (for retrieval of referenced nodes)62* @param[in] ec The edges container (for insertion of build edges)63* @param[in] tc The types container (for retrieval of type defaults)64* @param[in] dc The districts container (needed if an edge must be split)65* @param[in] options The options to use while building edges66*/67NIXMLPTHandler(NBEdgeCont& ec, NBPTStopCont& sc, NBPTLineCont& lc);686970/// @brief Destructor71~NIXMLPTHandler();7273protected:74/// @name inherited from GenericSAXHandler75//@{7677/** @brief Called on the opening of a tag;78*79* @param[in] element ID of the currently opened element80* @param[in] attrs Attributes within the currently opened element81* @exception ProcessError If something fails82* @see GenericSAXHandler::myStartElement83*/84void myStartElement(int element,85const SUMOSAXAttributes& attrs);868788/** @brief Called when a closing tag occurs89*90* @param[in] element ID of the currently opened element91* @exception ProcessError If something fails92* @see GenericSAXHandler::myEndElement93*/94void myEndElement(int element);95//@}969798private:99/** @brief Tries to parse the shape definition100*101* Returns the edge's geometry (may be empty if no one was defined).102* Writes an error message if an error occurred.103* @param[in] attrs The attributes to read the shape from104* @return The edge's shape105*/106PositionVector tryGetShape(const SUMOSAXAttributes& attrs);107108109/** @brief Tries to parse the spread type110*/111LaneSpreadFunction tryGetLaneSpread(const SUMOSAXAttributes& attrs);112113114/** @brief Sets from/to node information of the currently parsed edge115*116* If the nodes could be retrieved/built, they are set in myFromNode/myToNode,117* respectively, and true is returned. If not, false is returned.118* @param[in] attrs The SAX-attributes to parse the nodes from119* @return Whether valid nodes exist120*/121bool setNodes(const SUMOSAXAttributes& attrs);122123124private:125126/// @brief The edges container (for retrieving referenced stop edge)127NBEdgeCont& myEdgeCont;128129/// @brief The stop container (for loading of stops)130NBPTStopCont& myStopCont;131132/// @brief The line container (for loading of lines)133NBPTLineCont& myLineCont;134135/// @brief The currently processed stop136std::shared_ptr<NBPTStop> myCurrentStop;137138/// @brief The currently processed line139NBPTLine* myCurrentLine;140141/// @brief The currently processed stand-alone route142std::string myCurrentRouteID;143144/// @brief the completion level of the current line145double myCurrentCompletion;146147/// @brief element to receive parameters148std::vector<Parameterised*> myLastParameterised;149150/// @brief stand-alone route information151std::map<std::string, std::vector<std::shared_ptr<NBPTStop> > > myRouteStops;152std::map<std::string, EdgeVector > myRouteEdges;153154/// @brief whether the current stop should be discarded155bool myCurrentStopWasIgnored;156157int myMissingBefore;158int myMissingAfter;159160private:161162/** @brief Parses an public transport stop163* @param[in] attrs The attributes to get the stops's values from164*/165void addPTStop(const SUMOSAXAttributes& attrs);166167/** @brief Parses a route as port of a public transport line168* @param[in] attrs The attributes to get the routes's values from169*/170void addPTLineRoute(const SUMOSAXAttributes& attrs);171172/** @brief Parses a stand-alone route when parsing implicit ptlines from173* routes and flows174* @param[in] attrs The attributes to get the routes's values from175*/176void addRoute(const SUMOSAXAttributes& attrs);177178/** @brief Parses an public transport stop reference within a line element179* @param[in] attrs The attributes to get the stops's values from180*/181void addPTLineStop(const SUMOSAXAttributes& attrs);182183/** @brief Parses an public transport stop reference within a route element184* @param[in] attrs The attributes to get the stops's values from185*/186void addRouteStop(const SUMOSAXAttributes& attrs);187188/** @brief Parses an stop access definition189* @param[in] attrs The attributes to get the access's values from190*/191void addAccess(const SUMOSAXAttributes& attrs);192193/** @brief Parses a public transport line194* @param[in] attrs The attributes to get the lines's values from195*/196void addPTLine(const SUMOSAXAttributes& attrs);197198/** @brief Parses a public transport line199* @param[in] attrs The attributes to get the lines's values from200*/201void addPTLineFromFlow(const SUMOSAXAttributes& attrs);202203204private:205/** @brief invalid copy constructor */206NIXMLPTHandler(const NIXMLPTHandler& s);207208/** @brief invalid assignment operator */209NIXMLPTHandler& operator=(const NIXMLPTHandler& s);210211};212213214