SHAPER  9.15.0
ModelAPI_Document.h
1 // Copyright (C) 2014-2025 CEA, EDF
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 email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef ModelAPI_Document_H_
21 #define ModelAPI_Document_H_
22 
23 #include "ModelAPI.h"
24 #include "ModelAPI_Entity.h"
25 
26 #include <string>
27 #include <memory>
28 #include <vector>
29 #include <list>
30 #include <set>
31 #include <map>
32 
33 class ModelAPI_Feature;
34 class ModelAPI_Folder;
35 class ModelAPI_Object;
36 class ModelAPI_Result;
43 class ModelAPI_Data;
44 class GeomAPI_Shape;
45 
53 {
54 public:
58  virtual const std::string& kind() const = 0;
59 
63  virtual void close(const bool theForever = false) = 0;
64 
68  virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID,
69  const bool theMakeCurrent = true) = 0;
70 
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 
81  virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature) = 0;
82 
84  virtual void moveFeature(std::shared_ptr<ModelAPI_Feature> theMoved,
85  std::shared_ptr<ModelAPI_Feature> theAfterThis,
86  const bool theSplit = false) = 0;
87 
89  virtual const int id() const = 0;
90 
95  virtual std::shared_ptr<ModelAPI_Object> object(const std::string& theGroupID,
96  const int theIndex,
97  const bool theAllowFolder = false) = 0;
98 
103  virtual std::shared_ptr<ModelAPI_Object> objectByName(const std::string& theGroupID,
104  const std::wstring& theName) = 0;
105 
110  virtual int index(std::shared_ptr<ModelAPI_Object> theObject,
111  const bool theAllowFolder = false) = 0;
112 
116  virtual int size(const std::string& theGroupID, const bool theAllowFolder = false) = 0;
117 
120  virtual std::shared_ptr<ModelAPI_Object> parent(
121  const std::shared_ptr<ModelAPI_Object> theChild) = 0;
122 
127  virtual std::shared_ptr<ModelAPI_Feature> currentFeature(const bool theVisible) = 0;
128 
134  virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent,
135  const bool theVisible) = 0;
137  virtual void setCurrentFeatureUp() = 0;
138 
140  virtual int numInternalFeatures() = 0;
142  virtual std::shared_ptr<ModelAPI_Feature> internalFeature(const int theIndex) = 0;
147  virtual void synchronizeTransactions() = 0;
148 
150  MODELAPI_EXPORT virtual ~ModelAPI_Document();
151 
153  virtual std::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
154  const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
156  virtual std::shared_ptr<ModelAPI_ResultBody> createBody(
157  const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
159  virtual std::shared_ptr<ModelAPI_ResultPart> createPart(
160  const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
162  virtual std::shared_ptr<ModelAPI_ResultPart> copyPart(
163  const std::shared_ptr<ModelAPI_ResultPart>& theOrigin,
164  const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
166  virtual std::shared_ptr<ModelAPI_ResultGroup> createGroup(
167  const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
169  virtual std::shared_ptr<ModelAPI_ResultField> createField(
170  const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
172  virtual std::shared_ptr<ModelAPI_ResultParameter> createParameter(
173  const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
174 
176  virtual std::shared_ptr<ModelAPI_Feature> feature(
177  const std::shared_ptr<ModelAPI_Result>& theResult) = 0;
178 
181  virtual std::list<std::shared_ptr<ModelAPI_Feature> > allFeatures() = 0;
182 
185  virtual std::list<std::shared_ptr<ModelAPI_Object> > allObjects() = 0;
186 
190  virtual std::shared_ptr<ModelAPI_Folder> addFolder(
191  std::shared_ptr<ModelAPI_Feature> theAddBefore = std::shared_ptr<ModelAPI_Feature>()) = 0;
193  virtual void removeFolder(std::shared_ptr<ModelAPI_Folder> theFolder) = 0;
197  virtual std::shared_ptr<ModelAPI_Folder> findFolderAbove(
198  const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures) = 0;
202  virtual std::shared_ptr<ModelAPI_Folder> findFolderBelow(
203  const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures) = 0;
209  virtual std::shared_ptr<ModelAPI_Folder> findContainingFolder(
210  const std::shared_ptr<ModelAPI_Feature>& theFeature,
211  int& theIndexInFolder) = 0;
215  virtual bool moveToFolder(const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
216  const std::shared_ptr<ModelAPI_Folder>& theFolder) = 0;
223  virtual bool removeFromFolder(
224  const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
225  const bool theBefore = true) = 0;
226 
228  virtual void setActive(const bool theFlag) = 0;
230  virtual bool isActive() const = 0;
231 
233  virtual bool isOpened() = 0;
234 
236  virtual std::shared_ptr<ModelAPI_Feature> producedByFeature(
237  std::shared_ptr<ModelAPI_Result> theResult,
238  const std::shared_ptr<GeomAPI_Shape>& theShape) = 0;
239 
241  virtual bool isLater(std::shared_ptr<ModelAPI_Feature> theLater,
242  std::shared_ptr<ModelAPI_Feature> theCurrent) const = 0;
243 
245  MODELAPI_EXPORT virtual void updateHistory(const std::string theGroup) = 0;
246 
249  MODELAPI_EXPORT virtual void storeNodesState(const std::list<bool>& theStates) = 0;
250 
253  MODELAPI_EXPORT virtual void restoreNodesState(std::list<bool>& theStates) const = 0;
254 
256  MODELAPI_EXPORT virtual void eraseAllFeatures() = 0;
257 
261  MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Feature> nextFeature(
262  std::shared_ptr<ModelAPI_Feature> theCurrent, const bool theReverse = false) const = 0;
263 
271  MODELAPI_EXPORT virtual bool importPart(const char* theFileName,
272  std::list<std::shared_ptr<ModelAPI_Feature> >& theImported,
273  bool theCheckOnly = false) = 0;
274 
278  MODELAPI_EXPORT virtual bool save(const char* theFilename,
279  const std::list<std::shared_ptr<ModelAPI_Feature> >& theExportFeatures) const = 0;
280 
281 protected:
283  MODELAPI_EXPORT ModelAPI_Document();
284 
286  MODELAPI_EXPORT virtual void updateHistory(const std::shared_ptr<ModelAPI_Object> theObject) = 0;
287 
288  friend class ModelAPI_Object; // to add or remove from the history
289  friend class ModelAPI_Result; // to add or remove from the history
290 };
291 
293 typedef std::shared_ptr<ModelAPI_Document> DocumentPtr;
294 
295 #endif
Interface to the topological shape object.
Definition: GeomAPI_Shape.h:43
General object of the application that allows to get/set attributes from the document and compute res...
Definition: ModelAPI_Data.h:73
Document for internal data structure of any object storage.
Definition: ModelAPI_Document.h:53
virtual void setActive(const bool theFlag)=0
Informs the document that it becomes active and some actions must be performed.
virtual std::list< std::shared_ptr< ModelAPI_Object > > allObjects()=0
Returns all objects of the document including the hidden features which are not in history.
virtual void removeFolder(std::shared_ptr< ModelAPI_Folder > theFolder)=0
Removes the folder from the document (all features in the folder will be kept).
virtual std::shared_ptr< ModelAPI_Folder > findFolderBelow(const std::list< std::shared_ptr< ModelAPI_Feature > > &theFeatures)=0
Search a folder below the list of features applicable to store them (it means the list of features st...
virtual void close(const bool theForever=false)=0
Removes document data.
virtual std::shared_ptr< ModelAPI_Folder > findFolderAbove(const std::list< std::shared_ptr< ModelAPI_Feature > > &theFeatures)=0
Search a folder above the list of features applicable to store them (it means the list of features st...
virtual ~ModelAPI_Document()
To virtually destroy the fields of successors.
Definition: ModelAPI_Document.cpp:22
virtual std::shared_ptr< ModelAPI_Feature > internalFeature(const int theIndex)=0
Returns the feature by zero-based index: features in the history or not.
virtual const int id() const =0
! Returns the id of the document
virtual void updateHistory(const std::string theGroup)=0
Internally makes document know that feature was removed or added in history after creation.
virtual bool isOpened()=0
Returns true if document is opened and valid.
virtual void eraseAllFeatures()=0
Just removes all features without touching the document data (to be able undo)
virtual std::shared_ptr< ModelAPI_ResultField > createField(const std::shared_ptr< ModelAPI_Data > &theFeatureData, const int theIndex=0)=0
Creates a field result.
virtual void moveFeature(std::shared_ptr< ModelAPI_Feature > theMoved, std::shared_ptr< ModelAPI_Feature > theAfterThis, const bool theSplit=false)=0
Moves the feature to make it after the given one in the history.
virtual bool removeFromFolder(const std::list< std::shared_ptr< ModelAPI_Feature > > &theFeatures, const bool theBefore=true)=0
Remove features from the folder.
virtual std::list< std::shared_ptr< ModelAPI_Feature > > allFeatures()=0
Returns all features of the document including the hidden features which are not in history.
virtual std::shared_ptr< ModelAPI_Feature > producedByFeature(std::shared_ptr< ModelAPI_Result > theResult, const std::shared_ptr< GeomAPI_Shape > &theShape)=0
Returns the feature that produced the given face of the given result.
virtual void synchronizeTransactions()=0
Performs synchronization of transactions with the module document: If some document is not active (by...
virtual std::shared_ptr< ModelAPI_ResultPart > copyPart(const std::shared_ptr< ModelAPI_ResultPart > &theOrigin, const std::shared_ptr< ModelAPI_Data > &theFeatureData, const int theIndex=0)=0
Copies a part result, keeping the reference to the origin.
virtual bool save(const char *theFilename, const std::list< std::shared_ptr< ModelAPI_Feature > > &theExportFeatures) const =0
Export the list of features to the file.
virtual std::shared_ptr< ModelAPI_Folder > addFolder(std::shared_ptr< ModelAPI_Feature > theAddBefore=std::shared_ptr< ModelAPI_Feature >())=0
Creates a folder (group of the features in the object browser)
virtual std::shared_ptr< ModelAPI_ResultBody > createBody(const std::shared_ptr< ModelAPI_Data > &theFeatureData, const int theIndex=0)=0
Creates a body result.
virtual std::shared_ptr< ModelAPI_Feature > addFeature(std::string theID, const bool theMakeCurrent=true)=0
Adds to the document the new feature of the given feature id.
ModelAPI_Document()
Only for SWIG wrapping it is here.
Definition: ModelAPI_Document.cpp:27
virtual std::shared_ptr< ModelAPI_ResultConstruction > createConstruction(const std::shared_ptr< ModelAPI_Data > &theFeatureData, const int theIndex=0)=0
Creates a construction result.
virtual std::shared_ptr< ModelAPI_Feature > nextFeature(std::shared_ptr< ModelAPI_Feature > theCurrent, const bool theReverse=false) const =0
Returns the next (from the history point of view) feature, any: invisible or disabled.
virtual int size(const std::string &theGroupID, const bool theAllowFolder=false)=0
Returns the number of objects in the group of objects.
virtual std::shared_ptr< ModelAPI_ResultGroup > createGroup(const std::shared_ptr< ModelAPI_Data > &theFeatureData, const int theIndex=0)=0
Creates a group result.
virtual std::shared_ptr< ModelAPI_ResultPart > createPart(const std::shared_ptr< ModelAPI_Data > &theFeatureData, const int theIndex=0)=0
Creates a part result.
virtual void storeNodesState(const std::list< bool > &theStates)=0
Stores in the document boolean flags: states of the nodes in the object browser.
virtual std::shared_ptr< ModelAPI_Object > object(const std::string &theGroupID, const int theIndex, const bool theAllowFolder=false)=0
Returns the object in the group by the index (started from zero)
virtual const std::string & kind() const =0
Returns the kind of the document: "PartSet", "Part", or something else.
virtual std::shared_ptr< ModelAPI_ResultParameter > createParameter(const std::shared_ptr< ModelAPI_Data > &theFeatureData, const int theIndex=0)=0
Creates a parameter result.
virtual void restoreNodesState(std::list< bool > &theStates) const =0
Returns the stored nodes states.
virtual bool isActive() const =0
Returns true if this document is currently active.
virtual void refsToFeature(std::shared_ptr< ModelAPI_Feature > theFeature, std::set< std::shared_ptr< ModelAPI_Feature > > &theRefs, const bool isSendError=true)=0
Return a list of features, which refers to the feature.
virtual bool moveToFolder(const std::list< std::shared_ptr< ModelAPI_Feature > > &theFeatures, const std::shared_ptr< ModelAPI_Folder > &theFolder)=0
Add a list of features to the folder.
virtual bool isLater(std::shared_ptr< ModelAPI_Feature > theLater, std::shared_ptr< ModelAPI_Feature > theCurrent) const =0
Returns true if theLater is in history of features creation later than theCurrent.
virtual void updateHistory(const std::shared_ptr< ModelAPI_Object > theObject)=0
Internally makes document know that feature was removed or added in history after creation.
virtual std::shared_ptr< ModelAPI_Feature > feature(const std::shared_ptr< ModelAPI_Result > &theResult)=0
Returns a feature by result (owner of result)
virtual std::shared_ptr< ModelAPI_Feature > currentFeature(const bool theVisible)=0
Returns the feature that is currently edited in this document, normally this is the latest created fe...
virtual int numInternalFeatures()=0
Returns the number of all features: in the history or not.
virtual void removeFeature(std::shared_ptr< ModelAPI_Feature > theFeature)=0
Removes the feature from the document.
virtual std::shared_ptr< ModelAPI_Object > objectByName(const std::string &theGroupID, const std::wstring &theName)=0
Returns the first found object in the group by the object name.
virtual int index(std::shared_ptr< ModelAPI_Object > theObject, const bool theAllowFolder=false)=0
Returns the object index in the group.
virtual void setCurrentFeature(std::shared_ptr< ModelAPI_Feature > theCurrent, const bool theVisible)=0
Sets the current feature: all features below will be disabled, new features will be appended after th...
virtual std::shared_ptr< ModelAPI_Object > parent(const std::shared_ptr< ModelAPI_Object > theChild)=0
Returns the parent object of this child.
virtual bool importPart(const char *theFileName, std::list< std::shared_ptr< ModelAPI_Feature > > &theImported, bool theCheckOnly=false)=0
Loads the OCAF document from the file into the current document.
virtual void setCurrentFeatureUp()=0
Makes the current feature one feature upper.
virtual std::shared_ptr< ModelAPI_Folder > findContainingFolder(const std::shared_ptr< ModelAPI_Feature > &theFeature, int &theIndexInFolder)=0
Search a folder containing the given feature.
Represents a common parent class for Objects and documents.
Definition: ModelAPI_Entity.h:32
Feature function that represents the particular functionality of this operation.
Definition: ModelAPI_Feature.h:41
Folder feature (groups the features).
Definition: ModelAPI_Folder.h:31
Represents any object in the data model and in the object browser.
Definition: ModelAPI_Object.h:45
The body (shape) result of a feature.
Definition: ModelAPI_ResultBody.h:43
The construction element result of a feature.
Definition: ModelAPI_ResultConstruction.h:37
The fields result.
Definition: ModelAPI_ResultField.h:35
The groups result.
Definition: ModelAPI_ResultGroup.h:35
The construction element result of a feature.
Definition: ModelAPI_ResultParameter.h:34
The Part document, result of a creation of new part feature.
Definition: ModelAPI_ResultPart.h:37
The result of a feature.
Definition: ModelAPI_Result.h:37