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