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