/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2002-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 NLTriggerBuilder.h14/// @author Daniel Krajzewicz15/// @author Tino Morenz16/// @author Eric Nicolay17/// @author Michael Behrisch18/// @author Jakob Erdmann19/// @date Thu, 17 Oct 200220///21// Builds trigger objects for microsim22/****************************************************************************/23#pragma once24#include <config.h>2526#include <string>27#include <vector>28#include <utils/common/RGBColor.h>293031// ===========================================================================32// class declarations33// ===========================================================================34class MSTrigger;35class MSNet;36class MSLaneSpeedTrigger;37class NLHandler;38class MSTriggeredRerouter;39class MSLane;40class MSEdge;41class MSStoppingPlace;42class MSCalibrator;43class MSRouteProbe;4445class METriggeredCalibrator;464748// ===========================================================================49// class definitions50// ===========================================================================51/**52* @class NLTriggerBuilder53* @brief Builds trigger objects for microsim54*55* The building methods may be overridden, to build guisim-instances of the triggers,56* for example.57*58*/59class NLTriggerBuilder {60public:61/// @brief Constructor62NLTriggerBuilder();636465/// @brief Destructor66virtual ~NLTriggerBuilder();6768/** @brief Sets the parent handler to use for nested parsing69*70* @param[in] handler The netload handler to set71*/72void setHandler(NLHandler* handler);737475/** @brief Builds a vaporization76*77* Parses the attributes, reporting errors if the time values are false78* or the edge is not known.79* Instatiates events for enabling and disabling the vaporization otherwise.80*81* @param[in] attrs SAX-attributes which define the vaporizer82* @note recheck throwing the exception83*/84void buildVaporizer(const SUMOSAXAttributes& attrs);858687/// @name parsing methods88///89/// These methods parse the attributes for each of the described trigger90/// and call the according methods to build the trigger91//@{92/** @brief Parses his values and builds a lane speed trigger93*94* If one of the declaration values is errornous, an InvalidArgument is thrown.95*96* If the XML-file parsed during initialisation is errornous, and the97* MSLaneSpeedTrigger-constructor throws a ProcessError due to this, this98* exception is catched and an InvalidArgument with the message given in the99* ProcessError is thrown.100*101* @param[in] net The network the lane speed trigger belongs to102* @param[in] attrs SAX-attributes which define the trigger103* @param[in] base The base path104* @exception InvalidArgument If a parameter (lane/position) is not valid or the read definition is errornous105* @see buildLaneSpeedTrigger106*/107void parseAndBuildLaneSpeedTrigger(MSNet& net, const SUMOSAXAttributes& attrs,108const std::string& base);109110111/** @brief Parses his values and builds a rerouter112*113* @param[in] net The network the rerouter belongs to114* @param[in] attrs SAX-attributes which define the trigger115* @exception InvalidArgument If a parameter (edge) is not valid116*/117void parseAndBuildRerouter(MSNet& net, const SUMOSAXAttributes& attrs);118119120/** @brief Parses the values and builds a stopping places for busses, trains or container vehicles121*122* @param[in] net The network the stop belongs to123* @param[in] attrs SAX-attributes which define the stop124* @param[in] element which kind of stop is to be built125* @exception InvalidArgument If a parameter (lane/position) is not valid126*/127void parseAndBuildStoppingPlace(MSNet& net, const SUMOSAXAttributes& attrs, const SumoXMLTag element);128129130/** @brief Begin a parking area131*132* Simply calls the MSParkingArea constructor.133*134* @param[in] net The net the parking area belongs to135* @param[in] id The id of the parking area136* @param[in] lines Names of the lines that halt on this parking area137* @param[in] badges Names which grant access to this parking area138* @param[in] lane The lane the parking area is placed on139* @param[in] frompos Begin position of the parking area on the lane140* @param[in] topos End position of the parking area on the lane141* @param[in] capacity Capacity of the parking area142* @param[in] width Width of the default lot rectangle143* @param[in] length Length of the default lot rectangle144* @param[in] angle Angle of the default lot rectangle145* @exception InvalidArgument If the parking area can not be added to the net (is duplicate)146*/147virtual void beginParkingArea(MSNet& net,148const std::string& id, const std::vector<std::string>& lines,149const std::vector<std::string>& badges,150MSLane* lane, double frompos, double topos,151unsigned int capacity,152double width, double length, double angle, const std::string& name,153bool onRoad,154const std::string& departPos,155bool lefthand);156157158/** @brief Add a lot entry to current parking area159*160* Simply calls the addLotEntry method for current parking area.161*162* @param[in] x X position of the lot center163* @param[in] y Y position of the lot center164* @param[in] z Z position of the lot center165* @param[in] width Width of the lot rectangle166* @param[in] length Length of the lot rectangle167* @param[in] angle Angle of the lot rectangle168* @param[in] slope Slope of the lot rectangle169* @exception InvalidArgument If the current parking area is 0170*/171void addLotEntry(double x, double y, double z,172double width, double length,173double angle, double slope);174175176177/** @brief Parses the values and adds an access point to the currently parsed stopping place178*179* @param[in] net The network the stop belongs to180* @param[in] attrs SAX-attributes which define the access181* @exception InvalidArgument If a parameter (lane/position) is not valid182*/183void addAccess(MSNet& net, const SUMOSAXAttributes& attrs);184185186/** @brief Parses his values and builds a parking area187*188* @param[in] net The network the parking area belongs to189* @param[in] attrs SAX-attributes which define the trigger190* @exception InvalidArgument If a parameter (lane/position) is not valid191*/192void parseAndBeginParkingArea(MSNet& net, const SUMOSAXAttributes& attrs);193194195/** @brief Parses his values and adds a lot entry to current parking area196*197* @param[in] attrs SAX-attributes which define the lot entry198*/199void parseAndAddLotEntry(const SUMOSAXAttributes& attrs);200201202/** @brief End a parking area203*204* @exception InvalidArgument If the current parking area is 0205*/206virtual void endParkingArea();207208/** @brief End a stopping place209*210* @exception InvalidArgument If the current stopping place is 0211*/212virtual void endStoppingPlace();213214215/** @brief Parses his values and builds a charging station216*217* @param[in] net The network the charging station belongs to218* @param[in] attrs SAXattributes which define the trigger219* @exception InvalidArgument If a parameter (lane/position) is not valid220*/221void parseAndBuildChargingStation(MSNet& net, const SUMOSAXAttributes& attrs);222223/** @brief Parses its values and builds an overhead wire segment224*225* @param[in] net The network the overhead wire segment belongs to226* @param[in] attrs SAXattributes which define the trigger227* @exception InvalidArgument If a parameter (lane/position) is not valid228*/229void parseAndBuildOverheadWireSegment(MSNet& net, const SUMOSAXAttributes& attrs);230231/** @brief Parses its values and builds an overhead wire section232*233* @param[in] net The network the overhead wire segment belongs to234* @param[in] attrs SAXattributes which define the trigger235* @exception InvalidArgument If a substationId is not known, a segment is not known or is assigned to another overheadWireSection236*/237void parseAndBuildOverheadWireSection(MSNet& net, const SUMOSAXAttributes& attrs);238239/** @brief Parses its values and builds a traction substation240*241* @param[in] net The network the overhead wire segment belongs to242* @param[in] attrs SAXattributes which define the trigger243* @exception InvalidArgument If the id is not given or is empty...244*/245void parseAndBuildTractionSubstation(MSNet& net, const SUMOSAXAttributes& attrs);246247/** @brief Parses its values and builds an overhead wire clamp248*249* An overhead wire clamp is a conductive connection of wires in the opposite direction over the road250*251* @param[in] net The network the overhead wire clamp belongs to252* @param[in] attrs SAXattributes which define the trigger253* @exception InvalidArgument If the traction substation is not found in the net or if the start or end segment belongs to a different traction substation254*/255void parseAndBuildOverheadWireClamp(MSNet& net, const SUMOSAXAttributes& attrs);256257/** @brief Parses his values and builds a mesoscopic or microscopic calibrator258*259* @param[in] net The network the calibrator belongs to260* @param[in] attrs SAX-attributes which define the trigger261* @param[in] base The base path262* @exception InvalidArgument If a parameter (edge/position) is not valid263*/264void parseAndBuildCalibrator(MSNet& net, const SUMOSAXAttributes& attrs,265const std::string& base);266267/** @brief updates the parkingArea default capacity268*/269void updateParkingAreaDefaultCapacity();270//@}271272273MSStoppingPlace* getCurrentStop();274275276protected:277/// @name building methods278///279/// Called with parsed values, these methods build the trigger.280///281/// These methods should be overriden for the gui loader in order282/// to build visualizable versions of the triggers.283///284/// In most cases, these methods only call the constructor.285//@{286287/** @brief Builds a lane speed trigger288*289* Simply calls the MSLaneSpeedTrigger constructor.290*291* @param[in] net The net the lane speed trigger belongs to292* @param[in] id The id of the lane speed trigger293* @param[in] destLanes List of lanes affected by this speed trigger294* @param[in] file Name of the file to read the speeds to set from295* @see MSLaneSpeedTrigger296* @exception ProcessError If the XML definition file is errornous297*/298virtual MSLaneSpeedTrigger* buildLaneSpeedTrigger(MSNet& net,299const std::string& id, const std::vector<MSLane*>& destLanes,300const std::string& file);301302303/** @brief Builds a stopping place304*305* Simply calls the MSStoppingPlace constructor.306*307* @param[in] net The net the stop belongs to308* @param[in] id The id of the stop309* @param[in] lines Names of the lines that halt on this bus stop310* @param[in] lane The lane the stop is placed on311* @param[in] frompos Begin position of the stop on the lane312* @param[in] topos End position of the stop on the lane313* @param[in] element which kind of stop is to be built314* @exception InvalidArgument If the stop can not be added to the net (is duplicate)315*/316virtual void buildStoppingPlace(MSNet& net, std::string id, std::vector<std::string> lines, MSLane* lane,317double frompos, double topos, const SumoXMLTag element, std::string string,318int personCapacity, double parkingLength, RGBColor& color, double angle);319320/** @brief Builds a charging station321*322* Simply calls the MSChargingStation constructor and adds the result to the network.323*324* @param[in] net The net the charging station belongs to325* @param[in] id The id of the charging station326* @param[in] lane The lane the charging station is placed on327* @param[in] frompos Begin position of the charging station on the lane328* @param[in] topos End position of the charging station on the lane329* @param[in] chargingPower nominal energy charged in every timeStep per vehicle330* @param[in] totalPower max energy charged in every timestep by all vehicles together331* @param[in] efficiency efficiency of the charge332* @param[in] chargeInTransit enable or disable charge in transit333* @param[in] chargeDelay delay in the charge334* @param[in] chargeType charge type (normal, electric or fuel)335* @param[in] waitingTime waiting time until start charging336* @param[in] parkingArea The associated parking area337* @exception InvalidArgument If the charging station can not be added to the net (is duplicate)338*/339virtual void buildChargingStation(MSNet& net, const std::string& id, MSLane* lane, double frompos, double topos, const std::string& name,340double chargingPower, double totalPower, double efficiency, bool chargeInTransit, SUMOTime chargeDelay,341std::string chargeType, SUMOTime waitingTime, MSParkingArea* parkingArea);342343/** @brief Builds an overhead wire segment344*345* Simply calls the MSOverheadWire constructor and adds the result to the network.346*347* @param[in] net The net the overhead wire segment belongs to348* @param[in] id The id of the overhead wire segment349* @param[in] lane The lane the overhead wire segment is placed on350* @param[in] frompos Begin position of the overhead wire segment on the lane351* @param[in] topos End position of the overhead wire segment on the lane352* @param[in] voltageSource default voltage of overhead wire segment (unused) TODORICE353* @exception InvalidArgument If the overhead wire segment can not be added to the net (is duplicate according to the id)354*/355virtual void buildOverheadWireSegment(MSNet& net, const std::string& id, MSLane* lane, double frompos, double topos, bool voltageSource);356357/** @brief Builds an overhead wire inner segments358*359* Simply calls the buildOverheadWireSegment for inner edges connection, frontConnection and behindConnection if exists.360*361* @param[in] net The net the overhead wire inner segments belongs to362* @param[in] connection The inner lane that connects two regular lanes, or a regular lane with the inner "behindConnection" lane,363or the inner "frontConnection" lane with a regular lane, or the inner "frontConnection" lane with the inner "behindConnection" lane364* @param[in] frontConnection The inner lane that connects a regular lane with the inner "connection" lane365* @param[in] behindConnection The inner lane that connects the inner "connection" lane with a regular lane366* @exception InvalidArgument If the over can not be added to the net (is duplicate according to the id)367*/368void buildInnerOverheadWireSegments(MSNet& net, const MSLane* connection, const MSLane* frontConnection, const MSLane* behindConnection);369370/** @brief Builds a traction substation371*372* Simply calls the MSTractionSubstaion cosnstructor and adds the substation to the list of substations in the net.373*374* @param[in] net The net the traction substation belongs to375* @param[in] id The id of the traction substation376* @param[in] voltage The voltage level of the voltage source representing the traction substation377* @param[in] currentLimit The electric current limit(max current flowing from(through) the traction substation)378* @exception InvalidArgument If the over can not be added to the net (is duplicate according to the id)379*/380void buildTractionSubstation(MSNet& net, std::string id, double voltage, double currentLimit);381382virtual void buildOverheadWireClamp(MSNet& net, const std::string& id, MSLane* lane_start, MSLane* lane_end);383384/** @brief builds a microscopic calibrator385*386* Simply calls the MSCalibrator constructor.387*388* @param[in] id The id of the calibrator389* @param[in] edge The edge the calibrator is placed at390* @param[in] lane The lane the calibrator is placed at if it is lane specific, nullptr otherwise391* @param[in] pos The position on the edge the calibrator lies at392* @param[in] file The file to read the flows from393* @param[in] outfile The file to write calibrator statistics to394* @param[in] freq The frequency for the statistics output395* @param[in] probe an optional route probe to get distributions from396* @param[in] invalidJamThreshold stop calibrating if the relative speed drops below the threshold397* @param[in] vTypes to which vehicle types the calibrator applies398* @todo Is the position correct/needed399*/400virtual MSCalibrator* buildCalibrator(const std::string& id, MSEdge* edge, MSLane* lane, MSJunction* node, double pos,401const std::string& file, const std::string& outfile,402const SUMOTime freq,403const MSRouteProbe* probe,404const double invalidJamThreshold,405const std::string& vTypes,406const bool local);407408/** @brief builds a mesoscopic calibrator409*410* Simply calls the METriggeredCalibrator constructor.411*412* @param[in] id The id of the calibrator413* @param[in] edge The edge the calibrator is placed at414* @param[in] pos The position on the edge the calibrator lies at415* @param[in] file The file to read the flows from416* @param[in] outfile The file to write calibrator statistics to417* @param[in] freq The frequency for the statistics output418* @param[in] probe an optional route probe to get distributions from419* @param[in] invalidJamThreshold stop calibrating if the relative speed drops below the threshold420* @param[in] vTypes to which vehicle types the calibrator applies421* @todo Is the position correct/needed422*/423virtual METriggeredCalibrator* buildMECalibrator(const std::string& id, MSEdge* edge, double pos,424const std::string& file, const std::string& outfile,425const SUMOTime freq,426MSRouteProbe* probe,427const double invalidJamThreshold,428const std::string& vTypes);429430431/** @brief builds an rerouter432*433* Simply calls the MSTriggeredRerouter constructor.434*435* @param[in] net The net the rerouter belongs to436* @param[in] id The id of the rerouter437* @param[in] edges The edges the rerouter is placed at438* @param[in] prob The probability the rerouter reoutes vehicles with439*/440virtual MSTriggeredRerouter* buildRerouter(MSNet& net,441const std::string& id, MSEdgeVector& edges,442double prob, bool off, bool optional, SUMOTime timeThreshold,443const std::string& vTypes, const Position& pos, const double radius);444//@}445446447protected:448/// @name helper method for obtaining and checking values449/// @{450451/** @brief Helper method to obtain the filename452*453* Retrieves "file" from attributes, checks whether it is absolute454* and extends it by the given base path if not. Returns this455* information.456*457* @param[in] attrs The attributes to obtain the file name from458* @param[in] base The base path (the path the loaded additional file lies in)459* @return The (expanded) path to the named file460* @todo Recheck usage of the helper class461*/462std::string getFileName(const SUMOSAXAttributes& attrs,463const std::string& base,464const bool allowEmpty = false);465466467/** @brief Returns the lane defined by attribute "lane"468*469* Retrieves the lane id from the given attrs. Tries to retrieve the lane,470* throws an InvalidArgument if it does not exist.471*472* @param[in] attrs The attributes to obtain the lane id from473* @param[in] tt The trigger type (for user output)474* @param[in] tid The trigger id (for user output)475* @return The named lane if it is known476* @exception InvalidArgument If the named lane does not exist or a lane is not named477*/478MSLane* getLane(const SUMOSAXAttributes& attrs,479const std::string& tt, const std::string& tid);480481482/** @brief Returns the parking area defined by attribute "parkingArea"483*484* Retrieves the parking area id from the given attrs. Tries to retrieve the parking area,485* throws an InvalidArgument if it does not exist.486*487* @param[in] attrs The attributes to obtain the parking area id from488* @param[in] tt The trigger type (for user output)489* @param[in] tid The trigger id (for user output)490* @return The named parking area if it is known, nullptr if empty ID is given491* @exception InvalidArgument If the named parking area does not exist492*/493MSParkingArea* getParkingArea(const SUMOSAXAttributes& attrs,494const std::string& tt, const std::string& tid);495496497/** @brief returns the position on the lane checking it498*499* This method extracts the position, checks whether it shall be mirrored500* and checks whether it is within the lane. If not, an error is reported501* and a InvalidArgument is thrown.502*503* @param[in] attrs The attributes to obtain the position from504* @param[in] lane The lane the position shall be valid for505* @param[in] tt The trigger type (for user output)506* @param[in] tid The trigger id (for user output)507* @return The position on the lane508* @exception InvalidArgument If the position is beyond the lane509*/510double getPosition(const SUMOSAXAttributes& attrs,511MSLane* lane, const std::string& tt, const std::string& tid, MSEdge* edge = 0);512513/// @}514515516517518protected:519/// @brief The parent handler to set for subhandlers520NLHandler* myHandler;521/// @brief definition of the currently parsed parking area522MSParkingArea* myParkingArea;523/// @brief The currently parsed stop to add access points to524MSStoppingPlace* myCurrentStop;525526bool myHaveWarnedAboutEigen = false;527bool myParkingAreaCapacitySet = false;528};529530531