LCOV - code coverage report
Current view: top level - src/guisim - GUIBaseVehicle.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 8 16 50.0 %
Date: 2024-04-28 15:39:05 Functions: 2 7 28.6 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2001-2024 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    GUIBaseVehicle.h
      15             : /// @author  Daniel Krajzewicz
      16             : /// @author  Jakob Erdmann
      17             : /// @author  Sascha Krieg
      18             : /// @author  Michael Behrisch
      19             : /// @date    Sept 2002
      20             : ///
      21             : // A MSVehicle extended by some values for usage within the gui
      22             : /****************************************************************************/
      23             : #pragma once
      24             : #include <config.h>
      25             : 
      26             : #include <vector>
      27             : #include <set>
      28             : #include <string>
      29             : #include <utils/foxtools/fxheader.h>
      30             : #include <utils/common/RGBColor.h>
      31             : #include <utils/geom/GeomHelper.h>
      32             : #include <utils/geom/PositionVector.h>
      33             : #include <utils/gui/globjects/GUIGlObject.h>
      34             : #include <utils/gui/globjects/GUIGLObjectPopupMenu.h>
      35             : #include <utils/gui/settings/GUIPropertySchemeStorage.h>
      36             : #include <microsim/MSVehicle.h>
      37             : 
      38             : 
      39             : // ===========================================================================
      40             : // class declarations
      41             : // ===========================================================================
      42             : class GUISUMOAbstractView;
      43             : class GUIGLObjectPopupMenu;
      44             : class MSDevice_Vehroutes;
      45             : 
      46             : 
      47             : // ===========================================================================
      48             : // class definitions
      49             : // ===========================================================================
      50             : /**
      51             :  * @class GUIBaseVehicle
      52             :  * @brief A MSVehicle extended by some values for usage within the gui
      53             :  *
      54             :  * A visualisable MSVehicle. Extended by the possibility to retrieve names
      55             :  * of all available vehicles (static) and the possibility to retrieve the
      56             :  * color of the vehicle which is available in different forms allowing an
      57             :  * easier recognition of done actions such as lane changing.
      58             :  */
      59             : class GUIBaseVehicle : public GUIGlObject {
      60             : public:
      61             : 
      62             :     GUIBaseVehicle(MSBaseVehicle& vehicle);
      63             : 
      64             :     /// @brief destructor
      65             :     ~GUIBaseVehicle();
      66             : 
      67      926284 :     struct Seat {
      68      708388 :         Seat(): pos(Position::INVALID), angle(0) {}
      69             : 
      70      216512 :         Seat(const Position& _pos, double _angle):
      71      216512 :             pos(_pos), angle(_angle) {}
      72             : 
      73             :         Position pos;
      74             :         double angle;
      75             :     };
      76             :     typedef std::vector<Seat> Seats;
      77             : 
      78             :     /** @brief Return current position (x/y, cartesian)
      79             :      *
      80             :      * If the vehicle's myLane is 0, Position::INVALID.
      81             :      * @param[in] offset optional offset in longitudinal direction
      82             :      * @return The current position (in cartesian coordinates)
      83             :      * @see myLane
      84             :      */
      85             :     virtual Position getPosition(const double offset = 0) const = 0;
      86             : 
      87             :     /** @brief Return current position taking into account secondary shape
      88             :      * @param[in] offset optional offset in longitudinal direction
      89             :      * @return The current position (in cartesian coordinates)
      90             :      */
      91             :     virtual Position getVisualPosition(bool s2, const double offset = 0) const = 0;
      92             : 
      93             :     /** @brief Returns the vehicle's direction in radians
      94             :      * @return The vehicle's current angle
      95             :      */
      96             :     virtual double getAngle() const = 0;
      97             : 
      98             :     /** @brief Returns the vehicle's direction in radians taking into account
      99             :      * secondary shape
     100             :      * @return The vehicle's current angle
     101             :      */
     102             :     virtual double getVisualAngle(bool s2) const = 0;
     103             : 
     104             :     /// @brief return the current angle in navigational degrees
     105           0 :     double getNaviDegree() const {
     106           0 :         return GeomHelper::naviDegree(getAngle());
     107             :     }
     108             : 
     109             :     /// @brief gets the color value according to the current scheme index
     110             :     virtual double getColorValue(const GUIVisualizationSettings& s, int activeScheme) const = 0;
     111             : 
     112             :     /// @brief draws the given guiShape with distinct carriages/modules
     113             :     virtual void drawAction_drawCarriageClass(const GUIVisualizationSettings& s, bool asImage) const = 0;
     114             : 
     115             :     /** @brief Returns the time since the last lane change in seconds
     116             :      * @see MSVehicle::myLastLaneChangeOffset
     117             :      * @return The time since the last lane change in seconds
     118             :      */
     119             :     virtual double getLastLaneChangeOffset() const = 0;
     120             : 
     121             :     /** @brief Draws the route
     122             :      * @param[in] r The route to draw
     123             :      */
     124             :     virtual void drawRouteHelper(const GUIVisualizationSettings& s, ConstMSRoutePtr r, bool future, bool noLoop, const RGBColor& col) const = 0;
     125             : 
     126             :     /// @brief retrieve information about the current stop state
     127             :     virtual std::string getStopInfo() const = 0;
     128             : 
     129             :     /// @brief adds the blocking foes to the current selection
     130             :     virtual void selectBlockingFoes() const = 0;
     131             : 
     132             :     /** @brief Returns an own parameter window
     133             :      *
     134             :      * @param[in] app The application needed to build the parameter window
     135             :      * @param[in] parent The parent window needed to build the parameter window
     136             :      * @return The built parameter window
     137             :      * @see GUIGlObject::getParameterWindow
     138             :      */
     139             :     virtual GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) = 0;
     140             : 
     141             :     /** @brief Returns an own type parameter window
     142             :      *
     143             :      * @param[in] app The application needed to build the parameter window
     144             :      * @param[in] parent The parent window needed to build the parameter window
     145             :      * @return The built parameter window
     146             :      */
     147             :     virtual GUIParameterTableWindow* getTypeParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) = 0;
     148             : 
     149      613533 :     virtual void drawAction_drawVehicleBlinker(double /*length*/) const {}
     150      613533 :     virtual void drawAction_drawVehicleBrakeLight(double length, bool onlyOne = false) const {
     151             :         UNUSED_PARAMETER(length);
     152             :         UNUSED_PARAMETER(onlyOne);
     153      613533 :     }
     154           0 :     virtual void drawAction_drawLinkItems(const GUIVisualizationSettings& /*s*/) const {}
     155             :     virtual void drawAction_drawPersonsAndContainers(const GUIVisualizationSettings& s) const;
     156             :     /** @brief Draws the vehicle's best lanes */
     157           0 :     virtual void drawBestLanes() const {};
     158           0 :     virtual void drawAction_drawVehicleBlueLight() const {}
     159             : 
     160             : 
     161             : 
     162             : 
     163             : 
     164             :     /// @name inherited from GUIGlObject
     165             :     //@{
     166             : 
     167             :     /** @brief Returns an own popup-menu
     168             :      *
     169             :      * @param[in] app The application needed to build the popup-menu
     170             :      * @param[in] parent The parent window needed to build the popup-menu
     171             :      * @return The built popup-menu
     172             :      * @see GUIGlObject::getPopUpMenu
     173             :      */
     174             :     GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent);
     175             : 
     176             :     /// @brief notify object about popup menu removal
     177             :     void removedPopupMenu();
     178             : 
     179             :     /// @brief return exaggeration associated with this GLObject
     180             :     double getExaggeration(const GUIVisualizationSettings& s) const;
     181             : 
     182             :     /** @brief Returns the boundary to which the view shall be centered in order to show the object
     183             :      *
     184             :      * @return The boundary the object is within
     185             :      * @see GUIGlObject::getCenteringBoundary
     186             :      */
     187             :     virtual Boundary getCenteringBoundary() const;
     188             : 
     189             :     /// @brief Returns the value for generic parameter 'name' or ''
     190             :     const std::string getOptionalName() const;
     191             : 
     192             :     /** @brief Draws the object on the specified position with the specified angle
     193             :      * @param[in] s The settings for the current view (may influence drawing)
     194             :      * @param[in] pos The position to draw the vehicle on
     195             :      * @param[in] angle The drawing angle of the vehicle
     196             :      */
     197             :     void drawOnPos(const GUIVisualizationSettings& s, const Position& pos, const double angle) const;
     198             : 
     199             : 
     200             :     /** @brief Draws the object
     201             :      * @param[in] s The settings for the current view (may influence drawing)
     202             :      * @see GUIGlObject::drawGL
     203             :      */
     204             :     void drawGL(const GUIVisualizationSettings& s) const;
     205             : 
     206             : 
     207             :     /** @brief Draws additionally triggered visualisations
     208             :      * @param[in] parent The view
     209             :      * @param[in] s The settings for the current view (may influence drawing)
     210             :      */
     211             :     virtual void drawGLAdditional(GUISUMOAbstractView* const parent, const GUIVisualizationSettings& s) const;
     212             :     //@}
     213             : 
     214             : 
     215             : 
     216             :     /// @name Additional visualisations
     217             :     /// @{
     218             : 
     219             :     /** @brief Returns whether the named feature is enabled in the given view
     220             :      * @param[in] parent The view for which the feature may be enabled
     221             :      * @param[in] which The visualisation feature
     222             :      * @return see comment
     223             :      */
     224             :     bool hasActiveAddVisualisation(GUISUMOAbstractView* const parent, int which) const;
     225             : 
     226             : 
     227             :     /** @brief Adds the named visualisation feature to the given view
     228             :      * @param[in] parent The view for which the feature shall be enabled
     229             :      * @param[in] which The visualisation feature to enable
     230             :      * @see GUISUMOAbstractView::addAdditionalGLVisualisation
     231             :      */
     232             :     void addActiveAddVisualisation(GUISUMOAbstractView* const parent, int which);
     233             : 
     234             : 
     235             :     /** @brief Adds the named visualisation feature to the given view
     236             :      * @param[in] parent The view for which the feature shall be enabled
     237             :      * @param[in] which The visualisation feature to enable
     238             :      * @see GUISUMOAbstractView::removeAdditionalGLVisualisation
     239             :      */
     240             :     void removeActiveAddVisualisation(GUISUMOAbstractView* const parent, int which);
     241             :     /// @}
     242             : 
     243             :     /// @brief return the number of passengers
     244             :     int getNumPassengers() const;
     245             : 
     246             :     /// @brief return the number of passengers
     247             :     int getNumContainers() const;
     248             : 
     249             :     /// @brief lists equipped device (types) for the current vehicle
     250             :     std::string getDeviceDescription();
     251             : 
     252             :     /**
     253             :      * @class GUIBaseVehiclePopupMenu
     254             :      *
     255             :      * A popup-menu for vehicles. In comparison to the normal popup-menu, this one
     256             :      *  also allows to trigger further visualisations and to track the vehicle.
     257             :      */
     258             :     class GUIBaseVehiclePopupMenu : public GUIGLObjectPopupMenu {
     259           0 :         FXDECLARE(GUIBaseVehiclePopupMenu)
     260             :     public:
     261             :         /** @brief Constructor
     262             :          * @param[in] app The main window for instantiation of other windows
     263             :          * @param[in] parent The parent view for changing it
     264             :          * @param[in] o The object of interest
     265             :          */
     266             :         GUIBaseVehiclePopupMenu(GUIMainWindow& app, GUISUMOAbstractView& parent, GUIGlObject& o);
     267             : 
     268             :         /// @brief Destructor
     269             :         ~GUIBaseVehiclePopupMenu();
     270             : 
     271             :         /// @brief Called if all routes of the vehicle shall be shown
     272             :         long onCmdShowAllRoutes(FXObject*, FXSelector, void*);
     273             :         /// @brief Called if all routes of the vehicle shall be hidden
     274             :         long onCmdHideAllRoutes(FXObject*, FXSelector, void*);
     275             :         /// @brief Called if the current route of the vehicle shall be shown
     276             :         long onCmdShowCurrentRoute(FXObject*, FXSelector, void*);
     277             :         /// @brief Called if the current route of the vehicle shall be hidden
     278             :         long onCmdHideCurrentRoute(FXObject*, FXSelector, void*);
     279             :         /// @brief Called if the current route of the vehicle shall be shown
     280             :         long onCmdShowFutureRoute(FXObject*, FXSelector, void*);
     281             :         /// @brief Called if the current route of the vehicle shall be hidden
     282             :         long onCmdHideFutureRoute(FXObject*, FXSelector, void*);
     283             :         /// @brief Called if the current route of the vehicle shall be shown
     284             :         long onCmdShowRouteNoLoops(FXObject*, FXSelector, void*);
     285             :         /// @brief Called if the current route of the vehicle shall be hidden
     286             :         long onCmdHideRouteNoLoops(FXObject*, FXSelector, void*);
     287             :         /// @brief Called if the vehicle's best lanes shall be shown
     288             :         long onCmdShowBestLanes(FXObject*, FXSelector, void*);
     289             :         /// @brief Called if the vehicle's best lanes shall be hidden
     290             :         long onCmdHideBestLanes(FXObject*, FXSelector, void*);
     291             :         /// @brief Called if the vehicle shall be tracked
     292             :         long onCmdStartTrack(FXObject*, FXSelector, void*);
     293             :         /// @brief Called if the current shall not be tracked any longer
     294             :         long onCmdStopTrack(FXObject*, FXSelector, void*);
     295             :         /// @brief Called if all routes of the vehicle shall be shown
     296             :         long onCmdShowLFLinkItems(FXObject*, FXSelector, void*);
     297             :         /// @brief Called if all routes of the vehicle shall be hidden
     298             :         long onCmdHideLFLinkItems(FXObject*, FXSelector, void*);
     299             :         /// @brief Called to show (select) a vehicles foes
     300             :         long onCmdShowFoes(FXObject*, FXSelector, void*);
     301             :         /// @brief Called to select all riding persons and containers
     302             :         long onCmdSelectTransported(FXObject*, FXSelector, void*);
     303             :         /// @brief Called when removing the vehicle
     304             :         long onCmdRemoveObject(FXObject*, FXSelector, void*);
     305             :         /// @brief Called when toggling stop state
     306             :         long onCmdToggleStop(FXObject*, FXSelector, void*);
     307             : 
     308             :     protected:
     309           0 :         FOX_CONSTRUCTOR(GUIBaseVehiclePopupMenu)
     310             : 
     311             :     };
     312             : 
     313             : 
     314             :     /// @name Additional visualisations
     315             :     /// @{
     316             : 
     317             :     /** @brief Additional visualisation feature ids
     318             :      */
     319             :     enum VisualisationFeatures {
     320             :         /// @brief show vehicle's best lanes
     321             :         VO_SHOW_BEST_LANES = 1 << 0,
     322             :         /// @brief show vehicle's current route
     323             :         VO_SHOW_ROUTE = 1 << 1,
     324             :         /// @brief show all vehicle's routes
     325             :         VO_SHOW_ALL_ROUTES = 1 << 2,
     326             :         /// @brief LFLinkItems
     327             :         VO_SHOW_LFLINKITEMS = 1 << 3,
     328             :         /// @brief draw vehicle outside the road network
     329             :         VO_DRAW_OUTSIDE_NETWORK = 1 << 4,
     330             :         /// @brief show vehicle's current continued from the current position
     331             :         VO_SHOW_FUTURE_ROUTE = 1 << 5,
     332             :         /// @brief show vehicle's routes without loops
     333             :         VO_SHOW_ROUTE_NOLOOP = 1 << 6,
     334             :         /// @brief track the vehicle (only needed for cleaning up)
     335             :         VO_TRACK = 1 << 7
     336             :     };
     337             : 
     338             :     /// @brief Enabled visualisations, per view
     339             :     std::map<GUISUMOAbstractView*, int> myAdditionalVisualizations;
     340             : 
     341             : 
     342             :     /** @brief Chooses the route to draw and draws it, darkening it as given
     343             :      * @param[in] s The visualisation settings, needed to determine the vehicle's color
     344             :      * @param[in] routeNo The route to show (0: the current, >0: prior)
     345             :      * @param[in] darken The amount to darken the route by
     346             :      */
     347             :     void drawRoute(const GUIVisualizationSettings& s, int routeNo, double darken, bool future = false, bool noLoop = false) const;
     348             : 
     349             :     void drawStopLabels(const GUIVisualizationSettings& s, bool noLoop, const RGBColor& col) const;
     350             : 
     351             :     void drawParkingInfo(const GUIVisualizationSettings& s, const RGBColor& col) const;
     352             :     /// @}
     353             : 
     354             :     const MSBaseVehicle& getVehicle() {
     355           0 :         return myVehicle;
     356             :     }
     357             : 
     358             :     /// @brief gets the size multiplier value according to the current scheme index
     359             :     double getScaleValue(const GUIVisualizationSettings& s, int activeScheme) const;
     360             : 
     361             :     /// @brief sets the color according to the current scheme index and some vehicle function
     362             :     static bool setFunctionalColor(int activeScheme, const MSBaseVehicle* veh, RGBColor& col);
     363             : 
     364             : protected:
     365             : 
     366             :     /// @brief sets the color according to the current settings
     367             :     RGBColor setColor(const GUIVisualizationSettings& s) const;
     368             : 
     369             :     /// @brief returns the seat position for the person with the given index
     370             :     const Seat& getSeatPosition(int personIndex) const;
     371             :     const Seat& getContainerPosition(int containerIndex) const;
     372             : 
     373             :     static void drawLinkItem(const Position& pos, SUMOTime arrivalTime, SUMOTime leaveTime, double exagerate);
     374             : 
     375             :     /// @brief A shortcut to myVehicle.myType
     376             :     inline const MSVehicleType& getVType() const {
     377    44512030 :         return myVehicle.getVehicleType();
     378             :     }
     379             : 
     380             :     /// @brief draw vehicle body and return whether carriages are being drawn
     381             :     bool drawAction_drawVehicleAsPolyWithCarriagges(const GUIVisualizationSettings& s, double scaledLength, bool asImage = false) const;
     382             : 
     383             :     /// @brief add seats to mySeatPositions and update requiredSeats
     384             :     void computeSeats(const Position& front, const Position& back, double seatOffset, int maxSeats, double exaggeration, int& requiredSeats, Seats& into, double extraOffset = 0) const;
     385             : 
     386             :     /// @brief whether to reverse trains in their reversed state
     387             :     bool drawReversed(const GUIVisualizationSettings& s) const;
     388             : 
     389             : 
     390             : protected:
     391             :     /// The mutex used to avoid concurrent updates of the vehicle buffer
     392             :     mutable FXMutex myLock;
     393             : 
     394             :     /// @brief positions of seats in the vehicle (updated at every drawing step)
     395             :     mutable Seats mySeatPositions;
     396             :     mutable Seats myContainerPositions;
     397             : 
     398             : private:
     399             :     /// @brief The vehicle to which all calls should be delegated
     400             :     MSBaseVehicle& myVehicle;
     401             : 
     402             :     MSDevice_Vehroutes* myRoutes;
     403             : 
     404             :     /// @brief current popup (to clean up in destructor). GUIBaseVehicle is not responsible for removal
     405             :     GUIGLObjectPopupMenu* myPopup;
     406             : 
     407             : };

Generated by: LCOV version 1.14