Salome HOME
INT PAL 0052775: Any dialogue with the selector raises an exception for second viewer
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_AddMeshElementDlg.cxx
index 79588047cb0abfb36b46746cfd9387503fc559e0..44cba417c84887f55bb10c98755ca80dc2c491db 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -169,7 +169,8 @@ namespace SMESH
       // Preview for the balls
       vtkProperty* aBallProp = vtkProperty::New();
       aBallProp->SetColor(ffc.red() / 255. , ffc.green() / 255. , ffc.blue() / 255.);
-      double aBallElemSize = SMESH::GetFloat("SMESH:ball_elem_size",10);
+      //double aBallElemSize = SMESH::GetFloat("SMESH:ball_elem_size",10);
+      double aBallElemSize = SMESH::GetFloat("SMESH:ball_elem_diameter",1);
       aBallProp->SetPointSize(aBallElemSize);
 
       myBallPolyData = vtkPolyData::New();
@@ -427,7 +428,7 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI*          theMo
     GroupC1Layout->addWidget(DiameterSpinBox, 1, 1, 1, 2);
 
     DiameterSpinBox->RangeStepAndValidator( 1e-7, 1e+9, 0.1 );
-    DiameterSpinBox->SetValue( 1. );
+    DiameterSpinBox->SetValue( SMESH::GetFloat("SMESH:ball_elem_diameter", 1) );
     connect( DiameterSpinBox, SIGNAL( valueChanged ( double ) ), this, SLOT( onDiameterChanged( ) ) );
   }
   /* Add to group ************************************************/
@@ -514,10 +515,13 @@ void SMESHGUI_AddMeshElementDlg::Init()
   connect(SelectButtonC1A1,SIGNAL(clicked()),                     SLOT(SetEditCurrentArgument()));
   connect(LineEditC1A1,    SIGNAL(textChanged(const QString&)),   SLOT(onTextChange(const QString&)));
   connect(mySMESHGUI,      SIGNAL(SignalDeactivateActiveDialog()),SLOT(DeactivateActiveDialog()));
+
   connect(mySelectionMgr,  SIGNAL(currentSelectionChanged()),     SLOT(SelectionIntoArgument()));
   /* to close dialog if study frame change */
   connect(mySMESHGUI,      SIGNAL(SignalStudyFrameChanged()),     SLOT(reject()));
-  connect(mySMESHGUI,      SIGNAL(SignalCloseAllDialogs()),       SLOT(reject()));    
+  connect(mySMESHGUI,      SIGNAL(SignalCloseAllDialogs()),       SLOT(reject()));
+  connect(mySMESHGUI,      SIGNAL(SignalActivatedViewManager()),  SLOT(onOpenView()));
+  connect(mySMESHGUI,      SIGNAL(SignalCloseView()),             SLOT(onCloseView()));
 
   if (Reverse)
     connect(Reverse,       SIGNAL(stateChanged(int)),             SLOT(CheckBox(int)));
@@ -586,6 +590,7 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply()
     SMESH::long_array_var anIdList = new SMESH::long_array;
     anIdList->length( 1 );
     anIdList[0] = -1;
+    const bool onlyNodesInMesh = ( myMesh->NbElements() == 0 );
 
     switch (myElementType) {
     case SMDSAbs_0DElement:
@@ -645,8 +650,10 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply()
     mySelectionMgr->setSelectedObjects( aList, false );
 
     mySimulation->SetVisibility(false);
+    if ( onlyNodesInMesh )
+      myActor->SetRepresentation( SMESH_Actor::eEdge ); // wireframe
     SMESH::UpdateView();
-    
+
     buttonOk->setEnabled(false);
     buttonApply->setEnabled(false);
 
@@ -938,9 +945,15 @@ void SMESHGUI_AddMeshElementDlg::ActivateThisDialog()
 //=================================================================================
 void SMESHGUI_AddMeshElementDlg::enterEvent (QEvent*)
 {
-  if (GroupConstructors->isEnabled())
-    return;
-  ActivateThisDialog();
+  if ( !GroupConstructors->isEnabled() ) {
+    SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
+    if ( aViewWindow && !mySelector && !mySimulation) {
+      mySelector = aViewWindow->GetSelector();
+      mySimulation = new SMESH::TElementSimulation(
+        dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
+    }
+    ActivateThisDialog();
+  }
 }
 
 //=================================================================================
@@ -975,7 +988,7 @@ void SMESHGUI_AddMeshElementDlg::keyPressEvent( QKeyEvent* e )
 }
 
 //=================================================================================
-// function : isValid
+// function : onDiameterChanged()
 // purpose  :
 //=================================================================================
 void SMESHGUI_AddMeshElementDlg::onDiameterChanged(){
@@ -983,7 +996,37 @@ void SMESHGUI_AddMeshElementDlg::onDiameterChanged(){
 }
 
 //=================================================================================
-// function : isValid
+// function : onOpenView()
+// purpose  :
+//=================================================================================
+void SMESHGUI_AddMeshElementDlg::onOpenView()
+{
+  if ( mySelector && mySimulation ) {
+    mySimulation->SetVisibility(false);
+    SMESH::SetPointRepresentation(false);
+  }
+  else {
+    mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
+    mySimulation = new SMESH::TElementSimulation(
+      dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
+    ActivateThisDialog();
+  }
+}
+
+//=================================================================================
+// function : onCloseView()
+// purpose  :
+//=================================================================================
+void SMESHGUI_AddMeshElementDlg::onCloseView()
+{
+  DeactivateActiveDialog();
+  mySelector = 0;
+  delete mySimulation;
+  mySimulation = 0;
+}
+
+//=================================================================================
+// function : isValid()
 // purpose  :
 //=================================================================================
 bool SMESHGUI_AddMeshElementDlg::isValid()