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