/****************************************************************************/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 GUIBaseVehicle.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Sascha Krieg17/// @author Michael Behrisch18/// @date Sept 200219///20// A MSVehicle extended by some values for usage within the gui21/****************************************************************************/22#pragma once23#include <config.h>2425#include <vector>26#include <set>27#include <string>28#include <utils/foxtools/fxheader.h>29#include <utils/common/RGBColor.h>30#include <utils/geom/GeomHelper.h>31#include <utils/geom/PositionVector.h>32#include <utils/gui/globjects/GUIGlObject.h>33#include <utils/gui/globjects/GUIGLObjectPopupMenu.h>34#include <utils/gui/settings/GUIPropertySchemeStorage.h>35#include <microsim/MSVehicle.h>363738// ===========================================================================39// class declarations40// ===========================================================================41class GUISUMOAbstractView;42class GUIGLObjectPopupMenu;43class MSDevice_Vehroutes;444546// ===========================================================================47// class definitions48// ===========================================================================49/**50* @class GUIBaseVehicle51* @brief A MSVehicle extended by some values for usage within the gui52*53* A visualisable MSVehicle. Extended by the possibility to retrieve names54* of all available vehicles (static) and the possibility to retrieve the55* color of the vehicle which is available in different forms allowing an56* easier recognition of done actions such as lane changing.57*/58class GUIBaseVehicle : public GUIGlObject {59public:6061GUIBaseVehicle(MSBaseVehicle& vehicle);6263/// @brief destructor64~GUIBaseVehicle();6566struct Seat {67Seat(): pos(Position::INVALID), angle(0) {}6869Seat(const Position& _pos, double _angle):70pos(_pos), angle(_angle) {}7172Position pos;73double angle;74};75typedef std::vector<Seat> Seats;7677/** @brief Return current position (x/y, cartesian)78*79* If the vehicle's myLane is 0, Position::INVALID.80* @param[in] offset optional offset in longitudinal direction81* @return The current position (in cartesian coordinates)82* @see myLane83*/84virtual Position getPosition(const double offset = 0) const = 0;8586/** @brief Return current position taking into account secondary shape87* @param[in] offset optional offset in longitudinal direction88* @return The current position (in cartesian coordinates)89*/90virtual Position getVisualPosition(bool s2, const double offset = 0) const = 0;9192/** @brief Returns the vehicle's direction in radians93* @return The vehicle's current angle94*/95virtual double getAngle() const = 0;9697/** @brief Returns the vehicle's direction in radians taking into account98* secondary shape99* @return The vehicle's current angle100*/101virtual double getVisualAngle(bool s2) const = 0;102103/// @brief return the current angle in navigational degrees104double getNaviDegree() const {105return GeomHelper::naviDegree(getAngle());106}107108/// @brief draws the given guiShape with distinct carriages/modules109virtual void drawAction_drawCarriageClass(const GUIVisualizationSettings& s, double scaledLength, bool asImage) const = 0;110111/** @brief Returns the time since the last lane change in seconds112* @see MSVehicle::myLastLaneChangeOffset113* @return The time since the last lane change in seconds114*/115virtual double getLastLaneChangeOffset() const = 0;116117/** @brief Draws the route118* @param[in] r The route to draw119*/120virtual void drawRouteHelper(const GUIVisualizationSettings& s, ConstMSRoutePtr r, bool future, bool noLoop, const RGBColor& col) const = 0;121122/// @brief retrieve information about the current stop state123virtual std::string getStopInfo() const = 0;124125/// @brief adds the blocking foes to the current selection126virtual void selectBlockingFoes() const = 0;127128virtual void drawAction_drawVehicleBlinker(double /*length*/) const {}129virtual void drawAction_drawVehicleBrakeLight(double length, bool onlyOne = false) const {130UNUSED_PARAMETER(length);131UNUSED_PARAMETER(onlyOne);132}133virtual void drawAction_drawLinkItems(const GUIVisualizationSettings& /*s*/) const {}134virtual void drawAction_drawPersonsAndContainers(const GUIVisualizationSettings& s) const;135/** @brief Draws the vehicle's best lanes */136virtual void drawBestLanes() const {};137virtual void drawAction_drawVehicleBlueLight() const {}138139/// @name inherited from GUIGlObject140//@{141142/** @brief Returns an own popup-menu143*144* @param[in] app The application needed to build the popup-menu145* @param[in] parent The parent window needed to build the popup-menu146* @return The built popup-menu147* @see GUIGlObject::getPopUpMenu148*/149GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;150151/// @brief notify object about popup menu removal152void removedPopupMenu() override;153154/// @brief return exaggeration associated with this GLObject155double getExaggeration(const GUIVisualizationSettings& s) const override;156157/** @brief Returns the boundary to which the view shall be centered in order to show the object158*159* @return The boundary the object is within160* @see GUIGlObject::getCenteringBoundary161*/162virtual Boundary getCenteringBoundary() const override;163164/// @brief Returns the value for generic parameter 'name' or ''165const std::string getOptionalName() const override;166167/** @brief Draws the object on the specified position with the specified angle168* @param[in] s The settings for the current view (may influence drawing)169* @param[in] pos The position to draw the vehicle on170* @param[in] angle The drawing angle of the vehicle171*/172void drawOnPos(const GUIVisualizationSettings& s, const Position& pos, const double angle) const;173174175/** @brief Draws the object176* @param[in] s The settings for the current view (may influence drawing)177* @see GUIGlObject::drawGL178*/179void drawGL(const GUIVisualizationSettings& s) const override;180181182/** @brief Draws additionally triggered visualisations183* @param[in] parent The view184* @param[in] s The settings for the current view (may influence drawing)185*/186virtual void drawGLAdditional(GUISUMOAbstractView* const parent, const GUIVisualizationSettings& s) const override;187//@}188189/// @name Additional visualisations190/// @{191192/** @brief Returns whether the named feature is enabled in the given view193* @param[in] parent The view for which the feature may be enabled194* @param[in] which The visualisation feature195* @return see comment196*/197bool hasActiveAddVisualisation(GUISUMOAbstractView* const parent, int which) const;198199/** @brief Adds the named visualisation feature to the given view200* @param[in] parent The view for which the feature shall be enabled201* @param[in] which The visualisation feature to enable202* @see GUISUMOAbstractView::addAdditionalGLVisualisation203*/204void addActiveAddVisualisation(GUISUMOAbstractView* const parent, int which);205206/** @brief Adds the named visualisation feature to the given view207* @param[in] parent The view for which the feature shall be enabled208* @param[in] which The visualisation feature to enable209* @see GUISUMOAbstractView::removeAdditionalGLVisualisation210*/211void removeActiveAddVisualisation(GUISUMOAbstractView* const parent, int which) override;212/// @}213214/// @brief return the number of passengers215int getNumPassengers() const;216217/// @brief return the number of passengers218int getNumContainers() const;219220/// @brief lists equipped device (types) for the current vehicle221std::string getDeviceDescription();222223/**224* @class GUIBaseVehiclePopupMenu225*226* A popup-menu for vehicles. In comparison to the normal popup-menu, this one227* also allows to trigger further visualisations and to track the vehicle.228*/229class GUIBaseVehiclePopupMenu : public GUIGLObjectPopupMenu {230FXDECLARE(GUIBaseVehiclePopupMenu)231232public:233/** @brief Constructor234* @param[in] app The main window for instantiation of other windows235* @param[in] parent The parent view for changing it236* @param[in] o The object of interest237*/238GUIBaseVehiclePopupMenu(GUIMainWindow& app, GUISUMOAbstractView& parent, GUIGlObject* o);239240/// @brief Destructor241~GUIBaseVehiclePopupMenu();242243/// @brief Called if all routes of the vehicle shall be shown244long onCmdShowAllRoutes(FXObject*, FXSelector, void*);245/// @brief Called if all routes of the vehicle shall be hidden246long onCmdHideAllRoutes(FXObject*, FXSelector, void*);247/// @brief Called if the current route of the vehicle shall be shown248long onCmdShowCurrentRoute(FXObject*, FXSelector, void*);249/// @brief Called if the current route of the vehicle shall be hidden250long onCmdHideCurrentRoute(FXObject*, FXSelector, void*);251/// @brief Called if the current route of the vehicle shall be shown252long onCmdShowFutureRoute(FXObject*, FXSelector, void*);253/// @brief Called if the current route of the vehicle shall be hidden254long onCmdHideFutureRoute(FXObject*, FXSelector, void*);255/// @brief Called if the current route of the vehicle shall be shown256long onCmdShowRouteNoLoops(FXObject*, FXSelector, void*);257/// @brief Called if the current route of the vehicle shall be hidden258long onCmdHideRouteNoLoops(FXObject*, FXSelector, void*);259/// @brief Called if the vehicle's best lanes shall be shown260long onCmdShowBestLanes(FXObject*, FXSelector, void*);261/// @brief Called if the vehicle's best lanes shall be hidden262long onCmdHideBestLanes(FXObject*, FXSelector, void*);263/// @brief Called if the vehicle shall be tracked264long onCmdStartTrack(FXObject*, FXSelector, void*);265/// @brief Called if the current shall not be tracked any longer266long onCmdStopTrack(FXObject*, FXSelector, void*);267/// @brief Called if all routes of the vehicle shall be shown268long onCmdShowLFLinkItems(FXObject*, FXSelector, void*);269/// @brief Called if all routes of the vehicle shall be hidden270long onCmdHideLFLinkItems(FXObject*, FXSelector, void*);271/// @brief Called to show (select) a vehicles foes272long onCmdShowFoes(FXObject*, FXSelector, void*);273/// @brief Called to select all riding persons and containers274long onCmdSelectTransported(FXObject*, FXSelector, void*);275/// @brief Called when removing the vehicle276long onCmdRemoveObject(FXObject*, FXSelector, void*);277/// @brief Called when toggling stop state278long onCmdToggleStop(FXObject*, FXSelector, void*);279280protected:281FOX_CONSTRUCTOR(GUIBaseVehiclePopupMenu)282};283284285/// @name Additional visualisations286/// @{287288/** @brief Additional visualisation feature ids289*/290enum VisualisationFeatures {291/// @brief show vehicle's best lanes292VO_SHOW_BEST_LANES = 1 << 0,293/// @brief show vehicle's current route294VO_SHOW_ROUTE = 1 << 1,295/// @brief show all vehicle's routes296VO_SHOW_ALL_ROUTES = 1 << 2,297/// @brief LFLinkItems298VO_SHOW_LFLINKITEMS = 1 << 3,299/// @brief draw vehicle outside the road network300VO_DRAW_OUTSIDE_NETWORK = 1 << 4,301/// @brief show vehicle's current continued from the current position302VO_SHOW_FUTURE_ROUTE = 1 << 5,303/// @brief show vehicle's routes without loops304VO_SHOW_ROUTE_NOLOOP = 1 << 6,305/// @brief track the vehicle (only needed for cleaning up)306VO_TRACK = 1 << 7307};308309/// @brief Enabled visualisations, per view310std::map<GUISUMOAbstractView*, int> myAdditionalVisualizations;311312313/** @brief Chooses the route to draw and draws it, darkening it as given314* @param[in] s The visualisation settings, needed to determine the vehicle's color315* @param[in] routeNo The route to show (0: the current, >0: prior)316* @param[in] darken The amount to darken the route by317*/318void drawRoute(const GUIVisualizationSettings& s, int routeNo, double darken, bool future = false, bool noLoop = false) const;319320void drawStopLabels(const GUIVisualizationSettings& s, bool noLoop, const RGBColor& col) const;321322void drawParkingInfo(const GUIVisualizationSettings& s) const;323324void drawChargingInfo(const GUIVisualizationSettings& s) const;325/// @}326327const MSBaseVehicle& getVehicle() {328return myVehicle;329}330331/// @brief gets the size multiplier value according to the current scheme index332double getScaleValue(const GUIVisualizationSettings& s, int activeScheme) const;333334double getScaleVisual() const override {335return myVehicle.getVehicleType().getParameter().scaleVisual;336}337338/// @brief sets the color according to the current scheme index and some vehicle function339static bool setFunctionalColor(int activeScheme, const MSBaseVehicle* veh, RGBColor& col);340341protected:342343/// @brief sets the color according to the current settings344RGBColor setColor(const GUIVisualizationSettings& s) const;345346/// @brief returns the seat position for the person with the given index347const Seat& getSeatPosition(int personIndex) const;348const Seat& getContainerPosition(int containerIndex) const;349350static void drawLinkItem(const Position& pos, SUMOTime arrivalTime, SUMOTime leaveTime, double exagerate);351352/// @brief A shortcut to myVehicle.myType353inline const MSVehicleType& getVType() const {354return myVehicle.getVehicleType();355}356357/// @brief draw vehicle body and return whether carriages are being drawn358bool drawAction_drawVehicleAsPolyWithCarriagges(const GUIVisualizationSettings& s, double scaledLength, bool asImage = false) const;359360/// @brief add seats to mySeatPositions and update requiredSeats361void computeSeats(const Position& front, const Position& back, double seatOffset, int maxSeats, double exaggeration, int& requiredSeats, Seats& into, double extraOffset = 0) const;362363/// @brief whether to reverse trains in their reversed state364bool drawReversed(const GUIVisualizationSettings& s) const;365366367protected:368/// The mutex used to avoid concurrent updates of the vehicle buffer369mutable FXMutex myLock;370371/// @brief positions of seats in the vehicle (updated at every drawing step)372mutable Seats mySeatPositions;373mutable Seats myContainerPositions;374375private:376/// @brief The vehicle to which all calls should be delegated377MSBaseVehicle& myVehicle;378379MSDevice_Vehroutes* myRoutes;380381/// @brief current popup (to clean up in destructor). GUIBaseVehicle is not responsible for removal382GUIGLObjectPopupMenu* myPopup;383384};385386387