Salome HOME
IPAL21120 SIGSEGV on Meshing attached Compound with Automatic Hexadralization
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MergeNodesDlg.cxx
index 7ad8ccbe4c1f9bae6709c3e479afbe2ddad5d021..625788266e6851fdc9214ac63fa84b1544891df1 100644 (file)
@@ -1,6 +1,6 @@
-//  SMESH SMESHGUI : GUI for SMESH component
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
 //  This library is free software; you can redistribute it and/or
 //  License along with this library; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
-//
-//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+//  SMESH SMESHGUI : GUI for SMESH component
 //  File   : SMESHGUI_MergeNodesDlg.cxx
 //  Author : Michael ZORIN
 //  Module : SMESH
 //  $Header:
-
+//
 #include "SMESHGUI_MergeNodesDlg.h"
 
 #include "SMESHGUI.h"
 
 #include "SMESH_Actor.h"
 #include "SMESH_TypeFilter.hxx"
+#include "SMESH_LogicalFilter.hxx"
+#include "SMESHGUI_MeshUtils.h"
 #include "SMDS_Mesh.hxx"
 
 #include "GEOMBase.h"
 
 #include "SUIT_ResourceMgr.h"
+#include "SUIT_Session.h"
+#include "SUIT_MessageBox.h"
+
+#include "LightApp_Application.h"
 
 #include "SVTK_ViewModel.h"
 #include "SVTK_ViewWindow.h"
@@ -68,6 +73,9 @@
 #include <qpixmap.h>
 #include <qheader.h>
 
+//IDL Headers
+#include CORBA_SERVER_HEADER(SMESH_Group)
+
 using namespace std;
 
 //=================================================================================
@@ -79,9 +87,7 @@ SMESHGUI_MergeNodesDlg::SMESHGUI_MergeNodesDlg( SMESHGUI* theModule, const char*
      : 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 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_MERGE_NODES")));
   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
@@ -131,6 +137,10 @@ SMESHGUI_MergeNodesDlg::SMESHGUI_MergeNodesDlg( SMESHGUI* theModule, const char*
   GroupButtonsLayout->setAlignment(Qt::AlignTop);
   GroupButtonsLayout->setSpacing(6);
   GroupButtonsLayout->setMargin(11);
+  buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
+  buttonHelp->setText(tr("SMESH_BUT_HELP" ));
+  buttonHelp->setAutoDefault(TRUE);
+  GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
   buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
   buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
   buttonCancel->setAutoDefault(TRUE);
@@ -142,7 +152,7 @@ SMESHGUI_MergeNodesDlg::SMESHGUI_MergeNodesDlg( SMESHGUI* theModule, const char*
   QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
   GroupButtonsLayout->addItem(spacer_9, 0, 2);
   buttonOk = new QPushButton(GroupButtons, "buttonOk");
-  buttonOk->setText(tr("SMESH_BUT_OK" ));
+  buttonOk->setText(tr("SMESH_BUT_APPLY_AND_CLOSE" ));
   buttonOk->setAutoDefault(TRUE);
   buttonOk->setDefault(TRUE);
   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
@@ -152,7 +162,7 @@ SMESHGUI_MergeNodesDlg::SMESHGUI_MergeNodesDlg( SMESHGUI* theModule, const char*
 
   // Controls for mesh defining
   GroupMesh = new QGroupBox(this, "GroupMesh");
-  GroupMesh->setTitle(tr("SMESH_MESH"));
+  GroupMesh->setTitle(tr("SMESH_SELECT_WHOLE_MESH"));
   GroupMesh->setColumnLayout(0, Qt::Vertical);
   GroupMesh->layout()->setSpacing(0);
   GroupMesh->layout()->setMargin(0);
@@ -240,21 +250,38 @@ SMESHGUI_MergeNodesDlg::SMESHGUI_MergeNodesDlg( SMESHGUI* theModule, const char*
   SMESHGUI_MergeNodesDlgLayout->addWidget(GroupEdit, 3, 0);
 
   /* Initialisations */
-  SpinBoxTolerance->RangeStepAndValidator(0.0, 999999.999, 0.1, 3);
+  SpinBoxTolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.1, 3);
   SpinBoxTolerance->SetValue(1e-05);
 
   RadioButton1->setChecked(TRUE);
 
+  myEditCurrentArgument = (QWidget*)LineEditMesh; 
+
   myActor = 0;
+  mySubMeshOrGroup = SMESH::SMESH_subMesh::_nil();
 
-  mySMESHGUI->SetActiveDialogBox((QDialog*)this);
+  mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
 
-  myMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
+  mySMESHGUI->SetActiveDialogBox((QDialog*)this);
+  
+  // Costruction of the logical filter
+  SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
+  SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
+  
+  QPtrList<SUIT_SelectionFilter> aListOfFilters;
+  if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
+  if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
+
+  myMeshOrSubMeshOrGroupFilter =
+    new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
+  
+  //myMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
 
   /* signals and slots connections */
   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
+  connect(buttonHelp, SIGNAL(clicked()),   this, SLOT(ClickOnHelp()));
 
   connect(SelectMeshButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
   connect(DetectButton, SIGNAL (clicked()), this, SLOT(onDetect()));
@@ -271,15 +298,16 @@ SMESHGUI_MergeNodesDlg::SMESHGUI_MergeNodesDlg( SMESHGUI* theModule, const char*
   /* to close dialog if study change */
   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
 
-  /* Move widget on the botton right corner of main widget */
-  int x, y;
-  mySMESHGUI->DefineDlgPosition(this, x, y);
-  this->move(x, y);
   this->show(); /* displays Dialog */
 
   resize(0,0);
   buttonOk->setEnabled(false);
   buttonApply->setEnabled(false);
+
+  // Init Mesh field from selection
+  SelectionIntoArgument();
+
+  myHelpFileName = "merging_nodes_page.html";
 }
 
 //=================================================================================
@@ -330,7 +358,7 @@ bool SMESHGUI_MergeNodesDlg::ClickOnApply()
   } catch(...) {
   }
 
-  mySelectionMgr->clearSelected();
+  //mySelectionMgr->clearSelected();
   SMESH::UpdateView();
 
   onDetect();
@@ -354,14 +382,38 @@ void SMESHGUI_MergeNodesDlg::ClickOnOk()
 void SMESHGUI_MergeNodesDlg::ClickOnCancel()
 {
   mySelectionMgr->clearFilters();
-  mySelectionMgr->clearSelected();
+  //mySelectionMgr->clearSelected();
   SMESH::SetPointRepresentation(false);
-  myViewWindow->SetSelectionMode(ActorSelection);
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+    aViewWindow->SetSelectionMode(ActorSelection);
   disconnect(mySelectionMgr, 0, this, 0);
   mySMESHGUI->ResetState();
   reject();
 }
 
+//=================================================================================
+// function : ClickOnHelp()
+// purpose  :
+//=================================================================================
+void SMESHGUI_MergeNodesDlg::ClickOnHelp()
+{
+  LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
+  if (app) 
+    app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
+  else {
+               QString platform;
+#ifdef WIN32
+               platform = "winapplication";
+#else
+               platform = "application";
+#endif
+    SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
+                          QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+                          arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
+                          QObject::tr("BUT_OK"));
+  }
+}
+
 //=================================================================================
 // function : onEditNodesGroup()
 // purpose  :
@@ -388,7 +440,8 @@ void SMESHGUI_MergeNodesDlg::updateControls()
 {
   if (ListCoincident->childCount() < 1) {
     SMESH::SetPointRepresentation(false);
-    myViewWindow->SetSelectionMode(ActorSelection);
+    if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+      aViewWindow->SetSelectionMode(ActorSelection);
     return;
   }
 
@@ -431,7 +484,10 @@ void SMESHGUI_MergeNodesDlg::onDetect()
     ListEdit->clear();
 
     SMESH::array_of_long_array_var aNodeGroups;
-    aMeshEditor->FindCoincidentNodes(SpinBoxTolerance->GetValue(), aNodeGroups);
+    if(!mySubMeshOrGroup->_is_nil())
+      aMeshEditor->FindCoincidentNodesOnPart(mySubMeshOrGroup, SpinBoxTolerance->GetValue(), aNodeGroups);
+    else
+      aMeshEditor->FindCoincidentNodes(SpinBoxTolerance->GetValue(), aNodeGroups);
 
     for (int i = 0; i < aNodeGroups->length(); i++) {
       SMESH::long_array& aGroup = aNodeGroups[i];
@@ -476,7 +532,8 @@ void SMESHGUI_MergeNodesDlg::onSelectNodesGroup()
   mySelectionMgr->setSelectedObjects(aList, false);
 
   SMESH::SetPointRepresentation(true);
-  myViewWindow->SetSelectionMode(NodeSelection);
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+    aViewWindow->SetSelectionMode(NodeSelection);
 
   ListEdit->selectAll(true);
 }
@@ -590,8 +647,9 @@ void SMESHGUI_MergeNodesDlg::SetEditCurrentArgument()
   if (send == SelectMeshButton) {
     myEditCurrentArgument = (QWidget*)LineEditMesh;
     SMESH::SetPointRepresentation(false);
-    myViewWindow->SetSelectionMode(ActorSelection);
-    mySelectionMgr->installFilter(myMeshOrSubMeshFilter);
+    if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+      aViewWindow->SetSelectionMode(ActorSelection);
+    mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
   }
 
   myEditCurrentArgument->setFocus();
@@ -608,23 +666,37 @@ void SMESHGUI_MergeNodesDlg::SelectionIntoArgument()
   if (myEditCurrentArgument == (QWidget*)LineEditMesh) {
     QString aString = "";
     LineEditMesh->setText(aString);
-
+    
     ListCoincident->clear();
     ListEdit->clear();
-
+    myActor = 0;
+    
     int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
     if (nbSel != 1)
       return;
 
     SALOME_ListIO aList;
     mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
-
+    
     Handle(SALOME_InteractiveObject) IO = aList.First();
-    myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
-    myActor = SMESH::FindActorByEntry(aList.First()->getEntry());
-    if (myMesh->_is_nil() || !myActor)
+    myMesh = SMESH::GetMeshByIO(IO);
+    
+    if (myMesh->_is_nil())
       return;
-
+    
+    myActor = SMESH::FindActorByEntry(IO->getEntry());
+    if (!myActor)
+      myActor = SMESH::FindActorByObject(myMesh);
+    if(!myActor)
+      return;
+    
+    mySubMeshOrGroup = SMESH::SMESH_IDSource::_nil();
+    
+    if ((!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil() || //SUBMESH OR GROUP
+         !SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) &&
+        !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
+      mySubMeshOrGroup = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
+     
     LineEditMesh->setText(aString);
   }
 }
@@ -694,3 +766,20 @@ void SMESHGUI_MergeNodesDlg::hideEvent (QHideEvent*)
   if (!isMinimized())
     ClickOnCancel();
 }
+
+//=================================================================================
+// function : keyPressEvent()
+// purpose  :
+//=================================================================================
+void SMESHGUI_MergeNodesDlg::keyPressEvent( QKeyEvent* e )
+{
+  QDialog::keyPressEvent( e );
+  if ( e->isAccepted() )
+    return;
+
+  if ( e->key() == Key_F1 )
+    {
+      e->accept();
+      ClickOnHelp();
+    }
+}