Salome HOME
refs #561: the draft data model for Strickler table
[modules/hydro.git] / src / HYDROData / HYDROData_Image.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_Image_HeaderFile
20 #define HYDROData_Image_HeaderFile
21
22 #include <HYDROData_Entity.h>
23
24 #include <QImage>
25 #include <QTransform>
26
27 DEFINE_STANDARD_HANDLE(HYDROData_Image, HYDROData_Entity)
28
29 /**\class HYDROData_Image
30  * \brief Class that stores/retreives information about the image.
31  *
32  * Keeps image as binary array, transformation and other properties
33  * of image with correspondent API for forkind wit hthese properties.
34  */
35 class HYDROData_Image : public HYDROData_Entity
36 {
37
38 public:
39
40   enum TransformationMode
41   {
42     ManualGeodesic = 0,
43     ManualCartesian,
44     CartesianFromFile,
45     ReferenceImage
46   };
47
48 protected:
49   /**
50    * Enumeration of tags corresponding to the persistent object parameters.
51    */
52   enum DataTag
53   {
54     DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve
55     DataTag_Operator,        ///< name of the operator that must be executed for image update
56     DataTag_TrsfMode,        ///< transformation mode (0 - Lambert93, 1 - Cartesian, 2 - on other Image)
57     DataTag_TrsfPoints,      ///< image transformation points 
58     DataTag_TrsfImage,      ///< reference transformation image
59     DataTag_FilePath         ///< image imported file path
60   };
61
62 public:
63   DEFINE_STANDARD_RTTI(HYDROData_Image);
64
65   /**
66    * Returns the kind of this object. Must be redefined in all objects of known type.
67    */
68   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_IMAGE;}
69
70   /**
71    * Dump Image object to Python script representation.
72    */
73   HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
74
75   /**
76    * Updates object state.
77    * Reimplemented to update an Image object in the data structure.
78    * Call this method whenever you made changes for operator or reference objects.
79    * If it is changed, sets "MustBeUpdated" flag to other depended images.
80    */
81   HYDRODATA_EXPORT virtual void Update();
82
83   /**
84    * Checks that object has 2D presentation. Reimlemented to retun true.
85    */
86   HYDRODATA_EXPORT virtual bool IsHas2dPrs() const;
87
88   /**
89    * Returns data of object wrapped to QVariant.
90    * Reimplemented to wrap and return saved image.
91    * Transformation are applied to result image.
92    */
93   HYDRODATA_EXPORT virtual QVariant GetDataVariant();
94
95   /**
96    * Returns the list of all reference objects of this object.
97    */
98   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
99
100
101   /**
102    * Stores the image
103    * \param theImage new image
104    */
105   HYDRODATA_EXPORT void SetImage(const QImage& theImage);
106
107   /**
108    * Load the image from file
109    * \param theFilePath path to image
110    */
111   HYDRODATA_EXPORT bool LoadImage(const QString& theFilePath);
112
113   /**
114    * Returns the kept image
115    */
116   HYDRODATA_EXPORT QImage Image();
117
118   /**
119    * Stores the image file path
120    * \param theFilePath image file path
121    */
122   HYDRODATA_EXPORT void SetFilePath(const QString& theFilePath);
123
124   /**
125    * Returns uploaded image file path
126    */
127   HYDRODATA_EXPORT QString GetFilePath() const;
128
129   /**
130    * Stores the image transformation
131    * \param theTrsf new transformation
132    */
133   HYDRODATA_EXPORT void SetTrsf(const QTransform& theTrsf);
134
135   /**
136    * Returns the kept transformation, or "identity" if not yet stored
137    */
138   HYDRODATA_EXPORT QTransform Trsf() const;
139
140   /**
141    * Updates the matrix of transformation in accordance with reference points.
142    * \param theTrsf new transformation
143    */
144   HYDRODATA_EXPORT void UpdateTrsf();
145
146
147   /**
148    * Returns true if transformation is done by two points only
149    */
150   HYDRODATA_EXPORT bool IsByTwoPoints() const;
151
152
153   /**
154    * Removes all references from this image.
155    */
156   HYDRODATA_EXPORT bool HasReferences() const;
157
158   /**
159    * Removes all references from this image.
160    */
161   HYDRODATA_EXPORT void RemoveAllReferences();
162
163
164   /**
165    * Stores the transformation points in local cs of image
166    * \param thePointA point A
167    * \param thePointB point B
168    * \param thePointC point C
169    */
170   HYDRODATA_EXPORT void SetLocalPoints( const QPoint& thePointA,
171                                         const QPoint& thePointB,
172                                         const QPoint& thePointC = QPoint( INT_MIN, INT_MIN ),
173                                         const bool    theIsUpdate = true );
174
175   /**
176    * Returns the transformation points in local cs of image
177    * \param thePointA point A
178    * \param thePointB point B
179    * \param thePointC point C
180    * \return true if all parameters has been set before
181    */
182   HYDRODATA_EXPORT bool GetLocalPoints( QPoint& thePointA,
183                                         QPoint& thePointB,
184                                         QPoint& thePointC ) const;
185
186   /**
187    * Returns true if local points has been set before
188    */
189   HYDRODATA_EXPORT bool HasLocalPoints() const;
190
191
192   /**
193    * Stores the transformation points in global cs
194    * \param theMode transformation mode
195    * \param thePointA point A
196    * \param thePointB point B
197    * \param thePointC point C
198    */
199   HYDRODATA_EXPORT void SetGlobalPoints( const TransformationMode& theMode,
200                                          const QPointF&            thePointA,
201                                          const QPointF&            thePointB,
202                                          const QPointF&            thePointC = QPoint( INT_MIN, INT_MIN ),
203                                          const bool                theIsUpdate = true  );
204
205   /**
206    * Returns the transformation points in global cs
207    * \param theMode transformation mode
208    * \param thePointA point A
209    * \param thePointB point B
210    * \param thePointC point C
211    * \return true if all parameters has been set before
212    */
213   HYDRODATA_EXPORT bool GetGlobalPoints( TransformationMode& theMode,
214                                          QPointF&            thePointA,
215                                          QPointF&            thePointB,
216                                          QPointF&            thePointC ) const;
217
218   /**
219    * Get transformation points from the file and stores them in global cs
220    * \param theFileName the image georeferencement file name
221    * \return true in case of success
222    */
223   HYDRODATA_EXPORT bool SetGlobalPointsFromFile( const QString& theFileName );
224
225   /**
226    * Returns true if global points has been set before
227    */
228   HYDRODATA_EXPORT bool HasGlobalPoints() const;
229
230
231   /**
232    * Stores the transformation points in reference image local cs
233    * \param theRefImage reference image
234    * \param thePointA point A
235    * \param thePointB point B
236    * \param thePointC point C
237    */
238   HYDRODATA_EXPORT void SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
239                                             const QPointF&                 thePointA,
240                                             const QPointF&                 thePointB,
241                                             const QPointF&                 thePointC = QPoint( INT_MIN, INT_MIN ),
242                                             const bool                     theIsUpdate = true );
243
244   /**
245    * Returns the transformation points in reference image local cs
246    * \param theRefImage reference image
247    * \param thePointA point A
248    * \param thePointB point B
249    * \param thePointC point C
250    * \return true if all parameters has been set correctly
251    */
252   HYDRODATA_EXPORT bool GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
253                                             QPointF&                 thePointA,
254                                             QPointF&                 thePointB,
255                                             QPointF&                 thePointC ) const;
256
257   /**
258    * Returns true if reference points has been set before
259    */
260   HYDRODATA_EXPORT bool HasReferencePoints() const;
261
262
263   /**
264    * Stores the reference image for transformation
265    * \param theRefImage reference image
266    */
267   HYDRODATA_EXPORT void SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage );
268
269   /**
270    * Returns the reference image for transformation
271    */
272   HYDRODATA_EXPORT Handle(HYDROData_Image) GetTrsfReferenceImage() const;
273
274   /**
275    * Removes the reference image for transformation
276    */
277   HYDRODATA_EXPORT void RemoveTrsfReferenceImage();
278
279
280   /**
281    * Stores the transformation mode
282    */
283   HYDRODATA_EXPORT void SetTrsfMode( const TransformationMode& theMode );
284
285   /**
286    * Returns the transformation mode
287    */
288   HYDRODATA_EXPORT TransformationMode GetTrsfMode() const;
289
290
291   /**
292    * Returns the number of referenced objects
293    * \return zero if there is no references
294    */
295   HYDRODATA_EXPORT int NbReferences() const;
296
297   /**
298    * Appends reference to other object (image or polyline).
299    * \param theReferenced the object referenced by this
300    */
301   HYDRODATA_EXPORT void AppendReference( const Handle(HYDROData_Entity)& theReferenced );
302
303   /**
304    * Returns reference by index.
305    * \param theIndex number of reference [0; NbReference)
306    * \returns the referenced object, or Null if index is invalid
307    */
308   HYDRODATA_EXPORT Handle(HYDROData_Entity) Reference(const int theIndex) const;
309
310   /**
311    * Updates reference by index. If index is one-bigger than \a NbReferences, 
312    * this method appends it to the end (NbReferences is incremented).
313    * \param theIndex number of reference [0; NbReference]
314    * \param theReferenced the object referenced by this
315    */
316   HYDRODATA_EXPORT void ChangeReference(
317     const int theIndex, Handle(HYDROData_Entity) theReferenced);
318
319   /**
320    * Removes reference by index
321    * \param theIndex number of reference [0; NbReference)
322    */
323   HYDRODATA_EXPORT void RemoveReference(const int theIndex);
324
325   /**
326    * Removes all references.
327    */
328   HYDRODATA_EXPORT void ClearReferences();
329
330
331   /**
332    * Stores the operator name
333    * \param theOpName name of the operator that must be executed for image update
334    */
335   HYDRODATA_EXPORT void SetOperatorName(const QString theOpName);
336
337   /**
338    * Returns the operator name
339    * \returns the name of the operator that must be executed for image update
340    */
341   HYDRODATA_EXPORT QString OperatorName() const;
342
343   /**
344    * Stores the operator arguments
345    * \param theArgs array that stores the operator arguments, needed for execution
346    */
347   HYDRODATA_EXPORT void SetArgs(const QByteArray& theArgs);
348
349   /**
350    * Returns the operator arguments
351    * \returns array that stores the operator arguments, needed for execution
352    */
353   HYDRODATA_EXPORT QByteArray Args() const;
354   
355
356   /**
357    * Marks the image as self-splitted.
358    * \param theFlag is true for self-splitted image
359    */
360   HYDRODATA_EXPORT void SetIsSelfSplitted(bool theFlag);
361
362   /**
363    * Checks that the image is self-splitted.
364    * \returns true if image is self-splitted
365    */
366   HYDRODATA_EXPORT bool IsSelfSplitted() const;
367
368 private:
369
370   QPointF generateThirdPoint( const QPointF& thePointA,
371                               const QPointF& thePointB,
372                               const bool&    theIsLocal ) const;
373
374 protected:
375
376   friend class HYDROData_Iterator;
377
378   /**
379    * Creates new object in the internal data structure. Use higher level objects 
380    * to create objects with real content.
381    */
382   HYDRODATA_EXPORT HYDROData_Image();
383
384   /**
385    * Destructs properties of the object and object itself, removes it from the document.
386    */
387   HYDRODATA_EXPORT ~HYDROData_Image();
388
389 };
390
391 #endif