Salome HOME
Additional fix for bug IPAL9834(selection in transformation does not work for group...
[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 //
23 //
24 //  File   : SMESHGUI_RevolutionDlg.cxx
25 //  Author : Michael ZORIN
26 //  Module : SMESH
27 //  $Header:
28
29 #include "SMESHGUI_RevolutionDlg.h"
30
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_SpinBox.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_VTKUtils.h"
35 #include "SMESHGUI_MeshUtils.h"
36 #include "SMESHGUI_IdValidator.h"
37
38 #include "SMESH_Actor.h"
39 #include "SMESH_TypeFilter.hxx"
40 #include "SMESH_LogicalFilter.hxx"
41 #include "SMDS_Mesh.hxx"
42
43 #include "SUIT_ResourceMgr.h"
44 #include "SUIT_Session.h"
45 #include "SUIT_MessageBox.h"
46
47 #include "LightApp_Application.h"
48
49 #include "SVTK_ViewModel.h"
50 #include "SVTK_ViewWindow.h"
51 #include "SVTK_Selector.h"
52 #include "SVTK_Selection.h"
53 #include "SALOME_ListIO.hxx"
54
55 #include "utilities.h"
56
57 // OCCT Includes
58 #include <TColStd_MapOfInteger.hxx>
59 #include <TColStd_IndexedMapOfInteger.hxx>
60
61 // QT Includes
62 #include <qapplication.h>
63 #include <qbuttongroup.h>
64 #include <qgroupbox.h>
65 #include <qlabel.h>
66 #include <qlineedit.h>
67 #include <qpushbutton.h>
68 #include <qradiobutton.h>
69 #include <qcheckbox.h>
70 #include <qlayout.h>
71 #include <qspinbox.h>
72 #include <qvalidator.h>
73 #include <qpixmap.h>
74
75 // IDL Headers
76 #include "SALOMEconfig.h"
77 #include CORBA_SERVER_HEADER(SMESH_Group)
78
79 using namespace std;
80
81 //=================================================================================
82 // class    : SMESHGUI_RevolutionDlg()
83 // purpose  :
84 //=================================================================================
85 SMESHGUI_RevolutionDlg::SMESHGUI_RevolutionDlg( SMESHGUI* theModule, const char* name,
86                                                 bool modal, WFlags fl)
87      : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
88                 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
89      mySMESHGUI( theModule ),
90      mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
91 {
92   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
93   QPixmap image0 ( mgr->loadPixmap("SMESH", tr("ICON_DLG_EDGE")));
94   QPixmap image1 ( mgr->loadPixmap("SMESH", tr("ICON_DLG_TRIANGLE")));
95   QPixmap image2 ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
96
97   if (!name)
98     setName("SMESHGUI_RevolutionDlg");
99   resize(303, 185);
100   setCaption(tr("REVOLUTION_AROUND_AXIS"));
101   setSizeGripEnabled(TRUE);
102   SMESHGUI_RevolutionDlgLayout = new QGridLayout(this);
103   SMESHGUI_RevolutionDlgLayout->setSpacing(6);
104   SMESHGUI_RevolutionDlgLayout->setMargin(11);
105
106   /***************************************************************/
107   GroupConstructors = new QButtonGroup(this, "GroupConstructors");
108   GroupConstructors->setTitle(tr("SMESH_REVOLUTION" ));
109   GroupConstructors->setExclusive(TRUE);
110   GroupConstructors->setColumnLayout(0, Qt::Vertical);
111   GroupConstructors->layout()->setSpacing(0);
112   GroupConstructors->layout()->setMargin(0);
113   GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
114   GroupConstructorsLayout->setAlignment(Qt::AlignTop);
115   GroupConstructorsLayout->setSpacing(6);
116   GroupConstructorsLayout->setMargin(11);
117   RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
118   RadioButton1->setText(tr("" ));
119   RadioButton1->setPixmap(image0);
120   GroupConstructorsLayout->addWidget(RadioButton1, 0, 0);
121   RadioButton2= new QRadioButton(GroupConstructors, "RadioButton2");
122   RadioButton2->setText(tr("" ));
123   RadioButton2->setPixmap(image1);
124   GroupConstructorsLayout->addWidget(RadioButton2, 0, 2);
125   SMESHGUI_RevolutionDlgLayout->addWidget(GroupConstructors, 0, 0);
126
127   /***************************************************************/
128   GroupButtons = new QGroupBox(this, "GroupButtons");
129   GroupButtons->setGeometry(QRect(10, 10, 281, 48));
130   GroupButtons->setTitle(tr("" ));
131   GroupButtons->setColumnLayout(0, Qt::Vertical);
132   GroupButtons->layout()->setSpacing(0);
133   GroupButtons->layout()->setMargin(0);
134   GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
135   GroupButtonsLayout->setAlignment(Qt::AlignTop);
136   GroupButtonsLayout->setSpacing(6);
137   GroupButtonsLayout->setMargin(11);
138   buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
139   buttonHelp->setText(tr("SMESH_BUT_HELP" ));
140   buttonHelp->setAutoDefault(TRUE);
141   GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
142   buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
143   buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
144   buttonCancel->setAutoDefault(TRUE);
145   GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
146   buttonApply = new QPushButton(GroupButtons, "buttonApply");
147   buttonApply->setText(tr("SMESH_BUT_APPLY" ));
148   buttonApply->setAutoDefault(TRUE);
149   GroupButtonsLayout->addWidget(buttonApply, 0, 1);
150   QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
151   GroupButtonsLayout->addItem(spacer_9, 0, 2);
152   buttonOk = new QPushButton(GroupButtons, "buttonOk");
153   buttonOk->setText(tr("SMESH_BUT_OK" ));
154   buttonOk->setAutoDefault(TRUE);
155   buttonOk->setDefault(TRUE);
156   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
157   SMESHGUI_RevolutionDlgLayout->addWidget(GroupButtons, 2, 0);
158
159   /***************************************************************/
160   GroupArguments = new QGroupBox(this, "GroupArguments");
161   GroupArguments->setTitle(tr("REVOLUTION_1D"));
162   GroupArguments->setColumnLayout(0, Qt::Vertical);
163   GroupArguments->layout()->setSpacing(0);
164   GroupArguments->layout()->setMargin(0);
165   GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
166   GroupArgumentsLayout->setAlignment(Qt::AlignTop);
167   GroupArgumentsLayout->setSpacing(6);
168   GroupArgumentsLayout->setMargin(11);
169
170   // Controls for elements selection
171   TextLabelElements  = new QLabel(GroupArguments, "TextLabelElements");
172   TextLabelElements->setText(tr("SMESH_ID_ELEMENTS" ));
173   TextLabelElements->setFixedWidth(74);
174   GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
175
176   SelectElementsButton  = new QPushButton(GroupArguments, "SelectElementsButton");
177   SelectElementsButton->setText(tr("" ));
178   SelectElementsButton->setPixmap(image2);
179   SelectElementsButton->setToggleButton(FALSE);
180   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
181
182   LineEditElements  = new QLineEdit(GroupArguments, "LineEditElements");
183   LineEditElements->setValidator(new SMESHGUI_IdValidator(this, "validator"));
184   GroupArgumentsLayout->addWidget(LineEditElements, 0, 2);
185
186   // Control for the whole mesh selection
187   CheckBoxMesh = new QCheckBox(GroupArguments, "CheckBoxMesh");
188   CheckBoxMesh->setText(tr("SMESH_SELECT_WHOLE_MESH" ));
189   GroupArgumentsLayout->addMultiCellWidget(CheckBoxMesh, 1, 1, 0, 3);
190
191   // Controls for axis defining
192   GroupAxis = new QGroupBox(GroupArguments, "GroupAxis");
193   GroupAxis->setTitle(tr("SMESH_AXIS"));
194   GroupAxis->setColumnLayout(0, Qt::Vertical);
195   GroupAxis->layout()->setSpacing(0);
196   GroupAxis->layout()->setMargin(0);
197   QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis->layout());
198   GroupAxisLayout->setAlignment(Qt::AlignTop);
199   GroupAxisLayout->setSpacing(6);
200   GroupAxisLayout->setMargin(11);
201
202   TextLabelPoint = new QLabel(GroupAxis, "TextLabelPoint");
203   TextLabelPoint->setText(tr("SMESH_POINT"));
204   GroupAxisLayout->addWidget(TextLabelPoint, 0, 0);
205
206   SelectPointButton  = new QPushButton(GroupAxis, "SelectPointButton");
207   SelectPointButton->setPixmap(image2);
208   GroupAxisLayout->addWidget(SelectPointButton, 0, 1);
209
210   TextLabelX = new QLabel(GroupAxis, "TextLabelX");
211   TextLabelX->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
212   TextLabelX->setText(tr("SMESH_X"));
213   GroupAxisLayout->addWidget(TextLabelX, 0, 2);
214
215   SpinBox_X = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_X");
216   GroupAxisLayout->addWidget(SpinBox_X, 0, 3);
217
218   TextLabelY = new QLabel(GroupAxis, "TextLabelY");
219   TextLabelY->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
220   TextLabelY->setText(tr("SMESH_Y"));
221   GroupAxisLayout->addWidget(TextLabelY, 0, 4);
222
223   SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_Y");
224   GroupAxisLayout->addWidget(SpinBox_Y, 0, 5);
225
226   TextLabelZ = new QLabel(GroupAxis, "TextLabelZ");
227   TextLabelZ->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
228   TextLabelZ->setText(tr("SMESH_Z"));
229   GroupAxisLayout->addWidget(TextLabelZ, 0, 6);
230
231   SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_Z");
232   GroupAxisLayout->addWidget(SpinBox_Z, 0, 7);
233
234   TextLabelVector = new QLabel(GroupAxis, "TextLabelVector");
235   TextLabelVector->setText(tr("SMESH_VECTOR"));
236   GroupAxisLayout->addWidget(TextLabelVector, 1, 0);
237
238   SelectVectorButton = new QPushButton(GroupAxis, "SelectVectorButton");
239   SelectVectorButton->setPixmap(image2);
240   GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
241
242   TextLabelDX = new QLabel(GroupAxis, "TextLabelDX");
243   TextLabelDX->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
244   TextLabelDX->setText(tr("SMESH_DX"));
245   GroupAxisLayout->addWidget(TextLabelDX, 1, 2);
246
247   SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_DX");
248   GroupAxisLayout->addWidget(SpinBox_DX, 1, 3);
249
250   TextLabelDY = new QLabel(GroupAxis, "TextLabelDY");
251   TextLabelDY->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
252   TextLabelDY->setText(tr("SMESH_DY"));
253   GroupAxisLayout->addWidget(TextLabelDY, 1, 4);
254
255   SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_DY");
256   GroupAxisLayout->addWidget(SpinBox_DY, 1, 5);
257
258   TextLabelDZ = new QLabel(GroupAxis, "TextLabelDZ");
259   TextLabelDZ->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
260   TextLabelDZ->setText(tr("SMESH_DZ"));
261   GroupAxisLayout->addWidget(TextLabelDZ, 1, 6);
262
263   SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_DZ");
264   GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7);
265
266   GroupArgumentsLayout->addMultiCellWidget(GroupAxis, 2, 2, 0, 3);
267
268   // Controls for angle defining
269   TextLabelAngle = new QLabel(GroupArguments, "TextLabelAngle");
270   TextLabelAngle->setText(tr("SMESH_ANGLE" ));
271   GroupArgumentsLayout->addMultiCellWidget(TextLabelAngle, 3, 3, 0, 1);
272
273   SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments, "SpinBox_Angle");
274   GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
275
276   // Controls for nb. steps defining
277   TextLabelNbSteps = new QLabel(GroupArguments, "TextLabelNbSteps");
278   TextLabelNbSteps->setText(tr("SMESH_NUMBEROFSTEPS" ));
279   GroupArgumentsLayout->addMultiCellWidget(TextLabelNbSteps, 4, 4, 0, 1);
280
281   SpinBox_NbSteps = new QSpinBox(GroupArguments, "SpinBox_NbSteps");
282   GroupArgumentsLayout->addWidget(SpinBox_NbSteps, 4, 2);
283
284   // Controls for tolerance defining
285   TextLabelTolerance = new QLabel(GroupArguments, "TextLabelTolerance");
286   TextLabelTolerance->setText(tr("SMESH_TOLERANCE"));
287   GroupArgumentsLayout->addMultiCellWidget(TextLabelTolerance, 5, 5, 0, 1);
288
289   SpinBox_Tolerance = new SMESHGUI_SpinBox(GroupArguments, "SpinBox_Tolerance");
290   GroupArgumentsLayout->addWidget(SpinBox_Tolerance, 5, 2);
291
292   SMESHGUI_RevolutionDlgLayout->addWidget(GroupArguments, 1, 0);
293
294   /* Initialisations */
295   SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
296   SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
297   SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
298   SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
299   SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
300   SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
301
302   SpinBox_Angle->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5.0, 3);
303
304   QIntValidator* anIntValidator = new QIntValidator(SpinBox_NbSteps);
305   SpinBox_NbSteps->setValidator(anIntValidator);
306   SpinBox_NbSteps->setRange(1, 999999);
307
308   SpinBox_Tolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.1, 6);
309
310   GroupArguments->show();
311   RadioButton1->setChecked(TRUE);
312
313   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
314
315   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
316
317   // Costruction of the logical filter
318   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
319   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
320
321   QPtrList<SUIT_SelectionFilter> aListOfFilters;
322   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
323   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
324
325   myMeshOrSubMeshOrGroupFilter =
326     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
327
328   myHelpFileName = "revolution.htm";
329
330   Init();
331
332   /* signals and slots connections */
333   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
334   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
335   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
336   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
337   connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
338
339   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
340   connect(SelectPointButton, SIGNAL (clicked()),    this, SLOT(SetEditCurrentArgument()));
341   connect(SelectVectorButton, SIGNAL (clicked()),   this, SLOT(SetEditCurrentArgument()));
342
343   connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
344   connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
345   connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
346
347   connect(mySMESHGUI,     SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
348   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),      this, SLOT(SelectionIntoArgument()));
349   /* to close dialog if study change */
350   connect(mySMESHGUI,       SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
351   connect(LineEditElements, SIGNAL(textChanged(const QString&)),   SLOT(onTextChange(const QString&)));
352   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                 SLOT(onSelectMesh(bool)));
353
354   this->show(); /* displays Dialog */
355
356   ConstructorsClicked(0);
357   SelectionIntoArgument();
358   resize(0,0); // ??
359 }
360
361 //=================================================================================
362 // function : ~SMESHGUI_RevolutionDlg()
363 // purpose  : Destroys the object and frees any allocated resources
364 //=================================================================================
365 SMESHGUI_RevolutionDlg::~SMESHGUI_RevolutionDlg()
366 {
367   // no need to delete child widgets, Qt does it all for us
368 }
369
370 //=================================================================================
371 // function : Init()
372 // purpose  :
373 //=================================================================================
374 void SMESHGUI_RevolutionDlg::Init (bool ResetControls)
375 {
376   myBusy = false;
377
378   myEditCurrentArgument = 0;
379   LineEditElements->clear();
380   myElementsId = "";
381   myNbOkElements = 0;
382
383   myActor = 0;
384   myMesh = SMESH::SMESH_Mesh::_nil();
385
386   if (ResetControls) {
387     SpinBox_X->SetValue(0.0);
388     SpinBox_Y->SetValue(0.0);
389     SpinBox_Z->SetValue(0.0);
390     SpinBox_DX->SetValue(0.0);
391     SpinBox_DY->SetValue(0.0);
392     SpinBox_DZ->SetValue(0.0);
393
394     SpinBox_Angle->SetValue(45);
395     SpinBox_NbSteps->setValue(1);
396     SpinBox_Tolerance->SetValue(1e-05);
397
398     CheckBoxMesh->setChecked(false);
399     onSelectMesh(false);
400   }
401 }
402
403 //=================================================================================
404 // function : ConstructorsClicked()
405 // purpose  : Radio button management
406 //=================================================================================
407 void SMESHGUI_RevolutionDlg::ConstructorsClicked (int constructorId)
408 {
409   disconnect(mySelectionMgr, 0, this, 0);
410
411   Selection_Mode aSelMode = ActorSelection;
412
413   switch (constructorId) {
414   case 0:
415     {
416       GroupArguments->setTitle(tr("REVOLUTION_1D"));
417       aSelMode = EdgeSelection;
418       break;
419     }
420   case 1:
421     {
422       GroupArguments->setTitle(tr("REVOLUTION_2D"));
423       aSelMode = FaceSelection;
424       break;
425     }
426   }
427
428   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
429     SMESH::SetPointRepresentation(false);
430   }
431
432   if (!CheckBoxMesh->isChecked())
433     {
434       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
435         aViewWindow->SetSelectionMode(aSelMode);
436     }
437
438   myEditCurrentArgument = (QWidget*)LineEditElements;
439   LineEditElements->setFocus();
440
441   if (CheckBoxMesh->isChecked())
442     onSelectMesh(true);
443
444   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
445 }
446
447 //=================================================================================
448 // function : ClickOnApply()
449 // purpose  :
450 //=================================================================================
451 void SMESHGUI_RevolutionDlg::ClickOnApply()
452 {
453   if (mySMESHGUI->isActiveStudyLocked())
454     return;
455
456   if (myNbOkElements && IsAxisOk()) {
457     QStringList aListElementsId = QStringList::split(" ", myElementsId, false);
458
459     SMESH::long_array_var anElementsId = new SMESH::long_array;
460
461     anElementsId->length(aListElementsId.count());
462     for (int i = 0; i < aListElementsId.count(); i++)
463       anElementsId[i] = aListElementsId[i].toInt();
464
465     SMESH::AxisStruct anAxis;
466
467     anAxis.x =  SpinBox_X->GetValue();
468     anAxis.y =  SpinBox_Y->GetValue();
469     anAxis.z =  SpinBox_Z->GetValue();;
470     anAxis.vx = SpinBox_DX->GetValue();
471     anAxis.vy = SpinBox_DY->GetValue();
472     anAxis.vz = SpinBox_DZ->GetValue();
473
474     double anAngle = (SpinBox_Angle->GetValue())*PI/180;
475     long aNbSteps = (long)SpinBox_NbSteps->value();
476     double aTolerance = SpinBox_Tolerance->GetValue();
477
478     try {
479       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
480       QApplication::setOverrideCursor(Qt::waitCursor);
481       aMeshEditor->RotationSweep(anElementsId.inout(), anAxis, anAngle, aNbSteps, aTolerance);
482       QApplication::restoreOverrideCursor();
483     } catch (...) {
484     }
485
486     SMESH::UpdateView();
487     Init(false);
488     ConstructorsClicked(GetConstructorId());
489     SelectionIntoArgument();
490   }
491 }
492
493 //=================================================================================
494 // function : ClickOnOk()
495 // purpose  :
496 //=================================================================================
497 void SMESHGUI_RevolutionDlg::ClickOnOk()
498 {
499   ClickOnApply();
500   ClickOnCancel();
501 }
502
503 //=================================================================================
504 // function : ClickOnCancel()
505 // purpose  :
506 //=================================================================================
507 void SMESHGUI_RevolutionDlg::ClickOnCancel()
508 {
509   disconnect(mySelectionMgr, 0, this, 0);
510   mySelectionMgr->clearFilters();
511   //mySelectionMgr->clearSelected();
512   SMESH::SetPointRepresentation(false);
513   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
514     aViewWindow->SetSelectionMode(ActorSelection);
515   mySMESHGUI->ResetState();
516   reject();
517 }
518
519 //=================================================================================
520 // function : ClickOnHelp()
521 // purpose  :
522 //=================================================================================
523 void SMESHGUI_RevolutionDlg::ClickOnHelp()
524 {
525   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
526   if (app) 
527     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
528   else {
529     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
530                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
531                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
532                            QObject::tr("BUT_OK"));
533   }
534 }
535
536 //=======================================================================
537 // function : onTextChange()
538 // purpose  :
539 //=======================================================================
540 void SMESHGUI_RevolutionDlg::onTextChange (const QString& theNewText)
541 {
542   QLineEdit* send = (QLineEdit*)sender();
543
544   if (myBusy) return;
545   myBusy = true;
546
547   if (send == LineEditElements)
548     myNbOkElements = 0;
549
550   buttonOk->setEnabled(false);
551   buttonApply->setEnabled(false);
552
553   // hilight entered elements
554   SMDS_Mesh* aMesh = 0;
555   if (myActor)
556     aMesh = myActor->GetObject()->GetMesh();
557
558   if (aMesh) {
559     if (send == LineEditElements) {
560       Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
561
562       TColStd_MapOfInteger newIndices;
563
564       QStringList aListId = QStringList::split(" ", theNewText, false);
565       
566       for (int i = 0; i < aListId.count(); i++) {
567         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
568         if (e)
569           newIndices.Add(e->GetID());
570         myNbOkElements++;
571       }
572
573       mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
574       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
575         aViewWindow->highlight( myActor->getIO(), true, true );
576       
577       myElementsId = theNewText;
578     }
579   }
580
581   if (myNbOkElements && IsAxisOk()) {
582     buttonOk->setEnabled(true);
583     buttonApply->setEnabled(true);
584   }
585
586   myBusy = false;
587 }
588
589 //=================================================================================
590 // function : SelectionIntoArgument()
591 // purpose  : Called when selection as changed or other case
592 //=================================================================================
593 void SMESHGUI_RevolutionDlg::SelectionIntoArgument()
594 {
595   if (myBusy) return;
596
597   // clear
598   myActor = 0;
599   QString aString = "";
600
601   myBusy = true;
602   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
603     LineEditElements->setText(aString);
604     myNbOkElements = 0;
605     buttonOk->setEnabled(false);
606     buttonApply->setEnabled(false);
607   }
608   myBusy = false;
609
610   if (!GroupButtons->isEnabled()) // inactive
611     return;
612
613   // get selected mesh
614   const SALOME_ListIO& aList = mySelector->StoredIObjects();
615
616   int nbSel = aList.Extent();
617   if (nbSel != 1)
618     return;
619
620   Handle(SALOME_InteractiveObject) IO = aList.First();
621   myMesh = SMESH::GetMeshByIO(IO);
622   if (myMesh->_is_nil())
623     return;
624
625   myActor = SMESH::FindActorByObject(myMesh);
626   if (!myActor)
627     myActor = SMESH::FindActorByEntry(IO->getEntry());
628   if (!myActor)
629     return;
630
631   int aNbUnits = 0;
632
633   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
634     myElementsId = "";
635
636     if (CheckBoxMesh->isChecked()) {
637       int aConstructorId = GetConstructorId();
638
639       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
640
641       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
642         // get IDs from mesh
643         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
644         if (!aSMDSMesh)
645           return;
646
647         if (aConstructorId == 0) {
648           SMDS_EdgeIteratorPtr anIter = aSMDSMesh->edgesIterator();
649
650           while (anIter->more()) {
651             const SMDS_MeshEdge * edge = anIter->next();
652             if (edge) {
653               myElementsId += QString(" %1").arg(edge->GetID());
654               aNbUnits++;
655             }
656           }
657         } else if (aConstructorId == 1) {
658           SMDS_FaceIteratorPtr anIter = aSMDSMesh->facesIterator();
659           while (anIter->more()) {
660             const SMDS_MeshFace * face = anIter->next();
661             if (face) {
662               myElementsId += QString(" %1").arg(face->GetID());
663               aNbUnits++;
664             }
665           }
666         }
667       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
668         // get submesh
669         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
670
671         // get IDs from submesh
672         SMESH::long_array_var anElementsIds = new SMESH::long_array;
673         if (aConstructorId == 0)
674           anElementsIds = aSubMesh->GetElementsByType(SMESH::EDGE);
675         else if (aConstructorId == 1)
676           anElementsIds = aSubMesh->GetElementsByType(SMESH::FACE);
677
678         for (int i = 0; i < anElementsIds->length(); i++)
679           myElementsId += QString(" %1").arg(anElementsIds[i]);
680         aNbUnits = anElementsIds->length();
681       } else { // GROUP
682         // get smesh group
683         SMESH::SMESH_GroupBase_var aGroup =
684           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
685         if (aGroup->_is_nil())
686           return;
687
688         if ((aConstructorId == 0 && aGroup->GetType()!= SMESH::EDGE) ||
689             (aConstructorId == 1 && aGroup->GetType()!= SMESH::FACE))
690           return;
691
692         // get IDs from smesh group
693         SMESH::long_array_var anElementsIds = new SMESH::long_array;
694         anElementsIds = aGroup->GetListOfID();
695         for (int i = 0; i < anElementsIds->length(); i++) {
696           myElementsId += QString(" %1").arg(anElementsIds[i]);
697         }
698         aNbUnits = anElementsIds->length();
699       }
700     } else {
701       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
702       myElementsId = aString;
703     }
704
705     if (aNbUnits < 1)
706       return;
707
708     myNbOkElements = true;
709   } else {
710     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
711     if (aNbUnits != 1)
712       return;
713
714     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
715     if (!aMesh)
716       return;
717
718     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
719     if (!n)
720       return;
721
722     double x = n->X();
723     double y = n->Y();
724     double z = n->Z();
725
726     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
727       SpinBox_X->SetValue(x);
728       SpinBox_Y->SetValue(y);
729       SpinBox_Z->SetValue(z);
730     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
731       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
732       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
733       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
734     }
735   }
736
737   myBusy = true;
738   if (myEditCurrentArgument == (QWidget*)LineEditElements)
739     LineEditElements->setText(aString);
740   myBusy = false;
741
742   // OK
743   if (myNbOkElements && IsAxisOk()) {
744     buttonOk->setEnabled(true);
745     buttonApply->setEnabled(true);
746   }
747 }
748
749 //=================================================================================
750 // function : SetEditCurrentArgument()
751 // purpose  :
752 //=================================================================================
753 void SMESHGUI_RevolutionDlg::SetEditCurrentArgument()
754 {
755   QPushButton* send = (QPushButton*)sender();
756
757   disconnect(mySelectionMgr, 0, this, 0);
758   mySelectionMgr->clearSelected();
759   mySelectionMgr->clearFilters();
760
761   if (send == SelectElementsButton) {
762     myEditCurrentArgument = (QWidget*)LineEditElements;
763     SMESH::SetPointRepresentation(false);
764     if (CheckBoxMesh->isChecked()) {
765       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
766         aViewWindow->SetSelectionMode(ActorSelection);
767       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
768     } else {
769       int aConstructorId = GetConstructorId();
770       if (aConstructorId == 0)
771         {
772           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
773             aViewWindow->SetSelectionMode(EdgeSelection);
774         }
775       else if (aConstructorId == 1)
776         {
777           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
778             aViewWindow->SetSelectionMode(FaceSelection);
779         }
780     }
781   } else if (send == SelectPointButton) {
782     myEditCurrentArgument = (QWidget*)SpinBox_X;
783     SMESH::SetPointRepresentation(true);
784     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
785       aViewWindow->SetSelectionMode(NodeSelection);
786   } else if (send == SelectVectorButton) {
787     myEditCurrentArgument = (QWidget*)SpinBox_DX;
788     SMESH::SetPointRepresentation(true);
789     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
790       aViewWindow->SetSelectionMode(NodeSelection);
791   } else {
792   }
793
794   myEditCurrentArgument->setFocus();
795   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
796   SelectionIntoArgument();
797 }
798
799 //=================================================================================
800 // function : DeactivateActiveDialog()
801 // purpose  :
802 //=================================================================================
803 void SMESHGUI_RevolutionDlg::DeactivateActiveDialog()
804 {
805   if (GroupConstructors->isEnabled()) {
806     GroupConstructors->setEnabled(false);
807     GroupArguments->setEnabled(false);
808     GroupButtons->setEnabled(false);
809     mySMESHGUI->ResetState();
810     mySMESHGUI->SetActiveDialogBox(0);
811   }
812 }
813
814 //=================================================================================
815 // function : ActivateThisDialog()
816 // purpose  :
817 //=================================================================================
818 void SMESHGUI_RevolutionDlg::ActivateThisDialog()
819 {
820   /* Emit a signal to deactivate the active dialog */
821   mySMESHGUI->EmitSignalDeactivateDialog();
822   GroupConstructors->setEnabled(true);
823   GroupArguments->setEnabled(true);
824   GroupButtons->setEnabled(true);
825
826   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
827
828   ConstructorsClicked(GetConstructorId());
829   SelectionIntoArgument();
830 }
831
832 //=================================================================================
833 // function : enterEvent()
834 // purpose  :
835 //=================================================================================
836 void SMESHGUI_RevolutionDlg::enterEvent (QEvent*)
837 {
838   if (!GroupConstructors->isEnabled())
839     ActivateThisDialog();
840 }
841
842 //=================================================================================
843 // function : closeEvent()
844 // purpose  :
845 //=================================================================================
846 void SMESHGUI_RevolutionDlg::closeEvent (QCloseEvent*)
847 {
848   /* same than click on cancel button */
849   this->ClickOnCancel();
850 }
851
852 //=======================================================================
853 // function : hideEvent()
854 // purpose  : caused by ESC key
855 //=======================================================================
856 void SMESHGUI_RevolutionDlg::hideEvent (QHideEvent*)
857 {
858   if (!isMinimized())
859     ClickOnCancel();
860 }
861
862 //=======================================================================
863 //function : onSelectMesh
864 //purpose  :
865 //=======================================================================
866 void SMESHGUI_RevolutionDlg::onSelectMesh (bool toSelectMesh)
867 {
868   if (toSelectMesh)
869     TextLabelElements->setText(tr("SMESH_NAME"));
870   else
871     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
872
873   if (myEditCurrentArgument != LineEditElements) {
874     LineEditElements->clear();
875     return;
876   }
877
878   mySelectionMgr->clearFilters();
879   SMESH::SetPointRepresentation(false);
880
881   if (toSelectMesh) {
882     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
883       aViewWindow->SetSelectionMode(ActorSelection);
884     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
885     LineEditElements->setReadOnly(true);
886   } else {
887     int aConstructorId = GetConstructorId();
888     if (aConstructorId == 0)
889       {
890         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
891           aViewWindow->SetSelectionMode(EdgeSelection);
892       }
893     else if (aConstructorId == 0)
894       {
895         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
896           aViewWindow->SetSelectionMode(FaceSelection);
897       }
898
899     LineEditElements->setReadOnly(false);
900     onTextChange(LineEditElements->text());
901   }
902
903   SelectionIntoArgument();
904 }
905
906 //=================================================================================
907 // function : GetConstructorId()
908 // purpose  :
909 //=================================================================================
910 int SMESHGUI_RevolutionDlg::GetConstructorId()
911 {
912   if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
913     return GroupConstructors->id(GroupConstructors->selected());
914   return -1;
915 }
916
917 //=================================================================================
918 // function : IsAxisOk()
919 // purpose  :
920 //=================================================================================
921 bool SMESHGUI_RevolutionDlg::IsAxisOk()
922 {
923   return (SpinBox_DX->GetValue() != 0 ||
924           SpinBox_DY->GetValue() != 0 ||
925           SpinBox_DZ->GetValue() != 0);
926 }
927
928 //=================================================================================
929 // function : onVectorChanged()
930 // purpose  :
931 //=================================================================================
932 void SMESHGUI_RevolutionDlg::onVectorChanged()
933 {
934   if (IsAxisOk()) {
935     buttonOk->setEnabled(true);
936     buttonApply->setEnabled(true);
937   } else {
938     buttonOk->setEnabled(false);
939     buttonApply->setEnabled(false);
940   }
941 }
942
943 //=================================================================================
944 // function : keyPressEvent()
945 // purpose  :
946 //=================================================================================
947 void SMESHGUI_RevolutionDlg::keyPressEvent( QKeyEvent* e )
948 {
949   QDialog::keyPressEvent( e );
950   if ( e->isAccepted() )
951     return;
952
953   if ( e->key() == Key_F1 )
954     {
955       e->accept();
956       ClickOnHelp();
957     }
958 }