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