1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #ifndef HYDROData_Document_HeaderFile
24 #define HYDROData_Document_HeaderFile
26 #include <HYDROData.h>
27 #include <HYDROData_Entity.h>
29 #include <TDocStd_Document.hxx>
31 class HYDROData_InterpolatorsFactory;
32 class HYDROData_IProfilesInterpolator;
41 * Errors that could appear on document open/save actions.
42 * If there is no error, it is "OK".
45 DocError_OK = 0, ///< success
46 DocError_ResourcesProblem, ///< resources files are invalid or not found
47 DocError_CanNotOpen, ///< can not open file for reading or writing
48 DocError_InvalidVersion, ///< version of document is different than expected
49 DocError_InvalidFormat, ///< format of the document is bad
50 DocError_UnknownProblem ///< problem has unknown nature
53 DEFINE_STANDARD_HANDLE(HYDROData_Document, MMgt_TShared)
55 /**\class HYDROData_Document
57 * \brief Document for internal data structure of any object storage. Corresponds to the SALOME study.
59 * Document contains all data of the Study specific to this module.
60 * Also it provides acces to this data: open/save, transactions management etc.
61 * to provide access to all stored data.
64 class HYDROData_Document : public MMgt_TShared
68 DEFINE_STANDARD_RTTI(HYDROData_Document);
70 //! Returns the existing document or creates new if it is not exist
71 HYDRODATA_EXPORT static Handle(HYDROData_Document) Document(const int theStudyID);
73 //! Returns the document by object
74 HYDRODATA_EXPORT static Handle(HYDROData_Document) Document(
75 const TDF_Label& theObjectLabel );
79 //! Returns true if data model contains document for this study
80 HYDRODATA_EXPORT static bool HasDocument(const int theStudyID);
82 //! Get study id by document instance, if document doesn't exists return false
83 HYDRODATA_EXPORT static bool DocumentId( const Handle(HYDROData_Document)& theDocument,
88 //! Loads the OCAF document from the file.
89 //! \param theFileName full name of the file to load
90 //! \param theStudyID identifier of the SALOME study to associate with loaded file
91 //! \returns error status (OK in case of success)
92 HYDRODATA_EXPORT static Data_DocError Load(const char* theFileName, const int theStudyID);
94 //! Saves the OCAF document to the file.
95 //! \param theFileName full name of the file to store
96 //! \returns error status (OK in case of success)
97 HYDRODATA_EXPORT Data_DocError Save(const char* theFileName);
99 //! Removes document data
100 HYDRODATA_EXPORT void Close();
104 // Returns name of document instance in python dump script
105 HYDRODATA_EXPORT QString GetDocPyName() const;
107 //! Dump study document to Python script representation.
108 //! \param theFileName full name of the file to store
109 //! \returns true if document has been successfuly dumped
110 HYDRODATA_EXPORT bool DumpToPython( const QString& theFileName,
111 const bool theIsMultiFile ) const;
113 //! Dump model data to Python script representation.
114 HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects,
115 const bool theIsMultiFile ) const;
119 // Methods to work with objects presentation.
121 //! Returns the order of objects presentation. Objects in returned sequence
122 //! are order from top to low depending on z-level parameter. Objects that
123 //! have no z-level parameter are located at the end of sequence and
124 //! sorted alphabetically.
125 //! Only the following types of objects considered:
127 //! 2. KIND_IMMERSIBLE_ZONE
133 //! 8. KIND_POLYLINEXY
135 //! \param theIsAll if flag is true then all objects will be included,
136 //! otherwise only objects which have the z-level parameter
137 //! \returns ordered sequence of objects
138 HYDRODATA_EXPORT HYDROData_SequenceOfObjects GetObjectsLayerOrder(
139 const Standard_Boolean theIsAll = Standard_True ) const;
141 //! Sets the order of objects presentation.
142 HYDRODATA_EXPORT void SetObjectsLayerOrder( const HYDROData_SequenceOfObjects& theOrder );
144 //! Show object at the top of other model objects. If the object
145 //! already has the z-level parameter then nothing will be done.
146 HYDRODATA_EXPORT void Show( const Handle_HYDROData_Entity& theObject );
148 //! Show sequence of objects at the top of other model objects.
149 //! The objects from the sequence will be sorted alphabetically at first.
150 HYDRODATA_EXPORT void Show( const HYDROData_SequenceOfObjects& theObjects );
152 //! Removes the order of objects presentation.
153 HYDRODATA_EXPORT void RemoveObjectsLayerOrder();
155 HYDRODATA_EXPORT void GetLocalCS( double&, double& ) const;
156 HYDRODATA_EXPORT void SetLocalCS( double, double );
157 HYDRODATA_EXPORT void Transform( double& X, double& Y, bool IsToLocalCS ) const;
158 HYDRODATA_EXPORT void Transform( gp_Pnt& thePnt, bool IsToLocalCS ) const;
159 HYDRODATA_EXPORT void Transform( gp_XYZ& thePnt, bool IsToLocalCS ) const;
160 HYDRODATA_EXPORT void Transform( gp_XY& thePnt, bool IsToLocalCS ) const;
164 //! Starts a new operation (opens a tansaction)
165 HYDRODATA_EXPORT void StartOperation();
166 //! Finishes the previously started operation (closes the transaction)
167 HYDRODATA_EXPORT void CommitOperation(
168 const TCollection_ExtendedString& theName = TCollection_ExtendedString());
169 //! Aborts the operation
170 HYDRODATA_EXPORT void AbortOperation();
171 //! Returns true if operation has been started, but not yet finished or aborted
172 HYDRODATA_EXPORT bool IsOperation();
173 //! Returns true if document was modified (since creation/opening)
174 HYDRODATA_EXPORT bool IsModified();
178 //! Returns True if there are available Undos
179 HYDRODATA_EXPORT bool CanUndo();
180 //! Returns a list of stored undo actions
181 HYDRODATA_EXPORT const TDF_DeltaList& GetUndos();
182 //! Clears a list of stored undo actions
183 HYDRODATA_EXPORT void ClearUndos();
184 //! Undoes last operation
185 HYDRODATA_EXPORT void Undo();
187 //! Returns True if there are available Redos
188 HYDRODATA_EXPORT bool CanRedo();
189 //! Returns a list of stored undo actions
190 HYDRODATA_EXPORT const TDF_DeltaList& GetRedos();
191 //! Clears a list of stored undo actions
192 HYDRODATA_EXPORT void ClearRedos();
193 //! Redoes last operation
194 HYDRODATA_EXPORT void Redo();
198 //! Creates and locates in the document a new object
199 //! \param theKind kind of the created object, can not be UNKNOWN
200 //! \returns the created object
201 HYDRODATA_EXPORT Handle(HYDROData_Entity) CreateObject(const ObjectKind theKind);
204 //! Find the data object with the specified name.
205 HYDRODATA_EXPORT Handle(HYDROData_Entity) FindObjectByName(
206 const QString& theName,
207 const ObjectKind theObjectKind = KIND_UNKNOWN ) const;
209 //! Find the data objects with the specified names.
210 HYDRODATA_EXPORT HYDROData_SequenceOfObjects FindObjectsByNames(
211 const QStringList& theNames,
212 const ObjectKind theObjectKind = KIND_UNKNOWN ) const;
216 //! Returns interpolator factory instance
217 HYDRODATA_EXPORT HYDROData_InterpolatorsFactory* GetInterpolatorsFactory();
219 //! Get the appropriate interpolator by the name.
220 HYDRODATA_EXPORT HYDROData_IProfilesInterpolator* GetInterpolator( const TCollection_AsciiString& theName ) const;
222 //! Get list of registered interpolator names.
223 HYDRODATA_EXPORT NCollection_Sequence<TCollection_AsciiString> GetInterpolatorNames() const;
227 friend class HYDROData_Iterator;
228 friend class test_HYDROData_Document;
230 //! Creates new document: private because "Document" method must be used instead of direct creation.
231 HYDRODATA_EXPORT HYDROData_Document();
232 //! Creates new document by existing OCAF structure
233 HYDRODATA_EXPORT HYDROData_Document(const Handle(TDocStd_Document)& theDoc);
234 //! Deletes all high-level data, managed this document
235 HYDRODATA_EXPORT ~HYDROData_Document();
237 //! Returns the new identifier of the new object (may be used for correct ordering of objects)
238 HYDRODATA_EXPORT int NewID();
240 //! Returns the label where the objects are located (used by Iterator)
241 HYDRODATA_EXPORT TDF_Label LabelOfObjects();
243 HYDRODATA_EXPORT TDF_Label LabelOfLocalCS() const;
247 // Dump header Python part in to file \c theFile
248 bool DumpToPython( QFile& theFile,
249 MapOfTreatedObjects& theTreatedObjects ) const;
251 // Dump objects of type \c theObjectKind to file \c theFile
252 bool dumpPartitionToPython( QFile& theFile,
253 const bool theIsMultiFile,
254 MapOfTreatedObjects& theDumpedObjects,
255 const ObjectKind& theObjectKind ) const;
256 void UpdateLCSFields() const;
259 Handle(TDocStd_Document) myDoc; ///< OCAF document instance corresponding for keeping all persistent data
260 int myTransactionsAfterSave; ///< number of transactions after the last "save" call, used for "IsModified" method
263 HYDROData_InterpolatorsFactory* myInterpolatorsFactory; ///< iterpolators factory