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