1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef ModelAPI_Data_H_
22 #define ModelAPI_Data_H_
24 #ifdef _WINDOWS // to avoid too long decorated name warning
25 #pragma warning( disable : 4503 )
34 class ModelAPI_Attribute;
35 class ModelAPI_AttributeDocRef;
36 class ModelAPI_AttributeInteger;
37 class ModelAPI_AttributeDouble;
38 class ModelAPI_AttributeDoubleArray;
39 class ModelAPI_AttributeReference;
40 class ModelAPI_AttributeRefAttr;
41 class ModelAPI_AttributeRefList;
42 class ModelAPI_AttributeRefAttrList;
43 class ModelAPI_AttributeBoolean;
44 class ModelAPI_AttributeString;
45 class ModelAPI_AttributeStringArray;
46 class ModelAPI_Document;
47 class ModelAPI_Attribute;
48 class ModelAPI_Feature;
49 class ModelAPI_AttributeSelection;
50 class ModelAPI_AttributeSelectionList;
51 class ModelAPI_AttributeIntArray;
52 class ModelAPI_AttributeTables;
53 class ModelAPI_Object;
56 /// Enumeration that contains the execution status of the Object
57 enum ModelAPI_ExecState {
58 ModelAPI_StateDone, ///< execution was performed and result is up to date
59 ModelAPI_StateMustBeUpdated, ///< execution must be performed to obtain the up to date result
60 ModelAPI_StateExecFailed, ///< execution was failed (results are deleted in this case)
61 ModelAPI_StateInvalidArgument, ///< execution was not performed (results are deleted in this case)
62 ModelAPI_StateNothing ///< internal state that actually means that nothing must be changed
65 /**\class ModelAPI_Data
67 * \brief General object of the application that allows
68 * to get/set attributes from the document and compute result of an operation.
71 class MODELAPI_EXPORT ModelAPI_Data
75 /// Returns the name of the feature visible by the user in the object browser
76 virtual std::string name() = 0;
78 /// Defines the name of the feature visible by the user in the object browser
79 virtual void setName(const std::string& theName) = 0;
81 /// Returns the attribute that references to another document
82 virtual std::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID) = 0;
83 /// Returns the attribute that contains real value with double precision
84 virtual std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID) = 0;
85 /// Returns the attribute that contains double values array
86 virtual std::shared_ptr<ModelAPI_AttributeDoubleArray> realArray(const std::string& theID) = 0;
87 /// Returns the attribute that contains integer value
88 virtual std::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID) = 0;
89 /// Returns the attribute that contains reference to a feature
90 virtual std::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID) = 0;
91 /// Returns the attribute that contains selection to a shape
92 virtual std::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID) = 0;
93 /// Returns the attribute that contains selection to a shape
94 virtual std::shared_ptr<ModelAPI_AttributeSelectionList>
95 selectionList(const std::string& theID) = 0;
96 /// Returns the attribute that contains reference to an attribute of a feature
97 virtual std::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID) = 0;
98 /// Returns the attribute that contains list of references to features
99 virtual std::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID) = 0;
100 /// Returns the attribute that contains list of references to features or reference to
101 /// an attribute of a feature
102 virtual std::shared_ptr<ModelAPI_AttributeRefAttrList> refattrlist(const std::string& theID) = 0;
103 /// Returns the attribute that contains boolean value
104 virtual std::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID) = 0;
105 /// Returns the attribute that contains boolean value
106 virtual std::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID) = 0;
107 /// Returns the attribute that contains integer values array
108 virtual std::shared_ptr<ModelAPI_AttributeIntArray> intArray(const std::string& theID) = 0;
109 /// Returns the attribute that contains string values array
110 virtual std::shared_ptr<ModelAPI_AttributeStringArray> stringArray(const std::string& theID) = 0;
111 /// Returns the attribute that contains tables
112 virtual std::shared_ptr<ModelAPI_AttributeTables> tables(const std::string& theID) = 0;
114 /// Returns the generic attribute by identifier
115 /// \param theID identifier of the attribute
116 virtual std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID) = 0;
117 /// Returns all attributes of the feature of the given type
118 /// or all attributes if "theType" is empty
119 virtual std::list<std::shared_ptr<ModelAPI_Attribute> >
120 attributes(const std::string& theType) = 0;
121 /// Returns all attributes ids of the feature of the given type
122 /// or all attributes if "theType" is empty
123 virtual std::list<std::string> attributesIDs(const std::string& theType) = 0;
124 /// Identifier by the id (not fast, iteration by map)
125 /// \param theAttr attribute already created in this data
126 virtual const std::string& id(const std::shared_ptr<ModelAPI_Attribute>& theAttr) = 0;
127 /// Returns true if data belongs to same features
128 virtual bool isEqual(const std::shared_ptr<ModelAPI_Data>& theData) = 0;
129 /// Returns true if it is correctly connected to the data model
130 virtual bool isValid() = 0;
132 /// Initializes object by the attributes: must be called just after the object is created
133 /// for each attribute of the object
134 /// \param theID identifier of the attribute that can be referenced by this ID later
135 /// \param theAttrType type of the created attribute (received from the type method)
136 /// \returns the just created attribute
137 virtual std::shared_ptr<ModelAPI_Attribute>
138 addAttribute(const std::string& theID, const std::string theAttrType) = 0;
140 /// Useful method for "set" methods of the attributes: sends an UPDATE event and
141 /// makes attribute initialized
142 virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr) = 0;
143 /// Blocks sending "attribute updated" if theBlock is true
144 /// \param theID identifier of the attribute that can be referenced by this ID later
145 /// \param theAttrType type of the created attribute (received from the type method)
146 /// \returns the previous state of block
147 virtual bool blockSendAttributeUpdated(
148 const bool theBlock, const bool theSendMessage = true) = 0;
150 /// Erases all the data from the data model
151 virtual void erase() = 0;
153 /// To virtually destroy the fields of successors
154 virtual ~ModelAPI_Data();
156 /// Stores the state of the object to execute it later accordingly
157 virtual void execState(const ModelAPI_ExecState theState) = 0;
159 /// Returns the state of the latest execution of the feature
160 virtual ModelAPI_ExecState execState() = 0;
162 /// Registers error during the execution, causes the ExecutionFailed state
163 virtual void setError(const std::string& theError, bool theSend = true) = 0;
165 /// Returns error, arose during the execution
166 virtual std::string error() const = 0;
168 /// Returns the identifier of feature-owner, unique in this document
169 virtual int featureId() const = 0;
171 /// returns all objects referenced to this
172 virtual const std::set<std::shared_ptr<ModelAPI_Attribute> >& refsToMe() = 0;
174 /// returns all references by attributes of this data
175 /// \param theRefs returned list of pairs: id of referenced attribute and
176 /// list of referenced objects
177 virtual void referencesToObjects(
178 std::list<std::pair<std::string, std::list<std::shared_ptr<ModelAPI_Object> > > >& theRefs) =0;
180 /// Copies all attributes content into theTarget data
181 virtual void copyTo(std::shared_ptr<ModelAPI_Data> theTarget) = 0;
183 /// Returns the invalid data pointer (to avoid working with NULL shared ptrs in swig)
184 virtual std::shared_ptr<ModelAPI_Data> invalidPtr() = 0;
186 /// Identifier of the transaction when object (feature or result) was updated last time.
187 virtual int updateID() = 0;
189 /// Identifier of the transaction when object (feature or result) was updated last time.
190 /// This method is called by the updater.
191 virtual void setUpdateID(const int theID) = 0;
193 /// Returns the owner of htis data
194 virtual std::shared_ptr<ModelAPI_Object> owner() = 0;
196 /// Returns true if the object is deleted, but some data is still keept in memory
197 virtual bool isDeleted() = 0;
199 /// Sets true if the object is deleted, but some data is still keept in memory
200 virtual void setIsDeleted(const bool theFlag) = 0;
202 /// Returns \c true if theAttribute1 is going earlier than theAttribute2 in the data
203 virtual bool isPrecedingAttribute(const std::string& theAttribute1,
204 const std::string& theAttribute2) const = 0;
207 /// Objects are created for features automatically
210 /// Returns true if "is in history" custom behaviors is defined for the feature
211 virtual bool isInHistory() = 0;
213 /// Defines the custom "is in history" behavior
214 virtual void setIsInHistory(const bool theFlag) = 0;
216 /// Returns true if object must be displayed in the viewer: flag is stored in the
217 /// data model, so on undo/redo, open/save or recreation of object by history-playing it keeps
218 /// the original state i nthe current transaction.
219 virtual bool isDisplayed() = 0;
221 /// Sets the displayed/hidden state of the object. If it is changed, sends the "redisplay"
223 virtual void setDisplayed(const bool theDisplay) = 0;
225 friend class ModelAPI_Object;
228 typedef std::shared_ptr<ModelAPI_Data> DataPtr;