/****************************************************************************/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 GNEAttributeProperties.h14/// @author Pablo Alvarez Lopez15/// @date Jan 202016///17// Abstract Base class for attribute properties used in GNEAttributeCarrier18/****************************************************************************/19#pragma once20#include <config.h>2122#include <utils/geom/Position.h>23#include <utils/xml/SUMOSAXAttributes.h>2425// ===========================================================================26// class declarations27// ===========================================================================2829class GNETagProperties;3031// ===========================================================================32// class definitions33// ===========================================================================3435class GNEAttributeProperties {3637public:3839/// @brief enum class with all attribute properties40enum class Property : int {41INT = 1 << 0, // Attribute is an integer (Including Zero)42FLOAT = 1 << 1, // Attribute is a float43SUMOTIME = 1 << 2, // Attribute is a SUMOTime44BOOL = 1 << 3, // Attribute is boolean (0/1, true/false)45STRING = 1 << 4, // Attribute is a string46POSITION = 1 << 5, // Attribute is a position defined by doubles (x,y or x,y,z)47COLOR = 1 << 6, // Attribute is a color defined by a specifically word (Red, green) or by a special format (XXX,YYY,ZZZ)48VTYPE = 1 << 7, // Attribute corresponds to a Vtype or VTypeDistribution49VCLASS = 1 << 8, // Attribute is a VClass (passenger, bus, motorcicle...)50POSITIVE = 1 << 9, // Attribute is positive (Including Zero)51UNIQUE = 1 << 10, // Attribute is unique (cannot be edited in a selection of similar elements (ID, Position...)52FILEOPEN = 1 << 11, // Attribute is a filename that opens an existent file53FILESAVE = 1 << 12, // Attribute is a filename that can create a new file54DISCRETE = 1 << 13, // Attribute is discrete (only certain values are allowed)55PROBABILITY = 1 << 14, // Attribute is probability (only allowed values between 0 and 1, including both)56ANGLE = 1 << 15, // Attribute is an angle (only takes values between 0 and 360, including both, another value will be automatically reduced57LIST = 1 << 16, // Attribute is a list of other elements separated by spaces58SECUENCIAL = 1 << 17, // Attribute is a special sequence of elements (for example: secuencial lanes in Multi Lane E2 detectors)59DEFAULTVALUE = 1 << 18, // Attribute owns a static default value60SYNONYM = 1 << 19, // Attribute will be written with a different name in der XML61RANGE = 1 << 20, // Attribute only accept a range of elements (example: Probability [0,1])62UPDATEGEOMETRY = 1 << 21, // Attribute require update geometry at the end of function setAttribute(...)63ACTIVATABLE = 1 << 22, // Attribute can be switch on/off using a checkbox in frame64FLOW = 1 << 23, // Attribute is part of a flow definition (Number, vehsPerHour...)65COPYABLE = 1 << 24, // Attribute can be copied over other element with the same tagProperty (used for edge/lane templates)66ALWAYSENABLED = 1 << 25, // Attribute cannot be disabled67NO_PROPERTY = 1 << 26, // No property defined68};6970/// @brief enum class with all edit modes71enum class Edit : int {72CREATEMODE = 1 << 0, // Attribute can be modified in create mode73EDITMODE = 1 << 1, // Attribute can be modified in edit mode74NETEDITEDITOR = 1 << 2, // Attribute can be edited only in netedit editor75EXTENDEDEDITOR = 1 << 3, // Attribute cannot be edited in editor, but is editable in extended Dialog76GEOEDITOR = 1 << 4, // Attribute can be edited only in geo editor77FLOWEDITOR = 1 << 5, // Attribute can be edited only in flow editor78DIALOGEDITOR = 1 << 6, // Attribute can be edited in dialog editor79NO_EDIT = 1 << 7, // No edit property defined80};8182/// @brief parameter constructor for attribute properties without default values83GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const Property attributeProperty,84const Edit editProperty, const std::string& definition);8586/// @brief parameter constructor for attribute properties with default values specific87GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const Property attributeProperty,88const Edit editProperty, const std::string& definition, const std::string& defaultValue);8990/// @brief parameter constructor for attribute properties with default values generic91GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const Property attributeProperty,92const Edit editProperty, const std::string& definition, const std::string& defaultValueMask,93const std::string& defaultValue);9495/// @brief parameter constructor for special attribute properties (ej: no common)96GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const std::string& definition);9798/// @brief destructor99~GNEAttributeProperties();100101/// @brief check Attribute integrity (For example, throw an exception if tag has a Float default value, but given default value cannot be parse to float)102void checkAttributeIntegrity() const;103104/// @brief set discrete values105void setDiscreteValues(const std::vector<std::string>& discreteValues);106107/// @brief set discrete values108void setFilenameExtensions(const std::vector<std::string>& extensions);109110/// @brief set default activated value111void setDefaultActivated(const bool value);112113/// @brief set synonim114void setSynonym(const SumoXMLAttr synonym);115116/// @brief set range117void setRange(const double minimum, const double maximum);118119/// @brief set tag property parent120void setTagPropertyParent(GNETagProperties* tagPropertyParent);121122/// @brief set alternative name123void setAlternativeName(const std::string& alternativeName);124125/// @brief get XML Attribute126SumoXMLAttr getAttr() const;127128/// @brief get XML Attribute in string format (can be updated using alternative name)129const std::string& getAttrStr() const;130131/// @brief get reference to tagProperty parent132const GNETagProperties* getTagPropertyParent() const;133134/// @brief get position in list (used in frames for listing attributes with certain sort)135int getPositionListed() const;136137/// @brief get default value138const std::string& getDefinition() const;139140/// @brief get default value in string format141const std::string& getDefaultStringValue() const;142143/// @brief get default int value144int getDefaultIntValue() const;145146/// @brief get default double value147double getDefaultDoubleValue() const;148149/// @brief get default time value150SUMOTime getDefaultTimeValue() const;151152/// @brief get default bool value153bool getDefaultBoolValue() const;154155/// @brief get default bool value156const RGBColor& getDefaultColorValue() const;157158/// @brief get default position value159const Position& getDefaultPositionValue() const;160161/// @brief get default active value162bool getDefaultActivated() const;163164/// @brief return category (based on Edit)165std::string getCategory() const;166167/// @brief return a description of attribute168std::string getDescription() const;169170/// @brief get discrete values171const std::vector<std::string>& getDiscreteValues() const;172173/// @brief get filename extensions in string format used in open dialogs174const std::vector<std::string>& getFilenameExtensions() const;175176/// @brief get tag synonym177SumoXMLAttr getAttrSynonym() const;178179/// @brief get minimum range180double getMinimumRange() const;181182/// @brief get maximum range183double getMaximumRange() const;184185/// @brief return true if attribute owns a default value186bool hasDefaultValue() const;187188/// @brief return true if Attr correspond to an element that will be written in XML with another name189bool hasAttrSynonym() const;190191/// @brief return true if Attr correspond to an element that only accept a range of values192bool hasAttrRange() const;193194/// @brief return true if attribute is an integer195bool isInt() const;196197/// @brief return true if attribute is a float198bool isFloat() const;199200/// @brief return true if attribute is a SUMOTime201bool isSUMOTime() const;202203/// @brief return true if attribute is boolean204bool isBool() const;205206/// @brief return true if attribute is a string207bool isString() const;208209/// @brief return true if attribute is a position210bool isPosition() const;211212/// @brief return true if attribute is a probability213bool isProbability() const;214215/// @brief return true if attribute is an angle216bool isAngle() const;217218/// @brief return true if attribute is numerical (int or float)219bool isNumerical() const;220221/// @brief return true if attribute is positive222bool isPositive() const;223224/// @brief return true if attribute is a color225bool isColor() const;226227/// @brief return true if attribute is a VType or vTypeDistribution228bool isVType() const;229230/// @brief return true if attribute is a filename open231bool isFileOpen() const;232233/// @brief return true if attribute is a filename save234bool isFileSave() const;235236/// @brief return true if attribute is a VehicleClass237bool isVClass() const;238239/// @brief return true if attribute is a VehicleClass240bool isSVCPermission() const;241242/// @brief return true if attribute is a list243bool isList() const;244245/// @brief return true if attribute is sequential246bool isSecuential() const;247248/// @brief return true if attribute is unique249bool isUnique() const;250251/// @brief return true if attribute is discrete252bool isDiscrete() const;253254/// @brief return true if attribute requires a update geometry in setAttribute(...)255bool requireUpdateGeometry() const;256257/// @brief return true if attribute is activatable258bool isActivatable() const;259260/// @brief return true if attribute is part of a flow definition261bool isFlow() const;262263/// @brief return true if attribute is copyable264bool isCopyable() const;265266/// @brief return true if attribute is always enabled267bool isAlwaysEnabled() const;268269/// @name edit modes270/// @{271272/// @brief return true if this attribute can be edited in basic editor273bool isBasicEditor() const;274275/// @brief return true if this attribute cannot be edited in editor276bool isExtendedEditor() const;277278/// @brief return true if this attribute can be edited only in GEO editor279bool isGeoEditor() const;280281/// @brief return true if this attribute can be edited only in flow editor282bool isFlowEditor() const;283284/// @brief return true if this attribute can be edited only in netedit editor285bool isNeteditEditor() const;286287/// @brief return true if attribute can be modified in create mode288bool isCreateMode() const;289290/// @brief return true if attribute can be modified in edit mode291bool isEditMode() const;292293/// @brief return true if attribute can be modified in dialog editor294bool isDialogEditor() const;295296/// @}297298private:299/// @brief pointer to tagProperty parent300const GNETagProperties* myTagPropertyParent;301302/// @brief XML Attribute303SumoXMLAttr myAttribute = SUMO_ATTR_NOTHING;304305/// @brief string with the Attribute in text format (to avoid unnecesaries toStrings(...) calls)306std::string myAttrStr;307308/// @brief attribute properties309Property myAttributeProperty = Property::NO_PROPERTY;310311/// @brief edit properties312Edit myEditProperty = Edit::NO_EDIT;313314/// @brief text with a definition of attribute315std::string myDefinition;316317/// @brief default string value318std::string myDefaultStringValue;319320/// @brief default int value321int myDefaultIntValue = 0;322323/// @brief default double value324double myDefaultDoubleValue = 0;325326/// @brief default time value327SUMOTime myDefaultTimeValue = 0;328329/// @brief default bool value330bool myDefaultBoolValue = false;331332/// @brief get default bool value333RGBColor myDefaultColorValue = RGBColor::INVISIBLE;334335/// @brief get default position value336Position myDefaultPositionValue = Position::INVALID;337338/// @brief default activated (by default false)339bool myDefaultActivated = false;340341/// @brief discrete values that can take this Attribute (by default empty)342std::vector<std::string> myDiscreteValues;343344/// @brief filename extensions used in open dialogs (by default empty)345std::vector<std::string> myFilenameExtensions;346347/// @brief Attribute written in XML (If is SUMO_ATTR_NOTHING), original Attribute will be written)348SumoXMLAttr myAttrSynonym = SUMO_ATTR_NOTHING;349350/// @brief minimun Range351double myMinimumRange = 0;352353/// @brief maxium Range354double myMaximumRange = 0;355356/// @brief check build constraints357void checkBuildConstraints() const;358359/// @brief parse default values360void parseDefaultValues(const std::string& defaultValue, const bool overWritteDefaultString);361362/// @brief invalidate default constructor363GNEAttributeProperties() = delete;364365/// @brief Invalidated copy constructor.366GNEAttributeProperties(const GNEAttributeProperties&) = delete;367368/// @brief Invalidated assignment operator369GNEAttributeProperties& operator=(const GNEAttributeProperties& src) = delete;370};371372/// @brief override attribute parent bit operator373constexpr GNEAttributeProperties::Property operator|(GNEAttributeProperties::Property a, GNEAttributeProperties::Property b) {374return static_cast<GNEAttributeProperties::Property>(static_cast<int>(a) | static_cast<int>(b));375}376377/// @brief override attribute parent bit operator378constexpr bool operator&(GNEAttributeProperties::Property a, GNEAttributeProperties::Property b) {379return (static_cast<int>(a) & static_cast<int>(b)) != 0;380}381382/// @brief override attribute parent bit operator383constexpr GNEAttributeProperties::Edit operator|(GNEAttributeProperties::Edit a, GNEAttributeProperties::Edit b) {384return static_cast<GNEAttributeProperties::Edit>(static_cast<int>(a) | static_cast<int>(b));385}386387/// @brief override attribute parent bit operator388constexpr bool operator&(GNEAttributeProperties::Edit a, GNEAttributeProperties::Edit b) {389return (static_cast<int>(a) & static_cast<int>(b)) != 0;390}391392/****************************************************************************/393394395