Salome HOME
0022098: EDF 2036 SMESH: Create groups from none conected parts of a mesh
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_GroupDlg.cxx
index f6d02c232a452648b4efcad933a2488a07b0b51a..932a322995e43318573df86b7d9988b63bb41e96 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2013  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
@@ -44,6 +44,7 @@
 // SALOME GEOM includes
 #include <GEOMBase.h>
 #include <GEOM_SelectionFilter.h>
+#include <GEOM_wrap.hxx>
 
 // SALOME GUI includes
 #include <QtxColorButton.h>
@@ -123,7 +124,7 @@ SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
                                       SMESH::SMESH_Mesh_ptr theMesh )
   : QDialog( SMESH::GetDesktop( theModule ) ),
     mySMESHGUI( theModule ),
-    mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
+    mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), myStoredShownEntity(0),
     mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
     myIsBusy( false ),
     myNameChanged( false ),
@@ -151,7 +152,7 @@ SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
                                       const bool theIsConvert )
   : QDialog( SMESH::GetDesktop( theModule ) ),
     mySMESHGUI( theModule ),
-    mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
+    mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), myStoredShownEntity(0),
     mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
     myIsBusy( false ),
     myNameChanged( false ),
@@ -438,7 +439,7 @@ void SMESHGUI_GroupDlg::initDialog( bool create)
 
   connect(myOKBtn,         SIGNAL(clicked()), this, SLOT(onOK()));
   connect(myApplyBtn,      SIGNAL(clicked()), this, SLOT(onApply()));
-  connect(myCloseBtn,      SIGNAL(clicked()), this, SLOT(onClose()));
+  connect(myCloseBtn,      SIGNAL(clicked()), this, SLOT(reject()));
   connect(myHelpBtn,       SIGNAL(clicked()), this, SLOT(onHelp()));
 
   /* Init selection */
@@ -457,7 +458,7 @@ void SMESHGUI_GroupDlg::initDialog( bool create)
   myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
 
   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
-  connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()),        this, SLOT(onClose()));
+  connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()),        this, SLOT(reject()));
   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),  this, SLOT(onObjectSelectionChanged()));
   connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()),      this, SLOT(onVisibilityChanged()));
 
@@ -1033,8 +1034,6 @@ bool SMESHGUI_GroupDlg::onApply()
         return false;
 
       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
-      GEOM::GEOM_IGroupOperations_var aGroupOp =
-        SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
 
       if (myGeomObjects->length() == 1) {
         myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
@@ -1053,8 +1052,7 @@ bool SMESHGUI_GroupDlg::onApply()
         if (geomGen->_is_nil() || !aStudy)
           return false;
 
-        GEOM::GEOM_IGroupOperations_var op =
-          geomGen->GetIGroupOperations(aStudy->StudyId());
+        GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
         if (op->_is_nil())
           return false;
 
@@ -1071,8 +1069,8 @@ bool SMESHGUI_GroupDlg::onApply()
           }
         }
 
-        GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
-        GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
+        GEOM::GEOM_Object_var  aMeshShape = myMesh->GetShapeToMesh();
+        GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
         op->UnionList(aGroupVar, myGeomObjects);
 
         if (op->IsDone()) {
@@ -1191,7 +1189,7 @@ void SMESHGUI_GroupDlg::onOK()
 {
   setIsApplyAndClose( true );
   if ( onApply() )
-    onClose();
+    reject();
   setIsApplyAndClose( false );
 }
 
@@ -1373,15 +1371,19 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
 
         // Check if group constructed on the same shape as a mesh or on its child
         _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
-        GEOM::GEOM_IGroupOperations_var anOp =
-          SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
 
         // The main shape of the group
         GEOM::GEOM_Object_var aGroupMainShape;
-        if (aGeomGroup->GetType() == 37)
+        if (aGeomGroup->GetType() == 37) {
+          GEOM::GEOM_IGroupOperations_wrap anOp =
+            SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
           aGroupMainShape = anOp->GetMainShape(aGeomGroup);
-        else
-          aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
+          // aGroupMainShape is an existing servant => GEOM_Object_var not GEOM_Object_wrap
+        }
+        else {
+          aGroupMainShape = aGeomGroup;
+          aGroupMainShape->Register();
+        }
         _PTR(SObject) aGroupMainShapeSO =
           aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
 
@@ -1558,7 +1560,7 @@ void SMESHGUI_GroupDlg::onSelectAll()
 
   myElementsLab->setEnabled( !noElemsModif );
   myElements->setEnabled   ( !noElemsModif );
-  myFilterBtn->setEnabled  ( !mySelectAll->isChecked() );
+  myFilterBtn->setEnabled  ( !noElemsModif );
   myAddBtn->setEnabled     ( !noElemsModif );
   myRemoveBtn->setEnabled  ( !noElemsModif );
   mySortBtn->setEnabled    ( !noElemsModif );
@@ -1723,8 +1725,8 @@ void SMESHGUI_GroupDlg::setFilters()
     myFilterDlg->Init( aType );
   }
 
-  myFilterDlg->SetSelection();
   myFilterDlg->SetMesh( myMesh );
+  myFilterDlg->SetSelection();
   myFilterDlg->SetSourceWg( myElements, false );
 
   myFilterDlg->show();
@@ -1951,7 +1953,7 @@ void SMESHGUI_GroupDlg::onAdd()
 
   } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
-    GEOM::GEOM_IGroupOperations_var aGroupOp =
+    GEOM::GEOM_IGroupOperations_wrap aGroupOp =
       SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
 
     SMESH::ElementType aGroupType = SMESH::ALL;
@@ -2163,15 +2165,6 @@ void SMESHGUI_GroupDlg::onSort()
   }
 }
 
-//=================================================================================
-// function : closeEvent()
-// purpose  :
-//=================================================================================
-void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
-{
-  onClose();
-}
-
 //=================================================================================
 // function : onVisibilityChanged()
 // purpose  :
@@ -2182,10 +2175,10 @@ void SMESHGUI_GroupDlg::onVisibilityChanged()
 }
 
 //=================================================================================
-// function : SMESHGUI_GroupDlg::onClose
+// function : SMESHGUI_GroupDlg::reject
 // purpose  : SLOT called when "Close" button pressed. Close dialog
 //=================================================================================
-void SMESHGUI_GroupDlg::onClose()
+void SMESHGUI_GroupDlg::reject()
 {
   if (SMESH::GetCurrentVtkView()) {
     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
@@ -2206,7 +2199,7 @@ void SMESHGUI_GroupDlg::onClose()
   mySelectionMgr->clearFilters();
   mySMESHGUI->ResetState();
 
-  reject();
+  QDialog::reject();
 }
 
 //=================================================================================
@@ -2260,16 +2253,6 @@ void SMESHGUI_GroupDlg::enterEvent (QEvent*)
   }
 }
 
-//=================================================================================
-// function : hideEvent
-// purpose  : caused by ESC key
-//=================================================================================
-void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
-{
-  if (!isMinimized() && !myIsBusy)
-    onClose();
-}
-
 //=================================================================================
 // function : keyPressEvent()
 // purpose  :