1 #ifndef HYDROData_Document_HeaderFile
2 #define HYDROData_Document_HeaderFile
5 #include <HYDROData_Object.h>
7 #include <TDocStd_Document.hxx>
12 * Errors that could appear on document open/save actions.
13 * If there is no error, it is "OK".
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
24 DEFINE_STANDARD_HANDLE(HYDROData_Document, MMgt_TShared)
26 /**\class HYDROData_Document
28 * \brief Document for internal data structure of any object storage. Corresponds to the SALOME study.
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.
35 class HYDROData_Document : public MMgt_TShared
39 DEFINE_STANDARD_RTTI(HYDROData_Document);
41 //! Returns the existing document or creates new if it is not exist
42 HYDRODATA_EXPORT static Handle(HYDROData_Document) Document(const int theStudyID);
44 //! Returns the document by object
45 HYDRODATA_EXPORT static Handle(HYDROData_Document) Document(
46 const Handle(HYDROData_Object)& theObject );
48 //! Returns true if data model contains document for this study
49 HYDRODATA_EXPORT static bool HasDocument(const int theStudyID);
51 //! Get study id by document instance, if document doesn't exists return false
52 HYDRODATA_EXPORT static bool DocumentId( const Handle(HYDROData_Document)& theDocument,
55 //! Loads the OCAF document from the file.
56 //! \param theFileName full name of the file to load
57 //! \param theStudyID identifier of the SALOME study to associate with loaded file
58 //! \returns error status (OK in case of success)
59 HYDRODATA_EXPORT static Data_DocError Load(const char* theFileName, const int theStudyID);
61 //! Saves the OCAF document to the file.
62 //! \param theFileName full name of the file to store
63 //! \returns error status (OK in case of success)
64 HYDRODATA_EXPORT Data_DocError Save(const char* theFileName);
66 //! Removes document data
67 HYDRODATA_EXPORT void Close();
69 // Returns name of document instance in python dump script
70 HYDRODATA_EXPORT QString GetDocPyName() const;
72 //! Dump study document to Python script representation.
73 //! \param theFileName full name of the file to store
74 //! \returns true if document has been successfuly dumped
75 HYDRODATA_EXPORT bool DumpToPython( const QString& theFileName ) const;
77 //! Dump model data to Python script representation.
78 HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
80 //! Starts a new operation (opens a tansaction)
81 HYDRODATA_EXPORT void StartOperation();
82 //! Finishes the previously started operation (closes the transaction)
83 HYDRODATA_EXPORT void CommitOperation(
84 const TCollection_ExtendedString& theName = TCollection_ExtendedString());
85 //! Aborts the operation
86 HYDRODATA_EXPORT void AbortOperation();
87 //! Returns true if operation has been started, but not yet finished or aborted
88 HYDRODATA_EXPORT bool IsOperation();
89 //! Returns true if document was modified (since creation/opening)
90 HYDRODATA_EXPORT bool IsModified();
92 //! Returns True if there are available Undos
93 HYDRODATA_EXPORT bool CanUndo();
94 //! Returns a list of stored undo actions
95 HYDRODATA_EXPORT const TDF_DeltaList& GetUndos();
96 //! Clears a list of stored undo actions
97 HYDRODATA_EXPORT void ClearUndos();
98 //! Undoes last operation
99 HYDRODATA_EXPORT void Undo();
101 //! Returns True if there are available Redos
102 HYDRODATA_EXPORT bool CanRedo();
103 //! Returns a list of stored undo actions
104 HYDRODATA_EXPORT const TDF_DeltaList& GetRedos();
105 //! Clears a list of stored undo actions
106 HYDRODATA_EXPORT void ClearRedos();
107 //! Redoes last operation
108 HYDRODATA_EXPORT void Redo();
110 //! Creates and locates in the document a new object
111 //! \param theKind kind of the created object, can not be UNKNOWN
112 //! \returns the created object
113 HYDRODATA_EXPORT Handle_HYDROData_Object CreateObject(const ObjectKind theKind);
117 friend class HYDROData_Iterator;
118 friend class test_HYDROData_Document;
120 //! Creates new document: private because "Document" method must be used instead of direct creation.
121 HYDROData_Document();
122 //! Creates new document by existing OCAF structure
123 HYDROData_Document(const Handle(TDocStd_Document)& theDoc);
124 //! Deletes all high-level data, managed this document
125 ~HYDROData_Document();
127 //! Returns the new identifier of the new object (may be used for correct ordering of objects)
128 HYDRODATA_EXPORT int NewID();
130 //! Returns the label where the objects are located (used by Iterator)
131 TDF_Label LabelOfObjects();
135 // Dump header Python part in to file \c theFile
136 bool DumpToPython( QFile& theFile,
137 MapOfTreatedObjects& theTreatedObjects ) const;
139 // Dump objects of type \c theObjectKind to file \c theFile
140 bool dumpPartitionToPython( QFile& theFile,
141 MapOfTreatedObjects& theDumpedObjects,
142 const ObjectKind& theObjectKind ) const;
145 Handle(TDocStd_Document) myDoc; ///< OCAF document instance corresponding for keeping all persistent data
146 int myTransactionsAfterSave; ///< number of transactions after the last "save" call, used for "IsModified" method