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