Salome HOME
00a907299603744f177bd5464bd449e20aa986d6
[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   //! 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();
69
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();
78
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);
83
84 protected:
85
86   friend class HYDROData_Iterator;
87   friend class test_HYDROData_Document;
88
89   //! Creates new document: private because "Document" method must be used instead of direct creation.
90   HYDROData_Document();
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();
95
96   //! Returns the new identifier of the new object (may be used for correct ordering of objects)
97   HYDRODATA_EXPORT int NewID();
98
99   //! Returns the label where the objects are located (used by Iterator)
100   TDF_Label LabelOfObjects();
101
102 private:
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
105 };
106
107 #endif