/****************************************************************************/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 GUILane.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @date Sept 200218///19// Representation of a lane in the micro simulation (gui-version)20/****************************************************************************/21#pragma once22#include <config.h>2324#include <utils/foxtools/fxheader.h>25#include <string>26#include <utility>27#include <microsim/MSLane.h>28#include <microsim/MSEdge.h>29#include <utils/geom/Position.h>30#include <utils/geom/PositionVector.h>31#include <utils/gui/globjects/GUIGlObject.h>32#include <utils/gui/settings/GUIPropertySchemeStorage.h>333435// ===========================================================================36// class declarations37// ===========================================================================38class GUINet;39class MSVehicle;40class MSNet;41class TesselatedPolygon;42#ifdef HAVE_OSG43namespace osg {44class Geometry;45}46#endif4748// ===========================================================================49// class definitions50// ===========================================================================51/**52* @class GUILane53* @brief Representation of a lane in the micro simulation (gui-version)54*55* An extended MSLane. A mechanism to avoid concurrent56* visualisation and simulation what may cause problems when vehicles57* disappear is implemented using a mutex.58*/59class GUILane : public MSLane, public GUIGlObject {60public:61/** @brief Constructor62*63* @param[in] id The lane's id64* @param[in] maxSpeed The speed allowed on this lane65* @param[in] friction The initial friction on this lane66* @param[in] length The lane's length67* @param[in] edge The edge this lane belongs to68* @param[in] numericalID The numerical id of the lane69* @param[in] shape The shape of the lane70* @param[in] width The width of the lane71* @param[in] permissions Encoding of vehicle classes that may drive on this lane72* @see SUMOVehicleClass73* @see MSLane74*/75GUILane(const std::string& id, double maxSpeed, double friction,76double length, MSEdge* const edge, int numericalID,77const PositionVector& shape, double width,78SVCPermissions permissions,79SVCPermissions changeLeft, SVCPermissions changeRight,80int index, bool isRampAccel,81const std::string& type,82const PositionVector& outlineShape);838485/// @brief Destructor86~GUILane();8788/** @brief Returns the name of the parent object (if any)89* @note Inherited from GUIGlObject90* @return This object's parent id91*/92std::string getParentName() const override {93return getEdge().getID();94}9596void addSecondaryShape(const PositionVector& shape) override;9798double getLengthGeometryFactor(bool secondaryShape) const override {99return secondaryShape ? myLengthGeometryFactor2 : myLengthGeometryFactor;100}101102/// @name Access to vehicles103/// @{104105/** @brief Returns the vehicles container; locks it for microsimulation106*107* Locks "myLock" preventing usage by microsimulation.108*109* Please note that it is necessary to release the vehicles container110* afterwards using "releaseVehicles".111* @return The vehicles on this lane112* @see MSLane::getVehiclesSecure113*/114const VehCont& getVehiclesSecure() const override;115116117/** @brief Allows to use the container for microsimulation again118*119* Unlocks "myLock" preventing usage by microsimulation.120* @see MSLane::releaseVehicles121*/122void releaseVehicles() const override;123/// @}124125126127/// @name Vehicle movement (longitudinal)128/// @{129130/** the same as in MSLane, but locks the access for the visualisation131first; the access will be granted at the end of this method */132void planMovements(const SUMOTime t) override;133134/** the same as in MSLane, but locks the access for the visualisation135first; the access will be granted at the end of this method */136void setJunctionApproaches() const override;137138/** the same as in MSLane, but locks the access for the visualisation139first; the access will be granted at the end of this method */140void executeMovements(const SUMOTime t) override;141142/** the same as in MSLane, but locks the access for the visualisation143first; the access will be granted at the end of this method */144void integrateNewVehicles() override;145///@}146147148/** the same as in MSLane, but locks the access for the visualisation149first; the access will be granted at the end of this method */150void detectCollisions(SUMOTime timestep, const std::string& stage) override;151152153/** the same as in MSLane, but locks the access for the visualisation154first; the access will be granted at the end of this method */155MSVehicle* removeVehicle(MSVehicle* remVehicle, MSMoveReminder::Notification notification, bool notify) override;156157/// @brief remove parking vehicle158void removeParking(MSBaseVehicle* veh) override;159160/** @brief Sets the information about a vehicle lapping into this lane161*162* This vehicle is added to myVehicles and may be distinguished from regular163* vehicles by the disparity between this lane and v->getLane()164* @param[in] v The vehicle which laps into this lane165* @return This lane's length166*/167double setPartialOccupation(MSVehicle* v) override;168169/** @brief Removes the information about a vehicle lapping into this lane170* @param[in] v The vehicle which laps into this lane171*/172void resetPartialOccupation(MSVehicle* v) override;173174/// @name inherited from GUIGlObject175//@{176177/** @brief Returns an own popup-menu178*179* @param[in] app The application needed to build the popup-menu180* @param[in] parent The parent window needed to build the popup-menu181* @return The built popup-menu182* @see GUIGlObject::getPopUpMenu183*/184GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;185186/** @brief Returns an own parameter window187*188* @param[in] app The application needed to build the parameter window189* @param[in] parent The parent window needed to build the parameter window190* @return The built parameter window191* @see GUIGlObject::getParameterWindow192*/193GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) override;194195/** @brief Returns the boundary to which the view shall be centered in order to show the object196*197* @return The boundary the object is within198* @see GUIGlObject::getCenteringBoundary199*/200Boundary getCenteringBoundary() const override;201202/** @brief Draws the object203* @param[in] s The settings for the current view (may influence drawing)204* @see GUIGlObject::drawGL205*/206void drawGL(const GUIVisualizationSettings& s) const override;207208double getClickPriority() const override;209//@}210211const PositionVector& getShape(bool secondary) const override;212const std::vector<double>& getShapeRotations(bool secondary) const;213const std::vector<double>& getShapeLengths(bool secondary) const;214215double firstWaitingTime() const;216217/// @brief whether any of the neighboring lanes is not a bidi-lane218bool neighLaneNotBidi() const;219220/// @brief draw lane borders and white markings221void drawMarkings(const GUIVisualizationSettings& s, double scale) const;222223/// @brief bike lane markings on top of an intersection224void drawBikeMarkings() const;225226/// @brief bike lane markings on top of an intersection227void drawJunctionChangeProhibitions() const;228229/// @brief direction indicators for lanes230void drawDirectionIndicators(double exaggeration, bool spreadSuperposed, bool s2) const;231232/// @brief draw intersection positions of foe internal lanes with this one233void debugDrawFoeIntersections() const;234235double getEdgeLaneNumber() const;236237/** @brief Returns the stored traveltime for the edge of this lane238*/239double getStoredEdgeTravelTime() const;240241/** @brief Returns the loaded weight (effort) for the edge of this lane242*/243double getLoadedEdgeWeight() const;244245void setReachability(double value) {246myReachability = value;247}248249double getReachability() const {250return myReachability;251}252253#ifdef HAVE_OSG254void setGeometry(osg::Geometry* geom) {255myGeom = geom;256}257258void updateColor(const GUIVisualizationSettings& s);259260#endif261262/// @brief close this lane for traffic263void closeTraffic(bool rebuildAllowed = true);264265bool isClosed() const {266return myAmClosed;267}268269/// @brief gets the color value according to the current scheme index270double getColorValue(const GUIVisualizationSettings& s, int activeScheme) const override;271272/// @brief gets the color value according to the current scheme index including values for things that set the color indirectly273double getColorValueWithFunctional(const GUIVisualizationSettings& s, int activeScheme) const;274275/// @brief return color value based on cached settings276double getColorValueForTracker() const;277278/// @brief gets the scaling value according to the current scheme index279double getScaleValue(const GUIVisualizationSettings& s, int activeScheme, bool s2) const;280281/// @brief whether this lane is selected in the GUI282bool isSelected() const override;283284/* @brief sets the color according to the current scheme index and some lane function285* @param[in] id override active scheme when calling from meso gui286*/287bool setFunctionalColor(const GUIColorer& c, RGBColor& col, int activeScheme = -1) const;288289/// @brief whether to draw this lane as a railway290bool drawAsRailway(const GUIVisualizationSettings& s) const;291292protected:293/// moves myTmpVehicles int myVehicles after a lane change procedure294void swapAfterLaneChange(SUMOTime t) override;295296/** @brief Inserts the vehicle into this lane, and informs it about entering the network297*298* Calls the vehicles enterLaneAtInsertion function,299* updates statistics and modifies the active state as needed300* @param[in] veh The vehicle to be incorporated301* @param[in] pos The position of the vehicle302* @param[in] speed The speed of the vehicle303* @param[in] posLat The lateral position of the vehicle304* @param[in] at305* @param[in] notification The cause of insertion (i.e. departure, teleport, parking) defaults to departure306* @see MSLane::incorporateVehicle307*/308void incorporateVehicle(MSVehicle* veh, double pos, double speed, double posLat,309const MSLane::VehCont::iterator& at,310MSMoveReminder::Notification notification = MSMoveReminder::NOTIFICATION_DEPARTED) override;311312private:313/// @brief helper methods314void drawLinkNo(const GUIVisualizationSettings& s) const;315void drawTLSLinkNo(const GUIVisualizationSettings& s, const GUINet& net) const;316void drawLinkRules(const GUIVisualizationSettings& s, const GUINet& net) const;317void drawLinkRule(const GUIVisualizationSettings& s, const GUINet& net, const MSLink* link,318const PositionVector& shape, double x1, double x2) const;319void drawArrows(bool secondaryShape) const;320void drawLane2LaneConnections(double exaggeration, bool s2) const;321322323/// @brief add intermediate points at segment borders324PositionVector splitAtSegments(const PositionVector& shape);325326/// @brief get number of vehicles waiting for departure on this lane327double getPendingEmits() const;328329private:330void initRotations(const PositionVector& shape,331std::vector<double>& rotations,332std::vector<double>& lengths,333std::vector<RGBColor>& colors);334335/// @brief sets multiple colors according to the current scheme index and some lane function336bool setMultiColor(const GUIVisualizationSettings& s, const GUIColorer& c, RGBColor& col) const;337338/// @brief sets the color according to the currente settings339RGBColor setColor(const GUIVisualizationSettings& s) const;340341/// @brief whether to draw this lane as a waterway342bool drawAsWaterway(const GUIVisualizationSettings& s) const;343344/// @brief whether this lane or its parent edge is selected in the GUI345bool isLaneOrEdgeSelected() const;346347std::vector<RGBColor>& getShapeColors(bool secondary) const;348349/// The rotations of the shape parts350std::vector<double> myShapeRotations;351std::vector<double> myShapeRotations2;352353/// The lengths of the shape parts354std::vector<double> myShapeLengths;355std::vector<double> myShapeLengths2;356357/// The color of the shape parts (cached)358mutable std::vector<RGBColor> myShapeColors;359mutable std::vector<RGBColor> myShapeColors2;360361/// @brief the meso segment index for each geometry segment362std::vector<int> myShapeSegments;363/// @brief the shape indices where the meso segment changes (for segmentsIndex > 0)364std::vector<int> mySegmentStartIndex;365366/// @brief Half of lane width, for speed-up367double myHalfLaneWidth;368369/// @brief Quarter of lane width, for speed-up370double myQuarterLaneWidth;371372/// @brief the time distance from a particular edge373double myReachability = INVALID_DOUBLE;374375/// @brief list of parkingAreas on this lane376mutable std::vector<MSParkingArea*>* myParkingAreas;377378/// @brief An object that stores the tesselation379mutable TesselatedPolygon* myTesselation;380381#ifdef HAVE_OSG382osg::Geometry* myGeom;383#endif384385/// @brief state for dynamic lane closings386bool myAmClosed;387388/// @brief secondary shape for visualization389PositionVector myShape2;390double myLengthGeometryFactor2;391392/// @brief cached for tracking color value393static GUIVisualizationSettings* myCachedGUISettings;394395private:396/// The mutex used to avoid concurrent updates of the vehicle buffer397mutable FXMutex myLock;398399/// @brief special color to signify alternative coloring scheme400static const RGBColor MESO_USE_LANE_COLOR;401402403};404405406