Salome HOME
5250ffe6e915e952fb4dbd79f7c2654fa341cfaf
[modules/shaper.git] / src / ModelAPI / ModelAPI_Attribute.h
1 // Copyright (C) 2014-2023  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef ModelAPI_Attribute_H_
21 #define ModelAPI_Attribute_H_
22
23 #include "ModelAPI.h"
24 #include <string>
25 #include <memory>
26
27 class ModelAPI_Object;
28
29 /**\class ModelAPI_Attribute
30  * \ingroup DataModel
31  * \brief Generic attribute of the Object.
32  */
33 class ModelAPI_Attribute
34 {
35   ///< needed here to emit signal that feature changed on change of the attribute
36   std::shared_ptr<ModelAPI_Object> myObject;
37   std::string myID; ///< identifier of this attribute in Data class
38  protected:
39   // accessible from the attributes
40   bool myIsInitialized; ///< is some value assigned to this attribute
41   bool mySetInitializedBlocked; ///< is initialized blocked
42   bool myIsArgument;    ///< is this attribute used as an argument for execution
43   bool myIsImmutable;   ///< is this attribute can be changed programmatically (e.g. by constraint)
44
45  public:
46
47   /// Returns the type of this class of attributes, not static method
48   MODELAPI_EXPORT virtual std::string attributeType() = 0;
49
50   /// To virtually destroy the fields of successors
51   MODELAPI_EXPORT virtual ~ModelAPI_Attribute();
52
53   /// Sets the owner of this attribute
54   MODELAPI_EXPORT virtual void setObject(const std::shared_ptr<ModelAPI_Object>& theObject);
55
56   /// Returns the owner of this attribute
57   MODELAPI_EXPORT const std::shared_ptr<ModelAPI_Object>& owner() const;
58
59   /// Returns true if attribute was  initialized by some value
60   MODELAPI_EXPORT virtual bool isInitialized();
61
62   /// Makes attribute initialized
63   MODELAPI_EXPORT void setInitialized();
64
65   /// Blocks sending "attribute updated" if theBlock is true
66   /// \param theBlock a block value
67   /// \return the previous block value
68   MODELAPI_EXPORT bool blockSetInitialized(const bool theBlock);
69
70   /// Set this attribute is argument for result
71   /// (change of this attribute requires update of result).
72   /// By default it is true.
73   MODELAPI_EXPORT void setIsArgument(const bool theFlag);
74
75   /// Returns true if attribute causes the result change
76   MODELAPI_EXPORT bool isArgument();
77
78   /// Immutable argument can not be changed programmatically (e.g. by constraint)
79   /// By default it is false.
80   /// Returns the previous state of the attribute's immutability.
81   MODELAPI_EXPORT bool setImmutable(const bool theFlag);
82
83   /// Returns true if can not be changed programmatically
84   MODELAPI_EXPORT bool isImmutable();
85
86   /// ID of the attribute in Data
87   MODELAPI_EXPORT const std::string& id() const;
88
89   /// Resets attribute to deafult state.
90   MODELAPI_EXPORT virtual void reset();
91
92  protected:
93   /// Objects are created for features automatically
94   MODELAPI_EXPORT ModelAPI_Attribute();
95
96   /// Sets the ID of the attribute in Data (called from Data)
97   MODELAPI_EXPORT virtual void setID(const std::string theID);
98
99   /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
100   MODELAPI_EXPORT virtual void reinit();
101
102   friend class Model_Data;
103   friend class Model_Objects;
104 };
105
106 //! Pointer on attribute object
107 typedef std::shared_ptr<ModelAPI_Attribute> AttributePtr;
108
109 #endif