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