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