Salome HOME
54250: Wrong group contents after SplitQuad()
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MultiEditDlg.cxx
index a252ce333238a2c3080adcea34843c64534c507b..5651284ab2c1ea77e9b8665bc1ee0ae98ad7456f 100755 (executable)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  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
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -53,7 +53,6 @@
 #include <LightApp_SelectionMgr.h>
 #include <LightApp_Application.h>
 #include <SALOME_ListIO.hxx>
-#include <SALOME_ListIteratorOfListIO.hxx>
 #include <SalomeApp_Tools.h>
 
 #include <SVTK_Selector.h>
@@ -113,8 +112,8 @@ SMESHGUI_MultiEditDlg
                         const bool the3d2d,
                         bool       theDoInit):
   SMESHGUI_PreviewDlg(theModule),
-  mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
   mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
+  mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
   mySMESHGUI(theModule)
 {
   setModal(false);
@@ -398,6 +397,8 @@ void SMESHGUI_MultiEditDlg::Init()
   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
+  connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()), SLOT( onOpenView()));
+  connect(mySMESHGUI, SIGNAL(SignalCloseView()), SLOT( onCloseView()));
 
   // dialog controls
   connect(myFilterBtn, SIGNAL(clicked()), SLOT(onFilterBtn()  ));
@@ -477,6 +478,30 @@ void SMESHGUI_MultiEditDlg::reject()
   QDialog::reject();
 }
 
+//=================================================================================
+// function : onOpenView()
+// purpose  :
+//=================================================================================
+void SMESHGUI_MultiEditDlg::onOpenView()
+{
+  if(!mySelector) {
+    mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
+    mySMESHGUI->EmitSignalDeactivateDialog();
+    setEnabled(true);
+  }
+}
+
+//=================================================================================
+// function : onCloseView()
+// purpose  :
+//=================================================================================
+void SMESHGUI_MultiEditDlg::onCloseView()
+{
+  onDeactivate();
+  mySelector = 0;
+}
+
+
 //=================================================================================
 // function : onHelp()
 // purpose  :
@@ -589,6 +614,10 @@ void SMESHGUI_MultiEditDlg::onDeactivate()
 void SMESHGUI_MultiEditDlg::enterEvent (QEvent*)
 {
   if (!isEnabled()) {
+    SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
+    if ( aViewWindow && !mySelector) {
+      mySelector = aViewWindow->GetSelector();
+    }
     mySMESHGUI->EmitSignalDeactivateDialog();
     setEnabled(true);
     setSelectionMode();
@@ -646,6 +675,9 @@ void SMESHGUI_MultiEditDlg::onFilterAccepted()
 //=======================================================================
 bool SMESHGUI_MultiEditDlg::isIdValid (const int theId) const
 {
+  if ( !myActor )
+    return true; // filter can't work w/o actor
+
   SVTK_Selector* aSelector = SMESH::GetSelector();
   Handle(SMESHGUI_Filter) aFilter =
     Handle(SMESHGUI_Filter)::DownCast(aSelector->GetFilter(myFilterType));
@@ -739,7 +771,7 @@ void SMESHGUI_MultiEditDlg::updateButtons()
   bool isListBoxNonEmpty = myListBox->count() > 0;
   bool isToAll = myToAllChk->isChecked();
   myFilterBtn->setEnabled(!isToAll);
-  myRemoveBtn->setEnabled(isListBoxNonEmpty && !isToAll);
+  myRemoveBtn->setEnabled(myListBox->selectedItems().count() && !isToAll);
   mySortBtn->setEnabled(isListBoxNonEmpty &&!isToAll);
 
   const SALOME_ListIO& aList = mySelector->StoredIObjects();
@@ -859,6 +891,8 @@ void SMESHGUI_MultiEditDlg::onListSelectionChanged()
   mySelector->AddOrRemoveIndex(anActor->getIO(),anIndexes,false);
   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
     aViewWindow->highlight(anActor->getIO(),true,true);
+
+  myRemoveBtn->setEnabled( anIndexes.Extent() );
 }
 
 //=======================================================================
@@ -940,18 +974,18 @@ void SMESHGUI_MultiEditDlg::setSelectionMode()
   }
 
   if (entityType()) {
-    if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
-      aViewWindow->SetSelectionMode(VolumeSelection);
     SMESH::SetFilter(new SMESHGUI_VolumesFilter());
-  } else {
     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
-      aViewWindow->SetSelectionMode(FaceSelection);
+      aViewWindow->SetSelectionMode(VolumeSelection); // here myActor set to a filter
+  } else {
     if (myFilterType == SMESH::TriaFilter)
       SMESH::SetFilter(new SMESHGUI_TriangleFilter());
     else if (myFilterType == SMESH::QuadFilter)
       SMESH::SetFilter(new SMESHGUI_QuadrangleFilter());
     else
       SMESH::SetFilter(new SMESHGUI_FacesFilter());
+    if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+      aViewWindow->SetSelectionMode(FaceSelection); // here myActor set to a filter
   }
 }
 
@@ -1078,7 +1112,7 @@ bool SMESHGUI_ChangeOrientationDlg::process (SMESH::SMESH_MeshEditor_ptr theEdit
 
 int SMESHGUI_ChangeOrientationDlg::nbElemsInMesh()
 {
-  return ( myFilterType = SMESH::FaceFilter ) ? myMesh->NbFaces() : myMesh->NbVolumes();
+  return ( myFilterType == SMESH::FaceFilter ) ? myMesh->NbFaces() : myMesh->NbVolumes();
 }
 
 /*!
@@ -1282,7 +1316,7 @@ bool SMESHGUI_CuttingOfQuadsDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
     {
       if ( hasObj )
         return theEditor->QuadTo4Tri( obj ), true;
-      SMESH::SMESH_IDSource_wrap elems = theEditor->MakeIDSource( theIds, SMESH::FACE );
+      SMESH::IDSource_wrap elems = theEditor->MakeIDSource( theIds, SMESH::FACE );
       theEditor->QuadTo4Tri( elems );
       return true;
     }
@@ -1538,7 +1572,6 @@ SMESHGUI_SplitVolumesDlg::SMESHGUI_SplitVolumesDlg(SMESHGUI* theModule)
   QLabel* dXLbl = new QLabel( tr("SMESH_DX"), myFacetSelGrp);
   QLabel* dYLbl = new QLabel( tr("SMESH_DY"), myFacetSelGrp);
   QLabel* dZLbl = new QLabel( tr("SMESH_DZ"), myFacetSelGrp);
-  QPushButton* axisBtn[3];
   for ( int i = 0; i < 3; ++i )
   {
     myPointSpin[i] = new SMESHGUI_SpinBox( myFacetSelGrp );
@@ -1618,7 +1651,7 @@ bool SMESHGUI_SplitVolumesDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
                                         const SMESH::long_array&    theIds,
                                         SMESH::SMESH_IDSource_ptr   theObj)
 {
-  SMESH::SMESH_IDSource_wrap obj = theObj;
+  SMESH::IDSource_wrap obj = theObj;
   if ( CORBA::is_nil( obj ))
     obj = theEditor->MakeIDSource( theIds, SMESH::VOLUME );
   else
@@ -1635,16 +1668,18 @@ bool SMESHGUI_SplitVolumesDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
       aParameters << myDirSpin[2]->text();
       myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
 
-      SMESH::AxisStruct_var axis = new SMESH::AxisStruct;
-      axis->x  = myPointSpin[0]->GetValue();
-      axis->y  = myPointSpin[1]->GetValue();
-      axis->z  = myPointSpin[2]->GetValue();
-      axis->vx = myDirSpin[0]->GetValue();
-      axis->vy = myDirSpin[1]->GetValue();
-      axis->vz = myDirSpin[2]->GetValue();
-
-      theEditor->SplitHexahedraIntoPrisms( obj,  myGroupChoice->checkedId()+1,
-                                           axis, myAllDomainsChk->isChecked() );
+      SMESH::PointStruct_var point = new SMESH::PointStruct;
+      point->x  = myPointSpin[0]->GetValue();
+      point->y  = myPointSpin[1]->GetValue();
+      point->z  = myPointSpin[2]->GetValue();
+      SMESH::DirStruct_var norm = new SMESH::DirStruct;
+      norm->PS.x = myDirSpin[0]->GetValue();
+      norm->PS.y = myDirSpin[1]->GetValue();
+      norm->PS.z = myDirSpin[2]->GetValue();
+
+      theEditor->SplitHexahedraIntoPrisms( obj, point, norm,
+                                           myGroupChoice->checkedId()+1,
+                                           myAllDomainsChk->isChecked() );
     }
     else
     {
@@ -1698,6 +1733,10 @@ void SMESHGUI_SplitVolumesDlg::on3d2dChanged(int isPrism)
   }
   SMESHGUI_MultiEditDlg::on3d2dChanged( !myEntityType );
   myEntityType = 1; // == VOLUME
+  myChoiceWidget->hide();
+  myChoiceWidget->show();
+  resize(minimumSizeHint());
+  onSelectionDone();
 }
 
 //================================================================================
@@ -1788,6 +1827,8 @@ void SMESHGUI_SplitVolumesDlg::onSelectionDone()
     }
     updateButtons();
   }
+
+  myCriterionGrp->setEnabled( !myMesh->_is_nil() && nbElemsInMesh() > 0 );
 }
 
 //================================================================================
@@ -1811,7 +1852,7 @@ void SMESHGUI_SplitVolumesDlg::showFacetByElement( int elemID )
   gp_XYZ bc( 0,0,0 );
   Bnd_B3d bbox;
   SMDS_NodeIteratorPtr nIt = elem->nodeIterator();
-  vector< const SMDS_MeshNode* > nodes;
+  std::vector< const SMDS_MeshNode* > nodes;
   nodes.reserve( elem->NbNodes() );
   while ( nIt->more() )
   {
@@ -1941,7 +1982,7 @@ void SMESHGUI_SplitVolumesDlg::onSetDir()
     if ( sender() == myAxisBtn[i] )
       break;
   if ( i == 3 )
-    i == 0;
+    i = 0;
   myDirSpin[i]->SetValue(1.);
 
   if ( myActor && !myMesh->_is_nil() && myMesh->NbNodes() > 0 )