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