LCOV - code coverage report
Current view: top level - src/guisim - GUILane.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 37.5 % 8 3
Test Date: 2026-03-02 16:00:03 Functions: 50.0 % 2 1

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    GUILane.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @date    Sept 2002
      19              : ///
      20              : // Representation of a lane in the micro simulation (gui-version)
      21              : /****************************************************************************/
      22              : #pragma once
      23              : #include <config.h>
      24              : 
      25              : #include <utils/foxtools/fxheader.h>
      26              : #include <string>
      27              : #include <utility>
      28              : #include <microsim/MSLane.h>
      29              : #include <microsim/MSEdge.h>
      30              : #include <utils/geom/Position.h>
      31              : #include <utils/geom/PositionVector.h>
      32              : #include <utils/gui/globjects/GUIGlObject.h>
      33              : #include <utils/gui/settings/GUIPropertySchemeStorage.h>
      34              : 
      35              : 
      36              : // ===========================================================================
      37              : // class declarations
      38              : // ===========================================================================
      39              : class GUINet;
      40              : class MSVehicle;
      41              : class MSNet;
      42              : class TesselatedPolygon;
      43              : #ifdef HAVE_OSG
      44              : namespace osg {
      45              : class Geometry;
      46              : }
      47              : #endif
      48              : 
      49              : // ===========================================================================
      50              : // class definitions
      51              : // ===========================================================================
      52              : /**
      53              :  * @class GUILane
      54              :  * @brief Representation of a lane in the micro simulation (gui-version)
      55              :  *
      56              :  * An extended MSLane. A mechanism to avoid concurrent
      57              :  * visualisation and simulation what may cause problems when vehicles
      58              :  * disappear is implemented using a mutex.
      59              :  */
      60              : class GUILane : public MSLane, public GUIGlObject {
      61              : public:
      62              :     /** @brief Constructor
      63              :      *
      64              :      * @param[in] id The lane's id
      65              :      * @param[in] maxSpeed The speed allowed on this lane
      66              :      * @param[in] friction The initial friction on this lane
      67              :      * @param[in] length The lane's length
      68              :      * @param[in] edge The edge this lane belongs to
      69              :      * @param[in] numericalID The numerical id of the lane
      70              :      * @param[in] shape The shape of the lane
      71              :      * @param[in] width The width of the lane
      72              :      * @param[in] permissions Encoding of vehicle classes that may drive on this lane
      73              :      * @see SUMOVehicleClass
      74              :      * @see MSLane
      75              :      */
      76              :     GUILane(const std::string& id, double maxSpeed, double friction,
      77              :             double length, MSEdge* const edge, int numericalID,
      78              :             const PositionVector& shape, double width,
      79              :             SVCPermissions permissions,
      80              :             SVCPermissions changeLeft, SVCPermissions changeRight,
      81              :             int index, bool isRampAccel,
      82              :             const std::string& type,
      83              :             const PositionVector& outlineShape);
      84              : 
      85              : 
      86              :     /// @brief Destructor
      87              :     ~GUILane();
      88              : 
      89              :     /** @brief Returns the name of the parent object (if any)
      90              :      * @note Inherited from GUIGlObject
      91              :      * @return This object's parent id
      92              :      */
      93            0 :     std::string getParentName() const override {
      94            0 :         return getEdge().getID();
      95              :     }
      96              : 
      97              :     void addSecondaryShape(const PositionVector& shape) override;
      98              : 
      99     15845982 :     double getLengthGeometryFactor(bool secondaryShape) const override {
     100     15845982 :         return secondaryShape ? myLengthGeometryFactor2 :  myLengthGeometryFactor;
     101              :     }
     102              : 
     103              :     void updateMesoGUISegments() override;
     104              : 
     105              :     /// @name Access to vehicles
     106              :     /// @{
     107              : 
     108              :     /** @brief Returns the vehicles container; locks it for microsimulation
     109              :      *
     110              :      * Locks "myLock" preventing usage by microsimulation.
     111              :      *
     112              :      * Please note that it is necessary to release the vehicles container
     113              :      *  afterwards using "releaseVehicles".
     114              :      * @return The vehicles on this lane
     115              :      * @see MSLane::getVehiclesSecure
     116              :      */
     117              :     const VehCont& getVehiclesSecure() const override;
     118              : 
     119              : 
     120              :     /** @brief Allows to use the container for microsimulation again
     121              :      *
     122              :      * Unlocks "myLock" preventing usage by microsimulation.
     123              :      * @see MSLane::releaseVehicles
     124              :      */
     125              :     void releaseVehicles() const override;
     126              :     /// @}
     127              : 
     128              : 
     129              : 
     130              :     /// @name Vehicle movement (longitudinal)
     131              :     /// @{
     132              : 
     133              :     /** the same as in MSLane, but locks the access for the visualisation
     134              :         first; the access will be granted at the end of this method */
     135              :     void planMovements(const SUMOTime t) override;
     136              : 
     137              :     /** the same as in MSLane, but locks the access for the visualisation
     138              :         first; the access will be granted at the end of this method */
     139              :     void setJunctionApproaches() const override;
     140              : 
     141              :     /** the same as in MSLane, but locks the access for the visualisation
     142              :         first; the access will be granted at the end of this method */
     143              :     void executeMovements(const SUMOTime t) override;
     144              : 
     145              :     /** the same as in MSLane, but locks the access for the visualisation
     146              :         first; the access will be granted at the end of this method */
     147              :     void integrateNewVehicles() override;
     148              :     ///@}
     149              : 
     150              : 
     151              :     /** the same as in MSLane, but locks the access for the visualisation
     152              :         first; the access will be granted at the end of this method */
     153              :     void detectCollisions(SUMOTime timestep, const std::string& stage) override;
     154              : 
     155              : 
     156              :     /** the same as in MSLane, but locks the access for the visualisation
     157              :         first; the access will be granted at the end of this method */
     158              :     MSVehicle* removeVehicle(MSVehicle* remVehicle, MSMoveReminder::Notification notification, bool notify) override;
     159              : 
     160              :     /// @brief remove parking vehicle
     161              :     void removeParking(MSBaseVehicle* veh) override;
     162              : 
     163              :     /** @brief Sets the information about a vehicle lapping into this lane
     164              :      *
     165              :      * This vehicle is added to myVehicles and may be distinguished from regular
     166              :      * vehicles by the disparity between this lane and v->getLane()
     167              :      * @param[in] v The vehicle which laps into this lane
     168              :      * @return This lane's length
     169              :      */
     170              :     double setPartialOccupation(MSVehicle* v) override;
     171              : 
     172              :     /** @brief Removes the information about a vehicle lapping into this lane
     173              :      * @param[in] v The vehicle which laps into this lane
     174              :      */
     175              :     void resetPartialOccupation(MSVehicle* v) override;
     176              : 
     177              :     /// @name inherited from GUIGlObject
     178              :     //@{
     179              : 
     180              :     /** @brief Returns an own popup-menu
     181              :      *
     182              :      * @param[in] app The application needed to build the popup-menu
     183              :      * @param[in] parent The parent window needed to build the popup-menu
     184              :      * @return The built popup-menu
     185              :      * @see GUIGlObject::getPopUpMenu
     186              :      */
     187              :     GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
     188              : 
     189              :     /** @brief Returns an own parameter window
     190              :      *
     191              :      * @param[in] app The application needed to build the parameter window
     192              :      * @param[in] parent The parent window needed to build the parameter window
     193              :      * @return The built parameter window
     194              :      * @see GUIGlObject::getParameterWindow
     195              :      */
     196              :     GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) override;
     197              : 
     198              :     /** @brief Returns the boundary to which the view shall be centered in order to show the object
     199              :      *
     200              :      * @return The boundary the object is within
     201              :      * @see GUIGlObject::getCenteringBoundary
     202              :      */
     203              :     Boundary getCenteringBoundary() const override;
     204              : 
     205              :     /** @brief Draws the object
     206              :      * @param[in] s The settings for the current view (may influence drawing)
     207              :      * @see GUIGlObject::drawGL
     208              :      */
     209              :     void drawGL(const GUIVisualizationSettings& s) const override;
     210              : 
     211              :     double getClickPriority() const override;
     212              :     //@}
     213              : 
     214              :     const PositionVector& getShape(bool secondary) const override;
     215              :     const std::vector<double>& getShapeRotations(bool secondary) const;
     216              :     const std::vector<double>& getShapeLengths(bool secondary) const;
     217              : 
     218              :     double firstWaitingTime() const;
     219              : 
     220              :     /// @brief whether any of the neighboring lanes is not a bidi-lane
     221              :     bool neighLaneNotBidi() const;
     222              : 
     223              :     /// @brief draw lane borders and white markings
     224              :     void drawMarkings(const GUIVisualizationSettings& s, double scale) const;
     225              : 
     226              :     /// @brief bike lane markings on top of an intersection
     227              :     void drawBikeMarkings() const;
     228              : 
     229              :     /// @brief bike lane markings on top of an intersection
     230              :     void drawJunctionChangeProhibitions() const;
     231              : 
     232              :     /// @brief direction indicators for lanes
     233              :     void drawDirectionIndicators(double exaggeration, bool spreadSuperposed, bool s2) const;
     234              : 
     235              :     /// @brief draw intersection positions of foe internal lanes with this one
     236              :     void debugDrawFoeIntersections() const;
     237              : 
     238              :     double getEdgeLaneNumber() const;
     239              : 
     240              :     /** @brief Returns the stored traveltime for the edge of this lane
     241              :      */
     242              :     double getStoredEdgeTravelTime() const;
     243              : 
     244              :     /** @brief Returns the loaded weight (effort) for the edge of this lane
     245              :      */
     246              :     double getLoadedEdgeWeight() const;
     247              : 
     248              :     void setReachability(double value) {
     249            0 :         myReachability = value;
     250            0 :     }
     251              : 
     252              :     double getReachability() const {
     253              :         return myReachability;
     254              :     }
     255              : 
     256              : #ifdef HAVE_OSG
     257              :     void setGeometry(osg::Geometry* geom) {
     258         6070 :         myGeom = geom;
     259              :     }
     260              : 
     261              :     void updateColor(const GUIVisualizationSettings& s);
     262              : 
     263              : #endif
     264              : 
     265              :     /// @brief close this lane for traffic
     266              :     void closeTraffic(bool rebuildAllowed = true);
     267              : 
     268              :     bool isClosed() const {
     269            0 :         return myAmClosed;
     270              :     }
     271              : 
     272              :     /// @brief gets the color value according to the current scheme index
     273              :     double getColorValue(const GUIVisualizationSettings& s, int activeScheme) const override;
     274              : 
     275              :     /// @brief gets the color value according to the current scheme index including values for things that set the color indirectly
     276              :     double getColorValueWithFunctional(const GUIVisualizationSettings& s, int activeScheme) const;
     277              : 
     278              :     /// @brief return color value based on cached settings
     279              :     double getColorValueForTracker() const;
     280              : 
     281              :     /// @brief gets the scaling value according to the current scheme index
     282              :     double getScaleValue(const GUIVisualizationSettings& s, int activeScheme, bool s2) const;
     283              : 
     284              :     /// @brief whether this lane is selected in the GUI
     285              :     bool isSelected() const override;
     286              : 
     287              :     /* @brief sets the color according to the current scheme index and some lane function
     288              :      * @param[in] id override active scheme when calling from meso gui
     289              :      */
     290              :     bool setFunctionalColor(const GUIColorer& c, RGBColor& col, int activeScheme = -1) const;
     291              : 
     292              :     /// @brief whether to draw this lane as a railway
     293              :     bool drawAsRailway(const GUIVisualizationSettings& s) const;
     294              : 
     295              : protected:
     296              :     /// moves myTmpVehicles int myVehicles after a lane change procedure
     297              :     void swapAfterLaneChange(SUMOTime t) override;
     298              : 
     299              :     /** @brief Inserts the vehicle into this lane, and informs it about entering the network
     300              :      *
     301              :      * Calls the vehicles enterLaneAtInsertion function,
     302              :      *  updates statistics and modifies the active state as needed
     303              :      * @param[in] veh The vehicle to be incorporated
     304              :      * @param[in] pos The position of the vehicle
     305              :      * @param[in] speed The speed of the vehicle
     306              :      * @param[in] posLat The lateral position of the vehicle
     307              :      * @param[in] at
     308              :      * @param[in] notification The cause of insertion (i.e. departure, teleport, parking) defaults to departure
     309              :      * @see MSLane::incorporateVehicle
     310              :      */
     311              :     void incorporateVehicle(MSVehicle* veh, double pos, double speed, double posLat,
     312              :                             const MSLane::VehCont::iterator& at,
     313              :                             MSMoveReminder::Notification notification = MSMoveReminder::NOTIFICATION_DEPARTED) override;
     314              : 
     315              : private:
     316              :     /// @brief helper methods
     317              :     void drawLinkNo(const GUIVisualizationSettings& s) const;
     318              :     void drawTLSLinkNo(const GUIVisualizationSettings& s, const GUINet& net) const;
     319              :     void drawLinkRules(const GUIVisualizationSettings& s, const GUINet& net) const;
     320              :     void drawLinkRule(const GUIVisualizationSettings& s, const GUINet& net, const MSLink* link,
     321              :                       const PositionVector& shape, double x1, double x2) const;
     322              :     void drawArrows(bool secondaryShape) const;
     323              :     void drawLane2LaneConnections(double exaggeration, bool s2) const;
     324              : 
     325              : 
     326              :     /// @brief add intermediate points at segment borders
     327              :     PositionVector splitAtSegments(const PositionVector& shape);
     328              : 
     329              :     /// @brief get number of vehicles waiting for departure on this lane
     330              :     double getPendingEmits() const;
     331              : 
     332              : private:
     333              :     void initRotations(const PositionVector& shape,
     334              :                        std::vector<double>& rotations,
     335              :                        std::vector<double>& lengths,
     336              :                        std::vector<RGBColor>& colors);
     337              : 
     338              :     /// @brief sets multiple colors according to the current scheme index and some lane function
     339              :     bool setMultiColor(const GUIVisualizationSettings& s, const GUIColorer& c, RGBColor& col) const;
     340              : 
     341              :     /// @brief sets the color according to the currente settings
     342              :     RGBColor setColor(const GUIVisualizationSettings& s) const;
     343              : 
     344              :     /// @brief whether to draw this lane as a waterway
     345              :     bool drawAsWaterway(const GUIVisualizationSettings& s) const;
     346              : 
     347              :     /// @brief whether this lane or its parent edge is selected in the GUI
     348              :     bool isLaneOrEdgeSelected() const;
     349              : 
     350              :     std::vector<RGBColor>& getShapeColors(bool secondary) const;
     351              : 
     352              :     /// The rotations of the shape parts
     353              :     std::vector<double> myShapeRotations;
     354              :     std::vector<double> myShapeRotations2;
     355              : 
     356              :     /// The lengths of the shape parts
     357              :     std::vector<double> myShapeLengths;
     358              :     std::vector<double> myShapeLengths2;
     359              : 
     360              :     /// The color of the shape parts (cached)
     361              :     mutable std::vector<RGBColor> myShapeColors;
     362              :     mutable std::vector<RGBColor> myShapeColors2;
     363              : 
     364              :     /// @brief the meso segment index for each geometry segment
     365              :     std::vector<int> myShapeSegments;
     366              :     /// @brief the shape indices where the meso segment changes (for segmentsIndex > 0)
     367              :     std::vector<int> mySegmentStartIndex;
     368              : 
     369              :     /// @brief Half of lane width, for speed-up
     370              :     double myHalfLaneWidth;
     371              : 
     372              :     /// @brief Quarter of lane width, for speed-up
     373              :     double myQuarterLaneWidth;
     374              : 
     375              :     /// @brief the time distance from a particular edge
     376              :     double myReachability = INVALID_DOUBLE;
     377              : 
     378              :     /// @brief list of parkingAreas on this lane
     379              :     mutable std::vector<MSParkingArea*>* myParkingAreas;
     380              : 
     381              :     /// @brief An object that stores the tesselation
     382              :     mutable TesselatedPolygon* myTesselation;
     383              : 
     384              : #ifdef HAVE_OSG
     385              :     osg::Geometry* myGeom;
     386              : #endif
     387              : 
     388              :     /// @brief state for dynamic lane closings
     389              :     bool myAmClosed;
     390              : 
     391              :     /// @brief secondary shape for visualization
     392              :     PositionVector myShape2;
     393              :     double myLengthGeometryFactor2;
     394              : 
     395              :     /// @brief cached for tracking color value
     396              :     static GUIVisualizationSettings* myCachedGUISettings;
     397              : 
     398              : private:
     399              :     /// The mutex used to avoid concurrent updates of the vehicle buffer
     400              :     mutable FXMutex myLock;
     401              : 
     402              :     /// @brief special color to signify alternative coloring scheme
     403              :     static const RGBColor MESO_USE_LANE_COLOR;
     404              : 
     405              : 
     406              : };
        

Generated by: LCOV version 2.0-1