Path: blob/main/src/netedit/elements/GNEAttributeCarrier.h
169678 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 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/foxtools/fxheader.h>2425// ===========================================================================26// class declarations27// ===========================================================================2829class GNEHierarchicalElement;30class GNELane;31class GNENet;32class GNETagProperties;33class GNEUndoList;34class GUIGlObject;3536// ===========================================================================37// class definitions38// ===========================================================================39/**40* @class GNEAttributeCarrier41*42* Abstract Base class for gui objects which carry attributes43* inherits from GNEReferenceCounter for convenience44*/45class GNEAttributeCarrier : public GNEReferenceCounter {4647/// @brief declare friend class48friend class GNEChange_Attribute;49friend class GNEChange_ToggleAttribute;50friend class GNEAttributesEditorType;5152public:5354/**@brief Constructor55* @param[in] tag SUMO Tag assigned to this type of object56* @param[in] net GNENet in which this AttributeCarrier is stored57* @param[in] filename file in which this AttributeCarrier is stored58* @param[in] isTemplate flag to mark this AttributeCarrier as template59*/60GNEAttributeCarrier(const SumoXMLTag tag, GNENet* net, const std::string& filename, const bool isTemplate);6162/// @brief Destructor63virtual ~GNEAttributeCarrier();6465/// @brief get ID (all Attribute Carriers have one)66const std::string getID() const;6768/// @brief get pointer to net69GNENet* getNet() const;7071/// @brief get filename in which save this AC72const std::string& getFilename() const;7374/// @brief change defaultFilename (only used in SavingFilesHandler)75void changeDefaultFilename(const std::string& file);7677/// @brief select attribute carrier using GUIGlobalSelection78void selectAttributeCarrier();7980/// @brief unselect attribute carrier using GUIGlobalSelection81void unselectAttributeCarrier();8283/// @brief check if attribute carrier is selected84bool isAttributeCarrierSelected() const;8586/// @brief check if attribute carrier must be drawn using selecting color.87bool drawUsingSelectColor() const;8889/// @brief get GNEHierarchicalElement associated with this AttributeCarrier90virtual GNEHierarchicalElement* getHierarchicalElement() = 0;9192/// @name Function related front elements93/// @{9495/// @brief mark for drawing front96void markForDrawingFront();9798/// @brief unmark for drawing front99void unmarkForDrawingFront();100101/// @brief check if this AC is marked for drawing front102bool isMarkedForDrawingFront() const;103104/// @brief draw element in the given layer, or in front if corresponding flag is enabled105void drawInLayer(const double typeOrLayer, const double extraOffset = 0) const;106107/// @}108109/// @name Function related with grid (needed for elements that aren't always in grid)110/// @{111/// @brief mark if this AC was inserted in grid or not112void setInGrid(bool value);113114/// @brief check if this AC was inserted in grid115bool inGrid() const;116117/// @}118119/// @name Function related with graphics (must be implemented in all children)120/// @{121/// @brief get GUIGlObject associated with this AttributeCarrier122virtual GUIGlObject* getGUIGlObject() = 0;123124/// @brief get GUIGlObject associated with this AttributeCarrier (constant)125virtual const GUIGlObject* getGUIGlObject() const = 0;126127/// @brief update pre-computed geometry information128virtual void updateGeometry() = 0;129130/// @}131132/// @name Function related with contourdrawing (can be implemented in children)133/// @{134135/// @brief check if draw inspect contour (black/white)136bool checkDrawInspectContour() const;137138/// @brief check if draw front contour (green/blue)139bool checkDrawFrontContour() const;140141/// @brief check if draw from contour (green)142virtual bool checkDrawFromContour() const = 0;143144/// @brief check if draw from contour (magenta)145virtual bool checkDrawToContour() const = 0;146147/// @brief check if draw related contour (cyan)148virtual bool checkDrawRelatedContour() const = 0;149150/// @brief check if draw over contour (orange)151virtual bool checkDrawOverContour() const = 0;152153/// @brief check if draw delete contour (pink/white)154virtual bool checkDrawDeleteContour() const = 0;155156/// @brief check if draw delete contour small (pink/white)157virtual bool checkDrawDeleteContourSmall() const = 0;158159/// @brief check if draw select contour (blue)160virtual bool checkDrawSelectContour() const = 0;161162/// @brief check if draw move contour (red)163virtual bool checkDrawMoveContour() const = 0;164165/// @}166167/// @brief reset attribute carrier to their default values168void resetDefaultValues(const bool allowUndoRedo);169170/// @name Functions related with attributes (must be implemented in all children)171/// @{172/* @brief method for getting the Attribute of an XML key173* @param[in] key The attribute key174* @return string with the value associated to key175*/176virtual std::string getAttribute(SumoXMLAttr key) const = 0;177178/* @brief method for setting the attribute and letting the object perform additional changes179* @param[in] key The attribute key180* @param[in] value The new value181* @param[in] undoList The undoList on which to register changes182*/183virtual void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) = 0;184185/* @brief method for check if new value for certain attribute is valid186* @param[in] key The attribute key187* @param[in] value The new value188*/189virtual bool isValid(SumoXMLAttr key, const std::string& value) = 0;190191/* @brief method for enable attribute192* @param[in] key The attribute key193* @param[in] undoList The undoList on which to register changes194* @note certain attributes can be only enabled, and can produce the disabling of other attributes195*/196virtual void enableAttribute(SumoXMLAttr key, GNEUndoList* undoList);197198/* @brief method for disable attribute199* @param[in] key The attribute key200* @param[in] undoList The undoList on which to register changes201* @note certain attributes can be only enabled, and can produce the disabling of other attributes202*/203virtual void disableAttribute(SumoXMLAttr key, GNEUndoList* undoList);204205/* @brief method for check if the value for certain attribute is set206* @param[in] key The attribute key207*/208virtual bool isAttributeEnabled(SumoXMLAttr key) const;209210/* @brief method for check if the value for certain attribute is computed (for example, due a network recomputing)211* @param[in] key The attribute key212*/213virtual bool isAttributeComputed(SumoXMLAttr key) const;214215/* @brief method for check if the value for certain attribute is set216* @param[in] key The attribute key217*/218bool hasAttribute(SumoXMLAttr key) const;219220/// @brief get PopPup ID (Used in AC Hierarchy)221virtual std::string getPopUpID() const = 0;222223/// @brief get Hierarchy Name (Used in AC Hierarchy)224virtual std::string getHierarchyName() const = 0;225226/// @}227228/// @name Function related with parameters229/// @{230/// @brief get parameters map231virtual const Parameterised::Map& getACParametersMap() const = 0;232233/// @brief set parameters (string vector)234void setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters);235236/// @brief set parameters (string vector, undoList)237void setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters, GNEUndoList* undoList);238239/// @brief set parameters (map, undoList)240void setACParameters(const Parameterised::Map& parameters, GNEUndoList* undoList);241242/// @}243244/* @brief method for return an alternative value for disabled attributes. Used only in GNEFrames245* @param[in] key The attribute key246*/247std::string getAlternativeValueForDisabledAttributes(SumoXMLAttr key) const;248249/// @brief method for getting the attribute in the context of object selection250virtual std::string getAttributeForSelection(SumoXMLAttr key) const;251252/// @brief get tag assigned to this object in string format253const std::string& getTagStr() const;254255/// @brief get FXIcon associated to this AC256FXIcon* getACIcon() const;257258/// @brief check if this AC is template259bool isTemplate() const;260261/// @brief get tagProperty associated with this Attribute Carrier262const GNETagProperties* getTagProperty() const;263264/// @name parse functions265/// @{266267/// @brief true if a value of type T can be parsed from string268template<typename T>269static bool canParse(const std::string& string);270271/// @brief parses a value of type T from string (used for basic types: int, double, bool, etc.)272template<typename T>273static T parse(const std::string& string);274275/**@brief true if a value of type T can be parsed from string (requieres network)276* @note checkConsecutivity doesn't check connectivity trought connections277*/278template<typename T>279static bool canParse(const GNENet* net, const std::string& value, const bool checkConsecutivity);280281/// @brief parses a complex value of type T from string (use for list of edges, list of lanes, etc.)282template<typename T>283static T parse(const GNENet* net, const std::string& value);284285/// @brief parses a list of specific Attribute Carriers into a string of IDs286template<typename T>287static std::string parseIDs(const std::vector<T>& ACs);288289/// @}290291/// @name Certain attributes and ACs (for example, connections) can be either loaded or guessed. The following static variables are used to remark it.292/// @{293294/// @brief feature is still unchanged after being loaded (implies approval)295static const std::string FEATURE_LOADED;296297/// @brief feature has been reguessed (may still be unchanged be we can't tell (yet)298static const std::string FEATURE_GUESSED;299300/// @brief feature has been manually modified (implies approval)301static const std::string FEATURE_MODIFIED;302303/// @brief feature has been approved but not changed (i.e. after being reguessed)304static const std::string FEATURE_APPROVED;305306/// @brief lane start307static const std::string LANE_START;308309/// @brief lane end310static const std::string LANE_END;311312/// @}313314/// @brief true value in string format (used for comparing boolean values in getAttribute(...))315static const std::string TRUE_STR;316317/// @brief true value in string format(used for comparing boolean values in getAttribute(...))318static const std::string FALSE_STR;319320protected:321/// @brief reference to tagProperty associated with this attribute carrier322const GNETagProperties* myTagProperty;323324/// @brief pointer to net325GNENet* myNet = nullptr;326327/// @brief boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)328bool mySelected = false;329330/// @brief boolean to check if drawn this AC over other elements331bool myDrawInFront = false;332333/// @brief boolean to check if this AC is in grid334bool myInGrid = false;335336/// @brief filename in which save this AC337std::string myFilename;338339/// @brief boolean to check if center this element after creation340bool myCenterAfterCreation = true;341342/// @brief whether the current object is a template object (used for edit attributes)343const bool myIsTemplate = false;344345/// @brief method for enable or disable the attribute and nothing else (used in GNEChange_ToggleAttribute)346virtual void toggleAttribute(SumoXMLAttr key, const bool value);347348/// @name Functions related with common attributes349/// @{350/* @brief method for getting the common attribute of an XML key351* @param[in] key The attribute key352* @return string with the value associated to key353*/354std::string getCommonAttribute(const Parameterised* parameterised, SumoXMLAttr key) const;355356/* @brief method for setting the common attribute and letting the object perform additional changes357* @param[in] key The attribute key358* @param[in] value The new value359* @param[in] undoList The undoList on which to register changes360*/361void setCommonAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList);362363/* @brief method for check if new value for certain common attribute is valid364* @param[in] key The attribute key365* @param[in] value The new value366*/367bool isCommonValid(SumoXMLAttr key, const std::string& value) const;368369/// @brief method for setting the common attribute and nothing else (used in GNEChange_Attribute)370void setCommonAttribute(Parameterised* parameterised, SumoXMLAttr key, const std::string& value);371372/// @}373374private:375/// @brief method for setting the attribute and nothing else (used in GNEChange_Attribute)376virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;377378/// @brief Invalidated copy constructor.379GNEAttributeCarrier(const GNEAttributeCarrier&) = delete;380381/// @brief Invalidated assignment operator382GNEAttributeCarrier& operator=(const GNEAttributeCarrier& src) = delete;383};384385386