/****************************************************************************/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 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 disabled67SORTABLE = 1 << 26, // Attribute can be used for sort elements in dialog68NO_PROPERTY = 1 << 27, // No property defined69};7071/// @brief enum class with all edit modes72enum class Edit : int {73CREATEMODE = 1 << 0, // Attribute can be modified in create mode74EDITMODE = 1 << 1, // Attribute can be modified in edit mode75NETEDITEDITOR = 1 << 2, // Attribute can be edited only in netedit editor76EXTENDEDEDITOR = 1 << 3, // Attribute cannot be edited in editor, but is editable in extended Dialog77GEOEDITOR = 1 << 4, // Attribute can be edited only in geo editor78FLOWEDITOR = 1 << 5, // Attribute can be edited only in flow editor79DIALOGEDITOR = 1 << 6, // Attribute can be edited in dialog editor80NO_EDIT = 1 << 7, // No edit property defined81};8283/// @brief parameter constructor for attribute properties without default values84GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const Property attributeProperty,85const Edit editProperty, const std::string& definition);8687/// @brief parameter constructor for attribute properties with default values specific88GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const Property attributeProperty,89const Edit editProperty, const std::string& definition, const std::string& defaultValue);9091/// @brief parameter constructor for attribute properties with default values generic92GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const Property attributeProperty,93const Edit editProperty, const std::string& definition, const std::string& defaultValueMask,94const std::string& defaultValue);9596/// @brief parameter constructor for special attribute properties (ej: no common)97GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const std::string& definition);9899/// @brief destructor100~GNEAttributeProperties();101102/// @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)103void checkAttributeIntegrity() const;104105/// @brief set discrete values106void setDiscreteValues(const std::vector<std::string>& discreteValues);107108/// @brief set discrete values109void setFilenameExtensions(const std::vector<std::string>& extensions);110111/// @brief set default activated value112void setDefaultActivated(const bool value);113114/// @brief set synonim115void setSynonym(const SumoXMLAttr synonym);116117/// @brief set range118void setRange(const double minimum, const double maximum);119120/// @brief set tag property parent121void setTagPropertyParent(GNETagProperties* tagPropertyParent);122123/// @brief set alternative name124void setAlternativeName(const std::string& alternativeName);125126/// @brief get XML Attribute127SumoXMLAttr getAttr() const;128129/// @brief get XML Attribute in string format (can be updated using alternative name)130const std::string& getAttrStr() const;131132/// @brief get reference to tagProperty parent133const GNETagProperties* getTagPropertyParent() const;134135/// @brief get position in list (used in frames for listing attributes with certain sort)136int getPositionListed() const;137138/// @brief get default value139const std::string& getDefinition() const;140141/// @brief get default value in string format142const std::string& getDefaultStringValue() const;143144/// @brief get default int value145int getDefaultIntValue() const;146147/// @brief get default double value148double getDefaultDoubleValue() const;149150/// @brief get default time value151SUMOTime getDefaultTimeValue() const;152153/// @brief get default bool value154bool getDefaultBoolValue() const;155156/// @brief get default bool value157const RGBColor& getDefaultColorValue() const;158159/// @brief get default position value160const Position& getDefaultPositionValue() const;161162/// @brief get default active value163bool getDefaultActivated() const;164165/// @brief return category (based on Edit)166std::string getCategory() const;167168/// @brief return a description of attribute169std::string getDescription() const;170171/// @brief get discrete values172const std::vector<std::string>& getDiscreteValues() const;173174/// @brief get filename extensions in string format used in open dialogs175const std::vector<std::string>& getFilenameExtensions() const;176177/// @brief get tag synonym178SumoXMLAttr getAttrSynonym() const;179180/// @brief get minimum range181double getMinimumRange() const;182183/// @brief get maximum range184double getMaximumRange() const;185186/// @brief return true if attribute owns a default value187bool hasDefaultValue() const;188189/// @brief return true if Attr correspond to an element that will be written in XML with another name190bool hasAttrSynonym() const;191192/// @brief return true if Attr correspond to an element that only accept a range of values193bool hasAttrRange() const;194195/// @brief return true if attribute is an integer196bool isInt() const;197198/// @brief return true if attribute is a float199bool isFloat() const;200201/// @brief return true if attribute is a SUMOTime202bool isSUMOTime() const;203204/// @brief return true if attribute is boolean205bool isBool() const;206207/// @brief return true if attribute is a string208bool isString() const;209210/// @brief return true if attribute is a position211bool isPosition() const;212213/// @brief return true if attribute is a probability214bool isProbability() const;215216/// @brief return true if attribute is an angle217bool isAngle() const;218219/// @brief return true if attribute is numerical (int or float)220bool isNumerical() const;221222/// @brief return true if attribute is positive223bool isPositive() const;224225/// @brief return true if attribute is a color226bool isColor() const;227228/// @brief return true if attribute is a VType or vTypeDistribution229bool isVType() const;230231/// @brief return true if attribute is a filename open232bool isFileOpen() const;233234/// @brief return true if attribute is a filename save235bool isFileSave() const;236237/// @brief return true if attribute is a VehicleClass238bool isVClass() const;239240/// @brief return true if attribute is a VehicleClass241bool isSVCPermission() const;242243/// @brief return true if attribute is a list244bool isList() const;245246/// @brief return true if attribute is sequential247bool isSecuential() const;248249/// @brief return true if attribute is unique250bool isUnique() const;251252/// @brief return true if attribute is discrete253bool isDiscrete() const;254255/// @brief return true if attribute requires a update geometry in setAttribute(...)256bool requireUpdateGeometry() const;257258/// @brief return true if attribute is activatable259bool isActivatable() const;260261/// @brief return true if attribute is part of a flow definition262bool isFlow() const;263264/// @brief return true if attribute is copyable265bool isCopyable() const;266267/// @brief return true if attribute is always enabled268bool isAlwaysEnabled() const;269270/// @brief return true if attribute can be used for sorting elements in dialogs271bool isSortable() const;272273/// @name edit modes274/// @{275276/// @brief return true if this attribute can be edited in basic editor277bool isBasicEditor() const;278279/// @brief return true if this attribute cannot be edited in editor280bool isExtendedEditor() const;281282/// @brief return true if this attribute can be edited only in GEO editor283bool isGeoEditor() const;284285/// @brief return true if this attribute can be edited only in flow editor286bool isFlowEditor() const;287288/// @brief return true if this attribute can be edited only in netedit editor289bool isNeteditEditor() const;290291/// @brief return true if attribute can be modified in create mode292bool isCreateMode() const;293294/// @brief return true if attribute can be modified in edit mode295bool isEditMode() const;296297/// @brief return true if attribute can be modified in dialog editor298bool isDialogEditor() const;299300/// @}301302private:303/// @brief pointer to tagProperty parent304const GNETagProperties* myTagPropertyParent;305306/// @brief XML Attribute307SumoXMLAttr myAttribute = SUMO_ATTR_NOTHING;308309/// @brief string with the Attribute in text format (to avoid unnecesaries toStrings(...) calls)310std::string myAttrStr;311312/// @brief attribute properties313Property myAttributeProperty = Property::NO_PROPERTY;314315/// @brief edit properties316Edit myEditProperty = Edit::NO_EDIT;317318/// @brief text with a definition of attribute319std::string myDefinition;320321/// @brief default string value322std::string myDefaultStringValue;323324/// @brief default int value325int myDefaultIntValue = 0;326327/// @brief default double value328double myDefaultDoubleValue = 0;329330/// @brief default time value331SUMOTime myDefaultTimeValue = 0;332333/// @brief default bool value334bool myDefaultBoolValue = false;335336/// @brief get default bool value337RGBColor myDefaultColorValue = RGBColor::INVISIBLE;338339/// @brief get default position value340Position myDefaultPositionValue = Position::INVALID;341342/// @brief default activated (by default false)343bool myDefaultActivated = false;344345/// @brief discrete values that can take this Attribute (by default empty)346std::vector<std::string> myDiscreteValues;347348/// @brief filename extensions used in open dialogs (by default empty)349std::vector<std::string> myFilenameExtensions;350351/// @brief Attribute written in XML (If is SUMO_ATTR_NOTHING), original Attribute will be written)352SumoXMLAttr myAttrSynonym = SUMO_ATTR_NOTHING;353354/// @brief minimun Range355double myMinimumRange = 0;356357/// @brief maxium Range358double myMaximumRange = 0;359360/// @brief check build constraints361void checkBuildConstraints() const;362363/// @brief parse default values364void parseDefaultValues(const std::string& defaultValue, const bool overWritteDefaultString);365366/// @brief invalidate default constructor367GNEAttributeProperties() = delete;368369/// @brief Invalidated copy constructor.370GNEAttributeProperties(const GNEAttributeProperties&) = delete;371372/// @brief Invalidated assignment operator373GNEAttributeProperties& operator=(const GNEAttributeProperties& src) = delete;374};375376/// @brief override attribute parent bit operator377constexpr GNEAttributeProperties::Property operator|(GNEAttributeProperties::Property a, GNEAttributeProperties::Property b) {378return static_cast<GNEAttributeProperties::Property>(static_cast<int>(a) | static_cast<int>(b));379}380381/// @brief override attribute parent bit operator382constexpr bool operator&(GNEAttributeProperties::Property a, GNEAttributeProperties::Property b) {383return (static_cast<int>(a) & static_cast<int>(b)) != 0;384}385386/// @brief override attribute parent bit operator387constexpr GNEAttributeProperties::Edit operator|(GNEAttributeProperties::Edit a, GNEAttributeProperties::Edit b) {388return static_cast<GNEAttributeProperties::Edit>(static_cast<int>(a) | static_cast<int>(b));389}390391/// @brief override attribute parent bit operator392constexpr bool operator&(GNEAttributeProperties::Edit a, GNEAttributeProperties::Edit b) {393return (static_cast<int>(a) & static_cast<int>(b)) != 0;394}395396/****************************************************************************/397398399