From: ouv Date: Tue, 6 Aug 2013 12:52:21 +0000 (+0000) Subject: Fuse and Cut operations. X-Git-Tag: BR_hydro_v_0_1~130 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3769dbcedaa689e15ad79a619acd6f8bc21f47c6;p=modules%2Fhydro.git Fuse and Cut operations. --- diff --git a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx index fbfe8d5f..bcc97ca1 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx @@ -37,9 +37,6 @@ #include #include -#include -#include - HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule ) : HYDROGUI_Operation( theModule ), myActiveViewManager( 0 ), @@ -72,19 +69,14 @@ HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const return aPanel; } -void HYDROGUI_ImportImageOp::onApply() +bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags ) { HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel(); HYDROGUI_ImportImageDlg::TransformationDataMap aMap; bool anIsOk = aPanel->getTransformationDataMap( aMap ); if( !anIsOk || !myPreviewPrs ) - { - SUIT_MessageBox::critical( module()->getApp()->desktop(), - tr( "INSUFFICIENT_INPUT_DATA" ), - tr( "INPUT_VALID_DATA" ) ); - return; - } + return false; double xa1 = aMap[ HYDROGUI_PrsImage::PointA ].first.x(); double ya1 = aMap[ HYDROGUI_PrsImage::PointA ].first.y(); @@ -111,28 +103,27 @@ void HYDROGUI_ImportImageOp::onApply() int aStudyId = module()->getStudyId(); Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId ); - if( !aDocument.IsNull() ) - { - Handle(HYDROData_Image) anImageObj = - Handle(HYDROData_Image)::DownCast( aDocument->CreateObject( KIND_IMAGE ) ); - if( !anImageObj.IsNull() ) - { - static int ImageId = 0; - anImageObj->SetName( QString( "Image_%1" ).arg( QString::number( ++ImageId ) ) ); + if( aDocument.IsNull() ) + return false; - anImageObj->SetImage( anImage ); - anImageObj->SetTrsf( aTransform ); + Handle(HYDROData_Image) anImageObj = + Handle(HYDROData_Image)::DownCast( aDocument->CreateObject( KIND_IMAGE ) ); + if( anImageObj.IsNull() ) + return false; - module()->update( UF_Model | UF_Viewer ); - } - } - HYDROGUI_Operation::onApply(); + static int ImageId = 0; + anImageObj->SetName( QString( "Image_%1" ).arg( QString::number( ++ImageId ) ) ); + + anImageObj->SetImage( anImage ); + anImageObj->SetTrsf( aTransform ); + + theUpdateFlags = UF_Model | UF_Viewer; + return true; } -void HYDROGUI_ImportImageOp::onCancel() +void HYDROGUI_ImportImageOp::processCancel() { closePreview(); - HYDROGUI_Operation::onCancel(); } void HYDROGUI_ImportImageOp::onCreatePreview( QString theFileName ) diff --git a/src/HYDROGUI/HYDROGUI_ImportImageOp.h b/src/HYDROGUI/HYDROGUI_ImportImageOp.h index 3e6964eb..04a0f704 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageOp.h +++ b/src/HYDROGUI/HYDROGUI_ImportImageOp.h @@ -44,10 +44,10 @@ protected: virtual HYDROGUI_InputPanel* createInputPanel() const; -protected slots: - virtual void onApply(); - virtual void onCancel(); + virtual bool processApply( int& theUpdateFlags ); + virtual void processCancel(); +protected slots: void onCreatePreview( QString ); void onActivatePointSelection( int ); void onPointSelected(); diff --git a/src/HYDROGUI/HYDROGUI_ObjSelector.cxx b/src/HYDROGUI/HYDROGUI_ObjSelector.cxx index bbcc599b..f087c09d 100644 --- a/src/HYDROGUI/HYDROGUI_ObjSelector.cxx +++ b/src/HYDROGUI/HYDROGUI_ObjSelector.cxx @@ -21,10 +21,14 @@ // #include "HYDROGUI_ObjSelector.h" + +#include "HYDROGUI_DataModel.h" #include "HYDROGUI_Module.h" #include + #include +#include #include #include @@ -79,7 +83,6 @@ void HYDROGUI_ObjSelector::OnToggled( bool isChecked ) void HYDROGUI_ObjSelector::OnSelectionChanged() { - /* ouv: to do if( !myBtn->isChecked() ) return; @@ -87,18 +90,24 @@ void HYDROGUI_ObjSelector::OnSelectionChanged() SUIT_DataOwnerPtrList anOwners; aSelMgr->selected( anOwners ); + HYDROGUI_DataModel* aModel = myModule->getDataModel(); + QString anObjName; foreach( SUIT_DataOwner* anOwner, anOwners ) { - LightApp_GVDataOwner* aGrDOwner = dynamic_cast( anOwner ); + LightApp_DataOwner* aGrDOwner = dynamic_cast( anOwner ); if( aGrDOwner ) { - anObjName = aGrDOwner->object()->getName(); - break; + QString anEntry = aGrDOwner->entry(); + Handle(HYDROData_Object) anObject = aModel->objectByEntry( anEntry, KIND_IMAGE ); + if( !anObject.IsNull() ) + { + anObjName = anObject->GetName(); + break; + } } } myObjName->setText( anObjName ); - */ } QString HYDROGUI_ObjSelector::GetName() const diff --git a/src/HYDROGUI/HYDROGUI_Operation.cxx b/src/HYDROGUI/HYDROGUI_Operation.cxx index 5b1a90e9..35705791 100644 --- a/src/HYDROGUI/HYDROGUI_Operation.cxx +++ b/src/HYDROGUI/HYDROGUI_Operation.cxx @@ -33,6 +33,7 @@ #include #include +#include #include HYDROGUI_Operation::HYDROGUI_Operation( HYDROGUI_Module* theModule ) @@ -56,6 +57,17 @@ const QString& HYDROGUI_Operation::getName() const return myName; } +HYDROGUI_InputPanel* HYDROGUI_Operation::inputPanel() const +{ + if( !myPanel ) + { + ( ( HYDROGUI_Operation* )this )->myPanel = createInputPanel(); + connect( myPanel, SIGNAL( panelApply() ), this, SLOT( onApply() ) ); + connect( myPanel, SIGNAL( panelCancel() ), this, SLOT( onCancel() ) ); + } + return myPanel; +} + SUIT_SelectionMgr* HYDROGUI_Operation::selectionMgr() const { return myModule->getApp()->selectionMgr(); @@ -99,31 +111,19 @@ void HYDROGUI_Operation::commitOperation() inputPanel()->hide(); } -HYDROGUI_InputPanel* HYDROGUI_Operation::inputPanel() const -{ - if( !myPanel ) - { - ( ( HYDROGUI_Operation* )this )->myPanel = createInputPanel(); - connect( myPanel, SIGNAL( panelApply() ), this, SLOT( onApply() ) ); - connect( myPanel, SIGNAL( panelCancel() ), this, SLOT( onCancel() ) ); - } - return myPanel; -} - -Handle_HYDROData_Document HYDROGUI_Operation::doc() const +bool HYDROGUI_Operation::processApply( int& theUpdateFlags ) { - int aStudyId = myModule->application()->activeStudy()->id(); - return HYDROData_Document::Document( aStudyId ); + return false; } -void HYDROGUI_Operation::onApply() +void HYDROGUI_Operation::processCancel() { - commit(); } -void HYDROGUI_Operation::onCancel() +Handle_HYDROData_Document HYDROGUI_Operation::doc() const { - abort(); + int aStudyId = myModule->application()->activeStudy()->id(); + return HYDROData_Document::Document( aStudyId ); } Handle_HYDROData_Object HYDROGUI_Operation::FindObjectByName( const QString& theName, int theKind ) const @@ -136,3 +136,25 @@ Handle_HYDROData_Object HYDROGUI_Operation::FindObjectByName( const QString& the } return Handle_HYDROData_Object(); } + +void HYDROGUI_Operation::onApply() +{ + int anUpdateFlags = 0; + if( processApply( anUpdateFlags ) ) + { + module()->update( anUpdateFlags ); + commit(); + } + else + { + SUIT_MessageBox::critical( module()->getApp()->desktop(), + tr( "INSUFFICIENT_INPUT_DATA" ), + tr( "INPUT_VALID_DATA" ) ); + } +} + +void HYDROGUI_Operation::onCancel() +{ + processCancel(); + abort(); +} diff --git a/src/HYDROGUI/HYDROGUI_Operation.h b/src/HYDROGUI/HYDROGUI_Operation.h index 2f983751..dd7bcaee 100644 --- a/src/HYDROGUI/HYDROGUI_Operation.h +++ b/src/HYDROGUI/HYDROGUI_Operation.h @@ -53,6 +53,9 @@ protected: virtual HYDROGUI_InputPanel* createInputPanel() const = 0; + virtual bool processApply( int& theUpdateFlags ); + virtual void processCancel(); + Handle_HYDROData_Document doc() const; Handle_HYDROData_Object FindObjectByName( const QString& theName, int theKind ) const; diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx index bca023a3..82fc2b7f 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx @@ -60,6 +60,11 @@ HYDROGUI_TwoImagesDlg::~HYDROGUI_TwoImagesDlg() { } +QString HYDROGUI_TwoImagesDlg::GetName() const +{ + return myName->text(); +} + void HYDROGUI_TwoImagesDlg::GetSelectedImages( QString& theName1, QString& theName2 ) const { theName1 = myImage1->GetName(); diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h index faa0c06b..441a0ad6 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h +++ b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h @@ -33,10 +33,13 @@ class HYDROGUI_ObjSelector; class HYDROGUI_TwoImagesDlg : public HYDROGUI_InputPanel { + Q_OBJECT + public: HYDROGUI_TwoImagesDlg( HYDROGUI_Module* theModule, const QString& theTitle ); virtual ~HYDROGUI_TwoImagesDlg(); + QString GetName() const; void GetSelectedImages( QString& theEntry1, QString& theEntry2 ) const; private: diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx index f91ca6cb..748da501 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx @@ -22,13 +22,18 @@ #include "HYDROGUI_TwoImagesOp.h" +#include "HYDROGUI_Module.h" #include "HYDROGUI_TwoImagesDlg.h" +#include "HYDROGUI_UpdateFlags.h" #include #include #include +#include +#include + HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const int theType ) : HYDROGUI_Operation( theModule ), myType( theType ) @@ -38,6 +43,7 @@ HYDROGUI_TwoImagesOp::HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const in { case Fuse: aName = tr( "FUSE" ); break; case Cut: aName = tr( "CUT" ); break; + default: break; } setName( aName ); } @@ -51,22 +57,46 @@ HYDROGUI_InputPanel* HYDROGUI_TwoImagesOp::createInputPanel() const return new HYDROGUI_TwoImagesDlg( module(), getName() ); } -void HYDROGUI_TwoImagesOp::onApply() +bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags ) { HYDROGUI_TwoImagesDlg* aPanel = dynamic_cast( inputPanel() ); + + QString aNewName = aPanel->GetName(); + QString aName1, aName2; aPanel->GetSelectedImages( aName1, aName2 ); - Handle_HYDROData_Image anImage1 = Handle_HYDROData_Image::DownCast( + if( aNewName.isEmpty() || aName1.isEmpty() || aName2.isEmpty() ) + return false; + + Handle(HYDROData_Image) anImage1 = Handle(HYDROData_Image)::DownCast( FindObjectByName( aName1, KIND_IMAGE ) ); - Handle_HYDROData_Image anImage2 = Handle_HYDROData_Image::DownCast( + Handle(HYDROData_Image) anImage2 = Handle(HYDROData_Image)::DownCast( FindObjectByName( aName2, KIND_IMAGE ) ); + if( anImage1.IsNull() || anImage2.IsNull() ) + return false; HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory(); - ImageComposer_Operator* anOperator = 0; //TODO + 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; Handle(HYDROData_Image) aResult = aFactory->CreateImage( doc(), anOperator ); + if( aResult.IsNull() ) + return false; + + aResult->SetName( aNewName ); aResult->AppendReference( anImage1 ); aResult->AppendReference( anImage2 ); aFactory->UpdateImage( doc(), aResult ); + + theUpdateFlags = UF_Model | UF_Viewer; + return true; } diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesOp.h b/src/HYDROGUI/HYDROGUI_TwoImagesOp.h index 2fc1e0cc..8940d854 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesOp.h +++ b/src/HYDROGUI/HYDROGUI_TwoImagesOp.h @@ -39,8 +39,7 @@ public: protected: virtual HYDROGUI_InputPanel* createInputPanel() const; -protected slots: - virtual void onApply(); + virtual bool processApply( int& theUpdateFlags ); private: int myType; diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 0e20be6e..5ef51a55 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -154,6 +154,33 @@ Undo + + HYDROGUI_TwoImagesDlg + + BACKGROUND + Background + + + COLOR + Color + + + IMAGE_1 + Image 1 + + + IMAGE_2 + Image 2 + + + NAME + Name + + + TRANSPARENT + Transparent + + HYDROGUI_TwoImagesOp