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