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