Salome HOME
0019941: EDF 766 SMESH : Max length hypothesis
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_SmoothingDlg.cxx
index ef8eb7f463863227cba116d8ac024313713f556e..e38bf7713342e8970dfa3cd1cc851b0bbd24bfa0 100644 (file)
@@ -1,29 +1,29 @@
-// 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,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+//  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 
-// 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. 
+//  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.
 //
-// This library is distributed in the hope that it will be useful, 
-// but WITHOUT ANY WARRANTY; without even the implied warranty of 
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-// Lesser General Public License for more details. 
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
 //
-// You should have received a copy of the GNU Lesser General Public 
-// License along with this library; if not, write to the Free Software 
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+//  You should have received a copy of the GNU Lesser General Public
+//  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+// SMESH SMESHGUI : GUI for SMESH component
 // File   : SMESHGUI_SmoothingDlg.cxx
 // Author : Michael ZORIN, Open CASCADE S.A.S.
-//
-
 // SMESH includes
+//
 #include "SMESHGUI_SmoothingDlg.h"
 
 #include "SMESHGUI.h"
@@ -32,6 +32,7 @@
 #include "SMESHGUI_MeshUtils.h"
 #include "SMESHGUI_SpinBox.h"
 #include "SMESHGUI_IdValidator.h"
+#include "SMESHGUI_FilterDlg.h"
 
 #include <SMESH_Actor.h>
 #include <SMESH_TypeFilter.hxx>
@@ -72,6 +73,7 @@
 #include <QVBoxLayout>
 #include <QGridLayout>
 #include <QKeyEvent>
+#include <QButtonGroup>
 
 // IDL includes
 #include <SALOMEconfig.h>
@@ -88,7 +90,8 @@
 SMESHGUI_SmoothingDlg::SMESHGUI_SmoothingDlg( SMESHGUI* theModule )
   : QDialog( SMESH::GetDesktop( theModule ) ),
     mySMESHGUI( theModule ),
-    mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
+    mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
+    myFilterDlg(0)
 {
   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_SMOOTHING")));
   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
@@ -105,6 +108,7 @@ SMESHGUI_SmoothingDlg::SMESHGUI_SmoothingDlg( SMESHGUI* theModule )
 
   /***************************************************************/
   GroupConstructors = new QGroupBox(tr("SMESH_SMOOTHING"), this);
+  QButtonGroup* ButtonGroup = new QButtonGroup(this);
   QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
   GroupConstructorsLayout->setSpacing(SPACING);
   GroupConstructorsLayout->setMargin(MARGIN);
@@ -113,7 +117,7 @@ SMESHGUI_SmoothingDlg::SMESHGUI_SmoothingDlg( SMESHGUI* theModule )
   Constructor1->setIcon(image0);
   Constructor1->setChecked(true);
   GroupConstructorsLayout->addWidget(Constructor1);
-  GroupConstructorsLayout->addStretch();
+  ButtonGroup->addButton(Constructor1, 0);
 
   /***************************************************************/
   GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
@@ -121,6 +125,8 @@ SMESHGUI_SmoothingDlg::SMESHGUI_SmoothingDlg( SMESHGUI* theModule )
   GroupArgumentsLayout->setSpacing(SPACING);
   GroupArgumentsLayout->setMargin(MARGIN);
 
+  myIdValidator = new SMESHGUI_IdValidator(this);
+
   // Controls for elements selection
   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
 
@@ -128,7 +134,9 @@ SMESHGUI_SmoothingDlg::SMESHGUI_SmoothingDlg( SMESHGUI* theModule )
   SelectElementsButton->setIcon(image1);
 
   LineEditElements = new QLineEdit(GroupArguments);
-  LineEditElements->setValidator(new SMESHGUI_IdValidator(this));
+  LineEditElements->setValidator(myIdValidator);
+  QPushButton* filterElemBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
+  connect(filterElemBtn,   SIGNAL(clicked()), this, SLOT(setElemFilters()));
 
   // Control for the whole mesh selection
   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
@@ -140,7 +148,9 @@ SMESHGUI_SmoothingDlg::SMESHGUI_SmoothingDlg( SMESHGUI* theModule )
   SelectNodesButton->setIcon(image1);
 
   LineEditNodes  = new QLineEdit(GroupArguments);
-  LineEditNodes->setValidator(new SMESHGUI_IdValidator(this));
+  LineEditNodes->setValidator(myIdValidator);
+  QPushButton* filterNodeBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
+  connect(filterNodeBtn,   SIGNAL(clicked()), this, SLOT(setNodeFilters()));
 
   // Controls for method selection
   TextLabelMethod = new QLabel(tr("METHOD"), GroupArguments);
@@ -163,17 +173,19 @@ SMESHGUI_SmoothingDlg::SMESHGUI_SmoothingDlg( SMESHGUI* theModule )
   GroupArgumentsLayout->addWidget(TextLabelElements,      0, 0);
   GroupArgumentsLayout->addWidget(SelectElementsButton,   0, 1);
   GroupArgumentsLayout->addWidget(LineEditElements,       0, 2);
-  GroupArgumentsLayout->addWidget(CheckBoxMesh,           1, 0, 1, 3);
+  GroupArgumentsLayout->addWidget(filterElemBtn,          0, 3);
+  GroupArgumentsLayout->addWidget(CheckBoxMesh,           1, 0, 1, 4);
   GroupArgumentsLayout->addWidget(TextLabelNodes,         2, 0);
   GroupArgumentsLayout->addWidget(SelectNodesButton,      2, 1);
   GroupArgumentsLayout->addWidget(LineEditNodes,          2, 2);
+  GroupArgumentsLayout->addWidget(filterNodeBtn,          2, 3);
   GroupArgumentsLayout->addWidget(TextLabelMethod,        3, 0);
-  GroupArgumentsLayout->addWidget(ComboBoxMethod,         3, 2);
+  GroupArgumentsLayout->addWidget(ComboBoxMethod,         3, 2, 1, 2);
   GroupArgumentsLayout->addWidget(TextLabelLimit,         4, 0);
-  GroupArgumentsLayout->addWidget(SpinBox_IterationLimit, 4, 2);
+  GroupArgumentsLayout->addWidget(SpinBox_IterationLimit, 4, 2, 1, 2);
   GroupArgumentsLayout->addWidget(TextLabelAspectRatio,   5, 0);
-  GroupArgumentsLayout->addWidget(SpinBox_AspectRatio,    5, 2);
-  GroupArgumentsLayout->addWidget(CheckBoxParametric,     6, 0, 1, 3);
+  GroupArgumentsLayout->addWidget(SpinBox_AspectRatio,    5, 2, 1, 2);
+  GroupArgumentsLayout->addWidget(CheckBoxParametric,     6, 0, 1, 4);
 
   /***************************************************************/
   GroupButtons = new QGroupBox(this);
@@ -181,7 +193,7 @@ SMESHGUI_SmoothingDlg::SMESHGUI_SmoothingDlg( SMESHGUI* theModule )
   GroupButtonsLayout->setSpacing(SPACING);
   GroupButtonsLayout->setMargin(MARGIN);
 
-  buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
+  buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
   buttonOk->setAutoDefault(true);
   buttonOk->setDefault(true);
   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
@@ -269,6 +281,10 @@ SMESHGUI_SmoothingDlg::SMESHGUI_SmoothingDlg( SMESHGUI* theModule )
 SMESHGUI_SmoothingDlg::~SMESHGUI_SmoothingDlg()
 {
   // no need to delete child widgets, Qt does it all for us
+  if ( myFilterDlg != 0 ) {
+    myFilterDlg->setParent( 0 );
+    delete myFilterDlg;
+  }
 }
 
 //=================================================================================
@@ -307,8 +323,7 @@ void SMESHGUI_SmoothingDlg::ClickOnApply()
   if (mySMESHGUI->isActiveStudyLocked())
     return;
 
-  if (myNbOkElements &&
-      (myNbOkNodes || LineEditNodes->text().trimmed().isEmpty())) {
+  if (myNbOkElements && (myNbOkNodes || LineEditNodes->text().trimmed().isEmpty())) {
     QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
     QStringList aListNodesId    = LineEditNodes->text().split(" ", QString::SkipEmptyParts);
 
@@ -319,7 +334,7 @@ void SMESHGUI_SmoothingDlg::ClickOnApply()
     for (int i = 0; i < aListElementsId.count(); i++)
       anElementsId[i] = aListElementsId[i].toInt();
 
-    if (myNbOkNodes) {
+    if ( myNbOkNodes && aListNodesId.count() > 0 ) {
       aNodesId->length(aListNodesId.count());
       for (int i = 0; i < aListNodesId.count(); i++)
         aNodesId[i] = aListNodesId[i].toInt();
@@ -336,15 +351,15 @@ void SMESHGUI_SmoothingDlg::ClickOnApply()
 
     bool aResult = false;
     try {
+      SUIT_OverrideCursor aWaitCursor;
       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
-      QApplication::setOverrideCursor(Qt::WaitCursor);
+
       if ( CheckBoxParametric->isChecked() )
        aResult = aMeshEditor->SmoothParametric(anElementsId.inout(), aNodesId.inout(),
                                                anIterationLimit, aMaxAspectRatio, aMethod);
       else
        aResult = aMeshEditor->Smooth(anElementsId.inout(), aNodesId.inout(),
                                      anIterationLimit, aMaxAspectRatio, aMethod);
-      QApplication::restoreOverrideCursor();
     } catch (...) {
     }
 
@@ -379,8 +394,11 @@ void SMESHGUI_SmoothingDlg::ClickOnCancel()
   disconnect(mySelectionMgr, 0, this, 0);
   mySelectionMgr->clearFilters();
   //mySelectionMgr->clearSelected();
-  SMESH::SetPickable(); // ???
-  SMESH::SetPointRepresentation(false);
+  if (SMESH::GetCurrentVtkView()) {
+    SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
+    SMESH::SetPointRepresentation(false);
+    SMESH::SetPickable();
+  }
   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
     aViewWindow->SetSelectionMode(ActorSelection);
   mySMESHGUI->ResetState();
@@ -488,15 +506,19 @@ void SMESHGUI_SmoothingDlg::SelectionIntoArgument()
   if (myBusy) return;
 
   // clear
-  myActor = 0;
   QString aString = "";
 
   myBusy = true;
-  if (myEditCurrentArgument == (QWidget*)LineEditElements) {
-    LineEditElements->setText(aString);
-    myNbOkElements = 0;
+  if (myEditCurrentArgument == LineEditElements ||
+      myEditCurrentArgument == LineEditNodes) {
+    myEditCurrentArgument->setText(aString);
+    if (myEditCurrentArgument == LineEditElements)
+      myNbOkElements = 0;
+    else
+      myNbOkNodes = 0;
     buttonOk->setEnabled(false);
     buttonApply->setEnabled(false);
+    myActor = 0;
   }
   myBusy = false;
 
@@ -581,15 +603,18 @@ void SMESHGUI_SmoothingDlg::SelectionIntoArgument()
 
   myBusy = true;
   myEditCurrentArgument->setText(aString);
+  myEditCurrentArgument->repaint();
+  myEditCurrentArgument->setEnabled(false); // to update lineedit IPAL 19809
+  myEditCurrentArgument->setEnabled(true); 
   myBusy = false;
 
   // OK
   if (myEditCurrentArgument == LineEditElements)
-    myNbOkElements = true;
+    myNbOkElements = aNbUnits;
   else if (myEditCurrentArgument == LineEditNodes)
-    myNbOkNodes = true;
+    myNbOkNodes = aNbUnits;
 
-  if (myNbOkElements) {
+  if (myNbOkElements && (myNbOkNodes || LineEditNodes->text().trimmed().isEmpty())) {
     buttonOk->setEnabled(true);
     buttonApply->setEnabled(true);
   }
@@ -614,17 +639,21 @@ void SMESHGUI_SmoothingDlg::SetEditCurrentArgument()
         myEditCurrentArgument = LineEditElements;
         SMESH::SetPointRepresentation(false);
         if (CheckBoxMesh->isChecked()) {
-          mySelectionMgr->setSelectionModes(ActorSelection);
-          mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
+         //          mySelectionMgr->setSelectionModes(ActorSelection);
+         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+           aViewWindow->SetSelectionMode(ActorSelection);
+         mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
         } else {
          if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
-           aViewWindow->SetSelectionMode(CellSelection);
+           aViewWindow->SetSelectionMode(FaceSelection);
        }
-      }        else if (send == SelectNodesButton) {
+      } else if (send == SelectNodesButton) {
+       LineEditNodes->clear();
         myEditCurrentArgument = LineEditNodes;
         SMESH::SetPointRepresentation(true);
-       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) {
          aViewWindow->SetSelectionMode(NodeSelection);
+       }
       }
 
       myEditCurrentArgument->setFocus();
@@ -664,7 +693,7 @@ void SMESHGUI_SmoothingDlg::ActivateThisDialog()
 
   mySMESHGUI->SetActiveDialogBox(this);
   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
-    aViewWindow->SetSelectionMode(CellSelection);
+    aViewWindow->SetSelectionMode(FaceSelection);
   SelectionIntoArgument();
 }
 
@@ -709,8 +738,10 @@ void SMESHGUI_SmoothingDlg::onSelectMesh (bool toSelectMesh)
   else
     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
 
-  if (myEditCurrentArgument != LineEditElements) {
+  if (myEditCurrentArgument != LineEditElements &&
+      myEditCurrentArgument != LineEditNodes) {
     LineEditElements->clear();
+    LineEditNodes->clear();
     return;
   }
 
@@ -718,14 +749,19 @@ void SMESHGUI_SmoothingDlg::onSelectMesh (bool toSelectMesh)
   SMESH::SetPointRepresentation(false);
 
   if (toSelectMesh) {
-    mySelectionMgr->setSelectionModes(ActorSelection);
+    if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+      aViewWindow->SetSelectionMode(ActorSelection);
+    //    mySelectionMgr->setSelectionModes(ActorSelection);
     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
-    LineEditElements->setReadOnly(true);
+    myEditCurrentArgument->setReadOnly(true);
+    myEditCurrentArgument->setValidator(0);
   } else {
     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
-      aViewWindow->SetSelectionMode(CellSelection);
-    LineEditElements->setReadOnly(false);
-    onTextChange(LineEditElements->text());
+      aViewWindow->SetSelectionMode(myEditCurrentArgument == LineEditElements ? FaceSelection 
+                                                                              : NodeSelection );
+    myEditCurrentArgument->setReadOnly(false);
+    LineEditElements->setValidator(myIdValidator);
+    onTextChange(myEditCurrentArgument->text());
   }
 
   SelectionIntoArgument();
@@ -746,3 +782,43 @@ void SMESHGUI_SmoothingDlg::keyPressEvent( QKeyEvent* e )
     ClickOnHelp();
   }
 }
+
+//=================================================================================
+// function : setFilters()
+// purpose  : activate filter dialog
+//=================================================================================
+void SMESHGUI_SmoothingDlg::setFilters( const bool theIsElem )
+{
+  if ( !myFilterDlg )
+  {
+    QList<int> types;  
+    types.append( SMESH::NODE );
+    types.append( SMESH::ALL );
+    myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
+  }
+  myFilterDlg->Init( theIsElem ? SMESH::ALL : SMESH::NODE );
+
+  myFilterDlg->SetSelection();
+  myFilterDlg->SetMesh( myMesh );
+  myFilterDlg->SetSourceWg( theIsElem ? LineEditElements : LineEditNodes );
+
+  myFilterDlg->show();
+}
+
+//=================================================================================
+// function : setElemFilters()
+// purpose  : SLOT. Called when element "Filter" button pressed.
+//=================================================================================
+void SMESHGUI_SmoothingDlg::setElemFilters()
+{
+  setFilters( true );
+}
+
+//=================================================================================
+// function : setNodeFilters()
+// purpose  : SLOT. Called when node "Filter" button pressed.
+//=================================================================================
+void SMESHGUI_SmoothingDlg::setNodeFilters()
+{
+  setFilters( false );
+}