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