Salome HOME
Merge branch 'Pre_2.8.0_development'
[modules/shaper.git] / src / ModelAPI / ModelAPI_Attribute.h
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef ModelAPI_Attribute_H_
22 #define ModelAPI_Attribute_H_
23
24 #include "ModelAPI.h"
25 #include <string>
26 #include <memory>
27
28 class ModelAPI_Object;
29
30 /**\class ModelAPI_Attribute
31  * \ingroup DataModel
32  * \brief Generic attribute of the Object.
33  */
34 class ModelAPI_Attribute
35 {
36   ///< needed here to emit signal that feature changed on change of the attribute
37   std::shared_ptr<ModelAPI_Object> myObject;
38   std::string myID; ///< identifier of this attribute in Data class
39  protected:
40   // accessible from the attributes
41   bool myIsInitialized; ///< is some value assigned to this attribute
42   bool mySetInitializedBlocked; ///< is initialized blocked
43   bool myIsArgument;    ///< is this attribute used as an argument for execution
44   bool myIsImmutable;   ///< is this attribute can be changed programmatically (e.g. by constraint)
45
46  public:
47
48   /// Returns the type of this class of attributes, not static method
49   MODELAPI_EXPORT virtual std::string attributeType() = 0;
50
51   /// To virtually destroy the fields of successors
52   MODELAPI_EXPORT virtual ~ModelAPI_Attribute();
53
54   /// Sets the owner of this attribute
55   MODELAPI_EXPORT virtual void setObject(const std::shared_ptr<ModelAPI_Object>& theObject);
56
57   /// Returns the owner of this attribute
58   MODELAPI_EXPORT const std::shared_ptr<ModelAPI_Object>& owner() const;
59
60   /// Returns true if attribute was  initialized by some value
61   MODELAPI_EXPORT virtual bool isInitialized();
62
63   /// Makes attribute initialized
64   MODELAPI_EXPORT void setInitialized();
65
66   /// Blocks sending "attribute updated" if theBlock is true
67   /// \param theBlock a block value
68   /// \return the previous block value
69   MODELAPI_EXPORT bool blockSetInitialized(const bool theBlock);
70
71   /// Set this attribute is argument for result
72   /// (change of this attribute requires update of result).
73   /// By default it is true.
74   MODELAPI_EXPORT void setIsArgument(const bool theFlag);
75
76   /// Returns true if attribute causes the result change
77   MODELAPI_EXPORT bool isArgument();
78
79   /// Immutable argument can not be changed programmatically (e.g. by constraint)
80   /// By default it is false.
81   /// Returns the previous state of the attribute's immutability.
82   MODELAPI_EXPORT bool setImmutable(const bool theFlag);
83
84   /// Returns true if can not be changed programmatically
85   MODELAPI_EXPORT bool isImmutable();
86
87   /// ID of the attribute in Data
88   MODELAPI_EXPORT const std::string& id() const;
89
90   /// Resets attribute to deafult state.
91   MODELAPI_EXPORT virtual void reset();
92
93  protected:
94   /// Objects are created for features automatically
95   MODELAPI_EXPORT ModelAPI_Attribute();
96
97   /// Sets the ID of the attribute in Data (called from Data)
98   MODELAPI_EXPORT virtual void setID(const std::string theID);
99
100   /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
101   MODELAPI_EXPORT virtual void reinit();
102
103   friend class Model_Data;
104   friend class Model_Objects;
105 };
106
107 //! Pointer on attribute object
108 typedef std::shared_ptr<ModelAPI_Attribute> AttributePtr;
109
110 #endif