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