Salome HOME
fbda69941454765aba8e1be88e169ef2f871cc14
[modules/hydro.git] / src / HYDROData / HYDROData_Document.h
1 #ifndef HYDROData_Document_HeaderFile
2 #define HYDROData_Document_HeaderFile
3
4 #include <HYDROData.h>
5 #include <HYDROData_Object.h>
6
7 #include <TDocStd_Document.hxx>
8
9 /**
10  * Errors that could appear on document open/save actions.
11  * If there is no error, it is "OK".
12  */
13 enum Data_DocError {
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
20 };
21
22 DEFINE_STANDARD_HANDLE(HYDROData_Document, MMgt_TShared)
23
24 /**\class HYDROData_Document
25  *
26  * \brief Document for internal data structure of any object storage. Corresponds to the SALOME study.
27  *
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.
31  */
32
33 class HYDROData_Document : public MMgt_TShared
34 {
35 public:
36
37   DEFINE_STANDARD_RTTI(HYDROData_Document);
38
39   //! Returns the existing document or creates new if it is not exist
40   HYDRODATA_EXPORT static Handle(HYDROData_Document) Document(const int theStudyID);
41
42   //! Returns true if data model contains document for this study
43   HYDRODATA_EXPORT static bool HasDocument(const int theStudyID);
44
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);
50
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);
55
56   //! Removes document data
57   HYDRODATA_EXPORT void Close();
58
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();
70
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();
79
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();
88
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);
93
94 protected:
95
96   friend class HYDROData_Iterator;
97   friend class test_HYDROData_Document;
98
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();
105
106   //! Returns the new identifier of the new object (may be used for correct ordering of objects)
107   HYDRODATA_EXPORT int NewID();
108
109   //! Returns the label where the objects are located (used by Iterator)
110   TDF_Label LabelOfObjects();
111
112 private:
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
115 };
116
117 #endif