Salome HOME
Merge from V6_main (04/10/2012)
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ExtrusionDlg.cxx
1 // Copyright (C) 2007-2012  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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_ExtrusionDlg.cxx
25 // Author : Michael ZORIN, Open CASCADE S.A.S.
26 // SMESH includes
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 #include "SMESHGUI_FilterDlg.h"
37 #include "SMESHGUI_MeshEditPreview.h"
38
39 #include <SMESH_Actor.h>
40 #include <SMESH_TypeFilter.hxx>
41 #include <SMESH_LogicalFilter.hxx>
42
43 #include <SMDS_Mesh.hxx>
44
45 // SALOME GUI includes
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_Desktop.h>
48 #include <SUIT_MessageBox.h>
49 #include <SUIT_Session.h>
50 #include <SUIT_OverrideCursor.h>
51
52 #include <LightApp_Application.h>
53 #include <LightApp_SelectionMgr.h>
54
55 #include <SVTK_ViewModel.h>
56 #include <SVTK_ViewWindow.h>
57
58 #include <SalomeApp_IntSpinBox.h>
59
60 // OCCT includes
61 #include <TColStd_MapOfInteger.hxx>
62 #include <TColStd_IndexedMapOfInteger.hxx>
63 #include <gp_XYZ.hxx>
64
65 // Qt includes
66 #include <QApplication>
67 #include <QButtonGroup>
68 #include <QGroupBox>
69 #include <QLabel>
70 #include <QLineEdit>
71 #include <QPushButton>
72 #include <QRadioButton>
73 #include <QCheckBox>
74 #include <QHBoxLayout>
75 #include <QVBoxLayout>
76 #include <QGridLayout>
77 #include <QKeyEvent>
78
79 // IDL includes
80 #include <SALOMEconfig.h>
81 #include CORBA_SERVER_HEADER(SMESH_Group)
82 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
83
84 #define SPACING 6
85 #define MARGIN  11
86
87 //=================================================================================
88 // function : SMESHGUI_ExtrusionDlg()
89 // purpose  : constructor
90 //=================================================================================
91 SMESHGUI_ExtrusionDlg::SMESHGUI_ExtrusionDlg (SMESHGUI* theModule)
92   : SMESHGUI_PreviewDlg( theModule ),
93     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
94     myFilterDlg( 0 ),
95     mySelectedObject(SMESH::SMESH_IDSource::_nil())
96 {
97   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_EDGE")));
98   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_TRIANGLE")));
99   QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
100   QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_NODE")));
101
102   setModal( false );
103   setAttribute( Qt::WA_DeleteOnClose, true );
104   setWindowTitle(tr("EXTRUSION_ALONG_LINE"));
105   setSizeGripEnabled(true);
106
107   QVBoxLayout* SMESHGUI_ExtrusionDlgLayout = new QVBoxLayout(this);
108   SMESHGUI_ExtrusionDlgLayout->setSpacing(SPACING);
109   SMESHGUI_ExtrusionDlgLayout->setMargin(MARGIN);
110
111   /***************************************************************/
112   ConstructorsBox = new QGroupBox(tr("SMESH_EXTRUSION"), this);
113   GroupConstructors = new QButtonGroup(this);
114   QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
115   ConstructorsBoxLayout->setSpacing(SPACING);
116   ConstructorsBoxLayout->setMargin(MARGIN);
117
118   RadioButton0= new QRadioButton(ConstructorsBox);
119   RadioButton0->setIcon(image3);
120   RadioButton1= new QRadioButton(ConstructorsBox);
121   RadioButton1->setIcon(image0);
122   RadioButton2= new QRadioButton(ConstructorsBox);
123   RadioButton2->setIcon(image1);
124
125   ConstructorsBoxLayout->addWidget(RadioButton0);
126   ConstructorsBoxLayout->addWidget(RadioButton1);
127   ConstructorsBoxLayout->addWidget(RadioButton2);
128
129   GroupConstructors->addButton(RadioButton0, 0);
130   GroupConstructors->addButton(RadioButton1, 1);
131   GroupConstructors->addButton(RadioButton2, 2);
132
133   /***************************************************************/
134   GroupButtons = new QGroupBox(this);
135   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
136   GroupButtonsLayout->setSpacing(SPACING);
137   GroupButtonsLayout->setMargin(MARGIN);
138
139   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
140   buttonOk->setAutoDefault(true);
141   buttonOk->setDefault(true);
142   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
143   buttonApply->setAutoDefault(true);
144   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
145   buttonCancel->setAutoDefault(true);
146   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
147   buttonHelp->setAutoDefault(true);
148
149   GroupButtonsLayout->addWidget(buttonOk);
150   GroupButtonsLayout->addSpacing(10);
151   GroupButtonsLayout->addWidget(buttonApply);
152   GroupButtonsLayout->addSpacing(10);
153   GroupButtonsLayout->addStretch();
154   GroupButtonsLayout->addWidget(buttonCancel);
155   GroupButtonsLayout->addWidget(buttonHelp);
156
157   /***************************************************************/
158   GroupArguments = new QGroupBox(tr("EXTRUSION_0D"), this);
159   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
160   GroupArgumentsLayout->setSpacing(SPACING);
161   GroupArgumentsLayout->setMargin(MARGIN);
162
163   myIdValidator = new SMESHGUI_IdValidator(this);
164
165   // Controls for elements selection
166   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
167
168   SelectElementsButton = new QPushButton(GroupArguments);
169   SelectElementsButton->setIcon(image2);
170
171   LineEditElements = new QLineEdit(GroupArguments);
172   LineEditElements->setValidator(myIdValidator);
173   LineEditElements->setMaxLength(-1);
174   myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
175   connect(myFilterBtn,   SIGNAL(clicked()), this, SLOT(setFilters()));
176
177   // Control for the whole mesh selection
178   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
179
180   RadioButton3 = new QRadioButton(GroupArguments);
181   RadioButton3->setText( tr("SMESH_EXTRUSION_TO_DISTANCE") );
182   RadioButton4 = new QRadioButton(GroupArguments);
183   RadioButton4->setText( tr("SMESH_EXTRUSION_ALONG_VECTOR") );
184
185   //Control for the Distance selection
186   TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
187   
188   TextLabelDx = new QLabel(tr("SMESH_X"), GroupArguments);
189   SpinBox_Dx = new SMESHGUI_SpinBox(GroupArguments);
190   
191   TextLabelDy = new QLabel(tr("SMESH_Y"), GroupArguments);
192   SpinBox_Dy = new SMESHGUI_SpinBox(GroupArguments);
193
194   TextLabelDz = new QLabel(tr("SMESH_Z"), GroupArguments);
195   SpinBox_Dz = new SMESHGUI_SpinBox(GroupArguments);
196
197   // Controls for vector selection
198
199   TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupArguments);
200
201   SelectVectorButton = new QPushButton(GroupArguments);
202   SelectVectorButton->setIcon(image2);
203
204   TextLabelVx = new QLabel(tr("SMESH_DX"), GroupArguments);
205   SpinBox_Vx = new SMESHGUI_SpinBox(GroupArguments);
206
207   TextLabelVy = new QLabel(tr("SMESH_DY"), GroupArguments);
208   SpinBox_Vy = new SMESHGUI_SpinBox(GroupArguments);
209
210   TextLabelVz = new QLabel(tr("SMESH_DZ"), GroupArguments);
211   SpinBox_Vz = new SMESHGUI_SpinBox(GroupArguments);
212
213   TextLabelDist = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
214   SpinBox_VDist = new SMESHGUI_SpinBox(GroupArguments);
215
216   // Controls for nb. steps defining
217   TextLabelNbSteps = new QLabel(tr("SMESH_NUMBEROFSTEPS"), GroupArguments);
218   SpinBox_NbSteps = new SalomeApp_IntSpinBox(GroupArguments);
219
220   // CheckBox for groups generation
221   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
222
223   //Preview check box
224   myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
225
226   GroupArgumentsLayout->addWidget(TextLabelElements,    0, 0);
227   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
228   GroupArgumentsLayout->addWidget(LineEditElements,     0, 2, 1, 5);
229   GroupArgumentsLayout->addWidget(myFilterBtn,          0, 7);
230   GroupArgumentsLayout->addWidget(CheckBoxMesh,         1, 0, 1, 8);
231   GroupArgumentsLayout->addWidget(RadioButton3,         2, 1, 1, 3);
232   GroupArgumentsLayout->addWidget(RadioButton4,         2, 5, 1, 3);
233   GroupArgumentsLayout->addWidget(TextLabelDistance,    3, 0);
234   GroupArgumentsLayout->addWidget(TextLabelDx,          3, 2);
235   GroupArgumentsLayout->addWidget(SpinBox_Dx,           3, 3);
236   GroupArgumentsLayout->addWidget(TextLabelDy,          3, 4);
237   GroupArgumentsLayout->addWidget(SpinBox_Dy,           3, 5);
238   GroupArgumentsLayout->addWidget(TextLabelDz,          3, 6);
239   GroupArgumentsLayout->addWidget(SpinBox_Dz,           3, 7);
240   GroupArgumentsLayout->addWidget(TextLabelVector,      4, 0);
241   GroupArgumentsLayout->addWidget(SelectVectorButton,   4, 1);
242   GroupArgumentsLayout->addWidget(TextLabelVx,          4, 2);
243   GroupArgumentsLayout->addWidget(SpinBox_Vx,           4, 3);
244   GroupArgumentsLayout->addWidget(TextLabelVy,          4, 4);
245   GroupArgumentsLayout->addWidget(SpinBox_Vy,           4, 5);
246   GroupArgumentsLayout->addWidget(TextLabelVz,          4, 6);
247   GroupArgumentsLayout->addWidget(SpinBox_Vz,           4, 7);
248   GroupArgumentsLayout->addWidget(TextLabelDist,        5, 0);
249   GroupArgumentsLayout->addWidget(SpinBox_VDist,         5, 3);
250   GroupArgumentsLayout->addWidget(TextLabelNbSteps,     6, 0, 1, 3);
251   GroupArgumentsLayout->addWidget(SpinBox_NbSteps,      6, 3);
252   GroupArgumentsLayout->addWidget(myPreviewCheckBox,    7, 0, 1, 8);
253   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      8, 0, 1, 8);
254   GroupArgumentsLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 8, 0);
255
256
257   /***************************************************************/
258   SMESHGUI_ExtrusionDlgLayout->addWidget(ConstructorsBox);
259   SMESHGUI_ExtrusionDlgLayout->addWidget(GroupArguments);
260   SMESHGUI_ExtrusionDlgLayout->addWidget(GroupButtons);
261
262   /* Initialisations */
263   SpinBox_Vx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
264   SpinBox_Vy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
265   SpinBox_Vz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, "length_precision");
266
267   SpinBox_Dx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
268   SpinBox_Dy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
269   SpinBox_Dz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
270   
271   SpinBox_NbSteps->setRange(1, 999999);
272   SpinBox_VDist->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
273
274   RadioButton0->setChecked(true);
275   RadioButton3->setChecked(true);
276   MakeGroupsCheck->setChecked(true);
277
278   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
279
280   mySMESHGUI->SetActiveDialogBox(this);
281
282   // Costruction of the logical filter for the elements: mesh/sub-mesh/group
283   QList<SUIT_SelectionFilter*> aListOfFilters;
284   aListOfFilters.append(new SMESH_TypeFilter (MESH));
285   aListOfFilters.append(new SMESH_TypeFilter (SUBMESH_VERTEX));
286   aListOfFilters.append(new SMESH_TypeFilter (GROUP_NODE));
287   myMeshOrSubMeshOrGroupFilter0D =
288     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
289   aListOfFilters[0] = new SMESH_TypeFilter (MESH);
290   aListOfFilters[1] = new SMESH_TypeFilter (SUBMESH_EDGE);
291   aListOfFilters[2] = new SMESH_TypeFilter (GROUP_EDGE);
292   myMeshOrSubMeshOrGroupFilter1D =
293     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
294   aListOfFilters[0] = new SMESH_TypeFilter (MESH);
295   aListOfFilters[1] = new SMESH_TypeFilter (SUBMESH_FACE);
296   aListOfFilters[2] = new SMESH_TypeFilter (GROUP_FACE);
297   myMeshOrSubMeshOrGroupFilter2D =
298     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
299
300   myHelpFileName = "extrusion_page.html";
301
302   Init();
303
304   /***************************************************************/
305   // signals and slots connections
306   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
307   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
308   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
309   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
310
311   connect(RadioButton3, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
312   connect(RadioButton4, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
313
314   // to update state of the Ok & Apply buttons
315   connect(SpinBox_Vx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
316   connect(SpinBox_Vy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
317   connect(SpinBox_Vz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
318   connect(SpinBox_Dx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
319   connect(SpinBox_Dy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
320   connect(SpinBox_Dz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
321
322   connect(GroupConstructors,    SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
323   connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
324   connect(SelectVectorButton,   SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
325   connect(mySMESHGUI,           SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
326   connect(mySelectionMgr,       SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
327   /* to close dialog if study change */
328   connect(mySMESHGUI,           SIGNAL(SignalCloseAllDialogs()),   this, SLOT(ClickOnCancel()));
329   connect(LineEditElements,     SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
330   connect(CheckBoxMesh,         SIGNAL(toggled(bool)),               SLOT(onSelectMesh(bool)));
331
332   connect(SpinBox_Dx,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
333   connect(SpinBox_Dy,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
334   connect(SpinBox_Dz,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
335   connect(SpinBox_Vx,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
336   connect(SpinBox_Vy,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
337   connect(SpinBox_Vz,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
338   connect(SpinBox_VDist,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
339   connect(SpinBox_NbSteps,  SIGNAL(valueChanged(int)), this, SLOT(toDisplaySimulation()));
340
341   //To Connect preview check box
342   connectPreviewControl();
343
344   /***************************************************************/
345   
346   ConstructorsClicked(0);
347   ClickOnRadio();
348   SelectionIntoArgument();
349 }
350
351 //=================================================================================
352 // function : ~SMESHGUI_ExtrusionDlg()
353 // purpose  : destructor
354 //=================================================================================
355 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
356 {
357   if ( myFilterDlg != 0 ) {
358     myFilterDlg->setParent( 0 );
359     delete myFilterDlg;
360   }
361   if ( myMeshOrSubMeshOrGroupFilter0D ) delete myMeshOrSubMeshOrGroupFilter0D;
362   if ( myMeshOrSubMeshOrGroupFilter1D ) delete myMeshOrSubMeshOrGroupFilter1D;
363   if ( myMeshOrSubMeshOrGroupFilter2D ) delete myMeshOrSubMeshOrGroupFilter2D;
364 }
365
366 //=================================================================================
367 // function : Init()
368 // purpose  : initialization
369 //=================================================================================
370 void SMESHGUI_ExtrusionDlg::Init (bool ResetControls)
371 {
372   myBusy = false;
373   myIDs.clear();
374
375   LineEditElements->clear();
376   myNbOkElements = 0;
377
378   myActor = 0;
379   myMesh = SMESH::SMESH_Mesh::_nil();
380
381   if (ResetControls) {
382     SpinBox_NbSteps->setValue(1);
383     SpinBox_VDist->setValue(10);
384     SpinBox_Dx->SetValue(0);
385     SpinBox_Dy->SetValue(0);
386     SpinBox_Dz->SetValue(0);
387     SpinBox_Vx->SetValue(0);
388     SpinBox_Vy->SetValue(0);
389     SpinBox_Vz->SetValue(0);
390
391     CheckBoxMesh->setChecked(false);
392     onSelectMesh(false);
393     myPreviewCheckBox->setChecked(false);
394     onDisplaySimulation(false);
395   }
396
397   CheckIsEnable();
398 }
399
400 //=================================================================================
401 // function : CheckIsEnable()
402 // purpose  : Check whether the Ok and Apply buttons should be enabled or not
403 //=================================================================================
404 void SMESHGUI_ExtrusionDlg::CheckIsEnable()
405 {  
406   bool anIsEnable = myNbOkElements > 0 && isValuesValid();
407
408   buttonOk->setEnabled(anIsEnable);
409   buttonApply->setEnabled(anIsEnable);
410 }
411
412 //=================================================================================
413 // function : isValuesValid()
414 // purpose  : Return true in case if values entered into dialog are valid
415 //=================================================================================
416 bool SMESHGUI_ExtrusionDlg::isValuesValid() {
417   double aX, aY, aZ, aModule = 0;
418   if ( RadioButton3->isChecked() ) {
419     aX = SpinBox_Dx->GetValue();
420     aY = SpinBox_Dy->GetValue();
421     aZ = SpinBox_Dz->GetValue();
422     aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
423   } else   if ( RadioButton4->isChecked() ) {
424     aX = SpinBox_Vx->GetValue();
425     aY = SpinBox_Vy->GetValue();
426     aZ = SpinBox_Vz->GetValue();
427     aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
428   }
429   return aModule > 1.0E-38;
430 }
431
432 //=================================================================================
433 // function : ConstructorsClicked()
434 // purpose  : Radio button management
435 //=================================================================================
436 void SMESHGUI_ExtrusionDlg::ConstructorsClicked (int constructorId)
437 {
438   disconnect(mySelectionMgr, 0, this, 0);
439
440   hidePreview();
441
442   TextLabelElements->setText(tr( constructorId ? "SMESH_ID_ELEMENTS" : "SMESH_ID_NODES"));
443
444   switch (constructorId) {
445   case 0:
446     {
447       GroupArguments->setTitle(tr("EXTRUSION_0D"));
448       if (!CheckBoxMesh->isChecked())
449       {
450         LineEditElements->clear();
451         myIDs.clear();
452         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
453           aViewWindow->SetSelectionMode(NodeSelection);
454       }
455       break;
456     }
457   case 1:
458     {
459       GroupArguments->setTitle(tr("EXTRUSION_1D"));
460       if (!CheckBoxMesh->isChecked())
461       {
462         LineEditElements->clear();
463         myIDs.clear();
464         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
465           aViewWindow->SetSelectionMode(EdgeSelection);
466       }
467       break;
468     }
469   case 2:
470     {
471       GroupArguments->setTitle(tr("EXTRUSION_2D"));
472       if (!CheckBoxMesh->isChecked())
473       {
474         LineEditElements->clear();
475         myIDs.clear();
476         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
477           aViewWindow->SetSelectionMode(FaceSelection);
478       }
479       break;
480     }
481   }
482
483   myEditCurrentArgument = (QWidget*)LineEditElements;
484   LineEditElements->setFocus();
485
486   if (CheckBoxMesh->isChecked())
487     onSelectMesh(true);
488
489   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
490 }
491
492 //=================================================================================
493 // function : ConstructorsClicked()
494 // purpose  : Radio button management
495 //=================================================================================
496 void SMESHGUI_ExtrusionDlg::ClickOnRadio()
497 {
498   if ( RadioButton3->isChecked() ) {
499     TextLabelDistance->show();
500     TextLabelDx->show();
501     SpinBox_Dx->show();
502     TextLabelDy->show();
503     SpinBox_Dy->show();
504     TextLabelDz->show();
505     SpinBox_Dz->show();
506
507     TextLabelVector->hide();
508     TextLabelVx->hide();
509     SpinBox_Vx->hide();
510     TextLabelVy->hide();
511     SpinBox_Vy->hide();
512     TextLabelVz->hide();
513     SpinBox_Vz->hide();
514     TextLabelDist->hide();
515     SpinBox_VDist->hide();
516     SelectVectorButton->hide();
517   } else if ( RadioButton4->isChecked() ) {
518     TextLabelDistance->hide();
519     TextLabelDx->hide();
520     SpinBox_Dx->hide();
521     TextLabelDy->hide();
522     SpinBox_Dy->hide();
523     TextLabelDz->hide();
524     SpinBox_Dz->hide();
525
526     TextLabelVector->show();
527     TextLabelVx->show();
528     SpinBox_Vx->show();
529     TextLabelVy->show();
530     SpinBox_Vy->show();
531     TextLabelVz->show();
532     SpinBox_Vz->show();
533     TextLabelDist->show();
534     SpinBox_VDist->show();
535     SelectVectorButton->show();
536   }
537   onDisplaySimulation(true);
538   // AdjustSize
539   qApp->processEvents();
540   updateGeometry();
541   resize( minimumSizeHint() );
542 }
543
544 //=================================================================================
545 // function : ClickOnApply()
546 // purpose  : Called when user presses <Apply> button
547 //=================================================================================
548 bool SMESHGUI_ExtrusionDlg::ClickOnApply()
549 {
550   if (mySMESHGUI->isActiveStudyLocked())
551     return false;
552
553   if (!isValid())
554     return false;
555
556   if (myNbOkElements) {
557
558     SMESH::DirStruct aVector;
559     getExtrusionVector(aVector);
560     
561     QStringList aParameters;
562     if ( RadioButton3->isChecked() ) {
563       aParameters << SpinBox_Dx->text();
564       aParameters << SpinBox_Dy->text();
565       aParameters << SpinBox_Dz->text();
566     } else if ( RadioButton4->isChecked() ) {
567       // only 3 coords in a python dump command :(
568       // aParameters << SpinBox_Vx->text();
569       // aParameters << SpinBox_Vy->text();
570       // aParameters << SpinBox_Vz->text();
571       // aParameters << SpinBox_VDist->text();
572     }
573
574     long aNbSteps = (long)SpinBox_NbSteps->value();
575
576     aParameters << SpinBox_NbSteps->text();
577
578     try {
579       SUIT_OverrideCursor aWaitCursor;
580       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
581
582       myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
583
584       if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) {
585         if( CheckBoxMesh->isChecked() ) 
586           switch (GetConstructorId() ) {
587             case 0:
588               {
589                 SMESH::ListOfGroups_var groups = 
590                   aMeshEditor->ExtrusionSweepObject0DMakeGroups(mySelectedObject, aVector, aNbSteps);
591                 break;
592               }
593             case 1:
594               {
595                 SMESH::ListOfGroups_var groups = 
596                   aMeshEditor->ExtrusionSweepObject1DMakeGroups(mySelectedObject, aVector, aNbSteps);
597                 break;
598               }
599             case 2:
600               {
601                 SMESH::ListOfGroups_var groups = 
602                   aMeshEditor->ExtrusionSweepObject2DMakeGroups(mySelectedObject, aVector, aNbSteps);
603                 break;
604               }
605           }
606         else
607         {
608           SMESH::ListOfGroups_var groups;
609           if (GetConstructorId() == 0)
610             groups = aMeshEditor->ExtrusionSweepMakeGroups0D(myElementsId.inout(), aVector, aNbSteps);
611           else
612             groups = aMeshEditor->ExtrusionSweepMakeGroups(myElementsId.inout(), aVector, aNbSteps);
613         }
614
615       }
616       else {
617         if( CheckBoxMesh->isChecked() ) 
618           switch( GetConstructorId() ) {
619             case 0:
620               {
621               aMeshEditor->ExtrusionSweepObject0D(mySelectedObject, aVector, aNbSteps);
622                 break;
623               }
624             case 1:
625               {
626               aMeshEditor->ExtrusionSweepObject1D(mySelectedObject, aVector, aNbSteps);
627                 break;
628               }
629             case 2:
630               {
631               aMeshEditor->ExtrusionSweepObject2D(mySelectedObject, aVector, aNbSteps);
632                 break;
633           }
634         }
635         else
636           if (GetConstructorId() == 0)
637             aMeshEditor->ExtrusionSweep0D(myElementsId.inout(), aVector, aNbSteps);
638           else
639             aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
640       }
641
642     } catch (...) {
643     }
644
645     SMESH::Update(myIO, SMESH::eDisplay);
646     if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
647       mySMESHGUI->updateObjBrowser(true); // new groups may appear
648     Init(false);
649     ConstructorsClicked(GetConstructorId());
650     mySelectionMgr->clearSelected();
651     mySelectedObject = SMESH::SMESH_IDSource::_nil();
652     SelectionIntoArgument();
653
654     SMESHGUI::Modified();
655   }
656   return true;
657 }
658
659 //=================================================================================
660 // function : ClickOnOk()
661 // purpose  : Called when user presses <OK> button
662 //=================================================================================
663 void SMESHGUI_ExtrusionDlg::ClickOnOk()
664 {
665   if (ClickOnApply())
666     ClickOnCancel();
667 }
668
669 //=================================================================================
670 // function : ClickOnCancel()
671 // purpose  : Called when dialog box is closed
672 //=================================================================================
673 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
674 {
675   reject();
676 }
677
678 //=================================================================================
679 // function : ClickOnHelp()
680 // purpose  :
681 //=================================================================================
682 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
683 {
684   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
685   if (app) 
686     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
687   else {
688     QString platform;
689 #ifdef WIN32
690     platform = "winapplication";
691 #else
692     platform = "application";
693 #endif
694     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
695                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
696                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
697                                                                  platform)).
698                              arg(myHelpFileName));
699   }
700 }
701
702 //=================================================================================
703 // function : onTextChange()
704 // purpose  :
705 //=================================================================================
706 void SMESHGUI_ExtrusionDlg::onTextChange (const QString& theNewText)
707 {
708   QLineEdit* send = (QLineEdit*)sender();
709
710   // return if busy
711   if (myBusy) return;
712
713   // set busy flag
714   myBusy = true;
715
716   if (send == LineEditElements)
717     myNbOkElements = 0;
718
719   // hilight entered elements/nodes
720
721   if (!myIO.IsNull()) {
722     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
723
724     if (send == LineEditElements)
725     {
726       SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
727       SMESH::ElementType SMESHType;
728       SMDSAbs_ElementType SMDSType;
729       switch (GetConstructorId()) {
730       case 0:
731         {
732           SMESHType = SMESH::NODE;
733           SMDSType = SMDSAbs_Node;
734           break;
735         }
736       case 1:
737         {
738           SMESHType = SMESH::EDGE;
739           SMDSType = SMDSAbs_Edge;
740           break;                  
741         }
742       case 2:
743         {
744           SMESHType = SMESH::FACE;
745           SMDSType = SMDSAbs_Face;
746           break;
747         }
748       }
749       myElementsId = new SMESH::long_array;
750       myElementsId->length( aListId.count() );
751       TColStd_MapOfInteger newIndices;
752       for (int i = 0; i < aListId.count(); i++) {
753         int id = aListId[ i ].toInt();
754         bool validId = false;
755         if ( id > 0 ) {
756           if ( aMesh ) {
757             const SMDS_MeshElement * e;
758             if (SMDSType == SMDSAbs_Node)
759               e = aMesh->FindNode( id ); 
760             else
761               e = aMesh->FindElement( id );
762             validId = ( e && e->GetType() == SMDSType );
763           } else {
764             validId = ( myMesh->GetElementType( id, true ) == SMESHType );
765           }
766         }
767         if ( validId && newIndices.Add( id ))
768           myElementsId[ newIndices.Extent()-1 ] = id;
769       }
770       myElementsId->length( myNbOkElements = newIndices.Extent() );
771       mySelector->AddOrRemoveIndex(myIO, newIndices, false);
772       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
773         aViewWindow->highlight( myIO, true, true );
774     }
775   }
776
777   CheckIsEnable();
778
779   onDisplaySimulation(true);
780
781   myBusy = false;
782 }
783
784 //=================================================================================
785 // function : SelectionIntoArgument()
786 // purpose  : Called when selection as changed or other case
787 //=================================================================================
788 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
789 {
790   if (myBusy) return;
791
792   // return if dialog box is inactive
793   if (!GroupButtons->isEnabled())
794     return;
795
796   // clear
797   if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
798     myActor = 0;
799     Handle(SALOME_InteractiveObject) resIO = myIO;
800     myIO.Nullify();
801   }
802
803   QString aString = "";
804   // set busy flag
805   if(myEditCurrentArgument == (QWidget*)LineEditElements) {
806     myBusy = true;
807     LineEditElements->setText(aString);
808     myNbOkElements = 0;
809     myBusy = false;
810   }
811   // get selected mesh
812   SALOME_ListIO aList;
813   mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
814   int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
815   if (nbSel != 1)
816     return;
817
818   Handle(SALOME_InteractiveObject) IO = aList.First();
819
820   if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
821     myMesh = SMESH::GetMeshByIO(IO);
822     if (myMesh->_is_nil())
823       return;
824     myIO = IO;
825     myActor = SMESH::FindActorByObject(myMesh);
826   }
827
828   if (myEditCurrentArgument == (QWidget*)LineEditElements) {    
829     int aNbElements = 0;
830
831     // MakeGroups is available if there are groups
832     if ( myMesh->NbGroups() == 0 ) {
833       MakeGroupsCheck->setChecked(false);
834       MakeGroupsCheck->setEnabled(false);
835     } else {
836       MakeGroupsCheck->setEnabled(true);
837     }
838
839     if (CheckBoxMesh->isChecked()) {
840       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
841
842       if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
843         mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
844       else
845         return;
846     } else {
847       // get indices of selcted elements
848       TColStd_IndexedMapOfInteger aMapIndex;
849       mySelector->GetIndex(IO,aMapIndex);
850       aNbElements = aMapIndex.Extent();
851
852       if (aNbElements < 1)
853         return;
854
855       myElementsId = new SMESH::long_array;
856       myElementsId->length( aNbElements );
857       aString = "";
858       for ( int i = 0; i < aNbElements; ++i )
859         aString += QString(" %1").arg( myElementsId[ i ] = aMapIndex( i+1 ) );
860     }
861
862     myNbOkElements = true;
863
864     myBusy = true;
865     ((QLineEdit*)myEditCurrentArgument)->setText(aString);
866     myBusy = false;
867   }
868   else if(myEditCurrentArgument == (QWidget*)SpinBox_Vx){
869     TColStd_IndexedMapOfInteger aMapIndex;
870     mySelector->GetIndex(IO,aMapIndex);
871     int aNbElements = aMapIndex.Extent();
872     SMESH::SMESH_Mesh_var aMesh_var = SMESH::GetMeshByIO(IO);
873     SMESH_Actor* anActor = SMESH::FindActorByObject(aMesh_var);
874     SMDS_Mesh* aMesh =  anActor ? anActor->GetObject()->GetMesh() : 0;
875
876     if(aNbElements != 1 || !aMesh)
877       return;
878     
879     const SMDS_MeshFace* face = dynamic_cast<const SMDS_MeshFace*>(aMesh->FindElement(aMapIndex(aNbElements)));
880
881     if (!face)
882       return;
883
884     gp_XYZ aNormale = SMESH::getNormale(face);
885     SpinBox_Vx->SetValue(aNormale.X());
886     SpinBox_Vy->SetValue(aNormale.Y());
887     SpinBox_Vz->SetValue(aNormale.Z());
888     
889   }
890   
891   onDisplaySimulation(true);
892   
893   // OK
894   CheckIsEnable();
895 }
896
897 //=================================================================================
898 // function : SetEditCurrentArgument()
899 // purpose  :
900 //=================================================================================
901 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
902 {
903   QPushButton* send = (QPushButton*)sender();
904
905   disconnect(mySelectionMgr, 0, this, 0);
906   mySelectionMgr->clearSelected();
907   mySelectionMgr->clearFilters();
908
909   if (send == SelectElementsButton) {
910     myEditCurrentArgument = (QWidget*)LineEditElements;
911     if (CheckBoxMesh->isChecked())
912     {
913       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
914         aViewWindow->SetSelectionMode(ActorSelection);
915       switch( GetConstructorId() ) {
916       case 0: mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter0D); break;
917       case 1: mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter1D); break;
918       case 2: mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter2D); break;
919       }
920     }
921     else
922     {
923       int aConstructorId = GetConstructorId();
924       switch(aConstructorId) {
925       case 0:
926         {
927           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
928             aViewWindow->SetSelectionMode(NodeSelection);
929           break;
930         }
931       case 1:
932         {
933           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
934             aViewWindow->SetSelectionMode(EdgeSelection);
935           break;
936         }
937       case 2:
938         {
939           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
940             aViewWindow->SetSelectionMode(FaceSelection);
941           break;
942         }
943       }
944     }
945   }
946   else if (send == SelectVectorButton){
947     myEditCurrentArgument = (QWidget*)SpinBox_Vx;
948     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
949       aViewWindow->SetSelectionMode(FaceSelection);
950   }
951   
952   myEditCurrentArgument->setFocus();
953   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
954   SelectionIntoArgument();
955 }
956
957 //=================================================================================
958 // function : DeactivateActiveDialog()
959 // purpose  : Deactivates this dialog
960 //=================================================================================
961 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
962 {
963   if (ConstructorsBox->isEnabled()) {
964     ConstructorsBox->setEnabled(false);
965     GroupArguments->setEnabled(false);
966     GroupButtons->setEnabled(false);
967     mySMESHGUI->ResetState();
968     mySMESHGUI->SetActiveDialogBox(0);
969   }
970 }
971
972 //=================================================================================
973 // function : ActivateThisDialog()
974 // purpose  : Activates this dialog
975 //=================================================================================
976 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
977 {
978   // Emit a signal to deactivate the active dialog
979   mySMESHGUI->EmitSignalDeactivateDialog();
980   ConstructorsBox->setEnabled(true);
981   GroupArguments->setEnabled(true);
982   GroupButtons->setEnabled(true);
983
984   mySMESHGUI->SetActiveDialogBox(this);
985
986   ConstructorsClicked(GetConstructorId());
987   SelectionIntoArgument();
988 }
989
990 //=================================================================================
991 // function : enterEvent()
992 // purpose  : Mouse enter event
993 //=================================================================================
994 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
995 {
996   if (!ConstructorsBox->isEnabled())
997     ActivateThisDialog();
998 }
999
1000 //=================================================================================
1001 // function : closeEvent()
1002 // purpose  :
1003 //=================================================================================
1004 void SMESHGUI_ExtrusionDlg::closeEvent( QCloseEvent* )
1005 {
1006   /* same than click on cancel button */
1007   disconnect(mySelectionMgr, 0, this, 0);
1008   mySelectionMgr->clearFilters();
1009   //mySelectionMgr->clearSelected();
1010   if (SMESH::GetCurrentVtkView()) {
1011     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1012     SMESH::SetPointRepresentation(false);
1013     SMESH::SetPickable();
1014   }
1015   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1016     aViewWindow->SetSelectionMode(ActorSelection);
1017   mySMESHGUI->ResetState();
1018 }
1019
1020 void SMESHGUI_ExtrusionDlg::reject()
1021 {
1022   QDialog::reject();
1023   close();
1024 }
1025
1026 //=================================================================================
1027 // function : onSelectMesh()
1028 // purpose  :
1029 //=================================================================================
1030 void SMESHGUI_ExtrusionDlg::onSelectMesh (bool toSelectMesh)
1031 {
1032   if (toSelectMesh) {
1033     myIDs = LineEditElements->text();
1034     TextLabelElements->setText(tr("SMESH_NAME"));
1035   }
1036   else
1037     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
1038
1039   myFilterBtn->setEnabled(!toSelectMesh);
1040
1041   if (myEditCurrentArgument != LineEditElements) {
1042     LineEditElements->clear();
1043     return;
1044   }
1045
1046   mySelectionMgr->clearFilters();
1047
1048   if (toSelectMesh)
1049   {
1050     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1051       aViewWindow->SetSelectionMode(ActorSelection);
1052     switch( GetConstructorId() ) {
1053     case 0: mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter0D); break;
1054     case 1: mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter1D); break;
1055     case 2: mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter2D); break;
1056     }
1057     LineEditElements->setReadOnly(true);
1058     LineEditElements->setValidator(0);
1059   }
1060   else
1061   {
1062     int aConstructorId = GetConstructorId();
1063     switch(aConstructorId) {
1064       case 0:
1065         {
1066           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1067             aViewWindow->SetSelectionMode(NodeSelection);
1068           break;
1069         }
1070       case 1:
1071         {
1072           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1073             aViewWindow->SetSelectionMode(EdgeSelection);
1074           break;
1075         }
1076       case 2:
1077         {
1078           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1079             aViewWindow->SetSelectionMode(FaceSelection);
1080           break;
1081         }
1082     }
1083     LineEditElements->setReadOnly(false);
1084     LineEditElements->setValidator(myIdValidator);
1085     onTextChange(LineEditElements->text());
1086   }
1087
1088   SelectionIntoArgument();
1089
1090   if (!toSelectMesh)
1091     LineEditElements->setText( myIDs );
1092 }
1093
1094 //=================================================================================
1095 // function : GetConstructorId()
1096 // purpose  :
1097 //=================================================================================
1098 int SMESHGUI_ExtrusionDlg::GetConstructorId()
1099 {
1100   return GroupConstructors->checkedId();
1101 }
1102
1103 //=================================================================================
1104 // function : keyPressEvent()
1105 // purpose  :
1106 //=================================================================================
1107 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
1108 {
1109   QDialog::keyPressEvent( e );
1110   if ( e->isAccepted() )
1111     return;
1112
1113   if ( e->key() == Qt::Key_F1 ) {
1114     e->accept();
1115     ClickOnHelp();
1116   }
1117 }
1118
1119 //=================================================================================
1120 // function : setFilters()
1121 // purpose  : SLOT. Called when "Filter" button pressed.
1122 //=================================================================================
1123 void SMESHGUI_ExtrusionDlg::setFilters()
1124 {
1125   if(myMesh->_is_nil()) {
1126     SUIT_MessageBox::critical(this,
1127                               tr("SMESH_ERROR"),
1128                               tr("NO_MESH_SELECTED"));
1129    return;
1130   }
1131   if ( !myFilterDlg )
1132   {
1133     QList<int> types;  
1134     types.append( SMESH::NODE );
1135     types.append( SMESH::EDGE );
1136     types.append( SMESH::FACE );
1137     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
1138   }
1139   switch( GetConstructorId() ){
1140     case 0: 
1141       {
1142       myFilterDlg->Init( SMESH::NODE );
1143         break;
1144       }
1145     case 1:
1146       {
1147       myFilterDlg->Init( SMESH::EDGE );
1148         break;
1149       }
1150     case 2:
1151       {
1152       myFilterDlg->Init( SMESH::FACE );
1153         break;
1154       }
1155   }
1156   
1157
1158   myFilterDlg->SetSelection();
1159   myFilterDlg->SetMesh( myMesh );
1160   myFilterDlg->SetSourceWg( LineEditElements );
1161
1162   myFilterDlg->show();
1163 }
1164
1165 //=================================================================================
1166 // function : isValid
1167 // purpose  :
1168 //=================================================================================
1169 bool SMESHGUI_ExtrusionDlg::isValid()
1170 {
1171   QString msg;
1172   bool ok = true;
1173   if ( RadioButton3->isChecked() ) {
1174     ok = SpinBox_Dx->isValid( msg, true ) && ok;
1175     ok = SpinBox_Dy->isValid( msg, true ) && ok;
1176     ok = SpinBox_Dz->isValid( msg, true ) && ok;
1177   } else if ( RadioButton4->isChecked() ) {
1178     ok = SpinBox_Vx->isValid( msg, true ) && ok;
1179     ok = SpinBox_Vy->isValid( msg, true ) && ok;
1180     ok = SpinBox_Vz->isValid( msg, true ) && ok;
1181     ok = SpinBox_VDist->isValid( msg, true ) && ok;
1182   }
1183   ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
1184
1185   if( !ok ) {
1186     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1187     if ( !msg.isEmpty() )
1188       str += "\n" + msg;
1189     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1190     return false;
1191   }
1192   return true;
1193 }
1194
1195 //=================================================================================
1196 // function : onDisplaySimulation
1197 // purpose  : Show/Hide preview
1198 //=================================================================================
1199 void SMESHGUI_ExtrusionDlg::onDisplaySimulation( bool toDisplayPreview ) {
1200   if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1201     if (myNbOkElements && isValid() && isValuesValid()) {
1202       //Get input vector
1203       SMESH::DirStruct aVector;
1204       getExtrusionVector(aVector);
1205
1206       //Get Number of the steps 
1207       long aNbSteps = (long)SpinBox_NbSteps->value();
1208       
1209       try {
1210         SUIT_OverrideCursor aWaitCursor;
1211         SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1212         if( CheckBoxMesh->isChecked() ) {
1213           switch (GetConstructorId()) {
1214             case 0:
1215               {
1216                 aMeshEditor->ExtrusionSweepObject0D(mySelectedObject, aVector, aNbSteps);
1217                                         break;
1218               }
1219             case 1:
1220               {
1221                 aMeshEditor->ExtrusionSweepObject1D(mySelectedObject, aVector, aNbSteps);
1222                                         break;
1223               }
1224             case 2:
1225               {
1226                 aMeshEditor->ExtrusionSweepObject2D(mySelectedObject, aVector, aNbSteps);
1227                                         break;
1228               }
1229           }
1230         }
1231         else
1232           if(GetConstructorId() == 0)
1233             aMeshEditor->ExtrusionSweep0D(myElementsId.inout(), aVector, aNbSteps);
1234           else
1235             aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
1236         
1237         SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1238         mySimulation->SetData(aMeshPreviewStruct._retn());
1239       } catch (...) {
1240         hidePreview();
1241       }
1242     } else {
1243       hidePreview();
1244     }
1245   } else {
1246     hidePreview();
1247   }
1248 }
1249
1250 //=================================================================================
1251 // function : getExtrusionVector()
1252 // purpose  : get direction of the extrusion
1253 //=================================================================================
1254 void SMESHGUI_ExtrusionDlg::getExtrusionVector(SMESH::DirStruct& aVector) {
1255   if ( RadioButton3->isChecked() ) {
1256     aVector.PS.x = SpinBox_Dx->GetValue();
1257     aVector.PS.y = SpinBox_Dy->GetValue();
1258     aVector.PS.z = SpinBox_Dz->GetValue();      
1259   } else if ( RadioButton4->isChecked() ) {
1260     gp_XYZ aNormale(SpinBox_Vx->GetValue(),
1261                     SpinBox_Vy->GetValue(),
1262                     SpinBox_Vz->GetValue());
1263     
1264     
1265     aNormale /= aNormale.Modulus();
1266     double aVDist = (double)SpinBox_VDist->value();
1267     
1268     aVector.PS.x = aNormale.X()*aVDist;
1269     aVector.PS.y = aNormale.Y()*aVDist;
1270     aVector.PS.z = aNormale.Z()*aVDist;
1271   }
1272 }