Salome HOME
INT PAL 0052775: Any dialogue with the selector raises an exception for second viewer
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_PreviewDlg.cxx
index 7710d161bcc0193ac82e0fa2b4ac782e2bf8ac31..d466dedf32efe535dd17667d2ca2420039641735 100644 (file)
@@ -50,6 +50,8 @@ SMESHGUI_PreviewDlg::SMESHGUI_PreviewDlg(SMESHGUI* theModule) :
   myIsApplyAndClose( false )
 {
   mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI ));
   myIsApplyAndClose( false )
 {
   mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI ));
+  connect(mySMESHGUI, SIGNAL(SignalCloseView()),            this, SLOT(onCloseView()));
+  connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()), this, SLOT(onOpenView()));
 }
 
 //=================================================================================
 }
 
 //=================================================================================
@@ -66,7 +68,7 @@ SMESHGUI_PreviewDlg::~SMESHGUI_PreviewDlg()
 // purpose  : Show preview in the viewer
 //=================================================================================
 void SMESHGUI_PreviewDlg::showPreview(){
 // purpose  : Show preview in the viewer
 //=================================================================================
 void SMESHGUI_PreviewDlg::showPreview(){
-  if(mySimulation)
+  if(mySimulation && mySimulation->GetActor())
     mySimulation->SetVisibility(true);
 }
 
     mySimulation->SetVisibility(true);
 }
 
@@ -75,7 +77,7 @@ void SMESHGUI_PreviewDlg::showPreview(){
 // purpose  : Hide preview in the viewer
 //=================================================================================
 void SMESHGUI_PreviewDlg::hidePreview(){
 // purpose  : Hide preview in the viewer
 //=================================================================================
 void SMESHGUI_PreviewDlg::hidePreview(){
-  if(mySimulation)
+  if(mySimulation && mySimulation->GetActor())
     mySimulation->SetVisibility(false);
 }
 
     mySimulation->SetVisibility(false);
 }
 
@@ -87,7 +89,6 @@ void SMESHGUI_PreviewDlg::connectPreviewControl(){
   connect(myPreviewCheckBox, SIGNAL(toggled(bool)), this, SLOT(onDisplaySimulation(bool)));
 }
 
   connect(myPreviewCheckBox, SIGNAL(toggled(bool)), this, SLOT(onDisplaySimulation(bool)));
 }
 
-
 //=================================================================================
 // function : toDisplaySimulation
 // purpose  : 
 //=================================================================================
 // function : toDisplaySimulation
 // purpose  : 
@@ -124,7 +125,27 @@ bool SMESHGUI_PreviewDlg::isApplyAndClose() const
   return myIsApplyAndClose;
 }
 
   return myIsApplyAndClose;
 }
 
+//=================================================================================
+// function : onCloseView()
+// purpose  : SLOT called when close view
+//=================================================================================
+void SMESHGUI_PreviewDlg::onCloseView()
+{
+  if ( mySimulation && mySimulation->GetActor())
+    mySimulation->SetVisibility(false);
+  delete mySimulation;
+  mySimulation=0;
+}
 
 
+//=================================================================================
+// function : onOpenView()
+// purpose  : SLOT called when open view
+//=================================================================================
+void SMESHGUI_PreviewDlg::onOpenView()
+{
+  if ( !mySimulation)
+    mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI ));
+}
 //=================================================================================
 // class    : SMESHGUI_SMESHGUI_MultiPreviewDlg()
 // purpose  :
 //=================================================================================
 // class    : SMESHGUI_SMESHGUI_MultiPreviewDlg()
 // purpose  :
@@ -134,6 +155,8 @@ SMESHGUI_MultiPreviewDlg::SMESHGUI_MultiPreviewDlg( SMESHGUI* theModule ) :
   QDialog( SMESH::GetDesktop( theModule ) ),
   myIsApplyAndClose( false )
 {
   QDialog( SMESH::GetDesktop( theModule ) ),
   myIsApplyAndClose( false )
 {
+  mySimulationList.clear();
+  connect(mySMESHGUI, SIGNAL(SignalCloseView()), this, SLOT(onCloseView()));
 }
 
 //=================================================================================
 }
 
 //=================================================================================
@@ -152,7 +175,8 @@ SMESHGUI_MultiPreviewDlg::~SMESHGUI_MultiPreviewDlg()
 void SMESHGUI_MultiPreviewDlg::showPreview()
 {
   for ( int i = 0; i < mySimulationList.count(); i++ )
 void SMESHGUI_MultiPreviewDlg::showPreview()
 {
   for ( int i = 0; i < mySimulationList.count(); i++ )
-    mySimulationList[i]->SetVisibility( true );
+    if(mySimulationList[i] && mySimulationList[i]->GetActor())
+      mySimulationList[i]->SetVisibility( true );
 }
 
 //=================================================================================
 }
 
 //=================================================================================
@@ -162,7 +186,8 @@ void SMESHGUI_MultiPreviewDlg::showPreview()
 void SMESHGUI_MultiPreviewDlg::hidePreview()
 {
   for ( int i = 0; i < mySimulationList.count(); i++ )
 void SMESHGUI_MultiPreviewDlg::hidePreview()
 {
   for ( int i = 0; i < mySimulationList.count(); i++ )
-    mySimulationList[i]->SetVisibility( false );
+    if(mySimulationList[i] && mySimulationList[i]->GetActor())
+      mySimulationList[i]->SetVisibility( false );
 }
 
 //=================================================================================
 }
 
 //=================================================================================
@@ -174,7 +199,6 @@ void SMESHGUI_MultiPreviewDlg::connectPreviewControl()
   connect( myPreviewCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( onDisplaySimulation( bool ) ) );
 }
 
   connect( myPreviewCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( onDisplaySimulation( bool ) ) );
 }
 
-
 //=================================================================================
 // function : toDisplaySimulation
 // purpose  : 
 //=================================================================================
 // function : toDisplaySimulation
 // purpose  : 
@@ -227,3 +251,13 @@ void SMESHGUI_MultiPreviewDlg::setSimulationPreview( QList<SMESH::MeshPreviewStr
     mySimulationList[i]->SetData( theMeshPreviewStruct[i].operator->() );
   }
 }
     mySimulationList[i]->SetData( theMeshPreviewStruct[i].operator->() );
   }
 }
+
+//=================================================================================
+// function : onCloseView()
+// purpose  : SLOT called when close view
+//=================================================================================
+void SMESHGUI_MultiPreviewDlg::onCloseView()
+{
+  qDeleteAll( mySimulationList );
+  mySimulationList.clear();
+}