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