Salome HOME
Fix for problem: SIGSEGV appears if to select group after opening "Edit Group" dialog...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_SmoothingDlg.cxx
index 3adcb19c5021a18438aa1a81757dff4a38e544ec..40400d4996e97f249e12a2143e1fe31b7e6de466 100644 (file)
@@ -89,12 +89,10 @@ SMESHGUI_SmoothingDlg::SMESHGUI_SmoothingDlg( SMESHGUI* theModule, const char* n
      : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
                 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
      mySMESHGUI( theModule ),
-     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
-     myViewWindow( SMESH::GetViewWindow( theModule ) ),
-     mySelector( myViewWindow->GetSelector() )
+     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
 {
-  QPixmap image0 (SMESHGUI::resourceMgr()->loadPixmap("SMESH", tr("ICON_DLG_SMOOTHING")));
-  QPixmap image1 (SMESHGUI::resourceMgr()->loadPixmap("SMESH", tr("ICON_SELECT")));
+  QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_SMOOTHING")));
+  QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
 
   if (!name)
     setName("SMESHGUI_SmoothingDlg");
@@ -253,6 +251,8 @@ SMESHGUI_SmoothingDlg::SMESHGUI_SmoothingDlg( SMESHGUI* theModule, const char* n
   GroupArguments->show();
   myConstructorId = 0;
   Constructor1->setChecked(TRUE);
+  
+  mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
 
   mySMESHGUI->SetActiveDialogBox(this);
 
@@ -321,6 +321,7 @@ void SMESHGUI_SmoothingDlg::Init()
 
   myEditCurrentArgument = LineEditElements;
   LineEditElements->setFocus();
+  LineEditElements->clear();
   LineEditNodes->clear();
   myElementsId = "";
   myNbOkElements = 0;
@@ -423,7 +424,8 @@ void SMESHGUI_SmoothingDlg::ClickOnCancel()
   mySelectionMgr->clearSelected();
   SMESH::SetPickable(); // ???
   SMESH::SetPointRepresentation(false);
-  myViewWindow->SetSelectionMode(ActorSelection);
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+    aViewWindow->SetSelectionMode(ActorSelection);
   mySMESHGUI->ResetState();
   reject();
 }
@@ -456,57 +458,35 @@ void SMESHGUI_SmoothingDlg::onTextChange (const QString& theNewText)
     aMesh = myActor->GetObject()->GetMesh();
 
   if (aMesh) {
-    //mySelectionMgr->clearSelected();
-    //mySelectionMgr->AddIObject(myActor->getIO());
-    SALOME_ListIO aList;
-    aList.Append(myActor->getIO());
-    mySelectionMgr->setSelectedObjects(aList, false);
-
+    
     QStringList aListId = QStringList::split(" ", theNewText, false);
 
     if (send == LineEditElements) {
       const Handle(SALOME_InteractiveObject)& anIO = myActor->getIO();
-      TColStd_IndexedMapOfInteger selectedIndices;
       TColStd_MapOfInteger newIndices;
-      mySelector->GetIndex( anIO, selectedIndices );
       for (int i = 0; i < aListId.count(); i++) {
        const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
-       if (e) {
-         //if (!mySelectionMgr->IsIndexSelected(myActor->getIO(), e->GetID())) {
-          if (selectedIndices.Add(e->GetID())) {
-           //mySelectionMgr->AddOrRemoveIndex(myActor->getIO(), e->GetID(), true);
-            newIndices.Add(e->GetID());
-          }
-         myNbOkElements++;
-       }
-      }
-      if (newIndices.Extent() > 0) {
-        mySelector->AddOrRemoveIndex(anIO, newIndices, true);
-       myViewWindow->highlight( anIO, true, true );
+       if (e)
+         newIndices.Add(e->GetID());
+       myNbOkElements++;
       }
+      mySelector->AddOrRemoveIndex(anIO, newIndices, false);
+      if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+       aViewWindow->highlight( anIO, true, true );
       myElementsId = theNewText;
 
     } else if (send == LineEditNodes) {
-      TColStd_IndexedMapOfInteger selectedIndices;
       TColStd_MapOfInteger newIndices;
-      mySelector->GetIndex(myActor->getIO(), selectedIndices);
-
+      
       for (int i = 0; i < aListId.count(); i++) {
        const SMDS_MeshNode * n = aMesh->FindNode(aListId[ i ].toInt());
-       if (n) {
-         //if (!mySelectionMgr->IsIndexSelected(myActor->getIO(), n->GetID())) {
-          if (selectedIndices.Add(n->GetID())) {
-           //mySelectionMgr->AddOrRemoveIndex (myActor->getIO(), n->GetID(), true);
-            newIndices.Add(n->GetID());
-          }
-         myNbOkNodes++;
-       }
-      }
-      if (newIndices.Extent() > 0)
-      {
-        mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, true);
-       myViewWindow->highlight( myActor->getIO(), true, true );
+       if (n)
+         newIndices.Add(n->GetID());
+       myNbOkNodes++;
       }
+      mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
+      if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+       aViewWindow->highlight( myActor->getIO(), true, true );
     }
   }
 
@@ -656,12 +636,14 @@ void SMESHGUI_SmoothingDlg::SetEditCurrentArgument()
           mySelectionMgr->setSelectionModes(ActorSelection);
           mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
         } else {
-          myViewWindow->SetSelectionMode(CellSelection);
+         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+           aViewWindow->SetSelectionMode(CellSelection);
        }
       }        else if (send == SelectNodesButton) {
         myEditCurrentArgument = LineEditNodes;
         SMESH::SetPointRepresentation(true);
-        myViewWindow->SetSelectionMode(NodeSelection);
+       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+         aViewWindow->SetSelectionMode(NodeSelection);
       }
 
       myEditCurrentArgument->setFocus();
@@ -700,7 +682,8 @@ void SMESHGUI_SmoothingDlg::ActivateThisDialog()
   GroupButtons->setEnabled(true);
 
   mySMESHGUI->SetActiveDialogBox(this);
-  myViewWindow->SetSelectionMode(CellSelection);
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+    aViewWindow->SetSelectionMode(CellSelection);
   SelectionIntoArgument();
 }
 
@@ -758,7 +741,8 @@ void SMESHGUI_SmoothingDlg::onSelectMesh (bool toSelectMesh)
     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
     LineEditElements->setReadOnly(true);
   } else {
-    myViewWindow->SetSelectionMode(CellSelection);
+    if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+      aViewWindow->SetSelectionMode(CellSelection);
     LineEditElements->setReadOnly(false);
     onTextChange(LineEditElements->text());
   }