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