]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Separate reference image view is added for Import Image operation.
authorrkv <rkv@opencascade.com>
Wed, 23 Oct 2013 14:32:13 +0000 (14:32 +0000)
committerrkv <rkv@opencascade.com>
Wed, 23 Oct 2013 14:32:13 +0000 (14:32 +0000)
src/HYDROGUI/HYDROGUI_ImportImageOp.cxx
src/HYDROGUI/HYDROGUI_ImportImageOp.h
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_Module.h

index 46cbd7ebaf560f42cf84b05f5b7c7dc1127924e3..8e6cc2311c6c822ba545550c46e35093e3c95979 100644 (file)
 #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 ),
@@ -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<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() );
@@ -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;
+  }
 }
index 5a94c44c1df284cc90e42d58729e1489843c8cd3..c931a9dac71b1a0bf00fa663ca64bf0e42779abd 100644 (file)
@@ -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;
 };
index 51b899a7fef7142b1166c99632d28bcdef3eda79..cb2cd1c7564d79ad315971940c7d5c00085f4b9e 100644 (file)
@@ -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 );
index 14c366a9ba02cce29ce348e9d69daf72330e737f..c4c1317e0357977bb9d6ac57812beb361a6a89c1 100644 (file)
@@ -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