Salome HOME
0019928: EDF 771 SMESH : Extrusion (Revolution) with normal to a face
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ExtrusionDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File   : SMESHGUI_ExtrusionDlg.cxx
24 // Author : Michael ZORIN, Open CASCADE S.A.S.
25 // SMESH includes
26 //
27 #include "SMESHGUI_ExtrusionDlg.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_SpinBox.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESHGUI_FilterDlg.h"
36
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_LogicalFilter.hxx>
40
41 #include <SMDS_Mesh.hxx>
42
43 // SALOME GUI includes
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Desktop.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_Session.h>
48 #include <SUIT_OverrideCursor.h>
49
50 #include <LightApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
52
53 #include <SVTK_ViewModel.h>
54 #include <SVTK_ViewWindow.h>
55
56 #include <SalomeApp_IntSpinBox.h>
57
58 // OCCT includes
59 #include <TColStd_MapOfInteger.hxx>
60 #include <TColStd_IndexedMapOfInteger.hxx>
61 #include <gp_XYZ.hxx>
62
63 // Qt includes
64 #include <QApplication>
65 #include <QButtonGroup>
66 #include <QGroupBox>
67 #include <QLabel>
68 #include <QLineEdit>
69 #include <QPushButton>
70 #include <QRadioButton>
71 #include <QCheckBox>
72 #include <QHBoxLayout>
73 #include <QVBoxLayout>
74 #include <QGridLayout>
75 #include <QKeyEvent>
76
77 // IDL includes
78 #include <SALOMEconfig.h>
79 #include CORBA_SERVER_HEADER(SMESH_Group)
80 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
81
82 #define SPACING 6
83 #define MARGIN  11
84
85 //=================================================================================
86 // function : SMESHGUI_ExtrusionDlg()
87 // purpose  : constructor
88 //=================================================================================
89 SMESHGUI_ExtrusionDlg::SMESHGUI_ExtrusionDlg (SMESHGUI* theModule)
90   : QDialog( SMESH::GetDesktop( theModule ) ),
91     mySMESHGUI( theModule ),
92     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
93     myFilterDlg( 0 ),
94     mySelectedObject(SMESH::SMESH_IDSource::_nil())
95 {
96   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_EDGE")));
97   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_TRIANGLE")));
98   QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
99
100   setModal( false );
101   setAttribute( Qt::WA_DeleteOnClose, true );
102   setWindowTitle(tr("EXTRUSION_ALONG_LINE"));
103   setSizeGripEnabled(true);
104
105   QVBoxLayout* SMESHGUI_ExtrusionDlgLayout = new QVBoxLayout(this);
106   SMESHGUI_ExtrusionDlgLayout->setSpacing(SPACING);
107   SMESHGUI_ExtrusionDlgLayout->setMargin(MARGIN);
108
109   /***************************************************************/
110   ConstructorsBox = new QGroupBox(tr("SMESH_EXTRUSION"), this);
111   GroupConstructors = new QButtonGroup(this);
112   QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
113   ConstructorsBoxLayout->setSpacing(SPACING);
114   ConstructorsBoxLayout->setMargin(MARGIN);
115
116   RadioButton1= new QRadioButton(ConstructorsBox);
117   RadioButton1->setIcon(image0);
118   RadioButton2= new QRadioButton(ConstructorsBox);
119   RadioButton2->setIcon(image1);
120
121   ConstructorsBoxLayout->addWidget(RadioButton1);
122   ConstructorsBoxLayout->addWidget(RadioButton2);
123
124   GroupConstructors->addButton(RadioButton1, 0);
125   GroupConstructors->addButton(RadioButton2, 1);
126
127   /***************************************************************/
128   GroupButtons = new QGroupBox(this);
129   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
130   GroupButtonsLayout->setSpacing(SPACING);
131   GroupButtonsLayout->setMargin(MARGIN);
132
133   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
134   buttonOk->setAutoDefault(true);
135   buttonOk->setDefault(true);
136   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
137   buttonApply->setAutoDefault(true);
138   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
139   buttonCancel->setAutoDefault(true);
140   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
141   buttonHelp->setAutoDefault(true);
142
143   GroupButtonsLayout->addWidget(buttonOk);
144   GroupButtonsLayout->addSpacing(10);
145   GroupButtonsLayout->addWidget(buttonApply);
146   GroupButtonsLayout->addSpacing(10);
147   GroupButtonsLayout->addStretch();
148   GroupButtonsLayout->addWidget(buttonCancel);
149   GroupButtonsLayout->addWidget(buttonHelp);
150
151   /***************************************************************/
152   GroupArguments = new QGroupBox(tr("EXTRUSION_1D"), this);
153   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
154   GroupArgumentsLayout->setSpacing(SPACING);
155   GroupArgumentsLayout->setMargin(MARGIN);
156
157   myIdValidator = new SMESHGUI_IdValidator(this);
158
159   // Controls for elements selection
160   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
161
162   SelectElementsButton = new QPushButton(GroupArguments);
163   SelectElementsButton->setIcon(image2);
164
165   LineEditElements = new QLineEdit(GroupArguments);
166   LineEditElements->setValidator(myIdValidator);
167   myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
168   connect(myFilterBtn,   SIGNAL(clicked()), this, SLOT(setFilters()));
169
170   // Control for the whole mesh selection
171   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
172
173   RadioButton3 = new QRadioButton(GroupArguments);
174   RadioButton3->setText( tr("SMESH_EXTRUSION_TO_DISTANCE") );
175   RadioButton4 = new QRadioButton(GroupArguments);
176   RadioButton4->setText( tr("SMESH_EXTRUSION_ALONG_VECTOR") );
177
178   //Control for the Distance selection
179   TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
180   
181   TextLabelDx = new QLabel(tr("SMESH_X"), GroupArguments);
182   SpinBox_Dx = new SMESHGUI_SpinBox(GroupArguments);
183   
184   TextLabelDy = new QLabel(tr("SMESH_Y"), GroupArguments);
185   SpinBox_Dy = new SMESHGUI_SpinBox(GroupArguments);
186
187   TextLabelDz = new QLabel(tr("SMESH_Z"), GroupArguments);
188   SpinBox_Dz = new SMESHGUI_SpinBox(GroupArguments);
189
190   // Controls for vector selection
191
192   TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupArguments);
193
194   SelectVectorButton = new QPushButton(GroupArguments);
195   SelectVectorButton->setIcon(image2);
196
197   TextLabelVx = new QLabel(tr("SMESH_DX"), GroupArguments);
198   SpinBox_Vx = new SMESHGUI_SpinBox(GroupArguments);
199
200   TextLabelVy = new QLabel(tr("SMESH_DY"), GroupArguments);
201   SpinBox_Vy = new SMESHGUI_SpinBox(GroupArguments);
202
203   TextLabelVz = new QLabel(tr("SMESH_DZ"), GroupArguments);
204   SpinBox_Vz = new SMESHGUI_SpinBox(GroupArguments);
205
206   TextLabelDist = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
207   SpinBox_VDist = new SMESHGUI_SpinBox(GroupArguments);
208
209   // Controls for nb. steps defining
210   TextLabelNbSteps = new QLabel(tr("SMESH_NUMBEROFSTEPS"), GroupArguments);
211   SpinBox_NbSteps = new SalomeApp_IntSpinBox(GroupArguments);
212
213   // CheckBox for groups generation
214   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
215
216   GroupArgumentsLayout->addWidget(TextLabelElements,    0, 0);
217   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
218   GroupArgumentsLayout->addWidget(LineEditElements,     0, 2, 1, 5);
219   GroupArgumentsLayout->addWidget(myFilterBtn,          0, 7);
220   GroupArgumentsLayout->addWidget(CheckBoxMesh,         1, 0, 1, 8);
221   GroupArgumentsLayout->addWidget(RadioButton3,         2, 1, 1, 3);
222   GroupArgumentsLayout->addWidget(RadioButton4,         2, 5, 1, 3);
223   GroupArgumentsLayout->addWidget(TextLabelDistance,    3, 0);
224   GroupArgumentsLayout->addWidget(TextLabelDx,          3, 2);
225   GroupArgumentsLayout->addWidget(SpinBox_Dx,           3, 3);
226   GroupArgumentsLayout->addWidget(TextLabelDy,          3, 4);
227   GroupArgumentsLayout->addWidget(SpinBox_Dy,           3, 5);
228   GroupArgumentsLayout->addWidget(TextLabelDz,          3, 6);
229   GroupArgumentsLayout->addWidget(SpinBox_Dz,           3, 7);
230   GroupArgumentsLayout->addWidget(TextLabelVector,      4, 0);
231   GroupArgumentsLayout->addWidget(SelectVectorButton,   4, 1);
232   GroupArgumentsLayout->addWidget(TextLabelVx,          4, 2);
233   GroupArgumentsLayout->addWidget(SpinBox_Vx,           4, 3);
234   GroupArgumentsLayout->addWidget(TextLabelVy,          4, 4);
235   GroupArgumentsLayout->addWidget(SpinBox_Vy,           4, 5);
236   GroupArgumentsLayout->addWidget(TextLabelVz,          4, 6);
237   GroupArgumentsLayout->addWidget(SpinBox_Vz,           4, 7);
238   GroupArgumentsLayout->addWidget(TextLabelDist,        5, 0);
239   GroupArgumentsLayout->addWidget(SpinBox_VDist,         5, 3);
240   GroupArgumentsLayout->addWidget(TextLabelNbSteps,     6, 0, 1, 3);
241   GroupArgumentsLayout->addWidget(SpinBox_NbSteps,      6, 3);
242   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      7, 0, 1, 8);
243   GroupArgumentsLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 8, 0);
244
245
246   /***************************************************************/
247   SMESHGUI_ExtrusionDlgLayout->addWidget(ConstructorsBox);
248   SMESHGUI_ExtrusionDlgLayout->addWidget(GroupArguments);
249   SMESHGUI_ExtrusionDlgLayout->addWidget(GroupButtons);
250
251   /* Initialisations */
252   SpinBox_Vx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, 3);
253   SpinBox_Vy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, 3);
254   SpinBox_Vz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, 3);
255
256   SpinBox_Dx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
257   SpinBox_Dy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
258   SpinBox_Dz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
259   
260   SpinBox_NbSteps->setRange(1, 999999);
261   SpinBox_VDist->RangeStepAndValidator(0, COORD_MAX, 10.0, 3);
262
263   RadioButton1->setChecked(true);
264   RadioButton3->setChecked(true);
265   MakeGroupsCheck->setChecked(true);
266
267   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
268
269   mySMESHGUI->SetActiveDialogBox(this);
270
271   // Costruction of the logical filter for the elements: mesh/sub-mesh/group
272   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
273   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
274
275   QList<SUIT_SelectionFilter*> aListOfFilters;
276   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
277   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
278
279   myMeshOrSubMeshOrGroupFilter =
280     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
281
282   myHelpFileName = "extrusion_page.html";
283
284   Init();
285
286   /***************************************************************/
287   // signals and slots connections
288   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
289   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
290   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
291   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
292
293   connect(RadioButton3, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
294   connect(RadioButton4, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
295
296   // to update state of the Ok & Apply buttons
297   connect(SpinBox_Vx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
298   connect(SpinBox_Vy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
299   connect(SpinBox_Vz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
300   connect(SpinBox_Dx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
301   connect(SpinBox_Dy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
302   connect(SpinBox_Dz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
303
304   connect(GroupConstructors,    SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
305   connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
306   connect(SelectVectorButton,   SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
307   connect(mySMESHGUI,           SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
308   connect(mySelectionMgr,       SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
309   /* to close dialog if study change */
310   connect(mySMESHGUI,           SIGNAL(SignalCloseAllDialogs()),   this, SLOT(ClickOnCancel()));
311   connect(LineEditElements,     SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
312   connect(CheckBoxMesh,         SIGNAL(toggled(bool)),               SLOT(onSelectMesh(bool)));
313
314   /***************************************************************/
315   
316   ConstructorsClicked(0);
317   ClickOnRadio();
318   SelectionIntoArgument();
319 }
320
321 //=================================================================================
322 // function : ~SMESHGUI_ExtrusionDlg()
323 // purpose  : destructor
324 //=================================================================================
325 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
326 {
327   if ( myFilterDlg != 0 ) {
328     myFilterDlg->setParent( 0 );
329     delete myFilterDlg;
330   }
331 }
332
333 //=================================================================================
334 // function : Init()
335 // purpose  : initialization
336 //=================================================================================
337 void SMESHGUI_ExtrusionDlg::Init (bool ResetControls)
338 {
339   myBusy = false;
340   myIDs.clear();
341
342   LineEditElements->clear();
343   myNbOkElements = 0;
344
345   myActor = 0;
346   myMesh = SMESH::SMESH_Mesh::_nil();
347
348   if (ResetControls) {
349     SpinBox_NbSteps->setValue(1);
350     SpinBox_VDist->setValue(10);
351     SpinBox_Dx->SetValue(0);
352     SpinBox_Dy->SetValue(0);
353     SpinBox_Dz->SetValue(0);
354     SpinBox_Vx->SetValue(0);
355     SpinBox_Vy->SetValue(0);
356     SpinBox_Vz->SetValue(0);
357
358     CheckBoxMesh->setChecked(false);
359     onSelectMesh(false);
360   }
361
362   CheckIsEnable();
363 }
364
365 //=================================================================================
366 // function : CheckIsEnable()
367 // purpose  : Check whether the Ok and Apply buttons should be enabled or not
368 //=================================================================================
369 void SMESHGUI_ExtrusionDlg::CheckIsEnable()
370 {
371   double aX, aY, aZ, aModule;
372   if ( RadioButton3->isChecked() ) {
373     aX = SpinBox_Dx->GetValue();
374     aY = SpinBox_Dy->GetValue();
375     aZ = SpinBox_Dz->GetValue();
376     aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
377   } else   if ( RadioButton4->isChecked() ) {
378     aX = SpinBox_Vx->GetValue();
379     aY = SpinBox_Vy->GetValue();
380     aZ = SpinBox_Vz->GetValue();
381     aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
382   }
383   
384   bool anIsEnable = myNbOkElements > 0 && aModule > 1.0E-38;
385
386   buttonOk->setEnabled(anIsEnable);
387   buttonApply->setEnabled(anIsEnable);
388 }
389
390 //=================================================================================
391 // function : ConstructorsClicked()
392 // purpose  : Radio button management
393 //=================================================================================
394 void SMESHGUI_ExtrusionDlg::ConstructorsClicked (int constructorId)
395 {
396   disconnect(mySelectionMgr, 0, this, 0);
397
398   switch (constructorId) {
399   case 0:
400     {
401       GroupArguments->setTitle(tr("EXTRUSION_1D"));
402       if (!CheckBoxMesh->isChecked())
403         {
404           LineEditElements->clear();
405           myIDs.clear();
406           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
407             aViewWindow->SetSelectionMode(EdgeSelection);
408         }
409       break;
410     }
411   case 1:
412     {
413       GroupArguments->setTitle(tr("EXTRUSION_2D"));
414       if (!CheckBoxMesh->isChecked())
415         {
416           LineEditElements->clear();
417           myIDs.clear();
418           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
419             aViewWindow->SetSelectionMode(FaceSelection);
420         }
421       break;
422     }
423   }
424
425   myEditCurrentArgument = (QWidget*)LineEditElements;
426   LineEditElements->setFocus();
427
428   if (CheckBoxMesh->isChecked())
429     onSelectMesh(true);
430
431   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
432 }
433
434 //=================================================================================
435 // function : ConstructorsClicked()
436 // purpose  : Radio button management
437 //=================================================================================
438 void SMESHGUI_ExtrusionDlg::ClickOnRadio()
439 {
440   if ( RadioButton3->isChecked() ) {
441     TextLabelDistance->show();
442     TextLabelDx->show();
443     SpinBox_Dx->show();
444     TextLabelDy->show();
445     SpinBox_Dy->show();
446     TextLabelDz->show();
447     SpinBox_Dz->show();
448
449     TextLabelVector->hide();
450     TextLabelVx->hide();
451     SpinBox_Vx->hide();
452     TextLabelVy->hide();
453     SpinBox_Vy->hide();
454     TextLabelVz->hide();
455     SpinBox_Vz->hide();
456     TextLabelDist->hide();
457     SpinBox_VDist->hide();
458     SelectVectorButton->hide();
459   } else if ( RadioButton4->isChecked() ) {
460     TextLabelDistance->hide();
461     TextLabelDx->hide();
462     SpinBox_Dx->hide();
463     TextLabelDy->hide();
464     SpinBox_Dy->hide();
465     TextLabelDz->hide();
466     SpinBox_Dz->hide();
467
468     TextLabelVector->show();
469     TextLabelVx->show();
470     SpinBox_Vx->show();
471     TextLabelVy->show();
472     SpinBox_Vy->show();
473     TextLabelVz->show();
474     SpinBox_Vz->show();
475     TextLabelDist->show();
476     SpinBox_VDist->show();
477     SelectVectorButton->show();
478   }
479   // AdjustSize
480   qApp->processEvents();
481   updateGeometry();
482   resize( minimumSizeHint() );
483 }
484
485 //=================================================================================
486 // function : ClickOnApply()
487 // purpose  : Called when user presses <Apply> button
488 //=================================================================================
489 bool SMESHGUI_ExtrusionDlg::ClickOnApply()
490 {
491   if (mySMESHGUI->isActiveStudyLocked())
492     return false;
493
494   if (!isValid())
495     return false;
496
497   if (myNbOkElements) {
498
499     SMESH::DirStruct aVector;
500     QStringList aParameters;
501
502     if ( RadioButton3->isChecked() ) {
503       aVector.PS.x = SpinBox_Dx->GetValue();
504       aVector.PS.y = SpinBox_Dy->GetValue();
505       aVector.PS.z = SpinBox_Dz->GetValue();
506
507       aParameters << SpinBox_Dx->text();
508       aParameters << SpinBox_Dy->text();
509       aParameters << SpinBox_Dz->text();
510     } else if ( RadioButton4->isChecked() ) {
511       gp_XYZ aNormale(SpinBox_Vx->GetValue(),
512                       SpinBox_Vy->GetValue(),
513                       SpinBox_Vz->GetValue());
514     
515      
516       aNormale /= aNormale.Modulus();
517       long aVDist = (long)SpinBox_VDist->value();
518
519       aVector.PS.x = aNormale.X()*aVDist;
520       aVector.PS.y = aNormale.Y()*aVDist;
521       aVector.PS.z = aNormale.Z()*aVDist;
522
523       aParameters << SpinBox_Vx->text();
524       aParameters << SpinBox_Vy->text();
525       aParameters << SpinBox_Vz->text();
526       aParameters << SpinBox_VDist->text();
527     }
528
529     long aNbSteps = (long)SpinBox_NbSteps->value();
530
531     aParameters << SpinBox_NbSteps->text();
532
533     try {
534       SUIT_OverrideCursor aWaitCursor;
535       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
536
537       if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) {
538         if( CheckBoxMesh->isChecked() ) {
539           if( GetConstructorId() == 0 )
540             SMESH::ListOfGroups_var groups = 
541               aMeshEditor->ExtrusionSweepObject1DMakeGroups(mySelectedObject, aVector, aNbSteps);
542           else
543             SMESH::ListOfGroups_var groups = 
544               aMeshEditor->ExtrusionSweepObject2DMakeGroups(mySelectedObject, aVector, aNbSteps);
545         }
546         else
547           SMESH::ListOfGroups_var groups = 
548             aMeshEditor->ExtrusionSweepMakeGroups(myElementsId.inout(), aVector, aNbSteps);
549       }
550       else {
551         if( CheckBoxMesh->isChecked() ) {
552           if( GetConstructorId() == 0 )
553             aMeshEditor->ExtrusionSweepObject1D(mySelectedObject, aVector, aNbSteps);
554           else
555             aMeshEditor->ExtrusionSweepObject2D(mySelectedObject, aVector, aNbSteps);
556         }
557         else
558           aMeshEditor->ExtrusionSweep(myElementsId.inout(), aVector, aNbSteps);
559       }
560
561       myMesh->SetParameters( SMESHGUI::JoinObjectParameters(aParameters) );
562
563     } catch (...) {
564     }
565
566     SMESH::Update(myIO, SMESH::eDisplay);
567     if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
568       mySMESHGUI->updateObjBrowser(true); // new groups may appear
569     Init(false);
570     ConstructorsClicked(GetConstructorId());
571     mySelectionMgr->clearSelected();
572     mySelectedObject = SMESH::SMESH_IDSource::_nil();
573     SelectionIntoArgument();
574   }
575   return true;
576 }
577
578 //=================================================================================
579 // function : ClickOnOk()
580 // purpose  : Called when user presses <OK> button
581 //=================================================================================
582 void SMESHGUI_ExtrusionDlg::ClickOnOk()
583 {
584   if (ClickOnApply())
585     ClickOnCancel();
586 }
587
588 //=================================================================================
589 // function : ClickOnCancel()
590 // purpose  : Called when dialog box is closed
591 //=================================================================================
592 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
593 {
594   disconnect(mySelectionMgr, 0, this, 0);
595   mySelectionMgr->clearFilters();
596   //mySelectionMgr->clearSelected();
597   if (SMESH::GetCurrentVtkView()) {
598     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
599     SMESH::SetPointRepresentation(false);
600     SMESH::SetPickable();
601   }
602   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
603     aViewWindow->SetSelectionMode(ActorSelection);
604   mySMESHGUI->ResetState();
605   reject();
606 }
607
608 //=================================================================================
609 // function : ClickOnHelp()
610 // purpose  :
611 //=================================================================================
612 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
613 {
614   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
615   if (app) 
616     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
617   else {
618     QString platform;
619 #ifdef WIN32
620     platform = "winapplication";
621 #else
622     platform = "application";
623 #endif
624     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
625                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
626                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
627                                                                  platform)).
628                              arg(myHelpFileName));
629   }
630 }
631
632 //=================================================================================
633 // function : onTextChange()
634 // purpose  :
635 //=================================================================================
636 void SMESHGUI_ExtrusionDlg::onTextChange (const QString& theNewText)
637 {
638   QLineEdit* send = (QLineEdit*)sender();
639
640   // return if busy
641   if (myBusy) return;
642
643   // set busy flag
644   myBusy = true;
645
646   if (send == LineEditElements)
647     myNbOkElements = 0;
648
649   // hilight entered elements/nodes
650
651   if (!myIO.IsNull()) {
652     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
653
654     if (send == LineEditElements)
655     {
656       SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
657       SMESH::ElementType SMESHType = GetConstructorId() ? SMESH::FACE : SMESH::EDGE;
658       SMDSAbs_ElementType SMDSType = GetConstructorId() ? SMDSAbs_Face: SMDSAbs_Edge;
659
660       myElementsId = new SMESH::long_array;
661       myElementsId->length( aListId.count() );
662       TColStd_MapOfInteger newIndices;
663       for (int i = 0; i < aListId.count(); i++) {
664         int id = aListId[ i ].toInt();
665         bool validId = false;
666         if ( id > 0 ) {
667           if ( aMesh ) {
668             const SMDS_MeshElement * e = aMesh->FindElement( id );
669             validId = ( e && e->GetType() == SMDSType );
670           } else {
671             validId = ( myMesh->GetElementType( id, true ) == SMESHType );
672           }
673         }
674         if ( validId && newIndices.Add( id ))
675           myElementsId[ newIndices.Extent()-1 ] = id;
676       }
677       myElementsId->length( myNbOkElements = newIndices.Extent() );
678       mySelector->AddOrRemoveIndex(myIO, newIndices, false);
679       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
680         aViewWindow->highlight( myIO, true, true );
681     }
682   }
683
684   CheckIsEnable();
685
686   myBusy = false;
687 }
688
689 //=================================================================================
690 // function : SelectionIntoArgument()
691 // purpose  : Called when selection as changed or other case
692 //=================================================================================
693 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
694 {
695   if (myBusy) return;
696
697   // return if dialog box is inactive
698   if (!GroupButtons->isEnabled())
699     return;
700
701   // clear
702   if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
703     myActor = 0;
704     Handle(SALOME_InteractiveObject) resIO = myIO;
705     myIO.Nullify();
706   }
707
708   QString aString = "";
709   // set busy flag
710   if(myEditCurrentArgument == (QWidget*)LineEditElements) {
711     myBusy = true;
712     LineEditElements->setText(aString);
713     myNbOkElements = 0;
714     myBusy = false;
715   }
716   // get selected mesh
717   SALOME_ListIO aList;
718   mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
719   int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
720   if (nbSel != 1)
721     return;
722
723   Handle(SALOME_InteractiveObject) IO = aList.First();
724
725   if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
726     myMesh = SMESH::GetMeshByIO(IO);
727     if (myMesh->_is_nil())
728       return;
729     myIO = IO;
730     myActor = SMESH::FindActorByObject(myMesh);
731   }
732
733   if (myEditCurrentArgument == (QWidget*)LineEditElements) {    
734     int aNbElements = 0;
735
736     // MakeGroups is available if there are groups
737     if ( myMesh->NbGroups() == 0 ) {
738       MakeGroupsCheck->setChecked(false);
739       MakeGroupsCheck->setEnabled(false);
740     } else {
741       MakeGroupsCheck->setEnabled(true);
742     }
743
744     if (CheckBoxMesh->isChecked()) {
745       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
746
747       if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
748         mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
749       else
750         return;
751     } else {
752       // get indices of selcted elements
753       TColStd_IndexedMapOfInteger aMapIndex;
754       mySelector->GetIndex(IO,aMapIndex);
755       aNbElements = aMapIndex.Extent();
756
757       if (aNbElements < 1)
758         return;
759
760       myElementsId = new SMESH::long_array;
761       myElementsId->length( aNbElements );
762       aString = "";
763       for ( int i = 0; i < aNbElements; ++i )
764         aString += QString(" %1").arg( myElementsId[ i ] = aMapIndex( i+1 ) );
765     }
766
767     myNbOkElements = true;
768
769     myBusy = true;
770     ((QLineEdit*)myEditCurrentArgument)->setText(aString);
771     myBusy = false;
772   }
773   else if(myEditCurrentArgument == (QWidget*)SpinBox_Vx){
774     TColStd_IndexedMapOfInteger aMapIndex;
775     mySelector->GetIndex(IO,aMapIndex);
776     int aNbElements = aMapIndex.Extent();
777     SMESH::SMESH_Mesh_var aMesh_var = SMESH::GetMeshByIO(IO);
778     SMESH_Actor* anActor = SMESH::FindActorByObject(aMesh_var);
779     SMDS_Mesh* aMesh =  anActor ? anActor->GetObject()->GetMesh() : 0;
780
781     if(aNbElements != 1 || !aMesh)
782       return;
783     
784     const SMDS_MeshFace* face = dynamic_cast<const SMDS_MeshFace*>(aMesh->FindElement(aMapIndex(aNbElements)));
785
786     if (!face)
787       return;
788
789     gp_XYZ aNormale = SMESH::getNormale(face);
790     SpinBox_Vx->SetValue(aNormale.X());
791     SpinBox_Vy->SetValue(aNormale.Y());
792     SpinBox_Vz->SetValue(aNormale.Z());
793     
794   }
795   
796   // OK
797   CheckIsEnable();
798 }
799
800 //=================================================================================
801 // function : SetEditCurrentArgument()
802 // purpose  :
803 //=================================================================================
804 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
805 {
806   QPushButton* send = (QPushButton*)sender();
807
808   disconnect(mySelectionMgr, 0, this, 0);
809   mySelectionMgr->clearSelected();
810   mySelectionMgr->clearFilters();
811
812   if (send == SelectElementsButton) {
813     myEditCurrentArgument = (QWidget*)LineEditElements;
814     if (CheckBoxMesh->isChecked()) {
815       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
816         aViewWindow->SetSelectionMode(ActorSelection);
817       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
818     } else {
819       int aConstructorId = GetConstructorId();
820       if (aConstructorId == 0)
821         {
822           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
823             aViewWindow->SetSelectionMode(EdgeSelection);
824         }
825       else if (aConstructorId == 1)
826         {
827           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
828             aViewWindow->SetSelectionMode(FaceSelection);
829         }
830     }
831   }
832   else if (send == SelectVectorButton){
833     myEditCurrentArgument = (QWidget*)SpinBox_Vx;
834     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
835       aViewWindow->SetSelectionMode(FaceSelection);
836   }
837   
838   myEditCurrentArgument->setFocus();
839   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
840   SelectionIntoArgument();
841 }
842
843 //=================================================================================
844 // function : DeactivateActiveDialog()
845 // purpose  : Deactivates this dialog
846 //=================================================================================
847 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
848 {
849   if (ConstructorsBox->isEnabled()) {
850     ConstructorsBox->setEnabled(false);
851     GroupArguments->setEnabled(false);
852     GroupButtons->setEnabled(false);
853     mySMESHGUI->ResetState();
854     mySMESHGUI->SetActiveDialogBox(0);
855   }
856 }
857
858 //=================================================================================
859 // function : ActivateThisDialog()
860 // purpose  : Activates this dialog
861 //=================================================================================
862 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
863 {
864   // Emit a signal to deactivate the active dialog
865   mySMESHGUI->EmitSignalDeactivateDialog();
866   ConstructorsBox->setEnabled(true);
867   GroupArguments->setEnabled(true);
868   GroupButtons->setEnabled(true);
869
870   mySMESHGUI->SetActiveDialogBox(this);
871
872   ConstructorsClicked(GetConstructorId());
873   SelectionIntoArgument();
874 }
875
876 //=================================================================================
877 // function : enterEvent()
878 // purpose  : Mouse enter event
879 //=================================================================================
880 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
881 {
882   if (!ConstructorsBox->isEnabled())
883     ActivateThisDialog();
884 }
885
886 //=================================================================================
887 // function : onSelectMesh()
888 // purpose  :
889 //=================================================================================
890 void SMESHGUI_ExtrusionDlg::onSelectMesh (bool toSelectMesh)
891 {
892   if (toSelectMesh) {
893     myIDs = LineEditElements->text();
894     TextLabelElements->setText(tr("SMESH_NAME"));
895   }
896   else
897     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
898
899   myFilterBtn->setEnabled(!toSelectMesh);
900
901   if (myEditCurrentArgument != LineEditElements) {
902     LineEditElements->clear();
903     return;
904   }
905
906   mySelectionMgr->clearFilters();
907
908   if (toSelectMesh) {
909     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
910       aViewWindow->SetSelectionMode(ActorSelection);
911     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
912     LineEditElements->setReadOnly(true);
913     LineEditElements->setValidator(0);
914   } else {
915     int aConstructorId = GetConstructorId();
916     if (aConstructorId == 0)
917       {
918         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
919           aViewWindow->SetSelectionMode(EdgeSelection);
920       }
921     else if (aConstructorId == 1)
922       {
923         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
924           aViewWindow->SetSelectionMode(FaceSelection);
925       }
926
927     LineEditElements->setReadOnly(false);
928     LineEditElements->setValidator(myIdValidator);
929     onTextChange(LineEditElements->text());
930   }
931
932   SelectionIntoArgument();
933
934   if (!toSelectMesh)
935     LineEditElements->setText( myIDs );
936 }
937
938 //=================================================================================
939 // function : GetConstructorId()
940 // purpose  :
941 //=================================================================================
942 int SMESHGUI_ExtrusionDlg::GetConstructorId()
943 {
944   return GroupConstructors->checkedId();
945 }
946
947 //=================================================================================
948 // function : keyPressEvent()
949 // purpose  :
950 //=================================================================================
951 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
952 {
953   QDialog::keyPressEvent( e );
954   if ( e->isAccepted() )
955     return;
956
957   if ( e->key() == Qt::Key_F1 ) {
958     e->accept();
959     ClickOnHelp();
960   }
961 }
962
963 //=================================================================================
964 // function : setFilters()
965 // purpose  : SLOT. Called when "Filter" button pressed.
966 //=================================================================================
967 void SMESHGUI_ExtrusionDlg::setFilters()
968 {
969   if(myMesh->_is_nil()) {
970     SUIT_MessageBox::critical(this,
971                               tr("SMESH_ERROR"),
972                               tr("NO_MESH_SELECTED"));
973    return;
974   }
975   if ( !myFilterDlg )
976   {
977     QList<int> types;  
978     types.append( SMESH::EDGE );
979     types.append( SMESH::FACE );
980     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
981   }
982   myFilterDlg->Init( GetConstructorId() ? SMESH::FACE : SMESH::EDGE );
983
984   myFilterDlg->SetSelection();
985   myFilterDlg->SetMesh( myMesh );
986   myFilterDlg->SetSourceWg( LineEditElements );
987
988   myFilterDlg->show();
989 }
990
991 //=================================================================================
992 // function : isValid
993 // purpose  :
994 //=================================================================================
995 bool SMESHGUI_ExtrusionDlg::isValid()
996 {
997   QString msg;
998   bool ok = true;
999   if ( RadioButton3->isChecked() ) {
1000     ok = SpinBox_Dx->isValid( msg, true ) && ok;
1001     ok = SpinBox_Dy->isValid( msg, true ) && ok;
1002     ok = SpinBox_Dz->isValid( msg, true ) && ok;
1003   } else if ( RadioButton4->isChecked() ) {
1004     ok = SpinBox_Vx->isValid( msg, true ) && ok;
1005     ok = SpinBox_Vy->isValid( msg, true ) && ok;
1006     ok = SpinBox_Vz->isValid( msg, true ) && ok;
1007     ok = SpinBox_VDist->isValid( msg, true ) && ok;
1008   }
1009   ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
1010
1011   if( !ok ) {
1012     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1013     if ( !msg.isEmpty() )
1014       str += "\n" + msg;
1015     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1016     return false;
1017   }
1018   return true;
1019 }