1 #ifndef HYDROData_Document_HeaderFile
2 #define HYDROData_Document_HeaderFile
5 #include <HYDROData_Object.h>
7 #include <TDocStd_Document.hxx>
10 * Errors that could appear on document open/save actions.
11 * If there is no error, it is "OK".
14 DocError_OK = 0, ///< success
15 DocError_ResourcesProblem, ///< resources files are invalid or not found
16 DocError_CanNotOpen, ///< can not open file for reading or writing
17 DocError_InvalidVersion, ///< version of document is different than expected
18 DocError_InvalidFormat, ///< format of the document is bad
19 DocError_UnknownProblem ///< problem has unknown nature
22 DEFINE_STANDARD_HANDLE(HYDROData_Document, MMgt_TShared)
24 /**\class HYDROData_Document
26 * \brief Document for internal data structure of any object storage. Corresponds to the SALOME study.
28 * Document contains all data of the Study specific to this module.
29 * Also it provides acces to this data: open/save, transactions management etc.
30 * to provide access to all stored data.
33 class HYDROData_Document : public MMgt_TShared
37 DEFINE_STANDARD_RTTI(HYDROData_Document);
39 //! Returns the existing document or creates new if it is not exist
40 HYDRODATA_EXPORT static Handle(HYDROData_Document) Document(const int theStudyID);
42 //! Returns true if data model contains document for this study
43 HYDRODATA_EXPORT static bool HasDocument(const int theStudyID);
45 //! Loads the OCAF document from the file.
46 //! \param theFileName full name of the file to load
47 //! \param theStudyID identifier of the SALOME study to associate with loaded file
48 //! \returns error status (OK in case of success)
49 HYDRODATA_EXPORT static Data_DocError Load(const char* theFileName, const int theStudyID);
51 //! Saves the OCAF document to the file.
52 //! \param theFileName full name of the file to store
53 //! \returns error status (OK in case of success)
54 HYDRODATA_EXPORT Data_DocError Save(const char* theFileName);
56 //! Removes document data
57 HYDRODATA_EXPORT void Close();
59 //! Starts a new operation (opens a tansaction)
60 HYDRODATA_EXPORT void StartOperation();
61 //! Finishes the previously started operation (closes the transaction)
62 HYDRODATA_EXPORT void CommitOperation();
63 //! Aborts the operation
64 HYDRODATA_EXPORT void AbortOperation();
65 //! Returns true if operation has been started, but not yet finished or aborted
66 HYDRODATA_EXPORT bool IsOperation();
67 //! Returns true if document was modified (since creation/opening)
68 HYDRODATA_EXPORT bool IsModified();
70 //! Returns True if there are available Undos
71 HYDRODATA_EXPORT bool CanUndo();
72 //! Undoes last operation
73 HYDRODATA_EXPORT void Undo();
74 //! Returns True if there are available Redos
75 HYDRODATA_EXPORT bool CanRedo();
76 //! Redoes last operation
77 HYDRODATA_EXPORT void Redo();
79 //! Creates and locates in the document a new object
80 //! \param theKind kind of the created object, can not be UNKNOWN
81 //! \returns the created object
82 HYDRODATA_EXPORT Handle_HYDROData_Object CreateObject(const ObjectKind theKind);
86 friend class HYDROData_Iterator;
87 friend class test_HYDROData_Document;
89 //! Creates new document: private because "Document" method must be used instead of direct creation.
91 //! Creates new document by existing OCAF structure
92 HYDROData_Document(const Handle(TDocStd_Document)& theDoc);
93 //! Deletes all high-level data, managed this document
94 ~HYDROData_Document();
96 //! Returns the new identifier of the new object (may be used for correct ordering of objects)
97 HYDRODATA_EXPORT int NewID();
99 //! Returns the label where the objects are located (used by Iterator)
100 TDF_Label LabelOfObjects();
103 Handle(TDocStd_Document) myDoc; ///< OCAF document instance corresponding for keeping all persistent data
104 int myTransactionsAfterSave; ///< number of transactions after the last "save" call, used for "IsModified" method