From: ouv Date: Wed, 28 Aug 2013 08:09:32 +0000 (+0000) Subject: Edit composite images. X-Git-Tag: BR_hydro_v_0_1~99 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0d25f237574f54902a8d972ebc613301acfe3e43;p=modules%2Fhydro.git Edit composite images. --- diff --git a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx index 2b76bdb3..c31e5084 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx @@ -46,7 +46,7 @@ HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule, myPreviewPrs( 0 ), myPointType( HYDROGUI_PrsImage::None ) { - setName( theIsEdit ? tr( "EDIT_IMAGE" ) : tr( "IMPORT_IMAGE" ) ); + setName( theIsEdit ? tr( "EDIT_IMPORTED_IMAGE" ) : tr( "IMPORT_IMAGE" ) ); } HYDROGUI_ImportImageOp::~HYDROGUI_ImportImageOp() diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 7d2197a1..c355b2df 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -33,6 +33,8 @@ #include "HYDROGUI_Tool.h" #include "HYDROGUI_UpdateFlags.h" +#include + #include #include #include @@ -146,6 +148,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, bool anIsHiddenInSelection = false; bool anIsImage = false; + bool anIsCompositeImage = false; bool anIsPolyline = false; bool anIsVisualState = false; @@ -162,7 +165,12 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, anIsHiddenInSelection |= !aVisibility; if( anObject->GetKind() == KIND_IMAGE ) + { anIsImage = true; + Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject ); + if( !anImage.IsNull() ) + anIsCompositeImage = anImage->NbReferences() > 0; + } else if( anObject->GetKind() == KIND_POLYLINE ) anIsPolyline = true; else if( anObject->GetKind() == KIND_VISUAL_STATE ) @@ -179,7 +187,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, { if( anIsImage ) { - theMenu->addAction( action( EditImageId ) ); + theMenu->addAction( action( anIsCompositeImage ? EditCompositeImageId : EditImportedImageId ) ); theMenu->addAction( action( ObserveImageId ) ); theMenu->addAction( action( ExportImageId ) ); theMenu->addSeparator(); diff --git a/src/HYDROGUI/HYDROGUI_ObjSelector.cxx b/src/HYDROGUI/HYDROGUI_ObjSelector.cxx index 3b7e1e59..04bd20f0 100644 --- a/src/HYDROGUI/HYDROGUI_ObjSelector.cxx +++ b/src/HYDROGUI/HYDROGUI_ObjSelector.cxx @@ -99,7 +99,12 @@ void HYDROGUI_ObjSelector::OnSelectionChanged() if( !anObject.IsNull() ) anObjName = anObject->GetName(); - myObjName->setText( anObjName ); + SetName( anObjName ); +} + +void HYDROGUI_ObjSelector::SetName( const QString& theName ) +{ + myObjName->setText( theName ); } QString HYDROGUI_ObjSelector::GetName() const diff --git a/src/HYDROGUI/HYDROGUI_ObjSelector.h b/src/HYDROGUI/HYDROGUI_ObjSelector.h index 7327df51..f3853d74 100644 --- a/src/HYDROGUI/HYDROGUI_ObjSelector.h +++ b/src/HYDROGUI/HYDROGUI_ObjSelector.h @@ -39,6 +39,7 @@ public: void Clear(); + void SetName( const QString& ); QString GetName() const; protected: diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index a2b82864..77d05454 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -69,7 +69,8 @@ void HYDROGUI_Module::createActions() createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" ); createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I ); - createAction( EditImageId, "EDIT_IMAGE" ); + createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE" ); + createAction( EditCompositeImageId, "EDIT_COMPOSITE_IMAGE" ); createAction( ObserveImageId, "OBSERVE_IMAGE" ); createAction( ExportImageId, "EXPORT_IMAGE" ); createAction( CreatePolylineId, "CREATE_POLYLINE" ); @@ -221,8 +222,8 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId ); break; case ImportImageId: - case EditImageId: - anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImageId ); + case EditImportedImageId: + anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId ); break; case ObserveImageId: anOp = new HYDROGUI_ObserveImageOp( aModule ); @@ -240,6 +241,9 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const case CutId: anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Cut ); break; + case EditCompositeImageId: + anOp = new HYDROGUI_TwoImagesOp( aModule, HYDROGUI_TwoImagesOp::Edit ); + break; case DeleteId: anOp = new HYDROGUI_DeleteOp( aModule ); break; diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index 7c835e50..2e5015d1 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -31,7 +31,8 @@ enum OperationId UndoId, RedoId, ImportImageId, - EditImageId, + EditImportedImageId, + EditCompositeImageId, ObserveImageId, ExportImageId, CreatePolylineId, diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx index 8a313ec9..6cee6e26 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx @@ -108,6 +108,13 @@ QString HYDROGUI_TwoImagesDlg::getImageName() const return myImageName->text(); } +void HYDROGUI_TwoImagesDlg::setSelectedImages( const QString& theName1, + const QString& theName2 ) +{ + myImage1->SetName( theName1 ); + myImage2->SetName( theName2 ); +} + bool HYDROGUI_TwoImagesDlg::getSelectedImages( QString& theName1, QString& theName2 ) const { diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h index e9d38d53..a1f5d526 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h +++ b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h @@ -44,6 +44,8 @@ public: void setImageName( const QString& theName ); QString getImageName() const; + void setSelectedImages( const QString& theName1, + const QString& theName2 ); bool getSelectedImages( QString& theName1, QString& theName2 ) const; diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx index 70437263..fd30943f 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx @@ -37,8 +37,29 @@ 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( anOperator ) ) + myType = Fuse; + else if( dynamic_cast( anOperator ) ) + myType = Cut; + } + } + } + } + QString aName; switch( myType ) { @@ -65,8 +86,33 @@ void HYDROGUI_TwoImagesOp::startOperation() 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, @@ -82,12 +128,15 @@ 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( @@ -98,18 +147,28 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags, 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; @@ -123,6 +182,6 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags, anImage2->SetVisible( aViewId, false ); aResult->SetVisible( aViewId, true ); - theUpdateFlags = UF_Model | UF_Viewer; + theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced; return true; } diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesOp.h b/src/HYDROGUI/HYDROGUI_TwoImagesOp.h index ee3bbda7..d537f4c6 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesOp.h +++ b/src/HYDROGUI/HYDROGUI_TwoImagesOp.h @@ -25,12 +25,14 @@ #include "HYDROGUI_Operation.h" +#include + class HYDROGUI_TwoImagesOp : public HYDROGUI_Operation { Q_OBJECT public: - enum OperationType { Fuse, Cut }; + enum OperationType { Fuse, Cut, Edit }; public: HYDROGUI_TwoImagesOp( HYDROGUI_Module* theModule, const int theType ); @@ -44,7 +46,9 @@ protected: virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg ); private: - int myType; + int myType; + bool myIsEdit; + Handle(HYDROData_Image) myEditedObject; }; #endif