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