#include <LightApp_Application.h>
#include <LightApp_UpdateFlags.h>
+#include <STD_TabDesktop.h>
+#include <SUIT_Desktop.h>
+#include <QtxWorkstack.h>
+#include <QApplication>
+
HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule,
const bool theIsEdit )
: HYDROGUI_Operation( theModule ),
myEditedObject( 0 ),
myActiveViewManager( 0 ),
myPreviewViewManager( 0 ),
+ myRefViewManager( 0 ),
myPreviewPrs( 0 ),
myRefPreviewPrs( 0 ),
myPointType( HYDROGUI_PrsImage::None )
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<GraphicsView_ViewManager*>( 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() );
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 ) );
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 );
}
}
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;
+ }
}