]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
HYDRO bug 28: crash when Import image.
authorouv <ouv@opencascade.com>
Wed, 11 Sep 2013 10:47:36 +0000 (10:47 +0000)
committerouv <ouv@opencascade.com>
Wed, 11 Sep 2013 10:47:36 +0000 (10:47 +0000)
src/HYDROGUI/HYDROGUI_ImportImageOp.cxx
src/HYDROGUI/HYDROGUI_ImportImageOp.h

index 30ce138871e709defa5e5c9b735e0620d5740f9b..86055e826db3dd3f7a4acb36a3dd9be0e4624ee3 100644 (file)
@@ -183,22 +183,8 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
     }
   }
 
-  if( !myPreviewPrs )
-    return false;
-
-  QImage anImage = myPreviewPrs->getImage();
-
   bool anIsRefImage = aPanel->getTransformationMode() == HYDROGUI_ImportImageDlg::RefImage;
 
-  QTransform aRefTransform;
-  if( anIsRefImage && myRefPreviewPrs )
-  {
-    Handle(HYDROData_Image) aRefImageObj =
-      Handle(HYDROData_Image)::DownCast( myRefPreviewPrs->getObject() );
-    if( !aRefImageObj.IsNull() )
-      aRefTransform = aRefImageObj->Trsf();
-  }
-
   HYDROGUI_ImportImageDlg::TransformationDataMap aMap;
   if( !aPanel->getTransformationDataMap( aMap ) )
     return false;
@@ -272,7 +258,7 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
 
   QTransform aTransform;
   if( anIsRefImage )
-    aTransform = aTransform1Inverted * aTransform3 * aRefTransform;
+    aTransform = aTransform1Inverted * aTransform3 * myRefTransform;
   else
     aTransform = aTransform1Inverted * aTransform2;
 
@@ -287,7 +273,7 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
 
   anImageObj->SetName( anImageName );
 
-  anImageObj->SetImage( anImage );
+  anImageObj->SetImage( myImage );
   anImageObj->SetTrsf( aTransform );
 
   if( anIsRefImage )
@@ -323,18 +309,23 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
 
 void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage )
 {
+  myImage = theImage;
+
   LightApp_Application* anApp = module()->getApp();
 
   myActiveViewManager = anApp->activeViewManager();
 
   myPreviewPrs = new HYDROGUI_PrsImage( myIsEdit ? myEditedObject : 0 );
-  myPreviewPrs->setImage( theImage );
+  myPreviewPrs->setImage( myImage );
   myPreviewPrs->compute();
 
   myPreviewViewManager =
     dynamic_cast<GraphicsView_ViewManager*>( anApp->createViewManager( GraphicsView_Viewer::Type() ) );
   if( myPreviewViewManager )
   {
+    connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
+             this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
+
     module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_TransformImage );
     myPreviewViewManager->setTitle( tr( "TRANSFORM_IMAGE" ) );
     if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
@@ -365,7 +356,7 @@ void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage )
     anImageName = HYDROGUI_Tool::GenerateObjectName( module(), "Image" );
   aPanel->setImageName( anImageName );
 
-  aPanel->setImageSize( theImage.size() );
+  aPanel->setImageSize( myImage.size() );
 
   aPanel->initializePointSelection();
   onPointSelected( false );
@@ -393,6 +384,8 @@ void HYDROGUI_ImportImageOp::onPointCoordChanged( bool theIsRef,
 
 void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName )
 {
+  myRefTransform.reset();
+
   GraphicsView_ViewPort* aViewPort = 0;
   if( myPreviewViewManager )
     if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
@@ -419,6 +412,7 @@ void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName )
   if( !anImageObj.IsNull() )
   {
     anImage = anImageObj->Image();
+    myRefTransform = anImageObj->Trsf();
 
     myRefPreviewPrs = new HYDROGUI_PrsImage( anImageObj );
     myRefPreviewPrs->setImage( anImage );
@@ -450,6 +444,11 @@ void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName )
   onPointSelected( true );
 }
 
+void HYDROGUI_ImportImageOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
+{
+  closePreview();
+}
+
 void HYDROGUI_ImportImageOp::onPointSelected()
 {
   onPointSelected( myRefPreviewPrs && myRefPreviewPrs->isSelected() );
@@ -495,6 +494,9 @@ void HYDROGUI_ImportImageOp::closePreview()
 
   if( myPreviewViewManager )
   {
+    disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
+                this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
+
     module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
     myPreviewViewManager = 0;
   }
index 9dd9c050dd0e573abb6f1ac62a3cf01dcddd3464..67be1e103784649f083021239f43a67a0dabda66 100644 (file)
@@ -58,6 +58,8 @@ protected slots:
   void                       onPointCoordChanged( bool, int, bool, int );
   void                       onRefImageActivated( const QString& );
 
+  void                       onLastViewClosed( SUIT_ViewManager* );
+
   void                       onPointSelected();
   void                       onPointSelected( bool theIsRefImage );
 
@@ -74,6 +76,9 @@ private:
   HYDROGUI_PrsImage*         myPreviewPrs;
   HYDROGUI_PrsImage*         myRefPreviewPrs;
 
+  QImage                     myImage;
+  QTransform                 myRefTransform;
+
   int                        myPointType;
 };