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