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