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