Back to index

salome-smesh  6.5.0
SMESHGUI_SmoothingDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // SMESH SMESHGUI : GUI for SMESH component
00024 // File   : SMESHGUI_SmoothingDlg.cxx
00025 // Author : Michael ZORIN, Open CASCADE S.A.S.
00026 // SMESH includes
00027 //
00028 #include "SMESHGUI_SmoothingDlg.h"
00029 
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_Utils.h"
00032 #include "SMESHGUI_VTKUtils.h"
00033 #include "SMESHGUI_MeshUtils.h"
00034 #include "SMESHGUI_SpinBox.h"
00035 #include "SMESHGUI_IdValidator.h"
00036 #include "SMESHGUI_FilterDlg.h"
00037 
00038 #include <SMESH_Actor.h>
00039 #include <SMESH_TypeFilter.hxx>
00040 #include <SMESH_LogicalFilter.hxx>
00041 
00042 #include <SMDS_Mesh.hxx>
00043 
00044 // SALOME GUI includes
00045 #include <SUIT_ResourceMgr.h>
00046 #include <SUIT_OverrideCursor.h>
00047 #include <SUIT_Desktop.h>
00048 #include <SUIT_Session.h>
00049 #include <SUIT_MessageBox.h>
00050 
00051 #include <LightApp_Application.h>
00052 #include <LightApp_SelectionMgr.h>
00053 
00054 #include <SalomeApp_IntSpinBox.h>
00055 
00056 #include <SVTK_ViewModel.h>
00057 #include <SVTK_Selector.h>
00058 #include <SVTK_ViewWindow.h>
00059 #include <SVTK_Selection.h>
00060 #include <SALOME_ListIO.hxx>
00061 
00062 // OCCT includes
00063 #include <TColStd_MapOfInteger.hxx>
00064 
00065 // Qt includes
00066 #include <QApplication>
00067 #include <QGroupBox>
00068 #include <QLabel>
00069 #include <QLineEdit>
00070 #include <QPushButton>
00071 #include <QRadioButton>
00072 #include <QComboBox>
00073 #include <QCheckBox>
00074 #include <QHBoxLayout>
00075 #include <QVBoxLayout>
00076 #include <QGridLayout>
00077 #include <QKeyEvent>
00078 #include <QButtonGroup>
00079 
00080 // IDL includes
00081 #include <SALOMEconfig.h>
00082 #include CORBA_SERVER_HEADER(SMESH_Group)
00083 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00084 
00085 #define SPACING 6
00086 #define MARGIN  11
00087 
00094 class BusyLocker
00095 {
00096 public:
00098   BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
00100   ~BusyLocker() { myBusy = false; }
00101 private:
00102   bool& myBusy; 
00103 };
00104 
00105 
00106 //=================================================================================
00107 // function : SMESHGUI_SmoothingDlg()
00108 // purpose  : constructor
00109 //=================================================================================
00110 SMESHGUI_SmoothingDlg::SMESHGUI_SmoothingDlg( SMESHGUI* theModule )
00111   : QDialog( SMESH::GetDesktop( theModule ) ),
00112     mySMESHGUI( theModule ),
00113     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
00114     myFilterDlg(0),
00115     mySelectedObject(SMESH::SMESH_IDSource::_nil())
00116 {
00117   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_SMOOTHING")));
00118   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
00119 
00120   setModal(false);
00121   setAttribute(Qt::WA_DeleteOnClose, true);
00122   setWindowTitle(tr("SMESH_SMOOTHING"));
00123   setSizeGripEnabled(true);
00124 
00125   /***************************************************************/
00126   QVBoxLayout* SMESHGUI_SmoothingDlgLayout = new QVBoxLayout(this);
00127   SMESHGUI_SmoothingDlgLayout->setSpacing(SPACING);
00128   SMESHGUI_SmoothingDlgLayout->setMargin(MARGIN);
00129 
00130   /***************************************************************/
00131   GroupConstructors = new QGroupBox(tr("SMESH_SMOOTHING"), this);
00132   QButtonGroup* ButtonGroup = new QButtonGroup(this);
00133   QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
00134   GroupConstructorsLayout->setSpacing(SPACING);
00135   GroupConstructorsLayout->setMargin(MARGIN);
00136 
00137   Constructor1 = new QRadioButton(GroupConstructors);
00138   Constructor1->setIcon(image0);
00139   Constructor1->setChecked(true);
00140   GroupConstructorsLayout->addWidget(Constructor1);
00141   ButtonGroup->addButton(Constructor1, 0);
00142 
00143   /***************************************************************/
00144   GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
00145   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
00146   GroupArgumentsLayout->setSpacing(SPACING);
00147   GroupArgumentsLayout->setMargin(MARGIN);
00148 
00149   myIdValidator = new SMESHGUI_IdValidator(this);
00150 
00151   // Controls for elements selection
00152   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
00153 
00154   SelectElementsButton = new QPushButton(GroupArguments);
00155   SelectElementsButton->setIcon(image1);
00156 
00157   LineEditElements = new QLineEdit(GroupArguments);
00158   LineEditElements->setValidator(myIdValidator);
00159   LineEditElements->setMaxLength(-1);
00160   myElemFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
00161   connect(myElemFilterBtn,   SIGNAL(clicked()), this, SLOT(setElemFilters()));
00162 
00163   // Control for the whole mesh selection
00164   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
00165 
00166   // Controls for nodes selection
00167   TextLabelNodes = new QLabel(tr("FIXED_NODES_IDS"), GroupArguments);
00168 
00169   SelectNodesButton  = new QPushButton(GroupArguments);
00170   SelectNodesButton->setIcon(image1);
00171 
00172   LineEditNodes  = new QLineEdit(GroupArguments);
00173   LineEditNodes->setValidator(myIdValidator);
00174   LineEditNodes->setMaxLength(-1);
00175   QPushButton* filterNodeBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
00176   connect(filterNodeBtn,   SIGNAL(clicked()), this, SLOT(setNodeFilters()));
00177 
00178   // Controls for method selection
00179   TextLabelMethod = new QLabel(tr("METHOD"), GroupArguments);
00180 
00181   ComboBoxMethod = new QComboBox(GroupArguments);
00182 
00183   // Controls for iteration limit defining
00184   TextLabelLimit = new QLabel(tr("ITERATION_LIMIT"), GroupArguments);
00185 
00186   SpinBox_IterationLimit = new SalomeApp_IntSpinBox(GroupArguments);
00187 
00188   // Controls for max. aspect ratio defining
00189   TextLabelAspectRatio = new QLabel(tr("MAX_ASPECT_RATIO"), GroupArguments);
00190 
00191   SpinBox_AspectRatio = new SMESHGUI_SpinBox(GroupArguments);
00192 
00193   // Check box "Is Parametric"
00194   CheckBoxParametric = new QCheckBox( tr("IS_PARAMETRIC"), GroupArguments );
00195 
00196   GroupArgumentsLayout->addWidget(TextLabelElements,      0, 0);
00197   GroupArgumentsLayout->addWidget(SelectElementsButton,   0, 1);
00198   GroupArgumentsLayout->addWidget(LineEditElements,       0, 2);
00199   GroupArgumentsLayout->addWidget(myElemFilterBtn,        0, 3);
00200   GroupArgumentsLayout->addWidget(CheckBoxMesh,           1, 0, 1, 4);
00201   GroupArgumentsLayout->addWidget(TextLabelNodes,         2, 0);
00202   GroupArgumentsLayout->addWidget(SelectNodesButton,      2, 1);
00203   GroupArgumentsLayout->addWidget(LineEditNodes,          2, 2);
00204   GroupArgumentsLayout->addWidget(filterNodeBtn,          2, 3);
00205   GroupArgumentsLayout->addWidget(TextLabelMethod,        3, 0);
00206   GroupArgumentsLayout->addWidget(ComboBoxMethod,         3, 2, 1, 2);
00207   GroupArgumentsLayout->addWidget(TextLabelLimit,         4, 0);
00208   GroupArgumentsLayout->addWidget(SpinBox_IterationLimit, 4, 2, 1, 2);
00209   GroupArgumentsLayout->addWidget(TextLabelAspectRatio,   5, 0);
00210   GroupArgumentsLayout->addWidget(SpinBox_AspectRatio,    5, 2, 1, 2);
00211   GroupArgumentsLayout->addWidget(CheckBoxParametric,     6, 0, 1, 4);
00212 
00213   /***************************************************************/
00214   GroupButtons = new QGroupBox(this);
00215   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
00216   GroupButtonsLayout->setSpacing(SPACING);
00217   GroupButtonsLayout->setMargin(MARGIN);
00218 
00219   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
00220   buttonOk->setAutoDefault(true);
00221   buttonOk->setDefault(true);
00222   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
00223   buttonApply->setAutoDefault(true);
00224   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
00225   buttonCancel->setAutoDefault(true);
00226   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
00227   buttonHelp->setAutoDefault(true);
00228 
00229   GroupButtonsLayout->addWidget(buttonOk);
00230   GroupButtonsLayout->addSpacing(10);
00231   GroupButtonsLayout->addWidget(buttonApply);
00232   GroupButtonsLayout->addSpacing(10);
00233   GroupButtonsLayout->addStretch();
00234   GroupButtonsLayout->addWidget(buttonCancel);
00235   GroupButtonsLayout->addWidget(buttonHelp);
00236 
00237   /***************************************************************/
00238   SMESHGUI_SmoothingDlgLayout->addWidget(GroupConstructors);
00239   SMESHGUI_SmoothingDlgLayout->addWidget(GroupArguments);
00240   SMESHGUI_SmoothingDlgLayout->addWidget(GroupButtons);
00241 
00242   /***************************************************************/
00243   /* Initialisations */
00244   ComboBoxMethod->addItem(tr("LAPLACIAN"));
00245   ComboBoxMethod->addItem(tr("CENTROIDAL"));
00246 
00247   ComboBoxMethod->setCurrentIndex(0);
00248 
00249   CheckBoxParametric->setChecked( true );
00250   
00251   SpinBox_IterationLimit->setRange(1, 999999);
00252   SpinBox_IterationLimit->setValue(20);
00253   SpinBox_AspectRatio->RangeStepAndValidator(0.0, +999999.999, 0.1, "parametric_precision");
00254   SpinBox_AspectRatio->SetValue(1.1);
00255 
00256   GroupArguments->show();
00257   myConstructorId = 0;
00258   Constructor1->setChecked(true);
00259   
00260   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
00261 
00262   mySMESHGUI->SetActiveDialogBox(this);
00263 
00264   // Costruction of the logical filter for the elements: mesh/sub-mesh/group
00265   QList<SUIT_SelectionFilter*> aListOfFilters;
00266   aListOfFilters << new SMESH_TypeFilter(MESHorSUBMESH) << new SMESH_TypeFilter(GROUP);
00267 
00268   myMeshOrSubMeshOrGroupFilter =
00269     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
00270 
00271   myHelpFileName = "smoothing_page.html";
00272 
00273   Init();
00274 
00275   /***************************************************************/
00276   // signals and slots connections
00277   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
00278   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
00279   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
00280   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
00281 
00282   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
00283   connect(SelectNodesButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
00284   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
00285   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00286   /* to close dialog if study change */
00287   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
00288   connect(LineEditElements, SIGNAL(textChanged(const QString&)),
00289            SLOT(onTextChange(const QString&)));
00290   connect(LineEditNodes, SIGNAL(textChanged(const QString&)),
00291            SLOT(onTextChange(const QString&)));
00292   connect(CheckBoxMesh, SIGNAL(toggled(bool)),
00293            SLOT(onSelectMesh(bool)));
00294 }
00295 
00296 //=================================================================================
00297 // function : ~SMESHGUI_SmoothingDlg()
00298 // purpose  : destructor
00299 //=================================================================================
00300 SMESHGUI_SmoothingDlg::~SMESHGUI_SmoothingDlg()
00301 {
00302   // no need to delete child widgets, Qt does it all for us
00303   if ( myFilterDlg != 0 ) {
00304     myFilterDlg->setParent( 0 );
00305     delete myFilterDlg;
00306   }
00307 }
00308 
00309 //=================================================================================
00310 // function : Init()
00311 // purpose  : initialization
00312 //=================================================================================
00313 void SMESHGUI_SmoothingDlg::Init()
00314 {
00315   myBusy = false;
00316 
00317 //   ComboBoxMethod->setCurrentItem(0);
00318 
00319 //   SpinBox_IterationLimit->setValue(20);
00320 //   SpinBox_AspectRatio->SetValue(1.1);
00321 
00322   myEditCurrentArgument = LineEditElements;
00323   LineEditElements->setFocus();
00324   LineEditElements->clear();
00325   LineEditNodes->clear();
00326   myNbOkElements = 0;
00327   myNbOkNodes = 0;
00328   myActor     = 0;
00329   myIO.Nullify();
00330   myMesh = SMESH::SMESH_Mesh::_nil();
00331 
00332   CheckBoxMesh->setChecked(false);
00333   onSelectMesh(false);
00334 }
00335 
00336 //=================================================================================
00337 // function : ClickOnApply()
00338 // purpose  : Called when user presses <Apply> button
00339 //=================================================================================
00340 bool SMESHGUI_SmoothingDlg::ClickOnApply()
00341 {
00342   if (mySMESHGUI->isActiveStudyLocked())
00343     return false;
00344 
00345   if (!isValid())
00346     return false;
00347 
00348   if (myNbOkElements && (myNbOkNodes || LineEditNodes->text().trimmed().isEmpty())) {
00349     QStringList aListElementsId = LineEditElements->text().split(" ", QString::SkipEmptyParts);
00350     QStringList aListNodesId    = LineEditNodes->text().split(" ", QString::SkipEmptyParts);
00351 
00352     SMESH::long_array_var anElementsId = new SMESH::long_array;
00353     SMESH::long_array_var aNodesId = new SMESH::long_array;
00354 
00355     anElementsId->length(aListElementsId.count());
00356     for (int i = 0; i < aListElementsId.count(); i++)
00357       anElementsId[i] = aListElementsId[i].toInt();
00358 
00359     if ( myNbOkNodes && aListNodesId.count() > 0 ) {
00360       aNodesId->length(aListNodesId.count());
00361       for (int i = 0; i < aListNodesId.count(); i++)
00362         aNodesId[i] = aListNodesId[i].toInt();
00363     } else {
00364       aNodesId->length(0);
00365     }
00366 
00367     long anIterationLimit = (long)SpinBox_IterationLimit->value();
00368     double aMaxAspectRatio = SpinBox_AspectRatio->GetValue();
00369 
00370     QStringList aParameters;
00371     aParameters << SpinBox_IterationLimit->text();
00372     aParameters << SpinBox_AspectRatio->text();
00373 
00374     SMESH::SMESH_MeshEditor::Smooth_Method aMethod = SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH;
00375     if (ComboBoxMethod->currentIndex() > 0)
00376       aMethod =  SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH;
00377 
00378     bool aResult = false;
00379     try {
00380       SUIT_OverrideCursor aWaitCursor;
00381       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
00382 
00383       myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
00384 
00385       if ( CheckBoxParametric->isChecked() ) {
00386         if(CheckBoxMesh->isChecked())
00387           aResult = aMeshEditor->SmoothParametricObject(mySelectedObject, aNodesId.inout(),
00388                                                         anIterationLimit, aMaxAspectRatio, aMethod);
00389         else
00390           aResult = aMeshEditor->SmoothParametric(anElementsId.inout(), aNodesId.inout(),
00391                                                   anIterationLimit, aMaxAspectRatio, aMethod);
00392       }
00393       else {
00394         if(CheckBoxMesh->isChecked())
00395           aResult = aMeshEditor->SmoothObject(mySelectedObject, aNodesId.inout(),
00396                                               anIterationLimit, aMaxAspectRatio, aMethod);
00397         else
00398           aResult = aMeshEditor->Smooth(anElementsId.inout(), aNodesId.inout(),
00399                                         anIterationLimit, aMaxAspectRatio, aMethod);
00400       }
00401 
00402     } catch (...) {
00403     }
00404 
00405     if (aResult) {
00406       SMESH::Update(myIO, SMESH::eDisplay);
00407       SMESHGUI::Modified();
00408       Init();
00409 
00410       mySelectedObject = SMESH::SMESH_IDSource::_nil();
00411     }
00412   }
00413 
00414   return true;
00415 }
00416 
00417 //=================================================================================
00418 // function : ClickOnOk()
00419 // purpose  : Called when user presses <OK> button
00420 //=================================================================================
00421 void SMESHGUI_SmoothingDlg::ClickOnOk()
00422 {
00423   if( ClickOnApply() )
00424     ClickOnCancel();
00425 }
00426 
00427 //=================================================================================
00428 // function : ClickOnCancel()
00429 // purpose  : Called when dialog box is closed
00430 //=================================================================================
00431 void SMESHGUI_SmoothingDlg::ClickOnCancel()
00432 {
00433   disconnect(mySelectionMgr, 0, this, 0);
00434   mySelectionMgr->clearFilters();
00435   //mySelectionMgr->clearSelected();
00436   if (SMESH::GetCurrentVtkView()) {
00437     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
00438     SMESH::SetPointRepresentation(false);
00439     SMESH::SetPickable();
00440   }
00441   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00442     aViewWindow->SetSelectionMode(ActorSelection);
00443   mySMESHGUI->ResetState();
00444   reject();
00445 }
00446 
00447 //=================================================================================
00448 // function : ClickOnHelp()
00449 // purpose  :
00450 //=================================================================================
00451 void SMESHGUI_SmoothingDlg::ClickOnHelp()
00452 {
00453   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00454   if (app) 
00455     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00456   else {
00457     QString platform;
00458 #ifdef WIN32
00459     platform = "winapplication";
00460 #else
00461     platform = "application";
00462 #endif
00463     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00464                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00465                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
00466                                                                  platform)).
00467                              arg(myHelpFileName));
00468   }
00469 }
00470 
00471 //=======================================================================
00472 // function : onTextChange()
00473 // purpose  :
00474 //=======================================================================
00475 void SMESHGUI_SmoothingDlg::onTextChange (const QString& theNewText)
00476 {
00477   QLineEdit* send = (QLineEdit*)sender();
00478 
00479   // return if busy
00480   if (myBusy || myIO.IsNull()) return;
00481 
00482   // set busy flag
00483   BusyLocker lock( myBusy );
00484 
00485   if (send == LineEditElements)
00486     myNbOkElements = 0;
00487   else if (send == LineEditNodes)
00488     myNbOkNodes = 0;
00489 
00490   buttonOk->setEnabled(false);
00491   buttonApply->setEnabled(false);
00492 
00493   // hilight entered elements/nodes
00494   SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
00495   QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
00496 
00497   if (send == LineEditElements) {
00498     TColStd_MapOfInteger newIndices;
00499     for (int i = 0; i < aListId.count(); i++) {
00500       int id = aListId[ i ].toInt();
00501       if ( id > 0 ) {
00502         bool validId = aMesh ? ( aMesh->FindElement( id ) != 0 ) : ( myMesh->GetElementType( id, true ) != SMESH::EDGE );
00503         if ( validId ) 
00504           newIndices.Add( id );
00505       }
00506       myNbOkElements = newIndices.Extent();
00507       mySelector->AddOrRemoveIndex(myIO, newIndices, false);
00508       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00509         aViewWindow->highlight( myIO, true, true );
00510     }
00511   }
00512   else if (send == LineEditNodes) {
00513     TColStd_MapOfInteger newIndices;
00514     for (int i = 0; i < aListId.count(); i++) {
00515       int id = aListId[ i ].toInt();
00516       if ( id > 0 ) {
00517         bool validId = aMesh ? ( aMesh->FindNode( id ) != 0 ) : ( myMesh->GetElementType( id, false ) != SMESH::EDGE );
00518         if ( validId ) 
00519           newIndices.Add( id );
00520       }
00521       myNbOkNodes = newIndices.Extent();
00522       mySelector->AddOrRemoveIndex(myIO, newIndices, false);
00523       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00524         aViewWindow->highlight( myIO, true, true );
00525     }
00526   }
00527 
00528   if (myNbOkElements && (myNbOkNodes || LineEditNodes->text().trimmed().isEmpty())) {
00529     buttonOk->setEnabled(true);
00530     buttonApply->setEnabled(true);
00531   }
00532 }
00533 
00534 //=================================================================================
00535 // function : SelectionIntoArgument()
00536 // purpose  : Called when selection as changed or other case
00537 //=================================================================================
00538 void SMESHGUI_SmoothingDlg::SelectionIntoArgument()
00539 {
00540   if (myBusy) return;
00541 
00542   // clear
00543   QString aString = "";
00544 
00545   // set busy flag
00546   BusyLocker lock( myBusy );
00547 
00548   if (myEditCurrentArgument == LineEditElements ||
00549       myEditCurrentArgument == LineEditNodes) {
00550     myEditCurrentArgument->setText(aString);
00551     if (myEditCurrentArgument == LineEditElements) {
00552       myNbOkElements = 0;
00553       myActor = 0;
00554       myIO.Nullify();
00555     }
00556     else {
00557       myNbOkNodes = 0;
00558     }
00559     buttonOk->setEnabled(false);
00560     buttonApply->setEnabled(false);
00561   }
00562 
00563   if (!GroupButtons->isEnabled()) // inactive
00564     return;
00565 
00566   // get selected mesh
00567   SALOME_ListIO aList;
00568   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
00569   int nbSel = aList.Extent();
00570   if (nbSel != 1)
00571     return;
00572 
00573   Handle(SALOME_InteractiveObject) IO = aList.First();
00574 
00575   if (myEditCurrentArgument == LineEditElements) {
00576     myMesh = SMESH::GetMeshByIO(IO);
00577     if (myMesh->_is_nil())
00578       return;
00579     myIO = IO;
00580     myActor = SMESH::FindActorByObject(myMesh);
00581 
00582     if (CheckBoxMesh->isChecked()) {
00583       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
00584 
00585       SMESH::SMESH_IDSource_var obj = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( myIO );
00586       if ( !CORBA::is_nil( obj ) )
00587         mySelectedObject = obj;
00588       else
00589         return;
00590       myNbOkElements = true;
00591     } else {
00592       // get indices of selected elements
00593       TColStd_IndexedMapOfInteger aMapIndex;
00594       mySelector->GetIndex(IO,aMapIndex);
00595       myNbOkElements = aMapIndex.Extent();
00596 
00597       if (myNbOkElements < 1)
00598         return;
00599       
00600       QStringList elements;
00601       for ( int i = 0; i < myNbOkElements; ++i )
00602         elements << QString::number( aMapIndex( i+1 ) );
00603       aString = elements.join(" ");
00604     }
00605   } else if (myEditCurrentArgument == LineEditNodes && !myMesh->_is_nil() && myIO == IO ) {
00606     myNbOkNodes = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
00607   }
00608 
00609   myEditCurrentArgument->setText(aString);
00610   myEditCurrentArgument->repaint();
00611   myEditCurrentArgument->setEnabled(false); // to update lineedit IPAL 19809
00612   myEditCurrentArgument->setEnabled(true); 
00613 
00614   if (myNbOkElements && (myNbOkNodes || LineEditNodes->text().trimmed().isEmpty())) {
00615     buttonOk->setEnabled(true);
00616     buttonApply->setEnabled(true);
00617   }
00618 }
00619 
00620 //=================================================================================
00621 // function : SetEditCurrentArgument()
00622 // purpose  :
00623 //=================================================================================
00624 void SMESHGUI_SmoothingDlg::SetEditCurrentArgument()
00625 {
00626   QPushButton* send = (QPushButton*)sender();
00627 
00628   switch (myConstructorId) {
00629   case 0: /* default constructor */
00630     {
00631       disconnect(mySelectionMgr, 0, this, 0);
00632       mySelectionMgr->clearSelected();
00633       mySelectionMgr->clearFilters();
00634 
00635       if (send == SelectElementsButton) {
00636         myEditCurrentArgument = LineEditElements;
00637         SMESH::SetPointRepresentation(false);
00638         if (CheckBoxMesh->isChecked()) {
00639           //          mySelectionMgr->setSelectionModes(ActorSelection);
00640           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00641             aViewWindow->SetSelectionMode(ActorSelection);
00642           mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
00643         } else {
00644           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00645             aViewWindow->SetSelectionMode(FaceSelection);
00646         }
00647       } else if (send == SelectNodesButton) {
00648         LineEditNodes->clear();
00649         myEditCurrentArgument = LineEditNodes;
00650         SMESH::SetPointRepresentation(true);
00651         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) {
00652           aViewWindow->SetSelectionMode(NodeSelection);
00653         }
00654       }
00655 
00656       myEditCurrentArgument->setFocus();
00657       connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00658       SelectionIntoArgument();
00659       break;
00660     }
00661   }
00662 }
00663 
00664 //=================================================================================
00665 // function : DeactivateActiveDialog()
00666 // purpose  : Deactivates this dialog
00667 //=================================================================================
00668 void SMESHGUI_SmoothingDlg::DeactivateActiveDialog()
00669 {
00670   if (GroupConstructors->isEnabled()) {
00671     GroupConstructors->setEnabled(false);
00672     GroupArguments->setEnabled(false);
00673     GroupButtons->setEnabled(false);
00674     mySMESHGUI->ResetState();
00675     mySMESHGUI->SetActiveDialogBox(0);
00676   }
00677 }
00678 
00679 //=================================================================================
00680 // function : ActivateThisDialog()
00681 // purpose  : Activates this dialog
00682 //=================================================================================
00683 void SMESHGUI_SmoothingDlg::ActivateThisDialog()
00684 {
00685   // Emit a signal to deactivate the active dialog
00686   mySMESHGUI->EmitSignalDeactivateDialog();
00687   GroupConstructors->setEnabled(true);
00688   GroupArguments->setEnabled(true);
00689   GroupButtons->setEnabled(true);
00690 
00691   mySMESHGUI->SetActiveDialogBox(this);
00692   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00693     aViewWindow->SetSelectionMode(FaceSelection);
00694   SelectionIntoArgument();
00695 }
00696 
00697 //=================================================================================
00698 // function : enterEvent()
00699 // purpose  : Mouse enter event
00700 //=================================================================================
00701 void SMESHGUI_SmoothingDlg::enterEvent (QEvent*)
00702 {
00703   if (!GroupConstructors->isEnabled())
00704     ActivateThisDialog();
00705 }
00706 
00707 //=================================================================================
00708 // function : closeEvent()
00709 // purpose  :
00710 //=================================================================================
00711 void SMESHGUI_SmoothingDlg::closeEvent (QCloseEvent*)
00712 {
00713   /* same than click on cancel button */
00714   ClickOnCancel();
00715 }
00716 
00717 //=======================================================================
00718 // function : hideEvent()
00719 // purpose  : caused by ESC key
00720 //=======================================================================
00721 void SMESHGUI_SmoothingDlg::hideEvent (QHideEvent*)
00722 {
00723   if (!isMinimized())
00724     ClickOnCancel();
00725 }
00726 
00727 //=======================================================================
00728 // function : onSelectMesh()
00729 // purpose  :
00730 //=======================================================================
00731 void SMESHGUI_SmoothingDlg::onSelectMesh (bool toSelectMesh)
00732 {
00733   if (toSelectMesh)
00734     TextLabelElements->setText(tr("SMESH_NAME"));
00735   else
00736     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
00737   myElemFilterBtn->setEnabled(!toSelectMesh);
00738 
00739   if (myEditCurrentArgument != LineEditElements &&
00740       myEditCurrentArgument != LineEditNodes) {
00741     LineEditElements->clear();
00742     LineEditNodes->clear();
00743     return;
00744   }
00745 
00746   mySelectionMgr->clearFilters();
00747   SMESH::SetPointRepresentation(false);
00748 
00749   if (toSelectMesh) {
00750     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00751       aViewWindow->SetSelectionMode(ActorSelection);
00752     //    mySelectionMgr->setSelectionModes(ActorSelection);
00753     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
00754     myEditCurrentArgument->setReadOnly(true);
00755     myEditCurrentArgument->setValidator(0);
00756   } else {
00757     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00758       aViewWindow->SetSelectionMode(myEditCurrentArgument == LineEditElements ? FaceSelection 
00759                                                                               : NodeSelection );
00760     myEditCurrentArgument->setReadOnly(false);
00761     LineEditElements->setValidator(myIdValidator);
00762     onTextChange(myEditCurrentArgument->text());
00763   }
00764 
00765   SelectionIntoArgument();
00766 }
00767 
00768 //=================================================================================
00769 // function : keyPressEvent()
00770 // purpose  :
00771 //=================================================================================
00772 void SMESHGUI_SmoothingDlg::keyPressEvent( QKeyEvent* e )
00773 {
00774   QDialog::keyPressEvent( e );
00775   if ( e->isAccepted() )
00776     return;
00777 
00778   if ( e->key() == Qt::Key_F1 ) {
00779     e->accept();
00780     ClickOnHelp();
00781   }
00782 }
00783 
00784 //=================================================================================
00785 // function : setFilters()
00786 // purpose  : activate filter dialog
00787 //=================================================================================
00788 void SMESHGUI_SmoothingDlg::setFilters( const bool theIsElem )
00789 {
00790   if(myMesh->_is_nil()) {
00791     SUIT_MessageBox::critical(this,
00792                               tr("SMESH_ERROR"),
00793                               tr("NO_MESH_SELECTED"));
00794    return;
00795   }
00796   if ( !myFilterDlg )
00797   {
00798     QList<int> types;  
00799     types.append( SMESH::NODE );
00800     types.append( SMESH::ALL );
00801     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
00802   }
00803   myFilterDlg->Init( theIsElem ? SMESH::ALL : SMESH::NODE );
00804 
00805   myFilterDlg->SetSelection();
00806   myFilterDlg->SetMesh( myMesh );
00807   myFilterDlg->SetSourceWg( theIsElem ? LineEditElements : LineEditNodes );
00808 
00809   myFilterDlg->show();
00810 }
00811 
00812 //=================================================================================
00813 // function : setElemFilters()
00814 // purpose  : SLOT. Called when element "Filter" button pressed.
00815 //=================================================================================
00816 void SMESHGUI_SmoothingDlg::setElemFilters()
00817 {
00818   setFilters( true );
00819 }
00820 
00821 //=================================================================================
00822 // function : setNodeFilters()
00823 // purpose  : SLOT. Called when node "Filter" button pressed.
00824 //=================================================================================
00825 void SMESHGUI_SmoothingDlg::setNodeFilters()
00826 {
00827   setFilters( false );
00828 }
00829 
00830 //=================================================================================
00831 // function : isValid
00832 // purpose  :
00833 //=================================================================================
00834 bool SMESHGUI_SmoothingDlg::isValid()
00835 {
00836   QString msg;
00837   bool ok = true;
00838   ok = SpinBox_IterationLimit->isValid( msg, true ) && ok;
00839   ok = SpinBox_AspectRatio->isValid( msg, true ) && ok;
00840 
00841   if( !ok ) {
00842     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
00843     if ( !msg.isEmpty() )
00844       str += "\n" + msg;
00845     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
00846     return false;
00847   }
00848   return true;
00849 }