HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const int theType )
: HYDROGUI_Operation( theModule ),
- myType( theType )
+ myType( theType ),
+ myIsEdit( false ),
+ myEditedObject( 0 )
{
+ if( myType == Edit )
+ {
+ myIsEdit = true;
+ myEditedObject = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+ if( !myEditedObject.IsNull() )
+ {
+ if( HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory() )
+ {
+ if( ImageComposer_Operator* anOperator = aFactory->Operator( myEditedObject ) )
+ {
+ if( dynamic_cast<ImageComposer_FuseOperator*>( anOperator ) )
+ myType = Fuse;
+ else if( dynamic_cast<ImageComposer_CutOperator*>( anOperator ) )
+ myType = Cut;
+ }
+ }
+ }
+ }
+
QString aName;
switch( myType )
{
HYDROGUI_TwoImagesDlg* aPanel = (HYDROGUI_TwoImagesDlg*)inputPanel();
aPanel->reset();
- QString anImageName = HYDROGUI_Tool::GenerateObjectName( module(), getName() );
+ QString anImageName;
+ if( myIsEdit )
+ {
+ if( !myEditedObject.IsNull() )
+ anImageName = myEditedObject->GetName();
+ }
+ else
+ anImageName = HYDROGUI_Tool::GenerateObjectName( module(), getName() );
aPanel->setImageName( anImageName );
+
+ QString aSelectedName1, aSelectedName2;
+ if( myIsEdit && !myEditedObject.IsNull() )
+ {
+ if( myEditedObject->NbReferences() > 0 )
+ {
+ Handle(HYDROData_Image) anImage1 = myEditedObject->Reference( 0 );
+ if( !anImage1.IsNull() )
+ aSelectedName1 = anImage1->GetName();
+ }
+ if( myEditedObject->NbReferences() > 1 )
+ {
+ Handle(HYDROData_Image) anImage2 = myEditedObject->Reference( 1 );
+ if( !anImage2.IsNull() )
+ aSelectedName2 = anImage2->GetName();
+ }
+ aPanel->setSelectedImages( aSelectedName1, aSelectedName2 );
+ }
}
bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags,
if( !aPanel->getSelectedImages( aSelectedName1, aSelectedName2 ) )
return false;
- // check that there are no other objects with the same name in the document
- Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName );
- if( !anObject.IsNull() )
+ if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) )
{
- theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName );
- return false;
+ // check that there are no other objects with the same name in the document
+ Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName );
+ if( !anObject.IsNull() )
+ {
+ theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName );
+ return false;
+ }
}
Handle(HYDROData_Image) anImage1 = Handle(HYDROData_Image)::DownCast(
return false;
HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory();
- ImageComposer_Operator* anOperator = 0;
- switch( myType )
+ Handle(HYDROData_Image) aResult = 0;
+ if( myIsEdit )
{
- case Fuse: anOperator = new ImageComposer_FuseOperator(); break;
- case Cut: anOperator = new ImageComposer_CutOperator(); break;
- default: break;
+ aResult = myEditedObject;
+ aResult->ClearReferences();
+ }
+ else
+ {
+ ImageComposer_Operator* anOperator = 0;
+ switch( myType )
+ {
+ case Fuse: anOperator = new ImageComposer_FuseOperator(); break;
+ case Cut: anOperator = new ImageComposer_CutOperator(); break;
+ default: break;
+ }
+
+ if( !anOperator )
+ return false;
+
+ aResult = aFactory->CreateImage( doc(), anOperator );
}
- if( !anOperator )
- return false;
-
- Handle(HYDROData_Image) aResult = aFactory->CreateImage( doc(), anOperator );
if( aResult.IsNull() )
return false;
aResult->AppendReference( anImage2 );
aFactory->UpdateImage( doc(), aResult );
- int aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
+ size_t aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
anImage1->SetVisible( aViewId, false );
anImage2->SetVisible( aViewId, false );
aResult->SetVisible( aViewId, true );
- theUpdateFlags = UF_Model | UF_Viewer;
+ theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced;
return true;
}