/****************************************************************************/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 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 haveSeenMesoEdgeType() const {123return myHaveSeenMesoEdgeType;124}125126bool haveSeenTLSParams() const {127return myHaveSeenTLSParams;128}129130MMVersion networkVersion() const {131return myNetworkVersion;132}133134static Parameterised* addPredecessorConstraint(int element, const SUMOSAXAttributes& attrs, MSRailSignal* rs);135136protected:137/// @name inherited from GenericSAXHandler138//@{139140/** @brief Called on the opening of a tag;141*142* @param[in] element ID of the currently opened element143* @param[in] attrs Attributes within the currently opened element144* @exception ProcessError If something fails145* @see GenericSAXHandler::myStartElement146* @todo Refactor/describe147*/148virtual void myStartElement(int element,149const SUMOSAXAttributes& attrs);150151152/** @brief Called when a closing tag occurs153*154* @param[in] element ID of the currently opened element155* @exception ProcessError If something fails156* @see GenericSAXHandler::myEndElement157* @todo Refactor/describe158*/159virtual void myEndElement(int element);160//@}161162163protected:164void addParam(const SUMOSAXAttributes& attrs);165166/** @brief Builds an e1 detector using the given specification167* @param[in] attrs The attributes that define the detector168*/169virtual void addE1Detector(const SUMOSAXAttributes& attrs);170171/** @brief Builds an e1 detector using the given specification172* @param[in] attrs The attributes that define the detector173*/174virtual void addInstantE1Detector(const SUMOSAXAttributes& attrs);175176/** @brief Builds an e2 detector using the given specification177* @param[in] attrs The attributes that define the detector178*/179virtual void addE2Detector(const SUMOSAXAttributes& attrs);180181/** @brief Starts building of an e3 detector using the given specification182* @param[in] attrs The attributes that define the detector183*/184void beginE3Detector(const SUMOSAXAttributes& attrs);185186/** @brief Adds an entry to the currently processed e3 detector187* @param[in] attrs The attributes that define the entry188*/189void addE3Entry(const SUMOSAXAttributes& attrs);190191/** @brief Adds an exit to the currently processed e3 detector192* @param[in] attrs The attributes that define the exit193*/194void addE3Exit(const SUMOSAXAttributes& attrs);195196/// Builds of an e3 detector using collected values197virtual void endE3Detector();198199/** @brief Builds a vtype-detector using the given specification200* @param[in] attrs The attributes that define the detector201*/202virtual void addVTypeProbeDetector(const SUMOSAXAttributes& attrs);203204/** @brief Builds a routeProbe-detector using the given specification205* @param[in] attrs The attributes that define the detector206*/207virtual void addRouteProbeDetector(const SUMOSAXAttributes& attrs);208209/** @brief Builds edge or lane base mean data collector using the given specification210* @param[in] attrs The attributes that define the detector211* @param[in] objecttype The type (lane/edge) of the parsed mean data definition212*/213virtual void addEdgeLaneMeanData(const SUMOSAXAttributes& attrs, int objecttype);214215/** @brief Loads edge type specific meso parameters216* @param[in] attrs The attributes that hold the parameters217*/218virtual void addMesoEdgeType(const SUMOSAXAttributes& attrs);219220/** @brief Loads deadlock information for preparing additional rail signal checks221* @param[in] attrs The attributes that hold the parameters222*/223virtual void addDeadlock(const SUMOSAXAttributes& attrs);224225/// Closes the process of building an edge226virtual void closeEdge();227228private:229/// begins the processing of an edge230void beginEdgeParsing(const SUMOSAXAttributes& attrs);231232/// adds a lane to the previously opened edge233void addLane(const SUMOSAXAttributes& attrs);234235/// adds a request item to the current junction logic236void addRequest(const SUMOSAXAttributes& attrs);237238/// begins the reading of a junction row logic239void initJunctionLogic(const SUMOSAXAttributes& attrs);240241/// begins the reading of a traffic lights logic242void initTrafficLightLogic(const SUMOSAXAttributes& attrs);243244/// adds a phase to the traffic lights logic currently build245void addPhase(const SUMOSAXAttributes& attrs);246247/// adds a switching condition to the traffic lights logic currently build248void addCondition(const SUMOSAXAttributes& attrs);249250/// adds a switching condition assignment to the traffic lights logic currently build251void addAssignment(const SUMOSAXAttributes& attrs);252253/// adds a switching condition function to the traffic lights logic currently build254void addFunction(const SUMOSAXAttributes& attrs);255256/// adds a switching condition function to the traffic lights logic currently build257void closeFunction();258259/// opens a junction for processing260virtual void openJunction(const SUMOSAXAttributes& attrs);261262void parseLanes(const std::string& junctionID, const std::string& def, std::vector<MSLane*>& into, bool& ok);263264/// adds a connection265void addConnection(const SUMOSAXAttributes& attrs);266267void addConflict(const SUMOSAXAttributes& attrs);268269virtual void openWAUT(const SUMOSAXAttributes& attrs);270void addWAUTSwitch(const SUMOSAXAttributes& attrs);271void addWAUTJunction(const SUMOSAXAttributes& attrs);272273/// Parses network location description274void setLocation(const SUMOSAXAttributes& attrs);275276/** @begin Parses a district and creates a pseudo edge for it277*278* Called on the occurrence of a "district" element, this method279* retrieves the id of the district and creates a district type280* edge with this id.281*282* @param[in] attrs The attributes (of the "district"-element) to parse283* @exception ProcessError If an edge given in district@edges is not known284*/285void addDistrict(const SUMOSAXAttributes& attrs);286287288/** @begin Parses a district edge and connects it to the district289*290* Called on the occurrence of a "dsource" or "dsink" element, this method291* retrieves the id of the approachable edge. If this edge is known292* and valid, the approaching edge is informed about it.293*294* @param[in] attrs The attributes to parse295* @param[in] isSource whether a "dsource or a "dsink" was given296* @todo No exception?297*/298void addDistrictEdge(const SUMOSAXAttributes& attrs, bool isSource);299300/** @begin Parses a roundabout and sets flags for the edges301* @param[in] attrs The attributes to parse302*/303void addRoundabout(const SUMOSAXAttributes& attrs);304305306void closeWAUT();307308/// @brief Parses the given character into an enumeration typed link direction309LinkDirection parseLinkDir(const std::string& dir);310311/// @brief Parses the given character into an enumeration typed link state312LinkState parseLinkState(const std::string& state);313314protected:315/// @brief The net to fill (preinitialised)316MSNet& myNet;317318/// @brief A builder for object actions319NLDiscreteEventBuilder myActionBuilder;320321/// @brief Information whether the currently parsed edge is internal and not wished, here322bool myCurrentIsInternalToSkip;323324325/// @brief The detector builder to use326NLDetectorBuilder& myDetectorBuilder;327328/// @brief The trigger builder to use329NLTriggerBuilder& myTriggerBuilder;330331/// @brief The edge builder to use332NLEdgeControlBuilder& myEdgeControlBuilder;333334/// @brief The junction builder to use335NLJunctionControlBuilder& myJunctionControlBuilder;336337/// The id of the current district338std::string myCurrentDistrictID;339340/// internal information whether a tls-logic is currently read341bool myAmParsingTLLogicOrJunction;342343/// The id of the currently processed WAUT344std::string myCurrentWAUTID;345346/// The id of the currently processed edge type347std::string myCurrentTypeID;348349/// The network offset350Position myNetworkOffset;351352/// The network's boundaries353Boundary myOrigBoundary, myConvBoundary;354355bool myCurrentIsBroken;356357bool myHaveWarnedAboutInvalidTLType;358359Parameterised myLastEdgeParameters;360std::vector<Parameterised*> myLastParameterised;361362/// @brief whether the loaded network contains internal lanes363bool myHaveSeenInternalEdge;364365/// @brief Whether the network was built with higher speed on junctions366bool myHaveJunctionHigherSpeeds;367368/// @brief whether the loaded network contains edges with default lengths369bool myHaveSeenDefaultLength;370371/// @brief whether the loaded network contains explicit neighbor lanes372bool myHaveSeenNeighs;373374/// @brief whether additional files contained type-specific speed limits375bool myHaveSeenAdditionalSpeedRestrictions;376377/// @brief whether edge type specific meso parameters were loaded378bool myHaveSeenMesoEdgeType;379/// @brief whether tls params were loaded380bool myHaveSeenTLSParams;381382/// @brief the loaded network version383MMVersion myNetworkVersion;384385/// @brief whether the location element was already loadee386bool myNetIsLoaded;387388/// @brief rail signal for which constraints are being loaded389MSRailSignal* myConstrainedSignal;390391/// @brief the link element for the connection currently being parsed392MSLink* myCurrentLink = nullptr;393394/// @brief temporary data for building the junction graph after network parsing is finished395typedef std::map<std::string, std::pair<std::string, std::string> > JunctionGraph;396JunctionGraph myJunctionGraph;397398int myPreviousEdgeIdx = 0;399400private:401/** invalid copy constructor */402NLHandler(const NLHandler& s);403404/** invalid assignment operator */405NLHandler& operator=(const NLHandler& s);406407};408409410