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