Salome HOME
New icons for Smesh module.
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : SMESHGUI_ExtrusionDlg.cxx
23 // Author : Michael ZORIN, Open CASCADE S.A.S.
24 //
25
26 // SMESH includes
27 #include "SMESHGUI_ExtrusionDlg.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_SpinBox.h"
34 #include "SMESHGUI_IdValidator.h"
35
36 #include <SMESH_Actor.h>
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_LogicalFilter.hxx>
39
40 #include <SMDS_Mesh.hxx>
41
42 // SALOME GUI includes
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Desktop.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_Session.h>
47
48 #include <LightApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
50
51 #include <SVTK_ViewModel.h>
52 #include <SVTK_ViewWindow.h>
53
54 // OCCT includes
55 #include <TColStd_MapOfInteger.hxx>
56 #include <TColStd_IndexedMapOfInteger.hxx>
57
58 // Qt includes
59 #include <QApplication>
60 #include <QButtonGroup>
61 #include <QGroupBox>
62 #include <QLabel>
63 #include <QLineEdit>
64 #include <QPushButton>
65 #include <QRadioButton>
66 #include <QCheckBox>
67 #include <QSpinBox>
68 #include <QHBoxLayout>
69 #include <QVBoxLayout>
70 #include <QGridLayout>
71 #include <QKeyEvent>
72
73 // IDL includes
74 #include <SALOMEconfig.h>
75 #include CORBA_SERVER_HEADER(SMESH_Group)
76 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
77
78 #define SPACING 6
79 #define MARGIN  11
80
81 //=================================================================================
82 // function : SMESHGUI_ExtrusionDlg()
83 // purpose  : constructor
84 //=================================================================================
85 SMESHGUI_ExtrusionDlg::SMESHGUI_ExtrusionDlg (SMESHGUI* theModule)
86   : QDialog( SMESH::GetDesktop( theModule ) ),
87     mySMESHGUI( theModule ),
88     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
89 {
90   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_EDGE")));
91   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_TRIANGLE")));
92   QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
93
94   setModal( false );
95   setAttribute( Qt::WA_DeleteOnClose, true );
96   setWindowTitle(tr("EXTRUSION_ALONG_LINE"));
97   setSizeGripEnabled(true);
98
99   QVBoxLayout* SMESHGUI_ExtrusionDlgLayout = new QVBoxLayout(this);
100   SMESHGUI_ExtrusionDlgLayout->setSpacing(SPACING);
101   SMESHGUI_ExtrusionDlgLayout->setMargin(MARGIN);
102
103   /***************************************************************/
104   ConstructorsBox = new QGroupBox(tr("SMESH_EXTRUSION"), this);
105   GroupConstructors = new QButtonGroup(this);
106   QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
107   ConstructorsBoxLayout->setSpacing(SPACING);
108   ConstructorsBoxLayout->setMargin(MARGIN);
109
110   RadioButton1= new QRadioButton(ConstructorsBox);
111   RadioButton1->setIcon(image0);
112   RadioButton2= new QRadioButton(ConstructorsBox);
113   RadioButton2->setIcon(image1);
114
115   ConstructorsBoxLayout->addWidget(RadioButton1);
116   ConstructorsBoxLayout->addWidget(RadioButton2);
117
118   GroupConstructors->addButton(RadioButton1, 0);
119   GroupConstructors->addButton(RadioButton2, 1);
120
121   /***************************************************************/
122   GroupButtons = new QGroupBox(this);
123   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
124   GroupButtonsLayout->setSpacing(SPACING);
125   GroupButtonsLayout->setMargin(MARGIN);
126
127   buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
128   buttonOk->setAutoDefault(true);
129   buttonOk->setDefault(true);
130   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
131   buttonApply->setAutoDefault(true);
132   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
133   buttonCancel->setAutoDefault(true);
134   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
135   buttonHelp->setAutoDefault(true);
136
137   GroupButtonsLayout->addWidget(buttonOk);
138   GroupButtonsLayout->addSpacing(10);
139   GroupButtonsLayout->addWidget(buttonApply);
140   GroupButtonsLayout->addSpacing(10);
141   GroupButtonsLayout->addStretch();
142   GroupButtonsLayout->addWidget(buttonCancel);
143   GroupButtonsLayout->addWidget(buttonHelp);
144
145   /***************************************************************/
146   GroupArguments = new QGroupBox(tr("EXTRUSION_1D"), this);
147   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
148   GroupArgumentsLayout->setSpacing(SPACING);
149   GroupArgumentsLayout->setMargin(MARGIN);
150
151   myIdValidator = new SMESHGUI_IdValidator(this);
152
153   // Controls for elements selection
154   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
155
156   SelectElementsButton = new QPushButton(GroupArguments);
157   SelectElementsButton->setIcon(image2);
158
159   LineEditElements = new QLineEdit(GroupArguments);
160   LineEditElements->setValidator(myIdValidator);
161
162   // Control for the whole mesh selection
163   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
164
165   // Controls for vector selection
166   TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupArguments);
167
168   TextLabelDx = new QLabel(tr("SMESH_DX"), GroupArguments);
169   SpinBox_Dx = new SMESHGUI_SpinBox(GroupArguments);
170
171   TextLabelDy = new QLabel(tr("SMESH_DY"), GroupArguments);
172   SpinBox_Dy = new SMESHGUI_SpinBox(GroupArguments);
173
174   TextLabelDz = new QLabel(tr("SMESH_DZ"), GroupArguments);
175   SpinBox_Dz = new SMESHGUI_SpinBox(GroupArguments);
176
177   // Controls for nb. steps defining
178   TextLabelNbSteps = new QLabel(tr("SMESH_NUMBEROFSTEPS"), GroupArguments);
179   SpinBox_NbSteps = new QSpinBox(GroupArguments);
180
181   // CheckBox for groups generation
182   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
183
184   GroupArgumentsLayout->addWidget(TextLabelElements,    0, 0);
185   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
186   GroupArgumentsLayout->addWidget(LineEditElements,     0, 2, 1, 6);
187   GroupArgumentsLayout->addWidget(CheckBoxMesh,         1, 0, 1, 8);
188   GroupArgumentsLayout->addWidget(TextLabelVector,      2, 0);
189   GroupArgumentsLayout->addWidget(TextLabelDx,          2, 2);
190   GroupArgumentsLayout->addWidget(SpinBox_Dx,           2, 3);
191   GroupArgumentsLayout->addWidget(TextLabelDy,          2, 4);
192   GroupArgumentsLayout->addWidget(SpinBox_Dy,           2, 5);
193   GroupArgumentsLayout->addWidget(TextLabelDz,          2, 6);
194   GroupArgumentsLayout->addWidget(SpinBox_Dz,           2, 7);
195   GroupArgumentsLayout->addWidget(TextLabelNbSteps,     3, 0);
196   GroupArgumentsLayout->addWidget(SpinBox_NbSteps,      3, 2, 1, 6);
197   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      4, 0, 1, 8);
198
199   /***************************************************************/
200   SMESHGUI_ExtrusionDlgLayout->addWidget(ConstructorsBox);
201   SMESHGUI_ExtrusionDlgLayout->addWidget(GroupArguments);
202   SMESHGUI_ExtrusionDlgLayout->addWidget(GroupButtons);
203
204   /* Initialisations */
205   SpinBox_Dx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
206   SpinBox_Dy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
207   SpinBox_Dz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
208
209   SpinBox_NbSteps->setRange(1, 999999);
210
211   RadioButton1->setChecked(true);
212   MakeGroupsCheck->setChecked(true);
213
214   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
215
216   mySMESHGUI->SetActiveDialogBox(this);
217
218   // Costruction of the logical filter for the elements: mesh/sub-mesh/group
219   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
220   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
221
222   QList<SUIT_SelectionFilter*> aListOfFilters;
223   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
224   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
225
226   myMeshOrSubMeshOrGroupFilter =
227     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
228
229   myHelpFileName = "extrusion_page.html";
230
231   Init();
232
233   /***************************************************************/
234   // signals and slots connections
235   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
236   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
237   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
238   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
239
240   // to update state of the Ok & Apply buttons
241   connect(SpinBox_Dx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
242   connect(SpinBox_Dy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
243   connect(SpinBox_Dz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
244
245   connect(GroupConstructors,    SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
246   connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
247   connect(mySMESHGUI,           SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
248   connect(mySelectionMgr,       SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
249   /* to close dialog if study change */
250   connect(mySMESHGUI,           SIGNAL(SignalCloseAllDialogs()),   this, SLOT(ClickOnCancel()));
251   connect(LineEditElements,     SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
252   connect(CheckBoxMesh,         SIGNAL(toggled(bool)),               SLOT(onSelectMesh(bool)));
253
254   /***************************************************************/
255   
256   ConstructorsClicked(0);
257   SelectionIntoArgument();
258 }
259
260 //=================================================================================
261 // function : ~SMESHGUI_ExtrusionDlg()
262 // purpose  : destructor
263 //=================================================================================
264 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
265 {
266 }
267
268 //=================================================================================
269 // function : Init()
270 // purpose  : initialization
271 //=================================================================================
272 void SMESHGUI_ExtrusionDlg::Init (bool ResetControls)
273 {
274   myBusy = false;
275
276   LineEditElements->clear();
277   myNbOkElements = 0;
278
279   myActor = 0;
280   myMesh = SMESH::SMESH_Mesh::_nil();
281
282   if (ResetControls) {
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   CheckIsEnable();
293 }
294
295 //=================================================================================
296 // function : CheckIsEnable()
297 // purpose  : Check whether the Ok and Apply buttons should be enabled or not
298 //=================================================================================
299 void SMESHGUI_ExtrusionDlg::CheckIsEnable()
300 {
301   double aX = SpinBox_Dx->GetValue();
302   double aY = SpinBox_Dy->GetValue();
303   double aZ = SpinBox_Dz->GetValue();
304   double aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
305   
306   bool anIsEnable = myNbOkElements > 0 && aModule > 1.0E-38;
307
308   buttonOk->setEnabled(anIsEnable);
309   buttonApply->setEnabled(anIsEnable);
310 }
311
312 //=================================================================================
313 // function : ConstructorsClicked()
314 // purpose  : Radio button management
315 //=================================================================================
316 void SMESHGUI_ExtrusionDlg::ConstructorsClicked (int constructorId)
317 {
318   disconnect(mySelectionMgr, 0, this, 0);
319
320   switch (constructorId) {
321   case 0:
322     {
323       GroupArguments->setTitle(tr("EXTRUSION_1D"));
324       if (!CheckBoxMesh->isChecked())
325         {
326           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
327             aViewWindow->SetSelectionMode(EdgeSelection);
328         }
329       break;
330     }
331   case 1:
332     {
333       GroupArguments->setTitle(tr("EXTRUSION_2D"));
334       if (!CheckBoxMesh->isChecked())
335         {
336           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
337             aViewWindow->SetSelectionMode(FaceSelection);
338         }
339       break;
340     }
341   }
342
343   myEditCurrentArgument = LineEditElements;
344   LineEditElements->setFocus();
345
346   if (CheckBoxMesh->isChecked())
347     onSelectMesh(true);
348
349   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
350 }
351
352 //=================================================================================
353 // function : ClickOnApply()
354 // purpose  : Called when user presses <Apply> button
355 //=================================================================================
356 bool SMESHGUI_ExtrusionDlg::ClickOnApply()
357 {
358   if (mySMESHGUI->isActiveStudyLocked())
359     return false;
360
361   if (myNbOkElements) {
362
363     SMESH::DirStruct aVector;
364     aVector.PS.x = SpinBox_Dx->GetValue();
365     aVector.PS.y = SpinBox_Dy->GetValue();
366     aVector.PS.z = SpinBox_Dz->GetValue();
367
368     long aNbSteps = (long)SpinBox_NbSteps->value();
369
370     try {
371       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
372       QApplication::setOverrideCursor(Qt::WaitCursor);
373
374       if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
375         SMESH::ListOfGroups_var groups = 
376           aMeshEditor->ExtrusionSweepMakeGroups(myElementsId.inout(), aVector, aNbSteps);
377       else
378         aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
379
380       QApplication::restoreOverrideCursor();
381     } catch (...) {
382     }
383
384     SMESH::UpdateView();
385     if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
386       mySMESHGUI->updateObjBrowser(true); // new groups may appear
387     Init(false);
388     ConstructorsClicked(GetConstructorId());
389     SelectionIntoArgument();
390   }
391   return true;
392 }
393
394 //=================================================================================
395 // function : ClickOnOk()
396 // purpose  : Called when user presses <OK> button
397 //=================================================================================
398 void SMESHGUI_ExtrusionDlg::ClickOnOk()
399 {
400   if (ClickOnApply())
401     ClickOnCancel();
402 }
403
404 //=================================================================================
405 // function : ClickOnCancel()
406 // purpose  : Called when dialog box is closed
407 //=================================================================================
408 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
409 {
410   disconnect(mySelectionMgr, 0, this, 0);
411   mySelectionMgr->clearFilters();
412   //mySelectionMgr->clearSelected();
413   SMESH::SetPickable(); // ???
414   SMESH::SetPointRepresentation(false);
415   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
416     aViewWindow->SetSelectionMode(ActorSelection);
417   mySMESHGUI->ResetState();
418   reject();
419 }
420
421 //=================================================================================
422 // function : ClickOnHelp()
423 // purpose  :
424 //=================================================================================
425 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
426 {
427   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
428   if (app) 
429     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
430   else {
431     QString platform;
432 #ifdef WIN32
433     platform = "winapplication";
434 #else
435     platform = "application";
436 #endif
437     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
438                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
439                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
440                                                                  platform)).
441                              arg(myHelpFileName));
442   }
443 }
444
445 //=================================================================================
446 // function : onTextChange()
447 // purpose  :
448 //=================================================================================
449 void SMESHGUI_ExtrusionDlg::onTextChange (const QString& theNewText)
450 {
451   QLineEdit* send = (QLineEdit*)sender();
452
453   // return if busy
454   if (myBusy) return;
455
456   // set busy flag
457   myBusy = true;
458
459   if (send == LineEditElements)
460     myNbOkElements = 0;
461
462   // hilight entered elements/nodes
463
464   if (!myIO.IsNull()) {
465     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
466
467     if (send == LineEditElements)
468     {
469       SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
470       SMESH::ElementType SMESHType = GetConstructorId() ? SMESH::FACE : SMESH::EDGE;
471       SMDSAbs_ElementType SMDSType = GetConstructorId() ? SMDSAbs_Face: SMDSAbs_Edge;
472
473       myElementsId = new SMESH::long_array;
474       myElementsId->length( aListId.count() );
475       TColStd_MapOfInteger newIndices;
476       for (int i = 0; i < aListId.count(); i++) {
477         int id = aListId[ i ].toInt();
478         bool validId = false;
479         if ( id > 0 ) {
480           if ( aMesh ) {
481             const SMDS_MeshElement * e = aMesh->FindElement( id );
482             validId = ( e && e->GetType() == SMDSType );
483           } else {
484             validId = ( myMesh->GetElementType( id, true ) == SMESHType );
485           }
486         }
487         if ( validId && newIndices.Add( id ))
488           myElementsId[ newIndices.Extent()-1 ] = id;
489       }
490       myElementsId->length( myNbOkElements = newIndices.Extent() );
491       mySelector->AddOrRemoveIndex(myIO, newIndices, false);
492       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
493         aViewWindow->highlight( myIO, true, true );
494     }
495   }
496
497   CheckIsEnable();
498
499   myBusy = false;
500 }
501
502 //=================================================================================
503 // function : SelectionIntoArgument()
504 // purpose  : Called when selection as changed or other case
505 //=================================================================================
506 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
507 {
508   if (myBusy) return;
509
510   // return if dialog box is inactive
511   if (!GroupButtons->isEnabled())
512     return;
513
514   // clear
515   myActor = 0;
516   myIO.Nullify();
517   QString aString = "";
518
519   // set busy flag
520   myBusy = true;
521
522   myEditCurrentArgument->setText(aString);
523   myNbOkElements = 0;
524   myBusy = false;
525
526   // get selected mesh
527   SALOME_ListIO aList;
528   mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
529   int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
530   if (nbSel != 1)
531     return;
532
533   Handle(SALOME_InteractiveObject) IO = aList.First();
534   myMesh = SMESH::GetMeshByIO(IO);
535   if (myMesh->_is_nil())
536     return;
537   myIO = IO;
538   myActor = SMESH::FindActorByObject(myMesh);
539
540   if (myEditCurrentArgument == LineEditElements) {
541     int aNbElements = 0;
542
543     // MakeGroups is available if there are groups
544     if ( myMesh->NbGroups() == 0 ) {
545       MakeGroupsCheck->setChecked(false);
546       MakeGroupsCheck->setEnabled(false);
547     } else {
548       MakeGroupsCheck->setEnabled(true);
549     }
550
551     if (CheckBoxMesh->isChecked()) {
552       SMESH::ElementType neededType = GetConstructorId() ? SMESH::FACE : SMESH::EDGE;
553
554       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
555
556       SMESH::SMESH_Mesh_var mesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
557
558       if (!mesh->_is_nil()) { //MESH
559         // get elements from mesh
560           myElementsId = mesh->GetElementsByType(neededType);
561           aNbElements = myElementsId->length();
562       } else {
563         SMESH::SMESH_subMesh_var aSubMesh =
564           SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
565         
566         if (!aSubMesh->_is_nil()) { //SUBMESH
567           // get IDs from submesh
568           myElementsId = aSubMesh->GetElementsByType(neededType);
569           aNbElements = myElementsId->length();
570         } else {
571           SMESH::SMESH_GroupBase_var aGroup = 
572             SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
573
574           if (!aGroup->_is_nil() && aGroup->GetType() == neededType) { // GROUP
575             // get IDs from smesh group
576             myElementsId = aGroup->GetListOfID();
577             aNbElements = myElementsId->length();
578           }
579         }
580       }
581     } else {
582       // get indices of selcted elements
583       TColStd_IndexedMapOfInteger aMapIndex;
584       mySelector->GetIndex(IO,aMapIndex);
585       aNbElements = aMapIndex.Extent();
586
587       myElementsId = new SMESH::long_array;
588       myElementsId->length( aNbElements );
589       aString = "";
590       for ( int i = 0; i < aNbElements; ++i )
591         aString += QString(" %1").arg( myElementsId[ i ] = aMapIndex( i+1 ) );
592     }
593
594     if (aNbElements < 1)
595       return;
596
597     myNbOkElements = true;
598   }
599
600   myBusy = true;
601   myEditCurrentArgument->setText(aString);
602   myBusy = false;
603
604   // OK
605   CheckIsEnable();
606 }
607
608 //=================================================================================
609 // function : SetEditCurrentArgument()
610 // purpose  :
611 //=================================================================================
612 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
613 {
614   QPushButton* send = (QPushButton*)sender();
615
616   disconnect(mySelectionMgr, 0, this, 0);
617   mySelectionMgr->clearSelected();
618   mySelectionMgr->clearFilters();
619
620   if (send == SelectElementsButton) {
621     myEditCurrentArgument = LineEditElements;
622     if (CheckBoxMesh->isChecked()) {
623       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
624         aViewWindow->SetSelectionMode(ActorSelection);
625       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
626     } else {
627       int aConstructorId = GetConstructorId();
628       if (aConstructorId == 0)
629         {
630           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
631             aViewWindow->SetSelectionMode(EdgeSelection);
632         }
633       else if (aConstructorId == 1)
634         {
635           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
636             aViewWindow->SetSelectionMode(FaceSelection);
637         }
638     }
639   }
640
641   myEditCurrentArgument->setFocus();
642   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
643   SelectionIntoArgument();
644 }
645
646 //=================================================================================
647 // function : DeactivateActiveDialog()
648 // purpose  : Deactivates this dialog
649 //=================================================================================
650 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
651 {
652   if (ConstructorsBox->isEnabled()) {
653     ConstructorsBox->setEnabled(false);
654     GroupArguments->setEnabled(false);
655     GroupButtons->setEnabled(false);
656     mySMESHGUI->ResetState();
657     mySMESHGUI->SetActiveDialogBox(0);
658   }
659 }
660
661 //=================================================================================
662 // function : ActivateThisDialog()
663 // purpose  : Activates this dialog
664 //=================================================================================
665 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
666 {
667   // Emit a signal to deactivate the active dialog
668   mySMESHGUI->EmitSignalDeactivateDialog();
669   ConstructorsBox->setEnabled(true);
670   GroupArguments->setEnabled(true);
671   GroupButtons->setEnabled(true);
672
673   mySMESHGUI->SetActiveDialogBox(this);
674
675   ConstructorsClicked(GetConstructorId());
676   SelectionIntoArgument();
677 }
678
679 //=================================================================================
680 // function : enterEvent()
681 // purpose  : Mouse enter event
682 //=================================================================================
683 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
684 {
685   if (!ConstructorsBox->isEnabled())
686     ActivateThisDialog();
687 }
688
689 //=================================================================================
690 // function : onSelectMesh()
691 // purpose  :
692 //=================================================================================
693 void SMESHGUI_ExtrusionDlg::onSelectMesh (bool toSelectMesh)
694 {
695   if (toSelectMesh)
696     TextLabelElements->setText(tr("SMESH_NAME"));
697   else
698     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
699
700   if (myEditCurrentArgument != LineEditElements) {
701     LineEditElements->clear();
702     return;
703   }
704
705   mySelectionMgr->clearFilters();
706
707   if (toSelectMesh) {
708     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
709       aViewWindow->SetSelectionMode(ActorSelection);
710     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
711     LineEditElements->setReadOnly(true);
712     LineEditElements->setValidator(0);
713   } else {
714     int aConstructorId = GetConstructorId();
715     if (aConstructorId == 0)
716       {
717         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
718           aViewWindow->SetSelectionMode(EdgeSelection);
719       }
720     else if (aConstructorId == 0)
721       {
722         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
723           aViewWindow->SetSelectionMode(FaceSelection);
724       }
725
726     LineEditElements->setReadOnly(false);
727     LineEditElements->setValidator(myIdValidator);
728     onTextChange(LineEditElements->text());
729   }
730
731   SelectionIntoArgument();
732 }
733
734 //=================================================================================
735 // function : GetConstructorId()
736 // purpose  :
737 //=================================================================================
738 int SMESHGUI_ExtrusionDlg::GetConstructorId()
739 {
740   return GroupConstructors->checkedId();
741 }
742
743 //=================================================================================
744 // function : keyPressEvent()
745 // purpose  :
746 //=================================================================================
747 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
748 {
749   QDialog::keyPressEvent( e );
750   if ( e->isAccepted() )
751     return;
752
753   if ( e->key() == Qt::Key_F1 ) {
754     e->accept();
755     ClickOnHelp();
756   }
757 }