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