/****************************************************************************/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 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}101102void updateMesoGUISegments() override;103104/// @name Access to vehicles105/// @{106107/** @brief Returns the vehicles container; locks it for microsimulation108*109* Locks "myLock" preventing usage by microsimulation.110*111* Please note that it is necessary to release the vehicles container112* afterwards using "releaseVehicles".113* @return The vehicles on this lane114* @see MSLane::getVehiclesSecure115*/116const VehCont& getVehiclesSecure() const override;117118119/** @brief Allows to use the container for microsimulation again120*121* Unlocks "myLock" preventing usage by microsimulation.122* @see MSLane::releaseVehicles123*/124void releaseVehicles() const override;125/// @}126127128129/// @name Vehicle movement (longitudinal)130/// @{131132/** the same as in MSLane, but locks the access for the visualisation133first; the access will be granted at the end of this method */134void planMovements(const SUMOTime t) override;135136/** the same as in MSLane, but locks the access for the visualisation137first; the access will be granted at the end of this method */138void setJunctionApproaches() const override;139140/** the same as in MSLane, but locks the access for the visualisation141first; the access will be granted at the end of this method */142void executeMovements(const SUMOTime t) override;143144/** the same as in MSLane, but locks the access for the visualisation145first; the access will be granted at the end of this method */146void integrateNewVehicles() override;147///@}148149150/** the same as in MSLane, but locks the access for the visualisation151first; the access will be granted at the end of this method */152void detectCollisions(SUMOTime timestep, const std::string& stage) override;153154155/** the same as in MSLane, but locks the access for the visualisation156first; the access will be granted at the end of this method */157MSVehicle* removeVehicle(MSVehicle* remVehicle, MSMoveReminder::Notification notification, bool notify) override;158159/// @brief remove parking vehicle160void removeParking(MSBaseVehicle* veh) override;161162/** @brief Sets the information about a vehicle lapping into this lane163*164* This vehicle is added to myVehicles and may be distinguished from regular165* vehicles by the disparity between this lane and v->getLane()166* @param[in] v The vehicle which laps into this lane167* @return This lane's length168*/169double setPartialOccupation(MSVehicle* v) override;170171/** @brief Removes the information about a vehicle lapping into this lane172* @param[in] v The vehicle which laps into this lane173*/174void resetPartialOccupation(MSVehicle* v) override;175176/// @name inherited from GUIGlObject177//@{178179/** @brief Returns an own popup-menu180*181* @param[in] app The application needed to build the popup-menu182* @param[in] parent The parent window needed to build the popup-menu183* @return The built popup-menu184* @see GUIGlObject::getPopUpMenu185*/186GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;187188/** @brief Returns an own parameter window189*190* @param[in] app The application needed to build the parameter window191* @param[in] parent The parent window needed to build the parameter window192* @return The built parameter window193* @see GUIGlObject::getParameterWindow194*/195GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) override;196197/** @brief Returns the boundary to which the view shall be centered in order to show the object198*199* @return The boundary the object is within200* @see GUIGlObject::getCenteringBoundary201*/202Boundary getCenteringBoundary() const override;203204/** @brief Draws the object205* @param[in] s The settings for the current view (may influence drawing)206* @see GUIGlObject::drawGL207*/208void drawGL(const GUIVisualizationSettings& s) const override;209210double getClickPriority() const override;211//@}212213const PositionVector& getShape(bool secondary) const override;214const std::vector<double>& getShapeRotations(bool secondary) const;215const std::vector<double>& getShapeLengths(bool secondary) const;216217double firstWaitingTime() const;218219/// @brief whether any of the neighboring lanes is not a bidi-lane220bool neighLaneNotBidi() const;221222/// @brief draw lane borders and white markings223void drawMarkings(const GUIVisualizationSettings& s, double scale) const;224225/// @brief bike lane markings on top of an intersection226void drawBikeMarkings() const;227228/// @brief bike lane markings on top of an intersection229void drawJunctionChangeProhibitions() const;230231/// @brief direction indicators for lanes232void drawDirectionIndicators(double exaggeration, bool spreadSuperposed, bool s2) const;233234/// @brief draw intersection positions of foe internal lanes with this one235void debugDrawFoeIntersections() const;236237double getEdgeLaneNumber() const;238239/** @brief Returns the stored traveltime for the edge of this lane240*/241double getStoredEdgeTravelTime() const;242243/** @brief Returns the loaded weight (effort) for the edge of this lane244*/245double getLoadedEdgeWeight() const;246247void setReachability(double value) {248myReachability = value;249}250251double getReachability() const {252return myReachability;253}254255#ifdef HAVE_OSG256void setGeometry(osg::Geometry* geom) {257myGeom = geom;258}259260void updateColor(const GUIVisualizationSettings& s);261262#endif263264/// @brief close this lane for traffic265void closeTraffic(bool rebuildAllowed = true);266267bool isClosed() const {268return myAmClosed;269}270271/// @brief gets the color value according to the current scheme index272double getColorValue(const GUIVisualizationSettings& s, int activeScheme) const override;273274/// @brief gets the color value according to the current scheme index including values for things that set the color indirectly275double getColorValueWithFunctional(const GUIVisualizationSettings& s, int activeScheme) const;276277/// @brief return color value based on cached settings278double getColorValueForTracker() const;279280/// @brief gets the scaling value according to the current scheme index281double getScaleValue(const GUIVisualizationSettings& s, int activeScheme, bool s2) const;282283/// @brief whether this lane is selected in the GUI284bool isSelected() const override;285286/* @brief sets the color according to the current scheme index and some lane function287* @param[in] id override active scheme when calling from meso gui288*/289bool setFunctionalColor(const GUIColorer& c, RGBColor& col, int activeScheme = -1) const;290291/// @brief whether to draw this lane as a railway292bool drawAsRailway(const GUIVisualizationSettings& s) const;293294protected:295/// moves myTmpVehicles int myVehicles after a lane change procedure296void swapAfterLaneChange(SUMOTime t) override;297298/** @brief Inserts the vehicle into this lane, and informs it about entering the network299*300* Calls the vehicles enterLaneAtInsertion function,301* updates statistics and modifies the active state as needed302* @param[in] veh The vehicle to be incorporated303* @param[in] pos The position of the vehicle304* @param[in] speed The speed of the vehicle305* @param[in] posLat The lateral position of the vehicle306* @param[in] at307* @param[in] notification The cause of insertion (i.e. departure, teleport, parking) defaults to departure308* @see MSLane::incorporateVehicle309*/310void incorporateVehicle(MSVehicle* veh, double pos, double speed, double posLat,311const MSLane::VehCont::iterator& at,312MSMoveReminder::Notification notification = MSMoveReminder::NOTIFICATION_DEPARTED) override;313314private:315/// @brief helper methods316void drawLinkNo(const GUIVisualizationSettings& s) const;317void drawTLSLinkNo(const GUIVisualizationSettings& s, const GUINet& net) const;318void drawLinkRules(const GUIVisualizationSettings& s, const GUINet& net) const;319void drawLinkRule(const GUIVisualizationSettings& s, const GUINet& net, const MSLink* link,320const PositionVector& shape, double x1, double x2) const;321void drawArrows(bool secondaryShape) const;322void drawLane2LaneConnections(double exaggeration, bool s2) const;323324325/// @brief add intermediate points at segment borders326PositionVector splitAtSegments(const PositionVector& shape);327328/// @brief get number of vehicles waiting for departure on this lane329double getPendingEmits() const;330331private:332void initRotations(const PositionVector& shape,333std::vector<double>& rotations,334std::vector<double>& lengths,335std::vector<RGBColor>& colors);336337/// @brief sets multiple colors according to the current scheme index and some lane function338bool setMultiColor(const GUIVisualizationSettings& s, const GUIColorer& c, RGBColor& col) const;339340/// @brief sets the color according to the currente settings341RGBColor setColor(const GUIVisualizationSettings& s) const;342343/// @brief whether to draw this lane as a waterway344bool drawAsWaterway(const GUIVisualizationSettings& s) const;345346/// @brief whether this lane or its parent edge is selected in the GUI347bool isLaneOrEdgeSelected() const;348349std::vector<RGBColor>& getShapeColors(bool secondary) const;350351/// The rotations of the shape parts352std::vector<double> myShapeRotations;353std::vector<double> myShapeRotations2;354355/// The lengths of the shape parts356std::vector<double> myShapeLengths;357std::vector<double> myShapeLengths2;358359/// The color of the shape parts (cached)360mutable std::vector<RGBColor> myShapeColors;361mutable std::vector<RGBColor> myShapeColors2;362363/// @brief the meso segment index for each geometry segment364std::vector<int> myShapeSegments;365/// @brief the shape indices where the meso segment changes (for segmentsIndex > 0)366std::vector<int> mySegmentStartIndex;367368/// @brief Half of lane width, for speed-up369double myHalfLaneWidth;370371/// @brief Quarter of lane width, for speed-up372double myQuarterLaneWidth;373374/// @brief the time distance from a particular edge375double myReachability = INVALID_DOUBLE;376377/// @brief list of parkingAreas on this lane378mutable std::vector<MSParkingArea*>* myParkingAreas;379380/// @brief An object that stores the tesselation381mutable TesselatedPolygon* myTesselation;382383#ifdef HAVE_OSG384osg::Geometry* myGeom;385#endif386387/// @brief state for dynamic lane closings388bool myAmClosed;389390/// @brief secondary shape for visualization391PositionVector myShape2;392double myLengthGeometryFactor2;393394/// @brief cached for tracking color value395static GUIVisualizationSettings* myCachedGUISettings;396397private:398/// The mutex used to avoid concurrent updates of the vehicle buffer399mutable FXMutex myLock;400401/// @brief special color to signify alternative coloring scheme402static const RGBColor MESO_USE_LANE_COLOR;403404405};406407408