Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_RotationDlg.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_RotationDlg.cxx
25 //  Author : Michael ZORIN
26 //  Module : SMESH
27 //  $Header:
28
29 #include "SMESHGUI_RotationDlg.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_Desktop.h"
44 #include "SUIT_Session.h"
45
46 #include "SVTK_ViewModel.h"
47 #include "SVTK_ViewWindow.h"
48 #include "SVTK_Selector.h"
49 #include "SVTK_Selection.h"
50 #include "SALOME_ListIO.hxx"
51
52 #include "utilities.h"
53
54 // OCCT Includes
55 #include <TColStd_MapOfInteger.hxx>
56 #include <TColStd_IndexedMapOfInteger.hxx>
57
58 // QT Includes
59 #include <qapplication.h>
60 #include <qbuttongroup.h>
61 #include <qgroupbox.h>
62 #include <qlabel.h>
63 #include <qlineedit.h>
64 #include <qpushbutton.h>
65 #include <qradiobutton.h>
66 #include <qcheckbox.h>
67 #include <qlayout.h>
68 #include <qpixmap.h>
69
70 // IDL Headers
71 #include "SALOMEconfig.h"
72 #include CORBA_SERVER_HEADER(SMESH_Group)
73
74 using namespace std;
75
76 //=================================================================================
77 // class    : SMESHGUI_RotationDlg()
78 // purpose  :
79 //=================================================================================
80 SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule, const char* name,
81                                             bool modal, WFlags fl)
82      : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
83                WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
84      mySMESHGUI( theModule ),
85      mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
86 {
87   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_ROTATION")));
88   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
89
90   if (!name)
91     setName("SMESHGUI_RotationDlg");
92   resize(303, 185);
93   setCaption(tr("SMESH_ROTATION_TITLE"));
94   setSizeGripEnabled(TRUE);
95   SMESHGUI_RotationDlgLayout = new QGridLayout(this);
96   SMESHGUI_RotationDlgLayout->setSpacing(6);
97   SMESHGUI_RotationDlgLayout->setMargin(11);
98
99   /***************************************************************/
100   GroupConstructors = new QButtonGroup(this, "GroupConstructors");
101   GroupConstructors->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5,
102                                                (QSizePolicy::SizeType)0, 0, 0,
103                                                GroupConstructors->sizePolicy().hasHeightForWidth()));
104   GroupConstructors->setTitle(tr("SMESH_ROTATION"));
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   RadioButton1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)1,
117                                           (QSizePolicy::SizeType)0,
118                                           RadioButton1->sizePolicy().hasHeightForWidth()));
119   RadioButton1->setMinimumSize(QSize(50, 0));
120   GroupConstructorsLayout->addWidget(RadioButton1, 0, 0);
121   QSpacerItem* spacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
122   GroupConstructorsLayout->addItem(spacer, 0, 1);
123   SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors, 0, 0);
124
125   /***************************************************************/
126   GroupButtons = new QGroupBox(this, "GroupButtons");
127   GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
128                                           (QSizePolicy::SizeType)0, 0, 0,
129                                           GroupButtons->sizePolicy().hasHeightForWidth()));
130   GroupButtons->setGeometry(QRect(10, 10, 281, 48));
131   GroupButtons->setTitle(tr("" ));
132   GroupButtons->setColumnLayout(0, Qt::Vertical);
133   GroupButtons->layout()->setSpacing(0);
134   GroupButtons->layout()->setMargin(0);
135   GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
136   GroupButtonsLayout->setAlignment(Qt::AlignTop);
137   GroupButtonsLayout->setSpacing(6);
138   GroupButtonsLayout->setMargin(11);
139   buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
140   buttonCancel->setText(tr("SMESH_BUT_CLOSE"));
141   buttonCancel->setAutoDefault(TRUE);
142   GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
143   buttonApply = new QPushButton(GroupButtons, "buttonApply");
144   buttonApply->setText(tr("SMESH_BUT_APPLY"));
145   buttonApply->setAutoDefault(TRUE);
146   GroupButtonsLayout->addWidget(buttonApply, 0, 1);
147   QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
148   GroupButtonsLayout->addItem(spacer_9, 0, 2);
149   buttonOk = new QPushButton(GroupButtons, "buttonOk");
150   buttonOk->setText(tr("SMESH_BUT_OK"));
151   buttonOk->setAutoDefault(TRUE);
152   buttonOk->setDefault(TRUE);
153   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
154   SMESHGUI_RotationDlgLayout->addWidget(GroupButtons, 2, 0);
155
156   /***************************************************************/
157   GroupArguments = new QGroupBox(this, "GroupArguments");
158   GroupArguments->setTitle(tr("SMESH_ARGUMENTS"));
159   GroupArguments->setColumnLayout(0, Qt::Vertical);
160   GroupArguments->layout()->setSpacing(0);
161   GroupArguments->layout()->setMargin(0);
162   GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
163   GroupArgumentsLayout->setAlignment(Qt::AlignTop);
164   GroupArgumentsLayout->setSpacing(6);
165   GroupArgumentsLayout->setMargin(11);
166
167   // Controls for elements selection
168   TextLabelElements  = new QLabel(GroupArguments, "TextLabelElements");
169   TextLabelElements->setText(tr("SMESH_ID_ELEMENTS" ));
170   TextLabelElements->setFixedWidth(74);
171   GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
172
173   SelectElementsButton  = new QPushButton(GroupArguments, "SelectElementsButton");
174   SelectElementsButton->setText(tr("" ));
175   SelectElementsButton->setPixmap(image1);
176   SelectElementsButton->setToggleButton(FALSE);
177   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
178
179   LineEditElements  = new QLineEdit(GroupArguments, "LineEditElements");
180   LineEditElements->setValidator(new SMESHGUI_IdValidator(this, "validator"));
181   GroupArgumentsLayout->addWidget(LineEditElements, 0, 2);
182
183   // Control for the whole mesh selection
184   CheckBoxMesh = new QCheckBox(GroupArguments, "CheckBoxMesh");
185   CheckBoxMesh->setText(tr("SMESH_SELECT_WHOLE_MESH" ));
186   GroupArgumentsLayout->addMultiCellWidget(CheckBoxMesh, 1, 1, 0, 2);
187
188   // Controls for axis defining
189   GroupAxis = new QGroupBox(GroupArguments, "GroupAxis");
190   GroupAxis->setTitle(tr("SMESH_AXIS"));
191   GroupAxis->setColumnLayout(0, Qt::Vertical);
192   GroupAxis->layout()->setSpacing(0);
193   GroupAxis->layout()->setMargin(0);
194   QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis->layout());
195   GroupAxisLayout->setAlignment(Qt::AlignTop);
196   GroupAxisLayout->setSpacing(6);
197   GroupAxisLayout->setMargin(11);
198
199   TextLabelPoint = new QLabel(GroupAxis, "TextLabelPoint");
200   TextLabelPoint->setText(tr("SMESH_POINT"));
201   GroupAxisLayout->addWidget(TextLabelPoint, 0, 0);
202
203   SelectPointButton  = new QPushButton(GroupAxis, "SelectPointButton");
204   SelectPointButton->setPixmap(image1);
205   GroupAxisLayout->addWidget(SelectPointButton, 0, 1);
206
207   TextLabelX = new QLabel(GroupAxis, "TextLabelX");
208   TextLabelX->setText(tr("SMESH_X"));
209   GroupAxisLayout->addWidget(TextLabelX, 0, 2);
210
211   SpinBox_X = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_X");
212   GroupAxisLayout->addWidget(SpinBox_X, 0, 3);
213
214   TextLabelY = new QLabel(GroupAxis, "TextLabelY");
215   TextLabelY->setText(tr("SMESH_Y"));
216   GroupAxisLayout->addWidget(TextLabelY, 0, 4);
217
218   SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_Y");
219   GroupAxisLayout->addWidget(SpinBox_Y, 0, 5);
220
221   TextLabelZ = new QLabel(GroupAxis, "TextLabelZ");
222   TextLabelZ->setText(tr("SMESH_Z"));
223   GroupAxisLayout->addWidget(TextLabelZ, 0, 6);
224
225   SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_Z");
226   GroupAxisLayout->addWidget(SpinBox_Z, 0, 7);
227
228   TextLabelVector = new QLabel(GroupAxis, "TextLabelVector");
229   TextLabelVector->setText(tr("SMESH_VECTOR"));
230   GroupAxisLayout->addWidget(TextLabelVector, 1, 0);
231
232   SelectVectorButton = new QPushButton(GroupAxis, "SelectVectorButton");
233   SelectVectorButton->setPixmap(image1);
234   GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
235
236   TextLabelDX = new QLabel(GroupAxis, "TextLabelDX");
237   TextLabelDX->setText(tr("SMESH_DX"));
238   GroupAxisLayout->addWidget(TextLabelDX, 1, 2);
239
240   SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_DX");
241   GroupAxisLayout->addWidget(SpinBox_DX, 1, 3);
242
243   TextLabelDY = new QLabel(GroupAxis, "TextLabelDY");
244   TextLabelDY->setText(tr("SMESH_DY"));
245   GroupAxisLayout->addWidget(TextLabelDY, 1, 4);
246
247   SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_DY");
248   GroupAxisLayout->addWidget(SpinBox_DY, 1, 5);
249
250   TextLabelDZ = new QLabel(GroupAxis, "TextLabelDZ");
251   TextLabelDZ->setText(tr("SMESH_DZ"));
252   GroupAxisLayout->addWidget(TextLabelDZ, 1, 6);
253
254   SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_DZ");
255   GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7);
256
257   GroupArgumentsLayout->addMultiCellWidget(GroupAxis, 2, 2, 0, 2);
258
259   // Controls for angle defining
260   TextLabelAngle = new QLabel(GroupArguments, "TextLabelAngle");
261   TextLabelAngle->setText(tr("SMESH_ANGLE"));
262   GroupArgumentsLayout->addMultiCellWidget(TextLabelAngle, 3, 3, 0, 1);
263
264   SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments, "SpinBox_Angle");
265   GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
266
267   // Controls for "Create a copy" option
268   CheckBoxCopy = new QCheckBox(GroupArguments, "CheckBoxCopy");
269   CheckBoxCopy->setText(tr("SMESH_CREATE_COPY"));
270   GroupArgumentsLayout->addMultiCellWidget(CheckBoxCopy, 4, 4, 0, 2);
271
272   SMESHGUI_RotationDlgLayout->addWidget(GroupArguments, 1, 0);
273
274   /* Initialisations */
275   SpinBox_X->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
276   SpinBox_Y->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
277   SpinBox_Z->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
278   SpinBox_DX->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
279   SpinBox_DY->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
280   SpinBox_DZ->RangeStepAndValidator(-999999.999, +999999.999, 10.0, 3);
281
282   SpinBox_Angle->RangeStepAndValidator(-999999.999, +999999.999, 5.0, 3);
283
284   GroupArguments->show();
285   myConstructorId = 0;
286   RadioButton1->setChecked(TRUE);
287
288   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
289
290   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
291
292   // Costruction of the logical filter
293   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
294   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
295
296   QPtrList<SUIT_SelectionFilter> aListOfFilters;
297   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
298   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
299
300   myMeshOrSubMeshOrGroupFilter =
301     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
302
303   Init();
304
305   /* signals and slots connections */
306   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
307   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
308   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
309   connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
310
311   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
312   connect(SelectPointButton, SIGNAL (clicked()),    this, SLOT(SetEditCurrentArgument()));
313   connect(SelectVectorButton, SIGNAL (clicked()),   this, SLOT(SetEditCurrentArgument()));
314
315   connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
316   connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
317   connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
318
319   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
320   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),   this, SLOT(SelectionIntoArgument()));
321   /* to close dialog if study change */
322   connect(mySMESHGUI,       SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
323   connect(LineEditElements, SIGNAL(textChanged(const QString&)),    SLOT(onTextChange(const QString&)));
324   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                  SLOT(onSelectMesh(bool)));
325
326   this->show(); /* displays Dialog */
327
328   ConstructorsClicked(0);
329   resize(0,0); // ??
330 }
331
332 //=================================================================================
333 // function : ~SMESHGUI_RotationDlg()
334 // purpose  : Destroys the object and frees any allocated resources
335 //=================================================================================
336 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
337 {
338   // no need to delete child widgets, Qt does it all for us
339 }
340
341 //=================================================================================
342 // function : Init()
343 // purpose  :
344 //=================================================================================
345 void SMESHGUI_RotationDlg::Init (bool ResetControls)
346 {
347   myBusy = false;
348
349   myEditCurrentArgument = (QWidget*)LineEditElements;
350   LineEditElements->setFocus();
351   myElementsId = "";
352   myNbOkElements = 0;
353
354   buttonOk->setEnabled(false);
355   buttonApply->setEnabled(false);
356
357   myActor = 0;
358   myMesh = SMESH::SMESH_Mesh::_nil();
359
360   if (ResetControls) {
361     SpinBox_X->SetValue(0.0);
362     SpinBox_Y->SetValue(0.0);
363     SpinBox_Z->SetValue(0.0);
364     SpinBox_DX->SetValue(0.0);
365     SpinBox_DY->SetValue(0.0);
366     SpinBox_DZ->SetValue(0.0);
367
368     SpinBox_Angle->SetValue(45);
369
370     CheckBoxCopy->setChecked(false);
371     CheckBoxMesh->setChecked(false);
372   }
373
374   onSelectMesh(CheckBoxMesh->isChecked());
375 }
376
377 //=================================================================================
378 // function : ConstructorsClicked()
379 // purpose  : Radio button management
380 //=================================================================================
381 void SMESHGUI_RotationDlg::ConstructorsClicked (int constructorId)
382 {
383 }
384
385 //=================================================================================
386 // function : ClickOnApply()
387 // purpose  :
388 //=================================================================================
389 void SMESHGUI_RotationDlg::ClickOnApply()
390 {
391   if (mySMESHGUI->isActiveStudyLocked())
392     return;
393
394   if (myNbOkElements && IsAxisOk()) {
395     QStringList aListElementsId = QStringList::split(" ", myElementsId, false);
396
397     SMESH::long_array_var anElementsId = new SMESH::long_array;
398
399     anElementsId->length(aListElementsId.count());
400     for (int i = 0; i < aListElementsId.count(); i++)
401       anElementsId[i] = aListElementsId[i].toInt();
402
403     SMESH::AxisStruct anAxis;
404
405     anAxis.x =  SpinBox_X->GetValue();
406     anAxis.y =  SpinBox_Y->GetValue();
407     anAxis.z =  SpinBox_Z->GetValue();;
408     anAxis.vx = SpinBox_DX->GetValue();
409     anAxis.vy = SpinBox_DY->GetValue();
410     anAxis.vz = SpinBox_DZ->GetValue();
411
412     double anAngle = (SpinBox_Angle->GetValue())*PI/180;
413     bool toCreateCopy = CheckBoxCopy->isChecked();
414
415     try {
416       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
417       QApplication::setOverrideCursor(Qt::waitCursor);
418       aMeshEditor->Rotate(anElementsId.inout(), anAxis, anAngle, toCreateCopy);
419       QApplication::restoreOverrideCursor();
420     } catch (...) {
421     }
422
423     SMESH::UpdateView();
424     Init(false);
425     SelectionIntoArgument();
426   }
427 }
428
429 //=================================================================================
430 // function : ClickOnOk()
431 // purpose  :
432 //=================================================================================
433 void SMESHGUI_RotationDlg::ClickOnOk()
434 {
435   ClickOnApply();
436   ClickOnCancel();
437 }
438
439 //=================================================================================
440 // function : ClickOnCancel()
441 // purpose  :
442 //=================================================================================
443 void SMESHGUI_RotationDlg::ClickOnCancel()
444 {
445   disconnect(mySelectionMgr, 0, this, 0);
446   mySelectionMgr->clearFilters();
447   //mySelectionMgr->clearSelected();
448   SMESH::SetPointRepresentation(false);
449   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
450     aViewWindow->SetSelectionMode(ActorSelection);
451   mySMESHGUI->ResetState();
452   reject();
453 }
454
455 //=======================================================================
456 // function : onTextChange()
457 // purpose  :
458 //=======================================================================
459 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
460 {
461   QLineEdit* send = (QLineEdit*)sender();
462
463   if (myBusy) return;
464   myBusy = true;
465
466   if (send == LineEditElements)
467     myNbOkElements = 0;
468
469   buttonOk->setEnabled(false);
470   buttonApply->setEnabled(false);
471
472   // hilight entered elements
473   SMDS_Mesh* aMesh = 0;
474   if (myActor)
475     aMesh = myActor->GetObject()->GetMesh();
476
477   if (aMesh) {
478     if (send == LineEditElements) {
479       Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
480       
481       TColStd_MapOfInteger newIndices;
482       
483       QStringList aListId = QStringList::split(" ", theNewText, false);
484       for (int i = 0; i < aListId.count(); i++) {
485         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
486         if (e)
487           newIndices.Add(e->GetID());
488         myNbOkElements++;
489       }
490
491       mySelector->AddOrRemoveIndex( anIO, newIndices, false );
492       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
493         aViewWindow->highlight( anIO, true, true );
494       
495       myElementsId = theNewText;
496     }
497   }
498
499   if (myNbOkElements && IsAxisOk()) {
500     buttonOk->setEnabled(true);
501     buttonApply->setEnabled(true);
502   }
503
504   myBusy = false;
505 }
506
507 //=================================================================================
508 // function : SelectionIntoArgument()
509 // purpose  : Called when selection as changed or other case
510 //=================================================================================
511 void SMESHGUI_RotationDlg::SelectionIntoArgument()
512 {
513   if (myBusy) return;
514
515   // clear
516   myActor = 0;
517   QString aString = "";
518
519   myBusy = true;
520   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
521     LineEditElements->setText(aString);
522     myNbOkElements = 0;
523     buttonOk->setEnabled(false);
524     buttonApply->setEnabled(false);
525   }
526   myBusy = false;
527
528   if (!GroupButtons->isEnabled()) // inactive
529     return;
530
531   // get selected mesh
532   SALOME_ListIO aList;
533   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
534
535   int nbSel = aList.Extent();
536   if (nbSel != 1)
537     return;
538
539   Handle(SALOME_InteractiveObject) IO = aList.First();
540   myMesh = SMESH::GetMeshByIO(IO);
541   if (myMesh->_is_nil())
542     return;
543
544   myActor = SMESH::FindActorByObject(myMesh);
545   if (!myActor)
546     myActor = SMESH::FindActorByEntry(IO->getEntry());
547   if (!myActor)
548     return;
549
550   int aNbUnits = 0;
551
552   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
553     myElementsId = "";
554
555     if (CheckBoxMesh->isChecked()) {
556       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
557
558       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
559         // get IDs from mesh
560         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
561         if (!aSMDSMesh)
562           return;
563
564         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
565           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
566           if (e) {
567             myElementsId += QString(" %1").arg(i);
568             aNbUnits++;
569           }
570         }
571       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
572         // get submesh
573         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
574
575         // get IDs from submesh
576         SMESH::long_array_var anElementsIds = new SMESH::long_array;
577         anElementsIds = aSubMesh->GetElementsId();
578         for (int i = 0; i < anElementsIds->length(); i++) {
579           myElementsId += QString(" %1").arg(anElementsIds[i]);
580         }
581         aNbUnits = anElementsIds->length();
582       } else { // GROUP
583         // get smesh group
584         SMESH::SMESH_GroupBase_var aGroup =
585           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
586         if (aGroup->_is_nil())
587           return;
588
589         // get IDs from smesh group
590         SMESH::long_array_var anElementsIds = new SMESH::long_array;
591         anElementsIds = aGroup->GetListOfID();
592         for (int i = 0; i < anElementsIds->length(); i++) {
593           myElementsId += QString(" %1").arg(anElementsIds[i]);
594         }
595         aNbUnits = anElementsIds->length();
596       }
597     } else {
598       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
599       myElementsId = aString;
600     }
601
602     if (aNbUnits < 1)
603       return;
604
605     myNbOkElements = true;
606   } else {
607     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
608     if (aNbUnits != 1)
609       return;
610
611     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
612     if (!aMesh)
613       return;
614
615     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
616     if (!n)
617       return;
618
619     double x = n->X();
620     double y = n->Y();
621     double z = n->Z();
622
623     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
624       SpinBox_X->SetValue(x);
625       SpinBox_Y->SetValue(y);
626       SpinBox_Z->SetValue(z);
627     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
628       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
629       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
630       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
631     }
632   }
633
634   myBusy = true;
635   if (myEditCurrentArgument == (QWidget*)LineEditElements)
636     LineEditElements->setText(aString);
637   myBusy = false;
638
639   // OK
640   if (myNbOkElements && IsAxisOk()) {
641     buttonOk->setEnabled(true);
642     buttonApply->setEnabled(true);
643   }
644 }
645
646 //=================================================================================
647 // function : SetEditCurrentArgument()
648 // purpose  :
649 //=================================================================================
650 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
651 {
652   QPushButton* send = (QPushButton*)sender();
653
654   disconnect(mySelectionMgr, 0, this, 0);
655   mySelectionMgr->clearSelected();
656   mySelectionMgr->clearFilters();
657
658   switch (myConstructorId) {
659   case 0: /* default constructor */
660     {
661       SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
662       if (send == SelectElementsButton) {
663         myEditCurrentArgument = (QWidget*)LineEditElements;
664         SMESH::SetPointRepresentation(false);
665         if (CheckBoxMesh->isChecked()) {
666           if ( aViewWindow )
667             aViewWindow->SetSelectionMode(ActorSelection);
668           mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
669         } else {
670           if ( aViewWindow )
671             aViewWindow->SetSelectionMode( CellSelection );
672         }
673       } else if (send == SelectPointButton) {
674         myEditCurrentArgument = (QWidget*)SpinBox_X;
675         SMESH::SetPointRepresentation(true);
676         if ( aViewWindow )
677           aViewWindow->SetSelectionMode( NodeSelection );
678       } else if (send == SelectVectorButton) {
679         myEditCurrentArgument = (QWidget*)SpinBox_DX;
680         SMESH::SetPointRepresentation(true);
681         if ( aViewWindow )
682           aViewWindow->SetSelectionMode( NodeSelection );
683       }
684       break;
685     }
686   }
687
688   myEditCurrentArgument->setFocus();
689   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
690   SelectionIntoArgument();
691 }
692
693 //=================================================================================
694 // function : DeactivateActiveDialog()
695 // purpose  :
696 //=================================================================================
697 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
698 {
699   if (GroupConstructors->isEnabled()) {
700     GroupConstructors->setEnabled(false);
701     GroupArguments->setEnabled(false);
702     GroupButtons->setEnabled(false);
703     mySMESHGUI->ResetState();
704     mySMESHGUI->SetActiveDialogBox(0);
705   }
706 }
707
708 //=================================================================================
709 // function : ActivateThisDialog()
710 // purpose  :
711 //=================================================================================
712 void SMESHGUI_RotationDlg::ActivateThisDialog()
713 {
714   /* Emit a signal to deactivate the active dialog */
715   mySMESHGUI->EmitSignalDeactivateDialog();
716   GroupConstructors->setEnabled(true);
717   GroupArguments->setEnabled(true);
718   GroupButtons->setEnabled(true);
719
720   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
721
722   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
723     aViewWindow->SetSelectionMode( CellSelection );
724   SelectionIntoArgument();
725 }
726
727 //=================================================================================
728 // function : enterEvent()
729 // purpose  :
730 //=================================================================================
731 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
732 {
733   if (!GroupConstructors->isEnabled())
734     ActivateThisDialog();
735 }
736
737 //=================================================================================
738 // function : closeEvent()
739 // purpose  :
740 //=================================================================================
741 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
742 {
743   /* same than click on cancel button */
744   this->ClickOnCancel();
745 }
746
747 //=================================================================================
748 // function : hideEvent()
749 // purpose  : caused by ESC key
750 //=================================================================================
751 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
752 {
753   if (!isMinimized())
754     ClickOnCancel();
755 }
756
757 //=================================================================================
758 // function : onSelectMesh()
759 // purpose  :
760 //=================================================================================
761 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
762 {
763   if (toSelectMesh)
764     TextLabelElements->setText(tr("SMESH_NAME"));
765   else
766     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
767
768   if (myEditCurrentArgument != LineEditElements) {
769     LineEditElements->clear();
770     return;
771   }
772
773   mySelectionMgr->clearFilters();
774   SMESH::SetPointRepresentation(false);
775
776   if (toSelectMesh) {
777     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
778       aViewWindow->SetSelectionMode(ActorSelection);
779     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
780     LineEditElements->setReadOnly(true);
781   } else {
782     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
783       aViewWindow->SetSelectionMode( CellSelection );
784     LineEditElements->setReadOnly(false);
785     onTextChange(LineEditElements->text());
786   }
787
788   SelectionIntoArgument();
789 }
790
791 //=================================================================================
792 // function : IsAxisOk()
793 // purpose  :
794 //=================================================================================
795 bool SMESHGUI_RotationDlg::IsAxisOk()
796 {
797   return (SpinBox_DX->GetValue() != 0 ||
798           SpinBox_DY->GetValue() != 0 ||
799           SpinBox_DZ->GetValue() != 0);
800 }
801
802 //=================================================================================
803 // function : onVectorChanged()
804 // purpose  :
805 //=================================================================================
806 void SMESHGUI_RotationDlg::onVectorChanged()
807 {
808   if (IsAxisOk()) {
809     buttonOk->setEnabled(true);
810     buttonApply->setEnabled(true);
811   } else {
812     buttonOk->setEnabled(false);
813     buttonApply->setEnabled(false);
814   }
815 }