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 /**\class HYDROData_Image
36 * \brief Class that stores/retreives information about the image.
38 * Keeps image as binary array, transformation and other properties
39 * of image with correspondent API for forkind wit hthese properties.
41 class HYDROData_Image : public HYDROData_Entity
46 enum TransformationMode
56 * Enumeration of tags corresponding to the persistent object parameters.
60 DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve
61 DataTag_Operator, ///< name of the operator that must be executed for image update
62 DataTag_TrsfMode, ///< transformation mode (0 - Lambert93, 1 - Cartesian, 2 - on other Image)
63 DataTag_TrsfPoints, ///< image transformation points
64 DataTag_TrsfImage, ///< reference transformation image
65 DataTag_FilePath ///< image imported file path
69 DEFINE_STANDARD_RTTIEXT(HYDROData_Image, HYDROData_Entity);
72 * Returns the kind of this object. Must be redefined in all objects of known type.
74 HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_IMAGE;}
77 * Dump Image object to Python script representation.
79 HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath,
80 MapOfTreatedObjects& theTreatedObjects ) const;
83 * Updates object state.
84 * Reimplemented to update an Image object in the data structure.
85 * Call this method whenever you made changes for operator or reference objects.
86 * If it is changed, sets "MustBeUpdated" flag to other depended images.
88 HYDRODATA_EXPORT virtual void Update();
91 * Checks that object has 2D presentation. Reimlemented to retun true.
93 HYDRODATA_EXPORT virtual bool IsHas2dPrs() const;
96 * Returns data of object wrapped to QVariant.
97 * Reimplemented to wrap and return saved image.
98 * Transformation are applied to result image.
100 HYDRODATA_EXPORT virtual QVariant GetDataVariant();
103 * Returns the list of all reference objects of this object.
105 HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
110 * \param theImage new image
112 HYDRODATA_EXPORT void SetImage(const QImage& theImage);
115 * Load the image from file
116 * \param theFilePath path to image
118 HYDRODATA_EXPORT bool LoadImage(const QString& theFilePath);
121 * Returns the kept image
123 HYDRODATA_EXPORT QImage Image();
126 * Stores the image file path
127 * \param theFilePath image file path
129 HYDRODATA_EXPORT void SetFilePath(const QString& theFilePath);
132 * Returns uploaded image file path
134 HYDRODATA_EXPORT QString GetFilePath() const;
137 * Stores the image transformation
138 * \param theTrsf new transformation
140 HYDRODATA_EXPORT void SetTrsf(const QTransform& theTrsf);
143 * Returns the kept transformation, or "identity" if not yet stored
145 HYDRODATA_EXPORT QTransform Trsf() const;
148 * Updates the matrix of transformation in accordance with reference points.
149 * \param theTrsf new transformation
151 HYDRODATA_EXPORT void UpdateTrsf();
155 * Returns true if transformation is done by two points only
157 HYDRODATA_EXPORT bool IsByTwoPoints() const;
161 * Removes all references from this image.
163 HYDRODATA_EXPORT bool HasReferences() const;
166 * Removes all references from this image.
168 HYDRODATA_EXPORT void RemoveAllReferences();
172 * Stores the transformation points in local cs of image
173 * \param thePointA point A
174 * \param thePointB point B
175 * \param thePointC point C
177 HYDRODATA_EXPORT void SetLocalPoints( const QPoint& thePointA,
178 const QPoint& thePointB,
179 const QPoint& thePointC = QPoint( INT_MIN, INT_MIN ),
180 const bool theIsUpdate = true );
183 * Returns the transformation points in local cs of image
184 * \param thePointA point A
185 * \param thePointB point B
186 * \param thePointC point C
187 * \return true if all parameters has been set before
189 HYDRODATA_EXPORT bool GetLocalPoints( QPoint& thePointA,
191 QPoint& thePointC ) const;
194 * Returns true if local points has been set before
196 HYDRODATA_EXPORT bool HasLocalPoints() const;
200 * Stores the transformation points in global cs
201 * \param theMode transformation mode
202 * \param thePointA point A
203 * \param thePointB point B
204 * \param thePointC point C
206 HYDRODATA_EXPORT void SetGlobalPoints( const TransformationMode& theMode,
207 const QPointF& thePointA,
208 const QPointF& thePointB,
209 const QPointF& thePointC = QPoint( INT_MIN, INT_MIN ),
210 const bool theIsUpdate = true );
213 * Returns the transformation points in global cs
214 * \param theMode transformation mode
215 * \param thePointA point A
216 * \param thePointB point B
217 * \param thePointC point C
218 * \return true if all parameters has been set before
220 HYDRODATA_EXPORT bool GetGlobalPoints( TransformationMode& theMode,
223 QPointF& thePointC ) const;
226 * Get transformation points from the file and stores them in global cs
227 * \param theFileName the image georeferencement file name
228 * \return true in case of success
230 HYDRODATA_EXPORT bool SetGlobalPointsFromFile( const QString& theFileName );
233 * Returns true if global points has been set before
235 HYDRODATA_EXPORT bool HasGlobalPoints() const;
239 * Stores the transformation points in reference image local cs
240 * \param theRefImage reference image
241 * \param thePointA point A
242 * \param thePointB point B
243 * \param thePointC point C
245 HYDRODATA_EXPORT void SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
246 const QPointF& thePointA,
247 const QPointF& thePointB,
248 const QPointF& thePointC = QPoint( INT_MIN, INT_MIN ),
249 const bool theIsUpdate = true );
252 * Returns the transformation points in reference image local cs
253 * \param theRefImage reference image
254 * \param thePointA point A
255 * \param thePointB point B
256 * \param thePointC point C
257 * \return true if all parameters has been set correctly
259 HYDRODATA_EXPORT bool GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
262 QPointF& thePointC ) const;
265 * Returns true if reference points has been set before
267 HYDRODATA_EXPORT bool HasReferencePoints() const;
271 * Stores the reference image for transformation
272 * \param theRefImage reference image
274 HYDRODATA_EXPORT void SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage );
277 * Returns the reference image for transformation
279 HYDRODATA_EXPORT Handle(HYDROData_Image) GetTrsfReferenceImage() const;
282 * Removes the reference image for transformation
284 HYDRODATA_EXPORT void RemoveTrsfReferenceImage();
288 * Stores the transformation mode
290 HYDRODATA_EXPORT void SetTrsfMode( const TransformationMode& theMode );
293 * Returns the transformation mode
295 HYDRODATA_EXPORT TransformationMode GetTrsfMode() const;
299 * Returns the number of referenced objects
300 * \return zero if there is no references
302 HYDRODATA_EXPORT int NbReferences() const;
305 * Appends reference to other object (image or polyline).
306 * \param theReferenced the object referenced by this
308 HYDRODATA_EXPORT void AppendReference( const Handle(HYDROData_Entity)& theReferenced );
311 * Returns reference by index.
312 * \param theIndex number of reference [0; NbReference)
313 * \returns the referenced object, or Null if index is invalid
315 HYDRODATA_EXPORT Handle(HYDROData_Entity) Reference(const int theIndex) const;
318 * Updates reference by index. If index is one-bigger than \a NbReferences,
319 * this method appends it to the end (NbReferences is incremented).
320 * \param theIndex number of reference [0; NbReference]
321 * \param theReferenced the object referenced by this
323 HYDRODATA_EXPORT void ChangeReference(
324 const int theIndex, Handle(HYDROData_Entity) theReferenced);
327 * Removes reference by index
328 * \param theIndex number of reference [0; NbReference)
330 HYDRODATA_EXPORT void RemoveReference(const int theIndex);
333 * Removes all references.
335 HYDRODATA_EXPORT void ClearReferences();
339 * Stores the operator name
340 * \param theOpName name of the operator that must be executed for image update
342 HYDRODATA_EXPORT void SetOperatorName(const QString theOpName);
345 * Returns the operator name
346 * \returns the name of the operator that must be executed for image update
348 HYDRODATA_EXPORT QString OperatorName() const;
351 * Stores the operator arguments
352 * \param theArgs array that stores the operator arguments, needed for execution
354 HYDRODATA_EXPORT void SetArgs(const QByteArray& theArgs);
357 * Returns the operator arguments
358 * \returns array that stores the operator arguments, needed for execution
360 HYDRODATA_EXPORT QByteArray Args() const;
364 * Marks the image as self-split.
365 * \param theFlag is true for self-plit image
367 HYDRODATA_EXPORT void SetIsSelfSplit(bool theFlag);
370 * Checks that the image is self-split.
371 * \returns true if image is self-split
373 HYDRODATA_EXPORT bool IsSelfSplit() const;
377 QPointF generateThirdPoint( const QPointF& thePointA,
378 const QPointF& thePointB,
379 const bool& theIsLocal ) const;
383 friend class HYDROData_Iterator;
386 * Creates new object in the internal data structure. Use higher level objects
387 * to create objects with real content.
389 HYDRODATA_EXPORT HYDROData_Image();
392 * Destructs properties of the object and object itself, removes it from the document.
394 HYDRODATA_EXPORT ~HYDROData_Image();