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