Salome HOME
320dffb4035b640acc63fa219fa7731a2b34cd10
[modules/shaper.git] / src / ModelAPI / ModelAPI_Data.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_Data.hxx
4 // Created:     21 Mar 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef ModelAPI_Data_H_
8 #define ModelAPI_Data_H_
9
10 #ifdef _WINDOWS // to avoid too long decorated name warning 
11 #pragma warning( disable : 4503 )
12 #endif
13
14 #include "ModelAPI.h"
15 #include <string>
16 #include <list>
17 #include <set>
18 #include <memory>
19
20 class ModelAPI_Attribute;
21 class ModelAPI_AttributeDocRef;
22 class ModelAPI_AttributeInteger;
23 class ModelAPI_AttributeDouble;
24 class ModelAPI_AttributeReference;
25 class ModelAPI_AttributeRefAttr;
26 class ModelAPI_AttributeRefList;
27 class ModelAPI_AttributeRefAttrList;
28 class ModelAPI_AttributeBoolean;
29 class ModelAPI_AttributeString;
30 class ModelAPI_Document;
31 class ModelAPI_Attribute;
32 class ModelAPI_Feature;
33 class ModelAPI_AttributeSelection;
34 class ModelAPI_AttributeSelectionList;
35 class ModelAPI_AttributeIntArray;
36 class ModelAPI_Object;
37 class GeomAPI_Shape;
38
39 /// Enumeration that contains the execution status of the Object
40 enum ModelAPI_ExecState {
41   ModelAPI_StateDone, ///< execution was performed and result is up to date
42   ModelAPI_StateMustBeUpdated, ///< execution must be performed to obtain the up to date result
43   ModelAPI_StateExecFailed, ///< execution was failed (results are deleted in this case)
44   ModelAPI_StateInvalidArgument, ///< execution was not performed (results are deleted in this case)
45   ModelAPI_StateNothing ///< internal state that actually means that nothing must be changed
46 };
47
48 /**\class ModelAPI_Data
49  * \ingroup DataModel
50  * \brief General object of the application that allows
51  * to get/set attributes from the document and compute result of an operation.
52  */
53
54 class MODELAPI_EXPORT ModelAPI_Data
55 {
56  public:
57
58   /// Returns the name of the feature visible by the user in the object browser
59   virtual std::string name() = 0;
60
61   /// Defines the name of the feature visible by the user in the object browser
62   virtual void setName(const std::string& theName) = 0;
63
64   /// Returns the attribute that references to another document
65   virtual std::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID) = 0;
66   /// Returns the attribute that contains real value with double precision
67   virtual std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID) = 0;
68   /// Returns the attribute that contains integer value
69   virtual std::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID) = 0;
70   /// Returns the attribute that contains reference to a feature
71   virtual std::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID) = 0;
72   /// Returns the attribute that contains selection to a shape
73   virtual std::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID) = 0;
74   /// Returns the attribute that contains selection to a shape
75   virtual std::shared_ptr<ModelAPI_AttributeSelectionList> 
76     selectionList(const std::string& theID) = 0;
77   /// Returns the attribute that contains reference to an attribute of a feature
78   virtual std::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID) = 0;
79   /// Returns the attribute that contains list of references to features
80   virtual std::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID) = 0;
81   /// Returns the attribute that contains list of references to features or reference to
82   /// an attribute of a feature
83   virtual std::shared_ptr<ModelAPI_AttributeRefAttrList> refattrlist(const std::string& theID) = 0;
84   /// Returns the attribute that contains boolean value
85   virtual std::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID) = 0;
86   /// Returns the attribute that contains boolean value
87   virtual std::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID) = 0;
88   /// Returns the attribute that contains integer values array
89   virtual std::shared_ptr<ModelAPI_AttributeIntArray> intArray(const std::string& theID) = 0;
90
91   /// Returns the generic attribute by identifier
92   /// \param theID identifier of the attribute
93   virtual std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID) = 0;
94   /// Returns all attributes of the feature of the given type
95   /// or all attributes if "theType" is empty
96   virtual std::list<std::shared_ptr<ModelAPI_Attribute> >
97   attributes(const std::string& theType) = 0;
98   /// Returns all attributes ids of the feature of the given type
99   /// or all attributes if "theType" is empty
100   virtual std::list<std::string> attributesIDs(const std::string& theType) = 0;
101   /// Identifier by the id (not fast, iteration by map)
102   /// \param theAttr attribute already created in this data
103   virtual const std::string& id(const std::shared_ptr<ModelAPI_Attribute>& theAttr) = 0;
104   /// Returns true if data belongs to same features
105   virtual bool isEqual(const std::shared_ptr<ModelAPI_Data>& theData) = 0;
106   /// Returns true if it is correctly connected to the data model
107   virtual bool isValid() = 0;
108
109   /// Initializes object by the attributes: must be called just after the object is created
110   /// for each attribute of the object
111   /// \param theID identifier of the attribute that can be referenced by this ID later
112   /// \param theAttrType type of the created attribute (received from the type method)
113   /// \returns the just created attribute
114   virtual std::shared_ptr<ModelAPI_Attribute>
115     addAttribute(const std::string& theID, const std::string theAttrType) = 0;
116
117   /// Useful method for "set" methods of the attributes: sends an UPDATE event and
118   /// makes attribute initialized
119   virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr) = 0;
120   /// Blocks sending "attribute updated" if theBlock is true
121   /// \param theID identifier of the attribute that can be referenced by this ID later
122   /// \param theAttrType type of the created attribute (received from the type method)
123   /// \returns the just created attribute
124   virtual void blockSendAttributeUpdated(
125     const bool theBlock, const bool theSendMessage = true) = 0;
126
127   /// Erases all the data from the data model
128   virtual void erase() = 0;
129
130   /// To virtually destroy the fields of successors
131   virtual ~ModelAPI_Data();
132
133   /// Stores the state of the object to execute it later accordingly
134   virtual void execState(const ModelAPI_ExecState theState) = 0;
135
136   /// Returns the state of the latest execution of the feature
137   virtual ModelAPI_ExecState execState() = 0;
138
139   /// Registers error during the execution, causes the ExecutionFailed state
140   virtual void setError(const std::string& theError, bool theSend = true) = 0;
141
142   /// Returns error, arose during the execution
143   virtual std::string error() const = 0;
144
145   /// Returns the identifier of feature-owner, unique in this document
146   virtual int featureId() const = 0;
147
148   /// returns all objects referenced to this
149   virtual const std::set<std::shared_ptr<ModelAPI_Attribute> >& refsToMe() = 0;
150
151   /// returns all references by attributes of this data
152   /// \param theRefs returned list of pairs: id of referenced attribute and list of referenced objects
153   virtual void referencesToObjects(
154     std::list<std::pair<std::string, std::list<std::shared_ptr<ModelAPI_Object> > > >& theRefs) =0;
155
156   /// Copies all attributes content into theTarget data
157   virtual void copyTo(std::shared_ptr<ModelAPI_Data> theTarget) = 0;
158
159   /// Returns the invalid data pointer (to avoid working with NULL shared ptrs in swig)
160   virtual std::shared_ptr<ModelAPI_Data> invalidPtr() = 0;
161
162   /// Identifier of the transaction when object (feature or result) was updated last time.
163   virtual int updateID() = 0;
164
165   /// Identifier of the transaction when object (feature or result) was updated last time.
166   /// This method is called by the updater.
167   virtual void setUpdateID(const int theID) = 0;
168
169   /// Returns the owner of htis data
170   virtual std::shared_ptr<ModelAPI_Object> owner() = 0;
171
172   /// Returns true if the object is deleted, but some data is still keept in memory
173   virtual bool isDeleted() = 0;
174
175   /// Sets true if the object is deleted, but some data is still keept in memory
176   virtual void setIsDeleted(const bool theFlag) = 0;
177
178  protected:
179   /// Objects are created for features automatically
180   ModelAPI_Data();
181
182   /// Returns true if "is in history" custom behaviors is defined for the feature
183   virtual bool isInHistory() = 0;
184
185   /// Defines the custom "is in history" behavior
186   virtual void setIsInHistory(const bool theFlag) = 0;
187
188   /// Returns true if object must be displayed in the viewer: flag is stored in the
189   /// data model, so on undo/redo, open/save or recreation of object by history-playing it keeps
190   /// the original state i nthe current transaction.
191   virtual bool isDisplayed() = 0;
192
193   /// Sets the displayed/hidden state of the object. If it is changed, sends the "redisplay"
194   /// signal.
195   virtual void setDisplayed(const bool theDisplay) = 0;
196
197   friend class ModelAPI_Object;
198 };
199
200 typedef std::shared_ptr<ModelAPI_Data> DataPtr;
201
202 #endif