1 #ifndef HYDROData_Document_HeaderFile
2 #define HYDROData_Document_HeaderFile
5 #include <HYDROData_Entity.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 the document by object
46 HYDRODATA_EXPORT static Handle(HYDROData_Document) Document(
47 const TDF_Label& theObjectLabel );
51 //! Returns true if data model contains document for this study
52 HYDRODATA_EXPORT static bool HasDocument(const int theStudyID);
54 //! Get study id by document instance, if document doesn't exists return false
55 HYDRODATA_EXPORT static bool DocumentId( const Handle(HYDROData_Document)& theDocument,
60 //! Loads the OCAF document from the file.
61 //! \param theFileName full name of the file to load
62 //! \param theStudyID identifier of the SALOME study to associate with loaded file
63 //! \returns error status (OK in case of success)
64 HYDRODATA_EXPORT static Data_DocError Load(const char* theFileName, const int theStudyID);
66 //! Saves the OCAF document to the file.
67 //! \param theFileName full name of the file to store
68 //! \returns error status (OK in case of success)
69 HYDRODATA_EXPORT Data_DocError Save(const char* theFileName);
71 //! Removes document data
72 HYDRODATA_EXPORT void Close();
76 // Returns name of document instance in python dump script
77 HYDRODATA_EXPORT QString GetDocPyName() const;
79 //! Dump study document to Python script representation.
80 //! \param theFileName full name of the file to store
81 //! \returns true if document has been successfuly dumped
82 HYDRODATA_EXPORT bool DumpToPython( const QString& theFileName,
83 const bool theIsMultiFile ) const;
85 //! Dump model data to Python script representation.
86 HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects,
87 const bool theIsMultiFile ) const;
91 // Methods to work with objects presentation.
93 //! Returns the order of objects presentation. Objects in returned sequence
94 //! are order from top to low depending on z-level parameter. Objects that
95 //! have no z-level parameter are located at the end of sequence and
96 //! sorted alphabetically.
97 //! Only the following types of objects considered:
99 //! 2. KIND_IMMERSIBLE_ZONE
105 //! 8. KIND_POLYLINEXY
107 //! \param theIsAll if flag is true then all objects will be included,
108 //! otherwise only objects which have the z-level parameter
109 //! \returns ordered sequence of objects
110 HYDRODATA_EXPORT HYDROData_SequenceOfObjects GetObjectsLayerOrder(
111 const Standard_Boolean theIsAll = Standard_True ) const;
113 //! Sets the order of objects presentation.
114 HYDRODATA_EXPORT void SetObjectsLayerOrder( const HYDROData_SequenceOfObjects& theOrder );
116 //! Show object at the top of other model objects. If the object
117 //! already has the z-level parameter then nothing will be done.
118 HYDRODATA_EXPORT void Show( const Handle_HYDROData_Entity& theObject );
120 //! Show sequence of objects at the top of other model objects.
121 //! The objects from the sequence will be sorted alphabetically at first.
122 HYDRODATA_EXPORT void Show( const HYDROData_SequenceOfObjects& theObjects );
124 //! Removes the order of objects presentation.
125 HYDRODATA_EXPORT void RemoveObjectsLayerOrder();
127 HYDRODATA_EXPORT gp_Pnt2d GetLocalCS() const;
128 HYDRODATA_EXPORT void SetLocalCS( const gp_Pnt2d& );
132 //! Starts a new operation (opens a tansaction)
133 HYDRODATA_EXPORT void StartOperation();
134 //! Finishes the previously started operation (closes the transaction)
135 HYDRODATA_EXPORT void CommitOperation(
136 const TCollection_ExtendedString& theName = TCollection_ExtendedString());
137 //! Aborts the operation
138 HYDRODATA_EXPORT void AbortOperation();
139 //! Returns true if operation has been started, but not yet finished or aborted
140 HYDRODATA_EXPORT bool IsOperation();
141 //! Returns true if document was modified (since creation/opening)
142 HYDRODATA_EXPORT bool IsModified();
146 //! Returns True if there are available Undos
147 HYDRODATA_EXPORT bool CanUndo();
148 //! Returns a list of stored undo actions
149 HYDRODATA_EXPORT const TDF_DeltaList& GetUndos();
150 //! Clears a list of stored undo actions
151 HYDRODATA_EXPORT void ClearUndos();
152 //! Undoes last operation
153 HYDRODATA_EXPORT void Undo();
155 //! Returns True if there are available Redos
156 HYDRODATA_EXPORT bool CanRedo();
157 //! Returns a list of stored undo actions
158 HYDRODATA_EXPORT const TDF_DeltaList& GetRedos();
159 //! Clears a list of stored undo actions
160 HYDRODATA_EXPORT void ClearRedos();
161 //! Redoes last operation
162 HYDRODATA_EXPORT void Redo();
166 //! Creates and locates in the document a new object
167 //! \param theKind kind of the created object, can not be UNKNOWN
168 //! \returns the created object
169 HYDRODATA_EXPORT Handle(HYDROData_Entity) CreateObject(const ObjectKind theKind);
172 //! Find the data object with the specified name.
173 HYDRODATA_EXPORT Handle(HYDROData_Entity) FindObjectByName(
174 const QString& theName,
175 const ObjectKind theObjectKind = KIND_UNKNOWN ) const;
177 //! Find the data objects with the specified names.
178 HYDRODATA_EXPORT HYDROData_SequenceOfObjects FindObjectsByNames(
179 const QStringList& theNames,
180 const ObjectKind theObjectKind = KIND_UNKNOWN ) const;
184 friend class HYDROData_Iterator;
185 friend class test_HYDROData_Document;
187 //! Creates new document: private because "Document" method must be used instead of direct creation.
188 HYDRODATA_EXPORT HYDROData_Document();
189 //! Creates new document by existing OCAF structure
190 HYDRODATA_EXPORT HYDROData_Document(const Handle(TDocStd_Document)& theDoc);
191 //! Deletes all high-level data, managed this document
192 HYDRODATA_EXPORT ~HYDROData_Document();
194 //! Returns the new identifier of the new object (may be used for correct ordering of objects)
195 HYDRODATA_EXPORT int NewID();
197 //! Returns the label where the objects are located (used by Iterator)
198 HYDRODATA_EXPORT TDF_Label LabelOfObjects();
200 HYDRODATA_EXPORT TDF_Label LabelOfLocalCS() const;
204 // Dump header Python part in to file \c theFile
205 bool DumpToPython( QFile& theFile,
206 MapOfTreatedObjects& theTreatedObjects ) const;
208 // Dump objects of type \c theObjectKind to file \c theFile
209 bool dumpPartitionToPython( QFile& theFile,
210 const bool theIsMultiFile,
211 MapOfTreatedObjects& theDumpedObjects,
212 const ObjectKind& theObjectKind ) const;
215 Handle(TDocStd_Document) myDoc; ///< OCAF document instance corresponding for keeping all persistent data
216 int myTransactionsAfterSave; ///< number of transactions after the last "save" call, used for "IsModified" method