1 #ifndef HYDROData_Document_HeaderFile
2 #define HYDROData_Document_HeaderFile
5 #include <HYDROData_Object.h>
7 #include <TDocStd_Document.hxx>
13 * Errors that could appear on document open/save actions.
14 * If there is no error, it is "OK".
17 DocError_OK = 0, ///< success
18 DocError_ResourcesProblem, ///< resources files are invalid or not found
19 DocError_CanNotOpen, ///< can not open file for reading or writing
20 DocError_InvalidVersion, ///< version of document is different than expected
21 DocError_InvalidFormat, ///< format of the document is bad
22 DocError_UnknownProblem ///< problem has unknown nature
25 DEFINE_STANDARD_HANDLE(HYDROData_Document, MMgt_TShared)
27 /**\class HYDROData_Document
29 * \brief Document for internal data structure of any object storage. Corresponds to the SALOME study.
31 * Document contains all data of the Study specific to this module.
32 * Also it provides acces to this data: open/save, transactions management etc.
33 * to provide access to all stored data.
36 class HYDROData_Document : public MMgt_TShared
40 DEFINE_STANDARD_RTTI(HYDROData_Document);
42 //! Returns the existing document or creates new if it is not exist
43 HYDRODATA_EXPORT static Handle(HYDROData_Document) Document(const int theStudyID);
45 //! Returns true if data model contains document for this study
46 HYDRODATA_EXPORT static bool HasDocument(const int theStudyID);
48 //! Loads the OCAF document from the file.
49 //! \param theFileName full name of the file to load
50 //! \param theStudyID identifier of the SALOME study to associate with loaded file
51 //! \returns error status (OK in case of success)
52 HYDRODATA_EXPORT static Data_DocError Load(const char* theFileName, const int theStudyID);
54 //! Saves the OCAF document to the file.
55 //! \param theFileName full name of the file to store
56 //! \returns error status (OK in case of success)
57 HYDRODATA_EXPORT Data_DocError Save(const char* theFileName);
59 //! Removes document data
60 HYDRODATA_EXPORT void Close();
62 //! Dump study document to Python script representation.
63 //! \param theFileName full name of the file to store
64 //! \returns true if document has been successfuly dumped
65 HYDRODATA_EXPORT bool DumpToPython( const QString& theFileName ) const;
67 //! Starts a new operation (opens a tansaction)
68 HYDRODATA_EXPORT void StartOperation();
69 //! Finishes the previously started operation (closes the transaction)
70 HYDRODATA_EXPORT void CommitOperation(
71 const TCollection_ExtendedString& theName = TCollection_ExtendedString());
72 //! Aborts the operation
73 HYDRODATA_EXPORT void AbortOperation();
74 //! Returns true if operation has been started, but not yet finished or aborted
75 HYDRODATA_EXPORT bool IsOperation();
76 //! Returns true if document was modified (since creation/opening)
77 HYDRODATA_EXPORT bool IsModified();
79 //! Returns True if there are available Undos
80 HYDRODATA_EXPORT bool CanUndo();
81 //! Returns a list of stored undo actions
82 HYDRODATA_EXPORT const TDF_DeltaList& GetUndos();
83 //! Clears a list of stored undo actions
84 HYDRODATA_EXPORT void ClearUndos();
85 //! Undoes last operation
86 HYDRODATA_EXPORT void Undo();
88 //! Returns True if there are available Redos
89 HYDRODATA_EXPORT bool CanRedo();
90 //! Returns a list of stored undo actions
91 HYDRODATA_EXPORT const TDF_DeltaList& GetRedos();
92 //! Clears a list of stored undo actions
93 HYDRODATA_EXPORT void ClearRedos();
94 //! Redoes last operation
95 HYDRODATA_EXPORT void Redo();
97 //! Creates and locates in the document a new object
98 //! \param theKind kind of the created object, can not be UNKNOWN
99 //! \returns the created object
100 HYDRODATA_EXPORT Handle_HYDROData_Object CreateObject(const ObjectKind theKind);
104 friend class HYDROData_Iterator;
105 friend class test_HYDROData_Document;
107 //! Creates new document: private because "Document" method must be used instead of direct creation.
108 HYDROData_Document();
109 //! Creates new document by existing OCAF structure
110 HYDROData_Document(const Handle(TDocStd_Document)& theDoc);
111 //! Deletes all high-level data, managed this document
112 ~HYDROData_Document();
114 //! Returns the new identifier of the new object (may be used for correct ordering of objects)
115 HYDRODATA_EXPORT int NewID();
117 //! Returns the label where the objects are located (used by Iterator)
118 TDF_Label LabelOfObjects();
122 // Dump objects of type \c theObjectKind to file \c theFile
123 bool dumpPartitionToPython( QFile& theFile,
124 QMap<QString,Handle(HYDROData_Object)>& theDumpedObjects,
125 const ObjectKind& theObjectKind ) const;
128 Handle(TDocStd_Document) myDoc; ///< OCAF document instance corresponding for keeping all persistent data
129 int myTransactionsAfterSave; ///< number of transactions after the last "save" call, used for "IsModified" method