Salome HOME
Dump Python 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 {
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 SalomeApp_IntSpinBox(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   connect(SpinBox_Angle, SIGNAL(textChanged(const QString&)), this, SLOT(onAngleTextChange(const QString&)));
341
342   ConstructorsClicked(0);
343   SelectionIntoArgument();
344 }
345
346 //=================================================================================
347 // function : ~SMESHGUI_RevolutionDlg()
348 // purpose  : Destroys the object and frees any allocated resources
349 //=================================================================================
350 SMESHGUI_RevolutionDlg::~SMESHGUI_RevolutionDlg()
351 {
352   delete mySimulation;
353 }
354
355 //=================================================================================
356 // function : Init()
357 // purpose  :
358 //=================================================================================
359 void SMESHGUI_RevolutionDlg::Init (bool ResetControls)
360 {
361   myBusy = false;
362
363   myEditCurrentArgument = 0;
364   LineEditElements->clear();
365   myElementsId = "";
366   myNbOkElements = 0;
367
368   myActor = 0;
369   myMesh = SMESH::SMESH_Mesh::_nil();
370
371   if (ResetControls) {
372     SpinBox_X->SetValue(0.0);
373     SpinBox_Y->SetValue(0.0);
374     SpinBox_Z->SetValue(0.0);
375     SpinBox_DX->SetValue(0.0);
376     SpinBox_DY->SetValue(0.0);
377     SpinBox_DZ->SetValue(0.0);
378
379     SpinBox_Angle->SetValue(45);
380     SpinBox_NbSteps->setValue(1);
381     SpinBox_Tolerance->SetValue(1e-05);
382
383     CheckBoxMesh->setChecked(false);
384     onSelectMesh(false);
385     CheckBoxPreview->setChecked(false);
386     onDisplaySimulation(false);
387   }
388 }
389
390 //=================================================================================
391 // function : ConstructorsClicked()
392 // purpose  : Radio button management
393 //=================================================================================
394 void SMESHGUI_RevolutionDlg::ConstructorsClicked (int constructorId)
395 {
396   //disconnect(mySelectionMgr, 0, this, 0);
397
398   SALOME_ListIO io;
399   mySelectionMgr->selectedObjects( io );
400   SALOME_ListIO aList;
401   mySelectionMgr->setSelectedObjects( aList );
402 //   LineEditElements->clear();
403   myNbOkElements = 0;
404   buttonApply->setEnabled(false);
405   buttonOk->setEnabled(false);
406   mySimulation->SetVisibility(false);
407
408   Selection_Mode aSelMode = ActorSelection;
409
410   switch (constructorId) {
411   case 0:
412     {
413       GroupArguments->setTitle(tr("REVOLUTION_1D"));
414       aSelMode = EdgeSelection;
415       break;
416     }
417   case 1:
418     {
419       GroupArguments->setTitle(tr("REVOLUTION_2D"));
420       aSelMode = FaceSelection;
421       break;
422     }
423   }
424
425   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
426     SMESH::SetPointRepresentation(false);
427   }
428
429   if (!CheckBoxMesh->isChecked())
430     {
431       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
432         aViewWindow->SetSelectionMode(aSelMode);
433     }
434
435   myEditCurrentArgument = (QWidget*)LineEditElements;
436   LineEditElements->setFocus();
437
438   if (CheckBoxMesh->isChecked())
439     onSelectMesh(true);
440
441   //connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
442   mySelectionMgr->setSelectedObjects( io );
443 }
444
445 //=================================================================================
446 // function : ClickOnApply()
447 // purpose  :
448 //=================================================================================
449 bool SMESHGUI_RevolutionDlg::ClickOnApply()
450 {
451   if (mySMESHGUI->isActiveStudyLocked())
452     return false;
453
454   if (!isValid())
455     return false;
456
457   if (myNbOkElements && IsAxisOk()) {
458     QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
459
460     SMESH::long_array_var anElementsId = new SMESH::long_array;
461
462     anElementsId->length(aListElementsId.count());
463     for (int i = 0; i < aListElementsId.count(); i++)
464       anElementsId[i] = aListElementsId[i].toInt();
465
466     SMESH::AxisStruct anAxis;
467
468     anAxis.x =  SpinBox_X->GetValue();
469     anAxis.y =  SpinBox_Y->GetValue();
470     anAxis.z =  SpinBox_Z->GetValue();;
471     anAxis.vx = SpinBox_DX->GetValue();
472     anAxis.vy = SpinBox_DY->GetValue();
473     anAxis.vz = SpinBox_DZ->GetValue();
474
475     double anAngle = (SpinBox_Angle->GetValue())*PI/180;
476     long aNbSteps = (long)SpinBox_NbSteps->value();
477     double aTolerance = SpinBox_Tolerance->GetValue();
478
479     if ( GroupAngle->checkedId() == 1 )
480       anAngle = anAngle/aNbSteps;
481
482     QStringList aParameters;
483     aParameters << SpinBox_X->text();
484     aParameters << SpinBox_Y->text();
485     aParameters << SpinBox_Z->text();
486     aParameters << SpinBox_DX->text();
487     aParameters << SpinBox_DY->text();
488     aParameters << SpinBox_DZ->text();
489     aParameters << SpinBox_Angle->text();
490     aParameters << SpinBox_NbSteps->text();
491     aParameters << SpinBox_Tolerance->text();
492
493     try {
494       SUIT_OverrideCursor aWaitCursor;
495       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
496       
497       if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
498         SMESH::ListOfGroups_var groups = 
499           aMeshEditor->RotationSweepMakeGroups(anElementsId.inout(), anAxis,
500                                                anAngle, aNbSteps, aTolerance);
501       else
502         aMeshEditor->RotationSweep(anElementsId.inout(), anAxis, anAngle, aNbSteps, aTolerance);
503
504       myMesh->SetParameters( SMESHGUI::JoinObjectParameters(aParameters) );
505     } catch (...) {
506     }
507
508     SMESH::UpdateView();
509     if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() )
510       mySMESHGUI->updateObjBrowser(true); // new groups may appear
511     Init(false);
512     ConstructorsClicked(GetConstructorId());
513     SelectionIntoArgument();
514   }
515
516   return true;
517 }
518
519 //=================================================================================
520 // function : ClickOnOk()
521 // purpose  :
522 //=================================================================================
523 void SMESHGUI_RevolutionDlg::ClickOnOk()
524 {
525   if( ClickOnApply() )
526     ClickOnCancel();
527 }
528
529 //=================================================================================
530 // function : ClickOnCancel()
531 // purpose  :
532 //=================================================================================
533 void SMESHGUI_RevolutionDlg::ClickOnCancel()
534 {
535   disconnect(mySelectionMgr, 0, this, 0);
536   mySelectionMgr->clearFilters();
537   //mySelectionMgr->clearSelected();
538   SMESH::SetPointRepresentation(false);
539   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
540     aViewWindow->SetSelectionMode(ActorSelection);
541   mySMESHGUI->ResetState();
542   reject();
543 }
544
545 //=================================================================================
546 // function : ClickOnHelp()
547 // purpose  :
548 //=================================================================================
549 void SMESHGUI_RevolutionDlg::ClickOnHelp()
550 {
551   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
552   if (app) 
553     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
554   else {
555     QString platform;
556 #ifdef WIN32
557     platform = "winapplication";
558 #else
559     platform = "application";
560 #endif
561     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
562                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
563                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
564                                                                  platform)).
565                              arg(myHelpFileName));
566   }
567 }
568
569 //=======================================================================
570 // function : onAngleTextChange()
571 // purpose  :
572 //=======================================================================
573 void SMESHGUI_RevolutionDlg::onAngleTextChange (const QString& theNewText)
574 {
575   bool isNumber;
576   SpinBox_Angle->text().toDouble( &isNumber );
577   if( !isNumber )
578     RadioButton3->setChecked( true );
579   RadioButton4->setEnabled( isNumber );
580 }
581
582 //=======================================================================
583 // function : onTextChange()
584 // purpose  :
585 //=======================================================================
586 void SMESHGUI_RevolutionDlg::onTextChange (const QString& theNewText)
587 {
588   QLineEdit* send = (QLineEdit*)sender();
589
590   if (myBusy) return;
591   myBusy = true;
592
593   if (send == LineEditElements)
594     myNbOkElements = 0;
595
596   buttonOk->setEnabled(false);
597   buttonApply->setEnabled(false);
598
599   // hilight entered elements
600   SMDS_Mesh* aMesh = 0;
601   if (myActor)
602     aMesh = myActor->GetObject()->GetMesh();
603
604   if (aMesh) {
605     if (send == LineEditElements) {
606       Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
607
608       TColStd_MapOfInteger newIndices;
609
610       QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
611       
612       for (int i = 0; i < aListId.count(); i++) {
613         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
614         if (e)
615           newIndices.Add(e->GetID());
616         myNbOkElements++;
617       }
618
619       mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
620       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
621         aViewWindow->highlight( myActor->getIO(), true, true );
622       
623       myElementsId = theNewText;
624     }
625   }
626
627   if (myNbOkElements && IsAxisOk()) {
628     buttonOk->setEnabled(true);
629     buttonApply->setEnabled(true);
630   }
631   onDisplaySimulation(true);
632
633   myBusy = false;
634 }
635
636 //=================================================================================
637 // function : SelectionIntoArgument()
638 // purpose  : Called when selection as changed or other case
639 //=================================================================================
640 void SMESHGUI_RevolutionDlg::SelectionIntoArgument()
641 {
642   if (myBusy) return;
643
644   // clear
645   myActor = 0;
646   QString aString = "";
647
648   myBusy = true;
649   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
650     LineEditElements->setText(aString);
651     myNbOkElements = 0;
652     buttonOk->setEnabled(false);
653     buttonApply->setEnabled(false);
654   }
655   myBusy = false;
656
657   if (!GroupButtons->isEnabled()) // inactive
658     return;
659
660   // get selected mesh
661   const SALOME_ListIO& aList = mySelector->StoredIObjects();
662
663   int nbSel = aList.Extent();
664   if (nbSel != 1)
665     return;
666
667   Handle(SALOME_InteractiveObject) IO = aList.First();
668   myMesh = SMESH::GetMeshByIO(IO);
669   if (myMesh->_is_nil())
670     return;
671
672   myActor = SMESH::FindActorByObject(myMesh);
673   if (!myActor)
674     myActor = SMESH::FindActorByEntry(IO->getEntry());
675   if (!myActor)
676     return;
677
678   int aNbUnits = 0;
679
680   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
681     myElementsId = "";
682
683     // MakeGroups is available if there are groups
684     if ( myMesh->NbGroups() == 0 ) {
685       MakeGroupsCheck->setChecked(false);
686       MakeGroupsCheck->setEnabled(false);
687     } else {
688       MakeGroupsCheck->setEnabled(true);
689     }
690
691     if (CheckBoxMesh->isChecked()) {
692       int aConstructorId = GetConstructorId();
693
694       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
695
696       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
697         // get IDs from mesh
698         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
699         if (!aSMDSMesh)
700           return;
701
702         if (aConstructorId == 0) {
703           SMDS_EdgeIteratorPtr anIter = aSMDSMesh->edgesIterator();
704
705           while (anIter->more()) {
706             const SMDS_MeshEdge * edge = anIter->next();
707             if (edge) {
708               myElementsId += QString(" %1").arg(edge->GetID());
709               aNbUnits++;
710             }
711           }
712         } else if (aConstructorId == 1) {
713           SMDS_FaceIteratorPtr anIter = aSMDSMesh->facesIterator();
714           while (anIter->more()) {
715             const SMDS_MeshFace * face = anIter->next();
716             if (face) {
717               myElementsId += QString(" %1").arg(face->GetID());
718               aNbUnits++;
719             }
720           }
721         }
722       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
723         // get submesh
724         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
725
726         // get IDs from submesh
727         SMESH::long_array_var anElementsIds = new SMESH::long_array;
728         if (aConstructorId == 0)
729           anElementsIds = aSubMesh->GetElementsByType(SMESH::EDGE);
730         else if (aConstructorId == 1)
731           anElementsIds = aSubMesh->GetElementsByType(SMESH::FACE);
732
733         for (int i = 0; i < anElementsIds->length(); i++)
734           myElementsId += QString(" %1").arg(anElementsIds[i]);
735         aNbUnits = anElementsIds->length();
736       } else { // GROUP
737         // get smesh group
738         SMESH::SMESH_GroupBase_var aGroup =
739           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
740         if (aGroup->_is_nil())
741           return;
742
743         if ((aConstructorId == 0 && aGroup->GetType()!= SMESH::EDGE) ||
744             (aConstructorId == 1 && aGroup->GetType()!= SMESH::FACE))
745           return;
746
747         // get IDs from smesh group
748         SMESH::long_array_var anElementsIds = new SMESH::long_array;
749         anElementsIds = aGroup->GetListOfID();
750         for (int i = 0; i < anElementsIds->length(); i++) {
751           myElementsId += QString(" %1").arg(anElementsIds[i]);
752         }
753         aNbUnits = anElementsIds->length();
754       }
755     } else {
756       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
757       myElementsId = aString;
758     }
759
760     if (aNbUnits < 1)
761       return;
762
763     myNbOkElements = true;
764   } else {
765     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
766     if (aNbUnits != 1)
767       return;
768
769     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
770     if (!aMesh)
771       return;
772
773     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
774     if (!n)
775       return;
776
777     double x = n->X();
778     double y = n->Y();
779     double z = n->Z();
780
781     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
782       SpinBox_X->SetValue(x);
783       SpinBox_Y->SetValue(y);
784       SpinBox_Z->SetValue(z);
785     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
786       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
787       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
788       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
789     }
790   }
791
792   myBusy = true;
793   if (myEditCurrentArgument == (QWidget*)LineEditElements)
794     LineEditElements->setText(aString);
795   myBusy = false;
796
797   // OK
798   if (myNbOkElements && IsAxisOk()) {
799     buttonOk->setEnabled(true);
800     buttonApply->setEnabled(true);
801   }
802
803   onDisplaySimulation(true);
804 }
805
806 //=================================================================================
807 // function : SetEditCurrentArgument()
808 // purpose  :
809 //=================================================================================
810 void SMESHGUI_RevolutionDlg::SetEditCurrentArgument()
811 {
812   QPushButton* send = (QPushButton*)sender();
813
814   disconnect(mySelectionMgr, 0, this, 0);
815   mySelectionMgr->clearSelected();
816   mySelectionMgr->clearFilters();
817
818   if (send == SelectElementsButton) {
819     mySimulation->SetVisibility(false);
820     myEditCurrentArgument = (QWidget*)LineEditElements;
821     SMESH::SetPointRepresentation(false);
822     if (CheckBoxMesh->isChecked()) {
823       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
824         aViewWindow->SetSelectionMode(ActorSelection);
825       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
826     } else {
827       int aConstructorId = GetConstructorId();
828       if (aConstructorId == 0)
829         {
830           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
831             aViewWindow->SetSelectionMode(EdgeSelection);
832         }
833       else if (aConstructorId == 1)
834         {
835           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
836             aViewWindow->SetSelectionMode(FaceSelection);
837         }
838     }
839   } else if (send == SelectPointButton) {
840     myEditCurrentArgument = (QWidget*)SpinBox_X;
841     SMESH::SetPointRepresentation(true);
842     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
843       aViewWindow->SetSelectionMode(NodeSelection);
844   } else if (send == SelectVectorButton) {
845     myEditCurrentArgument = (QWidget*)SpinBox_DX;
846     SMESH::SetPointRepresentation(true);
847     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
848       aViewWindow->SetSelectionMode(NodeSelection);
849   } else {
850   }
851
852   myEditCurrentArgument->setFocus();
853   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
854   SelectionIntoArgument();
855 }
856
857 //=================================================================================
858 // function : DeactivateActiveDialog()
859 // purpose  :
860 //=================================================================================
861 void SMESHGUI_RevolutionDlg::DeactivateActiveDialog()
862 {
863   if (ConstructorsBox->isEnabled()) {
864     ConstructorsBox->setEnabled(false);
865     GroupArguments->setEnabled(false);
866     GroupButtons->setEnabled(false);
867     mySMESHGUI->ResetState();
868     mySMESHGUI->SetActiveDialogBox(0);
869   }
870 }
871
872 //=================================================================================
873 // function : ActivateThisDialog()
874 // purpose  :
875 //=================================================================================
876 void SMESHGUI_RevolutionDlg::ActivateThisDialog()
877 {
878   /* Emit a signal to deactivate the active dialog */
879   mySMESHGUI->EmitSignalDeactivateDialog();
880   ConstructorsBox->setEnabled(true);
881   GroupArguments->setEnabled(true);
882   GroupButtons->setEnabled(true);
883
884   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
885
886   ConstructorsClicked(GetConstructorId());
887   SelectionIntoArgument();
888 }
889
890 //=================================================================================
891 // function : enterEvent()
892 // purpose  :
893 //=================================================================================
894 void SMESHGUI_RevolutionDlg::enterEvent (QEvent*)
895 {
896   if (!ConstructorsBox->isEnabled())
897     ActivateThisDialog();
898 }
899
900 //=================================================================================
901 // function : closeEvent()
902 // purpose  :
903 //=================================================================================
904 void SMESHGUI_RevolutionDlg::closeEvent (QCloseEvent*)
905 {
906   /* same than click on cancel button */
907   ClickOnCancel();
908 }
909
910 //=======================================================================
911 // function : hideEvent()
912 // purpose  : caused by ESC key
913 //=======================================================================
914 void SMESHGUI_RevolutionDlg::hideEvent (QHideEvent*)
915 {
916   if (!isMinimized())
917     ClickOnCancel();
918 }
919
920 //=======================================================================
921 //function : onSelectMesh
922 //purpose  :
923 //=======================================================================
924 void SMESHGUI_RevolutionDlg::onSelectMesh (bool toSelectMesh)
925 {
926   if (toSelectMesh)
927     TextLabelElements->setText(tr("SMESH_NAME"));
928   else
929     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
930
931   if (myEditCurrentArgument != LineEditElements) {
932     LineEditElements->clear();
933     mySimulation->SetVisibility(false);
934     return;
935   }
936
937   mySelectionMgr->clearFilters();
938   SMESH::SetPointRepresentation(false);
939
940   if (toSelectMesh) {
941     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
942       aViewWindow->SetSelectionMode(ActorSelection);
943     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
944     LineEditElements->setReadOnly(true);
945     LineEditElements->setValidator(0);
946   } else {
947     int aConstructorId = GetConstructorId();
948     if (aConstructorId == 0)
949       {
950         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
951           aViewWindow->SetSelectionMode(EdgeSelection);
952       }
953     else if (aConstructorId == 0)
954       {
955         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
956           aViewWindow->SetSelectionMode(FaceSelection);
957       }
958
959     LineEditElements->setReadOnly(false);
960     LineEditElements->setValidator(myIdValidator);
961     onTextChange(LineEditElements->text());
962     mySimulation->SetVisibility(false);
963   }
964
965   SelectionIntoArgument();
966 }
967
968 //=================================================================================
969 // function : GetConstructorId()
970 // purpose  :
971 //=================================================================================
972 int SMESHGUI_RevolutionDlg::GetConstructorId()
973 {
974   return GroupConstructors->checkedId();
975 }
976
977 //=================================================================================
978 // function : IsAxisOk()
979 // purpose  :
980 //=================================================================================
981 bool SMESHGUI_RevolutionDlg::IsAxisOk()
982 {
983   return (SpinBox_DX->GetValue() != 0 ||
984           SpinBox_DY->GetValue() != 0 ||
985           SpinBox_DZ->GetValue() != 0);
986 }
987
988 //=================================================================================
989 // function : onVectorChanged()
990 // purpose  :
991 //=================================================================================
992 void SMESHGUI_RevolutionDlg::onVectorChanged()
993 {
994   if (IsAxisOk()) {
995     buttonOk->setEnabled(true);
996     buttonApply->setEnabled(true);
997   } else {
998     buttonOk->setEnabled(false);
999     buttonApply->setEnabled(false);
1000   }
1001   onDisplaySimulation(true);
1002 }
1003
1004 //=================================================================================
1005 // function : keyPressEvent()
1006 // purpose  :
1007 //=================================================================================
1008 void SMESHGUI_RevolutionDlg::keyPressEvent( QKeyEvent* e )
1009 {
1010   QDialog::keyPressEvent( e );
1011   if ( e->isAccepted() )
1012     return;
1013
1014   if ( e->key() == Qt::Key_F1 ) {
1015     e->accept();
1016     ClickOnHelp();
1017   }
1018 }
1019
1020 //=================================================================================
1021 // function : toDisplaySimulation()
1022 // purpose  :
1023 //=================================================================================
1024 void SMESHGUI_RevolutionDlg::toDisplaySimulation()
1025 {
1026   onDisplaySimulation(true);
1027 }
1028
1029 //=================================================================================
1030 // function : onDisplaySimulation()
1031 // purpose  :
1032 //=================================================================================
1033 void SMESHGUI_RevolutionDlg::onDisplaySimulation(bool toDisplayPreview)
1034 {
1035   if (CheckBoxPreview->isChecked() && toDisplayPreview)
1036   {
1037     //display preview
1038     if (myNbOkElements && IsAxisOk())
1039     {
1040       QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1041       
1042       SMESH::long_array_var anElementsId = new SMESH::long_array;
1043       
1044       anElementsId->length(aListElementsId.count());
1045       for (int i = 0; i < aListElementsId.count(); i++)
1046         anElementsId[i] = aListElementsId[i].toInt();
1047       
1048       SMESH::AxisStruct anAxis;
1049       
1050       anAxis.x =  SpinBox_X->GetValue();
1051       anAxis.y =  SpinBox_Y->GetValue();
1052       anAxis.z =  SpinBox_Z->GetValue();
1053       anAxis.vx = SpinBox_DX->GetValue();
1054       anAxis.vy = SpinBox_DY->GetValue();
1055       anAxis.vz = SpinBox_DZ->GetValue();
1056       
1057       double anAngle = (SpinBox_Angle->GetValue())*PI/180;
1058       long aNbSteps = (long)SpinBox_NbSteps->value();
1059       double aTolerance = SpinBox_Tolerance->GetValue();
1060       
1061       if (GroupAngle->checkedId() == 1)
1062         anAngle = anAngle/aNbSteps;
1063       
1064       try {
1065         SUIT_OverrideCursor aWaitCursor;
1066         SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1067         aMeshEditor->RotationSweep(anElementsId.inout(), 
1068                                    anAxis, 
1069                                    anAngle, 
1070                                    aNbSteps, 
1071                                    aTolerance);
1072         SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1073         mySimulation->SetData(aMeshPreviewStruct._retn());
1074       } catch (...) {}
1075     }
1076     else
1077     {
1078       mySimulation->SetVisibility(false);
1079     }
1080   }
1081   else
1082   {
1083     //erase preview
1084     mySimulation->SetVisibility(false);
1085   }
1086 }
1087
1088
1089 //=================================================================================
1090 // function : isValid
1091 // purpose  :
1092 //=================================================================================
1093 bool SMESHGUI_RevolutionDlg::isValid()
1094 {
1095   QString msg;
1096   bool ok = true;
1097   ok = SpinBox_X->isValid( msg, true ) && ok;
1098   ok = SpinBox_Y->isValid( msg, true ) && ok;
1099   ok = SpinBox_Z->isValid( msg, true ) && ok;
1100   ok = SpinBox_DX->isValid( msg, true ) && ok;
1101   ok = SpinBox_DY->isValid( msg, true ) && ok;
1102   ok = SpinBox_DZ->isValid( msg, true ) && ok;
1103   ok = SpinBox_Angle->isValid( msg, true ) && ok;
1104   ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
1105   ok = SpinBox_Tolerance->isValid( msg, true ) && ok;
1106
1107   if( !ok ) {
1108     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1109     if ( !msg.isEmpty() )
1110       str += "\n" + msg;
1111     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1112     return false;
1113   }
1114   return true;
1115 }