#include <HYDROData_Iterator.h>
#include <HYDROData_Lambert93.h>
-#include <HYDROOperations_Factory.h>
+#include <HYDROData_OperationsFactory.h>
#include <GraphicsView_ViewManager.h>
#include <GraphicsView_ViewPort.h>
#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 )
Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( anIterator.Current() );
if( !anImageObj.IsNull() )
{
- if( myIsEdit && HYDROGUI_Tool::IsEqual( anImageObj, myEditedObject ) )
+ if( myIsEdit && IsEqual( anImageObj, myEditedObject ) )
continue;
QPoint aPointA1, aPointB1, aPointC1;
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 );
+ Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anImageName );
if( !anObject.IsNull() )
{
theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anImageName );
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( onRefPointSelected() ) );
+ }
+ }
+ }
+ 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 );
}
onPointSelected( myRefPreviewPrs && myRefPreviewPrs->isSelected() );
}
+void HYDROGUI_ImportImageOp::onRefPointSelected()
+{
+ onPointSelected( true );
+}
+
void HYDROGUI_ImportImageOp::onPointSelected( bool theIsRefImage )
{
HYDROGUI_PrsImage* aPrs = theIsRefImage ? myRefPreviewPrs : myPreviewPrs;
void HYDROGUI_ImportImageOp::closePreview()
{
- // 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( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
- aViewPort->onBoundingRectChanged();
-
- if( myPreviewPrs )
- {
- delete myPreviewPrs;
- myPreviewPrs = 0;
- }
+ closeView( myPreviewViewManager );
+ closeView( myRefViewManager );
- if( myRefPreviewPrs )
- {
- delete myRefPreviewPrs;
- myRefPreviewPrs = 0;
- }
+ if( myActiveViewManager )
+ HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
+}
- if( myPreviewViewManager )
+void HYDROGUI_ImportImageOp::closeView( GraphicsView_ViewManager* &aViewMgr )
+{
+ if( aViewMgr )
{
- disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
+ GraphicsView_ViewPort* aViewPort = 0;
+ if( GraphicsView_Viewer* aViewer = aViewMgr->getViewer() )
+ {
+ aViewPort = aViewer->getActiveViewPort();
+ }
+ 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
+ HYDROGUI_PrsImage* aPrs;
+ switch ( module()->getViewManagerRole( aViewMgr ) )
+ {
+ case HYDROGUI_Module::VMR_ReferenceImage:
+ aPrs = myRefPreviewPrs;
+ myRefPreviewPrs = 0;
+ break;
+ case HYDROGUI_Module::VMR_TransformImage:
+ aPrs = myPreviewPrs;
+ myPreviewPrs = 0;
+ }
- if( myActiveViewManager )
- HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
+ // Remove the appropriate presentation from the view
+ if( aPrs && aViewPort )
+ {
+ aViewPort->removeItem( aPrs );
+ delete aPrs;
+ }
+
+ // Delete the view
+ module()->getApp()->removeViewManager( aViewMgr ); // aViewMgr is deleted here
+ aViewMgr = 0;
+ }
}