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