From: rkv Date: Wed, 23 Oct 2013 14:32:13 +0000 (+0000) Subject: Separate reference image view is added for Import Image operation. X-Git-Tag: BR_hydro_v_0_3~90 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8138ea79ff2b25c45aa08124d6c6c7214dccbdc2;p=modules%2Fhydro.git Separate reference image view is added for Import Image operation. --- diff --git a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx index 46cbd7eb..8e6cc231 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx @@ -41,6 +41,11 @@ #include #include +#include +#include +#include +#include + HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule, const bool theIsEdit ) : HYDROGUI_Operation( theModule ), @@ -48,6 +53,7 @@ HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule, myEditedObject( 0 ), myActiveViewManager( 0 ), myPreviewViewManager( 0 ), + myRefViewManager( 0 ), myPreviewPrs( 0 ), myRefPreviewPrs( 0 ), myPointType( HYDROGUI_PrsImage::None ) @@ -448,25 +454,58 @@ void HYDROGUI_ImportImageOp::onModeActivated( int theMode ) aRefImageName = aPanel->getRefImageName(); if( aRefImageName.isEmpty() ) return; // do nothing in this case to avoid visual moving of preview prs + onRefImageActivated( aRefImageName ); + } + else + { + if( myRefViewManager ) + { + closeView( myRefViewManager ); + } } - onRefImageActivated( aRefImageName ); } void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName ) { myRefTransform.reset(); - GraphicsView_ViewPort* aViewPort = 0; - if( myPreviewViewManager ) - if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() ) + + LightApp_Application* anApp = module()->getApp(); + ///// Get a view port for the reference image preview + if( myRefViewManager ) + { + if( GraphicsView_Viewer* aViewer = myRefViewManager->getViewer() ) + { aViewPort = aViewer->getActiveViewPort(); + } + } + else + { + anApp = module()->getApp(); + // Init reference image preview + myRefViewManager = + dynamic_cast( anApp->createViewManager( GraphicsView_Viewer::Type() ) ); + if( myRefViewManager ) + { + connect( myRefViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ), + this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) ); + + module()->setViewManagerRole( myRefViewManager, HYDROGUI_Module::VMR_ReferenceImage ); + myRefViewManager->setTitle( tr( "REFERENCE_IMAGE" ) ); + if( GraphicsView_Viewer* aViewer = myRefViewManager->getViewer() ) + { + aViewPort = aViewer->getActiveViewPort(); + connect( aViewer, SIGNAL( selectionChanged( GV_SelectionChangeStatus ) ), + this, SLOT( onPointSelected() ) ); + } + } + } + qApp->processEvents(); if( !aViewPort ) return; - if( myPreviewPrs ) - myPreviewPrs->setCaption( QString() ); - + // Remove the old presentation of the reference image if any if( myRefPreviewPrs ) { myRefPreviewPrs->setCaption( QString() ); @@ -476,6 +515,7 @@ void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName ) myRefPreviewPrs = 0; } + // Create a new reference image presentation QImage anImage; Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), theName, KIND_IMAGE ) ); @@ -491,25 +531,25 @@ void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName ) myRefPreviewPrs->setIsTransformationPointPreview( true ); myRefPreviewPrs->setTransformationPointType( myPointType ); - // vertically shift the reference prs relatively to the main prs - if( myPreviewPrs ) - { - myPreviewPrs->setCaption( tr( "IMPORTED_IMAGE" ) ); - - QImage anImage = myPreviewPrs->getImage(); - myRefPreviewPrs->moveBy( 0, anImage.height() + 60 ); - myRefPreviewPrs->setCaption( tr( "REFERENCE_IMAGE" ) ); - } - + // Add the new reference image presentation to the appropriate view aViewPort->addItem( myRefPreviewPrs ); } aViewPort->fitAll(); - HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel(); + // Split views horizontally + if( anApp->desktop()->inherits( "STD_TabDesktop" ) ) + { + QtxWorkstack* aWorkstack = ( (STD_TabDesktop*)anApp->desktop() )->workstack(); + aViewPort->activateWindow(); + aViewPort->show(); + aViewPort->setFocus(Qt::ActiveWindowFocusReason); + aWorkstack->splitHorizontal(); + } + // Initialize the dialog + HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel(); aPanel->setImageSize( anImage.size(), true ); - aPanel->initializePointSelection(); onPointSelected( true ); } @@ -549,36 +589,43 @@ void HYDROGUI_ImportImageOp::onPointSelected( bool theIsRefImage ) } void HYDROGUI_ImportImageOp::closePreview() +{ + closeView( myPreviewViewManager ); + closeView( myRefViewManager ); + + if( myActiveViewManager ) + HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager ); +} + +void HYDROGUI_ImportImageOp::closeView( GraphicsView_ViewManager* &aViewMgr ) { // It's very strange, but without calling this method (it's quite safe) a crash is stably reproduced. // Scenario: create any non-Graphics view, activate import op, click apply. // Result: a few SIGSEGVs coming from processEvents(), then crash. - if( myPreviewViewManager ) - if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() ) + if( aViewMgr ) + { + if( GraphicsView_Viewer* aViewer = aViewMgr->getViewer() ) + { if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() ) + { aViewPort->onBoundingRectChanged(); - - if( myPreviewPrs ) - { - delete myPreviewPrs; - myPreviewPrs = 0; - } - - if( myRefPreviewPrs ) - { - delete myRefPreviewPrs; - myRefPreviewPrs = 0; - } - - if( myPreviewViewManager ) - { - disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ), + } + } + disconnect( aViewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ), this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) ); - module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here - myPreviewViewManager = 0; - } + // Nullify appropriate presentation pointer + switch ( module()->getViewManagerRole( aViewMgr ) ) + { + case HYDROGUI_Module::VMR_ReferenceImage: + myRefPreviewPrs = 0; + break; + case HYDROGUI_Module::VMR_TransformImage: + myPreviewPrs = 0; + } - if( myActiveViewManager ) - HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager ); + // Delete the view and all its presentations + module()->getApp()->removeViewManager( aViewMgr ); // aViewMgr is deleted here + aViewMgr = 0; + } } diff --git a/src/HYDROGUI/HYDROGUI_ImportImageOp.h b/src/HYDROGUI/HYDROGUI_ImportImageOp.h index 5a94c44c..c931a9da 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageOp.h +++ b/src/HYDROGUI/HYDROGUI_ImportImageOp.h @@ -66,19 +66,21 @@ protected slots: private: void closePreview(); + void closeView( GraphicsView_ViewManager* &aViewMgr ); private: bool myIsEdit; Handle(HYDROData_Image) myEditedObject; - SUIT_ViewManager* myActiveViewManager; + SUIT_ViewManager* myActiveViewManager; //!< The previous view to come back to after the operation - GraphicsView_ViewManager* myPreviewViewManager; - HYDROGUI_PrsImage* myPreviewPrs; - HYDROGUI_PrsImage* myRefPreviewPrs; + GraphicsView_ViewManager* myPreviewViewManager; //!< The operation preview window + GraphicsView_ViewManager* myRefViewManager; //!< The reference image view window + HYDROGUI_PrsImage* myPreviewPrs; //!< The loaded image preview presentation + HYDROGUI_PrsImage* myRefPreviewPrs; //!< The reference image presentation - QImage myImage; - QTransform myRefTransform; + QImage myImage; //!< The loaded image to import + QTransform myRefTransform; //!< The loaded image transformation int myPointType; }; diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 51b899a7..cb2cd1c7 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -630,7 +630,7 @@ void HYDROGUI_Module::customEvent( QEvent* e ) if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() ) { - if( aRole != VMR_TransformImage ) + if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage ) aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect ); diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index 14c366a9..c4c1317e 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -58,6 +58,7 @@ public: VMR_Unknown = 0, VMR_General, VMR_TransformImage, + VMR_ReferenceImage, VMR_ObserveImage, //VMR_PreviewZone, // totally unused, to delete VMR_PreviewCaseZones // actually unused, to review