Salome HOME
Dump Python Extension - Debug
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_RevolutionDlg.cxx
1 // SMESH SMESHGUI : GUI for SMESH component
2 //
3 // Copyright (C) 2003  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 // File   : SMESHGUI_RevolutionDlg.cxx
23 // Author : Michael ZORIN, Open CASCADE S.A.S.
24 //
25
26 // SMESH includes
27 #include "SMESHGUI_RevolutionDlg.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESHGUI_MeshEditPreview.h"
36
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_LogicalFilter.hxx>
40 #include <SMDS_Mesh.hxx>
41
42 // SALOME GUI includes
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_Desktop.h>
47 #include <SUIT_OverrideCursor.h>
48
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
51 #include <SalomeApp_Application.h>
52 #include <SalomeApp_IntSpinBox.h>
53
54 #include <SVTK_ViewWindow.h>
55 #include <SVTK_Selector.h>
56 #include <SALOME_ListIO.hxx>
57 #include <VTKViewer_CellLocationsArray.h>
58
59 // OCCT includes
60 #include <TColStd_MapOfInteger.hxx>
61
62 // Qt includes
63 #include <QApplication>
64 #include <QButtonGroup>
65 #include <QGroupBox>
66 #include <QLabel>
67 #include <QLineEdit>
68 #include <QPushButton>
69 #include <QRadioButton>
70 #include <QCheckBox>
71 #include <QHBoxLayout>
72 #include <QVBoxLayout>
73 #include <QGridLayout>
74 #include <QKeyEvent>
75
76 // IDL includes
77 #include <SALOMEconfig.h>
78 #include CORBA_SERVER_HEADER(SMESH_Group)
79 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
80
81 #define SPACING 6
82 #define MARGIN  11
83
84 //=================================================================================
85 // class    : SMESHGUI_RevolutionDlg()
86 // purpose  :
87 //=================================================================================
88 SMESHGUI_RevolutionDlg::SMESHGUI_RevolutionDlg( SMESHGUI* theModule )
89   : QDialog( SMESH::GetDesktop( theModule ) ),
90     mySMESHGUI( theModule ),
91     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
92     mySelectedObject(SMESH::SMESH_IDSource::_nil())
93 {
94   mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI ));
95
96   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
97   QPixmap image0 ( mgr->loadPixmap("SMESH", tr("ICON_DLG_EDGE")));
98   QPixmap image1 ( mgr->loadPixmap("SMESH", tr("ICON_DLG_TRIANGLE")));
99   QPixmap image2 ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
100
101   setModal(false);
102   setAttribute(Qt::WA_DeleteOnClose, true);
103   setWindowTitle(tr("REVOLUTION_AROUND_AXIS"));
104   setSizeGripEnabled(true);
105   
106   QVBoxLayout* SMESHGUI_RevolutionDlgLayout = new QVBoxLayout(this);
107   SMESHGUI_RevolutionDlgLayout->setSpacing(SPACING);
108   SMESHGUI_RevolutionDlgLayout->setMargin(MARGIN);
109
110   /***************************************************************/
111   ConstructorsBox = new QGroupBox(tr("SMESH_REVOLUTION"), 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   GroupConstructors->addButton(RadioButton1, 0);
125   GroupConstructors->addButton(RadioButton2, 1);
126
127   /***************************************************************/
128   GroupArguments = new QGroupBox(tr("REVOLUTION_1D"), this);
129   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
130   GroupArgumentsLayout->setSpacing(SPACING);
131   GroupArgumentsLayout->setMargin(MARGIN);
132
133   myIdValidator = new SMESHGUI_IdValidator(this);
134
135   // Controls for elements selection
136   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
137
138   SelectElementsButton = new QPushButton(GroupArguments);
139   SelectElementsButton->setIcon(image2);
140
141   LineEditElements  = new QLineEdit(GroupArguments);
142   LineEditElements->setValidator(myIdValidator);
143
144   // Control for the whole mesh selection
145   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
146
147   // Controls for axis defining
148   GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
149   QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
150   GroupAxisLayout->setSpacing(SPACING);
151   GroupAxisLayout->setMargin(MARGIN);
152
153   TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
154   SelectPointButton  = new QPushButton(GroupAxis);
155   SelectPointButton->setIcon(image2);
156
157   TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
158   SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
159
160   TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
161   SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
162
163   TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
164   SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
165
166   TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
167   SelectVectorButton = new QPushButton(GroupAxis);
168   SelectVectorButton->setIcon(image2);
169
170   TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
171   SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
172
173   TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
174   SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
175
176   TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
177   SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
178
179   GroupAxisLayout->addWidget(TextLabelPoint,     0, 0);
180   GroupAxisLayout->addWidget(SelectPointButton,  0, 1);
181   GroupAxisLayout->addWidget(TextLabelX,         0, 2);
182   GroupAxisLayout->addWidget(SpinBox_X,          0, 3);
183   GroupAxisLayout->addWidget(TextLabelY,         0, 4);
184   GroupAxisLayout->addWidget(SpinBox_Y,          0, 5);
185   GroupAxisLayout->addWidget(TextLabelZ,         0, 6);
186   GroupAxisLayout->addWidget(SpinBox_Z,          0, 7);
187   GroupAxisLayout->addWidget(TextLabelVector,    1, 0);
188   GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
189   GroupAxisLayout->addWidget(TextLabelDX,        1, 2);
190   GroupAxisLayout->addWidget(SpinBox_DX,         1, 3);
191   GroupAxisLayout->addWidget(TextLabelDY,        1, 4);
192   GroupAxisLayout->addWidget(SpinBox_DY,         1, 5);
193   GroupAxisLayout->addWidget(TextLabelDZ,        1, 6);
194   GroupAxisLayout->addWidget(SpinBox_DZ,         1, 7);
195
196   // Controls for angle defining & number of steps defining
197   GroupAngleBox = new QGroupBox(tr("SMESH_ANGLE"), GroupArguments);
198   GroupAngle = new QButtonGroup(GroupAngleBox);
199   QGridLayout* GroupAngleLayout = new QGridLayout(GroupAngleBox);
200   GroupAngleLayout->setSpacing(6);
201   GroupAngleLayout->setMargin(11);
202
203   RadioButton3 = new QRadioButton(tr("ANGLE_BY_STEP"), GroupAngleBox);
204   RadioButton4 = new QRadioButton(tr("TOTAL_ANGLE"),   GroupAngleBox);
205   GroupAngle->addButton(RadioButton3, 0);
206   GroupAngle->addButton(RadioButton4, 1);
207
208   TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupAngleBox);
209   SpinBox_Angle = new SMESHGUI_SpinBox(GroupAngleBox);
210
211   TextLabelNbSteps = new QLabel(tr("SMESH_NUMBEROFSTEPS"), GroupAngleBox);
212   SpinBox_NbSteps = new SalomeApp_IntSpinBox(GroupAngleBox);
213
214   GroupAngleLayout->addWidget(RadioButton3,     0, 0);
215   GroupAngleLayout->addWidget(RadioButton4,     0, 1);
216   GroupAngleLayout->addWidget(TextLabelAngle,   1, 0);
217   GroupAngleLayout->addWidget(SpinBox_Angle,    1, 1);
218   GroupAngleLayout->addWidget(TextLabelNbSteps, 2, 0);
219   GroupAngleLayout->addWidget(SpinBox_NbSteps,  2, 1);
220
221   // Controls for tolerance defining
222   TextLabelTolerance = new QLabel(tr("SMESH_TOLERANCE"), GroupArguments);
223   SpinBox_Tolerance = new SMESHGUI_SpinBox(GroupArguments);
224
225   // Control for mesh preview
226   CheckBoxPreview = new QCheckBox(tr("PREVIEW"), GroupArguments);
227
228   // CheckBox for groups generation
229   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
230   MakeGroupsCheck->setChecked(true);
231
232   GroupArgumentsLayout->addWidget(TextLabelElements,    0, 0);
233   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
234   GroupArgumentsLayout->addWidget(LineEditElements,     0, 2);
235   GroupArgumentsLayout->addWidget(CheckBoxMesh,         1, 0, 1, 3);
236   GroupArgumentsLayout->addWidget(GroupAxis,            2, 0, 1, 3);
237   GroupArgumentsLayout->addWidget(GroupAngleBox,        3, 0, 1, 3);
238   GroupArgumentsLayout->addWidget(TextLabelTolerance,   4, 0, 1, 2);
239   GroupArgumentsLayout->addWidget(SpinBox_Tolerance,    4, 2);
240   GroupArgumentsLayout->addWidget(CheckBoxPreview,      5, 0, 1, 3);
241   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      6, 0, 1, 3);
242
243   /***************************************************************/
244   GroupButtons = new QGroupBox(this);
245   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
246   GroupButtonsLayout->setSpacing(SPACING);
247   GroupButtonsLayout->setMargin(MARGIN);
248   
249   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
250   buttonOk->setAutoDefault(true);
251   buttonOk->setDefault(true);
252   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
253   buttonApply->setAutoDefault(true);
254   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
255   buttonCancel->setAutoDefault(true);
256   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
257   buttonHelp->setAutoDefault(true);
258
259   GroupButtonsLayout->addWidget(buttonOk);
260   GroupButtonsLayout->addSpacing(10);
261   GroupButtonsLayout->addWidget(buttonApply);
262   GroupButtonsLayout->addSpacing(10);
263   GroupButtonsLayout->addStretch();
264   GroupButtonsLayout->addWidget(buttonCancel);
265   GroupButtonsLayout->addWidget(buttonHelp);
266
267   /***************************************************************/
268   SMESHGUI_RevolutionDlgLayout->addWidget(ConstructorsBox);
269   SMESHGUI_RevolutionDlgLayout->addWidget(GroupArguments);
270   SMESHGUI_RevolutionDlgLayout->addWidget(GroupButtons);
271
272   /* Initialisations */
273   SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
274   SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
275   SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
276   SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
277   SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
278   SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
279
280   RadioButton3->setChecked(true);
281
282   SpinBox_Angle->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5.0, 3);
283
284   SpinBox_NbSteps->setRange(1, 999999);
285
286   SpinBox_Tolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, 6);
287
288   RadioButton1->setChecked(true);
289
290   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
291
292   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
293
294   // Costruction of the logical filter
295   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
296   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
297
298   QList<SUIT_SelectionFilter*> aListOfFilters;
299   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
300   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
301
302   myMeshOrSubMeshOrGroupFilter =
303     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
304
305   myHelpFileName = "revolution_page.html";
306
307   Init();
308
309   /* signals and slots connections */
310   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
311   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
312   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
313   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
314   connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
315
316   connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
317   connect(SelectPointButton,    SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
318   connect(SelectVectorButton,   SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
319
320   connect(SpinBox_X,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
321   connect(SpinBox_Y,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
322   connect(SpinBox_Z,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
323
324   connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
325   connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
326   connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
327
328   connect(mySMESHGUI,     SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
329   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),      this, SLOT(SelectionIntoArgument()));
330   /* to close dialog if study change */
331   connect(mySMESHGUI,       SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
332   connect(LineEditElements, SIGNAL(textChanged(const QString&)),   SLOT(onTextChange(const QString&)));
333   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                 SLOT(onSelectMesh(bool)));
334
335   connect(GroupAngle,        SIGNAL(buttonClicked(int)),   this, SLOT(toDisplaySimulation()));
336   connect(SpinBox_Angle,     SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
337   connect(SpinBox_NbSteps,   SIGNAL(valueChanged(int)),    this, SLOT(toDisplaySimulation()));
338   connect(SpinBox_Tolerance, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
339   connect(CheckBoxPreview,   SIGNAL(toggled(bool)),        this, SLOT(onDisplaySimulation(bool)));
340
341   connect(SpinBox_Angle, SIGNAL(textChanged(const QString&)), this, SLOT(onAngleTextChange(const QString&)));
342
343   ConstructorsClicked(0);
344   SelectionIntoArgument();
345 }
346
347 //=================================================================================
348 // function : ~SMESHGUI_RevolutionDlg()
349 // purpose  : Destroys the object and frees any allocated resources
350 //=================================================================================
351 SMESHGUI_RevolutionDlg::~SMESHGUI_RevolutionDlg()
352 {
353   delete mySimulation;
354 }
355
356 //=================================================================================
357 // function : Init()
358 // purpose  :
359 //=================================================================================
360 void SMESHGUI_RevolutionDlg::Init (bool ResetControls)
361 {
362   myBusy = false;
363
364   myEditCurrentArgument = 0;
365   LineEditElements->clear();
366   myElementsId = "";
367   myNbOkElements = 0;
368
369   myActor = 0;
370   myMesh = SMESH::SMESH_Mesh::_nil();
371
372   if (ResetControls) {
373     SpinBox_X->SetValue(0.0);
374     SpinBox_Y->SetValue(0.0);
375     SpinBox_Z->SetValue(0.0);
376     SpinBox_DX->SetValue(0.0);
377     SpinBox_DY->SetValue(0.0);
378     SpinBox_DZ->SetValue(0.0);
379
380     SpinBox_Angle->SetValue(45);
381     SpinBox_NbSteps->setValue(1);
382     SpinBox_Tolerance->SetValue(1e-05);
383
384     CheckBoxMesh->setChecked(false);
385     onSelectMesh(false);
386     CheckBoxPreview->setChecked(false);
387     onDisplaySimulation(false);
388   }
389 }
390
391 //=================================================================================
392 // function : ConstructorsClicked()
393 // purpose  : Radio button management
394 //=================================================================================
395 void SMESHGUI_RevolutionDlg::ConstructorsClicked (int constructorId)
396 {
397   //disconnect(mySelectionMgr, 0, this, 0);
398
399   SALOME_ListIO io;
400   mySelectionMgr->selectedObjects( io );
401   SALOME_ListIO aList;
402   mySelectionMgr->setSelectedObjects( aList );
403 //   LineEditElements->clear();
404   myNbOkElements = 0;
405   buttonApply->setEnabled(false);
406   buttonOk->setEnabled(false);
407   mySimulation->SetVisibility(false);
408
409   Selection_Mode aSelMode = ActorSelection;
410
411   switch (constructorId) {
412   case 0:
413     {
414       GroupArguments->setTitle(tr("REVOLUTION_1D"));
415       aSelMode = EdgeSelection;
416       break;
417     }
418   case 1:
419     {
420       GroupArguments->setTitle(tr("REVOLUTION_2D"));
421       aSelMode = FaceSelection;
422       break;
423     }
424   }
425
426   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
427     SMESH::SetPointRepresentation(false);
428   }
429
430   if (!CheckBoxMesh->isChecked())
431     {
432       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
433         aViewWindow->SetSelectionMode(aSelMode);
434     }
435
436   myEditCurrentArgument = (QWidget*)LineEditElements;
437   LineEditElements->setFocus();
438
439   if (CheckBoxMesh->isChecked())
440     onSelectMesh(true);
441
442   //connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
443   mySelectionMgr->setSelectedObjects( io );
444 }
445
446 //=================================================================================
447 // function : ClickOnApply()
448 // purpose  :
449 //=================================================================================
450 bool SMESHGUI_RevolutionDlg::ClickOnApply()
451 {
452   if (mySMESHGUI->isActiveStudyLocked())
453     return false;
454
455   if (!isValid())
456     return false;
457
458   if (myNbOkElements && IsAxisOk()) {
459     QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
460
461     SMESH::long_array_var anElementsId = new SMESH::long_array;
462
463     anElementsId->length(aListElementsId.count());
464     for (int i = 0; i < aListElementsId.count(); i++)
465       anElementsId[i] = aListElementsId[i].toInt();
466
467     SMESH::AxisStruct anAxis;
468
469     anAxis.x =  SpinBox_X->GetValue();
470     anAxis.y =  SpinBox_Y->GetValue();
471     anAxis.z =  SpinBox_Z->GetValue();;
472     anAxis.vx = SpinBox_DX->GetValue();
473     anAxis.vy = SpinBox_DY->GetValue();
474     anAxis.vz = SpinBox_DZ->GetValue();
475
476     double anAngle = (SpinBox_Angle->GetValue())*PI/180;
477     long aNbSteps = (long)SpinBox_NbSteps->value();
478     double aTolerance = SpinBox_Tolerance->GetValue();
479
480     if ( GroupAngle->checkedId() == 1 )
481       anAngle = anAngle/aNbSteps;
482
483     QStringList aParameters;
484     aParameters << SpinBox_X->text();
485     aParameters << SpinBox_Y->text();
486     aParameters << SpinBox_Z->text();
487     aParameters << SpinBox_DX->text();
488     aParameters << SpinBox_DY->text();
489     aParameters << SpinBox_DZ->text();
490     aParameters << SpinBox_Angle->text();
491     aParameters << SpinBox_NbSteps->text();
492     aParameters << SpinBox_Tolerance->text();
493
494     try {
495       SUIT_OverrideCursor aWaitCursor;
496       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
497       
498       if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) {
499         if( CheckBoxMesh->isChecked() ) {
500           if( GetConstructorId() == 0 )
501             SMESH::ListOfGroups_var groups = 
502               aMeshEditor->RotationSweepObject1DMakeGroups(mySelectedObject, anAxis,
503                                                            anAngle, aNbSteps, aTolerance);
504           else
505             SMESH::ListOfGroups_var groups = 
506               aMeshEditor->RotationSweepObject2DMakeGroups(mySelectedObject, anAxis,
507                                                            anAngle, aNbSteps, aTolerance);
508         }
509         else
510           SMESH::ListOfGroups_var groups = 
511             aMeshEditor->RotationSweepMakeGroups(anElementsId.inout(), anAxis,
512                                                  anAngle, aNbSteps, aTolerance);
513       }
514       else {
515         if( CheckBoxMesh->isChecked() ) {
516           if( GetConstructorId() == 0 )
517             aMeshEditor->RotationSweepObject1D(mySelectedObject, anAxis, anAngle, aNbSteps, aTolerance);
518           else
519             aMeshEditor->RotationSweepObject2D(mySelectedObject, anAxis, anAngle, aNbSteps, aTolerance);
520         }
521         else
522           aMeshEditor->RotationSweep(anElementsId.inout(), anAxis, anAngle, aNbSteps, aTolerance);
523       }
524
525       myMesh->SetParameters( SMESHGUI::JoinObjectParameters(aParameters) );
526     } catch (...) {
527     }
528
529     SMESH::UpdateView();
530     if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
531       mySMESHGUI->updateObjBrowser(true); // new groups may appear
532     Init(false);
533     ConstructorsClicked(GetConstructorId());
534     mySelectedObject = SMESH::SMESH_IDSource::_nil();
535     SelectionIntoArgument();
536   }
537
538   return true;
539 }
540
541 //=================================================================================
542 // function : ClickOnOk()
543 // purpose  :
544 //=================================================================================
545 void SMESHGUI_RevolutionDlg::ClickOnOk()
546 {
547   if( ClickOnApply() )
548     ClickOnCancel();
549 }
550
551 //=================================================================================
552 // function : ClickOnCancel()
553 // purpose  :
554 //=================================================================================
555 void SMESHGUI_RevolutionDlg::ClickOnCancel()
556 {
557   disconnect(mySelectionMgr, 0, this, 0);
558   mySelectionMgr->clearFilters();
559   //mySelectionMgr->clearSelected();
560   SMESH::SetPointRepresentation(false);
561   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
562     aViewWindow->SetSelectionMode(ActorSelection);
563   mySMESHGUI->ResetState();
564   reject();
565 }
566
567 //=================================================================================
568 // function : ClickOnHelp()
569 // purpose  :
570 //=================================================================================
571 void SMESHGUI_RevolutionDlg::ClickOnHelp()
572 {
573   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
574   if (app) 
575     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
576   else {
577     QString platform;
578 #ifdef WIN32
579     platform = "winapplication";
580 #else
581     platform = "application";
582 #endif
583     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
584                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
585                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
586                                                                  platform)).
587                              arg(myHelpFileName));
588   }
589 }
590
591 //=======================================================================
592 // function : onAngleTextChange()
593 // purpose  :
594 //=======================================================================
595 void SMESHGUI_RevolutionDlg::onAngleTextChange (const QString& theNewText)
596 {
597   bool isNumber;
598   SpinBox_Angle->text().toDouble( &isNumber );
599   if( !isNumber )
600     RadioButton3->setChecked( true );
601   RadioButton4->setEnabled( isNumber );
602 }
603
604 //=======================================================================
605 // function : onTextChange()
606 // purpose  :
607 //=======================================================================
608 void SMESHGUI_RevolutionDlg::onTextChange (const QString& theNewText)
609 {
610   QLineEdit* send = (QLineEdit*)sender();
611
612   if (myBusy) return;
613   myBusy = true;
614
615   if (send == LineEditElements)
616     myNbOkElements = 0;
617
618   buttonOk->setEnabled(false);
619   buttonApply->setEnabled(false);
620
621   // hilight entered elements
622   SMDS_Mesh* aMesh = 0;
623   if (myActor)
624     aMesh = myActor->GetObject()->GetMesh();
625
626   if (aMesh) {
627     if (send == LineEditElements) {
628       Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
629
630       TColStd_MapOfInteger newIndices;
631
632       QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
633       
634       for (int i = 0; i < aListId.count(); i++) {
635         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
636         if (e)
637           newIndices.Add(e->GetID());
638         myNbOkElements++;
639       }
640
641       mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
642       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
643         aViewWindow->highlight( myActor->getIO(), true, true );
644       
645       myElementsId = theNewText;
646     }
647   }
648
649   if (myNbOkElements && IsAxisOk()) {
650     buttonOk->setEnabled(true);
651     buttonApply->setEnabled(true);
652   }
653   onDisplaySimulation(true);
654
655   myBusy = false;
656 }
657
658 //=================================================================================
659 // function : SelectionIntoArgument()
660 // purpose  : Called when selection as changed or other case
661 //=================================================================================
662 void SMESHGUI_RevolutionDlg::SelectionIntoArgument()
663 {
664   if (myBusy) return;
665
666   // clear
667   myActor = 0;
668   QString aString = "";
669
670   myBusy = true;
671   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
672     LineEditElements->setText(aString);
673     myNbOkElements = 0;
674     buttonOk->setEnabled(false);
675     buttonApply->setEnabled(false);
676   }
677   myBusy = false;
678
679   if (!GroupButtons->isEnabled()) // inactive
680     return;
681
682   // get selected mesh
683   const SALOME_ListIO& aList = mySelector->StoredIObjects();
684
685   int nbSel = aList.Extent();
686   if (nbSel != 1)
687     return;
688
689   Handle(SALOME_InteractiveObject) IO = aList.First();
690   myMesh = SMESH::GetMeshByIO(IO);
691   if (myMesh->_is_nil())
692     return;
693
694   myActor = SMESH::FindActorByObject(myMesh);
695   if (!myActor)
696     myActor = SMESH::FindActorByEntry(IO->getEntry());
697   if (!myActor)
698     return;
699
700   int aNbUnits = 0;
701
702   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
703     myElementsId = "";
704
705     // MakeGroups is available if there are groups
706     if ( myMesh->NbGroups() == 0 ) {
707       MakeGroupsCheck->setChecked(false);
708       MakeGroupsCheck->setEnabled(false);
709     } else {
710       MakeGroupsCheck->setEnabled(true);
711     }
712
713     if (CheckBoxMesh->isChecked()) {
714       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
715
716       if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
717         mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
718       else
719         return;
720     } else {
721       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
722       myElementsId = aString;
723       if (aNbUnits < 1)
724         return;
725     }
726     myNbOkElements = true;
727   } else {
728     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
729     if (aNbUnits != 1)
730       return;
731
732     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
733     if (!aMesh)
734       return;
735
736     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
737     if (!n)
738       return;
739
740     double x = n->X();
741     double y = n->Y();
742     double z = n->Z();
743
744     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
745       SpinBox_X->SetValue(x);
746       SpinBox_Y->SetValue(y);
747       SpinBox_Z->SetValue(z);
748     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
749       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
750       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
751       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
752     }
753   }
754
755   myBusy = true;
756   if (myEditCurrentArgument == (QWidget*)LineEditElements)
757     LineEditElements->setText(aString);
758   myBusy = false;
759
760   // OK
761   if (myNbOkElements && IsAxisOk()) {
762     buttonOk->setEnabled(true);
763     buttonApply->setEnabled(true);
764   }
765
766   onDisplaySimulation(true);
767 }
768
769 //=================================================================================
770 // function : SetEditCurrentArgument()
771 // purpose  :
772 //=================================================================================
773 void SMESHGUI_RevolutionDlg::SetEditCurrentArgument()
774 {
775   QPushButton* send = (QPushButton*)sender();
776
777   disconnect(mySelectionMgr, 0, this, 0);
778   mySelectionMgr->clearSelected();
779   mySelectionMgr->clearFilters();
780
781   if (send == SelectElementsButton) {
782     mySimulation->SetVisibility(false);
783     myEditCurrentArgument = (QWidget*)LineEditElements;
784     SMESH::SetPointRepresentation(false);
785     if (CheckBoxMesh->isChecked()) {
786       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
787         aViewWindow->SetSelectionMode(ActorSelection);
788       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
789     } else {
790       int aConstructorId = GetConstructorId();
791       if (aConstructorId == 0)
792         {
793           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
794             aViewWindow->SetSelectionMode(EdgeSelection);
795         }
796       else if (aConstructorId == 1)
797         {
798           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
799             aViewWindow->SetSelectionMode(FaceSelection);
800         }
801     }
802   } else if (send == SelectPointButton) {
803     myEditCurrentArgument = (QWidget*)SpinBox_X;
804     SMESH::SetPointRepresentation(true);
805     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
806       aViewWindow->SetSelectionMode(NodeSelection);
807   } else if (send == SelectVectorButton) {
808     myEditCurrentArgument = (QWidget*)SpinBox_DX;
809     SMESH::SetPointRepresentation(true);
810     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
811       aViewWindow->SetSelectionMode(NodeSelection);
812   } else {
813   }
814
815   myEditCurrentArgument->setFocus();
816   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
817   SelectionIntoArgument();
818 }
819
820 //=================================================================================
821 // function : DeactivateActiveDialog()
822 // purpose  :
823 //=================================================================================
824 void SMESHGUI_RevolutionDlg::DeactivateActiveDialog()
825 {
826   if (ConstructorsBox->isEnabled()) {
827     ConstructorsBox->setEnabled(false);
828     GroupArguments->setEnabled(false);
829     GroupButtons->setEnabled(false);
830     mySMESHGUI->ResetState();
831     mySMESHGUI->SetActiveDialogBox(0);
832   }
833 }
834
835 //=================================================================================
836 // function : ActivateThisDialog()
837 // purpose  :
838 //=================================================================================
839 void SMESHGUI_RevolutionDlg::ActivateThisDialog()
840 {
841   /* Emit a signal to deactivate the active dialog */
842   mySMESHGUI->EmitSignalDeactivateDialog();
843   ConstructorsBox->setEnabled(true);
844   GroupArguments->setEnabled(true);
845   GroupButtons->setEnabled(true);
846
847   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
848
849   ConstructorsClicked(GetConstructorId());
850   SelectionIntoArgument();
851 }
852
853 //=================================================================================
854 // function : enterEvent()
855 // purpose  :
856 //=================================================================================
857 void SMESHGUI_RevolutionDlg::enterEvent (QEvent*)
858 {
859   if (!ConstructorsBox->isEnabled())
860     ActivateThisDialog();
861 }
862
863 //=================================================================================
864 // function : closeEvent()
865 // purpose  :
866 //=================================================================================
867 void SMESHGUI_RevolutionDlg::closeEvent (QCloseEvent*)
868 {
869   /* same than click on cancel button */
870   ClickOnCancel();
871 }
872
873 //=======================================================================
874 // function : hideEvent()
875 // purpose  : caused by ESC key
876 //=======================================================================
877 void SMESHGUI_RevolutionDlg::hideEvent (QHideEvent*)
878 {
879   if (!isMinimized())
880     ClickOnCancel();
881 }
882
883 //=======================================================================
884 //function : onSelectMesh
885 //purpose  :
886 //=======================================================================
887 void SMESHGUI_RevolutionDlg::onSelectMesh (bool toSelectMesh)
888 {
889   if (toSelectMesh)
890     TextLabelElements->setText(tr("SMESH_NAME"));
891   else
892     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
893
894   if (myEditCurrentArgument != LineEditElements) {
895     LineEditElements->clear();
896     mySimulation->SetVisibility(false);
897     return;
898   }
899
900   mySelectionMgr->clearFilters();
901   SMESH::SetPointRepresentation(false);
902
903   if (toSelectMesh) {
904     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
905       aViewWindow->SetSelectionMode(ActorSelection);
906     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
907     LineEditElements->setReadOnly(true);
908     LineEditElements->setValidator(0);
909   } else {
910     int aConstructorId = GetConstructorId();
911     if (aConstructorId == 0)
912       {
913         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
914           aViewWindow->SetSelectionMode(EdgeSelection);
915       }
916     else if (aConstructorId == 0)
917       {
918         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
919           aViewWindow->SetSelectionMode(FaceSelection);
920       }
921
922     LineEditElements->setReadOnly(false);
923     LineEditElements->setValidator(myIdValidator);
924     onTextChange(LineEditElements->text());
925     mySimulation->SetVisibility(false);
926   }
927
928   SelectionIntoArgument();
929 }
930
931 //=================================================================================
932 // function : GetConstructorId()
933 // purpose  :
934 //=================================================================================
935 int SMESHGUI_RevolutionDlg::GetConstructorId()
936 {
937   return GroupConstructors->checkedId();
938 }
939
940 //=================================================================================
941 // function : IsAxisOk()
942 // purpose  :
943 //=================================================================================
944 bool SMESHGUI_RevolutionDlg::IsAxisOk()
945 {
946   return (SpinBox_DX->GetValue() != 0 ||
947           SpinBox_DY->GetValue() != 0 ||
948           SpinBox_DZ->GetValue() != 0);
949 }
950
951 //=================================================================================
952 // function : onVectorChanged()
953 // purpose  :
954 //=================================================================================
955 void SMESHGUI_RevolutionDlg::onVectorChanged()
956 {
957   if (IsAxisOk()) {
958     buttonOk->setEnabled(true);
959     buttonApply->setEnabled(true);
960   } else {
961     buttonOk->setEnabled(false);
962     buttonApply->setEnabled(false);
963   }
964   onDisplaySimulation(true);
965 }
966
967 //=================================================================================
968 // function : keyPressEvent()
969 // purpose  :
970 //=================================================================================
971 void SMESHGUI_RevolutionDlg::keyPressEvent( QKeyEvent* e )
972 {
973   QDialog::keyPressEvent( e );
974   if ( e->isAccepted() )
975     return;
976
977   if ( e->key() == Qt::Key_F1 ) {
978     e->accept();
979     ClickOnHelp();
980   }
981 }
982
983 //=================================================================================
984 // function : toDisplaySimulation()
985 // purpose  :
986 //=================================================================================
987 void SMESHGUI_RevolutionDlg::toDisplaySimulation()
988 {
989   onDisplaySimulation(true);
990 }
991
992 //=================================================================================
993 // function : onDisplaySimulation()
994 // purpose  :
995 //=================================================================================
996 void SMESHGUI_RevolutionDlg::onDisplaySimulation(bool toDisplayPreview)
997 {
998   if (CheckBoxPreview->isChecked() && toDisplayPreview)
999   {
1000     //display preview
1001     if (myNbOkElements && IsAxisOk())
1002     {
1003       QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1004       
1005       SMESH::long_array_var anElementsId = new SMESH::long_array;
1006       
1007       anElementsId->length(aListElementsId.count());
1008       for (int i = 0; i < aListElementsId.count(); i++)
1009         anElementsId[i] = aListElementsId[i].toInt();
1010       
1011       SMESH::AxisStruct anAxis;
1012       
1013       anAxis.x =  SpinBox_X->GetValue();
1014       anAxis.y =  SpinBox_Y->GetValue();
1015       anAxis.z =  SpinBox_Z->GetValue();
1016       anAxis.vx = SpinBox_DX->GetValue();
1017       anAxis.vy = SpinBox_DY->GetValue();
1018       anAxis.vz = SpinBox_DZ->GetValue();
1019       
1020       double anAngle = (SpinBox_Angle->GetValue())*PI/180;
1021       long aNbSteps = (long)SpinBox_NbSteps->value();
1022       double aTolerance = SpinBox_Tolerance->GetValue();
1023       
1024       if (GroupAngle->checkedId() == 1)
1025         anAngle = anAngle/aNbSteps;
1026       
1027       try {
1028         SUIT_OverrideCursor aWaitCursor;
1029         SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1030         if( CheckBoxMesh->isChecked() ) {
1031           if( GetConstructorId() == 0 )
1032             aMeshEditor->RotationSweepObject1D(mySelectedObject, anAxis,
1033                                                anAngle, aNbSteps, aTolerance);
1034           else
1035             aMeshEditor->RotationSweepObject2D(mySelectedObject, anAxis,
1036                                                anAngle, aNbSteps, aTolerance);
1037         }
1038         else
1039           aMeshEditor->RotationSweep(anElementsId.inout(), 
1040                                      anAxis, 
1041                                      anAngle, 
1042                                      aNbSteps, 
1043                                      aTolerance);
1044         SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1045         mySimulation->SetData(aMeshPreviewStruct._retn());
1046       } catch (...) {}
1047     }
1048     else
1049     {
1050       mySimulation->SetVisibility(false);
1051     }
1052   }
1053   else
1054   {
1055     //erase preview
1056     mySimulation->SetVisibility(false);
1057   }
1058 }
1059
1060
1061 //=================================================================================
1062 // function : isValid
1063 // purpose  :
1064 //=================================================================================
1065 bool SMESHGUI_RevolutionDlg::isValid()
1066 {
1067   QString msg;
1068   bool ok = true;
1069   ok = SpinBox_X->isValid( msg, true ) && ok;
1070   ok = SpinBox_Y->isValid( msg, true ) && ok;
1071   ok = SpinBox_Z->isValid( msg, true ) && ok;
1072   ok = SpinBox_DX->isValid( msg, true ) && ok;
1073   ok = SpinBox_DY->isValid( msg, true ) && ok;
1074   ok = SpinBox_DZ->isValid( msg, true ) && ok;
1075   ok = SpinBox_Angle->isValid( msg, true ) && ok;
1076   ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
1077   ok = SpinBox_Tolerance->isValid( msg, true ) && ok;
1078
1079   if( !ok ) {
1080     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1081     if ( !msg.isEmpty() )
1082       str += "\n" + msg;
1083     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1084     return false;
1085   }
1086   return true;
1087 }