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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #ifndef HYDROData_Image_HeaderFile
20 #define HYDROData_Image_HeaderFile
22 #include <HYDROData_Entity.h>
25 #pragma warning ( disable: 4251 )
32 #pragma warning ( default: 4251 )
35 DEFINE_STANDARD_HANDLE(HYDROData_Image, HYDROData_Entity)
37 /**\class HYDROData_Image
38 * \brief Class that stores/retreives information about the image.
40 * Keeps image as binary array, transformation and other properties
41 * of image with correspondent API for forkind wit hthese properties.
43 class HYDROData_Image : public HYDROData_Entity
48 enum TransformationMode
58 * Enumeration of tags corresponding to the persistent object parameters.
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
71 DEFINE_STANDARD_RTTI(HYDROData_Image);
74 * Returns the kind of this object. Must be redefined in all objects of known type.
76 HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_IMAGE;}
79 * Dump Image object to Python script representation.
81 HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
84 * Updates object state.
85 * Reimplemented to update an Image object in the data structure.
86 * Call this method whenever you made changes for operator or reference objects.
87 * If it is changed, sets "MustBeUpdated" flag to other depended images.
89 HYDRODATA_EXPORT virtual void Update();
92 * Checks that object has 2D presentation. Reimlemented to retun true.
94 HYDRODATA_EXPORT virtual bool IsHas2dPrs() const;
97 * Returns data of object wrapped to QVariant.
98 * Reimplemented to wrap and return saved image.
99 * Transformation are applied to result image.
101 HYDRODATA_EXPORT virtual QVariant GetDataVariant();
104 * Returns the list of all reference objects of this object.
106 HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
111 * \param theImage new image
113 HYDRODATA_EXPORT void SetImage(const QImage& theImage);
116 * Load the image from file
117 * \param theFilePath path to image
119 HYDRODATA_EXPORT bool LoadImage(const QString& theFilePath);
122 * Returns the kept image
124 HYDRODATA_EXPORT QImage Image();
127 * Stores the image file path
128 * \param theFilePath image file path
130 HYDRODATA_EXPORT void SetFilePath(const QString& theFilePath);
133 * Returns uploaded image file path
135 HYDRODATA_EXPORT QString GetFilePath() const;
138 * Stores the image transformation
139 * \param theTrsf new transformation
141 HYDRODATA_EXPORT void SetTrsf(const QTransform& theTrsf);
144 * Returns the kept transformation, or "identity" if not yet stored
146 HYDRODATA_EXPORT QTransform Trsf() const;
149 * Updates the matrix of transformation in accordance with reference points.
150 * \param theTrsf new transformation
152 HYDRODATA_EXPORT void UpdateTrsf();
156 * Returns true if transformation is done by two points only
158 HYDRODATA_EXPORT bool IsByTwoPoints() const;
162 * Removes all references from this image.
164 HYDRODATA_EXPORT bool HasReferences() const;
167 * Removes all references from this image.
169 HYDRODATA_EXPORT void RemoveAllReferences();
173 * Stores the transformation points in local cs of image
174 * \param thePointA point A
175 * \param thePointB point B
176 * \param thePointC point C
178 HYDRODATA_EXPORT void SetLocalPoints( const QPoint& thePointA,
179 const QPoint& thePointB,
180 const QPoint& thePointC = QPoint( INT_MIN, INT_MIN ),
181 const bool theIsUpdate = true );
184 * Returns the transformation points in local cs of image
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
190 HYDRODATA_EXPORT bool GetLocalPoints( QPoint& thePointA,
192 QPoint& thePointC ) const;
195 * Returns true if local points has been set before
197 HYDRODATA_EXPORT bool HasLocalPoints() const;
201 * Stores the transformation points in global cs
202 * \param theMode transformation mode
203 * \param thePointA point A
204 * \param thePointB point B
205 * \param thePointC point C
207 HYDRODATA_EXPORT void SetGlobalPoints( const TransformationMode& theMode,
208 const QPointF& thePointA,
209 const QPointF& thePointB,
210 const QPointF& thePointC = QPoint( INT_MIN, INT_MIN ),
211 const bool theIsUpdate = true );
214 * Returns the transformation points in global cs
215 * \param theMode transformation mode
216 * \param thePointA point A
217 * \param thePointB point B
218 * \param thePointC point C
219 * \return true if all parameters has been set before
221 HYDRODATA_EXPORT bool GetGlobalPoints( TransformationMode& theMode,
224 QPointF& thePointC ) const;
227 * Get transformation points from the file and stores them in global cs
228 * \param theFileName the image georeferencement file name
229 * \return true in case of success
231 HYDRODATA_EXPORT bool SetGlobalPointsFromFile( const QString& theFileName );
234 * Returns true if global points has been set before
236 HYDRODATA_EXPORT bool HasGlobalPoints() const;
240 * Stores the transformation points in reference image local cs
241 * \param theRefImage reference image
242 * \param thePointA point A
243 * \param thePointB point B
244 * \param thePointC point C
246 HYDRODATA_EXPORT void SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
247 const QPointF& thePointA,
248 const QPointF& thePointB,
249 const QPointF& thePointC = QPoint( INT_MIN, INT_MIN ),
250 const bool theIsUpdate = true );
253 * Returns the transformation points in reference image local cs
254 * \param theRefImage reference image
255 * \param thePointA point A
256 * \param thePointB point B
257 * \param thePointC point C
258 * \return true if all parameters has been set correctly
260 HYDRODATA_EXPORT bool GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
263 QPointF& thePointC ) const;
266 * Returns true if reference points has been set before
268 HYDRODATA_EXPORT bool HasReferencePoints() const;
272 * Stores the reference image for transformation
273 * \param theRefImage reference image
275 HYDRODATA_EXPORT void SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage );
278 * Returns the reference image for transformation
280 HYDRODATA_EXPORT Handle(HYDROData_Image) GetTrsfReferenceImage() const;
283 * Removes the reference image for transformation
285 HYDRODATA_EXPORT void RemoveTrsfReferenceImage();
289 * Stores the transformation mode
291 HYDRODATA_EXPORT void SetTrsfMode( const TransformationMode& theMode );
294 * Returns the transformation mode
296 HYDRODATA_EXPORT TransformationMode GetTrsfMode() const;
300 * Returns the number of referenced objects
301 * \return zero if there is no references
303 HYDRODATA_EXPORT int NbReferences() const;
306 * Appends reference to other object (image or polyline).
307 * \param theReferenced the object referenced by this
309 HYDRODATA_EXPORT void AppendReference( const Handle(HYDROData_Entity)& theReferenced );
312 * Returns reference by index.
313 * \param theIndex number of reference [0; NbReference)
314 * \returns the referenced object, or Null if index is invalid
316 HYDRODATA_EXPORT Handle(HYDROData_Entity) Reference(const int theIndex) const;
319 * Updates reference by index. If index is one-bigger than \a NbReferences,
320 * this method appends it to the end (NbReferences is incremented).
321 * \param theIndex number of reference [0; NbReference]
322 * \param theReferenced the object referenced by this
324 HYDRODATA_EXPORT void ChangeReference(
325 const int theIndex, Handle(HYDROData_Entity) theReferenced);
328 * Removes reference by index
329 * \param theIndex number of reference [0; NbReference)
331 HYDRODATA_EXPORT void RemoveReference(const int theIndex);
334 * Removes all references.
336 HYDRODATA_EXPORT void ClearReferences();
340 * Stores the operator name
341 * \param theOpName name of the operator that must be executed for image update
343 HYDRODATA_EXPORT void SetOperatorName(const QString theOpName);
346 * Returns the operator name
347 * \returns the name of the operator that must be executed for image update
349 HYDRODATA_EXPORT QString OperatorName() const;
352 * Stores the operator arguments
353 * \param theArgs array that stores the operator arguments, needed for execution
355 HYDRODATA_EXPORT void SetArgs(const QByteArray& theArgs);
358 * Returns the operator arguments
359 * \returns array that stores the operator arguments, needed for execution
361 HYDRODATA_EXPORT QByteArray Args() const;
365 * Marks the image as self-splitted.
366 * \param theFlag is true for self-splitted image
368 HYDRODATA_EXPORT void SetIsSelfSplitted(bool theFlag);
371 * Checks that the image is self-splitted.
372 * \returns true if image is self-splitted
374 HYDRODATA_EXPORT bool IsSelfSplitted() const;
378 QPointF generateThirdPoint( const QPointF& thePointA,
379 const QPointF& thePointB,
380 const bool& theIsLocal ) const;
384 friend class HYDROData_Iterator;
387 * Creates new object in the internal data structure. Use higher level objects
388 * to create objects with real content.
390 HYDRODATA_EXPORT HYDROData_Image();
393 * Destructs properties of the object and object itself, removes it from the document.
395 HYDRODATA_EXPORT ~HYDROData_Image();