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