Salome HOME
imn/auto-reorder_of_nodes_ver2
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_SmoothingDlg.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_SmoothingDlg.cxx
25 // Author : Michael ZORIN, Open CASCADE S.A.S.
26 // SMESH includes
27 //
28 #include "SMESHGUI_SmoothingDlg.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_SpinBox.h"
35 #include "SMESHGUI_IdValidator.h"
36 #include "SMESHGUI_FilterDlg.h"
37
38 #include <SMESH_Actor.h>
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESH_LogicalFilter.hxx>
41
42 #include <SMDS_Mesh.hxx>
43
44 // SALOME GUI includes
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_OverrideCursor.h>
47 #include <SUIT_Desktop.h>
48 #include <SUIT_Session.h>
49 #include <SUIT_MessageBox.h>
50
51 #include <LightApp_Application.h>
52 #include <LightApp_SelectionMgr.h>
53
54 #include <SalomeApp_IntSpinBox.h>
55
56 #include <SVTK_ViewModel.h>
57 #include <SVTK_Selector.h>
58 #include <SVTK_ViewWindow.h>
59 #include <SVTK_Selection.h>
60 #include <SALOME_ListIO.hxx>
61
62 // OCCT includes
63 #include <TColStd_MapOfInteger.hxx>
64
65 // Qt includes
66 #include <QApplication>
67 #include <QGroupBox>
68 #include <QLabel>
69 #include <QLineEdit>
70 #include <QPushButton>
71 #include <QRadioButton>
72 #include <QComboBox>
73 #include <QCheckBox>
74 #include <QHBoxLayout>
75 #include <QVBoxLayout>
76 #include <QGridLayout>
77 #include <QKeyEvent>
78 #include <QButtonGroup>
79
80 // IDL includes
81 #include <SALOMEconfig.h>
82 #include CORBA_SERVER_HEADER(SMESH_Group)
83 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
84
85 #define SPACING 6
86 #define MARGIN  11
87
88 /*!
89   \class BusyLocker
90   \brief Simple 'busy state' flag locker.
91   \internal
92 */
93
94 class BusyLocker
95 {
96 public:
97   //! Constructor. Sets passed boolean flag to \c true.
98   BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
99   //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
100   ~BusyLocker() { myBusy = false; }
101 private:
102   bool& myBusy; //! External 'busy state' boolean flag
103 };
104
105
106 //=================================================================================
107 // function : SMESHGUI_SmoothingDlg()
108 // purpose  : constructor
109 //=================================================================================
110 SMESHGUI_SmoothingDlg::SMESHGUI_SmoothingDlg( SMESHGUI* theModule )
111   : QDialog( SMESH::GetDesktop( theModule ) ),
112     mySMESHGUI( theModule ),
113     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
114     myFilterDlg(0),
115     mySelectedObject(SMESH::SMESH_IDSource::_nil())
116 {
117   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_SMOOTHING")));
118   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
119
120   setModal(false);
121   setAttribute(Qt::WA_DeleteOnClose, true);
122   setWindowTitle(tr("SMESH_SMOOTHING"));
123   setSizeGripEnabled(true);
124
125   /***************************************************************/
126   QVBoxLayout* SMESHGUI_SmoothingDlgLayout = new QVBoxLayout(this);
127   SMESHGUI_SmoothingDlgLayout->setSpacing(SPACING);
128   SMESHGUI_SmoothingDlgLayout->setMargin(MARGIN);
129
130   /***************************************************************/
131   GroupConstructors = new QGroupBox(tr("SMESH_SMOOTHING"), this);
132   QButtonGroup* ButtonGroup = new QButtonGroup(this);
133   QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
134   GroupConstructorsLayout->setSpacing(SPACING);
135   GroupConstructorsLayout->setMargin(MARGIN);
136
137   Constructor1 = new QRadioButton(GroupConstructors);
138   Constructor1->setIcon(image0);
139   Constructor1->setChecked(true);
140   GroupConstructorsLayout->addWidget(Constructor1);
141   ButtonGroup->addButton(Constructor1, 0);
142
143   /***************************************************************/
144   GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
145   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
146   GroupArgumentsLayout->setSpacing(SPACING);
147   GroupArgumentsLayout->setMargin(MARGIN);
148
149   myIdValidator = new SMESHGUI_IdValidator(this);
150
151   // Controls for elements selection
152   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
153
154   SelectElementsButton = new QPushButton(GroupArguments);
155   SelectElementsButton->setIcon(image1);
156
157   LineEditElements = new QLineEdit(GroupArguments);
158   LineEditElements->setValidator(myIdValidator);
159   LineEditElements->setMaxLength(-1);
160   myElemFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
161   connect(myElemFilterBtn,   SIGNAL(clicked()), this, SLOT(setElemFilters()));
162
163   // Control for the whole mesh selection
164   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
165
166   // Controls for nodes selection
167   TextLabelNodes = new QLabel(tr("FIXED_NODES_IDS"), GroupArguments);
168
169   SelectNodesButton  = new QPushButton(GroupArguments);
170   SelectNodesButton->setIcon(image1);
171
172   LineEditNodes  = new QLineEdit(GroupArguments);
173   LineEditNodes->setValidator(myIdValidator);
174   LineEditNodes->setMaxLength(-1);
175   QPushButton* filterNodeBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
176   connect(filterNodeBtn,   SIGNAL(clicked()), this, SLOT(setNodeFilters()));
177
178   // Controls for method selection
179   TextLabelMethod = new QLabel(tr("METHOD"), GroupArguments);
180
181   ComboBoxMethod = new QComboBox(GroupArguments);
182
183   // Controls for iteration limit defining
184   TextLabelLimit = new QLabel(tr("ITERATION_LIMIT"), GroupArguments);
185
186   SpinBox_IterationLimit = new SalomeApp_IntSpinBox(GroupArguments);
187
188   // Controls for max. aspect ratio defining
189   TextLabelAspectRatio = new QLabel(tr("MAX_ASPECT_RATIO"), GroupArguments);
190
191   SpinBox_AspectRatio = new SMESHGUI_SpinBox(GroupArguments);
192
193   // Check box "Is Parametric"
194   CheckBoxParametric = new QCheckBox( tr("IS_PARAMETRIC"), GroupArguments );
195
196   GroupArgumentsLayout->addWidget(TextLabelElements,      0, 0);
197   GroupArgumentsLayout->addWidget(SelectElementsButton,   0, 1);
198   GroupArgumentsLayout->addWidget(LineEditElements,       0, 2);
199   GroupArgumentsLayout->addWidget(myElemFilterBtn,        0, 3);
200   GroupArgumentsLayout->addWidget(CheckBoxMesh,           1, 0, 1, 4);
201   GroupArgumentsLayout->addWidget(TextLabelNodes,         2, 0);
202   GroupArgumentsLayout->addWidget(SelectNodesButton,      2, 1);
203   GroupArgumentsLayout->addWidget(LineEditNodes,          2, 2);
204   GroupArgumentsLayout->addWidget(filterNodeBtn,          2, 3);
205   GroupArgumentsLayout->addWidget(TextLabelMethod,        3, 0);
206   GroupArgumentsLayout->addWidget(ComboBoxMethod,         3, 2, 1, 2);
207   GroupArgumentsLayout->addWidget(TextLabelLimit,         4, 0);
208   GroupArgumentsLayout->addWidget(SpinBox_IterationLimit, 4, 2, 1, 2);
209   GroupArgumentsLayout->addWidget(TextLabelAspectRatio,   5, 0);
210   GroupArgumentsLayout->addWidget(SpinBox_AspectRatio,    5, 2, 1, 2);
211   GroupArgumentsLayout->addWidget(CheckBoxParametric,     6, 0, 1, 4);
212
213   /***************************************************************/
214   GroupButtons = new QGroupBox(this);
215   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
216   GroupButtonsLayout->setSpacing(SPACING);
217   GroupButtonsLayout->setMargin(MARGIN);
218
219   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
220   buttonOk->setAutoDefault(true);
221   buttonOk->setDefault(true);
222   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
223   buttonApply->setAutoDefault(true);
224   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
225   buttonCancel->setAutoDefault(true);
226   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
227   buttonHelp->setAutoDefault(true);
228
229   GroupButtonsLayout->addWidget(buttonOk);
230   GroupButtonsLayout->addSpacing(10);
231   GroupButtonsLayout->addWidget(buttonApply);
232   GroupButtonsLayout->addSpacing(10);
233   GroupButtonsLayout->addStretch();
234   GroupButtonsLayout->addWidget(buttonCancel);
235   GroupButtonsLayout->addWidget(buttonHelp);
236
237   /***************************************************************/
238   SMESHGUI_SmoothingDlgLayout->addWidget(GroupConstructors);
239   SMESHGUI_SmoothingDlgLayout->addWidget(GroupArguments);
240   SMESHGUI_SmoothingDlgLayout->addWidget(GroupButtons);
241
242   /***************************************************************/
243   /* Initialisations */
244   ComboBoxMethod->addItem(tr("LAPLACIAN"));
245   ComboBoxMethod->addItem(tr("CENTROIDAL"));
246
247   ComboBoxMethod->setCurrentIndex(0);
248
249   CheckBoxParametric->setChecked( true );
250   
251   SpinBox_IterationLimit->setRange(1, 999999);
252   SpinBox_IterationLimit->setValue(20);
253   SpinBox_AspectRatio->RangeStepAndValidator(0.0, +999999.999, 0.1, "parametric_precision");
254   SpinBox_AspectRatio->SetValue(1.1);
255
256   GroupArguments->show();
257   myConstructorId = 0;
258   Constructor1->setChecked(true);
259   
260   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
261
262   mySMESHGUI->SetActiveDialogBox(this);
263
264   // Costruction of the logical filter for the elements: mesh/sub-mesh/group
265   QList<SUIT_SelectionFilter*> aListOfFilters;
266   aListOfFilters << new SMESH_TypeFilter(SMESH::MESHorSUBMESH) << new SMESH_TypeFilter(SMESH::GROUP);
267
268   myMeshOrSubMeshOrGroupFilter =
269     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
270
271   myHelpFileName = "smoothing_page.html";
272
273   Init();
274
275   /***************************************************************/
276   // signals and slots connections
277   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
278   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
279   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
280   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
281
282   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
283   connect(SelectNodesButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
284   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
285   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
286   /* to close dialog if study change */
287   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
288   connect(LineEditElements, SIGNAL(textChanged(const QString&)),
289            SLOT(onTextChange(const QString&)));
290   connect(LineEditNodes, SIGNAL(textChanged(const QString&)),
291            SLOT(onTextChange(const QString&)));
292   connect(CheckBoxMesh, SIGNAL(toggled(bool)),
293            SLOT(onSelectMesh(bool)));
294 }
295
296 //=================================================================================
297 // function : ~SMESHGUI_SmoothingDlg()
298 // purpose  : destructor
299 //=================================================================================
300 SMESHGUI_SmoothingDlg::~SMESHGUI_SmoothingDlg()
301 {
302   // no need to delete child widgets, Qt does it all for us
303   if ( myFilterDlg != 0 ) {
304     myFilterDlg->setParent( 0 );
305     delete myFilterDlg;
306   }
307 }
308
309 //=================================================================================
310 // function : Init()
311 // purpose  : initialization
312 //=================================================================================
313 void SMESHGUI_SmoothingDlg::Init()
314 {
315   myBusy = false;
316
317 //   ComboBoxMethod->setCurrentItem(0);
318
319 //   SpinBox_IterationLimit->setValue(20);
320 //   SpinBox_AspectRatio->SetValue(1.1);
321
322   myEditCurrentArgument = LineEditElements;
323   LineEditElements->setFocus();
324   LineEditElements->clear();
325   LineEditNodes->clear();
326   myNbOkElements = 0;
327   myNbOkNodes = 0;
328   myActor     = 0;
329   myIO.Nullify();
330   myMesh = SMESH::SMESH_Mesh::_nil();
331
332   CheckBoxMesh->setChecked(false);
333   onSelectMesh(false);
334 }
335
336 //=================================================================================
337 // function : ClickOnApply()
338 // purpose  : Called when user presses <Apply> button
339 //=================================================================================
340 bool SMESHGUI_SmoothingDlg::ClickOnApply()
341 {
342   if (mySMESHGUI->isActiveStudyLocked())
343     return false;
344
345   if (!isValid())
346     return false;
347
348   if (myNbOkElements && (myNbOkNodes || LineEditNodes->text().trimmed().isEmpty())) {
349     QStringList aListElementsId = LineEditElements->text().split(" ", QString::SkipEmptyParts);
350     QStringList aListNodesId    = LineEditNodes->text().split(" ", QString::SkipEmptyParts);
351
352     SMESH::long_array_var anElementsId = new SMESH::long_array;
353     SMESH::long_array_var aNodesId = new SMESH::long_array;
354
355     anElementsId->length(aListElementsId.count());
356     for (int i = 0; i < aListElementsId.count(); i++)
357       anElementsId[i] = aListElementsId[i].toInt();
358
359     if ( myNbOkNodes && aListNodesId.count() > 0 ) {
360       aNodesId->length(aListNodesId.count());
361       for (int i = 0; i < aListNodesId.count(); i++)
362         aNodesId[i] = aListNodesId[i].toInt();
363     } else {
364       aNodesId->length(0);
365     }
366
367     long anIterationLimit = (long)SpinBox_IterationLimit->value();
368     double aMaxAspectRatio = SpinBox_AspectRatio->GetValue();
369
370     QStringList aParameters;
371     aParameters << SpinBox_IterationLimit->text();
372     aParameters << SpinBox_AspectRatio->text();
373
374     SMESH::SMESH_MeshEditor::Smooth_Method aMethod = SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH;
375     if (ComboBoxMethod->currentIndex() > 0)
376       aMethod =  SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH;
377
378     bool aResult = false;
379     try {
380       SUIT_OverrideCursor aWaitCursor;
381       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
382
383       myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
384
385       if ( CheckBoxParametric->isChecked() ) {
386         if(CheckBoxMesh->isChecked())
387           aResult = aMeshEditor->SmoothParametricObject(mySelectedObject, aNodesId.inout(),
388                                                         anIterationLimit, aMaxAspectRatio, aMethod);
389         else
390           aResult = aMeshEditor->SmoothParametric(anElementsId.inout(), aNodesId.inout(),
391                                                   anIterationLimit, aMaxAspectRatio, aMethod);
392       }
393       else {
394         if(CheckBoxMesh->isChecked())
395           aResult = aMeshEditor->SmoothObject(mySelectedObject, aNodesId.inout(),
396                                               anIterationLimit, aMaxAspectRatio, aMethod);
397         else
398           aResult = aMeshEditor->Smooth(anElementsId.inout(), aNodesId.inout(),
399                                         anIterationLimit, aMaxAspectRatio, aMethod);
400       }
401
402     } catch (...) {
403     }
404
405     if (aResult) {
406       SMESH::Update(myIO, SMESH::eDisplay);
407       SMESHGUI::Modified();
408       Init();
409
410       mySelectedObject = SMESH::SMESH_IDSource::_nil();
411     }
412   }
413
414   return true;
415 }
416
417 //=================================================================================
418 // function : ClickOnOk()
419 // purpose  : Called when user presses <OK> button
420 //=================================================================================
421 void SMESHGUI_SmoothingDlg::ClickOnOk()
422 {
423   if( ClickOnApply() )
424     reject();
425 }
426
427 //=================================================================================
428 // function : reject()
429 // purpose  : Called when dialog box is closed
430 //=================================================================================
431 void SMESHGUI_SmoothingDlg::reject()
432 {
433   disconnect(mySelectionMgr, 0, this, 0);
434   mySelectionMgr->clearFilters();
435   //mySelectionMgr->clearSelected();
436   if (SMESH::GetCurrentVtkView()) {
437     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
438     SMESH::SetPointRepresentation(false);
439     SMESH::SetPickable();
440   }
441   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
442     aViewWindow->SetSelectionMode(ActorSelection);
443   mySMESHGUI->ResetState();
444   QDialog::reject();
445 }
446
447 //=================================================================================
448 // function : ClickOnHelp()
449 // purpose  :
450 //=================================================================================
451 void SMESHGUI_SmoothingDlg::ClickOnHelp()
452 {
453   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
454   if (app) 
455     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
456   else {
457     QString platform;
458 #ifdef WIN32
459     platform = "winapplication";
460 #else
461     platform = "application";
462 #endif
463     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
464                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
465                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
466                                                                  platform)).
467                              arg(myHelpFileName));
468   }
469 }
470
471 //=======================================================================
472 // function : onTextChange()
473 // purpose  :
474 //=======================================================================
475 void SMESHGUI_SmoothingDlg::onTextChange (const QString& theNewText)
476 {
477   QLineEdit* send = (QLineEdit*)sender();
478
479   // return if busy
480   if (myBusy || myIO.IsNull()) return;
481
482   // set busy flag
483   BusyLocker lock( myBusy );
484
485   if (send == LineEditElements)
486     myNbOkElements = 0;
487   else if (send == LineEditNodes)
488     myNbOkNodes = 0;
489
490   buttonOk->setEnabled(false);
491   buttonApply->setEnabled(false);
492
493   // hilight entered elements/nodes
494   SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
495   QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
496
497   if (send == LineEditElements) {
498     TColStd_MapOfInteger newIndices;
499     for (int i = 0; i < aListId.count(); i++) {
500       int id = aListId[ i ].toInt();
501       if ( id > 0 ) {
502         bool validId = aMesh ? ( aMesh->FindElement( id ) != 0 ) : ( myMesh->GetElementType( id, true ) != SMESH::EDGE );
503         if ( validId ) 
504           newIndices.Add( id );
505       }
506       myNbOkElements = newIndices.Extent();
507       mySelector->AddOrRemoveIndex(myIO, newIndices, false);
508       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
509         aViewWindow->highlight( myIO, true, true );
510     }
511   }
512   else if (send == LineEditNodes) {
513     TColStd_MapOfInteger newIndices;
514     for (int i = 0; i < aListId.count(); i++) {
515       int id = aListId[ i ].toInt();
516       if ( id > 0 ) {
517         bool validId = aMesh ? ( aMesh->FindNode( id ) != 0 ) : ( myMesh->GetElementType( id, false ) != SMESH::EDGE );
518         if ( validId ) 
519           newIndices.Add( id );
520       }
521       myNbOkNodes = newIndices.Extent();
522       mySelector->AddOrRemoveIndex(myIO, newIndices, false);
523       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
524         aViewWindow->highlight( myIO, true, true );
525     }
526   }
527
528   if (myNbOkElements && (myNbOkNodes || LineEditNodes->text().trimmed().isEmpty())) {
529     buttonOk->setEnabled(true);
530     buttonApply->setEnabled(true);
531   }
532 }
533
534 //=================================================================================
535 // function : SelectionIntoArgument()
536 // purpose  : Called when selection as changed or other case
537 //=================================================================================
538 void SMESHGUI_SmoothingDlg::SelectionIntoArgument()
539 {
540   if (myBusy) return;
541
542   // clear
543   QString aString = "";
544
545   // set busy flag
546   BusyLocker lock( myBusy );
547
548   if (myEditCurrentArgument == LineEditElements ||
549       myEditCurrentArgument == LineEditNodes) {
550     myEditCurrentArgument->setText(aString);
551     if (myEditCurrentArgument == LineEditElements) {
552       myNbOkElements = 0;
553       myActor = 0;
554       myIO.Nullify();
555     }
556     else {
557       myNbOkNodes = 0;
558     }
559     buttonOk->setEnabled(false);
560     buttonApply->setEnabled(false);
561   }
562
563   if (!GroupButtons->isEnabled()) // inactive
564     return;
565
566   // get selected mesh
567   SALOME_ListIO aList;
568   mySelectionMgr->selectedObjects(aList);
569   int nbSel = aList.Extent();
570   if (nbSel != 1)
571     return;
572
573   Handle(SALOME_InteractiveObject) IO = aList.First();
574
575   if (myEditCurrentArgument == LineEditElements) {
576     myMesh = SMESH::GetMeshByIO(IO);
577     if (myMesh->_is_nil())
578       return;
579     myIO = IO;
580     myActor = SMESH::FindActorByObject(myMesh);
581
582     if (CheckBoxMesh->isChecked()) {
583       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
584
585       SMESH::SMESH_IDSource_var obj = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( myIO );
586       if ( !CORBA::is_nil( obj ) )
587         mySelectedObject = obj;
588       else
589         return;
590       myNbOkElements = true;
591     } else {
592       // get indices of selected elements
593       TColStd_IndexedMapOfInteger aMapIndex;
594       mySelector->GetIndex(IO,aMapIndex);
595       myNbOkElements = aMapIndex.Extent();
596
597       if (myNbOkElements < 1)
598         return;
599       
600       QStringList elements;
601       for ( int i = 0; i < myNbOkElements; ++i )
602         elements << QString::number( aMapIndex( i+1 ) );
603       aString = elements.join(" ");
604     }
605   } else if (myEditCurrentArgument == LineEditNodes && !myMesh->_is_nil() && myIO == IO ) {
606     myNbOkNodes = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
607   }
608
609   myEditCurrentArgument->setText(aString);
610   myEditCurrentArgument->repaint();
611   myEditCurrentArgument->setEnabled(false); // to update lineedit IPAL 19809
612   myEditCurrentArgument->setEnabled(true); 
613
614   if (myNbOkElements && (myNbOkNodes || LineEditNodes->text().trimmed().isEmpty())) {
615     buttonOk->setEnabled(true);
616     buttonApply->setEnabled(true);
617   }
618 }
619
620 //=================================================================================
621 // function : SetEditCurrentArgument()
622 // purpose  :
623 //=================================================================================
624 void SMESHGUI_SmoothingDlg::SetEditCurrentArgument()
625 {
626   QPushButton* send = (QPushButton*)sender();
627
628   switch (myConstructorId) {
629   case 0: /* default constructor */
630     {
631       disconnect(mySelectionMgr, 0, this, 0);
632       mySelectionMgr->clearSelected();
633       mySelectionMgr->clearFilters();
634
635       if (send == SelectElementsButton) {
636         myEditCurrentArgument = LineEditElements;
637         SMESH::SetPointRepresentation(false);
638         if (CheckBoxMesh->isChecked()) {
639           //          mySelectionMgr->setSelectionModes(ActorSelection);
640           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
641             aViewWindow->SetSelectionMode(ActorSelection);
642           mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
643         } else {
644           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
645             aViewWindow->SetSelectionMode(FaceSelection);
646         }
647       } else if (send == SelectNodesButton) {
648         LineEditNodes->clear();
649         myEditCurrentArgument = LineEditNodes;
650         SMESH::SetPointRepresentation(true);
651         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) {
652           aViewWindow->SetSelectionMode(NodeSelection);
653         }
654       }
655
656       myEditCurrentArgument->setFocus();
657       connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
658       SelectionIntoArgument();
659       break;
660     }
661   }
662 }
663
664 //=================================================================================
665 // function : DeactivateActiveDialog()
666 // purpose  : Deactivates this dialog
667 //=================================================================================
668 void SMESHGUI_SmoothingDlg::DeactivateActiveDialog()
669 {
670   if (GroupConstructors->isEnabled()) {
671     GroupConstructors->setEnabled(false);
672     GroupArguments->setEnabled(false);
673     GroupButtons->setEnabled(false);
674     mySMESHGUI->ResetState();
675     mySMESHGUI->SetActiveDialogBox(0);
676   }
677 }
678
679 //=================================================================================
680 // function : ActivateThisDialog()
681 // purpose  : Activates this dialog
682 //=================================================================================
683 void SMESHGUI_SmoothingDlg::ActivateThisDialog()
684 {
685   // Emit a signal to deactivate the active dialog
686   mySMESHGUI->EmitSignalDeactivateDialog();
687   GroupConstructors->setEnabled(true);
688   GroupArguments->setEnabled(true);
689   GroupButtons->setEnabled(true);
690
691   mySMESHGUI->SetActiveDialogBox(this);
692   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
693     aViewWindow->SetSelectionMode(FaceSelection);
694   SelectionIntoArgument();
695 }
696
697 //=================================================================================
698 // function : enterEvent()
699 // purpose  : Mouse enter event
700 //=================================================================================
701 void SMESHGUI_SmoothingDlg::enterEvent (QEvent*)
702 {
703   if (!GroupConstructors->isEnabled())
704     ActivateThisDialog();
705 }
706
707 //=======================================================================
708 // function : onSelectMesh()
709 // purpose  :
710 //=======================================================================
711 void SMESHGUI_SmoothingDlg::onSelectMesh (bool toSelectMesh)
712 {
713   if (toSelectMesh)
714     TextLabelElements->setText(tr("SMESH_NAME"));
715   else
716     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
717   myElemFilterBtn->setEnabled(!toSelectMesh);
718
719   if (myEditCurrentArgument != LineEditElements &&
720       myEditCurrentArgument != LineEditNodes) {
721     LineEditElements->clear();
722     LineEditNodes->clear();
723     return;
724   }
725
726   mySelectionMgr->clearFilters();
727   SMESH::SetPointRepresentation(false);
728
729   if (toSelectMesh) {
730     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
731       aViewWindow->SetSelectionMode(ActorSelection);
732     //    mySelectionMgr->setSelectionModes(ActorSelection);
733     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
734     myEditCurrentArgument->setReadOnly(true);
735     myEditCurrentArgument->setValidator(0);
736   } else {
737     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
738       aViewWindow->SetSelectionMode(myEditCurrentArgument == LineEditElements ? FaceSelection 
739                                                                               : NodeSelection );
740     myEditCurrentArgument->setReadOnly(false);
741     LineEditElements->setValidator(myIdValidator);
742     onTextChange(myEditCurrentArgument->text());
743   }
744
745   SelectionIntoArgument();
746 }
747
748 //=================================================================================
749 // function : keyPressEvent()
750 // purpose  :
751 //=================================================================================
752 void SMESHGUI_SmoothingDlg::keyPressEvent( QKeyEvent* e )
753 {
754   QDialog::keyPressEvent( e );
755   if ( e->isAccepted() )
756     return;
757
758   if ( e->key() == Qt::Key_F1 ) {
759     e->accept();
760     ClickOnHelp();
761   }
762 }
763
764 //=================================================================================
765 // function : setFilters()
766 // purpose  : activate filter dialog
767 //=================================================================================
768 void SMESHGUI_SmoothingDlg::setFilters( const bool theIsElem )
769 {
770   if(myMesh->_is_nil()) {
771     SUIT_MessageBox::critical(this,
772                               tr("SMESH_ERROR"),
773                               tr("NO_MESH_SELECTED"));
774    return;
775   }
776   if ( !myFilterDlg )
777   {
778     QList<int> types;  
779     types.append( SMESH::NODE );
780     types.append( SMESH::ALL );
781     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
782   }
783   myFilterDlg->Init( theIsElem ? SMESH::ALL : SMESH::NODE );
784
785   myFilterDlg->SetSelection();
786   myFilterDlg->SetMesh( myMesh );
787   myFilterDlg->SetSourceWg( theIsElem ? LineEditElements : LineEditNodes );
788
789   myFilterDlg->show();
790 }
791
792 //=================================================================================
793 // function : setElemFilters()
794 // purpose  : SLOT. Called when element "Filter" button pressed.
795 //=================================================================================
796 void SMESHGUI_SmoothingDlg::setElemFilters()
797 {
798   setFilters( true );
799 }
800
801 //=================================================================================
802 // function : setNodeFilters()
803 // purpose  : SLOT. Called when node "Filter" button pressed.
804 //=================================================================================
805 void SMESHGUI_SmoothingDlg::setNodeFilters()
806 {
807   setFilters( false );
808 }
809
810 //=================================================================================
811 // function : isValid
812 // purpose  :
813 //=================================================================================
814 bool SMESHGUI_SmoothingDlg::isValid()
815 {
816   QString msg;
817   bool ok = true;
818   ok = SpinBox_IterationLimit->isValid( msg, true ) && ok;
819   ok = SpinBox_AspectRatio->isValid( msg, true ) && ok;
820
821   if( !ok ) {
822     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
823     if ( !msg.isEmpty() )
824       str += "\n" + msg;
825     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
826     return false;
827   }
828   return true;
829 }