Salome HOME
2f15f1882ba0d8de15098351db4472e3709a93e0
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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
45 #include "SVTK_ViewModel.h"
46 #include "SVTK_ViewWindow.h"
47 #include "SVTK_Selector.h"
48 #include "SVTK_Selection.h"
49 #include "SALOME_ListIO.hxx"
50
51 #include "utilities.h"
52
53 // OCCT Includes
54 #include <TColStd_MapOfInteger.hxx>
55 #include <TColStd_IndexedMapOfInteger.hxx>
56
57 // QT Includes
58 #include <qapplication.h>
59 #include <qbuttongroup.h>
60 #include <qgroupbox.h>
61 #include <qlabel.h>
62 #include <qlineedit.h>
63 #include <qpushbutton.h>
64 #include <qradiobutton.h>
65 #include <qcheckbox.h>
66 #include <qlayout.h>
67 #include <qspinbox.h>
68 #include <qvalidator.h>
69 #include <qpixmap.h>
70
71 // IDL Headers
72 #include "SALOMEconfig.h"
73 #include CORBA_SERVER_HEADER(SMESH_Group)
74
75 using namespace std;
76
77 //=================================================================================
78 // class    : SMESHGUI_RevolutionDlg()
79 // purpose  :
80 //=================================================================================
81 SMESHGUI_RevolutionDlg::SMESHGUI_RevolutionDlg( SMESHGUI* theModule, const char* name,
82                                                 bool modal, WFlags fl)
83      : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
84                 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
85      mySMESHGUI( theModule ),
86      mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
87 {
88   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
89   QPixmap image0 ( mgr->loadPixmap("SMESH", tr("ICON_DLG_EDGE")));
90   QPixmap image1 ( mgr->loadPixmap("SMESH", tr("ICON_DLG_TRIANGLE")));
91   QPixmap image2 ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
92
93   if (!name)
94     setName("SMESHGUI_RevolutionDlg");
95   resize(303, 185);
96   setCaption(tr("REVOLUTION_AROUND_AXIS"));
97   setSizeGripEnabled(TRUE);
98   SMESHGUI_RevolutionDlgLayout = new QGridLayout(this);
99   SMESHGUI_RevolutionDlgLayout->setSpacing(6);
100   SMESHGUI_RevolutionDlgLayout->setMargin(11);
101
102   /***************************************************************/
103   GroupConstructors = new QButtonGroup(this, "GroupConstructors");
104   GroupConstructors->setTitle(tr("SMESH_REVOLUTION" ));
105   GroupConstructors->setExclusive(TRUE);
106   GroupConstructors->setColumnLayout(0, Qt::Vertical);
107   GroupConstructors->layout()->setSpacing(0);
108   GroupConstructors->layout()->setMargin(0);
109   GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
110   GroupConstructorsLayout->setAlignment(Qt::AlignTop);
111   GroupConstructorsLayout->setSpacing(6);
112   GroupConstructorsLayout->setMargin(11);
113   RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
114   RadioButton1->setText(tr("" ));
115   RadioButton1->setPixmap(image0);
116   GroupConstructorsLayout->addWidget(RadioButton1, 0, 0);
117   RadioButton2= new QRadioButton(GroupConstructors, "RadioButton2");
118   RadioButton2->setText(tr("" ));
119   RadioButton2->setPixmap(image1);
120   GroupConstructorsLayout->addWidget(RadioButton2, 0, 2);
121   SMESHGUI_RevolutionDlgLayout->addWidget(GroupConstructors, 0, 0);
122
123   /***************************************************************/
124   GroupButtons = new QGroupBox(this, "GroupButtons");
125   GroupButtons->setGeometry(QRect(10, 10, 281, 48));
126   GroupButtons->setTitle(tr("" ));
127   GroupButtons->setColumnLayout(0, Qt::Vertical);
128   GroupButtons->layout()->setSpacing(0);
129   GroupButtons->layout()->setMargin(0);
130   GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
131   GroupButtonsLayout->setAlignment(Qt::AlignTop);
132   GroupButtonsLayout->setSpacing(6);
133   GroupButtonsLayout->setMargin(11);
134   buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
135   buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
136   buttonCancel->setAutoDefault(TRUE);
137   GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
138   buttonApply = new QPushButton(GroupButtons, "buttonApply");
139   buttonApply->setText(tr("SMESH_BUT_APPLY" ));
140   buttonApply->setAutoDefault(TRUE);
141   GroupButtonsLayout->addWidget(buttonApply, 0, 1);
142   QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
143   GroupButtonsLayout->addItem(spacer_9, 0, 2);
144   buttonOk = new QPushButton(GroupButtons, "buttonOk");
145   buttonOk->setText(tr("SMESH_BUT_OK" ));
146   buttonOk->setAutoDefault(TRUE);
147   buttonOk->setDefault(TRUE);
148   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
149   SMESHGUI_RevolutionDlgLayout->addWidget(GroupButtons, 2, 0);
150
151   /***************************************************************/
152   GroupArguments = new QGroupBox(this, "GroupArguments");
153   GroupArguments->setTitle(tr("REVOLUTION_1D"));
154   GroupArguments->setColumnLayout(0, Qt::Vertical);
155   GroupArguments->layout()->setSpacing(0);
156   GroupArguments->layout()->setMargin(0);
157   GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
158   GroupArgumentsLayout->setAlignment(Qt::AlignTop);
159   GroupArgumentsLayout->setSpacing(6);
160   GroupArgumentsLayout->setMargin(11);
161
162   // Controls for elements selection
163   TextLabelElements  = new QLabel(GroupArguments, "TextLabelElements");
164   TextLabelElements->setText(tr("SMESH_ID_ELEMENTS" ));
165   TextLabelElements->setFixedWidth(74);
166   GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
167
168   SelectElementsButton  = new QPushButton(GroupArguments, "SelectElementsButton");
169   SelectElementsButton->setText(tr("" ));
170   SelectElementsButton->setPixmap(image2);
171   SelectElementsButton->setToggleButton(FALSE);
172   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
173
174   LineEditElements  = new QLineEdit(GroupArguments, "LineEditElements");
175   LineEditElements->setValidator(new SMESHGUI_IdValidator(this, "validator"));
176   GroupArgumentsLayout->addWidget(LineEditElements, 0, 2);
177
178   // Control for the whole mesh selection
179   CheckBoxMesh = new QCheckBox(GroupArguments, "CheckBoxMesh");
180   CheckBoxMesh->setText(tr("SMESH_SELECT_WHOLE_MESH" ));
181   GroupArgumentsLayout->addMultiCellWidget(CheckBoxMesh, 1, 1, 0, 3);
182
183   // Controls for axis defining
184   GroupAxis = new QGroupBox(GroupArguments, "GroupAxis");
185   GroupAxis->setTitle(tr("SMESH_AXIS"));
186   GroupAxis->setColumnLayout(0, Qt::Vertical);
187   GroupAxis->layout()->setSpacing(0);
188   GroupAxis->layout()->setMargin(0);
189   QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis->layout());
190   GroupAxisLayout->setAlignment(Qt::AlignTop);
191   GroupAxisLayout->setSpacing(6);
192   GroupAxisLayout->setMargin(11);
193
194   TextLabelPoint = new QLabel(GroupAxis, "TextLabelPoint");
195   TextLabelPoint->setText(tr("SMESH_POINT"));
196   GroupAxisLayout->addWidget(TextLabelPoint, 0, 0);
197
198   SelectPointButton  = new QPushButton(GroupAxis, "SelectPointButton");
199   SelectPointButton->setPixmap(image2);
200   GroupAxisLayout->addWidget(SelectPointButton, 0, 1);
201
202   TextLabelX = new QLabel(GroupAxis, "TextLabelX");
203   TextLabelX->setText(tr("SMESH_X"));
204   GroupAxisLayout->addWidget(TextLabelX, 0, 2);
205
206   SpinBox_X = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_X");
207   GroupAxisLayout->addWidget(SpinBox_X, 0, 3);
208
209   TextLabelY = new QLabel(GroupAxis, "TextLabelY");
210   TextLabelY->setText(tr("SMESH_Y"));
211   GroupAxisLayout->addWidget(TextLabelY, 0, 4);
212
213   SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_Y");
214   GroupAxisLayout->addWidget(SpinBox_Y, 0, 5);
215
216   TextLabelZ = new QLabel(GroupAxis, "TextLabelZ");
217   TextLabelZ->setText(tr("SMESH_Z"));
218   GroupAxisLayout->addWidget(TextLabelZ, 0, 6);
219
220   SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_Z");
221   GroupAxisLayout->addWidget(SpinBox_Z, 0, 7);
222
223   TextLabelVector = new QLabel(GroupAxis, "TextLabelVector");
224   TextLabelVector->setText(tr("SMESH_VECTOR"));
225   GroupAxisLayout->addWidget(TextLabelVector, 1, 0);
226
227   SelectVectorButton = new QPushButton(GroupAxis, "SelectVectorButton");
228   SelectVectorButton->setPixmap(image2);
229   GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
230
231   TextLabelDX = new QLabel(GroupAxis, "TextLabelDX");
232   TextLabelDX->setText(tr("SMESH_DX"));
233   GroupAxisLayout->addWidget(TextLabelDX, 1, 2);
234
235   SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_DX");
236   GroupAxisLayout->addWidget(SpinBox_DX, 1, 3);
237
238   TextLabelDY = new QLabel(GroupAxis, "TextLabelDY");
239   TextLabelDY->setText(tr("SMESH_DY"));
240   GroupAxisLayout->addWidget(TextLabelDY, 1, 4);
241
242   SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_DY");
243   GroupAxisLayout->addWidget(SpinBox_DY, 1, 5);
244
245   TextLabelDZ = new QLabel(GroupAxis, "TextLabelDZ");
246   TextLabelDZ->setText(tr("SMESH_DZ"));
247   GroupAxisLayout->addWidget(TextLabelDZ, 1, 6);
248
249   SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_DZ");
250   GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7);
251
252   GroupArgumentsLayout->addMultiCellWidget(GroupAxis, 2, 2, 0, 3);
253
254   // Controls for angle defining
255   TextLabelAngle = new QLabel(GroupArguments, "TextLabelAngle");
256   TextLabelAngle->setText(tr("SMESH_ANGLE" ));
257   GroupArgumentsLayout->addMultiCellWidget(TextLabelAngle, 3, 3, 0, 1);
258
259   SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments, "SpinBox_Angle");
260   GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
261
262   // Controls for nb. steps defining
263   TextLabelNbSteps = new QLabel(GroupArguments, "TextLabelNbSteps");
264   TextLabelNbSteps->setText(tr("SMESH_NUMBEROFSTEPS" ));
265   GroupArgumentsLayout->addMultiCellWidget(TextLabelNbSteps, 4, 4, 0, 1);
266
267   SpinBox_NbSteps = new QSpinBox(GroupArguments, "SpinBox_NbSteps");
268   GroupArgumentsLayout->addWidget(SpinBox_NbSteps, 4, 2);
269
270   // Controls for tolerance defining
271   TextLabelTolerance = new QLabel(GroupArguments, "TextLabelTolerance");
272   TextLabelTolerance->setText(tr("SMESH_TOLERANCE"));
273   GroupArgumentsLayout->addMultiCellWidget(TextLabelTolerance, 5, 5, 0, 1);
274
275   SpinBox_Tolerance = new SMESHGUI_SpinBox(GroupArguments, "SpinBox_Tolerance");
276   GroupArgumentsLayout->addWidget(SpinBox_Tolerance, 5, 2);
277
278   SMESHGUI_RevolutionDlgLayout->addWidget(GroupArguments, 1, 0);
279
280   /* Initialisations */
281   SpinBox_X->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
282   SpinBox_Y->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
283   SpinBox_Z->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
284   SpinBox_DX->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
285   SpinBox_DY->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
286   SpinBox_DZ->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
287
288   SpinBox_Angle->RangeStepAndValidator(-999999.999, +999999.999, 5.0, 3);
289
290   QIntValidator* anIntValidator = new QIntValidator(SpinBox_NbSteps);
291   SpinBox_NbSteps->setValidator(anIntValidator);
292   SpinBox_NbSteps->setRange(1, 999999);
293
294   SpinBox_Tolerance->RangeStepAndValidator(0.0, +999999.999, 0.1, 6);
295
296   GroupArguments->show();
297   RadioButton1->setChecked(TRUE);
298
299   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
300
301   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
302
303   // Costruction of the logical filter
304   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
305   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
306
307   QPtrList<SUIT_SelectionFilter> aListOfFilters;
308   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
309   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
310
311   myMeshOrSubMeshOrGroupFilter =
312     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
313
314   Init();
315
316   /* signals and slots connections */
317   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
318   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
319   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
320   connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
321
322   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
323   connect(SelectPointButton, SIGNAL (clicked()),    this, SLOT(SetEditCurrentArgument()));
324   connect(SelectVectorButton, SIGNAL (clicked()),   this, SLOT(SetEditCurrentArgument()));
325
326   connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
327   connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
328   connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
329
330   connect(mySMESHGUI,     SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
331   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),      this, SLOT(SelectionIntoArgument()));
332   /* to close dialog if study change */
333   connect(mySMESHGUI,       SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
334   connect(LineEditElements, SIGNAL(textChanged(const QString&)),   SLOT(onTextChange(const QString&)));
335   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                 SLOT(onSelectMesh(bool)));
336
337   /* Move widget on the botton right corner of main widget */
338   int x, y;
339   mySMESHGUI->DefineDlgPosition(this, x, y);
340   this->move(x, y);
341   this->show(); /* displays Dialog */
342
343   ConstructorsClicked(0);
344   resize(0,0); // ??
345 }
346
347 //=================================================================================
348 // function : ~SMESHGUI_RevolutionDlg()
349 // purpose  : Destroys the object and frees any allocated resources
350 //=================================================================================
351 SMESHGUI_RevolutionDlg::~SMESHGUI_RevolutionDlg()
352 {
353   // no need to delete child widgets, Qt does it all for us
354 }
355
356 //=================================================================================
357 // function : Init()
358 // purpose  :
359 //=================================================================================
360 void SMESHGUI_RevolutionDlg::Init (bool ResetControls)
361 {
362   myBusy = false;
363
364   myEditCurrentArgument = 0;
365   LineEditElements->clear();
366   myElementsId = "";
367   myNbOkElements = 0;
368
369   myActor = 0;
370   myMesh = SMESH::SMESH_Mesh::_nil();
371
372   if (ResetControls) {
373     SpinBox_X->SetValue(0.0);
374     SpinBox_Y->SetValue(0.0);
375     SpinBox_Z->SetValue(0.0);
376     SpinBox_DX->SetValue(0.0);
377     SpinBox_DY->SetValue(0.0);
378     SpinBox_DZ->SetValue(0.0);
379
380     SpinBox_Angle->SetValue(45);
381     SpinBox_NbSteps->setValue(1);
382     SpinBox_Tolerance->SetValue(1e-05);
383
384     CheckBoxMesh->setChecked(false);
385     onSelectMesh(false);
386   }
387 }
388
389 //=================================================================================
390 // function : ConstructorsClicked()
391 // purpose  : Radio button management
392 //=================================================================================
393 void SMESHGUI_RevolutionDlg::ConstructorsClicked (int constructorId)
394 {
395   disconnect(mySelectionMgr, 0, this, 0);
396
397   Selection_Mode aSelMode = ActorSelection;
398
399   switch (constructorId) {
400   case 0:
401     {
402       GroupArguments->setTitle(tr("REVOLUTION_1D"));
403       aSelMode = EdgeSelection;
404       break;
405     }
406   case 1:
407     {
408       GroupArguments->setTitle(tr("REVOLUTION_2D"));
409       aSelMode = FaceSelection;
410       break;
411     }
412   }
413
414   if (myEditCurrentArgument != (QWidget*)LineEditElements) {
415     SMESH::SetPointRepresentation(false);
416   }
417
418   if (!CheckBoxMesh->isChecked())
419     {
420       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
421         aViewWindow->SetSelectionMode(aSelMode);
422     }
423
424   myEditCurrentArgument = (QWidget*)LineEditElements;
425   LineEditElements->setFocus();
426
427   if (CheckBoxMesh->isChecked())
428     onSelectMesh(true);
429
430   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
431 }
432
433 //=================================================================================
434 // function : ClickOnApply()
435 // purpose  :
436 //=================================================================================
437 void SMESHGUI_RevolutionDlg::ClickOnApply()
438 {
439   if (mySMESHGUI->isActiveStudyLocked())
440     return;
441
442   if (myNbOkElements && IsAxisOk()) {
443     QStringList aListElementsId = QStringList::split(" ", myElementsId, false);
444
445     SMESH::long_array_var anElementsId = new SMESH::long_array;
446
447     anElementsId->length(aListElementsId.count());
448     for (int i = 0; i < aListElementsId.count(); i++)
449       anElementsId[i] = aListElementsId[i].toInt();
450
451     SMESH::AxisStruct anAxis;
452
453     anAxis.x =  SpinBox_X->GetValue();
454     anAxis.y =  SpinBox_Y->GetValue();
455     anAxis.z =  SpinBox_Z->GetValue();;
456     anAxis.vx = SpinBox_DX->GetValue();
457     anAxis.vy = SpinBox_DY->GetValue();
458     anAxis.vz = SpinBox_DZ->GetValue();
459
460     double anAngle = (SpinBox_Angle->GetValue())*PI/180;
461     long aNbSteps = (long)SpinBox_NbSteps->value();
462     double aTolerance = SpinBox_Tolerance->GetValue();
463
464     try {
465       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
466       QApplication::setOverrideCursor(Qt::waitCursor);
467       aMeshEditor->RotationSweep(anElementsId.inout(), anAxis, anAngle, aNbSteps, aTolerance);
468       QApplication::restoreOverrideCursor();
469     } catch (...) {
470     }
471
472     mySelectionMgr->clearSelected();
473     SMESH::UpdateView();
474     Init(false);
475     ConstructorsClicked(GetConstructorId());
476   }
477 }
478
479 //=================================================================================
480 // function : ClickOnOk()
481 // purpose  :
482 //=================================================================================
483 void SMESHGUI_RevolutionDlg::ClickOnOk()
484 {
485   ClickOnApply();
486   ClickOnCancel();
487 }
488
489 //=================================================================================
490 // function : ClickOnCancel()
491 // purpose  :
492 //=================================================================================
493 void SMESHGUI_RevolutionDlg::ClickOnCancel()
494 {
495   disconnect(mySelectionMgr, 0, this, 0);
496   mySelectionMgr->clearFilters();
497   mySelectionMgr->clearSelected();
498   SMESH::SetPointRepresentation(false);
499   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
500     aViewWindow->SetSelectionMode(ActorSelection);
501   mySMESHGUI->ResetState();
502   reject();
503 }
504
505 //=======================================================================
506 // function : onTextChange()
507 // purpose  :
508 //=======================================================================
509 void SMESHGUI_RevolutionDlg::onTextChange (const QString& theNewText)
510 {
511   QLineEdit* send = (QLineEdit*)sender();
512
513   if (myBusy) return;
514   myBusy = true;
515
516   if (send == LineEditElements)
517     myNbOkElements = 0;
518
519   buttonOk->setEnabled(false);
520   buttonApply->setEnabled(false);
521
522   // hilight entered elements
523   SMDS_Mesh* aMesh = 0;
524   if (myActor)
525     aMesh = myActor->GetObject()->GetMesh();
526
527   if (aMesh) {
528     if (send == LineEditElements) {
529       Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
530
531       TColStd_MapOfInteger newIndices;
532
533       QStringList aListId = QStringList::split(" ", theNewText, false);
534       
535       for (int i = 0; i < aListId.count(); i++) {
536         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
537         if (e)
538           newIndices.Add(e->GetID());
539         myNbOkElements++;
540       }
541
542       mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
543       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
544         aViewWindow->highlight( myActor->getIO(), true, true );
545       
546       myElementsId = theNewText;
547     }
548   }
549
550   if (myNbOkElements && IsAxisOk()) {
551     buttonOk->setEnabled(true);
552     buttonApply->setEnabled(true);
553   }
554
555   myBusy = false;
556 }
557
558 //=================================================================================
559 // function : SelectionIntoArgument()
560 // purpose  : Called when selection as changed or other case
561 //=================================================================================
562 void SMESHGUI_RevolutionDlg::SelectionIntoArgument()
563 {
564   if (myBusy) return;
565
566   // clear
567   myActor = 0;
568   QString aString = "";
569
570   myBusy = true;
571   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
572     LineEditElements->setText(aString);
573     myNbOkElements = 0;
574     buttonOk->setEnabled(false);
575     buttonApply->setEnabled(false);
576   }
577   myBusy = false;
578
579   if (!GroupButtons->isEnabled()) // inactive
580     return;
581
582   // get selected mesh
583   const SALOME_ListIO& aList = mySelector->StoredIObjects();
584
585   int nbSel = aList.Extent();
586   if (nbSel != 1)
587     return;
588
589   Handle(SALOME_InteractiveObject) IO = aList.First();
590   myMesh = SMESH::GetMeshByIO(IO);
591   if (myMesh->_is_nil())
592     return;
593
594   myActor = SMESH::FindActorByObject(myMesh);
595   if (!myActor)
596     myActor = SMESH::FindActorByEntry(IO->getEntry());
597   if (!myActor)
598     return;
599
600   int aNbUnits = 0;
601
602   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
603     myElementsId = "";
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, myActor->getIO(), aString);
671       myElementsId = aString;
672     }
673
674     if (aNbUnits < 1)
675       return;
676
677     myNbOkElements = true;
678   } else {
679     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), 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 (GroupConstructors->isEnabled()) {
775     GroupConstructors->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   GroupConstructors->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 (!GroupConstructors->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   this->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   if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
882     return GroupConstructors->id(GroupConstructors->selected());
883   return -1;
884 }
885
886 //=================================================================================
887 // function : IsAxisOk()
888 // purpose  :
889 //=================================================================================
890 bool SMESHGUI_RevolutionDlg::IsAxisOk()
891 {
892   return (SpinBox_DX->GetValue() != 0 ||
893           SpinBox_DY->GetValue() != 0 ||
894           SpinBox_DZ->GetValue() != 0);
895 }
896
897 //=================================================================================
898 // function : onVectorChanged()
899 // purpose  :
900 //=================================================================================
901 void SMESHGUI_RevolutionDlg::onVectorChanged()
902 {
903   if (IsAxisOk()) {
904     buttonOk->setEnabled(true);
905     buttonApply->setEnabled(true);
906   } else {
907     buttonOk->setEnabled(false);
908     buttonApply->setEnabled(false);
909   }
910 }