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