Path: blob/main/src/netedit/elements/GNEAttributeCarrier.h
193906 views
/****************************************************************************/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 GNEAttributeCarrier.h14/// @author Jakob Erdmann15/// @date Mar 201116///17// Abstract Base class for gui objects which carry attributes18/****************************************************************************/19#pragma once20#include <config.h>2122#include <netedit/GNEReferenceCounter.h>23#include <utils/common/FileBucket.h>24#include <utils/foxtools/fxheader.h>2526// ===========================================================================27// class declarations28// ===========================================================================2930class FileBucket;31class GNEHierarchicalElement;32class GNELane;33class GNEMoveElement;34class GNENet;35class GNETagProperties;36class GNEUndoList;37class GUIGlObject;38class Parameterised;3940// ===========================================================================41// class definitions42// ===========================================================================4344class GNEAttributeCarrier : public GNEReferenceCounter {4546/// @brief declare friend class47friend class GNEChange_Attribute;48friend class GNEChange_ToggleAttribute;49friend class GNEAttributesEditorType;5051public:52/**@brief Constructor for templates53* @param[in] tag SUMO Tag assigned to this type of object54* @param[in] net GNENet in which this AttributeCarrier is stored55*/56GNEAttributeCarrier(const SumoXMLTag tag, GNENet* net);5758/**@brief Constructor59* @param[in] tag SUMO Tag assigned to this type of object60* @param[in] net GNENet in which this AttributeCarrier is stored61* @param[in] fileBucket bucket in which this AttributeCarrier is stored62*/63GNEAttributeCarrier(const SumoXMLTag tag, GNENet* net, FileBucket* fileBucket);6465/// @brief Destructor66virtual ~GNEAttributeCarrier();6768/// @brief methods to retrieve the elements linked to this AttributeCarrier69/// @{7071/// @brief get GNEHierarchicalElement associated with this AttributeCarrier72virtual GNEHierarchicalElement* getHierarchicalElement() = 0;7374/// @brief get GNEMoveElement associated with this AttributeCarrier75virtual GNEMoveElement* getMoveElement() const = 0;7677/// @brief get parameters associated with this AttributeCarrier78virtual Parameterised* getParameters() = 0;7980/// @brief get parameters associated with this AttributeCarrier (constant)81virtual const Parameterised* getParameters() const = 0;8283/// @brief get GUIGlObject associated with this AttributeCarrier84virtual GUIGlObject* getGUIGlObject() = 0;8586/// @brief get GUIGlObject associated with this AttributeCarrier (constant)87virtual const GUIGlObject* getGUIGlObject() const = 0;8889/// @}9091/// @brief get ID (all Attribute Carriers have one)92const std::string getID() const override;9394/// @brief get pointer to net95GNENet* getNet() const;9697/// @brief get reference to fileBucket in which save this AC98virtual FileBucket* getFileBucket() const = 0;99100/// @brief update pre-computed geometry information101virtual void updateGeometry() = 0;102103/// @name Function related with selection104/// @{105/// @brief select attribute carrier using GUIGlobalSelection106void selectAttributeCarrier();107108/// @brief unselect attribute carrier using GUIGlobalSelection109void unselectAttributeCarrier();110111/// @brief check if attribute carrier is selected112bool isAttributeCarrierSelected() const;113114/// @}115116/// @name Function related with drawing117/// @{118119/// @brief check if attribute carrier must be drawn using selecting color.120bool drawUsingSelectColor() const;121122/// @brief check if draw moving geometry points123bool drawMovingGeometryPoints() const;124125/// @}126127/// @name Function related with front elements128/// @{129130/// @brief mark for drawing front131void markForDrawingFront();132133/// @brief unmark for drawing front134void unmarkForDrawingFront();135136/// @brief check if this AC is marked for drawing front137bool isMarkedForDrawingFront() const;138139/// @brief draw element in the given layer, or in front if corresponding flag is enabled140void drawInLayer(const double typeOrLayer, const double extraOffset = 0) const;141142/// @}143144/// @name Function related with grid (needed for elements that aren't always in grid)145/// @{146147/// @brief mark if this AC was inserted in grid or not148void setInGrid(bool value);149150/// @brief check if this AC was inserted in grid151bool inGrid() const;152153/// @}154155/// @name Function related with contour drawing156/// @{157158/// @brief check if draw inspect contour (black/white)159bool checkDrawInspectContour() const;160161/// @brief check if draw front contour (green/blue)162bool checkDrawFrontContour() const;163164/// @brief check if draw from contour (green)165virtual bool checkDrawFromContour() const = 0;166167/// @brief check if draw from contour (magenta)168virtual bool checkDrawToContour() const = 0;169170/// @brief check if draw related contour (cyan)171virtual bool checkDrawRelatedContour() const = 0;172173/// @brief check if draw over contour (orange)174virtual bool checkDrawOverContour() const = 0;175176/// @brief check if draw delete contour (pink/white)177virtual bool checkDrawDeleteContour() const = 0;178179/// @brief check if draw delete contour small (pink/white)180virtual bool checkDrawDeleteContourSmall() const = 0;181182/// @brief check if draw select contour (blue)183virtual bool checkDrawSelectContour() const = 0;184185/// @brief check if draw move contour (red)186virtual bool checkDrawMoveContour() const = 0;187188/// @}189190/// @brief reset attribute carrier to their default values191void resetDefaultValues(const bool allowUndoRedo);192193/// @name Functions related with attributes (must be implemented in all children)194/// @{195196/* @brief method for getting the Attribute of an XML key197* @param[in] key The attribute key198* @return string with the value associated to key199*/200virtual std::string getAttribute(SumoXMLAttr key) const = 0;201202/* @brief method for getting the Attribute of an XML key in double format203* @param[in] key The attribute key204* @return double with the value associated to key205*/206virtual double getAttributeDouble(SumoXMLAttr key) const = 0;207208/* @brief method for getting the Attribute of an XML key in position format209* @param[in] key The attribute key210* @return position with the value associated to key211*/212virtual Position getAttributePosition(SumoXMLAttr key) const = 0;213214/* @brief method for getting the Attribute of an XML key in positionVector format215* @param[in] key The attribute key216* @return positionVector with the value associated to key217*/218virtual PositionVector getAttributePositionVector(SumoXMLAttr key) const = 0;219220/* @brief method for setting the attribute and letting the object perform additional changes221* @param[in] key The attribute key222* @param[in] value The new value223* @param[in] undoList The undoList on which to register changes224*/225virtual void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) = 0;226227/* @brief method for check if new value for certain attribute is valid228* @param[in] key The attribute key229* @param[in] value The new value230*/231virtual bool isValid(SumoXMLAttr key, const std::string& value) = 0;232233/* @brief method for enable attribute234* @param[in] key The attribute key235* @param[in] undoList The undoList on which to register changes236* @note certain attributes can be only enabled, and can produce the disabling of other attributes237*/238virtual void enableAttribute(SumoXMLAttr key, GNEUndoList* undoList);239240/* @brief method for disable attribute241* @param[in] key The attribute key242* @param[in] undoList The undoList on which to register changes243* @note certain attributes can be only enabled, and can produce the disabling of other attributes244*/245virtual void disableAttribute(SumoXMLAttr key, GNEUndoList* undoList);246247/* @brief method for check if the value for certain attribute is set248* @param[in] key The attribute key249*/250virtual bool isAttributeEnabled(SumoXMLAttr key) const;251252/* @brief method for check if the value for certain attribute is computed (for example, due a network recomputing)253* @param[in] key The attribute key254*/255virtual bool isAttributeComputed(SumoXMLAttr key) const;256257/* @brief method for check if the value for certain attribute is set258* @param[in] key The attribute key259*/260bool hasAttribute(SumoXMLAttr key) const;261262/// @brief get PopPup ID (Used in AC Hierarchy)263virtual std::string getPopUpID() const = 0;264265/// @brief get Hierarchy Name (Used in AC Hierarchy)266virtual std::string getHierarchyName() const = 0;267268/// @}269270/// @name Function related with parameters271/// @{272273/// @brief set parameters (string vector)274void setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters);275276/// @brief set parameters (string vector, undoList)277void setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters, GNEUndoList* undoList);278279/// @brief set parameters (map, undoList)280void setACParameters(const Parameterised::Map& parameters, GNEUndoList* undoList);281282/// @}283284/* @brief method for return an alternative value for disabled attributes. Used only in GNEFrames285* @param[in] key The attribute key286*/287std::string getAlternativeValueForDisabledAttributes(SumoXMLAttr key) const;288289/// @brief method for getting the attribute in the context of object selection290virtual std::string getAttributeForSelection(SumoXMLAttr key) const;291292/// @brief get tag assigned to this object in string format293const std::string& getTagStr() const;294295/// @brief get FXIcon associated to this AC296FXIcon* getACIcon() const;297298/// @brief check if this AC is template299bool isTemplate() const;300301/// @brief get tagProperty associated with this Attribute Carrier302const GNETagProperties* getTagProperty() const;303304/// @name parse functions305/// @{306307/// @brief true if a value of type T can be parsed from string308template<typename T>309static bool canParse(const std::string& string);310311/// @brief parses a value of type T from string (used for basic types: int, double, bool, etc.)312template<typename T>313static T parse(const std::string& string);314315/**@brief true if a value of type T can be parsed from string (requieres network)316* @note checkConsecutivity doesn't check connectivity trought connections317*/318template<typename T>319static bool canParse(const GNENet* net, const std::string& value, const bool checkConsecutivity);320321/// @brief parses a complex value of type T from string (use for list of edges, list of lanes, etc.)322template<typename T>323static T parse(const GNENet* net, const std::string& value);324325/// @brief parses a list of specific Attribute Carriers into a string of IDs326template<typename T>327static std::string parseIDs(const std::vector<T>& ACs);328329/// @}330331/// @name Functions related with common attributes332/// @{333/* @brief method for getting the common attribute of an XML key334* @param[in] key The attribute key335* @return string with the value associated to key336*/337std::string getCommonAttribute(SumoXMLAttr key) const;338339/* @brief method for getting the common attribute of an XML key in double format340* @param[in] key The attribute key341* @return double with the value associated to key342*/343double getCommonAttributeDouble(SumoXMLAttr key) const;344345/* @brief method for getting the common attribute of an XML key in position format346* @param[in] key The attribute key347* @return double with the value associated to key348*/349Position getCommonAttributePosition(SumoXMLAttr key) const;350351/* @brief method for getting the common attribute of an XML key in positionVector format352* @param[in] key The attribute key353* @return double with the value associated to key354*/355PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const;356357/* @brief method for setting the common attribute and letting the object perform additional changes358* @param[in] key The attribute key359* @param[in] value The new value360* @param[in] undoList The undoList on which to register changes361*/362void setCommonAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList);363364/* @brief method for check if new value for certain common attribute is valid365* @param[in] key The attribute key366* @param[in] value The new value367*/368bool isCommonAttributeValid(SumoXMLAttr key, const std::string& value) const;369370/// @brief method for setting the common attribute and nothing else (used in GNEChange_Attribute)371void setCommonAttribute(SumoXMLAttr key, const std::string& value);372373/// @}374375/// @name Certain attributes and ACs (for example, connections) can be either loaded or guessed. The following static variables are used to remark it.376/// @{377378/// @brief feature is still unchanged after being loaded (implies approval)379static const std::string FEATURE_LOADED;380381/// @brief feature has been reguessed (may still be unchanged be we can't tell (yet)382static const std::string FEATURE_GUESSED;383384/// @brief feature has been manually modified (implies approval)385static const std::string FEATURE_MODIFIED;386387/// @brief feature has been approved but not changed (i.e. after being reguessed)388static const std::string FEATURE_APPROVED;389390/// @}391392/// @brief true value in string format (used for comparing boolean values in getAttribute(...))393static const std::string TRUE_STR;394395/// @brief true value in string format(used for comparing boolean values in getAttribute(...))396static const std::string FALSE_STR;397398protected:399/// @brief reference to tagProperty associated with this attribute carrier400const GNETagProperties* myTagProperty;401402/// @brief pointer to net403GNENet* myNet = nullptr;404405/// @brief boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)406bool mySelected = false;407408/// @brief boolean to check if drawn this AC over other elements409bool myDrawInFront = false;410411/// @brief boolean to check if this AC is in grid412bool myInGrid = false;413414/// @brief filebucket vinculated whith this AC415FileBucket* myFileBucket = nullptr;416417/// @brief boolean to check if center this element after creation418bool myCenterAfterCreation = true;419420/// @brief whether the current object is a template object (used for edit attributes)421const bool myIsTemplate = false;422423/// @brief method for enable or disable the attribute and nothing else (used in GNEChange_ToggleAttribute)424virtual void toggleAttribute(SumoXMLAttr key, const bool value);425426private:427/// @brief method for setting the attribute and nothing else (used in GNEChange_Attribute)428virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;429430/// @brief Invalidated copy constructor.431GNEAttributeCarrier(const GNEAttributeCarrier&) = delete;432433/// @brief Invalidated assignment operator434GNEAttributeCarrier& operator=(const GNEAttributeCarrier& src) = delete;435};436437438