Salome HOME
Merge with version on tag OCC-V2_1_0d
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESHGUI_SmoothingDlg.cxx
25 //  Author : Michael ZORIN
26 //  Module : SMESH
27 //  $Header: 
28
29 #include "SMESHGUI_SmoothingDlg.h"
30
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_SpinBox.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_VTKUtils.h"
35 #include "SMESHGUI_MeshUtils.h"
36 #include "SMESHGUI_IdValidator.h"
37 #include "SMESH_Actor.h"
38 #include "SMESH_TypeFilter.hxx"
39 #include "SMDS_Mesh.hxx"
40
41 #include "QAD_Application.h"
42 #include "QAD_Desktop.h"
43 #include "QAD_MessageBox.h"
44 #include "utilities.h"
45
46 // QT Includes
47 #include <qapplication.h>
48 #include <qbuttongroup.h>
49 #include <qgroupbox.h>
50 #include <qlabel.h>
51 #include <qlineedit.h>
52 #include <qpushbutton.h>
53 #include <qradiobutton.h>
54 #include <qcombobox.h>
55 #include <qcheckbox.h>
56 #include <qlayout.h>
57 #include <qspinbox.h> 
58 #include <qvalidator.h>
59 #include <qpixmap.h>
60
61 using namespace std;
62
63 //=================================================================================
64 // class    : SMESHGUI_SmoothingDlg()
65 // purpose  : 
66 //=================================================================================
67 SMESHGUI_SmoothingDlg::SMESHGUI_SmoothingDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
68                                               bool modal, WFlags fl )
69   : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu |
70              Qt::WDestructiveClose)
71 {
72   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_SMOOTHING")));
73   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
74
75   if ( !name )
76     setName( "SMESHGUI_SmoothingDlg" );
77   resize( 303, 185 ); 
78   setCaption( tr( "SMESH_SMOOTHING" ) );
79   setSizeGripEnabled( TRUE );
80   SMESHGUI_SmoothingDlgLayout = new QGridLayout( this ); 
81   SMESHGUI_SmoothingDlgLayout->setSpacing( 6 );
82   SMESHGUI_SmoothingDlgLayout->setMargin( 11 );
83
84   /***************************************************************/
85   GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
86   GroupConstructors->setTitle( tr( "SMESH_SMOOTHING"  ) );
87   GroupConstructors->setExclusive( TRUE );
88   GroupConstructors->setColumnLayout(0, Qt::Vertical );
89   GroupConstructors->layout()->setSpacing( 0 );
90   GroupConstructors->layout()->setMargin( 0 );
91   GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
92   GroupConstructorsLayout->setAlignment( Qt::AlignTop );
93   GroupConstructorsLayout->setSpacing( 6 );
94   GroupConstructorsLayout->setMargin( 11 );
95   Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
96   Constructor1->setText( tr( ""  ) );
97   Constructor1->setPixmap( image0 );
98   Constructor1->setChecked( TRUE );
99   Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
100   Constructor1->setMinimumSize( QSize( 50, 0 ) );
101   GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
102   QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
103   GroupConstructorsLayout->addItem( spacer, 0, 1 );
104   SMESHGUI_SmoothingDlgLayout->addWidget( GroupConstructors, 0, 0 );
105   
106   /***************************************************************/
107   GroupButtons = new QGroupBox( this, "GroupButtons" );
108   GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
109   GroupButtons->setTitle( tr( ""  ) );
110   GroupButtons->setColumnLayout(0, Qt::Vertical );
111   GroupButtons->layout()->setSpacing( 0 );
112   GroupButtons->layout()->setMargin( 0 );
113   GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
114   GroupButtonsLayout->setAlignment( Qt::AlignTop );
115   GroupButtonsLayout->setSpacing( 6 );
116   GroupButtonsLayout->setMargin( 11 );
117   buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
118   buttonCancel->setText( tr( "SMESH_BUT_CLOSE"  ) );
119   buttonCancel->setAutoDefault( TRUE );
120   GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
121   buttonApply = new QPushButton( GroupButtons, "buttonApply" );
122   buttonApply->setText( tr( "SMESH_BUT_APPLY"  ) );
123   buttonApply->setAutoDefault( TRUE );
124   GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
125   QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
126   GroupButtonsLayout->addItem( spacer_9, 0, 2 );
127   buttonOk = new QPushButton( GroupButtons, "buttonOk" );
128   buttonOk->setText( tr( "SMESH_BUT_OK"  ) );
129   buttonOk->setAutoDefault( TRUE );
130   buttonOk->setDefault( TRUE );
131   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
132   SMESHGUI_SmoothingDlgLayout->addWidget( GroupButtons, 2, 0 );
133
134   /***************************************************************/
135   GroupArguments = new QGroupBox( this, "GroupArguments" );
136   GroupArguments->setTitle( tr( "SMESH_ARGUMENTS"  ) );
137   GroupArguments->setColumnLayout(0, Qt::Vertical );
138   GroupArguments->layout()->setSpacing( 0 );
139   GroupArguments->layout()->setMargin( 0 );
140   GroupArgumentsLayout = new QGridLayout( GroupArguments->layout() );
141   GroupArgumentsLayout->setAlignment( Qt::AlignTop );
142   GroupArgumentsLayout->setSpacing( 6 );
143   GroupArgumentsLayout->setMargin( 11 );
144
145   // Controls for elements selection
146   TextLabelElements  = new QLabel( GroupArguments, "TextLabelElements" );
147   TextLabelElements->setText( tr( "SMESH_ID_ELEMENTS"  ) );
148   GroupArgumentsLayout->addWidget( TextLabelElements, 0, 0 );
149
150   SelectElementsButton  = new QPushButton( GroupArguments, "SelectElementsButton" );
151   SelectElementsButton->setText( tr( ""  ) );
152   SelectElementsButton->setPixmap( image1 );
153   SelectElementsButton->setToggleButton( FALSE );
154   GroupArgumentsLayout->addWidget( SelectElementsButton, 0, 1 );
155
156   LineEditElements  = new QLineEdit( GroupArguments, "LineEditElements" );
157   LineEditElements->setValidator( new SMESHGUI_IdValidator( this, "validator" ));
158   GroupArgumentsLayout->addWidget( LineEditElements, 0, 2 );
159
160   // Control for the whole mesh selection
161   CheckBoxMesh = new QCheckBox( GroupArguments, "CheckBoxMesh" );
162   CheckBoxMesh->setText( tr( "SMESH_SELECT_WHOLE_MESH" ) );
163   GroupArgumentsLayout->addMultiCellWidget( CheckBoxMesh, 1, 1, 0, 2 );
164
165   // Controls for nodes selection
166   TextLabelNodes = new QLabel( GroupArguments, "TextLabelNodes" );
167   TextLabelNodes->setText( tr( "FIXED_NODES_IDS" ) );
168   GroupArgumentsLayout->addWidget( TextLabelNodes, 2, 0 );
169
170   SelectNodesButton  = new QPushButton( GroupArguments, "SelectNodesButton" );
171   SelectNodesButton->setText( tr( ""  ) );
172   SelectNodesButton->setPixmap( image1 );
173   SelectNodesButton->setToggleButton( FALSE );
174   GroupArgumentsLayout->addWidget( SelectNodesButton, 2, 1 );
175
176   LineEditNodes  = new QLineEdit( GroupArguments, "LineEditNodes" );
177   LineEditNodes->setValidator( new SMESHGUI_IdValidator( this, "validator" ));
178   GroupArgumentsLayout->addWidget( LineEditNodes, 2, 2 );
179
180   // Controls for method selection
181   TextLabelMethod = new QLabel( GroupArguments, "TextLabelMethod" );
182   TextLabelMethod->setText( tr( "METHOD"  ) );
183   GroupArgumentsLayout->addMultiCellWidget( TextLabelMethod, 3, 3, 0, 1 );
184
185   ComboBoxMethod = new QComboBox( GroupArguments, "ComboBoxMethod" );
186   GroupArgumentsLayout->addWidget( ComboBoxMethod, 3, 2 );
187
188   // Controls for iteration limit defining
189   TextLabelLimit = new QLabel( GroupArguments, "TextLabelLimit" );
190   TextLabelLimit->setText( tr( "ITERATION_LIMIT"  ) );
191   GroupArgumentsLayout->addMultiCellWidget( TextLabelLimit, 4, 4, 0, 1 );
192
193   SpinBox_IterationLimit = new QSpinBox(GroupArguments, "SpinBox_IterationLimit");
194   GroupArgumentsLayout->addWidget( SpinBox_IterationLimit, 4, 2 );
195
196   // Controls for max. aspect ratio defining
197   TextLabelAspectRatio = new QLabel( GroupArguments, "TextLabelAspectRatio" );
198   TextLabelAspectRatio->setText( tr( "MAX_ASPECT_RATIO" ) );
199   GroupArgumentsLayout->addMultiCellWidget( TextLabelAspectRatio, 5, 5, 0, 1 );
200
201   SpinBox_AspectRatio = new SMESHGUI_SpinBox(GroupArguments, "SpinBox_AspectRatio");
202   GroupArgumentsLayout->addWidget( SpinBox_AspectRatio, 5, 2 );
203
204
205   SMESHGUI_SmoothingDlgLayout->addWidget( GroupArguments, 1, 0 );
206   
207   /* Initialisations */
208   ComboBoxMethod->insertItem(tr("LAPLACIAN"));
209   ComboBoxMethod->insertItem(tr("CENTROIDAL"));
210
211   QIntValidator* anIntValidator = new QIntValidator(SpinBox_IterationLimit);
212   SpinBox_IterationLimit->setValidator(anIntValidator);
213   SpinBox_IterationLimit->setRange( 1, 999999 );
214   SpinBox_AspectRatio->RangeStepAndValidator( 0.0, +999999.999, 0.1, 3 );
215
216   GroupArguments->show();
217   myConstructorId = 0 ;
218   Constructor1->setChecked( TRUE );
219   mySelection = Sel;  
220
221   mySMESHGUI  = SMESHGUI::GetSMESHGUI() ;
222   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
223   
224   // Costruction of the logical filter
225   SMESH_ListOfFilter aListOfFilters;
226   Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
227   if ( !aMeshOrSubMeshFilter.IsNull() )
228     aListOfFilters.Append( aMeshOrSubMeshFilter );
229   Handle(SMESH_TypeFilter) aSmeshGroupFilter = new SMESH_TypeFilter( GROUP );
230   if ( !aSmeshGroupFilter.IsNull() )
231     aListOfFilters.Append( aSmeshGroupFilter );
232   
233   myMeshOrSubMeshOrGroupFilter = new SMESH_LogicalFilter( aListOfFilters, SMESH_LogicalFilter::LO_OR );
234
235   Init();
236   /* signals and slots connections */
237   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
238   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
239   connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
240   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
241   
242   connect( SelectElementsButton, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
243   connect( SelectNodesButton, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
244   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
245   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
246   /* to close dialog if study change */
247   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
248   connect( LineEditElements, SIGNAL( textChanged( const QString& )),
249            SLOT( onTextChange( const QString& )));
250   connect( LineEditNodes, SIGNAL( textChanged( const QString& )),
251            SLOT( onTextChange( const QString& )));
252   connect( CheckBoxMesh, SIGNAL( toggled( bool )),
253            SLOT( onSelectMesh( bool )));
254   
255   /* Move widget on the botton right corner of main widget */
256   int x, y ;
257   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
258   this->move( x, y ) ;
259   this->show() ; /* displays Dialog */
260 }
261
262 //=================================================================================
263 // function : ~SMESHGUI_SmoothingDlg()
264 // purpose  : Destroys the object and frees any allocated resources
265 //=================================================================================
266 SMESHGUI_SmoothingDlg::~SMESHGUI_SmoothingDlg()
267 {
268   // no need to delete child widgets, Qt does it all for us
269 }
270
271
272 //=================================================================================
273 // function : Init()
274 // purpose  :
275 //=================================================================================
276 void SMESHGUI_SmoothingDlg::Init()
277 {
278   myBusy = false;  
279           
280   ComboBoxMethod->setCurrentItem(0);
281   
282   SpinBox_IterationLimit->setValue(20);
283   SpinBox_AspectRatio->SetValue(1.1);
284   
285   myEditCurrentArgument = LineEditElements;
286   LineEditElements->setFocus();
287   myElementsId = "";
288   myNbOkElements = 0 ;
289   myNbOkNodes = 0 ;
290   myActor     = 0;
291   myMesh = SMESH::SMESH_Mesh::_nil();
292   
293   CheckBoxMesh->setChecked(false);
294   onSelectMesh( false );
295 }
296
297
298 //=================================================================================
299 // function : ConstructorsClicked()
300 // purpose  : Radio button management
301 //=================================================================================
302 void SMESHGUI_SmoothingDlg::ConstructorsClicked(int constructorId)
303 {
304   return ;
305 }
306
307
308 //=================================================================================
309 // function : ClickOnApply()
310 // purpose  :
311 //=================================================================================
312 void SMESHGUI_SmoothingDlg::ClickOnApply()
313 {
314   if (mySMESHGUI->ActiveStudyLocked())
315     return;
316   
317   if ( myNbOkElements  && (myNbOkNodes || LineEditNodes->text().stripWhiteSpace().isEmpty()))
318     {
319       QStringList aListElementsId = QStringList::split( " ", myElementsId, false);
320       QStringList aListNodesId = QStringList::split( " ", LineEditNodes->text(), false);
321
322       SMESH::long_array_var anElementsId = new SMESH::long_array;
323       SMESH::long_array_var aNodesId = new SMESH::long_array;
324
325       anElementsId->length( aListElementsId.count() );
326       for ( int i = 0; i < aListElementsId.count(); i++ )
327         anElementsId[i] = aListElementsId[i].toInt();
328       
329       if (myNbOkNodes)
330         {
331           aNodesId->length( aListNodesId.count() );
332           for ( int i = 0; i < aListNodesId.count(); i++ )
333             aNodesId[i] = aListNodesId[i].toInt();
334         }
335       else
336         anElementsId->length(0);
337       
338       long anIterationLimit = (long)SpinBox_IterationLimit->value();
339       double aMaxAspectRatio = SpinBox_AspectRatio->GetValue();
340
341       SMESH::SMESH_MeshEditor::Smooth_Method aMethod = SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH;
342       if (ComboBoxMethod->currentItem() > 0)
343         aMethod =  SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH;
344       
345       bool aResult = false;
346       try
347         {
348           SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
349           QApplication::setOverrideCursor(Qt::waitCursor);
350           aResult = aMeshEditor->Smooth(anElementsId.inout(), aNodesId.inout(), anIterationLimit, aMaxAspectRatio, aMethod);
351           QApplication::restoreOverrideCursor();
352         }
353       catch( ... )
354         {
355         }
356       
357       if ( aResult )
358         {
359           Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
360           mySelection->ClearIObjects();
361           SMESH::UpdateView();
362           mySelection->AddIObject( anIO, false );
363           Init();
364         }
365     }
366   
367 }
368
369 //=================================================================================
370 // function : ClickOnOk()
371 // purpose  :
372 //=================================================================================
373 void SMESHGUI_SmoothingDlg::ClickOnOk()
374 {
375   ClickOnApply() ;
376   ClickOnCancel() ;
377 }
378
379         
380 //=================================================================================
381 // function : ClickOnCancel()
382 // purpose  :
383 //=================================================================================
384 void SMESHGUI_SmoothingDlg::ClickOnCancel()
385 {
386   mySelection->ClearFilters();
387   mySelection->ClearIObjects();
388   SMESH::SetPointRepresentation(false);
389   QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
390   disconnect( mySelection, 0, this, 0 );
391   mySMESHGUI->ResetState() ;
392   reject() ;
393 }
394
395 //=======================================================================
396 //function : onTextChange
397 //purpose  : 
398 //=======================================================================
399
400 void SMESHGUI_SmoothingDlg::onTextChange(const QString& theNewText)
401 {
402   QLineEdit* send = (QLineEdit*)sender();
403
404   if ( myBusy ) return;
405   myBusy = true;
406   
407   if (send == LineEditElements)
408     myNbOkElements = 0;
409   else if (send == LineEditNodes)
410     myNbOkNodes = 0;
411   
412   buttonOk->setEnabled( false );
413   buttonApply->setEnabled( false );
414   
415   // hilight entered elements/nodes
416   SMDS_Mesh* aMesh = 0;
417   if ( myActor )
418     aMesh = myActor->GetObject()->GetMesh();
419   
420   if ( aMesh ) {
421     mySelection->ClearIObjects();
422     mySelection->AddIObject( myActor->getIO() );
423     
424     QStringList aListId = QStringList::split( " ", theNewText, false);
425     
426     if (send == LineEditElements) {
427       for ( int i = 0; i < aListId.count(); i++ ) {
428         const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
429         if ( e ) {
430           if ( !mySelection->IsIndexSelected( myActor->getIO(), e->GetID() ))
431             mySelection->AddOrRemoveIndex (myActor->getIO(), e->GetID(), true);
432           myNbOkElements++;
433         }
434       }
435       myElementsId = theNewText;
436     }
437     else if (send == LineEditNodes) {   
438       for ( int i = 0; i < aListId.count(); i++ ) {
439         const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
440         if ( n ) {
441           if ( !mySelection->IsIndexSelected( myActor->getIO(), n->GetID() ))
442             mySelection->AddOrRemoveIndex (myActor->getIO(), n->GetID(), true);
443           myNbOkNodes++;
444         }
445       }
446     }
447   }
448   
449   if ( myNbOkElements && (myNbOkNodes || LineEditNodes->text().stripWhiteSpace().isEmpty()) ) {
450     buttonOk->setEnabled( true );
451     buttonApply->setEnabled( true );
452   }
453   
454   myBusy = false;
455 }
456
457 //=================================================================================
458 // function : SelectionIntoArgument()
459 // purpose  : Called when selection as changed or other case
460 //=================================================================================
461 void SMESHGUI_SmoothingDlg::SelectionIntoArgument()
462 {
463   if ( myBusy ) return;
464
465   // clear
466   myActor = 0;
467   QString aString = "";
468
469   myBusy = true;
470   if (myEditCurrentArgument == (QWidget*)LineEditElements)
471     {
472       LineEditElements->setText( aString );
473       myNbOkElements = 0;
474       buttonOk->setEnabled( false );
475       buttonApply->setEnabled( false );
476     }
477   myBusy = false;
478
479   if ( !GroupButtons->isEnabled() ) // inactive
480     return;
481   
482   // get selected mesh
483   
484   int nbSel = mySelection->IObjectCount();
485   if(nbSel != 1)
486     return;
487   
488   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
489   myMesh = SMESH::GetMeshByIO(IO);
490   if(myMesh->_is_nil())
491     return;
492   myActor = SMESH::FindActorByObject(myMesh);
493   if (!myActor)
494     return;
495   
496   int aNbUnits = 0;
497  
498   if (myEditCurrentArgument == LineEditElements)
499     {
500       myElementsId = "";
501       
502       if (CheckBoxMesh->isChecked())
503         {
504           SMESH::GetNameOfSelectedIObjects(mySelection, aString);
505           
506           if(!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) //MESH
507             {
508               // get IDs from mesh
509               SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
510               if (!aSMDSMesh)
511                 return;
512               
513               for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++  )
514                 {
515                   const SMDS_MeshElement * e = aSMDSMesh->FindElement( i );
516                   if ( e ) {
517                     myElementsId += QString(" %1").arg(i);
518                     aNbUnits++;
519                   }
520                 }
521             }
522           else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) //SUBMESH
523             {
524               // get submesh
525               SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO) ;
526               
527               // get IDs from submesh
528               SMESH::long_array_var anElementsIds = new SMESH::long_array;
529               anElementsIds = aSubMesh->GetElementsId();
530               for ( int i = 0; i < anElementsIds->length(); i++ )
531                 myElementsId += QString(" %1").arg(anElementsIds[i]);
532               aNbUnits = anElementsIds->length();
533             }
534           else // GROUP
535             {
536               // get smesh group
537               SMESH::SMESH_GroupBase_var aGroup
538                 = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
539               if (aGroup->_is_nil())
540                 return;
541               
542               // get IDs from smesh group
543               SMESH::long_array_var anElementsIds = new SMESH::long_array;
544               anElementsIds = aGroup->GetListOfID();
545               for ( int i = 0; i < anElementsIds->length(); i++ )
546                 myElementsId += QString(" %1").arg(anElementsIds[i]);
547               aNbUnits = anElementsIds->length();
548             }
549         }
550       else
551         {
552           aNbUnits = SMESH::GetNameOfSelectedElements(mySelection, aString) ;
553           myElementsId = aString;
554         }
555     }
556   else if (myEditCurrentArgument == LineEditNodes && !myMesh->_is_nil() && myActor)
557     {
558       myNbOkNodes = 0;
559       aNbUnits = SMESH::GetNameOfSelectedNodes(mySelection, aString) ;
560     }
561   
562   if(aNbUnits < 1)
563     return ;
564
565   myBusy = true;
566   myEditCurrentArgument->setText( aString );
567   myBusy = false;
568   
569   // OK
570   if (myEditCurrentArgument == LineEditElements)
571     myNbOkElements = true;
572   else if (myEditCurrentArgument == LineEditNodes)
573     myNbOkNodes = true;
574   
575   if (myNbOkElements)
576     {
577       buttonOk->setEnabled( true );
578       buttonApply->setEnabled( true );
579     }
580 }
581
582
583 //=================================================================================
584 // function : SetEditCurrentArgument()
585 // purpose  :
586 //=================================================================================
587 void SMESHGUI_SmoothingDlg::SetEditCurrentArgument()
588 {
589   QPushButton* send = (QPushButton*)sender();
590   
591   switch (myConstructorId)
592     {
593     case 0: /* default constructor */
594       { 
595         disconnect( mySelection, 0, this, 0 );
596         mySelection->ClearIObjects();
597         mySelection->ClearFilters();
598         
599         if(send == SelectElementsButton) {
600           myEditCurrentArgument = LineEditElements;
601           SMESH::SetPointRepresentation(false);
602           if (CheckBoxMesh->isChecked())
603             {
604               QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
605               mySelection->AddFilter(myMeshOrSubMeshOrGroupFilter);
606             }
607           else
608             QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
609         }
610         else if (send == SelectNodesButton)
611           {
612             myEditCurrentArgument = LineEditNodes;
613             SMESH::SetPointRepresentation(true);
614             QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
615           }
616         
617         myEditCurrentArgument->setFocus();
618         connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
619         SelectionIntoArgument() ;
620         break;
621       }
622     }
623 }
624
625 //=================================================================================
626 // function : DeactivateActiveDialog()
627 // purpose  :
628 //=================================================================================
629 void SMESHGUI_SmoothingDlg::DeactivateActiveDialog()
630 {
631   if ( GroupConstructors->isEnabled() ) {
632     GroupConstructors->setEnabled(false) ;
633     GroupArguments->setEnabled(false) ;
634     GroupButtons->setEnabled(false) ;
635     mySMESHGUI->ResetState() ;    
636     mySMESHGUI->SetActiveDialogBox(0) ;
637   }
638 }
639
640
641 //=================================================================================
642 // function : ActivateThisDialog()
643 // purpose  :
644 //=================================================================================
645 void SMESHGUI_SmoothingDlg::ActivateThisDialog()
646 {
647   /* Emit a signal to deactivate the active dialog */
648   mySMESHGUI->EmitSignalDeactivateDialog() ;   
649   GroupConstructors->setEnabled(true) ;
650   GroupArguments->setEnabled(true) ;
651   GroupButtons->setEnabled(true) ;
652   
653   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
654
655   QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
656   SelectionIntoArgument();
657 }
658
659
660 //=================================================================================
661 // function : enterEvent()
662 // purpose  :
663 //=================================================================================
664 void SMESHGUI_SmoothingDlg::enterEvent(QEvent* e)
665 {
666   if ( GroupConstructors->isEnabled() )
667     return ;  
668   ActivateThisDialog() ;
669 }
670
671
672 //=================================================================================
673 // function : closeEvent()
674 // purpose  :
675 //=================================================================================
676 void SMESHGUI_SmoothingDlg::closeEvent( QCloseEvent* e )
677 {
678   /* same than click on cancel button */
679   this->ClickOnCancel() ;
680 }
681
682
683 //=======================================================================
684 //function : hideEvent
685 //purpose  : caused by ESC key
686 //=======================================================================
687
688 void SMESHGUI_SmoothingDlg::hideEvent ( QHideEvent * e )
689 {
690   if ( !isMinimized() )
691     ClickOnCancel();
692 }
693
694
695 //=======================================================================
696 //function : onSelectMesh
697 //purpose  :
698 //=======================================================================
699 void SMESHGUI_SmoothingDlg::onSelectMesh ( bool toSelectMesh )
700 {
701   if (toSelectMesh)
702     TextLabelElements->setText( tr( "SMESH_NAME" ) );
703   else
704     TextLabelElements->setText( tr( "SMESH_ID_ELEMENTS" ) );
705   
706   if (myEditCurrentArgument != LineEditElements)
707     {
708       LineEditElements->clear();
709       return;
710     }
711   
712   mySelection->ClearFilters() ;
713   SMESH::SetPointRepresentation(false);
714   
715   if (toSelectMesh)
716     {
717       QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
718       mySelection->AddFilter(myMeshOrSubMeshOrGroupFilter);
719       LineEditElements->setReadOnly(true);
720     }
721   else
722     {
723       QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
724       LineEditElements->setReadOnly(false);
725       onTextChange(LineEditElements->text());
726     }
727   
728   SelectionIntoArgument();
729 }