1 // File: ModelAPI_Document.cxx
2 // Created: 28 Feb 2014
3 // Author: Mikhail PONIKAROV
5 #ifndef ModelAPI_Document_HeaderFile
6 #define ModelAPI_Document_HeaderFile
10 #include <boost/shared_ptr.hpp>
13 class ModelAPI_Feature;
14 class ModelAPI_Object;
15 class ModelAPI_Result;
16 class ModelAPI_ResultConstruction;
17 class ModelAPI_ResultBody;
18 class ModelAPI_ResultPart;
21 /**\class Model_Document
23 * \brief Document for internal data structure of any object storage.
24 * Document contains all data that must be stored/retrived in the file.
25 * Also it provides acces to this data: open/save, transactions management etc.
27 class ModelAPI_Document
30 //! Loads the OCAF document from the file.
31 //! \param theFileName full name of the file to load
32 //! \param theStudyID identifier of the SALOME study to associate with loaded file
33 //! \returns true if file was loaded successfully
34 virtual bool load(const char* theFileName) = 0;
36 //! Saves the OCAF document to the file.
37 //! \param theFileName full name of the file to store
38 //! \returns true if file was stored successfully
39 virtual bool save(const char* theFileName) = 0;
41 //! Removes document data
42 virtual void close() = 0;
44 //! Starts a new operation (opens a tansaction)
45 virtual void startOperation() = 0;
46 //! Finishes the previously started operation (closes the transaction)
47 virtual void finishOperation() = 0;
48 //! Aborts the operation
49 virtual void abortOperation() = 0;
50 //! Returns true if operation has been started, but not yet finished or aborted
51 virtual bool isOperation() = 0;
52 //! Returns true if document was modified (since creation/opening)
53 virtual bool isModified() = 0;
55 //! Returns True if there are available Undos
56 virtual bool canUndo() = 0;
57 //! Undoes last operation
58 virtual void undo() = 0;
59 //! Returns True if there are available Redos
60 virtual bool canRedo() = 0;
61 //! Redoes last operation
62 virtual void redo() = 0;
64 //! Adds to the document the new feature of the given feature id
65 //! \param creates feature and puts it in the document (if it is not action)
66 virtual boost::shared_ptr<ModelAPI_Feature> addFeature(std::string theID) = 0;
68 //! Removes the feature from the document
69 virtual void removeFeature(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
71 ///! Adds a new sub-document by the identifier, or returns existing one if it is already exist
72 virtual boost::shared_ptr<ModelAPI_Document>
73 subDocument(std::string theDocID) = 0;
75 ///! Returns the id of the document
76 virtual const std::string& id() const = 0;
78 //! Returns the object in the group by the index (started from zero)
79 //! \param theGroupID group that contains an object
80 //! \param theIndex zero-based index of feature in the group
81 virtual boost::shared_ptr<ModelAPI_Object>
82 object(const std::string& theGroupID, const int theIndex) = 0;
84 //! Returns the number of objects in the group of objects
85 virtual int size(const std::string& theGroupID) = 0;
87 /// To virtually destroy the fields of successors
88 virtual ~ModelAPI_Document() {}
90 /// Creates a construction cresults
91 virtual boost::shared_ptr<ModelAPI_ResultConstruction> createConstruction() = 0;
92 /// Creates a body results
93 virtual boost::shared_ptr<ModelAPI_ResultBody> createBody() = 0;
94 /// Creates a part results
95 virtual boost::shared_ptr<ModelAPI_ResultPart> createPart() = 0;
97 //! Allows to store the result in the data tree of the document (attaches 'data' of result to tree)
98 virtual void storeResult(boost::shared_ptr<ModelAPI_Data> theFeatureData,
99 boost::shared_ptr<ModelAPI_Result> theResult, const int theResultIndex = 0) = 0;
101 //! Returns a feature by result (owner of result)
102 virtual boost::shared_ptr<ModelAPI_Feature> feature(
103 const boost::shared_ptr<ModelAPI_Result>& theResult) = 0;
106 /// Only for SWIG wrapping it is here
107 MODELAPI_EXPORT ModelAPI_Document()
112 //! Pointer on document object
113 typedef boost::shared_ptr<ModelAPI_Document> DocumentPtr;