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