1 #ifndef HYDROData_Document_HeaderFile
2 #define HYDROData_Document_HeaderFile
5 #include <HYDROData_Entity.h>
7 #include <TDocStd_Document.hxx>
15 * Errors that could appear on document open/save actions.
16 * If there is no error, it is "OK".
19 DocError_OK = 0, ///< success
20 DocError_ResourcesProblem, ///< resources files are invalid or not found
21 DocError_CanNotOpen, ///< can not open file for reading or writing
22 DocError_InvalidVersion, ///< version of document is different than expected
23 DocError_InvalidFormat, ///< format of the document is bad
24 DocError_UnknownProblem ///< problem has unknown nature
27 DEFINE_STANDARD_HANDLE(HYDROData_Document, MMgt_TShared)
29 /**\class HYDROData_Document
31 * \brief Document for internal data structure of any object storage. Corresponds to the SALOME study.
33 * Document contains all data of the Study specific to this module.
34 * Also it provides acces to this data: open/save, transactions management etc.
35 * to provide access to all stored data.
38 class HYDROData_Document : public MMgt_TShared
42 DEFINE_STANDARD_RTTI(HYDROData_Document);
44 //! Returns the existing document or creates new if it is not exist
45 HYDRODATA_EXPORT static Handle(HYDROData_Document) Document(const int theStudyID);
47 //! Returns the document by object
48 HYDRODATA_EXPORT static Handle(HYDROData_Document) Document(
49 const TDF_Label& theObjectLabel );
53 //! Returns true if data model contains document for this study
54 HYDRODATA_EXPORT static bool HasDocument(const int theStudyID);
56 //! Get study id by document instance, if document doesn't exists return false
57 HYDRODATA_EXPORT static bool DocumentId( const Handle(HYDROData_Document)& theDocument,
62 //! Loads the OCAF document from the file.
63 //! \param theFileName full name of the file to load
64 //! \param theStudyID identifier of the SALOME study to associate with loaded file
65 //! \returns error status (OK in case of success)
66 HYDRODATA_EXPORT static Data_DocError Load(const char* theFileName, const int theStudyID);
68 //! Saves the OCAF document to the file.
69 //! \param theFileName full name of the file to store
70 //! \returns error status (OK in case of success)
71 HYDRODATA_EXPORT Data_DocError Save(const char* theFileName);
73 //! Removes document data
74 HYDRODATA_EXPORT void Close();
78 // Returns name of document instance in python dump script
79 HYDRODATA_EXPORT QString GetDocPyName() const;
81 //! Dump study document to Python script representation.
82 //! \param theFileName full name of the file to store
83 //! \returns true if document has been successfuly dumped
84 HYDRODATA_EXPORT bool DumpToPython( const QString& theFileName,
85 const bool theIsMultiFile ) const;
87 //! Dump model data to Python script representation.
88 HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects,
89 const bool theIsMultiFile ) const;
93 // Methods to work with objects presentation.
95 //! Returns the order of objects presentation. Objects in returned sequence
96 //! are order from top to low depending on z-level parameter. Objects that
97 //! have no z-level parameter are located at the end of sequence and
98 //! sorted alphabetically.
99 //! Only the following types of objects considered:
101 //! 2. KIND_IMMERSIBLE_ZONE
107 //! 8. KIND_POLYLINEXY
109 //! \param theIsAll if flag is true then all objects will be included,
110 //! otherwise only objects which have the z-level parameter
111 //! \returns ordered sequence of objects
112 HYDRODATA_EXPORT HYDROData_SequenceOfObjects GetObjectsLayerOrder(
113 const Standard_Boolean theIsAll = Standard_True ) const;
115 //! Sets the order of objects presentation.
116 HYDRODATA_EXPORT void SetObjectsLayerOrder( const HYDROData_SequenceOfObjects& theOrder );
118 //! Show object at the top of other model objects. If the object
119 //! already has the z-level parameter then nothing will be done.
120 HYDRODATA_EXPORT void Show( const Handle_HYDROData_Entity& theObject );
122 //! Show sequence of objects at the top of other model objects.
123 //! The objects from the sequence will be sorted alphabetically at first.
124 HYDRODATA_EXPORT void Show( const HYDROData_SequenceOfObjects& theObjects );
126 //! Removes the order of objects presentation.
127 HYDRODATA_EXPORT void RemoveObjectsLayerOrder();
129 HYDRODATA_EXPORT gp_Pnt2d GetLocalCS() const;
130 HYDRODATA_EXPORT void SetLocalCS( const gp_Pnt2d& );
131 HYDRODATA_EXPORT void Transform( double& X, double& Y, bool IsToLocalCS ) const;
132 HYDRODATA_EXPORT void Transform( gp_Pnt& thePnt, bool IsToLocalCS ) const;
133 HYDRODATA_EXPORT void Transform( gp_XYZ& thePnt, bool IsToLocalCS ) const;
137 //! Starts a new operation (opens a tansaction)
138 HYDRODATA_EXPORT void StartOperation();
139 //! Finishes the previously started operation (closes the transaction)
140 HYDRODATA_EXPORT void CommitOperation(
141 const TCollection_ExtendedString& theName = TCollection_ExtendedString());
142 //! Aborts the operation
143 HYDRODATA_EXPORT void AbortOperation();
144 //! Returns true if operation has been started, but not yet finished or aborted
145 HYDRODATA_EXPORT bool IsOperation();
146 //! Returns true if document was modified (since creation/opening)
147 HYDRODATA_EXPORT bool IsModified();
151 //! Returns True if there are available Undos
152 HYDRODATA_EXPORT bool CanUndo();
153 //! Returns a list of stored undo actions
154 HYDRODATA_EXPORT const TDF_DeltaList& GetUndos();
155 //! Clears a list of stored undo actions
156 HYDRODATA_EXPORT void ClearUndos();
157 //! Undoes last operation
158 HYDRODATA_EXPORT void Undo();
160 //! Returns True if there are available Redos
161 HYDRODATA_EXPORT bool CanRedo();
162 //! Returns a list of stored undo actions
163 HYDRODATA_EXPORT const TDF_DeltaList& GetRedos();
164 //! Clears a list of stored undo actions
165 HYDRODATA_EXPORT void ClearRedos();
166 //! Redoes last operation
167 HYDRODATA_EXPORT void Redo();
171 //! Creates and locates in the document a new object
172 //! \param theKind kind of the created object, can not be UNKNOWN
173 //! \returns the created object
174 HYDRODATA_EXPORT Handle(HYDROData_Entity) CreateObject(const ObjectKind theKind);
177 //! Find the data object with the specified name.
178 HYDRODATA_EXPORT Handle(HYDROData_Entity) FindObjectByName(
179 const QString& theName,
180 const ObjectKind theObjectKind = KIND_UNKNOWN ) const;
182 //! Find the data objects with the specified names.
183 HYDRODATA_EXPORT HYDROData_SequenceOfObjects FindObjectsByNames(
184 const QStringList& theNames,
185 const ObjectKind theObjectKind = KIND_UNKNOWN ) const;
189 friend class HYDROData_Iterator;
190 friend class test_HYDROData_Document;
192 //! Creates new document: private because "Document" method must be used instead of direct creation.
193 HYDRODATA_EXPORT HYDROData_Document();
194 //! Creates new document by existing OCAF structure
195 HYDRODATA_EXPORT HYDROData_Document(const Handle(TDocStd_Document)& theDoc);
196 //! Deletes all high-level data, managed this document
197 HYDRODATA_EXPORT ~HYDROData_Document();
199 //! Returns the new identifier of the new object (may be used for correct ordering of objects)
200 HYDRODATA_EXPORT int NewID();
202 //! Returns the label where the objects are located (used by Iterator)
203 HYDRODATA_EXPORT TDF_Label LabelOfObjects();
205 HYDRODATA_EXPORT TDF_Label LabelOfLocalCS() const;
209 // Dump header Python part in to file \c theFile
210 bool DumpToPython( QFile& theFile,
211 MapOfTreatedObjects& theTreatedObjects ) const;
213 // Dump objects of type \c theObjectKind to file \c theFile
214 bool dumpPartitionToPython( QFile& theFile,
215 const bool theIsMultiFile,
216 MapOfTreatedObjects& theDumpedObjects,
217 const ObjectKind& theObjectKind ) const;
220 Handle(TDocStd_Document) myDoc; ///< OCAF document instance corresponding for keeping all persistent data
221 int myTransactionsAfterSave; ///< number of transactions after the last "save" call, used for "IsModified" method