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