]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_Document.h
Salome HOME
Dump of document data to Python sript.
[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 class QFile;
10
11 /**
12  * Errors that could appear on document open/save actions.
13  * If there is no error, it is "OK".
14  */
15 enum Data_DocError {
16   DocError_OK = 0, ///< success
17   DocError_ResourcesProblem, ///< resources files are invalid or not found
18   DocError_CanNotOpen, ///< can not open file for reading or writing
19   DocError_InvalidVersion, ///< version of document is different than expected
20   DocError_InvalidFormat, ///< format of the document is bad
21   DocError_UnknownProblem ///< problem has unknown nature
22 };
23
24 DEFINE_STANDARD_HANDLE(HYDROData_Document, MMgt_TShared)
25
26 /**\class HYDROData_Document
27  *
28  * \brief Document for internal data structure of any object storage. Corresponds to the SALOME study.
29  *
30  * Document contains all data of the Study specific to this module.
31  * Also it provides acces to this data: open/save, transactions management etc.
32  * to provide access to all stored data.
33  */
34
35 class HYDROData_Document : public MMgt_TShared
36 {
37 public:
38
39   DEFINE_STANDARD_RTTI(HYDROData_Document);
40
41   //! Returns the existing document or creates new if it is not exist
42   HYDRODATA_EXPORT static Handle(HYDROData_Document) Document(const int theStudyID);
43
44   //! Returns true if data model contains document for this study
45   HYDRODATA_EXPORT static bool HasDocument(const int theStudyID);
46
47   //! Get study id by document instance, if document doesn't exists return false
48   HYDRODATA_EXPORT static bool DocumentId( const Handle(HYDROData_Document)& theDocument,
49                                            int&                              theDocId );
50
51   //! Loads the OCAF document from the file.
52   //! \param theFileName full name of the file to load
53   //! \param theStudyID identifier of the SALOME study to associate with loaded file
54   //! \returns error status (OK in case of success)
55   HYDRODATA_EXPORT static Data_DocError Load(const char* theFileName, const int theStudyID);
56
57   //! Saves the OCAF document to the file.
58   //! \param theFileName full name of the file to store
59   //! \returns error status (OK in case of success)
60   HYDRODATA_EXPORT Data_DocError Save(const char* theFileName);
61
62   //! Removes document data
63   HYDRODATA_EXPORT void Close();
64
65   // Returns name of document instance in python dump script
66   HYDRODATA_EXPORT QString GetDocPyName() const;
67
68   //! Dump study document to Python script representation.
69   //! \param theFileName full name of the file to store
70   //! \returns true if document has been successfuly dumped
71   HYDRODATA_EXPORT bool DumpToPython( const QString& theFileName ) const;
72
73   //! Dump model data to Python script representation.
74   HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
75
76   //! Starts a new operation (opens a tansaction)
77   HYDRODATA_EXPORT void StartOperation();
78   //! Finishes the previously started operation (closes the transaction)
79   HYDRODATA_EXPORT void CommitOperation(
80     const TCollection_ExtendedString& theName = TCollection_ExtendedString());
81   //! Aborts the operation 
82   HYDRODATA_EXPORT void AbortOperation();
83   //! Returns true if operation has been started, but not yet finished or aborted
84   HYDRODATA_EXPORT bool IsOperation();
85   //! Returns true if document was modified (since creation/opening)
86   HYDRODATA_EXPORT bool IsModified();
87
88   //! Returns True if there are available Undos
89   HYDRODATA_EXPORT bool CanUndo();
90   //! Returns a list of stored undo actions
91   HYDRODATA_EXPORT const TDF_DeltaList& GetUndos();
92   //! Clears a list of stored undo actions
93   HYDRODATA_EXPORT void ClearUndos();
94   //! Undoes last operation
95   HYDRODATA_EXPORT void Undo();
96
97   //! Returns True if there are available Redos
98   HYDRODATA_EXPORT bool CanRedo();
99   //! Returns a list of stored undo actions
100   HYDRODATA_EXPORT const TDF_DeltaList& GetRedos();
101   //! Clears a list of stored undo actions
102   HYDRODATA_EXPORT void ClearRedos();
103   //! Redoes last operation
104   HYDRODATA_EXPORT void Redo();
105
106   //! Creates and locates in the document a new object
107   //! \param theKind kind of the created object, can not be UNKNOWN
108   //! \returns the created object
109   HYDRODATA_EXPORT Handle_HYDROData_Object CreateObject(const ObjectKind theKind);
110
111 protected:
112
113   friend class HYDROData_Iterator;
114   friend class test_HYDROData_Document;
115
116   //! Creates new document: private because "Document" method must be used instead of direct creation.
117   HYDROData_Document();
118   //! Creates new document by existing OCAF structure
119   HYDROData_Document(const Handle(TDocStd_Document)& theDoc);
120   //! Deletes all high-level data, managed this document
121   ~HYDROData_Document();
122
123   //! Returns the new identifier of the new object (may be used for correct ordering of objects)
124   HYDRODATA_EXPORT int NewID();
125
126   //! Returns the label where the objects are located (used by Iterator)
127   TDF_Label LabelOfObjects();
128
129 private:
130   
131   // Dump header Python part in to file \c theFile
132   bool DumpToPython( QFile&               theFile,
133                      MapOfTreatedObjects& theTreatedObjects ) const;
134
135   // Dump objects of type \c theObjectKind to file \c theFile
136   bool dumpPartitionToPython( QFile&               theFile,
137                               MapOfTreatedObjects& theDumpedObjects,
138                               const ObjectKind&    theObjectKind ) const;
139
140 private:
141   Handle(TDocStd_Document) myDoc; ///< OCAF document instance corresponding for keeping all persistent data
142   int myTransactionsAfterSave; ///< number of transactions after the last "save" call, used for "IsModified" method
143 };
144
145 #endif