1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #ifndef ModelAPI_Document_H_
21 #define ModelAPI_Document_H_
24 #include "ModelAPI_Entity.h"
32 class ModelAPI_Feature;
33 class ModelAPI_Folder;
34 class ModelAPI_Object;
35 class ModelAPI_Result;
36 class ModelAPI_ResultConstruction;
37 class ModelAPI_ResultBody;
38 class ModelAPI_ResultPart;
39 class ModelAPI_ResultGroup;
40 class ModelAPI_ResultField;
41 class ModelAPI_ResultParameter;
45 /**\class ModelAPI_Document
47 * \brief Document for internal data structure of any object storage.
48 * Document contains all data that must be stored/retrieved in the file.
49 * Also it provides access to this data: open/save, transactions management etc.
51 class ModelAPI_Document: public ModelAPI_Entity
54 //! Returns the kind of the document: "PartSet", "Part", or something else.
55 //! This kind is used for feature buttons enable/disable depending on active document
56 //! (it uses workbench "document" identifier in XML configuration file for this)
57 virtual const std::string& kind() const = 0;
59 //! Removes document data
60 //! \param theForever if it is false, document is just hidden
61 //! (to keep possibility make it back on Undo/Redo)
62 virtual void close(const bool theForever = false) = 0;
64 //! Adds to the document the new feature of the given feature id
65 //! \param theID creates feature and puts it in the document (if it is not action)
66 //! \param theMakeCurrent to make current this new feature in this document
67 virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID,
68 const bool theMakeCurrent = true) = 0;
70 //! Return a list of features, which refers to the feature
71 //! \param theFeature a feature
72 //! \param theRefs a list of features
73 //! \param isSendError a flag whether the error message should be send
74 virtual void refsToFeature(std::shared_ptr<ModelAPI_Feature> theFeature,
75 std::set<std::shared_ptr<ModelAPI_Feature> >& theRefs,
76 const bool isSendError = true) = 0;
78 //! Removes the feature from the document
79 //! \param theFeature a feature to be removed
80 virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature) = 0;
82 //! Moves the feature to make it after the given one in the history.
83 virtual void moveFeature(std::shared_ptr<ModelAPI_Feature> theMoved,
84 std::shared_ptr<ModelAPI_Feature> theAfterThis) = 0;
86 ///! Returns the id of the document
87 virtual const int id() const = 0;
89 //! Returns the object in the group by the index (started from zero)
90 //! \param theGroupID group that contains an object
91 //! \param theIndex zero-based index of feature in the group
92 //! \param theAllowFolder take into account grouping feature by folders
93 virtual std::shared_ptr<ModelAPI_Object> object(const std::string& theGroupID,
95 const bool theAllowFolder = false) = 0;
97 //! Returns the first found object in the group by the object name
98 //! \param theGroupID group that contains an object
99 //! \param theName name of the object to search
100 //! \returns null if such object is not found
101 virtual std::shared_ptr<ModelAPI_Object> objectByName(const std::string& theGroupID,
102 const std::string& theName) = 0;
104 //! Returns the object index in the group. Object must be visible. Otherwise returns -1.
105 //! \param theObject object of this document
106 //! \param theAllowFolder take into account grouping feature by folders
107 //! \returns index started from zero, or -1 if object is invisible or belongs to another document
108 virtual const int index(std::shared_ptr<ModelAPI_Object> theObject,
109 const bool theAllowFolder = false) = 0;
111 //! Returns the number of objects in the group of objects
112 //! \param theGroupID group of objects
113 //! \param theAllowFolder take into account grouping feature by folders
114 virtual int size(const std::string& theGroupID, const bool theAllowFolder = false) = 0;
116 //! Returns the parent object of this child. This may be result or feature, parent of a
117 //! top result. Fast method, that uses internal data structure specifics.
118 virtual std::shared_ptr<ModelAPI_Object> parent(
119 const std::shared_ptr<ModelAPI_Object> theChild) = 0;
121 //! Returns the feature that is currently edited in this document, normally
122 //! this is the latest created feature
123 //! \param theVisible use visible features only: flag is true for Object Browser functionality
124 //! \returns null if next created feature must be the first
125 virtual std::shared_ptr<ModelAPI_Feature> currentFeature(const bool theVisible) = 0;
127 //! Sets the current feature: all features below will be disabled, new features
128 //! will be appended after this one. This method does not flushes the events appeared:
129 //! it will be done by the finishOperation, or direct flushes
130 //! \param theCurrent the selected feature as current: blow it everything become disabled
131 //! \param theVisible use visible features only: flag is true for Object Browser functionality
132 virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent,
133 const bool theVisible) = 0;
134 //! Makes the current feature one feature upper
135 virtual void setCurrentFeatureUp() = 0;
137 //! Returns the number of all features: in the history or not
138 virtual int numInternalFeatures() = 0;
139 //! Returns the feature by zero-based index: features in the history or not
140 virtual std::shared_ptr<ModelAPI_Feature> internalFeature(const int theIndex) = 0;
141 //! Performs synchronization of transactions with the module document:
142 //! If some document is not active (by undo of activation) but in memory,
143 //! on activation the transactions must be synchronized because all redo-s performed
144 //! without this participation
145 virtual void synchronizeTransactions() = 0;
147 //! To virtually destroy the fields of successors
148 MODELAPI_EXPORT virtual ~ModelAPI_Document();
150 //! Creates a construction result
151 virtual std::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
152 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
153 //! Creates a body result
154 virtual std::shared_ptr<ModelAPI_ResultBody> createBody(
155 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
156 //! Creates a part result
157 virtual std::shared_ptr<ModelAPI_ResultPart> createPart(
158 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
159 //! Copies a part result, keeping the reference to the origin
160 virtual std::shared_ptr<ModelAPI_ResultPart> copyPart(
161 const std::shared_ptr<ModelAPI_ResultPart>& theOrigin,
162 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
163 //! Creates a group result
164 virtual std::shared_ptr<ModelAPI_ResultGroup> createGroup(
165 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
166 //! Creates a field result
167 virtual std::shared_ptr<ModelAPI_ResultField> createField(
168 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
169 //! Creates a parameter result
170 virtual std::shared_ptr<ModelAPI_ResultParameter> createParameter(
171 const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
173 //! Returns a feature by result (owner of result)
174 virtual std::shared_ptr<ModelAPI_Feature> feature(
175 const std::shared_ptr<ModelAPI_Result>& theResult) = 0;
177 //! Returns all features of the document including the hidden features which are not in
178 //! history. Not very fast method, for calling once, not in big cycles.
179 virtual std::list<std::shared_ptr<ModelAPI_Feature> > allFeatures() = 0;
181 //! Returns all objects of the document including the hidden features which are not in
182 //! history. Not very fast method, for calling once, not in big cycles.
183 virtual std::list<std::shared_ptr<ModelAPI_Object> > allObjects() = 0;
185 //! Creates a folder (group of the features in the object browser)
186 //! \param theAddBefore a feature, the folder is added before
187 //! (if empty, the folder is added after the last feature)
188 virtual std::shared_ptr<ModelAPI_Folder> addFolder(
189 std::shared_ptr<ModelAPI_Feature> theAddBefore = std::shared_ptr<ModelAPI_Feature>()) = 0;
190 //! Removes the folder from the document (all features in the folder will be kept).
191 virtual void removeFolder(std::shared_ptr<ModelAPI_Folder> theFolder) = 0;
192 //! Search a folder above the list of features applicable to store them
193 //! (it means the list of features stored in the folder should be consequential)
194 //! \return Empty pointer if there is no applicable folder
195 virtual std::shared_ptr<ModelAPI_Folder> findFolderAbove(
196 const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures) = 0;
197 //! Search a folder below the list of features applicable to store them
198 //! (it means the list of features stored in the folder should be consequential)
199 //! \return Empty pointer if there is no applicable folder
200 virtual std::shared_ptr<ModelAPI_Folder> findFolderBelow(
201 const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures) = 0;
202 //! Search a folder containing the given feature.
203 //! Additionally calculates a zero-based index of the feature in this folder.
204 //! \param theFeature feature to search
205 //! \param theIndexInFolder zero-based index in the folder or -1 if the feature is top-level.
206 //! \return the folder containing the feature or empty pointer if the feature is top-level.
207 virtual std::shared_ptr<ModelAPI_Folder> findContainingFolder(
208 const std::shared_ptr<ModelAPI_Feature>& theFeature,
209 int& theIndexInFolder) = 0;
210 //! Add a list of features to the folder. The correctness of the adding is not performed
211 //! (such checks have been done in corresponding find.. method).
212 //! \return \c true if the movement is successful
213 virtual bool moveToFolder(const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
214 const std::shared_ptr<ModelAPI_Folder>& theFolder) = 0;
215 //! Remove features from the folder
216 //! \param theFeatures list of features to be removed
217 //! \param theBefore extract features before the folder (this parameter is applicable only
218 //! when all features in the folder are taking out,
219 //! in other cases the direction is taken automatically)
220 //! \return \c true if the features have been moved out
221 virtual bool removeFromFolder(
222 const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
223 const bool theBefore = true) = 0;
225 //! Informs the document that it becomes active and some actions must be performed
226 virtual void setActive(const bool theFlag) = 0;
227 //! Returns true if this document is currently active
228 virtual bool isActive() const = 0;
230 /// Returns true if document is opened and valid
231 virtual bool isOpened() = 0;
233 /// Returns the feature that produced the given face of the given result.
234 virtual std::shared_ptr<ModelAPI_Feature> producedByFeature(
235 std::shared_ptr<ModelAPI_Result> theResult,
236 const std::shared_ptr<GeomAPI_Shape>& theShape) = 0;
238 /// Returns true if theLater is in history of features creation later than theCurrent
239 virtual bool isLater(std::shared_ptr<ModelAPI_Feature> theLater,
240 std::shared_ptr<ModelAPI_Feature> theCurrent) const = 0;
242 //! Internally makes document know that feature was removed or added in history after creation
243 MODELAPI_EXPORT virtual void updateHistory(const std::string theGroup) = 0;
245 /// Stores in the document boolean flags: states of the nodes in the object browser.
246 /// Normally is called outside of the transaction, just before "save".
247 MODELAPI_EXPORT virtual void storeNodesState(const std::list<bool>& theStates) = 0;
249 /// Returns the stored nodes states. Normally it is calls just after "open".
250 /// Appends the values to theStates list.
251 MODELAPI_EXPORT virtual void restoreNodesState(std::list<bool>& theStates) const = 0;
253 /// Just removes all features without touching the document data (to be able undo)
254 MODELAPI_EXPORT virtual void eraseAllFeatures() = 0;
256 /// Returns the next (from the history point of view) feature, any: invisible or disabled
257 /// \param theCurrent previous to the resulting feature
258 /// \param theReverse if it is true, iterates in reversed order (next becomes previous)
259 MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Feature> nextFeature(
260 std::shared_ptr<ModelAPI_Feature> theCurrent, const bool theReverse = false) const = 0;
263 //! Only for SWIG wrapping it is here
264 MODELAPI_EXPORT ModelAPI_Document();
266 //! Internally makes document know that feature was removed or added in history after creation
267 MODELAPI_EXPORT virtual void updateHistory(const std::shared_ptr<ModelAPI_Object> theObject) = 0;
269 friend class ModelAPI_Object; // to add or remove from the history
270 friend class ModelAPI_Result; // to add or remove from the history
273 //! Pointer on document object
274 typedef std::shared_ptr<ModelAPI_Document> DocumentPtr;