Path: blob/main/src/netedit/elements/demand/GNEDemandElement.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 GNEDemandElement.h14/// @author Pablo Alvarez Lopez15/// @date Dec 201816///17// A abstract class for demand elements18/****************************************************************************/19#pragma once20#include <config.h>2122#include <netedit/elements/GNEAttributeCarrier.h>23#include <netedit/elements/GNEHierarchicalElement.h>24#include <netedit/elements/GNEPathElement.h>25#include <utils/gui/div/GUIGeometry.h>26#include <utils/gui/globjects/GUIGlObject.h>2728// ===========================================================================29// class declarations30// ===========================================================================3132class SUMOVehicleParameter;3334// ===========================================================================35// class definitions36// ===========================================================================3738class GNEDemandElement : public GNEAttributeCarrier, public GNEHierarchicalElement, public GUIGlObject, public GNEPathElement {3940public:41/// @brief friend declaration (needed for vTypes)42friend class GNERouteHandler;43friend class GNEDemandElementFlow;44friend class GNEDemandElementPlan;4546/// @brief enum class for demandElement problems47enum class Problem {48OK, // There is no problem49INVALID_ELEMENT, // Element is invalid (for example, a route without edges)50INVALID_PATH, // Path (route, trip... ) is not valid (i.e is empty)51DISCONNECTED_PLAN, // Plan element (person, containers) is not connected with the previous or next plan52INVALID_STOPPOSITION, // StopPosition is invalid (only used in stops over edges or lanes53STOP_DOWNSTREAM, // Stops don't follow their route parent54REPEATEDROUTE_DISCONNECTED, // Repeated route is disconnected55NO_PLANS // Person or container doesn't have a plan56};5758/**@brief Constructor for templates59* @param[in] tag Type of xml tag that define the demand element element (SUMO_TAG_ROUTE, SUMO_TAG_VEHICLE, etc...)60*/61GNEDemandElement(GNENet* net, SumoXMLTag tag);6263/**@brief Constructor64* @param[in] id Gl-id of the demand element element (Must be unique)65* @param[in] tag SUMO Tag assigned to this type of object66* @param[in] net GNENet in which this AttributeCarrier is stored67* @param[in] fileBucket bucket in which this AttributeCarrier is stored68*/69GNEDemandElement(const std::string& id, GNENet* net, SumoXMLTag tag, FileBucket* fileBucket);7071/**@brief Constructor72* @param[in] demandElementParent pointer to parent demand element pointer73* @param[in] tag Type of xml tag that define the demand element element (SUMO_TAG_ROUTE, SUMO_TAG_VEHICLE, etc...)74*/75GNEDemandElement(GNEDemandElement* demandElementParent, SumoXMLTag tag);7677/// @brief Destructor78virtual ~GNEDemandElement();7980/// @brief methods to retrieve the elements linked to this GNEDemandElement81/// @{8283/// @brief get GNEHierarchicalElement associated with this GNEDemandElement84GNEHierarchicalElement* getHierarchicalElement() override;8586/// @brief get GUIGlObject associated with this GNEDemandElement87GUIGlObject* getGUIGlObject() override;8889/// @brief get GUIGlObject associated with this GNEDemandElement (constant)90const GUIGlObject* getGUIGlObject() const override;9192/// @}9394/// @brief get reference to fileBucket in which save this AC95FileBucket* getFileBucket() const override;9697/// @brief change filebucket manually (used only during calibratorFlows creation)98void changeFileBucket(FileBucket* fileBucket);99100/// @brief get demand element geometry (stacked)101const GUIGeometry& getDemandElementGeometry();102103/// @brief get previous child demand element to the given demand element104GNEDemandElement* getPreviousChildDemandElement(const GNEDemandElement* demandElement) const;105106/// @brief get next child demand element to the given demand element107GNEDemandElement* getNextChildDemandElement(const GNEDemandElement* demandElement) const;108109/// @brief update element stacked geometry (stacked)110void updateDemandElementGeometry(const GNELane* lane, const double posOverLane);111112/// @brief update stack label113void updateDemandElementStackLabel(const int stack);114115/// @brief update element spread geometry116void updateDemandElementSpreadGeometry(const GNELane* lane, const double posOverLane);117118/// @name members and functions relative to elements common to all demand elements119/// @{120121/// @brief obtain VClass related with this demand element122virtual SUMOVehicleClass getVClass() const = 0;123124/// @brief get color125virtual const RGBColor& getColor() const = 0;126127/// @}128129/// @name members and functions relative to write demand elements into XML130/// @{131132/**@brief write demand element element into a xml file133* @param[in] device device in which write parameters of demand element element134*/135virtual void writeDemandElement(OutputDevice& device) const = 0;136137/// @brief check if current demand element is valid to be written into XML (by default true, can be reimplemented in children)138virtual Problem isDemandElementValid() const = 0;139140/// @brief return a string with the current demand element problem (by default empty, can be reimplemented in children)141virtual std::string getDemandElementProblem() const = 0;142143/// @brief fix demand element problem (by default throw an exception, has to be reimplemented in children)144virtual void fixDemandElementProblem() = 0;145146/// @}147148/**@brief open DemandElement Dialog149* @note: if demand element needs an demand element dialog, this function has to be implemented in childrens (see GNERerouter and GNEVariableSpeedSign)150* @throw invalid argument if demand element doesn't have an demand element Dialog151*/152virtual void openDemandElementDialog();153154/// @name Functions related with geometry of element155/// @{156157/// @brief Returns position of demand element in view158virtual Position getPositionInView() const = 0;159160/// @brief split geometry161virtual void splitEdgeGeometry(const double splitPosition, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) = 0;162163/// @brief get demand element geometry164const GUIGeometry& getDemandElementGeometry() const;165166/// @}167168/// @name Function related with contour drawing169/// @{170171/// @brief check if draw from contour (green)172bool checkDrawFromContour() const override;173174/// @brief check if draw from contour (magenta)175bool checkDrawToContour() const override;176177/// @brief check if draw related contour (cyan)178bool checkDrawRelatedContour() const override;179180/// @brief check if draw over contour (orange)181bool checkDrawOverContour() const override;182183/// @brief check if draw delete contour (pink/white)184bool checkDrawDeleteContour() const override;185186/// @brief check if draw delete contour small (pink/white)187bool checkDrawDeleteContourSmall() const override;188189/// @brief check if draw select contour (blue)190bool checkDrawSelectContour() const override;191192/// @brief check if draw move contour (red)193bool checkDrawMoveContour() const override;194195/// @}196197/// @name inherited from GUIGlObject198/// @{199200/**@brief Returns an own popup-menu201*202* @param[in] app The application needed to build the popup-menu203* @param[in] parent The parent window needed to build the popup-menu204* @return The built popup-menu205* @see GUIGlObject::getPopUpMenu206*/207virtual GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) override;208209/**@brief Returns an own parameter window210*211* @param[in] app The application needed to build the parameter window212* @param[in] parent The parent window needed to build the parameter window213* @return The built parameter window214* @see GUIGlObject::getParameterWindow215*/216GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent) override;217218/// @brief check if element is locked219bool isGLObjectLocked() const override;220221/// @brief mark element as front element222void markAsFrontElement() override;223224/// @brief delete element225void deleteGLObject() override;226227/// @brief select element228void selectGLObject() override;229230/// @brief update GLObject (geometry, ID, etc.)231void updateGLObject() override;232233/// @}234235/// @name inherited from GNEAttributeCarrier236/// @{237238/* @brief method for getting the Attribute of an XML key in position format239* @param[in] key The attribute key240* @return position with the value associated to key241*/242Position getAttributePosition(SumoXMLAttr key) const override;243244/* @brief method for getting the Attribute of an XML key in positionVector format245* @param[in] key The attribute key246* @return positionVector with the value associated to key247*/248PositionVector getAttributePositionVector(SumoXMLAttr key) const override;249250/// @}251252/// @name inherited from GNEPathElement253/// @{254255/// @brief check if path element is selected256bool isPathElementSelected() const override;257258/// @}259260/// @brief get invalid stops261std::vector<GNEDemandElement*> getInvalidStops() const;262263protected:264/// @brief demand element geometry (also called "stacked geometry")265GUIGeometry myDemandElementGeometry;266267/// @brief demand element spread geometry (Only used by vehicles and pedestrians)268GUIGeometry mySpreadGeometry;269270/// @brief stacked label number271int myStackedLabelNumber = 0;272273/// @brief check if a new demand element ID is valid274bool isValidDemandElementID(const std::string& value) const;275276/// @brief check if a new demand element ID is valid277bool isValidDemandElementID(const std::vector<SumoXMLTag>& tags, const std::string& value) const;278279/// @brief set demand element id280void setDemandElementID(const std::string& newID);281282/// @brief get type parent (needed because first parent can be either type or typeDistribution)283GNEDemandElement* getTypeParent() const;284285/// @brief get route parent (always the second parent demand element)286GNEDemandElement* getRouteParent() const;287288/// @brief draw line between junctions289void drawJunctionLine(const GNEDemandElement* element) const;290291/// @brief draw stack label292void drawStackLabel(const int number, const std::string& element, const Position& position, const double rotation,293const double width, const double length, const double exaggeration) const;294295/// @name replace parent elements296/// @{297298/// @brief all edges299void replaceParentEdges(const std::string& value);300301/// @brief replace the first parent lane302void replaceFirstParentLane(const std::string& value);303304/// @brief replace the first parent junction305void replaceFirstParentJunction(const std::string& value);306307/// @brief replace the last parent junction308void replaceLastParentJunction(const std::string& value);309310/// @brief replace the first parent edge311void replaceFirstParentEdge(const std::string& value);312313/// @brief replace the last parent edge314void replaceLastParentEdge(const std::string& value);315316/// @brief replace the first parent additional317void replaceFirstParentAdditional(SumoXMLTag tag, const std::string& value);318319/// @brief replace the last parent additional320void replaceLastParentAdditional(SumoXMLTag tag, const std::string& value);321322/// @brief replace demand element parent323void replaceDemandElementParent(const std::vector<SumoXMLTag> tags, const std::string& value, const int parentIndex);324325/// @}326327/// @brief auxiliar struct used for calculate pathStopIndex328struct EdgeStopIndex {329330/// @brief constructor331EdgeStopIndex(GNEEdge* edge_, GNEDemandElement* stop) :332edge(edge_),333stops({stop}) {}334335/// @brief edge (obtained from segment)336const GNEEdge* edge = nullptr;337338/// @brief list of stops placed in the edge339std::vector<GNEDemandElement*> stops;340341/// @brief stopIndex (-1 menans out of route)342int stopIndex = -1;343344private:345/// @brief default constructor (disabled)346EdgeStopIndex() {}347};348349/// @brief get edgeStopIndex350std::vector<EdgeStopIndex> getEdgeStopIndex() const;351352/// @brief get color by scheme (used by vehicles, persons and containers)353RGBColor getColorByScheme(const GUIColorer& c, const SUMOVehicleParameter* parameters) const;354355/// @brief build menu command route length356void buildMenuCommandRouteLength(GUIGLObjectPopupMenu* ret) const;357358/// @brief build menu command route length359void buildMenuAddReverse(GUIGLObjectPopupMenu* ret) const;360361private:362/**@brief check restriction with the number of children363* @throw ProcessError if itis called without be reimplemented in child class364*/365virtual bool checkChildDemandElementRestriction() const;366367/// @brief Invalidated copy constructor.368GNEDemandElement(const GNEDemandElement&) = delete;369370/// @brief Invalidated assignment operator.371GNEDemandElement& operator=(const GNEDemandElement&) = delete;372};373374375