Salome HOME
Variables naming.
[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    * Returns data of object wrapped to QVariant.
68    * Reimplemented to wrap and return saved image.
69    * Transformation are applied to result image.
70    */
71   HYDRODATA_EXPORT virtual QVariant GetDataVariant();
72
73   /**
74    * Returns the list of all reference objects of this object.
75    */
76   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
77
78
79   /**
80    * Stores the image
81    * \param theImage new image
82    */
83   HYDRODATA_EXPORT void SetImage(const QImage& theImage);
84
85   /**
86    * Load the image from file
87    * \param theFilePath path to image
88    */
89   HYDRODATA_EXPORT bool LoadImage(const QString& theFilePath);
90
91   /**
92    * Returns the kept image
93    */
94   HYDRODATA_EXPORT QImage Image();
95
96   /**
97    * Stores the image file path
98    * \param theFilePath image file path
99    */
100   HYDRODATA_EXPORT void SetFilePath(const QString& theFilePath);
101
102   /**
103    * Returns uploaded image file path
104    */
105   HYDRODATA_EXPORT QString GetFilePath() const;
106
107   /**
108    * Stores the image transformation
109    * \param theTrsf new transformation
110    */
111   HYDRODATA_EXPORT void SetTrsf(const QTransform& theTrsf);
112
113   /**
114    * Returns the kept transformation, or "identity" if not yet stored
115    */
116   HYDRODATA_EXPORT QTransform Trsf() const;
117
118   /**
119    * Updates the matrix of transformation in accordance with reference points.
120    * \param theTrsf new transformation
121    */
122   HYDRODATA_EXPORT void UpdateTrsf();
123
124
125   /**
126    * Returns true if transformation is done by two points only
127    */
128   HYDRODATA_EXPORT bool IsByTwoPoints() const;
129
130
131   /**
132    * Removes all references from this image.
133    */
134   HYDRODATA_EXPORT bool HasReferences() const;
135
136   /**
137    * Removes all references from this image.
138    */
139   HYDRODATA_EXPORT void RemoveAllReferences();
140
141
142   /**
143    * Stores the transformation points in local cs of image
144    * \param thePointA point A
145    * \param thePointB point B
146    * \param thePointC point C
147    */
148   HYDRODATA_EXPORT void SetLocalPoints( const QPoint& thePointA,
149                                         const QPoint& thePointB,
150                                         const QPoint& thePointC = QPoint( INT_MIN, INT_MIN ),
151                                         const bool    theIsUpdate = true );
152
153   /**
154    * Returns the transformation points in local cs of image
155    * \param thePointA point A
156    * \param thePointB point B
157    * \param thePointC point C
158    * \return true if all parameters has been set before
159    */
160   HYDRODATA_EXPORT bool GetLocalPoints( QPoint& thePointA,
161                                         QPoint& thePointB,
162                                         QPoint& thePointC ) const;
163
164   /**
165    * Returns true if local points has been set before
166    */
167   HYDRODATA_EXPORT bool HasLocalPoints() const;
168
169
170   /**
171    * Stores the transformation points in global cs
172    * \param theMode transformation mode
173    * \param thePointA point A
174    * \param thePointB point B
175    * \param thePointC point C
176    */
177   HYDRODATA_EXPORT void SetGlobalPoints( const TransformationMode& theMode,
178                                          const QPointF&            thePointA,
179                                          const QPointF&            thePointB,
180                                          const QPointF&            thePointC = QPoint( INT_MIN, INT_MIN ),
181                                          const bool                theIsUpdate = true  );
182
183   /**
184    * Returns the transformation points in global cs
185    * \param theMode transformation mode
186    * \param thePointA point A
187    * \param thePointB point B
188    * \param thePointC point C
189    * \return true if all parameters has been set before
190    */
191   HYDRODATA_EXPORT bool GetGlobalPoints( TransformationMode& theMode,
192                                          QPointF&            thePointA,
193                                          QPointF&            thePointB,
194                                          QPointF&            thePointC ) const;
195
196   /**
197    * Get transformation points from the file and stores them in global cs
198    * \param theFileName the image georeferencement file name
199    * \return true in case of success
200    */
201   HYDRODATA_EXPORT bool SetGlobalPointsFromFile( const QString& theFileName );
202
203   /**
204    * Returns true if global points has been set before
205    */
206   HYDRODATA_EXPORT bool HasGlobalPoints() const;
207
208
209   /**
210    * Stores the transformation points in reference image local cs
211    * \param theRefImage reference image
212    * \param thePointA point A
213    * \param thePointB point B
214    * \param thePointC point C
215    */
216   HYDRODATA_EXPORT void SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
217                                             const QPointF&                 thePointA,
218                                             const QPointF&                 thePointB,
219                                             const QPointF&                 thePointC = QPoint( INT_MIN, INT_MIN ),
220                                             const bool                     theIsUpdate = true );
221
222   /**
223    * Returns the transformation points in reference image local cs
224    * \param theRefImage reference image
225    * \param thePointA point A
226    * \param thePointB point B
227    * \param thePointC point C
228    * \return true if all parameters has been set correctly
229    */
230   HYDRODATA_EXPORT bool GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
231                                             QPointF&                 thePointA,
232                                             QPointF&                 thePointB,
233                                             QPointF&                 thePointC ) const;
234
235   /**
236    * Returns true if reference points has been set before
237    */
238   HYDRODATA_EXPORT bool HasReferencePoints() const;
239
240
241   /**
242    * Stores the reference image for transformation
243    * \param theRefImage reference image
244    */
245   HYDRODATA_EXPORT void SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage );
246
247   /**
248    * Returns the reference image for transformation
249    */
250   HYDRODATA_EXPORT Handle(HYDROData_Image) GetTrsfReferenceImage() const;
251
252   /**
253    * Removes the reference image for transformation
254    */
255   HYDRODATA_EXPORT void RemoveTrsfReferenceImage();
256
257
258   /**
259    * Stores the transformation mode
260    */
261   HYDRODATA_EXPORT void SetTrsfMode( const TransformationMode& theMode );
262
263   /**
264    * Returns the transformation mode
265    */
266   HYDRODATA_EXPORT TransformationMode GetTrsfMode() const;
267
268
269   /**
270    * Returns the number of referenced objects
271    * \return zero if there is no references
272    */
273   HYDRODATA_EXPORT int NbReferences() const;
274
275   /**
276    * Appends reference to other object (image or polyline).
277    * \param theReferenced the object referenced by this
278    */
279   HYDRODATA_EXPORT void AppendReference( const Handle(HYDROData_Entity)& theReferenced );
280
281   /**
282    * Returns reference by index.
283    * \param theIndex number of reference [0; NbReference)
284    * \returns the referenced object, or Null if index is invalid
285    */
286   HYDRODATA_EXPORT Handle(HYDROData_Entity) Reference(const int theIndex) const;
287
288   /**
289    * Updates reference by index. If index is one-bigger than \a NbReferences, 
290    * this method appends it to the end (NbReferences is incremented).
291    * \param theIndex number of reference [0; NbReference]
292    * \param theReferenced the object referenced by this
293    */
294   HYDRODATA_EXPORT void ChangeReference(
295     const int theIndex, Handle(HYDROData_Entity) theReferenced);
296
297   /**
298    * Removes reference by index
299    * \param theIndex number of reference [0; NbReference)
300    */
301   HYDRODATA_EXPORT void RemoveReference(const int theIndex);
302
303   /**
304    * Removes all references.
305    */
306   HYDRODATA_EXPORT void ClearReferences();
307
308
309   /**
310    * Stores the operator name
311    * \param theOpName name of the operator that must be executed for image update
312    */
313   HYDRODATA_EXPORT void SetOperatorName(const QString theOpName);
314
315   /**
316    * Returns the operator name
317    * \returns the name of the operator that must be executed for image update
318    */
319   HYDRODATA_EXPORT QString OperatorName() const;
320
321   /**
322    * Stores the operator arguments
323    * \param theArgs array that stores the operator arguments, needed for execution
324    */
325   HYDRODATA_EXPORT void SetArgs(const QByteArray& theArgs);
326
327   /**
328    * Returns the operator arguments
329    * \returns array that stores the operator arguments, needed for execution
330    */
331   HYDRODATA_EXPORT QByteArray Args() const;
332   
333
334   /**
335    * Marks the image as self-splitted.
336    * \param theFlag is true for self-splitted image
337    */
338   HYDRODATA_EXPORT void SetIsSelfSplitted(bool theFlag);
339
340   /**
341    * Checks that the image is self-splitted.
342    * \returns true if image is self-splitted
343    */
344   HYDRODATA_EXPORT bool IsSelfSplitted() const;
345
346 private:
347
348   QPointF generateThirdPoint( const QPointF& thePointA,
349                               const QPointF& thePointB,
350                               const bool&    theIsLocal ) const;
351
352 protected:
353
354   friend class HYDROData_Iterator;
355
356   /**
357    * Creates new object in the internal data structure. Use higher level objects 
358    * to create objects with real content.
359    */
360   HYDRODATA_EXPORT HYDROData_Image();
361
362   /**
363    * Destructs properties of the object and object itself, removes it from the document.
364    */
365   HYDRODATA_EXPORT ~HYDROData_Image();
366
367 };
368
369 #endif