Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ExtrusionDlg.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_ExtrusionDlg.cxx
25 //  Author : Michael ZORIN
26 //  Module : SMESH
27 //  $Header: 
28
29 #include "SMESHGUI_ExtrusionDlg.h"
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_SpinBox.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_IdValidator.h"
36 #include "SMESH_Actor.h"
37 #include "SMESH_TypeFilter.hxx"
38 #include "SMDS_Mesh.hxx"
39
40 #include "QAD_Application.h"
41 #include "QAD_Desktop.h"
42 #include "QAD_MessageBox.h"
43 #include "utilities.h"
44
45 // QT Includes
46 #include <qapplication.h>
47 #include <qbuttongroup.h>
48 #include <qgroupbox.h>
49 #include <qlabel.h>
50 #include <qlineedit.h>
51 #include <qpushbutton.h>
52 #include <qradiobutton.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_ExtrusionDlg()
63 // purpose  : 
64 //=================================================================================
65 SMESHGUI_ExtrusionDlg::SMESHGUI_ExtrusionDlg( 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_EDGE")));
71   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_TRIANGLE")));
72   QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
73
74   if ( !name )
75     setName( "SMESHGUI_ExtrusionDlg" );
76   resize( 303, 185 ); 
77   setCaption( tr( "EXTRUSION_ALONG_LINE" ) );
78   setSizeGripEnabled( TRUE );
79   SMESHGUI_ExtrusionDlgLayout = new QGridLayout( this ); 
80   SMESHGUI_ExtrusionDlgLayout->setSpacing( 6 );
81   SMESHGUI_ExtrusionDlgLayout->setMargin( 11 );
82
83   /***************************************************************/
84   GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
85   GroupConstructors->setTitle( tr( "SMESH_EXTRUSION"  ) );
86   GroupConstructors->setExclusive( TRUE );
87   GroupConstructors->setColumnLayout(0, Qt::Vertical );
88   GroupConstructors->layout()->setSpacing( 0 );
89   GroupConstructors->layout()->setMargin( 0 );
90   GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
91   GroupConstructorsLayout->setAlignment( Qt::AlignTop );
92   GroupConstructorsLayout->setSpacing( 6 );
93   GroupConstructorsLayout->setMargin( 11 );
94   RadioButton1= new QRadioButton( GroupConstructors, "RadioButton1" );
95   RadioButton1->setText( tr( ""  ) );
96   RadioButton1->setPixmap( image0 );
97   GroupConstructorsLayout->addWidget( RadioButton1, 0, 0 );
98   RadioButton2= new QRadioButton( GroupConstructors, "RadioButton2" );
99   RadioButton2->setText( tr( ""  ) );
100   RadioButton2->setPixmap( image1 );
101   GroupConstructorsLayout->addWidget( RadioButton2, 0, 2 );
102   SMESHGUI_ExtrusionDlgLayout->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_ExtrusionDlgLayout->addWidget( GroupButtons, 2, 0 );
131
132   /***************************************************************/
133   GroupArguments = new QGroupBox( this, "GroupArguments" );
134   GroupArguments->setTitle( tr( "EXTRUSION_1D"  ) );
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   TextLabelElements->setFixedWidth(74);
147   GroupArgumentsLayout->addWidget( TextLabelElements, 0, 0 );
148
149   SelectElementsButton  = new QPushButton( GroupArguments, "SelectElementsButton" );
150   SelectElementsButton->setText( tr( ""  ) );
151   SelectElementsButton->setPixmap( image2 );
152   SelectElementsButton->setToggleButton( FALSE );
153   GroupArgumentsLayout->addWidget( SelectElementsButton, 0, 1 );
154   
155   LineEditElements  = new QLineEdit( GroupArguments, "LineEditElements" );
156   LineEditElements->setValidator( new SMESHGUI_IdValidator( this, "validator" ));
157   GroupArgumentsLayout->addMultiCellWidget( LineEditElements, 0, 0, 2, 7 );
158
159   // Control for the whole mesh selection
160   CheckBoxMesh = new QCheckBox( GroupArguments, "CheckBoxMesh" );
161   CheckBoxMesh->setText( tr( "SMESH_SELECT_WHOLE_MESH"  ) );
162   GroupArgumentsLayout->addMultiCellWidget( CheckBoxMesh, 1, 1, 0, 7 );
163
164   // Controls for vector selection
165   TextLabelVector = new QLabel( GroupArguments, "TextLabelVector" );
166   TextLabelVector->setText( tr( "SMESH_VECTOR" ) );
167   GroupArgumentsLayout->addWidget( TextLabelVector, 2, 0 );
168   
169   TextLabelDx = new QLabel( GroupArguments, "TextLabelDx" );
170   TextLabelDx->setText( tr( "SMESH_DX" ) );
171   GroupArgumentsLayout->addWidget( TextLabelDx, 2, 2 );
172
173   SpinBox_Dx = new SMESHGUI_SpinBox(GroupArguments, "SpinBox_Dx");
174   GroupArgumentsLayout->addWidget( SpinBox_Dx, 2, 3 );
175
176   TextLabelDy = new QLabel( GroupArguments, "TextLabelDy" );
177   TextLabelDy->setText( tr( "SMESH_DY" ) );
178   GroupArgumentsLayout->addWidget( TextLabelDy, 2, 4 );
179
180   SpinBox_Dy = new SMESHGUI_SpinBox(GroupArguments, "SpinBox_Dy");
181   GroupArgumentsLayout->addWidget( SpinBox_Dy, 2, 5 );
182
183   TextLabelDz = new QLabel( GroupArguments, "TextLabelDz" );
184   TextLabelDz->setText( tr( "SMESH_DZ" ) );
185   GroupArgumentsLayout->addWidget( TextLabelDz, 2, 6 );
186   
187   SpinBox_Dz = new SMESHGUI_SpinBox(GroupArguments, "SpinBox_Dz");
188   GroupArgumentsLayout->addWidget( SpinBox_Dz, 2, 7 );
189   
190   // Controls for nb. steps defining
191   TextLabelNbSteps = new QLabel( GroupArguments, "TextLabelNbSteps" );
192   TextLabelNbSteps->setText( tr( "SMESH_NUMBEROFSTEPS"  ) );
193   GroupArgumentsLayout->addMultiCellWidget( TextLabelNbSteps, 3, 3, 0, 1 );
194
195   SpinBox_NbSteps = new QSpinBox(GroupArguments, "SpinBox_NbSteps");
196   GroupArgumentsLayout->addMultiCellWidget( SpinBox_NbSteps, 3, 3,  2, 7 );
197   
198   SMESHGUI_ExtrusionDlgLayout->addWidget( GroupArguments, 1, 0 );
199   
200   /* Initialisations */
201   SpinBox_Dx->RangeStepAndValidator( -999999.999, +999999.999, 10.0, 3 );
202   SpinBox_Dy->RangeStepAndValidator( -999999.999, +999999.999, 10.0, 3 );
203   SpinBox_Dz->RangeStepAndValidator( -999999.999, +999999.999, 10.0, 3 );
204
205   QIntValidator* anIntValidator = new QIntValidator(SpinBox_NbSteps);
206   SpinBox_NbSteps->setValidator(anIntValidator);
207   SpinBox_NbSteps->setRange( 1, 999999 );
208  
209   GroupArguments->show();
210   RadioButton1->setChecked( TRUE );
211   mySelection = Sel;  
212
213   mySMESHGUI  = SMESHGUI::GetSMESHGUI() ;
214   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
215     
216   // Costruction of the logical filter
217   SMESH_ListOfFilter aListOfFilters;
218   Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
219   if ( !aMeshOrSubMeshFilter.IsNull() )
220     aListOfFilters.Append( aMeshOrSubMeshFilter );
221   Handle(SMESH_TypeFilter) aSmeshGroupFilter = new SMESH_TypeFilter( GROUP );
222   if ( !aSmeshGroupFilter.IsNull() )
223     aListOfFilters.Append( aSmeshGroupFilter );
224   
225   myMeshOrSubMeshOrGroupFilter = new SMESH_LogicalFilter( aListOfFilters, SMESH_LogicalFilter::LO_OR );
226   
227   Init();
228   /* signals and slots connections */
229   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
230   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
231   connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
232   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
233   
234   connect( SelectElementsButton, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
235   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
236   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
237   /* to close dialog if study change */
238   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
239   connect( LineEditElements, 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   ConstructorsClicked(0);
251 }
252
253 //=================================================================================
254 // function : ~SMESHGUI_ExtrusionDlg()
255 // purpose  : Destroys the object and frees any allocated resources
256 //=================================================================================
257 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
258 {
259   // no need to delete child widgets, Qt does it all for us
260 }
261
262
263 //=================================================================================
264 // function : Init()
265 // purpose  :
266 //=================================================================================
267 void SMESHGUI_ExtrusionDlg::Init(  bool ResetControls )
268 {
269   myBusy = false;    
270   
271   LineEditElements->clear();
272   myElementsId = "";
273   myNbOkElements = 0 ;
274
275   buttonOk->setEnabled( false );
276   buttonApply->setEnabled( false );
277   
278   myActor     = 0;
279   myMesh = SMESH::SMESH_Mesh::_nil();
280   
281   if( ResetControls )
282     {
283       SpinBox_NbSteps->setValue(1);
284       SpinBox_Dx->SetValue(0);
285       SpinBox_Dy->SetValue(0);
286       SpinBox_Dz->SetValue(0);
287       
288       CheckBoxMesh->setChecked(false);
289       onSelectMesh( false );
290     }
291 }
292
293
294 //=================================================================================
295 // function : ConstructorsClicked()
296 // purpose  : Radio button management
297 //=================================================================================
298 void SMESHGUI_ExtrusionDlg::ConstructorsClicked(int constructorId)
299 {
300   disconnect(mySelection, 0, this, 0);
301   
302   switch(constructorId)
303     { 
304     case 0 :
305       {
306         GroupArguments->setTitle( tr( "EXTRUSION_1D" ) );
307         if ( !CheckBoxMesh->isChecked() )
308           QAD_Application::getDesktop()->SetSelectionMode( EdgeSelection, true );
309         break;
310       }
311     case 1 :
312       { 
313         GroupArguments->setTitle( tr( "EXTRUSION_2D" ) );
314         if ( !CheckBoxMesh->isChecked() )
315           QAD_Application::getDesktop()->SetSelectionMode( FaceSelection, true );
316         break;
317       }
318     }
319
320   myEditCurrentArgument = LineEditElements;
321   LineEditElements->setFocus();
322   
323   if (CheckBoxMesh->isChecked())
324     onSelectMesh(true);
325   
326   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
327 }
328
329
330 //=================================================================================
331 // function : ClickOnApply()
332 // purpose  :
333 //=================================================================================
334 void SMESHGUI_ExtrusionDlg::ClickOnApply()
335 {
336   if (mySMESHGUI->ActiveStudyLocked())
337     return;
338   
339   if ( myNbOkElements)
340     {
341       QStringList aListElementsId = QStringList::split( " ", myElementsId, false);
342       
343       SMESH::long_array_var anElementsId = new SMESH::long_array;
344       
345       anElementsId->length( aListElementsId.count() );
346       for ( int i = 0; i < aListElementsId.count(); i++ )
347         anElementsId[i] = aListElementsId[i].toInt();
348       
349       SMESH::DirStruct aVector;
350       aVector.PS.x = SpinBox_Dx->GetValue();
351       aVector.PS.y = SpinBox_Dy->GetValue();
352       aVector.PS.z = SpinBox_Dz->GetValue();
353
354       long aNbSteps = (long)SpinBox_NbSteps->value();
355
356       try
357         {
358           SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
359           QApplication::setOverrideCursor(Qt::waitCursor);
360           aMeshEditor->ExtrusionSweep(anElementsId.inout(), aVector, aNbSteps);
361           QApplication::restoreOverrideCursor();
362         }
363       catch( ... )
364         {
365         }
366       
367       mySelection->ClearIObjects();
368       SMESH::UpdateView();
369       Init( false);
370       ConstructorsClicked( GetConstructorId() );
371     }
372 }
373
374 //=================================================================================
375 // function : ClickOnOk()
376 // purpose  :
377 //=================================================================================
378 void SMESHGUI_ExtrusionDlg::ClickOnOk()
379 {
380   ClickOnApply();
381   ClickOnCancel();
382 }
383
384         
385 //=================================================================================
386 // function : ClickOnCancel()
387 // purpose  :
388 //=================================================================================
389 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
390 {
391   mySelection->ClearFilters();
392   mySelection->ClearIObjects();
393   SMESH::SetPointRepresentation(false);
394   QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
395   disconnect( mySelection, 0, this, 0 );
396   mySMESHGUI->ResetState() ;
397   reject() ;
398 }
399
400 //=======================================================================
401 //function : onTextChange
402 //purpose  : 
403 //=======================================================================
404 void SMESHGUI_ExtrusionDlg::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   
414   buttonOk->setEnabled( false );
415   buttonApply->setEnabled( false );
416   
417   // hilight entered elements/nodes
418   SMDS_Mesh* aMesh = 0;
419   if ( myActor )
420     aMesh = myActor->GetObject()->GetMesh();
421   
422   if ( aMesh ) {
423     mySelection->ClearIObjects();
424     mySelection->AddIObject( myActor->getIO() );
425     
426     QStringList aListId = QStringList::split( " ", theNewText, false);
427     
428     if (send == LineEditElements) {
429       for ( int i = 0; i < aListId.count(); i++ ) {
430         const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
431         if ( e ) {
432           if ( !mySelection->IsIndexSelected( myActor->getIO(), e->GetID() ))
433             mySelection->AddOrRemoveIndex (myActor->getIO(), e->GetID(), true);
434           myNbOkElements++;
435         }
436       }
437       myElementsId = theNewText;
438     }
439   }
440   
441   if ( myNbOkElements ) {
442     buttonOk->setEnabled( true );
443     buttonApply->setEnabled( true );
444   }
445   
446   myBusy = false;
447 }
448
449 //=================================================================================
450 // function : SelectionIntoArgument()
451 // purpose  : Called when selection as changed or other case
452 //=================================================================================
453 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
454 {
455   if ( myBusy ) return;
456   
457   // clear
458   myActor = 0;
459   QString aString = "";
460
461   myBusy = true;
462   myEditCurrentArgument->setText( aString );
463   myNbOkElements = 0;
464   buttonOk->setEnabled( false );
465   buttonApply->setEnabled( false );
466   myBusy = false;
467   
468   if ( !GroupButtons->isEnabled() ) // inactive
469     return;
470   
471   buttonOk->setEnabled( false );
472   buttonApply->setEnabled( false );
473   
474   // get selected mesh
475   
476   int nbSel = SMESH::GetNameOfSelectedIObjects(mySelection, aString);
477   if(nbSel != 1)
478     return;
479   
480   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
481   myMesh = SMESH::GetMeshByIO(IO);
482   if(myMesh->_is_nil())
483     return;
484   myActor = SMESH::FindActorByObject(myMesh);
485   if (!myActor)
486     return;
487   
488   if (myEditCurrentArgument == LineEditElements)
489     {
490       int aNbElements = 0;
491       myElementsId = "";
492       
493       if (CheckBoxMesh->isChecked())
494         {
495           SMESH::GetNameOfSelectedIObjects(mySelection, aString);
496         
497           int aConstructorId = GetConstructorId();
498
499           if(!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) //MESH
500             {
501               // get IDs from mesh
502               SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
503               if (!aSMDSMesh)
504                 return;
505               
506               if (aConstructorId == 0)
507                 {
508                   SMDS_EdgeIteratorPtr anIter = aSMDSMesh->edgesIterator();
509                   
510                   while ( anIter->more() )
511                     {
512                       const SMDS_MeshEdge * edge = anIter->next();
513                       if ( edge ) {
514                         myElementsId += QString(" %1").arg(edge->GetID());
515                         aNbElements++;
516                       }
517                     }
518                 }
519               else if (aConstructorId == 1)
520                 {
521                   SMDS_FaceIteratorPtr anIter = aSMDSMesh->facesIterator();               
522                   while ( anIter->more() )
523                     {
524                       const SMDS_MeshFace * face = anIter->next();
525                       if ( face ) {
526                         myElementsId += QString(" %1").arg(face->GetID());
527                         aNbElements++;
528                       }
529                     }
530                 }
531             }
532           else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) //SUBMESH
533             {
534               // get submesh
535               SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO) ;
536               
537               // get IDs from submesh
538               SMESH::long_array_var anElementsIds = new SMESH::long_array;
539               if (aConstructorId == 0)
540                 anElementsIds = aSubMesh->GetElementsByType(SMESH::EDGE);
541               else if (aConstructorId == 1)
542                 anElementsIds = aSubMesh->GetElementsByType(SMESH::FACE);
543               
544               for ( int i = 0; i < anElementsIds->length(); i++ )
545                 myElementsId += QString(" %1").arg(anElementsIds[i]);
546               aNbElements = anElementsIds->length();
547             }
548           else // GROUP
549             {
550               // get smesh group
551               SMESH::SMESH_GroupBase_var aGroup =
552                 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
553               if (aGroup->_is_nil())
554                 return;
555               
556               if ( (aConstructorId == 0 && aGroup->GetType()!= SMESH::EDGE) ||
557                    (aConstructorId == 1 && aGroup->GetType()!= SMESH::FACE) )
558                 return;
559               
560               // get IDs from smesh group
561               SMESH::long_array_var anElementsIds = new SMESH::long_array;
562               anElementsIds = aGroup->GetListOfID();
563               for ( int i = 0; i < anElementsIds->length(); i++ )
564                 myElementsId += QString(" %1").arg(anElementsIds[i]);
565               aNbElements = anElementsIds->length();
566             }
567         }
568       else
569         {
570           aNbElements = SMESH::GetNameOfSelectedElements(mySelection, aString) ;
571           myElementsId = aString;
572         }
573       
574       if(aNbElements < 1)
575         return ;
576       
577       myNbOkElements = true;
578     }
579   
580   myBusy = true;
581   myEditCurrentArgument->setText( aString );
582   myBusy = false;
583   
584   // OK
585   
586   if(myNbOkElements)
587     {
588       buttonOk->setEnabled( true );
589       buttonApply->setEnabled( true );
590     }
591 }
592
593
594 //=================================================================================
595 // function : SetEditCurrentArgument()
596 // purpose  :
597 //=================================================================================
598 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
599 {
600   QPushButton* send = (QPushButton*)sender();
601   
602   disconnect( mySelection, 0, this, 0 );
603   mySelection->ClearIObjects();
604   mySelection->ClearFilters();
605   
606   if(send == SelectElementsButton) {
607     myEditCurrentArgument = LineEditElements;
608     if (CheckBoxMesh->isChecked())
609       {
610         QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
611         mySelection->AddFilter(myMeshOrSubMeshOrGroupFilter);
612       }
613     else
614       {
615         int aConstructorId = GetConstructorId();
616         if (aConstructorId == 0)
617           QAD_Application::getDesktop()->SetSelectionMode( EdgeSelection, true );
618         else if (aConstructorId == 1)
619           QAD_Application::getDesktop()->SetSelectionMode( FaceSelection, true );
620       }
621   }
622   
623   myEditCurrentArgument->setFocus();
624   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
625   SelectionIntoArgument() ;
626 }
627
628 //=================================================================================
629 // function : DeactivateActiveDialog()
630 // purpose  :
631 //=================================================================================
632 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
633 {
634   if ( GroupConstructors->isEnabled() ) {
635     GroupConstructors->setEnabled(false) ;
636     GroupArguments->setEnabled(false) ;
637     GroupButtons->setEnabled(false) ;
638     mySMESHGUI->ResetState() ;    
639     mySMESHGUI->SetActiveDialogBox(0) ;
640   }
641 }
642
643
644 //=================================================================================
645 // function : ActivateThisDialog()
646 // purpose  :
647 //=================================================================================
648 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
649 {
650   /* Emit a signal to deactivate the active dialog */
651   mySMESHGUI->EmitSignalDeactivateDialog() ;   
652   GroupConstructors->setEnabled(true) ;
653   GroupArguments->setEnabled(true) ;
654   GroupButtons->setEnabled(true) ;
655   
656   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
657
658   ConstructorsClicked(GetConstructorId());
659   SelectionIntoArgument();
660 }
661
662
663 //=================================================================================
664 // function : enterEvent()
665 // purpose  :
666 //=================================================================================
667 void SMESHGUI_ExtrusionDlg::enterEvent(QEvent* e)
668 {
669   if ( GroupConstructors->isEnabled() )
670     return ;  
671   ActivateThisDialog() ;
672 }
673
674
675 //=================================================================================
676 // function : closeEvent()
677 // purpose  :
678 //=================================================================================
679 void SMESHGUI_ExtrusionDlg::closeEvent( QCloseEvent* e )
680 {
681   /* same than click on cancel button */
682   this->ClickOnCancel() ;
683 }
684
685
686 //=======================================================================
687 //function : hideEvent
688 //purpose  : caused by ESC key
689 //=======================================================================
690
691 void SMESHGUI_ExtrusionDlg::hideEvent ( QHideEvent * e )
692 {
693   if ( !isMinimized() )
694     ClickOnCancel();
695 }
696
697
698 //=======================================================================
699 //function : onSelectMesh
700 //purpose  :
701 //=======================================================================
702 void SMESHGUI_ExtrusionDlg::onSelectMesh ( bool toSelectMesh )
703 {
704   if (toSelectMesh)
705     TextLabelElements->setText( tr( "SMESH_NAME" ) );
706   else
707     TextLabelElements->setText( tr( "SMESH_ID_ELEMENTS" ) );
708   
709   if (myEditCurrentArgument != LineEditElements)
710     {
711       LineEditElements->clear();
712       return;
713     }
714   
715   mySelection->ClearFilters() ;
716   
717   if (toSelectMesh)
718     {
719       QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
720       mySelection->AddFilter(myMeshOrSubMeshOrGroupFilter);
721       LineEditElements->setReadOnly(true);
722     }
723   else
724     {
725       int aConstructorId = GetConstructorId();
726       if (aConstructorId == 0)
727         QAD_Application::getDesktop()->SetSelectionMode( EdgeSelection, true );
728       else if (aConstructorId == 0)
729         QAD_Application::getDesktop()->SetSelectionMode( FaceSelection, true );
730       
731       LineEditElements->setReadOnly(false);
732       onTextChange(LineEditElements->text());
733     }
734   
735   SelectionIntoArgument();
736 }
737
738
739 //=================================================================================
740 // function : GetConstructorId()
741 // purpose  : 
742 //=================================================================================
743 int SMESHGUI_ExtrusionDlg::GetConstructorId()
744
745   if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
746     return GroupConstructors->id( GroupConstructors->selected() );
747   return -1;
748 }