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