/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2002-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 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 energy charged in every timeStep330* @param[in] efficiency efficiency of the charge331* @param[in] chargeInTransit enable or disable charge in transit332* @param[in] chargeDelay delay in the charge333* @param[in] chargeType charge type (normal, electric or fuel)334* @param[in] waitingTime waiting time until start charging335* @param[in] parkingArea The associated parking area336* @exception InvalidArgument If the charging station can not be added to the net (is duplicate)337*/338virtual void buildChargingStation(MSNet& net, const std::string& id, MSLane* lane, double frompos, double topos, const std::string& name,339double chargingPower, double efficiency, bool chargeInTransit, SUMOTime chargeDelay, std::string chargeType,340SUMOTime waitingTime, MSParkingArea* parkingArea);341342/** @brief Builds an overhead wire segment343*344* Simply calls the MSOverheadWire constructor and adds the result to the network.345*346* @param[in] net The net the overhead wire segment belongs to347* @param[in] id The id of the overhead wire segment348* @param[in] lane The lane the overhead wire segment is placed on349* @param[in] frompos Begin position of the overhead wire segment on the lane350* @param[in] topos End position of the overhead wire segment on the lane351* @param[in] voltageSource default voltage of overhead wire segment (unused) TODORICE352* @exception InvalidArgument If the overhead wire segment can not be added to the net (is duplicate according to the id)353*/354virtual void buildOverheadWireSegment(MSNet& net, const std::string& id, MSLane* lane, double frompos, double topos, bool voltageSource);355356/** @brief Builds an overhead wire inner segments357*358* Simply calls the buildOverheadWireSegment for inner edges connection, frontConnection and behindConnection if exists.359*360* @param[in] net The net the overhead wire inner segments belongs to361* @param[in] connection The inner lane that connects two regular lanes, or a regular lane with the inner "behindConnection" lane,362or the inner "frontConnection" lane with a regular lane, or the inner "frontConnection" lane with the inner "behindConnection" lane363* @param[in] frontConnection The inner lane that connects a regular lane with the inner "connection" lane364* @param[in] behindConnection The inner lane that connects the inner "connection" lane with a regular lane365* @exception InvalidArgument If the over can not be added to the net (is duplicate according to the id)366*/367void buildInnerOverheadWireSegments(MSNet& net, const MSLane* connection, const MSLane* frontConnection, const MSLane* behindConnection);368369/** @brief Builds a traction substation370*371* Simply calls the MSTractionSubstaion cosnstructor and adds the substation to the list of substations in the net.372*373* @param[in] net The net the traction substation belongs to374* @param[in] id The id of the traction substation375* @param[in] voltage The voltage level of the voltage source representing the traction substation376* @param[in] currentLimit The electric current limit(max current flowing from(through) the traction substation)377* @exception InvalidArgument If the over can not be added to the net (is duplicate according to the id)378*/379void buildTractionSubstation(MSNet& net, std::string id, double voltage, double currentLimit);380381virtual void buildOverheadWireClamp(MSNet& net, const std::string& id, MSLane* lane_start, MSLane* lane_end);382383/** @brief builds a microscopic calibrator384*385* Simply calls the MSCalibrator constructor.386*387* @param[in] id The id of the calibrator388* @param[in] edge The edge the calibrator is placed at389* @param[in] lane The lane the calibrator is placed at if it is lane specific, nullptr otherwise390* @param[in] pos The position on the edge the calibrator lies at391* @param[in] file The file to read the flows from392* @param[in] outfile The file to write calibrator statistics to393* @param[in] freq The frequency for the statistics output394* @param[in] probe an optional route probe to get distributions from395* @param[in] invalidJamThreshold stop calibrating if the relative speed drops below the threshold396* @param[in] vTypes to which vehicle types the calibrator applies397* @todo Is the position correct/needed398*/399virtual MSCalibrator* buildCalibrator(const std::string& id, MSEdge* edge, MSLane* lane, MSJunction* node, double pos,400const std::string& file, const std::string& outfile,401const SUMOTime freq,402const MSRouteProbe* probe,403const double invalidJamThreshold,404const std::string& vTypes,405const bool local);406407/** @brief builds a mesoscopic calibrator408*409* Simply calls the METriggeredCalibrator constructor.410*411* @param[in] id The id of the calibrator412* @param[in] edge The edge the calibrator is placed at413* @param[in] pos The position on the edge the calibrator lies at414* @param[in] file The file to read the flows from415* @param[in] outfile The file to write calibrator statistics to416* @param[in] freq The frequency for the statistics output417* @param[in] probe an optional route probe to get distributions from418* @param[in] invalidJamThreshold stop calibrating if the relative speed drops below the threshold419* @param[in] vTypes to which vehicle types the calibrator applies420* @todo Is the position correct/needed421*/422virtual METriggeredCalibrator* buildMECalibrator(const std::string& id, MSEdge* edge, double pos,423const std::string& file, const std::string& outfile,424const SUMOTime freq,425MSRouteProbe* probe,426const double invalidJamThreshold,427const std::string& vTypes);428429430/** @brief builds an rerouter431*432* Simply calls the MSTriggeredRerouter constructor.433*434* @param[in] net The net the rerouter belongs to435* @param[in] id The id of the rerouter436* @param[in] edges The edges the rerouter is placed at437* @param[in] prob The probability the rerouter reoutes vehicles with438*/439virtual MSTriggeredRerouter* buildRerouter(MSNet& net,440const std::string& id, MSEdgeVector& edges,441double prob, bool off, bool optional, SUMOTime timeThreshold,442const std::string& vTypes, const Position& pos, const double radius);443//@}444445446protected:447/// @name helper method for obtaining and checking values448/// @{449450/** @brief Helper method to obtain the filename451*452* Retrieves "file" from attributes, checks whether it is absolute453* and extends it by the given base path if not. Returns this454* information.455*456* @param[in] attrs The attributes to obtain the file name from457* @param[in] base The base path (the path the loaded additional file lies in)458* @return The (expanded) path to the named file459* @todo Recheck usage of the helper class460*/461std::string getFileName(const SUMOSAXAttributes& attrs,462const std::string& base,463const bool allowEmpty = false);464465466/** @brief Returns the lane defined by attribute "lane"467*468* Retrieves the lane id from the given attrs. Tries to retrieve the lane,469* throws an InvalidArgument if it does not exist.470*471* @param[in] attrs The attributes to obtain the lane id from472* @param[in] tt The trigger type (for user output)473* @param[in] tid The trigger id (for user output)474* @return The named lane if it is known475* @exception InvalidArgument If the named lane does not exist or a lane is not named476*/477MSLane* getLane(const SUMOSAXAttributes& attrs,478const std::string& tt, const std::string& tid);479480481/** @brief Returns the parking area defined by attribute "parkingArea"482*483* Retrieves the parking area id from the given attrs. Tries to retrieve the parking area,484* throws an InvalidArgument if it does not exist.485*486* @param[in] attrs The attributes to obtain the parking area id from487* @param[in] tt The trigger type (for user output)488* @param[in] tid The trigger id (for user output)489* @return The named parking area if it is known, nullptr if empty ID is given490* @exception InvalidArgument If the named parking area does not exist491*/492MSParkingArea* getParkingArea(const SUMOSAXAttributes& attrs,493const std::string& tt, const std::string& tid);494495496/** @brief returns the position on the lane checking it497*498* This method extracts the position, checks whether it shall be mirrored499* and checks whether it is within the lane. If not, an error is reported500* and a InvalidArgument is thrown.501*502* @param[in] attrs The attributes to obtain the position from503* @param[in] lane The lane the position shall be valid for504* @param[in] tt The trigger type (for user output)505* @param[in] tid The trigger id (for user output)506* @return The position on the lane507* @exception InvalidArgument If the position is beyond the lane508*/509double getPosition(const SUMOSAXAttributes& attrs,510MSLane* lane, const std::string& tt, const std::string& tid, MSEdge* edge = 0);511512/// @}513514515516517protected:518/// @brief The parent handler to set for subhandlers519NLHandler* myHandler;520/// @brief definition of the currently parsed parking area521MSParkingArea* myParkingArea;522/// @brief The currently parsed stop to add access points to523MSStoppingPlace* myCurrentStop;524525bool myHaveWarnedAboutEigen = false;526bool myParkingAreaCapacitySet = false;527};528529530