Salome HOME
Merge branch 'Dev_0.6' of newgeom:newgeom into Dev_0.6
[modules/shaper.git] / src / ModelAPI / ModelAPI_Attribute.h
1 // File:        ModelAPI_Attribute.h
2 // Created:     2 Apr 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef ModelAPI_Attribute_H_
6 #define ModelAPI_Attribute_H_
7
8 #include "ModelAPI.h"
9 #include <string>
10 #include <memory>
11
12 class ModelAPI_Object;
13
14 /**\class ModelAPI_Attribute
15  * \ingroup DataModel
16  * \brief Generic attribute of the Object.
17  */
18 class ModelAPI_Attribute
19 {
20   ///< needed here to emit signal that feature changed on change of the attribute
21   std::shared_ptr<ModelAPI_Object> myObject;
22   std::string myID; ///< identifier of this attribute in Data class
23  protected:
24   // accessible from the attributes
25   bool myIsInitialized; ///< is some value assigned to this attribute
26   bool myIsArgument;    ///< is this attribute used as an argument for execution
27   bool myIsImmutable;   ///< is this attribute can be changed programmatically (e.g. by constraint)
28
29  public:
30
31   /// Returns the type of this class of attributes, not static method
32   MODELAPI_EXPORT virtual std::string attributeType() = 0;
33
34   /// To virtually destroy the fields of successors
35   MODELAPI_EXPORT virtual ~ModelAPI_Attribute()
36   {
37   }
38
39   /// Sets the owner of this attribute
40   MODELAPI_EXPORT virtual void setObject(const std::shared_ptr<ModelAPI_Object>& theObject)
41   {
42     myObject = theObject;
43   }
44
45   /// Returns the owner of this attribute
46   MODELAPI_EXPORT const std::shared_ptr<ModelAPI_Object>& owner() const
47   {
48     return myObject;
49   }
50
51   /// Returns true if attribute was  initialized by some value
52   MODELAPI_EXPORT bool isInitialized()
53   {
54     return myIsInitialized;
55   }
56
57   /// Makes attribute initialized
58   MODELAPI_EXPORT void setInitialized()
59   {
60     myIsInitialized = true;
61   }
62
63   /// Set this attribute is argument for result (change of this attribute requires update of result).
64   /// By default it is true.
65   MODELAPI_EXPORT void setIsArgument(const bool theFlag)
66   {
67     myIsArgument = theFlag;
68   }
69
70   /// Returns true if attribute causes the result change
71   MODELAPI_EXPORT bool isArgument()
72   {
73     return myIsArgument;
74   }
75
76   /// Immutable argument can not be changed programaticaly (e.g. by constraint)
77   /// By default it is false.
78   /// Returns the previous state of the attribute's immutability.
79   MODELAPI_EXPORT bool setImmutable(const bool theFlag)
80   {
81     bool aResult = myIsImmutable;
82     myIsImmutable = theFlag;
83     return aResult;
84   }
85
86   /// Returns true if can not be changed programaticaly
87   MODELAPI_EXPORT bool isImmutable()
88   {
89     return myIsImmutable;
90   }
91
92   /// ID of the attribute in Data
93   MODELAPI_EXPORT const std::string& id() const
94   {
95     return myID;
96   }
97
98  protected:
99   /// Objects are created for features automatically
100   ModelAPI_Attribute()
101   {
102     myIsInitialized = false;
103     myIsArgument = true;
104     myIsImmutable = false;
105   }
106
107   /// Sets the ID of the attribute in Data (called from Data)
108   MODELAPI_EXPORT void setID(const std::string theID)
109   {
110     myID = theID;
111   }
112
113   friend class Model_Data;
114 };
115
116 //! Pointer on attribute object
117 typedef std::shared_ptr<ModelAPI_Attribute> AttributePtr;
118
119 #endif