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