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 20452fc65c95785afb236029fffeaf436dccbe41..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();
@@ -413,33 +414,21 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI*          theMo
 
   Reverse = (myElementType == SMDSAbs_Face || myElementType == SMDSAbs_Volume ) ? new QCheckBox(tr("SMESH_REVERSE"), GroupC1) : 0;
 
-  AutomaticPresentation = (myGeomType == SMDSEntity_Quadrangle || myGeomType == SMDSEntity_Polygon ||
-                           myGeomType == SMDSEntity_Pyramid    || myGeomType == SMDSEntity_Hexa    ||
-                           myGeomType == SMDSEntity_Penta      || myGeomType == SMDSEntity_Hexagonal_Prism ) ? new QCheckBox(tr("SMESH_AUTOMATIC_PRESENTATION"), GroupC1) : 0;
-  if ( AutomaticPresentation ) {
-    GetNextPresentationButton = new QPushButton(tr("SMESH_BUT_GET_NEXT_SHAPE"), GroupC1);
-    GetNextPresentationButton->setAutoDefault(false);
-  }
   DiameterSpinBox = ( myGeomType == SMDSEntity_Ball ) ? new SMESHGUI_SpinBox(GroupC1) : 0;
   QLabel* diameterLabel = DiameterSpinBox ? new QLabel( tr("BALL_DIAMETER"),GroupC1) : 0;
 
   GroupC1Layout->addWidget(TextLabelC1A1,    0, 0);
   GroupC1Layout->addWidget(SelectButtonC1A1, 0, 1);
   GroupC1Layout->addWidget(LineEditC1A1,     0, 2);
-  if ( AutomaticPresentation ) {
-    AutomaticPresentation->setChecked(true);
-    GroupC1Layout->addWidget(AutomaticPresentation, 1, 0, 1, 2);
-    GroupC1Layout->addWidget(GetNextPresentationButton, 1, 2, 1, 1);
-  }
   if ( Reverse ) {
-    GroupC1Layout->addWidget(Reverse, 2, 0, 1, 3);
+    GroupC1Layout->addWidget(Reverse, 1, 0, 1, 3);
   }
   if ( DiameterSpinBox ) {
     GroupC1Layout->addWidget(diameterLabel,   1, 0);
     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 ************************************************/
@@ -518,25 +507,25 @@ void SMESHGUI_AddMeshElementDlg::Init()
   myActor = 0;
 
   /* signals and slots connections */
-  connect(buttonOk,                SIGNAL(clicked()),                     SLOT(ClickOnOk()));
-  connect(buttonCancel,            SIGNAL(clicked()),                     SLOT(reject()));
-  connect(buttonApply,             SIGNAL(clicked()),                     SLOT(ClickOnApply()));
-  connect(buttonHelp,              SIGNAL(clicked()),                     SLOT(ClickOnHelp()));
-
-  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()));
+  connect(buttonOk,        SIGNAL(clicked()),                     SLOT(ClickOnOk()));
+  connect(buttonCancel,    SIGNAL(clicked()),                     SLOT(reject()));
+  connect(buttonApply,     SIGNAL(clicked()),                     SLOT(ClickOnApply()));
+  connect(buttonHelp,      SIGNAL(clicked()),                     SLOT(ClickOnHelp()));
+
+  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(SignalStudyFrameChanged()),     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)));
-  if (AutomaticPresentation) {
-    connect(AutomaticPresentation, SIGNAL(stateChanged(int)),             SLOT(SelectionIntoArgument()));
-    connect(GetNextPresentationButton, SIGNAL(clicked()),                 SLOT(GetNextShapePresentation()));
-  }
+    connect(Reverse,       SIGNAL(stateChanged(int)),             SLOT(CheckBox(int)));
+
   // set selection mode
   SMESH::SetPointRepresentation(true);
 
@@ -601,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:
@@ -660,12 +650,12 @@ 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);
-    if ( AutomaticPresentation )
-      GetNextPresentationButton->setEnabled(false);
 
     myEditCurrentArgument->setText("");
 
@@ -738,8 +728,6 @@ void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
 
   buttonOk->setEnabled(false);
   buttonApply->setEnabled(false);
-  if ( AutomaticPresentation )
-    GetNextPresentationButton->setEnabled(false);
 
   mySimulation->SetVisibility(false);
 
@@ -781,8 +769,6 @@ void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
   if(myNbOkNodes) {
     buttonOk->setEnabled(true);
     buttonApply->setEnabled(true);
-    if ( AutomaticPresentation && AutomaticPresentation->isChecked() )
-      GetNextPresentationButton->setEnabled(true);
     displaySimulation();
   }
 
@@ -802,7 +788,6 @@ void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
   myActor = 0;
 
   myBusy = true;
-  QString anOldEditArgument = myEditCurrentArgument->text();
   myEditCurrentArgument->setText("");
   myBusy = false;
 
@@ -811,8 +796,6 @@ void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
 
   buttonOk->setEnabled(false);
   buttonApply->setEnabled(false);
-  if ( AutomaticPresentation )
-    GetNextPresentationButton->setEnabled(false);
 
   mySimulation->SetVisibility(false);
   //  SMESH::SetPointRepresentation(true);
@@ -856,34 +839,14 @@ void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
 
   // get selected nodes
   QString aString = "";
-  int nbNodes = 0;
-  while ( aString == "" || anOldEditArgument == aString ) {
-    if ( AutomaticPresentation && AutomaticPresentation->isChecked() ) {
-      nbNodes = SMESH::GetNameOfSelectedSortedNodes( myGeomType , mySelector, myActor, myShift, aString );
-    }
-    else
-      nbNodes = SMESH::GetNameOfSelectedNodes( mySelector, myActor->getIO(), aString );
-    if ( aString!= "" && myNbNodes == nbNodes && anOldEditArgument == aString && AutomaticPresentation && AutomaticPresentation->isChecked()) {
-      myShift++;
-      if ( myShift > nbNodes ) {
-        myEditCurrentArgument->setText(aString);
-        myShift = 0;
-        break;
-      }
-      continue;
-    }
-    myBusy = true;
-    myEditCurrentArgument->setText(aString);
-    myBusy = false;
-    if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 )
-      myNbNodes = nbNodes;
-    else if (myNbNodes != nbNodes && myNbNodes != 1) {
-      myShift = 0;
-      return;
-    }
-    if ( !AutomaticPresentation || !AutomaticPresentation->isChecked() ||
-       ( myIsPoly && nbNodes < 3 ) )
-      break;
+  int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
+  myBusy = true;
+  myEditCurrentArgument->setText(aString);
+  myBusy = false;
+  if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 ) {
+    myNbNodes = nbNodes;
+  } else if (myNbNodes != nbNodes && myNbNodes != 1) {
+    return;
   }
 
   // OK
@@ -891,8 +854,6 @@ void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
 
   buttonOk->setEnabled(true);
   buttonApply->setEnabled(true);
-  if ( AutomaticPresentation && AutomaticPresentation->isChecked() )
-    GetNextPresentationButton->setEnabled(true);
 
   displaySimulation();
 }
@@ -942,16 +903,6 @@ void SMESHGUI_AddMeshElementDlg::SetEditCurrentArgument()
   SelectionIntoArgument();
 }
 
-//=================================================================================
-// function : GetNextShapePresentation()
-// purpose  :
-//=================================================================================
-void SMESHGUI_AddMeshElementDlg::GetNextShapePresentation()
-{
-  myShift++;
-  SetEditCurrentArgument();
-}
-
 //=================================================================================
 // function : DeactivateActiveDialog()
 // purpose  :
@@ -994,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();
+  }
 }
 
 //=================================================================================
@@ -1031,7 +988,7 @@ void SMESHGUI_AddMeshElementDlg::keyPressEvent( QKeyEvent* e )
 }
 
 //=================================================================================
-// function : isValid
+// function : onDiameterChanged()
 // purpose  :
 //=================================================================================
 void SMESHGUI_AddMeshElementDlg::onDiameterChanged(){
@@ -1039,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()