Salome HOME
Tests for Bathymetry object.
[modules/hydro.git] / src / HYDROData / HYDROData_Image.cxx
index 88650062dc8ee423ba9f017cf6661675e6a386e5..08a069fd756abcdb2ef11a4c6943781354fadb7d 100644 (file)
@@ -1,7 +1,9 @@
-#include <HYDROData_Image.h>
-#include <HYDROData_Iterator.h>
 
-#include <HYDROOperations_Factory.h>
+#include "HYDROData_Image.h"
+
+#include "HYDROData_Iterator.h"
+#include "HYDROOperations_Factory.h"
+#include "HYDROData_Tool.h"
 
 #include <TDataStd_RealArray.hxx>
 #include <TDataStd_ByteArray.hxx>
@@ -13,6 +15,7 @@
 #include <TDF_ListIteratorOfLabelList.hxx>
 
 #include <ImageComposer_Operator.h>
+#include <ImageComposer_MetaTypes.h>
 
 #include <QStringList>
 
@@ -119,6 +122,10 @@ QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObject
                     .arg( anImageName ).arg( aRefImgName );
       }
     }
+
+    // Necessary to update image in case of composed operator
+    aResList << QString( "" );
+    aResList << QString( "%1.Update();" ).arg( anImageName );
   }
 
   // Dump transformation matrix for image
@@ -168,6 +175,69 @@ QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObject
   return aResList;
 }
 
+void HYDROData_Image::Update()
+{
+  HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory();
+
+  // Update image only if there is an operation
+  ImageComposer_Operator* anOp = aFactory->Operator( this );
+  if ( anOp ) 
+  {
+    // Fill by arguments and process the operation
+    QVariant anObj1, anObj2;
+    int aNbReferences = NbReferences();
+
+    if ( aNbReferences > 0 )
+    {
+      // First referenced object
+      Handle(HYDROData_Object) aRefObj = Reference( 0 );
+      if ( !aRefObj.IsNull() )
+      {
+        anObj1 = aRefObj->GetDataVariant();
+        if ( !anObj1.isNull() && anObj1.canConvert<ImageComposer_Image>() )
+        {
+          ImageComposer_Image anImage = anObj1.value<ImageComposer_Image>();
+          QTransform aTransform = anImage.transform();
+          SetTrsf( aTransform );
+        }
+      }
+    }
+
+    if ( aNbReferences > 1 )
+    {
+      // Second referenced object
+      Handle(HYDROData_Object) aRefObj = Reference( 1 );
+      if ( !aRefObj.IsNull() )
+        anObj2 = aRefObj->GetDataVariant();
+    }
+
+    ImageComposer_Image aResImg = anOp->process( anObj1, anObj2 );
+    SetImage( aResImg );
+  }
+
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
+  if ( !aDocument.IsNull() )
+  {
+    // Change the states of this and all depended images
+    MustBeUpdated( true );
+    HYDROData_Tool::SetMustBeUpdatedImages( aDocument );
+    MustBeUpdated( false );
+  }
+}
+
+QVariant HYDROData_Image::GetDataVariant()
+{
+  QTransform aTransform = Trsf();
+
+  ImageComposer_Image anImage = Image();
+  anImage.setTransform( aTransform );
+
+  QVariant aVarData;
+  aVarData.setValue<ImageComposer_Image>( anImage );
+  
+  return aVarData;
+}
+
 void HYDROData_Image::SetImage(const QImage& theImage)
 {
   if (theImage.isNull()) {