Salome HOME
Merge branch 'V9_9_BR'
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_RevolutionDlg.cxx
1 // Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_RevolutionDlg.cxx
25 // Author : Michael ZORIN, Open CASCADE S.A.S.
26 // SMESH includes
27
28 #include "SMESHGUI_RevolutionDlg.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_SpinBox.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_IdValidator.h"
36 #include "SMESHGUI_MeshEditPreview.h"
37 #include "SMESHGUI_FilterDlg.h"
38 #include "SMESHGUI_ExtrusionDlg.h"
39
40 #include <SMESH_Actor.h>
41 #include <SMESH_TypeFilter.hxx>
42 #include <SMESH_LogicalFilter.hxx>
43 #include <SMDS_Mesh.hxx>
44
45 // SALOME GUI includes
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_Session.h>
48 #include <SUIT_MessageBox.h>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_OverrideCursor.h>
51
52 #include <LightApp_Application.h>
53 #include <LightApp_SelectionMgr.h>
54 #include <SalomeApp_Application.h>
55 #include <SalomeApp_IntSpinBox.h>
56
57 #include <SVTK_ViewWindow.h>
58 #include <SVTK_Selector.h>
59 #include <SALOME_ListIO.hxx>
60 //#include <VTKViewer_CellLocationsArray.h>
61
62 // OCCT includes
63 #include <TColStd_MapOfInteger.hxx>
64
65 // Qt includes
66 #include <QApplication>
67 #include <QButtonGroup>
68 #include <QGroupBox>
69 #include <QLabel>
70 #include <QLineEdit>
71 #include <QPushButton>
72 #include <QRadioButton>
73 #include <QCheckBox>
74 #include <QHBoxLayout>
75 #include <QVBoxLayout>
76 #include <QGridLayout>
77 #include <QKeyEvent>
78 #include <QMenu>
79
80 // IDL includes
81 #include <SALOMEconfig.h>
82 #include CORBA_SERVER_HEADER(SMESH_Group)
83 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
84
85 #define SPACING 6
86 #define MARGIN  11
87
88 //=================================================================================
89 // class    : SMESHGUI_RevolutionDlg()
90 // purpose  :
91 //=================================================================================
92 SMESHGUI_RevolutionDlg::SMESHGUI_RevolutionDlg( SMESHGUI* theModule )
93   : SMESHGUI_PreviewDlg( theModule ),
94     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
95     myVectorDefinition(NONE_SELECT)
96 {
97   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
98   QPixmap image ( 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   GroupArguments = new QGroupBox(tr("REVOLUTION"), this);
111   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
112   GroupArgumentsLayout->setSpacing(SPACING);
113   GroupArgumentsLayout->setMargin(MARGIN);
114
115   // Controls for elements selection
116   SelectorWdg = new SMESHGUI_3TypesSelector( GroupArguments );
117
118   // Controls for axis defining
119   GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
120   QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
121   GroupAxisLayout->setSpacing(SPACING);
122   GroupAxisLayout->setMargin(MARGIN);
123
124   TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
125   SelectPointButton  = new QPushButton(GroupAxis);
126   SelectPointButton->setIcon(image);
127   SelectPointButton->setCheckable(true);
128
129   TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
130   SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
131
132   TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
133   SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
134
135   TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
136   SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
137
138   TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
139   SelectVectorButton = new QPushButton(GroupAxis);
140   SelectVectorButton->setIcon(image);
141   SelectVectorButton->setCheckable(true);
142
143   TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
144   SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
145
146   TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
147   SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
148
149   TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
150   SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
151
152   GroupAxisLayout->addWidget(TextLabelPoint,     0, 0);
153   GroupAxisLayout->addWidget(SelectPointButton,  0, 1);
154   GroupAxisLayout->addWidget(TextLabelX,         0, 2);
155   GroupAxisLayout->addWidget(SpinBox_X,          0, 3);
156   GroupAxisLayout->addWidget(TextLabelY,         0, 4);
157   GroupAxisLayout->addWidget(SpinBox_Y,          0, 5);
158   GroupAxisLayout->addWidget(TextLabelZ,         0, 6);
159   GroupAxisLayout->addWidget(SpinBox_Z,          0, 7);
160   GroupAxisLayout->addWidget(TextLabelVector,    1, 0);
161   GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
162   GroupAxisLayout->addWidget(TextLabelDX,        1, 2);
163   GroupAxisLayout->addWidget(SpinBox_DX,         1, 3);
164   GroupAxisLayout->addWidget(TextLabelDY,        1, 4);
165   GroupAxisLayout->addWidget(SpinBox_DY,         1, 5);
166   GroupAxisLayout->addWidget(TextLabelDZ,        1, 6);
167   GroupAxisLayout->addWidget(SpinBox_DZ,         1, 7);
168
169   // Controls for angle defining & number of steps defining
170   GroupAngleBox = new QGroupBox(tr("SMESH_ANGLE"), GroupArguments);
171   GroupAngle = new QButtonGroup(GroupAngleBox);
172   QGridLayout* GroupAngleLayout = new QGridLayout(GroupAngleBox);
173   GroupAngleLayout->setSpacing(6);
174   GroupAngleLayout->setMargin(11);
175
176   RadioButton3 = new QRadioButton(tr("ANGLE_BY_STEP"), GroupAngleBox);
177   RadioButton4 = new QRadioButton(tr("TOTAL_ANGLE"),   GroupAngleBox);
178   GroupAngle->addButton(RadioButton3, 0);
179   GroupAngle->addButton(RadioButton4, 1);
180
181   TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupAngleBox);
182   SpinBox_Angle = new SMESHGUI_SpinBox(GroupAngleBox);
183
184   TextLabelNbSteps = new QLabel(tr("SMESH_NUMBEROFSTEPS"), GroupAngleBox);
185   SpinBox_NbSteps = new SalomeApp_IntSpinBox(GroupAngleBox);
186
187   GroupAngleLayout->addWidget(RadioButton3,     0, 0);
188   GroupAngleLayout->addWidget(RadioButton4,     0, 1);
189   GroupAngleLayout->addWidget(TextLabelAngle,   1, 0);
190   GroupAngleLayout->addWidget(SpinBox_Angle,    1, 1);
191   GroupAngleLayout->addWidget(TextLabelNbSteps, 2, 0);
192   GroupAngleLayout->addWidget(SpinBox_NbSteps,  2, 1);
193
194   // Controls for tolerance defining
195   TextLabelTolerance = new QLabel(tr("SMESH_TOLERANCE"), GroupArguments);
196   SpinBox_Tolerance = new SMESHGUI_SpinBox(GroupArguments);
197
198   // Control for mesh preview
199   myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
200
201   // CheckBox for groups generation
202   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
203   MakeGroupsCheck->setChecked(true);
204
205   GroupArgumentsLayout->addWidget(SelectorWdg,          0, 0, 3, 4);
206   GroupArgumentsLayout->addWidget(GroupAxis,            0, 4, 1, 4);
207   GroupArgumentsLayout->addWidget(GroupAngleBox,        1, 4, 1, 4);
208   GroupArgumentsLayout->addWidget(TextLabelTolerance,   2, 4, 1, 2);
209   GroupArgumentsLayout->addWidget(SpinBox_Tolerance,    2, 6, 1, 2);
210   GroupArgumentsLayout->addWidget(myPreviewCheckBox,    3, 0, 1, 2);
211   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      3, 2, 1, 2);
212   SelectorWdg->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
213   SelectorWdg->setMinimumWidth(320);
214
215   SelectorWdg->GetButtonGroup()->addButton( SelectVectorButton );
216   SelectorWdg->GetButtonGroup()->addButton( SelectPointButton );
217
218   /***************************************************************/
219   GroupButtons = new QGroupBox(this);
220   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
221   GroupButtonsLayout->setSpacing(SPACING);
222   GroupButtonsLayout->setMargin(MARGIN);
223   
224   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
225   buttonOk->setAutoDefault(true);
226   buttonOk->setDefault(true);
227   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
228   buttonApply->setAutoDefault(true);
229   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
230   buttonCancel->setAutoDefault(true);
231   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
232   buttonHelp->setAutoDefault(true);
233
234   GroupButtonsLayout->addWidget(buttonOk);
235   GroupButtonsLayout->addSpacing(10);
236   GroupButtonsLayout->addWidget(buttonApply);
237   GroupButtonsLayout->addSpacing(10);
238   GroupButtonsLayout->addStretch();
239   GroupButtonsLayout->addWidget(buttonCancel);
240   GroupButtonsLayout->addWidget(buttonHelp);
241
242   /***************************************************************/
243   SMESHGUI_RevolutionDlgLayout->addWidget(GroupArguments);
244   SMESHGUI_RevolutionDlgLayout->addWidget(GroupButtons);
245
246   /* Initialisations */
247   SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
248   SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
249   SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
250   SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
251   SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
252   SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
253
254   RadioButton3->setChecked(true);
255
256   SpinBox_Angle->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5.0, "angle_precision");
257
258   SpinBox_NbSteps->setRange(1, 999999);
259
260   SpinBox_Tolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, "len_tol_precision");
261
262   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
263
264   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
265
266   myHelpFileName = "revolution.html";
267
268   Init();
269
270   /*Create menu to vector selection*/
271   SelectVectorMenu = new QMenu(this);
272   myMenuActions[SelectVectorMenu->addAction( tr( "MEN_POINT_SELECT" ) )] = POINT_SELECT;
273   myMenuActions[SelectVectorMenu->addAction( tr( "MEN_FACE_SELECT" ) )] = FACE_SELECT;
274   connect( SelectVectorMenu, SIGNAL( triggered( QAction* ) ), SLOT( onSelectVectorMenu( QAction* ) ) );
275
276   /* signals and slots connections */
277   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
278   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
279   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
280   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
281
282   connect(SelectPointButton,    SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
283   connect(SelectVectorButton,   SIGNAL(clicked()), this, SLOT(onSelectVectorButton()));
284
285   connect(SpinBox_X,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
286   connect(SpinBox_Y,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
287   connect(SpinBox_Z,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
288
289   connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(CheckIsEnable()));
290   connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(CheckIsEnable()));
291   connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(CheckIsEnable()));
292   connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
293   connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
294   connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
295
296   connect(mySMESHGUI,     SIGNAL(SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
297   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),      SLOT(SelectionIntoArgument()));
298   connect(SelectorWdg,    SIGNAL(selectionChanged()), this, SLOT(toDisplaySimulation()));
299   connect(SelectorWdg,    SIGNAL(selectionChanged()), this, SLOT(CheckIsEnable()));
300   /* to close dialog if study change */
301   connect(mySMESHGUI,       SIGNAL(SignalCloseAllDialogs()),      this, SLOT(reject()));
302   connect(mySMESHGUI,       SIGNAL(SignalActivatedViewManager()), this, SLOT(onOpenView()));
303   connect(mySMESHGUI,       SIGNAL(SignalCloseView()),            this, SLOT(onCloseView()));
304
305   connect(GroupAngle,        SIGNAL(buttonClicked(int)),   this, SLOT(toDisplaySimulation()));
306   connect(SpinBox_Angle,     SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
307   connect(SpinBox_NbSteps,   SIGNAL(valueChanged(int)),    this, SLOT(toDisplaySimulation()));
308   connect(SpinBox_Tolerance, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
309
310   //To Connect preview check box
311   connectPreviewControl();
312
313   connect(SpinBox_Angle, SIGNAL(textChanged(const QString&)), this, SLOT(onAngleTextChange(const QString&)));
314
315   CheckIsEnable();
316 }
317
318 //=================================================================================
319 // function : ~SMESHGUI_RevolutionDlg()
320 // purpose  : Destroys the object and frees any allocated resources
321 //=================================================================================
322 SMESHGUI_RevolutionDlg::~SMESHGUI_RevolutionDlg()
323 {
324 }
325
326 //=================================================================================
327 // function : Init()
328 // purpose  :
329 //=================================================================================
330 void SMESHGUI_RevolutionDlg::Init (bool ResetControls)
331 {
332   if (ResetControls) {
333     SpinBox_X->SetValue(0.0);
334     SpinBox_Y->SetValue(0.0);
335     SpinBox_Z->SetValue(0.0);
336     SpinBox_DX->SetValue(0.0);
337     SpinBox_DY->SetValue(0.0);
338     SpinBox_DZ->SetValue(0.0);
339
340     SpinBox_Angle->SetValue(45);
341     SpinBox_NbSteps->setValue(1);
342     SpinBox_Tolerance->SetValue(1e-05);
343
344     myPreviewCheckBox->setChecked(false);
345     onDisplaySimulation(false);
346   }
347   SelectorWdg->Clear();
348 }
349
350 //=================================================================================
351 // function : CheckIsEnable()
352 // purpose  : Check whether the Ok and Apply buttons should be enabled or not
353 //=================================================================================
354
355 void SMESHGUI_RevolutionDlg::CheckIsEnable()
356 {  
357   bool anIsEnable = SelectorWdg->IsAnythingSelected() && IsAxisOk();
358
359   buttonOk->setEnabled(anIsEnable);
360   buttonApply->setEnabled(anIsEnable);
361 }
362
363 //=================================================================================
364 // function : isValid
365 // purpose  : Return true in case if values entered into dialog are valid
366 //=================================================================================
367 bool SMESHGUI_RevolutionDlg::isValid()
368 {
369   QString msg;
370   bool ok = true;
371   ok = SpinBox_X->isValid( msg, true ) && ok;
372   ok = SpinBox_Y->isValid( msg, true ) && ok;
373   ok = SpinBox_Z->isValid( msg, true ) && ok;
374   ok = SpinBox_DX->isValid( msg, true ) && ok;
375   ok = SpinBox_DY->isValid( msg, true ) && ok;
376   ok = SpinBox_DZ->isValid( msg, true ) && ok;
377   ok = SpinBox_Angle->isValid( msg, true ) && ok;
378   ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
379   ok = SpinBox_Tolerance->isValid( msg, true ) && ok;
380
381   if( !ok ) {
382     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
383     if ( !msg.isEmpty() )
384       str += "\n" + msg;
385     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
386     return false;
387   }
388   return true;
389 }
390
391 //=================================================================================
392 // function : ClickOnApply()
393 // purpose  :
394 //=================================================================================
395 bool SMESHGUI_RevolutionDlg::ClickOnApply()
396 {
397   if (SMESHGUI::isStudyLocked())
398     return false;
399
400   if (!isValid())
401     return false;
402
403   if ( SelectorWdg->IsAnythingSelected() && IsAxisOk() ) {
404
405     SMESH::AxisStruct anAxis;
406
407     anAxis.x =  SpinBox_X->GetValue();
408     anAxis.y =  SpinBox_Y->GetValue();
409     anAxis.z =  SpinBox_Z->GetValue();;
410     anAxis.vx = SpinBox_DX->GetValue();
411     anAxis.vy = SpinBox_DY->GetValue();
412     anAxis.vz = SpinBox_DZ->GetValue();
413
414     double    anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
415     long     aNbSteps = (long)SpinBox_NbSteps->value();
416     double aTolerance = SpinBox_Tolerance->GetValue();
417
418     if ( GroupAngle->checkedId() == 1 )
419       anAngle = anAngle/aNbSteps;
420
421     QStringList aParameters;
422     aParameters << SpinBox_X->text();
423     aParameters << SpinBox_Y->text();
424     aParameters << SpinBox_Z->text();
425     aParameters << SpinBox_DX->text();
426     aParameters << SpinBox_DY->text();
427     aParameters << SpinBox_DZ->text();
428     aParameters << SpinBox_Angle->text();
429     aParameters << SpinBox_NbSteps->text();
430     aParameters << SpinBox_Tolerance->text();
431
432     bool meshHadNewTypeBefore = true;
433     int  maxSelType = 0;
434     const bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
435
436     try {
437       SUIT_OverrideCursor aWaitCursor;
438
439       SMESH::SMESH_Mesh_var mesh = SelectorWdg->GetMesh();
440
441       mesh->SetParameters( aParameters.join(":").toUtf8().constData() );
442
443       SMESH::ListOfIDSources_var nodes = new SMESH::ListOfIDSources();
444       SMESH::ListOfIDSources_var edges = new SMESH::ListOfIDSources();
445       SMESH::ListOfIDSources_var faces = new SMESH::ListOfIDSources();
446       maxSelType = SelectorWdg->GetSelected( nodes, edges, faces );
447
448       // is it necessary to switch on the next Display Mode?
449       SMESH::ElementType newType = (SMESH::ElementType)( maxSelType + 1 );
450       SMESH::array_of_ElementType_var oldTypes = mesh->GetTypes();
451       meshHadNewTypeBefore = false;
452       for ( size_t i = 0; i < oldTypes->length() && !meshHadNewTypeBefore; ++i )
453         meshHadNewTypeBefore = ( oldTypes[i] >= newType );
454
455       SMESH::SMESH_MeshEditor_var aMeshEditor = mesh->GetMeshEditor();
456
457       SMESH::ListOfGroups_var groups = 
458         aMeshEditor->RotationSweepObjects( nodes, edges, faces, anAxis,
459                                            anAngle, aNbSteps, aTolerance, makeGroups);
460
461     } catch (...) {
462     }
463
464     SMESH_Actor* actor = SelectorWdg->GetActor();
465     if ( actor && !meshHadNewTypeBefore )
466     {
467       unsigned int aMode = actor->GetEntityMode();
468       switch ( maxSelType ) {
469       case SMESH::NODE: // extrude node -> edges
470         actor->SetRepresentation(SMESH_Actor::eEdge);
471         actor->SetEntityMode( aMode |= SMESH_Actor::eEdges ); break;
472       case SMESH::EDGE: // edge -> faces
473         actor->SetRepresentation(SMESH_Actor::eSurface);
474         actor->SetEntityMode( aMode |= SMESH_Actor::eFaces ); break;
475       case SMESH::FACE: // faces -> volumes
476         actor->SetRepresentation(SMESH_Actor::eSurface);
477         actor->SetEntityMode( aMode |= SMESH_Actor::eVolumes ); break;
478       }
479     }
480     if ( actor )
481       SMESH::Update( actor->getIO(), actor->GetVisibility() );
482     if ( makeGroups )
483       mySMESHGUI->updateObjBrowser(true); // new groups may appear
484     Init(false);
485     mySelectionMgr->clearSelected();
486     SelectorWdg->Clear();
487
488     SMESHGUI::Modified();
489   }
490
491   return true;
492 }
493
494 //=================================================================================
495 // function : ClickOnOk()
496 // purpose  :
497 //=================================================================================
498 void SMESHGUI_RevolutionDlg::ClickOnOk()
499 {
500   if( ClickOnApply() )
501     reject();
502 }
503
504 //=================================================================================
505 // function : reject()
506 // purpose  :
507 //=================================================================================
508 void SMESHGUI_RevolutionDlg::reject()
509 {
510   disconnect(mySelectionMgr, 0, this, 0);
511   mySelectionMgr->clearFilters();
512   //mySelectionMgr->clearSelected();
513   if (SMESH::GetCurrentVtkView()) {
514     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
515     SMESH::SetPointRepresentation(false);
516   }
517   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
518     aViewWindow->SetSelectionMode(ActorSelection);
519   mySMESHGUI->ResetState();
520
521   QDialog::reject();
522 }
523
524 //=================================================================================
525 // function : onOpenView()
526 // purpose  :
527 //=================================================================================
528 void SMESHGUI_RevolutionDlg::onOpenView()
529 {
530   if ( mySelector ) {
531     mySimulation->SetVisibility(false);
532     SMESH::SetPointRepresentation(false);
533   }
534   else {
535     mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
536     ActivateThisDialog();
537   }
538 }
539
540 //=================================================================================
541 // function : onCloseView()
542 // purpose  :
543 //=================================================================================
544 void SMESHGUI_RevolutionDlg::onCloseView()
545 {
546   DeactivateActiveDialog();
547   mySelector = 0;
548 }
549
550 //=================================================================================
551 // function : ClickOnHelp()
552 // purpose  :
553 //=================================================================================
554 void SMESHGUI_RevolutionDlg::ClickOnHelp()
555 {
556   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
557   if (app) 
558     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
559   else {
560     QString platform;
561 #ifdef WIN32
562     platform = "winapplication";
563 #else
564     platform = "application";
565 #endif
566     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
567                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
568                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
569                                                                  platform)).
570                              arg(myHelpFileName));
571   }
572 }
573
574 //=======================================================================
575 // function : onAngleTextChange()
576 // purpose  :
577 //=======================================================================
578 void SMESHGUI_RevolutionDlg::onAngleTextChange (const QString& /*theNewText*/)
579 {
580   bool isNumber;
581   SpinBox_Angle->text().toDouble( &isNumber );
582   if( !isNumber )
583     RadioButton3->setChecked( true );
584   RadioButton4->setEnabled( isNumber );
585 }
586
587 //=================================================================================
588 // function : SelectionIntoArgument()
589 // purpose  : Called when selection as changed or other case
590 //=================================================================================
591 void SMESHGUI_RevolutionDlg::SelectionIntoArgument()
592 {
593   if (!GroupButtons->isEnabled()) // inactive
594     return;
595   
596   if ( SelectVectorButton->isChecked() ||
597        SelectPointButton->isChecked() )
598   {
599     // get selected mesh
600     SALOME_ListIO aList;
601     mySelectionMgr->selectedObjects(aList);
602     int nbSel = aList.Extent();
603     if (nbSel != 1)
604       return;
605
606     Handle(SALOME_InteractiveObject) IO = aList.First();
607     SVTK_TIndexedMapOfVtkId aMapIndex;
608     mySelector->GetIndex(IO,aMapIndex);
609     if ( aMapIndex.Extent() != 1 )
610       return;
611
612     SMESH_Actor* anActor = SMESH::FindActorByEntry( IO->getEntry() );
613     SMDS_Mesh*     aMesh = anActor ? anActor->GetObject()->GetMesh() : 0;
614     if ( !aMesh )
615       return;
616
617     bool isNodeSelected = ((myEditCurrentArgument == (QWidget*)SpinBox_X ) ||
618                            (myEditCurrentArgument == (QWidget*)SpinBox_DX &&
619                             myVectorDefinition==POINT_SELECT));
620
621     bool isFaceSelected = (myEditCurrentArgument == (QWidget*)SpinBox_DX &&
622                            myVectorDefinition==FACE_SELECT);
623
624     if ( isNodeSelected )
625     {
626       const SMDS_MeshNode * n = aMesh->FindNode( aMapIndex(1) );
627       if (!n)
628         return;
629       double x = n->X();
630       double y = n->Y();
631       double z = n->Z();
632
633       if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
634         SpinBox_X->SetValue(x);
635         SpinBox_Y->SetValue(y);
636         SpinBox_Z->SetValue(z);
637       } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
638         SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
639         SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
640         SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
641       }
642     }
643     else if ( isFaceSelected )
644     {
645       const SMDS_MeshFace* face =
646         SMDS_Mesh::DownCast<SMDS_MeshFace>( aMesh->FindElement( aMapIndex( 1 )));
647       if (!face)
648         return;
649       gp_XYZ aNormale = SMESH::getNormale(face);
650       SpinBox_DX->SetValue(aNormale.X());
651       SpinBox_DY->SetValue(aNormale.Y());
652       SpinBox_DZ->SetValue(aNormale.Z());
653
654     }
655   }
656
657   CheckIsEnable();
658   onDisplaySimulation(true);
659 }
660
661 //=================================================================================
662 // function : SetEditCurrentArgument()
663 // purpose  :
664 //=================================================================================
665 void SMESHGUI_RevolutionDlg::SetEditCurrentArgument()
666 {
667   QPushButton* send = (QPushButton*)sender();
668
669   disconnect(mySelectionMgr, 0, this, 0);
670   mySelectionMgr->clearSelected();
671   mySelectionMgr->clearFilters();
672
673   if (send == SelectPointButton) {
674     myEditCurrentArgument = (QWidget*)SpinBox_X;
675     myEditCurrentArgument->setFocus();
676     SMESH::SetPointRepresentation(true);
677     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
678       aViewWindow->SetSelectionMode(NodeSelection);
679   }
680   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
681   SelectionIntoArgument();
682 }
683
684 //=================================================================================
685 // function : DeactivateActiveDialog()
686 // purpose  :
687 //=================================================================================
688 void SMESHGUI_RevolutionDlg::DeactivateActiveDialog()
689 {
690   if (GroupButtons->isEnabled())
691   {
692     GroupArguments->setEnabled(false);
693     GroupButtons->setEnabled(false);
694     SelectorWdg->setEnabled(false);
695     mySMESHGUI->ResetState();
696     mySMESHGUI->SetActiveDialogBox(0);
697   }
698 }
699
700 //=================================================================================
701 // function : ActivateThisDialog()
702 // purpose  :
703 //=================================================================================
704 void SMESHGUI_RevolutionDlg::ActivateThisDialog()
705 {
706   /* Emit a signal to deactivate the active dialog */
707   mySMESHGUI->EmitSignalDeactivateDialog();
708   GroupArguments->setEnabled(true);
709   GroupButtons->setEnabled(true);
710   SelectorWdg->setEnabled(true);
711
712   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
713 }
714
715 //=================================================================================
716 // function : enterEvent()
717 // purpose  :
718 //=================================================================================
719 void SMESHGUI_RevolutionDlg::enterEvent (QEvent*)
720 {
721   if (!GroupButtons->isEnabled()) {
722     SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
723     if ( aViewWindow && !mySelector) {
724       mySelector = aViewWindow->GetSelector();
725     }
726     ActivateThisDialog();
727   }
728 }
729
730 //=================================================================================
731 // function : IsAxisOk()
732 // purpose  :
733 //=================================================================================
734 bool SMESHGUI_RevolutionDlg::IsAxisOk()
735 {
736   return (SpinBox_DX->GetValue() != 0 ||
737           SpinBox_DY->GetValue() != 0 ||
738           SpinBox_DZ->GetValue() != 0);
739 }
740
741 //=================================================================================
742 // function : keyPressEvent()
743 // purpose  :
744 //=================================================================================
745 void SMESHGUI_RevolutionDlg::keyPressEvent( QKeyEvent* e )
746 {
747   QDialog::keyPressEvent( e );
748   if ( e->isAccepted() )
749     return;
750
751   if ( e->key() == Qt::Key_F1 ) {
752     e->accept();
753     ClickOnHelp();
754   }
755 }
756
757 //=================================================================================
758 // function : onDisplaySimulation()
759 // purpose  : Show/Hide preview
760 //=================================================================================
761 void SMESHGUI_RevolutionDlg::onDisplaySimulation(bool toDisplayPreview)
762 {
763   if (myPreviewCheckBox->isChecked() && toDisplayPreview)
764   {
765     if (SelectorWdg->IsAnythingSelected() && IsAxisOk())
766     {
767       SMESH::AxisStruct anAxis;
768       
769       anAxis.x =  SpinBox_X->GetValue();
770       anAxis.y =  SpinBox_Y->GetValue();
771       anAxis.z =  SpinBox_Z->GetValue();
772       anAxis.vx = SpinBox_DX->GetValue();
773       anAxis.vy = SpinBox_DY->GetValue();
774       anAxis.vz = SpinBox_DZ->GetValue();
775
776       double    anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
777       long     aNbSteps = (long)SpinBox_NbSteps->value();
778       double aTolerance = SpinBox_Tolerance->GetValue();
779       
780       if (GroupAngle->checkedId() == 1)
781         anAngle = anAngle/aNbSteps;
782       
783       try
784       {
785         SUIT_OverrideCursor aWaitCursor;
786
787         SMESH::SMESH_Mesh_var             mesh = SelectorWdg->GetMesh();
788         SMESH::SMESH_MeshEditor_var meshEditor = mesh->GetMeshEditPreviewer();
789         SMESH::ListOfGroups_var         groups;
790
791         SMESH::ListOfIDSources_var nodes = new SMESH::ListOfIDSources();
792         SMESH::ListOfIDSources_var edges = new SMESH::ListOfIDSources();
793         SMESH::ListOfIDSources_var faces = new SMESH::ListOfIDSources();
794         SelectorWdg->GetSelected( nodes, edges, faces );
795         const bool makeGroups = false;
796
797         meshEditor->RotationSweepObjects(nodes, edges, faces, 
798                                          anAxis, anAngle, aNbSteps, aTolerance, makeGroups );
799
800         SMESH::MeshPreviewStruct_var aMeshPreviewStruct = meshEditor->GetPreviewData();
801         mySimulation->SetData( aMeshPreviewStruct.in() );
802       }
803       catch (...) {}
804     }
805     else
806     {
807       mySimulation->SetVisibility(false);
808     }
809   }
810   else
811   {
812     //erase preview
813     mySimulation->SetVisibility(false);
814   }
815 }
816
817 //=================================================================================
818 // function : onSelectVectorButton()
819 // purpose  : [slot]
820 //=================================================================================
821 void SMESHGUI_RevolutionDlg::onSelectVectorButton()
822 {
823   if(SelectVectorMenu) {
824     SelectVectorMenu->exec( QCursor::pos() );
825   }
826 }
827
828 //=================================================================================
829 // function : onSelectVectorMenu()
830 // purpose  : [slot]
831 //=================================================================================
832 void SMESHGUI_RevolutionDlg::onSelectVectorMenu( QAction* action)
833 {
834   if(!action)
835     return;
836
837   disconnect(mySelectionMgr, 0, this, 0);
838
839   switch(myMenuActions[action]) {
840   case POINT_SELECT: 
841     SMESH::SetPointRepresentation(true);
842     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
843       aViewWindow->SetSelectionMode(NodeSelection);
844     break;
845     
846   case FACE_SELECT: 
847     SMESH::SetPointRepresentation(false);
848     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
849       aViewWindow->SetSelectionMode(FaceSelection);
850     break;
851   }
852
853   myVectorDefinition = myMenuActions[action];
854   myEditCurrentArgument = (QWidget*)SpinBox_DX;
855   myEditCurrentArgument->setFocus();
856   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
857   SelectionIntoArgument();
858 }
859
860