+QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
+{
+ QStringList aResList;
+
+ Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+ if ( aDocument.IsNull() )
+ return aResList;
+
+ QString aDocName = aDocument->GetDocPyName();
+ QString anImageName = GetName();
+
+ aResList << QString( "%1 = %2.CreateObject( %3 );" )
+ .arg( anImageName ).arg( aDocName ).arg( PYTHON_IMAGE_ID );
+ aResList << QString( "%1.SetName( \"%2\" );" )
+ .arg( anImageName ).arg( anImageName );
+
+ QString aFilePath = GetFilePath();
+ if ( !aFilePath.isEmpty() )
+ {
+ aResList << QString( "" );
+ aResList << QString( "%1.LoadImage( \"%2\" );" )
+ .arg( anImageName ).arg( aFilePath );
+ aResList << QString( "" );
+
+ // Dump transformation points for image
+
+ QString aGap = QString().fill( ' ', anImageName.size() + 16 );
+
+ bool anIsByTwoPoints = IsByTwoPoints();
+
+ QPoint aLocalPointA, aLocalPointB, aLocalPointC;
+ if ( GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC ) )
+ {
+ aResList << QString( "%1.SetLocalPoints( QPoint( %2, %3 )," )
+ .arg( anImageName ).arg( aLocalPointA.x() ).arg( aLocalPointA.y() );
+ aResList << QString( aGap + "QPoint( %1, %2 )," )
+ .arg( aLocalPointB.x() ).arg( aLocalPointB.y() );
+ aResList << QString( aGap + "QPoint( %1, %2 ) );" )
+ .arg( aLocalPointC.x() ).arg( aLocalPointC.y() );
+ aResList << QString( "" );
+ }
+
+ HYDROData_Image::TransformationMode aTransformationMode;
+ QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
+ if ( GetGlobalPoints( aTransformationMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
+ {
+ aResList << QString( "%1.SetGlobalPoints( %2," )
+ .arg( anImageName ).arg( aTransformationMode );
+ aResList << QString( aGap + "QPointF( %1, %2 )," )
+ .arg( aTrsfPointA.x() ).arg( aTrsfPointA.y() );
+ aResList << QString( aGap + "QPointF( %1, %2 )," )
+ .arg( aTrsfPointB.x() ).arg( aTrsfPointB.y() );
+ aResList << QString( aGap + "QPointF( %1, %2 ) );" )
+ .arg( aTrsfPointC.x() ).arg( aTrsfPointC.y() );
+
+ if ( aTransformationMode == ReferenceImage )
+ {
+ Handle(HYDROData_Image) aRefImg = GetTrsfReferenceImage();
+ setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "SetTrsfReferenceImage" );
+ }
+ }
+ }
+ else
+ {
+ // Image is composed from other image(s)
+
+ QString anOperatorName = OperatorName();
+ if ( !anOperatorName.isEmpty() )
+ {
+ aResList << QString( "" );
+
+ aResList << QString( "%1.SetOperatorName( \"%2\" );" )
+ .arg( anImageName ).arg( anOperatorName );
+
+ ImageComposer_Operator* anImageOp =
+ HYDROData_OperationsFactory::Factory()->Operator( OperatorName() );
+ if ( anImageOp )
+ {
+ // Dump operation arguments
+ QString anOpArgsArrayName;
+ QStringList anOpArgs = anImageOp->dumpArgsToPython( anOpArgsArrayName );
+ if ( !anOpArgs.isEmpty() )
+ {
+ aResList << QString( "" );
+ aResList << anOpArgs;
+
+ aResList << QString( "" );
+ aResList << QString( "%1.SetArgs( %2 );" )
+ .arg( anImageName ).arg( anOpArgsArrayName );
+ }
+ }
+ }
+
+ int aNbReferences = NbReferences();
+ if ( aNbReferences > 0 )
+ {
+ aResList << QString( "" );
+
+ for ( int i = 0; i < aNbReferences; ++i )
+ {
+ Handle(HYDROData_Image) aRefImg = Handle(HYDROData_Image)::DownCast( Reference( i ) );
+ setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "AppendReference" );
+ }
+ }
+
+ // Necessary to update image in case of composed operator
+ aResList << QString( "" );
+ aResList << QString( "%1.Update();" ).arg( anImageName );
+ }
+
+ return aResList;
+}
+
+void HYDROData_Image::Update()
+{
+ HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory();
+
+ ImageComposer_Operator* anOp = aFactory->Operator( OperatorName() );
+ if ( anOp ) // Update image if there is an operation
+ {
+ // Fill by arguments and process the operation
+ QVariant anObj1, anObj2;
+ int aNbReferences = NbReferences();
+
+ if ( aNbReferences > 0 )
+ {
+ // First referenced object
+ Handle(HYDROData_Entity) 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_Entity) aRefObj = Reference( 1 );
+ if ( !aRefObj.IsNull() )
+ anObj2 = aRefObj->GetDataVariant();
+ }
+
+ ImageComposer_Image aResImg = anOp->process( anObj1, anObj2 );
+ SetImage( aResImg );
+ }
+ else // Update image if it positioned relatively to other image
+ {
+ UpdateTrsf();
+ }
+
+ Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+ if ( !aDocument.IsNull() )
+ {
+ // Change the states of this and all depended images
+ SetToUpdate( true );
+ HYDROData_Tool::SetMustBeUpdatedImages( aDocument );
+ SetToUpdate( false );
+ }
+}
+
+QVariant HYDROData_Image::GetDataVariant()
+{
+ QTransform aTransform = Trsf();
+
+ ImageComposer_Image anImage = Image();
+ anImage.setTransform( aTransform );
+
+ QVariant aVarData;
+ aVarData.setValue<ImageComposer_Image>( anImage );
+
+ return aVarData;
+}
+