Salome HOME
382cd817c4853c8c78277d8c327dfeaae682f194
[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 protected:
21   /**
22    * Enumeration of tags corresponding to the persistent object parameters.
23    */
24   enum DataTag
25   {
26     DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve
27     DataTag_Operator,    ///< name of the operator that must be executed for image update
28     DataTag_TrsfMode,    ///< transformation mode (0 - Lambert93, 1 - Cartesian)
29     DataTag_TrsfPoints,  ///< image transformation points (3 input + 3 output lambert + 3 output cartesian)
30     DataTag_FilePath     ///< image imported file path
31   };
32
33 public:
34   DEFINE_STANDARD_RTTI(HYDROData_Image);
35
36   /**
37    * Returns the kind of this object. Must be redefined in all objects of known type.
38    */
39   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_IMAGE;}
40
41   /**
42    * Dump Image object to Python script representation.
43    */
44   HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
45
46   /**
47    * Updates object state.
48    * Reimplemented to update an Image object in the data structure.
49    * Call this method whenever you made changes for operator or reference objects.
50    * If it is changed, sets "MustBeUpdated" flag to other depended images.
51    * \param theIsForce force reupdating of data object
52    */
53   HYDRODATA_EXPORT virtual void Update( const bool theIsForce = true );
54
55   /**
56    * Returns data of object wrapped to QVariant.
57    * Reimplemented to wrap and return saved image.
58    * Transformation are applied to result image.
59    */
60   HYDRODATA_EXPORT virtual QVariant GetDataVariant();
61
62   /**
63    * Stores the image
64    * \param theImage new image
65    */
66   HYDRODATA_EXPORT void SetImage(const QImage& theImage);
67
68   /**
69    * Load the image from file
70    * \param theFilePath path to image
71    */
72   HYDRODATA_EXPORT bool LoadImage(const QString& theFilePath);
73
74   /**
75    * Returns the kept image
76    */
77   HYDRODATA_EXPORT QImage Image();
78
79   /**
80    * Stores the image file path
81    * \param theFilePath image file path
82    */
83   HYDRODATA_EXPORT void SetFilePath(const QString& theFilePath);
84
85   /**
86    * Returns uploaded image file path
87    */
88   HYDRODATA_EXPORT QString GetFilePath() const;
89
90   /**
91    * Stores the image transformation
92    * \param theTrsf new transformation
93    */
94   HYDRODATA_EXPORT void SetTrsf(const QTransform& theTrsf);
95
96   /**
97    * Returns the kept transformation, or "identity" if not yet stored
98    */
99   HYDRODATA_EXPORT QTransform Trsf() const;
100
101   /**
102    * Stores the image transformation points (3 input + 3 output)
103    * \param thePointA input point A
104    * \param thePointB input point B
105    * \param thePointC input point C
106    * \param theLambertPointA output point A in Lambert93 coordinates
107    * \param theLambertPointB output point B in Lambert93 coordinates
108    * \param theLambertPointC output point C in Lambert93 coordinates
109    * \param theCartesianPointA output point A in Cartesian coordinates
110    * \param theCartesianPointB output point B in Cartesian coordinates
111    * \param theCartesianPointC output point C in Cartesian coordinates
112    */
113   HYDRODATA_EXPORT void SetTrsfPoints(const QPoint& thePointA,
114                                       const QPoint& thePointB,
115                                       const QPoint& thePointC,
116                                       const QPointF& theLambertPointA,
117                                       const QPointF& theLambertPointB,
118                                       const QPointF& theLambertPointC,
119                                       const QPointF& theCartesianPointA,
120                                       const QPointF& theCartesianPointB,
121                                       const QPointF& theCartesianPointC);
122
123   /**
124    * Returns the image transformation points (3 input + 3 output)
125    * \param thePointA input point A
126    * \param thePointB input point B
127    * \param thePointC input point C
128    * \param theLambertPointA output point A in Lambert93 coordinates
129    * \param theLambertPointB output point B in Lambert93 coordinates
130    * \param theLambertPointC output point C in Lambert93 coordinates
131    * \param theCartesianPointA output point A in Cartesian coordinates
132    * \param theCartesianPointB output point B in Cartesian coordinates
133    * \param theCartesianPointC output point C in Cartesian coordinates
134    */
135   HYDRODATA_EXPORT void TrsfPoints(QPoint& thePointA,
136                                    QPoint& thePointB,
137                                    QPoint& thePointC,
138                                    QPointF& theLambertPointA,
139                                    QPointF& theLambertPointB,
140                                    QPointF& theLambertPointC,
141                                    QPointF& theCartesianPointA,
142                                    QPointF& theCartesianPointB,
143                                    QPointF& theCartesianPointC) const;
144
145   /**
146    * Returns true if the image has stored transformation points
147    */
148   HYDRODATA_EXPORT bool HasTrsfPoints() const;
149
150   /**
151    * Stores the transformation mode (0 - Lambert93, 1 - Cartesian)
152    */
153   HYDRODATA_EXPORT void SetTrsfMode(const int theMode);
154
155   /**
156    * Returns the transformation mode (0 - Lambert93, 1 - Cartesian)
157    */
158   HYDRODATA_EXPORT int TrsfMode() const;
159
160   /**
161    * Returns the number of referenced objects
162    * \return zero if there is no references
163    */
164   HYDRODATA_EXPORT int NbReferences() const;
165
166   /**
167    * Appends reference to other object (image or polyline).
168    * \param theReferenced the object referenced by this
169    */
170   HYDRODATA_EXPORT void AppendReference( const Handle(HYDROData_Entity)& theReferenced );
171
172   /**
173    * Returns reference by index.
174    * \param theIndex number of reference [0; NbReference)
175    * \returns the referenced object, or Null if index is invalid
176    */
177   HYDRODATA_EXPORT Handle(HYDROData_Entity) Reference(const int theIndex) const;
178
179   /**
180    * Updates reference by index. If index is one-bigger than \a NbReferences, 
181    * this method appends it to the end (NbReferences is incremented).
182    * \param theIndex number of reference [0; NbReference]
183    * \param theReferenced the object referenced by this
184    */
185   HYDRODATA_EXPORT void ChangeReference(
186     const int theIndex, Handle(HYDROData_Entity) theReferenced);
187
188   /**
189    * Removes reference by index
190    * \param theIndex number of reference [0; NbReference)
191    */
192   HYDRODATA_EXPORT void RemoveReference(const int theIndex);
193
194   /**
195    * Removes all references.
196    */
197   HYDRODATA_EXPORT void ClearReferences();
198
199   /**
200    * Stores the operator name
201    * \param theOpName name of the operator that must be executed for image update
202    */
203   HYDRODATA_EXPORT void SetOperatorName(const QString theOpName);
204
205   /**
206    * Returns the operator name
207    * \returns the name of the operator that must be executed for image update
208    */
209   HYDRODATA_EXPORT QString OperatorName() const;
210
211   /**
212    * Stores the operator arguments
213    * \param theArgs array that stores the operator arguments, needed for execution
214    */
215   HYDRODATA_EXPORT void SetArgs(const QByteArray& theArgs);
216
217   /**
218    * Returns the operator arguments
219    * \returns array that stores the operator arguments, needed for execution
220    */
221   HYDRODATA_EXPORT QByteArray Args() const;
222   
223   /**
224    * Sets the "MustBeUpdated" flag: if image is depended on updated features.
225    * \param theFlag is true for images that must be updated, false for up-to-date
226    */
227   HYDRODATA_EXPORT void MustBeUpdated(bool theFlag);
228
229   /**
230    * Returns the "MustBeUpdated" flag: is image must be recomputed or not
231    * \returns false if image is up to date
232    */
233   HYDRODATA_EXPORT bool MustBeUpdated() const;
234
235   /**
236    * Marks the image as self-splitted.
237    * \param theFlag is true for self-splitted image
238    */
239   HYDRODATA_EXPORT void SetIsSelfSplitted(bool theFlag);
240
241   /**
242    * Checks that the image is self-splitted.
243    * \returns true if image is self-splitted
244    */
245   HYDRODATA_EXPORT bool IsSelfSplitted() const;
246
247 protected:
248
249   friend class HYDROData_Iterator;
250
251   /**
252    * Creates new object in the internal data structure. Use higher level objects 
253    * to create objects with real content.
254    */
255   HYDROData_Image();
256
257   /**
258    * Destructs properties of the object and object itself, removes it from the document.
259    */
260   ~HYDROData_Image();
261
262 };
263
264 #endif