Salome HOME
Debug
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ExtrusionDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File   : SMESHGUI_ExtrusionDlg.cxx
24 // Author : Michael ZORIN, Open CASCADE S.A.S.
25 // SMESH includes
26 //
27 #include "SMESHGUI_ExtrusionDlg.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_SpinBox.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESHGUI_FilterDlg.h"
36
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_LogicalFilter.hxx>
40
41 #include <SMDS_Mesh.hxx>
42
43 // SALOME GUI includes
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Desktop.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_Session.h>
48 #include <SUIT_OverrideCursor.h>
49
50 #include <LightApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
52
53 #include <SVTK_ViewModel.h>
54 #include <SVTK_ViewWindow.h>
55
56 #include <SalomeApp_Notebook.h>
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     SMESHGUI_Helper( theModule ),
93     mySMESHGUI( theModule ),
94     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
95     myFilterDlg( 0 ),
96     mySelectedObject(SMESH::SMESH_IDSource::_nil())
97 {
98   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_EDGE")));
99   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_TRIANGLE")));
100   QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
101
102   setModal( false );
103   setAttribute( Qt::WA_DeleteOnClose, true );
104   setWindowTitle(tr("EXTRUSION_ALONG_LINE"));
105   setSizeGripEnabled(true);
106
107   QVBoxLayout* SMESHGUI_ExtrusionDlgLayout = new QVBoxLayout(this);
108   SMESHGUI_ExtrusionDlgLayout->setSpacing(SPACING);
109   SMESHGUI_ExtrusionDlgLayout->setMargin(MARGIN);
110
111   /***************************************************************/
112   ConstructorsBox = new QGroupBox(tr("SMESH_EXTRUSION"), this);
113   GroupConstructors = new QButtonGroup(this);
114   QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
115   ConstructorsBoxLayout->setSpacing(SPACING);
116   ConstructorsBoxLayout->setMargin(MARGIN);
117
118   RadioButton1= new QRadioButton(ConstructorsBox);
119   RadioButton1->setIcon(image0);
120   RadioButton2= new QRadioButton(ConstructorsBox);
121   RadioButton2->setIcon(image1);
122
123   ConstructorsBoxLayout->addWidget(RadioButton1);
124   ConstructorsBoxLayout->addWidget(RadioButton2);
125
126   GroupConstructors->addButton(RadioButton1, 0);
127   GroupConstructors->addButton(RadioButton2, 1);
128
129   /***************************************************************/
130   GroupButtons = new QGroupBox(this);
131   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
132   GroupButtonsLayout->setSpacing(SPACING);
133   GroupButtonsLayout->setMargin(MARGIN);
134
135   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
136   buttonOk->setAutoDefault(true);
137   buttonOk->setDefault(true);
138   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
139   buttonApply->setAutoDefault(true);
140   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
141   buttonCancel->setAutoDefault(true);
142   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
143   buttonHelp->setAutoDefault(true);
144
145   GroupButtonsLayout->addWidget(buttonOk);
146   GroupButtonsLayout->addSpacing(10);
147   GroupButtonsLayout->addWidget(buttonApply);
148   GroupButtonsLayout->addSpacing(10);
149   GroupButtonsLayout->addStretch();
150   GroupButtonsLayout->addWidget(buttonCancel);
151   GroupButtonsLayout->addWidget(buttonHelp);
152
153   /***************************************************************/
154   GroupArguments = new QGroupBox(tr("EXTRUSION_1D"), this);
155   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
156   GroupArgumentsLayout->setSpacing(SPACING);
157   GroupArgumentsLayout->setMargin(MARGIN);
158
159   myIdValidator = new SMESHGUI_IdValidator(this);
160
161   // Controls for elements selection
162   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
163
164   SelectElementsButton = new QPushButton(GroupArguments);
165   SelectElementsButton->setIcon(image2);
166
167   LineEditElements = new QLineEdit(GroupArguments);
168   LineEditElements->setValidator(myIdValidator);
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, 3);
255   SpinBox_Vy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, 3);
256   SpinBox_Vz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.01, 3);
257
258   SpinBox_Dx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
259   SpinBox_Dy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
260   SpinBox_Dz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
261   
262   SpinBox_NbSteps->setRange(1, 999999);
263   SpinBox_VDist->RangeStepAndValidator(0, COORD_MAX, 10.0, 3);
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       getNotebook()->setParameters( myMesh, aParameters );
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   return true;
578 }
579
580 //=================================================================================
581 // function : ClickOnOk()
582 // purpose  : Called when user presses <OK> button
583 //=================================================================================
584 void SMESHGUI_ExtrusionDlg::ClickOnOk()
585 {
586   if (ClickOnApply())
587     ClickOnCancel();
588 }
589
590 //=================================================================================
591 // function : ClickOnCancel()
592 // purpose  : Called when dialog box is closed
593 //=================================================================================
594 void SMESHGUI_ExtrusionDlg::ClickOnCancel()
595 {
596   reject();
597 }
598
599 //=================================================================================
600 // function : ClickOnHelp()
601 // purpose  :
602 //=================================================================================
603 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
604 {
605   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
606   if (app) 
607     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
608   else {
609     QString platform;
610 #ifdef WIN32
611     platform = "winapplication";
612 #else
613     platform = "application";
614 #endif
615     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
616                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
617                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
618                                                                  platform)).
619                              arg(myHelpFileName));
620   }
621 }
622
623 //=================================================================================
624 // function : onTextChange()
625 // purpose  :
626 //=================================================================================
627 void SMESHGUI_ExtrusionDlg::onTextChange (const QString& theNewText)
628 {
629   QLineEdit* send = (QLineEdit*)sender();
630
631   // return if busy
632   if (myBusy) return;
633
634   // set busy flag
635   myBusy = true;
636
637   if (send == LineEditElements)
638     myNbOkElements = 0;
639
640   // hilight entered elements/nodes
641
642   if (!myIO.IsNull()) {
643     QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
644
645     if (send == LineEditElements)
646     {
647       SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
648       SMESH::ElementType SMESHType = GetConstructorId() ? SMESH::FACE : SMESH::EDGE;
649       SMDSAbs_ElementType SMDSType = GetConstructorId() ? SMDSAbs_Face: SMDSAbs_Edge;
650
651       myElementsId = new SMESH::long_array;
652       myElementsId->length( aListId.count() );
653       TColStd_MapOfInteger newIndices;
654       for (int i = 0; i < aListId.count(); i++) {
655         int id = aListId[ i ].toInt();
656         bool validId = false;
657         if ( id > 0 ) {
658           if ( aMesh ) {
659             const SMDS_MeshElement * e = aMesh->FindElement( id );
660             validId = ( e && e->GetType() == SMDSType );
661           } else {
662             validId = ( myMesh->GetElementType( id, true ) == SMESHType );
663           }
664         }
665         if ( validId && newIndices.Add( id ))
666           myElementsId[ newIndices.Extent()-1 ] = id;
667       }
668       myElementsId->length( myNbOkElements = newIndices.Extent() );
669       mySelector->AddOrRemoveIndex(myIO, newIndices, false);
670       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
671         aViewWindow->highlight( myIO, true, true );
672     }
673   }
674
675   CheckIsEnable();
676
677   myBusy = false;
678 }
679
680 //=================================================================================
681 // function : SelectionIntoArgument()
682 // purpose  : Called when selection as changed or other case
683 //=================================================================================
684 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
685 {
686   if (myBusy) return;
687
688   // return if dialog box is inactive
689   if (!GroupButtons->isEnabled())
690     return;
691
692   // clear
693   if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
694     myActor = 0;
695     Handle(SALOME_InteractiveObject) resIO = myIO;
696     myIO.Nullify();
697   }
698
699   QString aString = "";
700   // set busy flag
701   if(myEditCurrentArgument == (QWidget*)LineEditElements) {
702     myBusy = true;
703     LineEditElements->setText(aString);
704     myNbOkElements = 0;
705     myBusy = false;
706   }
707   // get selected mesh
708   SALOME_ListIO aList;
709   mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
710   int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
711   if (nbSel != 1)
712     return;
713
714   Handle(SALOME_InteractiveObject) IO = aList.First();
715
716   if(myEditCurrentArgument != (QWidget*)SpinBox_Vx) {
717     myMesh = SMESH::GetMeshByIO(IO);
718     if (myMesh->_is_nil())
719       return;
720     myIO = IO;
721     myActor = SMESH::FindActorByObject(myMesh);
722   }
723
724   if (myEditCurrentArgument == (QWidget*)LineEditElements) {    
725     int aNbElements = 0;
726
727     // MakeGroups is available if there are groups
728     if ( myMesh->NbGroups() == 0 ) {
729       MakeGroupsCheck->setChecked(false);
730       MakeGroupsCheck->setEnabled(false);
731     } else {
732       MakeGroupsCheck->setEnabled(true);
733     }
734
735     if (CheckBoxMesh->isChecked()) {
736       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
737
738       if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
739         mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
740       else
741         return;
742     } else {
743       // get indices of selcted elements
744       TColStd_IndexedMapOfInteger aMapIndex;
745       mySelector->GetIndex(IO,aMapIndex);
746       aNbElements = aMapIndex.Extent();
747
748       if (aNbElements < 1)
749         return;
750
751       myElementsId = new SMESH::long_array;
752       myElementsId->length( aNbElements );
753       aString = "";
754       for ( int i = 0; i < aNbElements; ++i )
755         aString += QString(" %1").arg( myElementsId[ i ] = aMapIndex( i+1 ) );
756     }
757
758     myNbOkElements = true;
759
760     myBusy = true;
761     ((QLineEdit*)myEditCurrentArgument)->setText(aString);
762     myBusy = false;
763   }
764   else if(myEditCurrentArgument == (QWidget*)SpinBox_Vx){
765     TColStd_IndexedMapOfInteger aMapIndex;
766     mySelector->GetIndex(IO,aMapIndex);
767     int aNbElements = aMapIndex.Extent();
768     SMESH::SMESH_Mesh_var aMesh_var = SMESH::GetMeshByIO(IO);
769     SMESH_Actor* anActor = SMESH::FindActorByObject(aMesh_var);
770     SMDS_Mesh* aMesh =  anActor ? anActor->GetObject()->GetMesh() : 0;
771
772     if(aNbElements != 1 || !aMesh)
773       return;
774     
775     const SMDS_MeshFace* face = dynamic_cast<const SMDS_MeshFace*>(aMesh->FindElement(aMapIndex(aNbElements)));
776
777     if (!face)
778       return;
779
780     gp_XYZ aNormale = SMESH::getNormale(face);
781     SpinBox_Vx->SetValue(aNormale.X());
782     SpinBox_Vy->SetValue(aNormale.Y());
783     SpinBox_Vz->SetValue(aNormale.Z());
784     
785   }
786   
787   // OK
788   CheckIsEnable();
789 }
790
791 //=================================================================================
792 // function : SetEditCurrentArgument()
793 // purpose  :
794 //=================================================================================
795 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
796 {
797   QPushButton* send = (QPushButton*)sender();
798
799   disconnect(mySelectionMgr, 0, this, 0);
800   mySelectionMgr->clearSelected();
801   mySelectionMgr->clearFilters();
802
803   if (send == SelectElementsButton) {
804     myEditCurrentArgument = (QWidget*)LineEditElements;
805     if (CheckBoxMesh->isChecked()) {
806       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
807         aViewWindow->SetSelectionMode(ActorSelection);
808       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
809     } else {
810       int aConstructorId = GetConstructorId();
811       if (aConstructorId == 0)
812         {
813           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
814             aViewWindow->SetSelectionMode(EdgeSelection);
815         }
816       else if (aConstructorId == 1)
817         {
818           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
819             aViewWindow->SetSelectionMode(FaceSelection);
820         }
821     }
822   }
823   else if (send == SelectVectorButton){
824     myEditCurrentArgument = (QWidget*)SpinBox_Vx;
825     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
826       aViewWindow->SetSelectionMode(FaceSelection);
827   }
828   
829   myEditCurrentArgument->setFocus();
830   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
831   SelectionIntoArgument();
832 }
833
834 //=================================================================================
835 // function : DeactivateActiveDialog()
836 // purpose  : Deactivates this dialog
837 //=================================================================================
838 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
839 {
840   if (ConstructorsBox->isEnabled()) {
841     ConstructorsBox->setEnabled(false);
842     GroupArguments->setEnabled(false);
843     GroupButtons->setEnabled(false);
844     mySMESHGUI->ResetState();
845     mySMESHGUI->SetActiveDialogBox(0);
846   }
847 }
848
849 //=================================================================================
850 // function : ActivateThisDialog()
851 // purpose  : Activates this dialog
852 //=================================================================================
853 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
854 {
855   // Emit a signal to deactivate the active dialog
856   mySMESHGUI->EmitSignalDeactivateDialog();
857   ConstructorsBox->setEnabled(true);
858   GroupArguments->setEnabled(true);
859   GroupButtons->setEnabled(true);
860
861   mySMESHGUI->SetActiveDialogBox(this);
862
863   ConstructorsClicked(GetConstructorId());
864   SelectionIntoArgument();
865 }
866
867 //=================================================================================
868 // function : enterEvent()
869 // purpose  : Mouse enter event
870 //=================================================================================
871 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
872 {
873   if (!ConstructorsBox->isEnabled())
874     ActivateThisDialog();
875 }
876
877 //=================================================================================
878 // function : closeEvent()
879 // purpose  :
880 //=================================================================================
881 void SMESHGUI_ExtrusionDlg::closeEvent( QCloseEvent* )
882 {
883   /* same than click on cancel button */
884   disconnect(mySelectionMgr, 0, this, 0);
885   mySelectionMgr->clearFilters();
886   //mySelectionMgr->clearSelected();
887   if (SMESH::GetCurrentVtkView()) {
888     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
889     SMESH::SetPointRepresentation(false);
890     SMESH::SetPickable();
891   }
892   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
893     aViewWindow->SetSelectionMode(ActorSelection);
894   mySMESHGUI->ResetState();
895 }
896
897 void SMESHGUI_ExtrusionDlg::reject()
898 {
899   QDialog::reject();
900   close();
901 }
902
903 //=================================================================================
904 // function : onSelectMesh()
905 // purpose  :
906 //=================================================================================
907 void SMESHGUI_ExtrusionDlg::onSelectMesh (bool toSelectMesh)
908 {
909   if (toSelectMesh) {
910     myIDs = LineEditElements->text();
911     TextLabelElements->setText(tr("SMESH_NAME"));
912   }
913   else
914     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
915
916   myFilterBtn->setEnabled(!toSelectMesh);
917
918   if (myEditCurrentArgument != LineEditElements) {
919     LineEditElements->clear();
920     return;
921   }
922
923   mySelectionMgr->clearFilters();
924
925   if (toSelectMesh) {
926     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
927       aViewWindow->SetSelectionMode(ActorSelection);
928     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
929     LineEditElements->setReadOnly(true);
930     LineEditElements->setValidator(0);
931   } else {
932     int aConstructorId = GetConstructorId();
933     if (aConstructorId == 0)
934       {
935         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
936           aViewWindow->SetSelectionMode(EdgeSelection);
937       }
938     else if (aConstructorId == 1)
939       {
940         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
941           aViewWindow->SetSelectionMode(FaceSelection);
942       }
943
944     LineEditElements->setReadOnly(false);
945     LineEditElements->setValidator(myIdValidator);
946     onTextChange(LineEditElements->text());
947   }
948
949   SelectionIntoArgument();
950
951   if (!toSelectMesh)
952     LineEditElements->setText( myIDs );
953 }
954
955 //=================================================================================
956 // function : GetConstructorId()
957 // purpose  :
958 //=================================================================================
959 int SMESHGUI_ExtrusionDlg::GetConstructorId()
960 {
961   return GroupConstructors->checkedId();
962 }
963
964 //=================================================================================
965 // function : keyPressEvent()
966 // purpose  :
967 //=================================================================================
968 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
969 {
970   QDialog::keyPressEvent( e );
971   if ( e->isAccepted() )
972     return;
973
974   if ( e->key() == Qt::Key_F1 ) {
975     e->accept();
976     ClickOnHelp();
977   }
978 }
979
980 //=================================================================================
981 // function : setFilters()
982 // purpose  : SLOT. Called when "Filter" button pressed.
983 //=================================================================================
984 void SMESHGUI_ExtrusionDlg::setFilters()
985 {
986   if(myMesh->_is_nil()) {
987     SUIT_MessageBox::critical(this,
988                               tr("SMESH_ERROR"),
989                               tr("NO_MESH_SELECTED"));
990    return;
991   }
992   if ( !myFilterDlg )
993   {
994     QList<int> types;  
995     types.append( SMESH::EDGE );
996     types.append( SMESH::FACE );
997     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, types );
998   }
999   myFilterDlg->Init( GetConstructorId() ? SMESH::FACE : SMESH::EDGE );
1000
1001   myFilterDlg->SetSelection();
1002   myFilterDlg->SetMesh( myMesh );
1003   myFilterDlg->SetSourceWg( LineEditElements );
1004
1005   myFilterDlg->show();
1006 }
1007
1008 //=================================================================================
1009 // function : isValid
1010 // purpose  :
1011 //=================================================================================
1012 bool SMESHGUI_ExtrusionDlg::isValid()
1013 {
1014   QList<QAbstractSpinBox*> aSpinBoxList;
1015   if ( RadioButton3->isChecked() )
1016     aSpinBoxList << SpinBox_Dx << SpinBox_Dy << SpinBox_Dz;
1017   else if ( RadioButton4->isChecked() )
1018     aSpinBoxList << SpinBox_Vx << SpinBox_Vy << SpinBox_Vz;
1019   aSpinBoxList << SpinBox_NbSteps;
1020   return checkParameters( true, aSpinBoxList );
1021 }