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