Salome HOME
Dump Puthon extension
[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         aMeshEditor->RotationSweep(anElementsId.inout(), anAxis, anAngle, aNbSteps, aTolerance);
522       }
523
524       myMesh->SetParameters( SMESHGUI::JoinObjectParameters(aParameters) );
525     } catch (...) {
526     }
527
528     SMESH::UpdateView();
529     if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
530       mySMESHGUI->updateObjBrowser(true); // new groups may appear
531     Init(false);
532     ConstructorsClicked(GetConstructorId());
533     mySelectedObject = SMESH::SMESH_IDSource::_nil();
534     SelectionIntoArgument();
535   }
536
537   return true;
538 }
539
540 //=================================================================================
541 // function : ClickOnOk()
542 // purpose  :
543 //=================================================================================
544 void SMESHGUI_RevolutionDlg::ClickOnOk()
545 {
546   if( ClickOnApply() )
547     ClickOnCancel();
548 }
549
550 //=================================================================================
551 // function : ClickOnCancel()
552 // purpose  :
553 //=================================================================================
554 void SMESHGUI_RevolutionDlg::ClickOnCancel()
555 {
556   disconnect(mySelectionMgr, 0, this, 0);
557   mySelectionMgr->clearFilters();
558   //mySelectionMgr->clearSelected();
559   SMESH::SetPointRepresentation(false);
560   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
561     aViewWindow->SetSelectionMode(ActorSelection);
562   mySMESHGUI->ResetState();
563   reject();
564 }
565
566 //=================================================================================
567 // function : ClickOnHelp()
568 // purpose  :
569 //=================================================================================
570 void SMESHGUI_RevolutionDlg::ClickOnHelp()
571 {
572   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
573   if (app) 
574     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
575   else {
576     QString platform;
577 #ifdef WIN32
578     platform = "winapplication";
579 #else
580     platform = "application";
581 #endif
582     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
583                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
584                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
585                                                                  platform)).
586                              arg(myHelpFileName));
587   }
588 }
589
590 //=======================================================================
591 // function : onAngleTextChange()
592 // purpose  :
593 //=======================================================================
594 void SMESHGUI_RevolutionDlg::onAngleTextChange (const QString& theNewText)
595 {
596   bool isNumber;
597   SpinBox_Angle->text().toDouble( &isNumber );
598   if( !isNumber )
599     RadioButton3->setChecked( true );
600   RadioButton4->setEnabled( isNumber );
601 }
602
603 //=======================================================================
604 // function : onTextChange()
605 // purpose  :
606 //=======================================================================
607 void SMESHGUI_RevolutionDlg::onTextChange (const QString& theNewText)
608 {
609   QLineEdit* send = (QLineEdit*)sender();
610
611   if (myBusy) return;
612   myBusy = true;
613
614   if (send == LineEditElements)
615     myNbOkElements = 0;
616
617   buttonOk->setEnabled(false);
618   buttonApply->setEnabled(false);
619
620   // hilight entered elements
621   SMDS_Mesh* aMesh = 0;
622   if (myActor)
623     aMesh = myActor->GetObject()->GetMesh();
624
625   if (aMesh) {
626     if (send == LineEditElements) {
627       Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
628
629       TColStd_MapOfInteger newIndices;
630
631       QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
632       
633       for (int i = 0; i < aListId.count(); i++) {
634         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
635         if (e)
636           newIndices.Add(e->GetID());
637         myNbOkElements++;
638       }
639
640       mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
641       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
642         aViewWindow->highlight( myActor->getIO(), true, true );
643       
644       myElementsId = theNewText;
645     }
646   }
647
648   if (myNbOkElements && IsAxisOk()) {
649     buttonOk->setEnabled(true);
650     buttonApply->setEnabled(true);
651   }
652   onDisplaySimulation(true);
653
654   myBusy = false;
655 }
656
657 //=================================================================================
658 // function : SelectionIntoArgument()
659 // purpose  : Called when selection as changed or other case
660 //=================================================================================
661 void SMESHGUI_RevolutionDlg::SelectionIntoArgument()
662 {
663   if (myBusy) return;
664
665   // clear
666   myActor = 0;
667   QString aString = "";
668
669   myBusy = true;
670   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
671     LineEditElements->setText(aString);
672     myNbOkElements = 0;
673     buttonOk->setEnabled(false);
674     buttonApply->setEnabled(false);
675   }
676   myBusy = false;
677
678   if (!GroupButtons->isEnabled()) // inactive
679     return;
680
681   // get selected mesh
682   const SALOME_ListIO& aList = mySelector->StoredIObjects();
683
684   int nbSel = aList.Extent();
685   if (nbSel != 1)
686     return;
687
688   Handle(SALOME_InteractiveObject) IO = aList.First();
689   myMesh = SMESH::GetMeshByIO(IO);
690   if (myMesh->_is_nil())
691     return;
692
693   myActor = SMESH::FindActorByObject(myMesh);
694   if (!myActor)
695     myActor = SMESH::FindActorByEntry(IO->getEntry());
696   if (!myActor)
697     return;
698
699   int aNbUnits = 0;
700
701   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
702     myElementsId = "";
703
704     // MakeGroups is available if there are groups
705     if ( myMesh->NbGroups() == 0 ) {
706       MakeGroupsCheck->setChecked(false);
707       MakeGroupsCheck->setEnabled(false);
708     } else {
709       MakeGroupsCheck->setEnabled(true);
710     }
711
712     if (CheckBoxMesh->isChecked()) {
713       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
714
715       if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
716         mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
717       else
718         return;
719     } else {
720       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
721       myElementsId = aString;
722       if (aNbUnits < 1)
723         return;
724     }
725     myNbOkElements = true;
726   } else {
727     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
728     if (aNbUnits != 1)
729       return;
730
731     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
732     if (!aMesh)
733       return;
734
735     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
736     if (!n)
737       return;
738
739     double x = n->X();
740     double y = n->Y();
741     double z = n->Z();
742
743     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
744       SpinBox_X->SetValue(x);
745       SpinBox_Y->SetValue(y);
746       SpinBox_Z->SetValue(z);
747     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
748       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
749       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
750       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
751     }
752   }
753
754   myBusy = true;
755   if (myEditCurrentArgument == (QWidget*)LineEditElements)
756     LineEditElements->setText(aString);
757   myBusy = false;
758
759   // OK
760   if (myNbOkElements && IsAxisOk()) {
761     buttonOk->setEnabled(true);
762     buttonApply->setEnabled(true);
763   }
764
765   onDisplaySimulation(true);
766 }
767
768 //=================================================================================
769 // function : SetEditCurrentArgument()
770 // purpose  :
771 //=================================================================================
772 void SMESHGUI_RevolutionDlg::SetEditCurrentArgument()
773 {
774   QPushButton* send = (QPushButton*)sender();
775
776   disconnect(mySelectionMgr, 0, this, 0);
777   mySelectionMgr->clearSelected();
778   mySelectionMgr->clearFilters();
779
780   if (send == SelectElementsButton) {
781     mySimulation->SetVisibility(false);
782     myEditCurrentArgument = (QWidget*)LineEditElements;
783     SMESH::SetPointRepresentation(false);
784     if (CheckBoxMesh->isChecked()) {
785       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
786         aViewWindow->SetSelectionMode(ActorSelection);
787       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
788     } else {
789       int aConstructorId = GetConstructorId();
790       if (aConstructorId == 0)
791         {
792           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
793             aViewWindow->SetSelectionMode(EdgeSelection);
794         }
795       else if (aConstructorId == 1)
796         {
797           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
798             aViewWindow->SetSelectionMode(FaceSelection);
799         }
800     }
801   } else if (send == SelectPointButton) {
802     myEditCurrentArgument = (QWidget*)SpinBox_X;
803     SMESH::SetPointRepresentation(true);
804     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
805       aViewWindow->SetSelectionMode(NodeSelection);
806   } else if (send == SelectVectorButton) {
807     myEditCurrentArgument = (QWidget*)SpinBox_DX;
808     SMESH::SetPointRepresentation(true);
809     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
810       aViewWindow->SetSelectionMode(NodeSelection);
811   } else {
812   }
813
814   myEditCurrentArgument->setFocus();
815   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
816   SelectionIntoArgument();
817 }
818
819 //=================================================================================
820 // function : DeactivateActiveDialog()
821 // purpose  :
822 //=================================================================================
823 void SMESHGUI_RevolutionDlg::DeactivateActiveDialog()
824 {
825   if (ConstructorsBox->isEnabled()) {
826     ConstructorsBox->setEnabled(false);
827     GroupArguments->setEnabled(false);
828     GroupButtons->setEnabled(false);
829     mySMESHGUI->ResetState();
830     mySMESHGUI->SetActiveDialogBox(0);
831   }
832 }
833
834 //=================================================================================
835 // function : ActivateThisDialog()
836 // purpose  :
837 //=================================================================================
838 void SMESHGUI_RevolutionDlg::ActivateThisDialog()
839 {
840   /* Emit a signal to deactivate the active dialog */
841   mySMESHGUI->EmitSignalDeactivateDialog();
842   ConstructorsBox->setEnabled(true);
843   GroupArguments->setEnabled(true);
844   GroupButtons->setEnabled(true);
845
846   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
847
848   ConstructorsClicked(GetConstructorId());
849   SelectionIntoArgument();
850 }
851
852 //=================================================================================
853 // function : enterEvent()
854 // purpose  :
855 //=================================================================================
856 void SMESHGUI_RevolutionDlg::enterEvent (QEvent*)
857 {
858   if (!ConstructorsBox->isEnabled())
859     ActivateThisDialog();
860 }
861
862 //=================================================================================
863 // function : closeEvent()
864 // purpose  :
865 //=================================================================================
866 void SMESHGUI_RevolutionDlg::closeEvent (QCloseEvent*)
867 {
868   /* same than click on cancel button */
869   ClickOnCancel();
870 }
871
872 //=======================================================================
873 // function : hideEvent()
874 // purpose  : caused by ESC key
875 //=======================================================================
876 void SMESHGUI_RevolutionDlg::hideEvent (QHideEvent*)
877 {
878   if (!isMinimized())
879     ClickOnCancel();
880 }
881
882 //=======================================================================
883 //function : onSelectMesh
884 //purpose  :
885 //=======================================================================
886 void SMESHGUI_RevolutionDlg::onSelectMesh (bool toSelectMesh)
887 {
888   if (toSelectMesh)
889     TextLabelElements->setText(tr("SMESH_NAME"));
890   else
891     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
892
893   if (myEditCurrentArgument != LineEditElements) {
894     LineEditElements->clear();
895     mySimulation->SetVisibility(false);
896     return;
897   }
898
899   mySelectionMgr->clearFilters();
900   SMESH::SetPointRepresentation(false);
901
902   if (toSelectMesh) {
903     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
904       aViewWindow->SetSelectionMode(ActorSelection);
905     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
906     LineEditElements->setReadOnly(true);
907     LineEditElements->setValidator(0);
908   } else {
909     int aConstructorId = GetConstructorId();
910     if (aConstructorId == 0)
911       {
912         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
913           aViewWindow->SetSelectionMode(EdgeSelection);
914       }
915     else if (aConstructorId == 0)
916       {
917         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
918           aViewWindow->SetSelectionMode(FaceSelection);
919       }
920
921     LineEditElements->setReadOnly(false);
922     LineEditElements->setValidator(myIdValidator);
923     onTextChange(LineEditElements->text());
924     mySimulation->SetVisibility(false);
925   }
926
927   SelectionIntoArgument();
928 }
929
930 //=================================================================================
931 // function : GetConstructorId()
932 // purpose  :
933 //=================================================================================
934 int SMESHGUI_RevolutionDlg::GetConstructorId()
935 {
936   return GroupConstructors->checkedId();
937 }
938
939 //=================================================================================
940 // function : IsAxisOk()
941 // purpose  :
942 //=================================================================================
943 bool SMESHGUI_RevolutionDlg::IsAxisOk()
944 {
945   return (SpinBox_DX->GetValue() != 0 ||
946           SpinBox_DY->GetValue() != 0 ||
947           SpinBox_DZ->GetValue() != 0);
948 }
949
950 //=================================================================================
951 // function : onVectorChanged()
952 // purpose  :
953 //=================================================================================
954 void SMESHGUI_RevolutionDlg::onVectorChanged()
955 {
956   if (IsAxisOk()) {
957     buttonOk->setEnabled(true);
958     buttonApply->setEnabled(true);
959   } else {
960     buttonOk->setEnabled(false);
961     buttonApply->setEnabled(false);
962   }
963   onDisplaySimulation(true);
964 }
965
966 //=================================================================================
967 // function : keyPressEvent()
968 // purpose  :
969 //=================================================================================
970 void SMESHGUI_RevolutionDlg::keyPressEvent( QKeyEvent* e )
971 {
972   QDialog::keyPressEvent( e );
973   if ( e->isAccepted() )
974     return;
975
976   if ( e->key() == Qt::Key_F1 ) {
977     e->accept();
978     ClickOnHelp();
979   }
980 }
981
982 //=================================================================================
983 // function : toDisplaySimulation()
984 // purpose  :
985 //=================================================================================
986 void SMESHGUI_RevolutionDlg::toDisplaySimulation()
987 {
988   onDisplaySimulation(true);
989 }
990
991 //=================================================================================
992 // function : onDisplaySimulation()
993 // purpose  :
994 //=================================================================================
995 void SMESHGUI_RevolutionDlg::onDisplaySimulation(bool toDisplayPreview)
996 {
997   if (CheckBoxPreview->isChecked() && toDisplayPreview)
998   {
999     //display preview
1000     if (myNbOkElements && IsAxisOk())
1001     {
1002       QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1003       
1004       SMESH::long_array_var anElementsId = new SMESH::long_array;
1005       
1006       anElementsId->length(aListElementsId.count());
1007       for (int i = 0; i < aListElementsId.count(); i++)
1008         anElementsId[i] = aListElementsId[i].toInt();
1009       
1010       SMESH::AxisStruct anAxis;
1011       
1012       anAxis.x =  SpinBox_X->GetValue();
1013       anAxis.y =  SpinBox_Y->GetValue();
1014       anAxis.z =  SpinBox_Z->GetValue();
1015       anAxis.vx = SpinBox_DX->GetValue();
1016       anAxis.vy = SpinBox_DY->GetValue();
1017       anAxis.vz = SpinBox_DZ->GetValue();
1018       
1019       double anAngle = (SpinBox_Angle->GetValue())*PI/180;
1020       long aNbSteps = (long)SpinBox_NbSteps->value();
1021       double aTolerance = SpinBox_Tolerance->GetValue();
1022       
1023       if (GroupAngle->checkedId() == 1)
1024         anAngle = anAngle/aNbSteps;
1025       
1026       try {
1027         SUIT_OverrideCursor aWaitCursor;
1028         SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1029         if( CheckBoxMesh->isChecked() ) {
1030           if( GetConstructorId() == 0 )
1031             aMeshEditor->RotationSweepObject1D(mySelectedObject, anAxis,
1032                                                anAngle, aNbSteps, aTolerance);
1033           else
1034             aMeshEditor->RotationSweepObject2D(mySelectedObject, anAxis,
1035                                                anAngle, aNbSteps, aTolerance);
1036         }
1037         else
1038           aMeshEditor->RotationSweep(anElementsId.inout(), 
1039                                      anAxis, 
1040                                      anAngle, 
1041                                      aNbSteps, 
1042                                      aTolerance);
1043         SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1044         mySimulation->SetData(aMeshPreviewStruct._retn());
1045       } catch (...) {}
1046     }
1047     else
1048     {
1049       mySimulation->SetVisibility(false);
1050     }
1051   }
1052   else
1053   {
1054     //erase preview
1055     mySimulation->SetVisibility(false);
1056   }
1057 }
1058
1059
1060 //=================================================================================
1061 // function : isValid
1062 // purpose  :
1063 //=================================================================================
1064 bool SMESHGUI_RevolutionDlg::isValid()
1065 {
1066   QString msg;
1067   bool ok = true;
1068   ok = SpinBox_X->isValid( msg, true ) && ok;
1069   ok = SpinBox_Y->isValid( msg, true ) && ok;
1070   ok = SpinBox_Z->isValid( msg, true ) && ok;
1071   ok = SpinBox_DX->isValid( msg, true ) && ok;
1072   ok = SpinBox_DY->isValid( msg, true ) && ok;
1073   ok = SpinBox_DZ->isValid( msg, true ) && ok;
1074   ok = SpinBox_Angle->isValid( msg, true ) && ok;
1075   ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
1076   ok = SpinBox_Tolerance->isValid( msg, true ) && ok;
1077
1078   if( !ok ) {
1079     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1080     if ( !msg.isEmpty() )
1081       str += "\n" + msg;
1082     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1083     return false;
1084   }
1085   return true;
1086 }