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