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