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