Salome HOME
PAL10332 - references are interpreted as original objects in filters, dialogs, etc.
[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   /* 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     SMESH::UpdateView();
428     Init(false);
429     SelectionIntoArgument();
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   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
454     aViewWindow->SetSelectionMode(ActorSelection);
455   mySMESHGUI->ResetState();
456   reject();
457 }
458
459 //=======================================================================
460 // function : onTextChange()
461 // purpose  :
462 //=======================================================================
463 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
464 {
465   QLineEdit* send = (QLineEdit*)sender();
466
467   if (myBusy) return;
468   myBusy = true;
469
470   if (send == LineEditElements)
471     myNbOkElements = 0;
472
473   buttonOk->setEnabled(false);
474   buttonApply->setEnabled(false);
475
476   // hilight entered elements
477   SMDS_Mesh* aMesh = 0;
478   if (myActor)
479     aMesh = myActor->GetObject()->GetMesh();
480
481   if (aMesh) {
482     if (send == LineEditElements) {
483       Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
484       
485       TColStd_MapOfInteger newIndices;
486       
487       QStringList aListId = QStringList::split(" ", theNewText, false);
488       for (int i = 0; i < aListId.count(); i++) {
489         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
490         if (e)
491           newIndices.Add(e->GetID());
492         myNbOkElements++;
493       }
494
495       mySelector->AddOrRemoveIndex( anIO, newIndices, false );
496       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
497         aViewWindow->highlight( anIO, true, true );
498       
499       myElementsId = theNewText;
500     }
501   }
502
503   if (myNbOkElements && IsAxisOk()) {
504     buttonOk->setEnabled(true);
505     buttonApply->setEnabled(true);
506   }
507
508   myBusy = false;
509 }
510
511 //=================================================================================
512 // function : SelectionIntoArgument()
513 // purpose  : Called when selection as changed or other case
514 //=================================================================================
515 void SMESHGUI_RotationDlg::SelectionIntoArgument()
516 {
517   if (myBusy) return;
518
519   // clear
520   myActor = 0;
521   QString aString = "";
522
523   myBusy = true;
524   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
525     LineEditElements->setText(aString);
526     myNbOkElements = 0;
527     buttonOk->setEnabled(false);
528     buttonApply->setEnabled(false);
529   }
530   myBusy = false;
531
532   if (!GroupButtons->isEnabled()) // inactive
533     return;
534
535   // get selected mesh
536   SALOME_ListIO aList;
537   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
538
539   int nbSel = aList.Extent();
540   if (nbSel != 1)
541     return;
542
543   Handle(SALOME_InteractiveObject) IO = aList.First();
544   myMesh = SMESH::GetMeshByIO(IO);
545   if (myMesh->_is_nil())
546     return;
547
548   myActor = SMESH::FindActorByObject(myMesh);
549   if (!myActor)
550     myActor = SMESH::FindActorByEntry(IO->getEntry());
551   if (!myActor)
552     return;
553
554   int aNbUnits = 0;
555
556   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
557     myElementsId = "";
558
559     if (CheckBoxMesh->isChecked()) {
560       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
561
562       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
563         // get IDs from mesh
564         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
565         if (!aSMDSMesh)
566           return;
567
568         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
569           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
570           if (e) {
571             myElementsId += QString(" %1").arg(i);
572             aNbUnits++;
573           }
574         }
575       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
576         // get submesh
577         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
578
579         // get IDs from submesh
580         SMESH::long_array_var anElementsIds = new SMESH::long_array;
581         anElementsIds = aSubMesh->GetElementsId();
582         for (int i = 0; i < anElementsIds->length(); i++) {
583           myElementsId += QString(" %1").arg(anElementsIds[i]);
584         }
585         aNbUnits = anElementsIds->length();
586       } else { // GROUP
587         // get smesh group
588         SMESH::SMESH_GroupBase_var aGroup =
589           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
590         if (aGroup->_is_nil())
591           return;
592
593         // get IDs from smesh group
594         SMESH::long_array_var anElementsIds = new SMESH::long_array;
595         anElementsIds = aGroup->GetListOfID();
596         for (int i = 0; i < anElementsIds->length(); i++) {
597           myElementsId += QString(" %1").arg(anElementsIds[i]);
598         }
599         aNbUnits = anElementsIds->length();
600       }
601     } else {
602       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
603       myElementsId = aString;
604     }
605
606     if (aNbUnits < 1)
607       return;
608
609     myNbOkElements = true;
610   } else {
611     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
612     if (aNbUnits != 1)
613       return;
614
615     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
616     if (!aMesh)
617       return;
618
619     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
620     if (!n)
621       return;
622
623     double x = n->X();
624     double y = n->Y();
625     double z = n->Z();
626
627     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
628       SpinBox_X->SetValue(x);
629       SpinBox_Y->SetValue(y);
630       SpinBox_Z->SetValue(z);
631     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
632       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
633       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
634       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
635     }
636   }
637
638   myBusy = true;
639   if (myEditCurrentArgument == (QWidget*)LineEditElements)
640     LineEditElements->setText(aString);
641   myBusy = false;
642
643   // OK
644   if (myNbOkElements && IsAxisOk()) {
645     buttonOk->setEnabled(true);
646     buttonApply->setEnabled(true);
647   }
648 }
649
650 //=================================================================================
651 // function : SetEditCurrentArgument()
652 // purpose  :
653 //=================================================================================
654 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
655 {
656   QPushButton* send = (QPushButton*)sender();
657
658   disconnect(mySelectionMgr, 0, this, 0);
659   mySelectionMgr->clearSelected();
660   mySelectionMgr->clearFilters();
661
662   switch (myConstructorId) {
663   case 0: /* default constructor */
664     {
665       SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
666       if (send == SelectElementsButton) {
667         myEditCurrentArgument = (QWidget*)LineEditElements;
668         SMESH::SetPointRepresentation(false);
669         if (CheckBoxMesh->isChecked()) {
670           if ( aViewWindow )
671             aViewWindow->SetSelectionMode(ActorSelection);
672           mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
673         } else {
674           if ( aViewWindow )
675             aViewWindow->SetSelectionMode( CellSelection );
676         }
677       } else if (send == SelectPointButton) {
678         myEditCurrentArgument = (QWidget*)SpinBox_X;
679         SMESH::SetPointRepresentation(true);
680         if ( aViewWindow )
681           aViewWindow->SetSelectionMode( NodeSelection );
682       } else if (send == SelectVectorButton) {
683         myEditCurrentArgument = (QWidget*)SpinBox_DX;
684         SMESH::SetPointRepresentation(true);
685         if ( aViewWindow )
686           aViewWindow->SetSelectionMode( NodeSelection );
687       }
688       break;
689     }
690   }
691
692   myEditCurrentArgument->setFocus();
693   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
694   SelectionIntoArgument();
695 }
696
697 //=================================================================================
698 // function : DeactivateActiveDialog()
699 // purpose  :
700 //=================================================================================
701 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
702 {
703   if (GroupConstructors->isEnabled()) {
704     GroupConstructors->setEnabled(false);
705     GroupArguments->setEnabled(false);
706     GroupButtons->setEnabled(false);
707     mySMESHGUI->ResetState();
708     mySMESHGUI->SetActiveDialogBox(0);
709   }
710 }
711
712 //=================================================================================
713 // function : ActivateThisDialog()
714 // purpose  :
715 //=================================================================================
716 void SMESHGUI_RotationDlg::ActivateThisDialog()
717 {
718   /* Emit a signal to deactivate the active dialog */
719   mySMESHGUI->EmitSignalDeactivateDialog();
720   GroupConstructors->setEnabled(true);
721   GroupArguments->setEnabled(true);
722   GroupButtons->setEnabled(true);
723
724   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
725
726   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
727     aViewWindow->SetSelectionMode( CellSelection );
728   SelectionIntoArgument();
729 }
730
731 //=================================================================================
732 // function : enterEvent()
733 // purpose  :
734 //=================================================================================
735 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
736 {
737   if (!GroupConstructors->isEnabled())
738     ActivateThisDialog();
739 }
740
741 //=================================================================================
742 // function : closeEvent()
743 // purpose  :
744 //=================================================================================
745 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
746 {
747   /* same than click on cancel button */
748   this->ClickOnCancel();
749 }
750
751 //=================================================================================
752 // function : hideEvent()
753 // purpose  : caused by ESC key
754 //=================================================================================
755 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
756 {
757   if (!isMinimized())
758     ClickOnCancel();
759 }
760
761 //=================================================================================
762 // function : onSelectMesh()
763 // purpose  :
764 //=================================================================================
765 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
766 {
767   if (toSelectMesh)
768     TextLabelElements->setText(tr("SMESH_NAME"));
769   else
770     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
771
772   if (myEditCurrentArgument != LineEditElements) {
773     LineEditElements->clear();
774     return;
775   }
776
777   mySelectionMgr->clearFilters();
778   SMESH::SetPointRepresentation(false);
779
780   if (toSelectMesh) {
781     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
782       aViewWindow->SetSelectionMode(ActorSelection);
783     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
784     LineEditElements->setReadOnly(true);
785   } else {
786     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
787       aViewWindow->SetSelectionMode( CellSelection );
788     LineEditElements->setReadOnly(false);
789     onTextChange(LineEditElements->text());
790   }
791
792   SelectionIntoArgument();
793 }
794
795 //=================================================================================
796 // function : IsAxisOk()
797 // purpose  :
798 //=================================================================================
799 bool SMESHGUI_RotationDlg::IsAxisOk()
800 {
801   return (SpinBox_DX->GetValue() != 0 ||
802           SpinBox_DY->GetValue() != 0 ||
803           SpinBox_DZ->GetValue() != 0);
804 }
805
806 //=================================================================================
807 // function : onVectorChanged()
808 // purpose  :
809 //=================================================================================
810 void SMESHGUI_RotationDlg::onVectorChanged()
811 {
812   if (IsAxisOk()) {
813     buttonOk->setEnabled(true);
814     buttonApply->setEnabled(true);
815   } else {
816     buttonOk->setEnabled(false);
817     buttonApply->setEnabled(false);
818   }
819 }