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 const TCollection_ExtendedString& theName = TCollection_ExtendedString());
64 //! Aborts the operation
65 HYDRODATA_EXPORT void AbortOperation();
66 //! Returns true if operation has been started, but not yet finished or aborted
67 HYDRODATA_EXPORT bool IsOperation();
68 //! Returns true if document was modified (since creation/opening)
69 HYDRODATA_EXPORT bool IsModified();
71 //! Returns True if there are available Undos
72 HYDRODATA_EXPORT bool CanUndo();
73 //! Returns a list of stored undo actions
74 HYDRODATA_EXPORT const TDF_DeltaList& GetUndos();
75 //! Clears a list of stored undo actions
76 HYDRODATA_EXPORT void ClearUndos();
77 //! Undoes last operation
78 HYDRODATA_EXPORT void Undo();
80 //! Returns True if there are available Redos
81 HYDRODATA_EXPORT bool CanRedo();
82 //! Returns a list of stored undo actions
83 HYDRODATA_EXPORT const TDF_DeltaList& GetRedos();
84 //! Clears a list of stored undo actions
85 HYDRODATA_EXPORT void ClearRedos();
86 //! Redoes last operation
87 HYDRODATA_EXPORT void Redo();
89 //! Creates and locates in the document a new object
90 //! \param theKind kind of the created object, can not be UNKNOWN
91 //! \returns the created object
92 HYDRODATA_EXPORT Handle_HYDROData_Object CreateObject(const ObjectKind theKind);
96 friend class HYDROData_Iterator;
97 friend class test_HYDROData_Document;
99 //! Creates new document: private because "Document" method must be used instead of direct creation.
100 HYDROData_Document();
101 //! Creates new document by existing OCAF structure
102 HYDROData_Document(const Handle(TDocStd_Document)& theDoc);
103 //! Deletes all high-level data, managed this document
104 ~HYDROData_Document();
106 //! Returns the new identifier of the new object (may be used for correct ordering of objects)
107 HYDRODATA_EXPORT int NewID();
109 //! Returns the label where the objects are located (used by Iterator)
110 TDF_Label LabelOfObjects();
113 Handle(TDocStd_Document) myDoc; ///< OCAF document instance corresponding for keeping all persistent data
114 int myTransactionsAfterSave; ///< number of transactions after the last "save" call, used for "IsModified" method