#include "HYDROGUI_TwoImagesOp.h"
+#include "HYDROGUI_Module.h"
+#include "HYDROGUI_Tool.h"
#include "HYDROGUI_TwoImagesDlg.h"
+#include "HYDROGUI_UpdateFlags.h"
#include <HYDROData_Document.h>
#include <HYDROData_Image.h>
#include <HYDROOperations_Factory.h>
+#include <ImageComposer_CutOperator.h>
+#include <ImageComposer_FuseOperator.h>
+
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 )
{
case Fuse: aName = tr( "FUSE" ); break;
case Cut: aName = tr( "CUT" ); break;
+ default: break;
}
setName( aName );
}
return new HYDROGUI_TwoImagesDlg( module(), getName() );
}
-void HYDROGUI_TwoImagesOp::onApply()
+void HYDROGUI_TwoImagesOp::startOperation()
+{
+ HYDROGUI_Operation::startOperation();
+
+ HYDROGUI_TwoImagesDlg* aPanel = (HYDROGUI_TwoImagesDlg*)inputPanel();
+ aPanel->reset();
+
+ 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,
+ QString& theErrorMsg )
{
HYDROGUI_TwoImagesDlg* aPanel = dynamic_cast<HYDROGUI_TwoImagesDlg*>( inputPanel() );
- QString aName1, aName2;
- aPanel->GetSelectedImages( aName1, aName2 );
- Handle_HYDROData_Image anImage1 = Handle_HYDROData_Image::DownCast(
- FindObjectByName( aName1, KIND_IMAGE ) );
- Handle_HYDROData_Image anImage2 = Handle_HYDROData_Image::DownCast(
- FindObjectByName( aName2, KIND_IMAGE ) );
+ QString anImageName = aPanel->getImageName();
+ if( anImageName.isEmpty() )
+ return false;
+
+ QString aSelectedName1, aSelectedName2;
+ if( !aPanel->getSelectedImages( aSelectedName1, aSelectedName2 ) )
+ return false;
+
+ if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) )
+ {
+ // 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(
+ HYDROGUI_Tool::FindObjectByName( module(), aSelectedName1, KIND_IMAGE ) );
+ Handle(HYDROData_Image) anImage2 = Handle(HYDROData_Image)::DownCast(
+ HYDROGUI_Tool::FindObjectByName( module(), aSelectedName2, KIND_IMAGE ) );
+ if( anImage1.IsNull() || anImage2.IsNull() )
+ return false;
HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory();
- ImageComposer_Operator* anOperator = 0; //TODO
+ Handle(HYDROData_Image) aResult = 0;
+ if( myIsEdit )
+ {
+ 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 );
+ }
- Handle(HYDROData_Image) aResult = aFactory->CreateImage( doc(), anOperator );
+ if( aResult.IsNull() )
+ return false;
+
+ aResult->SetName( anImageName );
aResult->AppendReference( anImage1 );
aResult->AppendReference( anImage2 );
aFactory->UpdateImage( doc(), aResult );
+
+ size_t aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
+ anImage1->SetVisible( aViewId, false );
+ anImage2->SetVisible( aViewId, false );
+ aResult->SetVisible( aViewId, true );
+
+ theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced;
+ return true;
}