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