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