Salome HOME
Merge branch 'master' of newgeom:newgeom
[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  protected:
23   // accessible from the attributes
24   bool myIsInitialized;
25   bool myIsArgument;
26   bool myIsImmutable;
27
28  public:
29
30   /// Returns the type of this class of attributes, not static method
31   MODELAPI_EXPORT virtual std::string attributeType() = 0;
32
33   /// To virtually destroy the fields of successors
34   MODELAPI_EXPORT virtual ~ModelAPI_Attribute()
35   {
36   }
37
38   /// Sets the owner of this attribute
39   MODELAPI_EXPORT virtual void setObject(const std::shared_ptr<ModelAPI_Object>& theObject)
40   {
41     myObject = theObject;
42   }
43
44   /// Returns the owner of this attribute
45   MODELAPI_EXPORT const std::shared_ptr<ModelAPI_Object>& owner() const
46   {
47     return myObject;
48   }
49
50   /// Returns true if attribute was  initialized by some value
51   MODELAPI_EXPORT bool isInitialized()
52   {
53     return myIsInitialized;
54   }
55
56   /// Makes attribute initialized
57   MODELAPI_EXPORT void setInitialized()
58   {
59     myIsInitialized = true;
60   }
61
62   /// Set this attribute is argument for result (change of this attribute requires update of result).
63   /// By default it is true.
64   MODELAPI_EXPORT void setIsArgument(const bool theFlag)
65   {
66     myIsArgument = theFlag;
67   }
68
69   /// Returns true if attribute causes the result change
70   MODELAPI_EXPORT bool isArgument()
71   {
72     return myIsArgument;
73   }
74
75   /// Immutable argument can not be changed programaticaly (e.g. by constraint)
76   /// By default it is false.
77   /// Returns the previous state of the attribute's immutability.
78   MODELAPI_EXPORT bool setImmutable(const bool theFlag)
79   {
80     bool aResult = myIsImmutable;
81     myIsImmutable = theFlag;
82     return aResult;
83   }
84
85   /// Returns true if can not be changed programaticaly
86   MODELAPI_EXPORT bool isImmutable()
87   {
88     return myIsImmutable;
89   }
90
91  protected:
92   /// Objects are created for features automatically
93   ModelAPI_Attribute()
94   {
95     myIsInitialized = false;
96     myIsArgument = true;
97     myIsImmutable = false;
98   }
99
100 };
101
102 //! Pointer on attribute object
103 typedef std::shared_ptr<ModelAPI_Attribute> AttributePtr;
104
105 #endif