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