Salome HOME
Update flag for calculation case during polyline changing.
[modules/hydro.git] / src / HYDROData / HYDROData_Image.h
index dda1648b3ab7cbdf34f308c852c18357a0a6bd12..90dec9c3210a6cba816ac85c1825ddb53e46b65c 100644 (file)
@@ -1,12 +1,13 @@
+
 #ifndef HYDROData_Image_HeaderFile
 #define HYDROData_Image_HeaderFile
 
-#include <HYDROData_Object.h>
+#include <HYDROData_Entity.h>
 
 #include <QImage>
 #include <QTransform>
 
-DEFINE_STANDARD_HANDLE(HYDROData_Image, HYDROData_Object)
+DEFINE_STANDARD_HANDLE(HYDROData_Image, HYDROData_Entity)
 
 /**\class HYDROData_Image
  * \brief Class that stores/retreives information about the image.
@@ -14,8 +15,32 @@ DEFINE_STANDARD_HANDLE(HYDROData_Image, HYDROData_Object)
  * Keeps image as binary array, transformation and other properties
  * of image with correspondent API for forkind wit hthese properties.
  */
-class HYDROData_Image : public HYDROData_Object
+class HYDROData_Image : public HYDROData_Entity
 {
+
+public:
+
+  enum TransformationMode
+  {
+    ManualGeodesic = 0,
+    ManualCartesian,
+    ReferenceImage
+  };
+
+protected:
+  /**
+   * Enumeration of tags corresponding to the persistent object parameters.
+   */
+  enum DataTag
+  {
+    DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve
+    DataTag_Operator,        ///< name of the operator that must be executed for image update
+    DataTag_TrsfMode,        ///< transformation mode (0 - Lambert93, 1 - Cartesian, 2 - on other Image)
+    DataTag_TrsfPoints,      ///< image transformation points 
+    DataTag_TrsfImage,      ///< reference transformation image
+    DataTag_FilePath         ///< image imported file path
+  };
+
 public:
   DEFINE_STANDARD_RTTI(HYDROData_Image);
 
@@ -24,17 +49,54 @@ public:
    */
   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_IMAGE;}
 
+  /**
+   * Dump Image object to Python script representation.
+   */
+  HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
+
+  /**
+   * Updates object state.
+   * Reimplemented to update an Image object in the data structure.
+   * Call this method whenever you made changes for operator or reference objects.
+   * If it is changed, sets "MustBeUpdated" flag to other depended images.
+   */
+  HYDRODATA_EXPORT virtual void Update();
+
+  /**
+   * Returns data of object wrapped to QVariant.
+   * Reimplemented to wrap and return saved image.
+   * Transformation are applied to result image.
+   */
+  HYDRODATA_EXPORT virtual QVariant GetDataVariant();
+
   /**
    * Stores the image
    * \param theImage new image
    */
   HYDRODATA_EXPORT void SetImage(const QImage& theImage);
 
+  /**
+   * Load the image from file
+   * \param theFilePath path to image
+   */
+  HYDRODATA_EXPORT bool LoadImage(const QString& theFilePath);
+
   /**
    * Returns the kept image
    */
   HYDRODATA_EXPORT QImage Image();
 
+  /**
+   * Stores the image file path
+   * \param theFilePath image file path
+   */
+  HYDRODATA_EXPORT void SetFilePath(const QString& theFilePath);
+
+  /**
+   * Returns uploaded image file path
+   */
+  HYDRODATA_EXPORT QString GetFilePath() const;
+
   /**
    * Stores the image transformation
    * \param theTrsf new transformation
@@ -44,67 +106,179 @@ public:
   /**
    * Returns the kept transformation, or "identity" if not yet stored
    */
-  HYDRODATA_EXPORT QTransform Trsf();
+  HYDRODATA_EXPORT QTransform Trsf() const;
+
+  /**
+   * Updates the matrix of transformation in accordance with reference points.
+   * \param theTrsf new transformation
+   */
+  HYDRODATA_EXPORT void UpdateTrsf();
+
+
+  /**
+   * Returns true if transformation is done by two points only
+   */
+  HYDRODATA_EXPORT bool IsByTwoPoints() const;
+
+
+  /**
+   * Removes all references from this image.
+   */
+  HYDRODATA_EXPORT bool HasReferences() const;
+
+  /**
+   * Removes all references from this image.
+   */
+  HYDRODATA_EXPORT void RemoveAllReferences();
+
+
+  /**
+   * Stores the transformation points in local cs of image
+   * \param thePointA point A
+   * \param thePointB point B
+   * \param thePointC point C
+   */
+  HYDRODATA_EXPORT void SetLocalPoints( const QPoint& thePointA,
+                                        const QPoint& thePointB,
+                                        const QPoint& thePointC = QPoint( INT_MIN, INT_MIN ),
+                                        const bool    theIsUpdate = true );
+
+  /**
+   * Returns the transformation points in local cs of image
+   * \param thePointA point A
+   * \param thePointB point B
+   * \param thePointC point C
+   * \return true if all parameters has been set before
+   */
+  HYDRODATA_EXPORT bool GetLocalPoints( QPoint& thePointA,
+                                        QPoint& thePointB,
+                                        QPoint& thePointC ) const;
+
+  /**
+   * Returns true if local points has been set before
+   */
+  HYDRODATA_EXPORT bool HasLocalPoints() const;
+
+
+  /**
+   * Stores the transformation points in global cs
+   * \param theMode transformation mode
+   * \param thePointA point A
+   * \param thePointB point B
+   * \param thePointC point C
+   */
+  HYDRODATA_EXPORT void SetGlobalPoints( const TransformationMode& theMode,
+                                         const QPointF&            thePointA,
+                                         const QPointF&            thePointB,
+                                         const QPointF&            thePointC = QPoint( INT_MIN, INT_MIN ),
+                                         const bool                theIsUpdate = true  );
+
+  /**
+   * Returns the transformation points in global cs
+   * \param theMode transformation mode
+   * \param thePointA point A
+   * \param thePointB point B
+   * \param thePointC point C
+   * \return true if all parameters has been set before
+   */
+  HYDRODATA_EXPORT bool GetGlobalPoints( TransformationMode& theMode,
+                                         QPointF&            thePointA,
+                                         QPointF&            thePointB,
+                                         QPointF&            thePointC ) const;
+
+  /**
+   * Returns true if global points has been set before
+   */
+  HYDRODATA_EXPORT bool HasGlobalPoints() const;
+
+
+  /**
+   * Stores the transformation points in reference image local cs
+   * \param theRefImage reference image
+   * \param thePointA point A
+   * \param thePointB point B
+   * \param thePointC point C
+   */
+  HYDRODATA_EXPORT void SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
+                                            const QPointF&                 thePointA,
+                                            const QPointF&                 thePointB,
+                                            const QPointF&                 thePointC = QPoint( INT_MIN, INT_MIN ),
+                                            const bool                     theIsUpdate = true );
 
   /**
-   * Stores the image transformation points (3 input + 3 output)
-   * \param thePointAIn input point A
-   * \param thePointBIn input point B
-   * \param thePointCIn input point C
-   * \param thePointAOut output point A
-   * \param thePointBOut output point B
-   * \param thePointCOut output point C
+   * Returns the transformation points in reference image local cs
+   * \param theRefImage reference image
+   * \param thePointA point A
+   * \param thePointB point B
+   * \param thePointC point C
+   * \return true if all parameters has been set correctly
    */
-  HYDRODATA_EXPORT void SetTrsfPoints(const QPoint& thePointAIn,
-                                      const QPoint& thePointBIn,
-                                      const QPoint& thePointCIn,
-                                      const QPointF& thePointAOut,
-                                      const QPointF& thePointBOut,
-                                      const QPointF& thePointCOut);
+  HYDRODATA_EXPORT bool GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
+                                            QPointF&                 thePointA,
+                                            QPointF&                 thePointB,
+                                            QPointF&                 thePointC ) const;
 
   /**
-   * Returns the image transformation points (3 input + 3 output)
-   * \param thePointAIn input point A
-   * \param thePointBIn input point B
-   * \param thePointCIn input point C
-   * \param thePointAOut output point A
-   * \param thePointBOut output point B
-   * \param thePointCOut output point C
+   * Returns true if reference points has been set before
    */
-  HYDRODATA_EXPORT void TrsfPoints(QPoint& thePointAIn,
-                                   QPoint& thePointBIn,
-                                   QPoint& thePointCIn,
-                                   QPointF& thePointAOut,
-                                   QPointF& thePointBOut,
-                                   QPointF& thePointCOut);
+  HYDRODATA_EXPORT bool HasReferencePoints() const;
+
+
+  /**
+   * Stores the reference image for transformation
+   * \param theRefImage reference image
+   */
+  HYDRODATA_EXPORT void SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage );
+
+  /**
+   * Returns the reference image for transformation
+   */
+  HYDRODATA_EXPORT Handle(HYDROData_Image) GetTrsfReferenceImage() const;
+
+  /**
+   * Removes the reference image for transformation
+   */
+  HYDRODATA_EXPORT void RemoveTrsfReferenceImage();
+
 
   /**
-   * Appends reference to other image.
-   * \param theReferenced the image referenced by this
+   * Stores the transformation mode
    */
-  HYDRODATA_EXPORT void AppendReference(Handle(HYDROData_Image) theReferenced);
+  HYDRODATA_EXPORT void SetTrsfMode( const TransformationMode& theMode );
 
   /**
-   * Returns the number of referenced images
+   * Returns the transformation mode
+   */
+  HYDRODATA_EXPORT TransformationMode GetTrsfMode() const;
+
+
+  /**
+   * Returns the number of referenced objects
    * \return zero if there is no references
    */
-  HYDRODATA_EXPORT int NbReferences();
+  HYDRODATA_EXPORT int NbReferences() const;
+
+  /**
+   * Appends reference to other object (image or polyline).
+   * \param theReferenced the object referenced by this
+   */
+  HYDRODATA_EXPORT void AppendReference( const Handle(HYDROData_Entity)& theReferenced );
 
   /**
    * Returns reference by index.
    * \param theIndex number of reference [0; NbReference)
-   * \returns the referenced image, or Null if index is invalid
+   * \returns the referenced object, or Null if index is invalid
    */
-  HYDRODATA_EXPORT Handle(HYDROData_Image) Reference(const int theIndex) const;
+  HYDRODATA_EXPORT Handle(HYDROData_Entity) Reference(const int theIndex) const;
 
   /**
    * Updates reference by index. If index is one-bigger than \a NbReferences, 
    * this method appends it to the end (NbReferences is incremented).
    * \param theIndex number of reference [0; NbReference]
-   * \param theReferenced the image referenced by this
+   * \param theReferenced the object referenced by this
    */
   HYDRODATA_EXPORT void ChangeReference(
-    const int theIndex, Handle(HYDROData_Image) theReferenced);
+    const int theIndex, Handle(HYDROData_Entity) theReferenced);
 
   /**
    * Removes reference by index
@@ -117,6 +291,7 @@ public:
    */
   HYDRODATA_EXPORT void ClearReferences();
 
+
   /**
    * Stores the operator name
    * \param theOpName name of the operator that must be executed for image update
@@ -127,7 +302,7 @@ public:
    * Returns the operator name
    * \returns the name of the operator that must be executed for image update
    */
-  HYDRODATA_EXPORT QString OperatorName();
+  HYDRODATA_EXPORT QString OperatorName() const;
 
   /**
    * Stores the operator arguments
@@ -139,19 +314,26 @@ public:
    * Returns the operator arguments
    * \returns array that stores the operator arguments, needed for execution
    */
-  HYDRODATA_EXPORT QByteArray Args();
+  HYDRODATA_EXPORT QByteArray Args() const;
   
+
   /**
-   * Sets the "MustBeUpdated" flag: if image is depended on updated features.
-   * \param theFlag is true for images that must be updated, false for up-to-date
+   * Marks the image as self-splitted.
+   * \param theFlag is true for self-splitted image
    */
-  HYDRODATA_EXPORT void MustBeUpdated(bool theFlag);
+  HYDRODATA_EXPORT void SetIsSelfSplitted(bool theFlag);
 
   /**
-   * Returns the "MustBeUpdated" flag: is image must be recomputed or not
-   * \returns false if image is up to date
+   * Checks that the image is self-splitted.
+   * \returns true if image is self-splitted
    */
-  HYDRODATA_EXPORT bool MustBeUpdated();
+  HYDRODATA_EXPORT bool IsSelfSplitted() const;
+
+private:
+
+  QPointF generateThirdPoint( const QPointF& thePointA,
+                              const QPointF& thePointB,
+                              const bool&    theIsLocal ) const;
 
 protected: