1 #ifndef HYDROData_Document_HeaderFile
2 #define HYDROData_Document_HeaderFile
5 #include <HYDROData_Entity.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 TDF_Label& theObjectLabel );
50 //! Returns true if data model contains document for this study
51 HYDRODATA_EXPORT static bool HasDocument(const int theStudyID);
53 //! Get study id by document instance, if document doesn't exists return false
54 HYDRODATA_EXPORT static bool DocumentId( const Handle(HYDROData_Document)& theDocument,
59 //! Loads the OCAF document from the file.
60 //! \param theFileName full name of the file to load
61 //! \param theStudyID identifier of the SALOME study to associate with loaded file
62 //! \returns error status (OK in case of success)
63 HYDRODATA_EXPORT static Data_DocError Load(const char* theFileName, const int theStudyID);
65 //! Saves the OCAF document to the file.
66 //! \param theFileName full name of the file to store
67 //! \returns error status (OK in case of success)
68 HYDRODATA_EXPORT Data_DocError Save(const char* theFileName);
70 //! Removes document data
71 HYDRODATA_EXPORT void Close();
75 // Returns name of document instance in python dump script
76 HYDRODATA_EXPORT QString GetDocPyName() const;
78 //! Dump study document to Python script representation.
79 //! \param theFileName full name of the file to store
80 //! \returns true if document has been successfuly dumped
81 HYDRODATA_EXPORT bool DumpToPython( const QString& theFileName,
82 const bool theIsMultiFile ) const;
84 //! Dump model data to Python script representation.
85 HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects,
86 const bool theIsMultiFile ) const;
90 //! Starts a new operation (opens a tansaction)
91 HYDRODATA_EXPORT void StartOperation();
92 //! Finishes the previously started operation (closes the transaction)
93 HYDRODATA_EXPORT void CommitOperation(
94 const TCollection_ExtendedString& theName = TCollection_ExtendedString());
95 //! Aborts the operation
96 HYDRODATA_EXPORT void AbortOperation();
97 //! Returns true if operation has been started, but not yet finished or aborted
98 HYDRODATA_EXPORT bool IsOperation();
99 //! Returns true if document was modified (since creation/opening)
100 HYDRODATA_EXPORT bool IsModified();
104 //! Returns True if there are available Undos
105 HYDRODATA_EXPORT bool CanUndo();
106 //! Returns a list of stored undo actions
107 HYDRODATA_EXPORT const TDF_DeltaList& GetUndos();
108 //! Clears a list of stored undo actions
109 HYDRODATA_EXPORT void ClearUndos();
110 //! Undoes last operation
111 HYDRODATA_EXPORT void Undo();
113 //! Returns True if there are available Redos
114 HYDRODATA_EXPORT bool CanRedo();
115 //! Returns a list of stored undo actions
116 HYDRODATA_EXPORT const TDF_DeltaList& GetRedos();
117 //! Clears a list of stored undo actions
118 HYDRODATA_EXPORT void ClearRedos();
119 //! Redoes last operation
120 HYDRODATA_EXPORT void Redo();
124 //! Creates and locates in the document a new object
125 //! \param theKind kind of the created object, can not be UNKNOWN
126 //! \returns the created object
127 HYDRODATA_EXPORT Handle(HYDROData_Entity) CreateObject(const ObjectKind theKind);
130 //! Find the data object with the specified name.
131 HYDRODATA_EXPORT Handle(HYDROData_Entity) FindObjectByName(
132 const QString& theName,
133 const ObjectKind theObjectKind = KIND_UNKNOWN ) const;
135 //! Find the data objects with the specified names.
136 HYDRODATA_EXPORT HYDROData_SequenceOfObjects FindObjectsByNames(
137 const QStringList& theNames,
138 const ObjectKind theObjectKind = KIND_UNKNOWN ) const;
142 friend class HYDROData_Iterator;
143 friend class test_HYDROData_Document;
145 //! Creates new document: private because "Document" method must be used instead of direct creation.
146 HYDRODATA_EXPORT HYDROData_Document();
147 //! Creates new document by existing OCAF structure
148 HYDRODATA_EXPORT HYDROData_Document(const Handle(TDocStd_Document)& theDoc);
149 //! Deletes all high-level data, managed this document
150 HYDRODATA_EXPORT ~HYDROData_Document();
152 //! Returns the new identifier of the new object (may be used for correct ordering of objects)
153 HYDRODATA_EXPORT int NewID();
155 //! Returns the label where the objects are located (used by Iterator)
156 HYDRODATA_EXPORT TDF_Label LabelOfObjects();
160 // Dump header Python part in to file \c theFile
161 bool DumpToPython( QFile& theFile,
162 MapOfTreatedObjects& theTreatedObjects ) const;
164 // Dump objects of type \c theObjectKind to file \c theFile
165 bool dumpPartitionToPython( QFile& theFile,
166 const bool theIsMultiFile,
167 MapOfTreatedObjects& theDumpedObjects,
168 const ObjectKind& theObjectKind ) const;
171 Handle(TDocStd_Document) myDoc; ///< OCAF document instance corresponding for keeping all persistent data
172 int myTransactionsAfterSave; ///< number of transactions after the last "save" call, used for "IsModified" method