Salome HOME
Merging with WPdev
[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                 QString platform;
524 #ifdef WIN32
525                 platform = "winapplication";
526 #else
527                 platform = "application";
528 #endif
529     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
530                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
531                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
532                            QObject::tr("BUT_OK"));
533   }
534 }
535
536 //=======================================================================
537 // function : onTextChange()
538 // purpose  :
539 //=======================================================================
540 void SMESHGUI_RevolutionDlg::onTextChange (const QString& theNewText)
541 {
542   QLineEdit* send = (QLineEdit*)sender();
543
544   if (myBusy) return;
545   myBusy = true;
546
547   if (send == LineEditElements)
548     myNbOkElements = 0;
549
550   buttonOk->setEnabled(false);
551   buttonApply->setEnabled(false);
552
553   // hilight entered elements
554   SMDS_Mesh* aMesh = 0;
555   if (myActor)
556     aMesh = myActor->GetObject()->GetMesh();
557
558   if (aMesh) {
559     if (send == LineEditElements) {
560       Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
561
562       TColStd_MapOfInteger newIndices;
563
564       QStringList aListId = QStringList::split(" ", theNewText, false);
565       
566       for (int i = 0; i < aListId.count(); i++) {
567         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
568         if (e)
569           newIndices.Add(e->GetID());
570         myNbOkElements++;
571       }
572
573       mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
574       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
575         aViewWindow->highlight( myActor->getIO(), true, true );
576       
577       myElementsId = theNewText;
578     }
579   }
580
581   if (myNbOkElements && IsAxisOk()) {
582     buttonOk->setEnabled(true);
583     buttonApply->setEnabled(true);
584   }
585
586   myBusy = false;
587 }
588
589 //=================================================================================
590 // function : SelectionIntoArgument()
591 // purpose  : Called when selection as changed or other case
592 //=================================================================================
593 void SMESHGUI_RevolutionDlg::SelectionIntoArgument()
594 {
595   if (myBusy) return;
596
597   // clear
598   myActor = 0;
599   QString aString = "";
600
601   myBusy = true;
602   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
603     LineEditElements->setText(aString);
604     myNbOkElements = 0;
605     buttonOk->setEnabled(false);
606     buttonApply->setEnabled(false);
607   }
608   myBusy = false;
609
610   if (!GroupButtons->isEnabled()) // inactive
611     return;
612
613   // get selected mesh
614   const SALOME_ListIO& aList = mySelector->StoredIObjects();
615
616   int nbSel = aList.Extent();
617   if (nbSel != 1)
618     return;
619
620   Handle(SALOME_InteractiveObject) IO = aList.First();
621   myMesh = SMESH::GetMeshByIO(IO);
622   if (myMesh->_is_nil())
623     return;
624
625   myActor = SMESH::FindActorByObject(myMesh);
626   if (!myActor)
627     myActor = SMESH::FindActorByEntry(IO->getEntry());
628   if (!myActor)
629     return;
630
631   int aNbUnits = 0;
632
633   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
634     myElementsId = "";
635
636     if (CheckBoxMesh->isChecked()) {
637       int aConstructorId = GetConstructorId();
638
639       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
640
641       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
642         // get IDs from mesh
643         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
644         if (!aSMDSMesh)
645           return;
646
647         if (aConstructorId == 0) {
648           SMDS_EdgeIteratorPtr anIter = aSMDSMesh->edgesIterator();
649
650           while (anIter->more()) {
651             const SMDS_MeshEdge * edge = anIter->next();
652             if (edge) {
653               myElementsId += QString(" %1").arg(edge->GetID());
654               aNbUnits++;
655             }
656           }
657         } else if (aConstructorId == 1) {
658           SMDS_FaceIteratorPtr anIter = aSMDSMesh->facesIterator();
659           while (anIter->more()) {
660             const SMDS_MeshFace * face = anIter->next();
661             if (face) {
662               myElementsId += QString(" %1").arg(face->GetID());
663               aNbUnits++;
664             }
665           }
666         }
667       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
668         // get submesh
669         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
670
671         // get IDs from submesh
672         SMESH::long_array_var anElementsIds = new SMESH::long_array;
673         if (aConstructorId == 0)
674           anElementsIds = aSubMesh->GetElementsByType(SMESH::EDGE);
675         else if (aConstructorId == 1)
676           anElementsIds = aSubMesh->GetElementsByType(SMESH::FACE);
677
678         for (int i = 0; i < anElementsIds->length(); i++)
679           myElementsId += QString(" %1").arg(anElementsIds[i]);
680         aNbUnits = anElementsIds->length();
681       } else { // GROUP
682         // get smesh group
683         SMESH::SMESH_GroupBase_var aGroup =
684           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
685         if (aGroup->_is_nil())
686           return;
687
688         if ((aConstructorId == 0 && aGroup->GetType()!= SMESH::EDGE) ||
689             (aConstructorId == 1 && aGroup->GetType()!= SMESH::FACE))
690           return;
691
692         // get IDs from smesh group
693         SMESH::long_array_var anElementsIds = new SMESH::long_array;
694         anElementsIds = aGroup->GetListOfID();
695         for (int i = 0; i < anElementsIds->length(); i++) {
696           myElementsId += QString(" %1").arg(anElementsIds[i]);
697         }
698         aNbUnits = anElementsIds->length();
699       }
700     } else {
701       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
702       myElementsId = aString;
703     }
704
705     if (aNbUnits < 1)
706       return;
707
708     myNbOkElements = true;
709   } else {
710     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
711     if (aNbUnits != 1)
712       return;
713
714     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
715     if (!aMesh)
716       return;
717
718     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
719     if (!n)
720       return;
721
722     double x = n->X();
723     double y = n->Y();
724     double z = n->Z();
725
726     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
727       SpinBox_X->SetValue(x);
728       SpinBox_Y->SetValue(y);
729       SpinBox_Z->SetValue(z);
730     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
731       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
732       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
733       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
734     }
735   }
736
737   myBusy = true;
738   if (myEditCurrentArgument == (QWidget*)LineEditElements)
739     LineEditElements->setText(aString);
740   myBusy = false;
741
742   // OK
743   if (myNbOkElements && IsAxisOk()) {
744     buttonOk->setEnabled(true);
745     buttonApply->setEnabled(true);
746   }
747 }
748
749 //=================================================================================
750 // function : SetEditCurrentArgument()
751 // purpose  :
752 //=================================================================================
753 void SMESHGUI_RevolutionDlg::SetEditCurrentArgument()
754 {
755   QPushButton* send = (QPushButton*)sender();
756
757   disconnect(mySelectionMgr, 0, this, 0);
758   mySelectionMgr->clearSelected();
759   mySelectionMgr->clearFilters();
760
761   if (send == SelectElementsButton) {
762     myEditCurrentArgument = (QWidget*)LineEditElements;
763     SMESH::SetPointRepresentation(false);
764     if (CheckBoxMesh->isChecked()) {
765       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
766         aViewWindow->SetSelectionMode(ActorSelection);
767       mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
768     } else {
769       int aConstructorId = GetConstructorId();
770       if (aConstructorId == 0)
771         {
772           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
773             aViewWindow->SetSelectionMode(EdgeSelection);
774         }
775       else if (aConstructorId == 1)
776         {
777           if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
778             aViewWindow->SetSelectionMode(FaceSelection);
779         }
780     }
781   } else if (send == SelectPointButton) {
782     myEditCurrentArgument = (QWidget*)SpinBox_X;
783     SMESH::SetPointRepresentation(true);
784     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
785       aViewWindow->SetSelectionMode(NodeSelection);
786   } else if (send == SelectVectorButton) {
787     myEditCurrentArgument = (QWidget*)SpinBox_DX;
788     SMESH::SetPointRepresentation(true);
789     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
790       aViewWindow->SetSelectionMode(NodeSelection);
791   } else {
792   }
793
794   myEditCurrentArgument->setFocus();
795   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
796   SelectionIntoArgument();
797 }
798
799 //=================================================================================
800 // function : DeactivateActiveDialog()
801 // purpose  :
802 //=================================================================================
803 void SMESHGUI_RevolutionDlg::DeactivateActiveDialog()
804 {
805   if (GroupConstructors->isEnabled()) {
806     GroupConstructors->setEnabled(false);
807     GroupArguments->setEnabled(false);
808     GroupButtons->setEnabled(false);
809     mySMESHGUI->ResetState();
810     mySMESHGUI->SetActiveDialogBox(0);
811   }
812 }
813
814 //=================================================================================
815 // function : ActivateThisDialog()
816 // purpose  :
817 //=================================================================================
818 void SMESHGUI_RevolutionDlg::ActivateThisDialog()
819 {
820   /* Emit a signal to deactivate the active dialog */
821   mySMESHGUI->EmitSignalDeactivateDialog();
822   GroupConstructors->setEnabled(true);
823   GroupArguments->setEnabled(true);
824   GroupButtons->setEnabled(true);
825
826   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
827
828   ConstructorsClicked(GetConstructorId());
829   SelectionIntoArgument();
830 }
831
832 //=================================================================================
833 // function : enterEvent()
834 // purpose  :
835 //=================================================================================
836 void SMESHGUI_RevolutionDlg::enterEvent (QEvent*)
837 {
838   if (!GroupConstructors->isEnabled())
839     ActivateThisDialog();
840 }
841
842 //=================================================================================
843 // function : closeEvent()
844 // purpose  :
845 //=================================================================================
846 void SMESHGUI_RevolutionDlg::closeEvent (QCloseEvent*)
847 {
848   /* same than click on cancel button */
849   this->ClickOnCancel();
850 }
851
852 //=======================================================================
853 // function : hideEvent()
854 // purpose  : caused by ESC key
855 //=======================================================================
856 void SMESHGUI_RevolutionDlg::hideEvent (QHideEvent*)
857 {
858   if (!isMinimized())
859     ClickOnCancel();
860 }
861
862 //=======================================================================
863 //function : onSelectMesh
864 //purpose  :
865 //=======================================================================
866 void SMESHGUI_RevolutionDlg::onSelectMesh (bool toSelectMesh)
867 {
868   if (toSelectMesh)
869     TextLabelElements->setText(tr("SMESH_NAME"));
870   else
871     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
872
873   if (myEditCurrentArgument != LineEditElements) {
874     LineEditElements->clear();
875     return;
876   }
877
878   mySelectionMgr->clearFilters();
879   SMESH::SetPointRepresentation(false);
880
881   if (toSelectMesh) {
882     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
883       aViewWindow->SetSelectionMode(ActorSelection);
884     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
885     LineEditElements->setReadOnly(true);
886   } else {
887     int aConstructorId = GetConstructorId();
888     if (aConstructorId == 0)
889       {
890         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
891           aViewWindow->SetSelectionMode(EdgeSelection);
892       }
893     else if (aConstructorId == 0)
894       {
895         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
896           aViewWindow->SetSelectionMode(FaceSelection);
897       }
898
899     LineEditElements->setReadOnly(false);
900     onTextChange(LineEditElements->text());
901   }
902
903   SelectionIntoArgument();
904 }
905
906 //=================================================================================
907 // function : GetConstructorId()
908 // purpose  :
909 //=================================================================================
910 int SMESHGUI_RevolutionDlg::GetConstructorId()
911 {
912   if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
913     return GroupConstructors->id(GroupConstructors->selected());
914   return -1;
915 }
916
917 //=================================================================================
918 // function : IsAxisOk()
919 // purpose  :
920 //=================================================================================
921 bool SMESHGUI_RevolutionDlg::IsAxisOk()
922 {
923   return (SpinBox_DX->GetValue() != 0 ||
924           SpinBox_DY->GetValue() != 0 ||
925           SpinBox_DZ->GetValue() != 0);
926 }
927
928 //=================================================================================
929 // function : onVectorChanged()
930 // purpose  :
931 //=================================================================================
932 void SMESHGUI_RevolutionDlg::onVectorChanged()
933 {
934   if (IsAxisOk()) {
935     buttonOk->setEnabled(true);
936     buttonApply->setEnabled(true);
937   } else {
938     buttonOk->setEnabled(false);
939     buttonApply->setEnabled(false);
940   }
941 }
942
943 //=================================================================================
944 // function : keyPressEvent()
945 // purpose  :
946 //=================================================================================
947 void SMESHGUI_RevolutionDlg::keyPressEvent( QKeyEvent* e )
948 {
949   QDialog::keyPressEvent( e );
950   if ( e->isAccepted() )
951     return;
952
953   if ( e->key() == Key_F1 )
954     {
955       e->accept();
956       ClickOnHelp();
957     }
958 }