Salome HOME
Merge remote branch 'origin/V8_5_asterstudy'
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_RevolutionDlg.cxx
1 // Copyright (C) 2007-2016  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, 1, 4);
206   GroupArgumentsLayout->addWidget(GroupAxis,            1, 0, 1, 4);
207   GroupArgumentsLayout->addWidget(GroupAngleBox,        2, 0, 1, 4);
208   GroupArgumentsLayout->addWidget(TextLabelTolerance,   3, 0, 1, 2);
209   GroupArgumentsLayout->addWidget(SpinBox_Tolerance,    3, 2, 1, 2);
210   GroupArgumentsLayout->addWidget(myPreviewCheckBox,    4, 0, 1, 4);
211   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      5, 0, 1, 4);
212
213   SelectorWdg->GetButtonGroup()->addButton( SelectVectorButton );
214   SelectorWdg->GetButtonGroup()->addButton( SelectPointButton );
215
216   /***************************************************************/
217   GroupButtons = new QGroupBox(this);
218   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
219   GroupButtonsLayout->setSpacing(SPACING);
220   GroupButtonsLayout->setMargin(MARGIN);
221   
222   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
223   buttonOk->setAutoDefault(true);
224   buttonOk->setDefault(true);
225   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
226   buttonApply->setAutoDefault(true);
227   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
228   buttonCancel->setAutoDefault(true);
229   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
230   buttonHelp->setAutoDefault(true);
231
232   GroupButtonsLayout->addWidget(buttonOk);
233   GroupButtonsLayout->addSpacing(10);
234   GroupButtonsLayout->addWidget(buttonApply);
235   GroupButtonsLayout->addSpacing(10);
236   GroupButtonsLayout->addStretch();
237   GroupButtonsLayout->addWidget(buttonCancel);
238   GroupButtonsLayout->addWidget(buttonHelp);
239
240   /***************************************************************/
241   SMESHGUI_RevolutionDlgLayout->addWidget(GroupArguments);
242   SMESHGUI_RevolutionDlgLayout->addWidget(GroupButtons);
243
244   /* Initialisations */
245   SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
246   SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
247   SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
248   SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
249   SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
250   SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
251
252   RadioButton3->setChecked(true);
253
254   SpinBox_Angle->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5.0, "angle_precision");
255
256   SpinBox_NbSteps->setRange(1, 999999);
257
258   SpinBox_Tolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, "len_tol_precision");
259
260   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
261
262   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
263
264   myHelpFileName = "revolution.html";
265
266   Init();
267
268   /*Create menu to vector selection*/
269   SelectVectorMenu = new QMenu(this);
270   myMenuActions[SelectVectorMenu->addAction( tr( "MEN_POINT_SELECT" ) )] = POINT_SELECT;
271   myMenuActions[SelectVectorMenu->addAction( tr( "MEN_FACE_SELECT" ) )] = FACE_SELECT;
272   connect( SelectVectorMenu, SIGNAL( triggered( QAction* ) ), SLOT( onSelectVectorMenu( QAction* ) ) );
273
274   /* signals and slots connections */
275   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(ClickOnOk()));
276   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
277   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(ClickOnApply()));
278   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
279
280   connect(SelectPointButton,    SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
281   connect(SelectVectorButton,   SIGNAL(clicked()), this, SLOT(onSelectVectorButton()));
282
283   connect(SpinBox_X,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
284   connect(SpinBox_Y,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
285   connect(SpinBox_Z,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
286
287   connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(CheckIsEnable()));
288   connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(CheckIsEnable()));
289   connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(CheckIsEnable()));
290   connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
291   connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
292   connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
293
294   connect(mySMESHGUI,     SIGNAL(SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
295   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),      SLOT(SelectionIntoArgument()));
296   connect(SelectorWdg,    SIGNAL(selectionChanged()), this, SLOT(toDisplaySimulation()));
297   connect(SelectorWdg,    SIGNAL(selectionChanged()), this, SLOT(CheckIsEnable()));
298   /* to close dialog if study change */
299   connect(mySMESHGUI,       SIGNAL(SignalCloseAllDialogs()),      this, SLOT(reject()));
300   connect(mySMESHGUI,       SIGNAL(SignalActivatedViewManager()), this, SLOT(onOpenView()));
301   connect(mySMESHGUI,       SIGNAL(SignalCloseView()),            this, SLOT(onCloseView()));
302
303   connect(GroupAngle,        SIGNAL(buttonClicked(int)),   this, SLOT(toDisplaySimulation()));
304   connect(SpinBox_Angle,     SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
305   connect(SpinBox_NbSteps,   SIGNAL(valueChanged(int)),    this, SLOT(toDisplaySimulation()));
306   connect(SpinBox_Tolerance, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
307
308   //To Connect preview check box
309   connectPreviewControl();
310
311   connect(SpinBox_Angle, SIGNAL(textChanged(const QString&)), this, SLOT(onAngleTextChange(const QString&)));
312
313   CheckIsEnable();
314 }
315
316 //=================================================================================
317 // function : ~SMESHGUI_RevolutionDlg()
318 // purpose  : Destroys the object and frees any allocated resources
319 //=================================================================================
320 SMESHGUI_RevolutionDlg::~SMESHGUI_RevolutionDlg()
321 {
322 }
323
324 //=================================================================================
325 // function : Init()
326 // purpose  :
327 //=================================================================================
328 void SMESHGUI_RevolutionDlg::Init (bool ResetControls)
329 {
330   if (ResetControls) {
331     SpinBox_X->SetValue(0.0);
332     SpinBox_Y->SetValue(0.0);
333     SpinBox_Z->SetValue(0.0);
334     SpinBox_DX->SetValue(0.0);
335     SpinBox_DY->SetValue(0.0);
336     SpinBox_DZ->SetValue(0.0);
337
338     SpinBox_Angle->SetValue(45);
339     SpinBox_NbSteps->setValue(1);
340     SpinBox_Tolerance->SetValue(1e-05);
341
342     myPreviewCheckBox->setChecked(false);
343     onDisplaySimulation(false);
344   }
345   SelectorWdg->Clear();
346 }
347
348 //=================================================================================
349 // function : CheckIsEnable()
350 // purpose  : Check whether the Ok and Apply buttons should be enabled or not
351 //=================================================================================
352
353 void SMESHGUI_RevolutionDlg::CheckIsEnable()
354 {  
355   bool anIsEnable = SelectorWdg->IsAnythingSelected() && IsAxisOk();
356
357   buttonOk->setEnabled(anIsEnable);
358   buttonApply->setEnabled(anIsEnable);
359 }
360
361 //=================================================================================
362 // function : isValid
363 // purpose  : Return true in case if values entered into dialog are valid
364 //=================================================================================
365 bool SMESHGUI_RevolutionDlg::isValid()
366 {
367   QString msg;
368   bool ok = true;
369   ok = SpinBox_X->isValid( msg, true ) && ok;
370   ok = SpinBox_Y->isValid( msg, true ) && ok;
371   ok = SpinBox_Z->isValid( msg, true ) && ok;
372   ok = SpinBox_DX->isValid( msg, true ) && ok;
373   ok = SpinBox_DY->isValid( msg, true ) && ok;
374   ok = SpinBox_DZ->isValid( msg, true ) && ok;
375   ok = SpinBox_Angle->isValid( msg, true ) && ok;
376   ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
377   ok = SpinBox_Tolerance->isValid( msg, true ) && ok;
378
379   if( !ok ) {
380     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
381     if ( !msg.isEmpty() )
382       str += "\n" + msg;
383     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
384     return false;
385   }
386   return true;
387 }
388
389 //=================================================================================
390 // function : ClickOnApply()
391 // purpose  :
392 //=================================================================================
393 bool SMESHGUI_RevolutionDlg::ClickOnApply()
394 {
395   if (SMESHGUI::isStudyLocked())
396     return false;
397
398   if (!isValid())
399     return false;
400
401   if ( SelectorWdg->IsAnythingSelected() && IsAxisOk() ) {
402
403     SMESH::AxisStruct anAxis;
404
405     anAxis.x =  SpinBox_X->GetValue();
406     anAxis.y =  SpinBox_Y->GetValue();
407     anAxis.z =  SpinBox_Z->GetValue();;
408     anAxis.vx = SpinBox_DX->GetValue();
409     anAxis.vy = SpinBox_DY->GetValue();
410     anAxis.vz = SpinBox_DZ->GetValue();
411
412     double    anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
413     long     aNbSteps = (long)SpinBox_NbSteps->value();
414     double aTolerance = SpinBox_Tolerance->GetValue();
415
416     if ( GroupAngle->checkedId() == 1 )
417       anAngle = anAngle/aNbSteps;
418
419     QStringList aParameters;
420     aParameters << SpinBox_X->text();
421     aParameters << SpinBox_Y->text();
422     aParameters << SpinBox_Z->text();
423     aParameters << SpinBox_DX->text();
424     aParameters << SpinBox_DY->text();
425     aParameters << SpinBox_DZ->text();
426     aParameters << SpinBox_Angle->text();
427     aParameters << SpinBox_NbSteps->text();
428     aParameters << SpinBox_Tolerance->text();
429
430     bool meshHadNewTypeBefore = true;
431     int  maxSelType = 0;
432     const bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
433
434     try {
435       SUIT_OverrideCursor aWaitCursor;
436
437       SMESH::SMESH_Mesh_var mesh = SelectorWdg->GetMesh();
438
439       mesh->SetParameters( aParameters.join(":").toUtf8().constData() );
440
441       SMESH::ListOfIDSources_var nodes = new SMESH::ListOfIDSources();
442       SMESH::ListOfIDSources_var edges = new SMESH::ListOfIDSources();
443       SMESH::ListOfIDSources_var faces = new SMESH::ListOfIDSources();
444       maxSelType = SelectorWdg->GetSelected( nodes, edges, faces );
445
446       // is it necessary to switch on the next Display Mode?
447       SMESH::ElementType newType = (SMESH::ElementType)( maxSelType + 1 );
448       SMESH::array_of_ElementType_var oldTypes = mesh->GetTypes();
449       meshHadNewTypeBefore = false;
450       for ( size_t i = 0; i < oldTypes->length() && !meshHadNewTypeBefore; ++i )
451         meshHadNewTypeBefore = ( oldTypes[i] >= newType );
452
453       SMESH::SMESH_MeshEditor_var aMeshEditor = mesh->GetMeshEditor();
454
455       SMESH::ListOfGroups_var groups = 
456         aMeshEditor->RotationSweepObjects( nodes, edges, faces, anAxis,
457                                            anAngle, aNbSteps, aTolerance, makeGroups);
458
459     } catch (...) {
460     }
461
462     SMESH_Actor* actor = SelectorWdg->GetActor();
463     if ( actor && !meshHadNewTypeBefore )
464     {
465       unsigned int aMode = actor->GetEntityMode();
466       switch ( maxSelType ) {
467       case SMESH::NODE: // extrude node -> edges
468         actor->SetRepresentation(SMESH_Actor::eEdge);
469         actor->SetEntityMode( aMode |= SMESH_Actor::eEdges ); break;
470       case SMESH::EDGE: // edge -> faces
471         actor->SetRepresentation(SMESH_Actor::eSurface);
472         actor->SetEntityMode( aMode |= SMESH_Actor::eFaces ); break;
473       case SMESH::FACE: // faces -> volumes
474         actor->SetRepresentation(SMESH_Actor::eSurface);
475         actor->SetEntityMode( aMode |= SMESH_Actor::eVolumes ); break;
476       }
477     }
478     if ( actor )
479       SMESH::Update( actor->getIO(), actor->GetVisibility() );
480     if ( makeGroups )
481       mySMESHGUI->updateObjBrowser(true); // new groups may appear
482     Init(false);
483     mySelectionMgr->clearSelected();
484     SelectorWdg->Clear();
485
486     SMESHGUI::Modified();
487   }
488
489   return true;
490 }
491
492 //=================================================================================
493 // function : ClickOnOk()
494 // purpose  :
495 //=================================================================================
496 void SMESHGUI_RevolutionDlg::ClickOnOk()
497 {
498   if( ClickOnApply() )
499     reject();
500 }
501
502 //=================================================================================
503 // function : reject()
504 // purpose  :
505 //=================================================================================
506 void SMESHGUI_RevolutionDlg::reject()
507 {
508   disconnect(mySelectionMgr, 0, this, 0);
509   mySelectionMgr->clearFilters();
510   //mySelectionMgr->clearSelected();
511   if (SMESH::GetCurrentVtkView()) {
512     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
513     SMESH::SetPointRepresentation(false);
514   }
515   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
516     aViewWindow->SetSelectionMode(ActorSelection);
517   mySMESHGUI->ResetState();
518
519   QDialog::reject();
520 }
521
522 //=================================================================================
523 // function : onOpenView()
524 // purpose  :
525 //=================================================================================
526 void SMESHGUI_RevolutionDlg::onOpenView()
527 {
528   if ( mySelector ) {
529     mySimulation->SetVisibility(false);
530     SMESH::SetPointRepresentation(false);
531   }
532   else {
533     mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
534     ActivateThisDialog();
535   }
536 }
537
538 //=================================================================================
539 // function : onCloseView()
540 // purpose  :
541 //=================================================================================
542 void SMESHGUI_RevolutionDlg::onCloseView()
543 {
544   DeactivateActiveDialog();
545   mySelector = 0;
546 }
547
548 //=================================================================================
549 // function : ClickOnHelp()
550 // purpose  :
551 //=================================================================================
552 void SMESHGUI_RevolutionDlg::ClickOnHelp()
553 {
554   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
555   if (app) 
556     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
557   else {
558     QString platform;
559 #ifdef WIN32
560     platform = "winapplication";
561 #else
562     platform = "application";
563 #endif
564     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
565                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
566                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
567                                                                  platform)).
568                              arg(myHelpFileName));
569   }
570 }
571
572 //=======================================================================
573 // function : onAngleTextChange()
574 // purpose  :
575 //=======================================================================
576 void SMESHGUI_RevolutionDlg::onAngleTextChange (const QString& theNewText)
577 {
578   bool isNumber;
579   SpinBox_Angle->text().toDouble( &isNumber );
580   if( !isNumber )
581     RadioButton3->setChecked( true );
582   RadioButton4->setEnabled( isNumber );
583 }
584
585 //=================================================================================
586 // function : SelectionIntoArgument()
587 // purpose  : Called when selection as changed or other case
588 //=================================================================================
589 void SMESHGUI_RevolutionDlg::SelectionIntoArgument()
590 {
591   if (!GroupButtons->isEnabled()) // inactive
592     return;
593   
594   if ( SelectVectorButton->isChecked() ||
595        SelectPointButton->isChecked() )
596   {
597     // get selected mesh
598     SALOME_ListIO aList;
599     mySelectionMgr->selectedObjects(aList);
600     int nbSel = aList.Extent();
601     if (nbSel != 1)
602       return;
603
604     Handle(SALOME_InteractiveObject) IO = aList.First();
605     TColStd_IndexedMapOfInteger aMapIndex;
606     mySelector->GetIndex(IO,aMapIndex);
607     if ( aMapIndex.Extent() != 1 )
608       return;
609
610     SMESH_Actor* anActor = SMESH::FindActorByEntry( IO->getEntry() );
611     SMDS_Mesh*     aMesh = anActor ? anActor->GetObject()->GetMesh() : 0;
612     if ( !aMesh )
613       return;
614
615     bool isNodeSelected = ((myEditCurrentArgument == (QWidget*)SpinBox_X ) ||
616                            (myEditCurrentArgument == (QWidget*)SpinBox_DX &&
617                             myVectorDefinition==POINT_SELECT));
618
619     bool isFaceSelected = (myEditCurrentArgument == (QWidget*)SpinBox_DX &&
620                            myVectorDefinition==FACE_SELECT);
621
622     if ( isNodeSelected )
623     {
624       const SMDS_MeshNode * n = aMesh->FindNode( aMapIndex(1) );
625       if (!n)
626         return;
627       double x = n->X();
628       double y = n->Y();
629       double z = n->Z();
630
631       if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
632         SpinBox_X->SetValue(x);
633         SpinBox_Y->SetValue(y);
634         SpinBox_Z->SetValue(z);
635       } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
636         SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
637         SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
638         SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
639       }
640     }
641     else if ( isFaceSelected )
642     {
643       const SMDS_MeshFace* face =
644         SMDS_Mesh::DownCast<SMDS_MeshFace>( aMesh->FindElement( aMapIndex( 1 )));
645       if (!face)
646         return;
647       gp_XYZ aNormale = SMESH::getNormale(face);
648       SpinBox_DX->SetValue(aNormale.X());
649       SpinBox_DY->SetValue(aNormale.Y());
650       SpinBox_DZ->SetValue(aNormale.Z());
651
652     }
653   }
654
655   CheckIsEnable();
656   onDisplaySimulation(true);
657 }
658
659 //=================================================================================
660 // function : SetEditCurrentArgument()
661 // purpose  :
662 //=================================================================================
663 void SMESHGUI_RevolutionDlg::SetEditCurrentArgument()
664 {
665   QPushButton* send = (QPushButton*)sender();
666
667   disconnect(mySelectionMgr, 0, this, 0);
668   mySelectionMgr->clearSelected();
669   mySelectionMgr->clearFilters();
670
671   if (send == SelectPointButton) {
672     myEditCurrentArgument = (QWidget*)SpinBox_X;
673     myEditCurrentArgument->setFocus();
674     SMESH::SetPointRepresentation(true);
675     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
676       aViewWindow->SetSelectionMode(NodeSelection);
677   }
678   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
679   SelectionIntoArgument();
680 }
681
682 //=================================================================================
683 // function : DeactivateActiveDialog()
684 // purpose  :
685 //=================================================================================
686 void SMESHGUI_RevolutionDlg::DeactivateActiveDialog()
687 {
688   if (GroupButtons->isEnabled())
689   {
690     GroupArguments->setEnabled(false);
691     GroupButtons->setEnabled(false);
692     SelectorWdg->setEnabled(false);
693     mySMESHGUI->ResetState();
694     mySMESHGUI->SetActiveDialogBox(0);
695   }
696 }
697
698 //=================================================================================
699 // function : ActivateThisDialog()
700 // purpose  :
701 //=================================================================================
702 void SMESHGUI_RevolutionDlg::ActivateThisDialog()
703 {
704   /* Emit a signal to deactivate the active dialog */
705   mySMESHGUI->EmitSignalDeactivateDialog();
706   GroupArguments->setEnabled(true);
707   GroupButtons->setEnabled(true);
708   SelectorWdg->setEnabled(true);
709
710   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
711 }
712
713 //=================================================================================
714 // function : enterEvent()
715 // purpose  :
716 //=================================================================================
717 void SMESHGUI_RevolutionDlg::enterEvent (QEvent*)
718 {
719   if (!GroupButtons->isEnabled()) {
720     SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
721     if ( aViewWindow && !mySelector) {
722       mySelector = aViewWindow->GetSelector();
723     }
724     ActivateThisDialog();
725   }
726 }
727
728 //=================================================================================
729 // function : IsAxisOk()
730 // purpose  :
731 //=================================================================================
732 bool SMESHGUI_RevolutionDlg::IsAxisOk()
733 {
734   return (SpinBox_DX->GetValue() != 0 ||
735           SpinBox_DY->GetValue() != 0 ||
736           SpinBox_DZ->GetValue() != 0);
737 }
738
739 //=================================================================================
740 // function : keyPressEvent()
741 // purpose  :
742 //=================================================================================
743 void SMESHGUI_RevolutionDlg::keyPressEvent( QKeyEvent* e )
744 {
745   QDialog::keyPressEvent( e );
746   if ( e->isAccepted() )
747     return;
748
749   if ( e->key() == Qt::Key_F1 ) {
750     e->accept();
751     ClickOnHelp();
752   }
753 }
754
755 //=================================================================================
756 // function : onDisplaySimulation()
757 // purpose  : Show/Hide preview
758 //=================================================================================
759 void SMESHGUI_RevolutionDlg::onDisplaySimulation(bool toDisplayPreview)
760 {
761   if (myPreviewCheckBox->isChecked() && toDisplayPreview)
762   {
763     if (SelectorWdg->IsAnythingSelected() && IsAxisOk())
764     {
765       SMESH::AxisStruct anAxis;
766       
767       anAxis.x =  SpinBox_X->GetValue();
768       anAxis.y =  SpinBox_Y->GetValue();
769       anAxis.z =  SpinBox_Z->GetValue();
770       anAxis.vx = SpinBox_DX->GetValue();
771       anAxis.vy = SpinBox_DY->GetValue();
772       anAxis.vz = SpinBox_DZ->GetValue();
773
774       double    anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
775       long     aNbSteps = (long)SpinBox_NbSteps->value();
776       double aTolerance = SpinBox_Tolerance->GetValue();
777       
778       if (GroupAngle->checkedId() == 1)
779         anAngle = anAngle/aNbSteps;
780       
781       try
782       {
783         SUIT_OverrideCursor aWaitCursor;
784
785         SMESH::SMESH_Mesh_var             mesh = SelectorWdg->GetMesh();
786         SMESH::SMESH_MeshEditor_var meshEditor = mesh->GetMeshEditPreviewer();
787         SMESH::ListOfGroups_var         groups;
788
789         SMESH::ListOfIDSources_var nodes = new SMESH::ListOfIDSources();
790         SMESH::ListOfIDSources_var edges = new SMESH::ListOfIDSources();
791         SMESH::ListOfIDSources_var faces = new SMESH::ListOfIDSources();
792         SelectorWdg->GetSelected( nodes, edges, faces );
793         const bool makeGroups = false;
794
795         meshEditor->RotationSweepObjects(nodes, edges, faces, 
796                                          anAxis, anAngle, aNbSteps, aTolerance, makeGroups );
797
798         SMESH::MeshPreviewStruct_var aMeshPreviewStruct = meshEditor->GetPreviewData();
799         mySimulation->SetData( aMeshPreviewStruct._retn() );
800       }
801       catch (...) {}
802     }
803     else
804     {
805       mySimulation->SetVisibility(false);
806     }
807   }
808   else
809   {
810     //erase preview
811     mySimulation->SetVisibility(false);
812   }
813 }
814
815 //=================================================================================
816 // function : onSelectVectorButton()
817 // purpose  : [slot]
818 //=================================================================================
819 void SMESHGUI_RevolutionDlg::onSelectVectorButton()
820 {
821   if(SelectVectorMenu) {
822     SelectVectorMenu->exec( QCursor::pos() );
823   }
824 }
825
826 //=================================================================================
827 // function : onSelectVectorMenu()
828 // purpose  : [slot]
829 //=================================================================================
830 void SMESHGUI_RevolutionDlg::onSelectVectorMenu( QAction* action)
831 {
832   if(!action)
833     return;
834
835   disconnect(mySelectionMgr, 0, this, 0);
836
837   switch(myMenuActions[action]) {
838   case POINT_SELECT: 
839     SMESH::SetPointRepresentation(true);
840     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
841       aViewWindow->SetSelectionMode(NodeSelection);
842     break;
843     
844   case FACE_SELECT: 
845     SMESH::SetPointRepresentation(false);
846     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
847       aViewWindow->SetSelectionMode(FaceSelection);
848     break;
849   }
850
851   myVectorDefinition = myMenuActions[action];
852   myEditCurrentArgument = (QWidget*)SpinBox_DX;
853   myEditCurrentArgument->setFocus();
854   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
855   SelectionIntoArgument();
856 }
857
858