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