/****************************************************************************/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 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 gets the color value according to the current scheme index109virtual double getColorValue(const GUIVisualizationSettings& s, int activeScheme) const = 0;110111/// @brief draws the given guiShape with distinct carriages/modules112virtual void drawAction_drawCarriageClass(const GUIVisualizationSettings& s, double scaledLength, bool asImage) const = 0;113114/** @brief Returns the time since the last lane change in seconds115* @see MSVehicle::myLastLaneChangeOffset116* @return The time since the last lane change in seconds117*/118virtual double getLastLaneChangeOffset() const = 0;119120/** @brief Draws the route121* @param[in] r The route to draw122*/123virtual void drawRouteHelper(const GUIVisualizationSettings& s, ConstMSRoutePtr r, bool future, bool noLoop, const RGBColor& col) const = 0;124125/// @brief retrieve information about the current stop state126virtual std::string getStopInfo() const = 0;127128/// @brief adds the blocking foes to the current selection129virtual void selectBlockingFoes() const = 0;130131/** @brief Returns an own parameter window132*133* @param[in] app The application needed to build the parameter window134* @param[in] parent The parent window needed to build the parameter window135* @return The built parameter window136* @see GUIGlObject::getParameterWindow137*/138virtual GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) = 0;139140/** @brief Returns an own type parameter window141*142* @param[in] app The application needed to build the parameter window143* @param[in] parent The parent window needed to build the parameter window144* @return The built parameter window145*/146virtual GUIParameterTableWindow* getTypeParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) = 0;147148virtual void drawAction_drawVehicleBlinker(double /*length*/) const {}149virtual void drawAction_drawVehicleBrakeLight(double length, bool onlyOne = false) const {150UNUSED_PARAMETER(length);151UNUSED_PARAMETER(onlyOne);152}153virtual void drawAction_drawLinkItems(const GUIVisualizationSettings& /*s*/) const {}154virtual void drawAction_drawPersonsAndContainers(const GUIVisualizationSettings& s) const;155/** @brief Draws the vehicle's best lanes */156virtual void drawBestLanes() const {};157virtual void drawAction_drawVehicleBlueLight() const {}158159160161162163/// @name inherited from GUIGlObject164//@{165166/** @brief Returns an own popup-menu167*168* @param[in] app The application needed to build the popup-menu169* @param[in] parent The parent window needed to build the popup-menu170* @return The built popup-menu171* @see GUIGlObject::getPopUpMenu172*/173GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent);174175/// @brief notify object about popup menu removal176void removedPopupMenu();177178/// @brief return exaggeration associated with this GLObject179double getExaggeration(const GUIVisualizationSettings& s) const;180181/** @brief Returns the boundary to which the view shall be centered in order to show the object182*183* @return The boundary the object is within184* @see GUIGlObject::getCenteringBoundary185*/186virtual Boundary getCenteringBoundary() const;187188/// @brief Returns the value for generic parameter 'name' or ''189const std::string getOptionalName() const;190191/** @brief Draws the object on the specified position with the specified angle192* @param[in] s The settings for the current view (may influence drawing)193* @param[in] pos The position to draw the vehicle on194* @param[in] angle The drawing angle of the vehicle195*/196void drawOnPos(const GUIVisualizationSettings& s, const Position& pos, const double angle) const;197198199/** @brief Draws the object200* @param[in] s The settings for the current view (may influence drawing)201* @see GUIGlObject::drawGL202*/203void drawGL(const GUIVisualizationSettings& s) const;204205206/** @brief Draws additionally triggered visualisations207* @param[in] parent The view208* @param[in] s The settings for the current view (may influence drawing)209*/210virtual void drawGLAdditional(GUISUMOAbstractView* const parent, const GUIVisualizationSettings& s) const;211//@}212213214215/// @name Additional visualisations216/// @{217218/** @brief Returns whether the named feature is enabled in the given view219* @param[in] parent The view for which the feature may be enabled220* @param[in] which The visualisation feature221* @return see comment222*/223bool hasActiveAddVisualisation(GUISUMOAbstractView* const parent, int which) const;224225226/** @brief Adds the named visualisation feature to the given view227* @param[in] parent The view for which the feature shall be enabled228* @param[in] which The visualisation feature to enable229* @see GUISUMOAbstractView::addAdditionalGLVisualisation230*/231void addActiveAddVisualisation(GUISUMOAbstractView* const parent, int which);232233234/** @brief Adds the named visualisation feature to the given view235* @param[in] parent The view for which the feature shall be enabled236* @param[in] which The visualisation feature to enable237* @see GUISUMOAbstractView::removeAdditionalGLVisualisation238*/239void removeActiveAddVisualisation(GUISUMOAbstractView* const parent, int which);240/// @}241242/// @brief return the number of passengers243int getNumPassengers() const;244245/// @brief return the number of passengers246int getNumContainers() const;247248/// @brief lists equipped device (types) for the current vehicle249std::string getDeviceDescription();250251/**252* @class GUIBaseVehiclePopupMenu253*254* A popup-menu for vehicles. In comparison to the normal popup-menu, this one255* also allows to trigger further visualisations and to track the vehicle.256*/257class GUIBaseVehiclePopupMenu : public GUIGLObjectPopupMenu {258FXDECLARE(GUIBaseVehiclePopupMenu)259260public:261/** @brief Constructor262* @param[in] app The main window for instantiation of other windows263* @param[in] parent The parent view for changing it264* @param[in] o The object of interest265*/266GUIBaseVehiclePopupMenu(GUIMainWindow& app, GUISUMOAbstractView& parent, GUIGlObject* o);267268/// @brief Destructor269~GUIBaseVehiclePopupMenu();270271/// @brief Called if all routes of the vehicle shall be shown272long onCmdShowAllRoutes(FXObject*, FXSelector, void*);273/// @brief Called if all routes of the vehicle shall be hidden274long onCmdHideAllRoutes(FXObject*, FXSelector, void*);275/// @brief Called if the current route of the vehicle shall be shown276long onCmdShowCurrentRoute(FXObject*, FXSelector, void*);277/// @brief Called if the current route of the vehicle shall be hidden278long onCmdHideCurrentRoute(FXObject*, FXSelector, void*);279/// @brief Called if the current route of the vehicle shall be shown280long onCmdShowFutureRoute(FXObject*, FXSelector, void*);281/// @brief Called if the current route of the vehicle shall be hidden282long onCmdHideFutureRoute(FXObject*, FXSelector, void*);283/// @brief Called if the current route of the vehicle shall be shown284long onCmdShowRouteNoLoops(FXObject*, FXSelector, void*);285/// @brief Called if the current route of the vehicle shall be hidden286long onCmdHideRouteNoLoops(FXObject*, FXSelector, void*);287/// @brief Called if the vehicle's best lanes shall be shown288long onCmdShowBestLanes(FXObject*, FXSelector, void*);289/// @brief Called if the vehicle's best lanes shall be hidden290long onCmdHideBestLanes(FXObject*, FXSelector, void*);291/// @brief Called if the vehicle shall be tracked292long onCmdStartTrack(FXObject*, FXSelector, void*);293/// @brief Called if the current shall not be tracked any longer294long onCmdStopTrack(FXObject*, FXSelector, void*);295/// @brief Called if all routes of the vehicle shall be shown296long onCmdShowLFLinkItems(FXObject*, FXSelector, void*);297/// @brief Called if all routes of the vehicle shall be hidden298long onCmdHideLFLinkItems(FXObject*, FXSelector, void*);299/// @brief Called to show (select) a vehicles foes300long onCmdShowFoes(FXObject*, FXSelector, void*);301/// @brief Called to select all riding persons and containers302long onCmdSelectTransported(FXObject*, FXSelector, void*);303/// @brief Called when removing the vehicle304long onCmdRemoveObject(FXObject*, FXSelector, void*);305/// @brief Called when toggling stop state306long onCmdToggleStop(FXObject*, FXSelector, void*);307308protected:309FOX_CONSTRUCTOR(GUIBaseVehiclePopupMenu)310};311312313/// @name Additional visualisations314/// @{315316/** @brief Additional visualisation feature ids317*/318enum VisualisationFeatures {319/// @brief show vehicle's best lanes320VO_SHOW_BEST_LANES = 1 << 0,321/// @brief show vehicle's current route322VO_SHOW_ROUTE = 1 << 1,323/// @brief show all vehicle's routes324VO_SHOW_ALL_ROUTES = 1 << 2,325/// @brief LFLinkItems326VO_SHOW_LFLINKITEMS = 1 << 3,327/// @brief draw vehicle outside the road network328VO_DRAW_OUTSIDE_NETWORK = 1 << 4,329/// @brief show vehicle's current continued from the current position330VO_SHOW_FUTURE_ROUTE = 1 << 5,331/// @brief show vehicle's routes without loops332VO_SHOW_ROUTE_NOLOOP = 1 << 6,333/// @brief track the vehicle (only needed for cleaning up)334VO_TRACK = 1 << 7335};336337/// @brief Enabled visualisations, per view338std::map<GUISUMOAbstractView*, int> myAdditionalVisualizations;339340341/** @brief Chooses the route to draw and draws it, darkening it as given342* @param[in] s The visualisation settings, needed to determine the vehicle's color343* @param[in] routeNo The route to show (0: the current, >0: prior)344* @param[in] darken The amount to darken the route by345*/346void drawRoute(const GUIVisualizationSettings& s, int routeNo, double darken, bool future = false, bool noLoop = false) const;347348void drawStopLabels(const GUIVisualizationSettings& s, bool noLoop, const RGBColor& col) const;349350void drawParkingInfo(const GUIVisualizationSettings& s) const;351352void drawChargingInfo(const GUIVisualizationSettings& s) const;353/// @}354355const MSBaseVehicle& getVehicle() {356return myVehicle;357}358359/// @brief gets the size multiplier value according to the current scheme index360double getScaleValue(const GUIVisualizationSettings& s, int activeScheme) const;361362double getScaleVisual() const {363return myVehicle.getVehicleType().getParameter().scaleVisual;364}365366/// @brief sets the color according to the current scheme index and some vehicle function367static bool setFunctionalColor(int activeScheme, const MSBaseVehicle* veh, RGBColor& col);368369protected:370371/// @brief sets the color according to the current settings372RGBColor setColor(const GUIVisualizationSettings& s) const;373374/// @brief returns the seat position for the person with the given index375const Seat& getSeatPosition(int personIndex) const;376const Seat& getContainerPosition(int containerIndex) const;377378static void drawLinkItem(const Position& pos, SUMOTime arrivalTime, SUMOTime leaveTime, double exagerate);379380/// @brief A shortcut to myVehicle.myType381inline const MSVehicleType& getVType() const {382return myVehicle.getVehicleType();383}384385/// @brief draw vehicle body and return whether carriages are being drawn386bool drawAction_drawVehicleAsPolyWithCarriagges(const GUIVisualizationSettings& s, double scaledLength, bool asImage = false) const;387388/// @brief add seats to mySeatPositions and update requiredSeats389void computeSeats(const Position& front, const Position& back, double seatOffset, int maxSeats, double exaggeration, int& requiredSeats, Seats& into, double extraOffset = 0) const;390391/// @brief whether to reverse trains in their reversed state392bool drawReversed(const GUIVisualizationSettings& s) const;393394395protected:396/// The mutex used to avoid concurrent updates of the vehicle buffer397mutable FXMutex myLock;398399/// @brief positions of seats in the vehicle (updated at every drawing step)400mutable Seats mySeatPositions;401mutable Seats myContainerPositions;402403private:404/// @brief The vehicle to which all calls should be delegated405MSBaseVehicle& myVehicle;406407MSDevice_Vehroutes* myRoutes;408409/// @brief current popup (to clean up in destructor). GUIBaseVehicle is not responsible for removal410GUIGLObjectPopupMenu* myPopup;411412};413414415