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