Salome HOME
Merge from BR_phase16 branch (09/12/09)
[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( aParameters.join(":").toLatin1().constData() );
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   reject();
595 }
596
597 //=================================================================================
598 // function : ClickOnHelp()
599 // purpose  :
600 //=================================================================================
601 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
602 {
603   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
604   if (app) 
605     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
606   else {
607     QString platform;
608 #ifdef WIN32
609     platform = "winapplication";
610 #else
611     platform = "application";
612 #endif
613     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
614                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
615                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
616                                                                  platform)).
617                              arg(myHelpFileName));
618   }
619 }
620
621 //=================================================================================
622 // function : onTextChange()
623 // purpose  :
624 //=================================================================================
625 void SMESHGUI_ExtrusionDlg::onTextChange (const QString& theNewText)
626 {
627   QLineEdit* send = (QLineEdit*)sender();
628
629   // return if busy
630   if (myBusy) return;
631
632   // set busy flag
633   myBusy = true;
634
635   if (send == LineEditElements)
636     myNbOkElements = 0;
637
638   // hilight entered elements/nodes
639
640   if (!myIO.IsNull()) {
641     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
642
643     if (send == LineEditElements)
644     {
645       SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
646       SMESH::ElementType SMESHType = GetConstructorId() ? SMESH::FACE : SMESH::EDGE;
647       SMDSAbs_ElementType SMDSType = GetConstructorId() ? SMDSAbs_Face: SMDSAbs_Edge;
648
649       myElementsId = new SMESH::long_array;
650       myElementsId->length( aListId.count() );
651       TColStd_MapOfInteger newIndices;
652       for (int i = 0; i < aListId.count(); i++) {
653         int id = aListId[ i ].toInt();
654         bool validId = false;
655         if ( id > 0 ) {
656           if ( aMesh ) {
657             const SMDS_MeshElement * e = aMesh->FindElement( id );
658             validId = ( e && e->GetType() == SMDSType );
659           } else {
660             validId = ( myMesh->GetElementType( id, true ) == SMESHType );
661           }
662         }
663         if ( validId && newIndices.Add( id ))
664           myElementsId[ newIndices.Extent()-1 ] = id;
665       }
666       myElementsId->length( myNbOkElements = newIndices.Extent() );
667       mySelector->AddOrRemoveIndex(myIO, newIndices, false);
668       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
669         aViewWindow->highlight( myIO, true, true );
670     }
671   }
672
673   CheckIsEnable();
674
675   myBusy = false;
676 }
677
678 //=================================================================================
679 // function : SelectionIntoArgument()
680 // purpose  : Called when selection as changed or other case
681 //=================================================================================
682 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
683 {
684   if (myBusy) return;
685
686   // return if dialog box is inactive
687   if (!GroupButtons->isEnabled())
688     return;
689
690   // clear
691   if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
692     myActor = 0;
693     Handle(SALOME_InteractiveObject) resIO = myIO;
694     myIO.Nullify();
695   }
696
697   QString aString = "";
698   // set busy flag
699   if(myEditCurrentArgument == (QWidget*)LineEditElements) {
700     myBusy = true;
701     LineEditElements->setText(aString);
702     myNbOkElements = 0;
703     myBusy = false;
704   }
705   // get selected mesh
706   SALOME_ListIO aList;
707   mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
708   int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
709   if (nbSel != 1)
710     return;
711
712   Handle(SALOME_InteractiveObject) IO = aList.First();
713
714   if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
715     myMesh = SMESH::GetMeshByIO(IO);
716     if (myMesh->_is_nil())
717       return;
718     myIO = IO;
719     myActor = SMESH::FindActorByObject(myMesh);
720   }
721
722   if (myEditCurrentArgument == (QWidget*)LineEditElements) {    
723     int aNbElements = 0;
724
725     // MakeGroups is available if there are groups
726     if ( myMesh->NbGroups() == 0 ) {
727       MakeGroupsCheck->setChecked(false);
728       MakeGroupsCheck->setEnabled(false);
729     } else {
730       MakeGroupsCheck->setEnabled(true);
731     }
732
733     if (CheckBoxMesh->isChecked()) {
734       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
735
736       if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
737         mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
738       else
739         return;
740     } else {
741       // get indices of selcted elements
742       TColStd_IndexedMapOfInteger aMapIndex;
743       mySelector->GetIndex(IO,aMapIndex);
744       aNbElements = aMapIndex.Extent();
745
746       if (aNbElements < 1)
747         return;
748
749       myElementsId = new SMESH::long_array;
750       myElementsId->length( aNbElements );
751       aString = "";
752       for ( int i = 0; i < aNbElements; ++i )
753         aString += QString(" %1").arg( myElementsId[ i ] = aMapIndex( i+1 ) );
754     }
755
756     myNbOkElements = true;
757
758     myBusy = true;
759     ((QLineEdit*)myEditCurrentArgument)->setText(aString);
760     myBusy = false;
761   }
762   else if(myEditCurrentArgument == (QWidget*)SpinBox_Vx){
763     TColStd_IndexedMapOfInteger aMapIndex;
764     mySelector->GetIndex(IO,aMapIndex);
765     int aNbElements = aMapIndex.Extent();
766     SMESH::SMESH_Mesh_var aMesh_var = SMESH::GetMeshByIO(IO);
767     SMESH_Actor* anActor = SMESH::FindActorByObject(aMesh_var);
768     SMDS_Mesh* aMesh =  anActor ? anActor->GetObject()->GetMesh() : 0;
769
770     if(aNbElements != 1 || !aMesh)
771       return;
772     
773     const SMDS_MeshFace* face = dynamic_cast<const SMDS_MeshFace*>(aMesh->FindElement(aMapIndex(aNbElements)));
774
775     if (!face)
776       return;
777
778     gp_XYZ aNormale = SMESH::getNormale(face);
779     SpinBox_Vx->SetValue(aNormale.X());
780     SpinBox_Vy->SetValue(aNormale.Y());
781     SpinBox_Vz->SetValue(aNormale.Z());
782     
783   }
784   
785   // OK
786   CheckIsEnable();
787 }
788
789 //=================================================================================
790 // function : SetEditCurrentArgument()
791 // purpose  :
792 //=================================================================================
793 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
794 {
795   QPushButton* send = (QPushButton*)sender();
796
797   disconnect(mySelectionMgr, 0, this, 0);
798   mySelectionMgr->clearSelected();
799   mySelectionMgr->clearFilters();
800
801   if (send == SelectElementsButton) {
802     myEditCurrentArgument = (QWidget*)LineEditElements;
803     if (CheckBoxMesh->isChecked()) {
804       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
805         aViewWindow->SetSelectionMode(ActorSelection);
806       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
807     } else {
808       int aConstructorId = GetConstructorId();
809       if (aConstructorId == 0)
810         {
811           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
812             aViewWindow->SetSelectionMode(EdgeSelection);
813         }
814       else if (aConstructorId == 1)
815         {
816           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
817             aViewWindow->SetSelectionMode(FaceSelection);
818         }
819     }
820   }
821   else if (send == SelectVectorButton){
822     myEditCurrentArgument = (QWidget*)SpinBox_Vx;
823     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
824       aViewWindow->SetSelectionMode(FaceSelection);
825   }
826   
827   myEditCurrentArgument->setFocus();
828   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
829   SelectionIntoArgument();
830 }
831
832 //=================================================================================
833 // function : DeactivateActiveDialog()
834 // purpose  : Deactivates this dialog
835 //=================================================================================
836 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
837 {
838   if (ConstructorsBox->isEnabled()) {
839     ConstructorsBox->setEnabled(false);
840     GroupArguments->setEnabled(false);
841     GroupButtons->setEnabled(false);
842     mySMESHGUI->ResetState();
843     mySMESHGUI->SetActiveDialogBox(0);
844   }
845 }
846
847 //=================================================================================
848 // function : ActivateThisDialog()
849 // purpose  : Activates this dialog
850 //=================================================================================
851 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
852 {
853   // Emit a signal to deactivate the active dialog
854   mySMESHGUI->EmitSignalDeactivateDialog();
855   ConstructorsBox->setEnabled(true);
856   GroupArguments->setEnabled(true);
857   GroupButtons->setEnabled(true);
858
859   mySMESHGUI->SetActiveDialogBox(this);
860
861   ConstructorsClicked(GetConstructorId());
862   SelectionIntoArgument();
863 }
864
865 //=================================================================================
866 // function : enterEvent()
867 // purpose  : Mouse enter event
868 //=================================================================================
869 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
870 {
871   if (!ConstructorsBox->isEnabled())
872     ActivateThisDialog();
873 }
874
875 //=================================================================================
876 // function : closeEvent()
877 // purpose  :
878 //=================================================================================
879 void SMESHGUI_ExtrusionDlg::closeEvent( QCloseEvent* )
880 {
881   /* same than click on cancel button */
882   disconnect(mySelectionMgr, 0, this, 0);
883   mySelectionMgr->clearFilters();
884   //mySelectionMgr->clearSelected();
885   if (SMESH::GetCurrentVtkView()) {
886     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
887     SMESH::SetPointRepresentation(false);
888     SMESH::SetPickable();
889   }
890   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
891     aViewWindow->SetSelectionMode(ActorSelection);
892   mySMESHGUI->ResetState();
893 }
894
895 void SMESHGUI_ExtrusionDlg::reject()
896 {
897   QDialog::reject();
898   close();
899 }
900
901 //=================================================================================
902 // function : onSelectMesh()
903 // purpose  :
904 //=================================================================================
905 void SMESHGUI_ExtrusionDlg::onSelectMesh (bool toSelectMesh)
906 {
907   if (toSelectMesh) {
908     myIDs = LineEditElements->text();
909     TextLabelElements->setText(tr("SMESH_NAME"));
910   }
911   else
912     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
913
914   myFilterBtn->setEnabled(!toSelectMesh);
915
916   if (myEditCurrentArgument != LineEditElements) {
917     LineEditElements->clear();
918     return;
919   }
920
921   mySelectionMgr->clearFilters();
922
923   if (toSelectMesh) {
924     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
925       aViewWindow->SetSelectionMode(ActorSelection);
926     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
927     LineEditElements->setReadOnly(true);
928     LineEditElements->setValidator(0);
929   } else {
930     int aConstructorId = GetConstructorId();
931     if (aConstructorId == 0)
932       {
933         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
934           aViewWindow->SetSelectionMode(EdgeSelection);
935       }
936     else if (aConstructorId == 1)
937       {
938         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
939           aViewWindow->SetSelectionMode(FaceSelection);
940       }
941
942     LineEditElements->setReadOnly(false);
943     LineEditElements->setValidator(myIdValidator);
944     onTextChange(LineEditElements->text());
945   }
946
947   SelectionIntoArgument();
948
949   if (!toSelectMesh)
950     LineEditElements->setText( myIDs );
951 }
952
953 //=================================================================================
954 // function : GetConstructorId()
955 // purpose  :
956 //=================================================================================
957 int SMESHGUI_ExtrusionDlg::GetConstructorId()
958 {
959   return GroupConstructors->checkedId();
960 }
961
962 //=================================================================================
963 // function : keyPressEvent()
964 // purpose  :
965 //=================================================================================
966 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
967 {
968   QDialog::keyPressEvent( e );
969   if ( e->isAccepted() )
970     return;
971
972   if ( e->key() == Qt::Key_F1 ) {
973     e->accept();
974     ClickOnHelp();
975   }
976 }
977
978 //=================================================================================
979 // function : setFilters()
980 // purpose  : SLOT. Called when "Filter" button pressed.
981 //=================================================================================
982 void SMESHGUI_ExtrusionDlg::setFilters()
983 {
984   if(myMesh->_is_nil()) {
985     SUIT_MessageBox::critical(this,
986                               tr("SMESH_ERROR"),
987                               tr("NO_MESH_SELECTED"));
988    return;
989   }
990   if ( !myFilterDlg )
991   {
992     QList<int> types;  
993     types.append( SMESH::EDGE );
994     types.append( SMESH::FACE );
995     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
996   }
997   myFilterDlg->Init( GetConstructorId() ? SMESH::FACE : SMESH::EDGE );
998
999   myFilterDlg->SetSelection();
1000   myFilterDlg->SetMesh( myMesh );
1001   myFilterDlg->SetSourceWg( LineEditElements );
1002
1003   myFilterDlg->show();
1004 }
1005
1006 //=================================================================================
1007 // function : isValid
1008 // purpose  :
1009 //=================================================================================
1010 bool SMESHGUI_ExtrusionDlg::isValid()
1011 {
1012   QString msg;
1013   bool ok = true;
1014   if ( RadioButton3->isChecked() ) {
1015     ok = SpinBox_Dx->isValid( msg, true ) && ok;
1016     ok = SpinBox_Dy->isValid( msg, true ) && ok;
1017     ok = SpinBox_Dz->isValid( msg, true ) && ok;
1018   } else if ( RadioButton4->isChecked() ) {
1019     ok = SpinBox_Vx->isValid( msg, true ) && ok;
1020     ok = SpinBox_Vy->isValid( msg, true ) && ok;
1021     ok = SpinBox_Vz->isValid( msg, true ) && ok;
1022     ok = SpinBox_VDist->isValid( msg, true ) && ok;
1023   }
1024   ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
1025
1026   if( !ok ) {
1027     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1028     if ( !msg.isEmpty() )
1029       str += "\n" + msg;
1030     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1031     return false;
1032   }
1033   return true;
1034 }