/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2026 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 NLHandler.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Clemens Honomichl17/// @author Michael Behrisch18/// @date Sept 200219///20// The XML-Handler for network loading21/****************************************************************************/22#pragma once23#include <config.h>2425#include <utils/geom/Boundary.h>26#include <utils/shapes/ShapeHandler.h>27#include <microsim/MSRouteHandler.h>28#include "NLDiscreteEventBuilder.h"293031// ===========================================================================32// class declarations33// ===========================================================================34class NLContainer;35class NLDetectorBuilder;36class NLEdgeControlBuilder;37class NLJunctionControlBuilder;38class NLTriggerBuilder;39class MSTrafficLightLogic;40class MSRailSignal;414243// ===========================================================================44// class definitions45// ===========================================================================464748/**49* @class NLShapeHandler50* @brief The XML-Handler for shapes loading network loading51*52* This subclasses ShapeHandler with MSLane specific function53*/54class NLShapeHandler : public ShapeHandler {55public:56NLShapeHandler(const std::string& file, ShapeContainer& sc) :57ShapeHandler(file, sc) {}5859/// @brief Destructor60virtual ~NLShapeHandler() {}6162Position getLanePos(const std::string& poiID, const std::string& laneID, double lanePos, bool friendlyPos, double lanePosLat);6364virtual bool addLanePosParams() {65return true;66}67};686970/**71* @class NLHandler72* @brief The XML-Handler for network loading73*74* The SAX2-handler responsible for parsing networks and routes to load.75* This is an extension of the MSRouteHandler as routes and vehicles may also76* be loaded from network descriptions.77*/78class NLHandler : public MSRouteHandler {79public:80/// @brief Definition of a lane vector81typedef std::vector<MSLane*> LaneVector;8283public:84/** @brief Constructor85*86* @param[in] file Name of the parsed file87* @param[in, out] net The network to fill88* @param[in] detBuilder The detector builder to use89* @param[in] triggerBuilder The trigger builder to use90* @param[in] edgeBuilder The builder of edges to use91* @param[in] junctionBuilder The builder of junctions to use92*/93NLHandler(const std::string& file, MSNet& net,94NLDetectorBuilder& detBuilder, NLTriggerBuilder& triggerBuilder,95NLEdgeControlBuilder& edgeBuilder,96NLJunctionControlBuilder& junctionBuilder);979899/// @brief Destructor100virtual ~NLHandler();101102bool haveSeenInternalEdge() const {103return myHaveSeenInternalEdge;104}105106bool hasJunctionHigherSpeeds() const {107return myHaveJunctionHigherSpeeds;108}109110bool haveSeenDefaultLength() const {111return myHaveSeenDefaultLength;112}113114bool haveSeenNeighs() const {115return myHaveSeenNeighs;116}117118bool haveSeenAdditionalSpeedRestrictions() const {119return myHaveSeenAdditionalSpeedRestrictions;120}121122bool haveSeenTLSParams() const {123return myHaveSeenTLSParams;124}125126MMVersion networkVersion() const {127return myNetworkVersion;128}129130static Parameterised* addPredecessorConstraint(int element, const SUMOSAXAttributes& attrs, MSRailSignal* rs);131132protected:133/// @name inherited from GenericSAXHandler134//@{135136/** @brief Called on the opening of a tag;137*138* @param[in] element ID of the currently opened element139* @param[in] attrs Attributes within the currently opened element140* @exception ProcessError If something fails141* @see GenericSAXHandler::myStartElement142* @todo Refactor/describe143*/144virtual void myStartElement(int element,145const SUMOSAXAttributes& attrs);146147148/** @brief Called when a closing tag occurs149*150* @param[in] element ID of the currently opened element151* @exception ProcessError If something fails152* @see GenericSAXHandler::myEndElement153* @todo Refactor/describe154*/155virtual void myEndElement(int element);156//@}157158159protected:160void addParam(const SUMOSAXAttributes& attrs);161162/** @brief Builds an e1 detector using the given specification163* @param[in] attrs The attributes that define the detector164*/165virtual void addE1Detector(const SUMOSAXAttributes& attrs);166167/** @brief Builds an e1 detector using the given specification168* @param[in] attrs The attributes that define the detector169*/170virtual void addInstantE1Detector(const SUMOSAXAttributes& attrs);171172/** @brief Builds an e2 detector using the given specification173* @param[in] attrs The attributes that define the detector174*/175virtual void addE2Detector(const SUMOSAXAttributes& attrs);176177/** @brief Starts building of an e3 detector using the given specification178* @param[in] attrs The attributes that define the detector179*/180void beginE3Detector(const SUMOSAXAttributes& attrs);181182/** @brief Adds an entry to the currently processed e3 detector183* @param[in] attrs The attributes that define the entry184*/185void addE3Entry(const SUMOSAXAttributes& attrs);186187/** @brief Adds an exit to the currently processed e3 detector188* @param[in] attrs The attributes that define the exit189*/190void addE3Exit(const SUMOSAXAttributes& attrs);191192/// Builds of an e3 detector using collected values193virtual void endE3Detector();194195/** @brief Builds a vtype-detector using the given specification196* @param[in] attrs The attributes that define the detector197*/198virtual void addVTypeProbeDetector(const SUMOSAXAttributes& attrs);199200/** @brief Builds a routeProbe-detector using the given specification201* @param[in] attrs The attributes that define the detector202*/203virtual void addRouteProbeDetector(const SUMOSAXAttributes& attrs);204205/** @brief Builds edge or lane base mean data collector using the given specification206* @param[in] attrs The attributes that define the detector207* @param[in] objecttype The type (lane/edge) of the parsed mean data definition208*/209virtual void addEdgeLaneMeanData(const SUMOSAXAttributes& attrs, int objecttype);210211/** @brief Loads deadlock information for preparing additional rail signal checks212* @param[in] attrs The attributes that hold the parameters213*/214virtual void addDeadlock(const SUMOSAXAttributes& attrs);215216/// Closes the process of building an edge217virtual void closeEdge();218219private:220/// begins the processing of an edge221void beginEdgeParsing(const SUMOSAXAttributes& attrs);222223/// adds a lane to the previously opened edge224void addLane(const SUMOSAXAttributes& attrs);225226/// adds a request item to the current junction logic227void addRequest(const SUMOSAXAttributes& attrs);228229/// begins the reading of a junction row logic230void initJunctionLogic(const SUMOSAXAttributes& attrs);231232/// begins the reading of a traffic lights logic233void initTrafficLightLogic(const SUMOSAXAttributes& attrs);234235/// adds a phase to the traffic lights logic currently build236void addPhase(const SUMOSAXAttributes& attrs);237238/// adds a switching condition to the traffic lights logic currently build239void addCondition(const SUMOSAXAttributes& attrs);240241/// adds a switching condition assignment to the traffic lights logic currently build242void addAssignment(const SUMOSAXAttributes& attrs);243244/// adds a switching condition function to the traffic lights logic currently build245void addFunction(const SUMOSAXAttributes& attrs);246247/// adds a switching condition function to the traffic lights logic currently build248void closeFunction();249250/// opens a junction for processing251virtual void openJunction(const SUMOSAXAttributes& attrs);252253void parseLanes(const std::string& junctionID, const std::string& def, std::vector<MSLane*>& into, bool& ok);254255/// adds a connection256void addConnection(const SUMOSAXAttributes& attrs);257258void addConflict(const SUMOSAXAttributes& attrs);259260virtual void openWAUT(const SUMOSAXAttributes& attrs);261void addWAUTSwitch(const SUMOSAXAttributes& attrs);262void addWAUTJunction(const SUMOSAXAttributes& attrs);263264/// Parses network location description265void setLocation(const SUMOSAXAttributes& attrs);266267/** @begin Parses a district and creates a pseudo edge for it268*269* Called on the occurrence of a "district" element, this method270* retrieves the id of the district and creates a district type271* edge with this id.272*273* @param[in] attrs The attributes (of the "district"-element) to parse274* @exception ProcessError If an edge given in district@edges is not known275*/276void addDistrict(const SUMOSAXAttributes& attrs);277278279/** @begin Parses a district edge and connects it to the district280*281* Called on the occurrence of a "dsource" or "dsink" element, this method282* retrieves the id of the approachable edge. If this edge is known283* and valid, the approaching edge is informed about it.284*285* @param[in] attrs The attributes to parse286* @param[in] isSource whether a "dsource or a "dsink" was given287* @todo No exception?288*/289void addDistrictEdge(const SUMOSAXAttributes& attrs, bool isSource);290291/** @begin Parses a roundabout and sets flags for the edges292* @param[in] attrs The attributes to parse293*/294void addRoundabout(const SUMOSAXAttributes& attrs);295296297void closeWAUT();298299/// @brief Parses the given character into an enumeration typed link direction300LinkDirection parseLinkDir(const std::string& dir);301302/// @brief Parses the given character into an enumeration typed link state303LinkState parseLinkState(const std::string& state);304305int parseDetectPersons(const std::string& detectPersonsString, const std::string& id, bool& ok);306307protected:308/// @brief The net to fill (preinitialised)309MSNet& myNet;310311/// @brief A builder for object actions312NLDiscreteEventBuilder myActionBuilder;313314/// @brief Information whether the currently parsed edge is internal and not wished, here315bool myCurrentIsInternalToSkip;316317318/// @brief The detector builder to use319NLDetectorBuilder& myDetectorBuilder;320321/// @brief The trigger builder to use322NLTriggerBuilder& myTriggerBuilder;323324/// @brief The edge builder to use325NLEdgeControlBuilder& myEdgeControlBuilder;326327/// @brief The junction builder to use328NLJunctionControlBuilder& myJunctionControlBuilder;329330/// The id of the current district331std::string myCurrentDistrictID;332333/// internal information whether a tls-logic is currently read334bool myAmParsingTLLogicOrJunction;335336/// The id of the currently processed WAUT337std::string myCurrentWAUTID;338339/// The id of the currently processed edge type340std::string myCurrentTypeID;341342/// The network offset343Position myNetworkOffset;344345/// The network's boundaries346Boundary myOrigBoundary, myConvBoundary;347348bool myCurrentIsBroken;349350bool myHaveWarnedAboutInvalidTLType;351352Parameterised myLastEdgeParameters;353std::vector<Parameterised*> myLastParameterised;354355/// @brief whether the loaded network contains internal lanes356bool myHaveSeenInternalEdge;357358/// @brief Whether the network was built with higher speed on junctions359bool myHaveJunctionHigherSpeeds;360361/// @brief whether the loaded network contains edges with default lengths362bool myHaveSeenDefaultLength;363364/// @brief whether the loaded network contains explicit neighbor lanes365bool myHaveSeenNeighs;366367/// @brief whether additional files contained type-specific speed limits368bool myHaveSeenAdditionalSpeedRestrictions;369370/// @brief whether tls params were loaded371bool myHaveSeenTLSParams;372373/// @brief the loaded network version374MMVersion myNetworkVersion;375376/// @brief whether the location element was already loadee377bool myNetIsLoaded;378379/// @brief rail signal for which constraints are being loaded380MSRailSignal* myConstrainedSignal;381382/// @brief the link element for the connection currently being parsed383MSLink* myCurrentLink = nullptr;384385/// @brief temporary data for building the junction graph after network parsing is finished386typedef std::map<std::string, std::pair<std::string, std::string> > JunctionGraph;387JunctionGraph myJunctionGraph;388389int myPreviousEdgeIdx = 0;390391private:392/** invalid copy constructor */393NLHandler(const NLHandler& s);394395/** invalid assignment operator */396NLHandler& operator=(const NLHandler& s);397398};399400401