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