]> SALOME platform Git repositories - modules/hydro.git/blobdiff - src/HYDROGUI/HYDROGUI_ImportImageOp.cxx
Salome HOME
Name validator is added to the Calculation Case dialog.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportImageOp.cxx
index 5f73b4b0d870ad5726d6d59f3558f7e15c3733e2..dabeaad10cc3f0a3c3b3b2f484b93fbb96cde800 100644 (file)
@@ -32,7 +32,7 @@
 #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 ),
@@ -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 )
@@ -120,7 +126,7 @@ void HYDROGUI_ImportImageOp::startOperation()
     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;
@@ -187,7 +193,7 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
   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 );
@@ -339,7 +345,7 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
   if( myIsEdit )
     anImageObj->Update();
 
-  theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced;
+  theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced;
   return true;
 }
 
@@ -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( 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() );
@@ -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 );
 }
@@ -524,6 +564,11 @@ void HYDROGUI_ImportImageOp::onPointSelected()
   onPointSelected( myRefPreviewPrs && myRefPreviewPrs->isSelected() );
 }
 
+void HYDROGUI_ImportImageOp::onRefPointSelected()
+{
+  onPointSelected( true );
+}
+
 void HYDROGUI_ImportImageOp::onPointSelected( bool theIsRefImage )
 {
   HYDROGUI_PrsImage* aPrs = theIsRefImage ? myRefPreviewPrs : myPreviewPrs;
@@ -550,35 +595,47 @@ void HYDROGUI_ImportImageOp::onPointSelected( bool theIsRefImage )
 
 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;
+  }
 }