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