Path: blob/main/src/netedit/elements/demand/GNEVehicle.h
185790 views
/****************************************************************************/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 GNEVehicle.h14/// @author Pablo Alvarez Lopez15/// @date Jan 201916///17// Representation of vehicles in netedit18/****************************************************************************/19#pragma once20#include <config.h>21#include <utils/gui/globjects/GUIGLObjectPopupMenu.h>2223#include "GNEDemandElement.h"24#include "GNEDemandElementFlow.h"2526// ===========================================================================27// class declaration28// ===========================================================================2930class GNEMoveElementVehicle;31class GNEMoveElementView;3233// ===========================================================================34// class definitions35// ===========================================================================3637class GNEVehicle : public GNEDemandElement, public GNEDemandElementFlow {3839public:40/// @brief class used in GUIGLObjectPopupMenu for single vehicle transformations41class GNESingleVehiclePopupMenu : public GUIGLObjectPopupMenu {42FXDECLARE(GNESingleVehiclePopupMenu)4344public:45/** @brief Constructor46* @param[in] vehicle GNEVehicle to be transformed47* @param[in] app The main window for instantiation of other windows48* @param[in] parent The parent view for changing it49*/50GNESingleVehiclePopupMenu(GNEVehicle* vehicle, GUIMainWindow& app, GUISUMOAbstractView& parent);5152/// @brief Destructor53~GNESingleVehiclePopupMenu();5455/// @brief Called to transform the current vehicle to another vehicle type56long onCmdTransform(FXObject*, FXSelector sel, void*);5758protected:59/// @brief default constructor needed by FOX60FOX_CONSTRUCTOR(GNESingleVehiclePopupMenu);6162private:63/// @brief current vehicle64GNEVehicle* myVehicle;65};6667/// @brief class used in GUIGLObjectPopupMenu for single vehicle transformations68class GNESelectedVehiclesPopupMenu : public GUIGLObjectPopupMenu {69FXDECLARE(GNESelectedVehiclesPopupMenu)7071public:72/** @brief Constructor73* @param[in] vehicle clicked GNEVehicle74* @param[in] selectedVehicle vector with selected GNEVehicle75* @param[in] app The main window for instantiation of other windows76* @param[in] parent The parent view for changing it77*/78GNESelectedVehiclesPopupMenu(GNEVehicle* vehicle, const std::vector<GNEVehicle*>& selectedVehicle,79GUIMainWindow& app, GUISUMOAbstractView& parent);8081/// @brief Destructor82~GNESelectedVehiclesPopupMenu();8384/// @brief Called to transform the current vehicle to another vehicle type85long onCmdTransform(FXObject* obj, FXSelector sel, void*);8687protected:88/// @brief default constructor needed by FOX89FOX_CONSTRUCTOR(GNESelectedVehiclesPopupMenu);9091private:92/// @brief current selected vehicles93std::vector<GNEVehicle*> mySelectedVehicles;9495/// @brief selected menu commands96std::map<FXObject*, SumoXMLTag> myRestrictedMenuCommands;9798/// @brief tag of clicked vehicle99SumoXMLTag myVehicleTag;100};101102/// @brief default constructor103GNEVehicle(SumoXMLTag tag, GNENet* net);104105/// @brief default constructor for vehicles and routeFlows without embedded routes106GNEVehicle(SumoXMLTag tag, const std::string& vehicleID, GNENet* net, FileBucket* fileBucket,107GNEDemandElement* vehicleType, GNEDemandElement* route);108109/// @brief parameter constructor for vehicles and routeFlows without embedded routes110GNEVehicle(SumoXMLTag tag, GNENet* net, FileBucket* fileBucket, GNEDemandElement* vehicleType,111GNEDemandElement* route, const SUMOVehicleParameter& vehicleParameters);112113/// @brief parameter constructor for vehicles and routeFlows with embedded routes (note: After creation create immediately a embedded route referencing this vehicle)114GNEVehicle(SumoXMLTag tag, GNENet* net, FileBucket* fileBucket, GNEDemandElement* vehicleType,115const SUMOVehicleParameter& vehicleParameters);116117/// @brief default constructor for trips and Flows over edges118GNEVehicle(SumoXMLTag tag, const std::string& vehicleID, GNENet* net, FileBucket* fileBucket,119GNEDemandElement* vehicleType, GNEEdge* fromEdge, GNEEdge* toEdge);120121/// @brief parameter constructor for trips and Flows over junctions122GNEVehicle(SumoXMLTag tag, GNENet* net, FileBucket* fileBucket, GNEDemandElement* vehicleType,123GNEEdge* fromEdge, GNEEdge* toEdge, const SUMOVehicleParameter& vehicleParameters);124125/// @brief default constructor for trips and Flows over junctions126GNEVehicle(SumoXMLTag tag, const std::string& vehicleID, GNENet* net, FileBucket* fileBucket,127GNEDemandElement* vehicleType, GNEJunction* fromJunction, GNEJunction* toJunction);128129/// @brief parameter constructor for trips and Flows over junctions130GNEVehicle(SumoXMLTag tag, GNENet* net, FileBucket* fileBucket, GNEDemandElement* vehicleType,131GNEJunction* fromJunction, GNEJunction* toJunction, const SUMOVehicleParameter& vehicleParameters);132133/// @brief parameter constructor for trips and Flows over TAZs134GNEVehicle(SumoXMLTag tag, GNENet* net, FileBucket* fileBucket, GNEDemandElement* vehicleType,135GNEAdditional* fromTAZ, GNEAdditional* toTAZ, const SUMOVehicleParameter& vehicleParameters);136137/// @brief destructor138~GNEVehicle();139140/// @brief methods to retrieve the elements linked to this vehicle141/// @{142143/// @brief get GNEMoveElement associated with this vehicle144GNEMoveElement* getMoveElement() const override;145146/// @brief get parameters associated with this vehicle147Parameterised* getParameters() override;148149/// @brief get parameters associated with this vehicle (constant)150const Parameterised* getParameters() const override;151152/// @}153154/**@brief write demand element element into a xml file155* @param[in] device device in which write parameters of demand element element156*/157void writeDemandElement(OutputDevice& device) const override;158159/// @brief check if current demand element is valid to be written into XML (by default true, can be reimplemented in children)160Problem isDemandElementValid() const override;161162/// @brief return a string with the current demand element problem (by default empty, can be reimplemented in children)163std::string getDemandElementProblem() const override;164165/// @brief fix demand element problem (by default throw an exception, has to be reimplemented in children)166void fixDemandElementProblem() override;167168/// @name members and functions relative to elements common to all demand elements169/// @{170/// @brief obtain VClass related with this demand element171SUMOVehicleClass getVClass() const override;172173/// @brief get color174const RGBColor& getColor() const override;175176/// @}177178/// @name Functions related with geometry of element179/// @{180/// @brief update pre-computed geometry information181void updateGeometry() override;182183/// @brief Returns position of demand element in view184Position getPositionInView() const override;185186/// @}187188/// @name Function related with drawing189/// @{190/// @brief check if draw related contour (cyan)191bool checkDrawRelatedContour() const override;192193/// @}194195/// @name inherited from GUIGlObject196/// @{197/**@brief Returns an own popup-menu198*199* @param[in] app The application needed to build the popup-menu200* @param[in] parent The parent window needed to build the popup-menu201* @return The built popup-menu202* @see GUIGlObject::getPopUpMenu203*/204GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;205206/**@brief Returns the name of the parent object207* @return This object's parent id208*/209std::string getParentName() const override;210211/// @brief return exaggeration associated with this GLObject212double getExaggeration(const GUIVisualizationSettings& s) const override;213214/**@brief Returns the boundary to which the view shall be centered in order to show the object215* @return The boundary the object is within216*/217Boundary getCenteringBoundary() const override;218219/// @brief split geometry220void splitEdgeGeometry(const double splitPosition, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) override;221222/**@brief Draws the object223* @param[in] s The settings for the current view (may influence drawing)224* @see GUIGlObject::drawGL225*/226void drawGL(const GUIVisualizationSettings& s) const override;227228/// @}229230/// @name inherited from GNEPathElement231/// @{232233/// @brief compute pathElement234void computePathElement() override;235236/**@brief Draws partial object over lane237* @param[in] s The settings for the current view (may influence drawing)238* @param[in] segment lane segment239* @param[in] offsetFront front offset240*/241void drawLanePartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const override;242243/**@brief Draws partial object over junction244* @param[in] s The settings for the current view (may influence drawing)245* @param[in] segment junction segment246* @param[in] offsetFront front offset247*/248void drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const override;249250/// @brief get first path lane251GNELane* getFirstPathLane() const override;252253/// @brief get last path lane254GNELane* getLastPathLane() const override;255/// @}256257/// @brief inherited from GNEAttributeCarrier258/// @{259/* @brief method for getting the Attribute of an XML key260* @param[in] key The attribute key261* @return string with the value associated to key262*/263std::string getAttribute(SumoXMLAttr key) const override;264265/* @brief method for getting the Attribute of an XML key in double format266* @param[in] key The attribute key267* @return double with the value associated to key268*/269double getAttributeDouble(SumoXMLAttr key) const override;270271/* @brief method for getting the Attribute of an XML key in position format272* @param[in] key The attribute key273* @return position with the value associated to key274*/275Position getAttributePosition(SumoXMLAttr key) const override;276277/* @brief method for setting the attribute and letting the object perform demand element changes278* @param[in] key The attribute key279* @param[in] value The new value280* @param[in] undoList The undoList on which to register changes281* @param[in] net optionally the GNENet to inform about gui updates282*/283void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) override;284285/* @brief method for setting the attribute and letting the object perform demand element changes286* @param[in] key The attribute key287* @param[in] value The new value288* @param[in] undoList The undoList on which to register changes289*/290bool isValid(SumoXMLAttr key, const std::string& value) override;291292/* @brief method for enable attribute293* @param[in] key The attribute key294* @param[in] undoList The undoList on which to register changes295* @note certain attributes can be only enabled, and can produce the disabling of other attributes296*/297void enableAttribute(SumoXMLAttr key, GNEUndoList* undoList) override;298299/* @brief method for disable attribute300* @param[in] key The attribute key301* @param[in] undoList The undoList on which to register changes302* @note certain attributes can be only enabled, and can produce the disabling of other attributes303*/304void disableAttribute(SumoXMLAttr key, GNEUndoList* undoList) override;305306/* @brief method for check if the value for certain attribute is set307* @param[in] key The attribute key308*/309bool isAttributeEnabled(SumoXMLAttr key) const override;310311/// @brief get PopPup ID (Used in AC Hierarchy)312std::string getPopUpID() const override;313314/// @brief get Hierarchy Name (Used in AC Hierarchy)315std::string getHierarchyName() const override;316317/// @}318319/// @brief create a copy of the given vehicle320static GNEDemandElement* copyVehicle(const GNEVehicle* originalVehicle);321322protected:323/// @brief move element vehicle over lanes324GNEMoveElementVehicle* myMoveElementVehicle = nullptr;325326/// @brief move element over view327GNEMoveElementView* myMoveElementView = nullptr;328329/// @brief position over view330Position myPosOverView;331332/// @brief variable used for draw vehicle contours333GNEContour myVehicleContour;334335/// @brief get drawing color336RGBColor getDrawingColor(const GUIVisualizationSettings& s) const;337338/// @brier get sumo vehicle parameter339const SUMOVehicleParameter& getSUMOVehicleParameter() const;340341private:342/// @brief method for setting the attribute and nothing else343void setAttribute(SumoXMLAttr key, const std::string& value) override;344345/// @brief method for enable or disable the attribute and nothing else (used in GNEChange_ToggleAttribute)346void toggleAttribute(SumoXMLAttr key, const bool value) override;347348/// @brief Invalidated copy constructor.349GNEVehicle(const GNEVehicle&) = delete;350351/// @brief Invalidated assignment operator352GNEVehicle& operator=(const GNEVehicle&) = delete;353};354355356