Salome HOME
Bug IPAL19413 - Qt4 porting: import salome_test fails
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : SMESHGUI_RotationDlg.cxx
23 // Author : Michael ZORIN, Open CASCADE S.A.S.
24 //
25
26 // SMESH includes
27 #include "SMESHGUI_RotationDlg.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_IdValidator.h"
35
36 #include <SMESH_Actor.h>
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_LogicalFilter.hxx>
39 #include <SMDS_Mesh.hxx>
40
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_ResourceMgr.h>
46
47 #include <LightApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
49
50 #include <SVTK_ViewModel.h>
51 #include <SVTK_ViewWindow.h>
52 #include <SALOME_ListIO.hxx>
53
54 // SALOME KERNEL includes
55 #include <SALOMEDSClient_SObject.hxx>
56
57 // OCCT includes
58 #include <TColStd_MapOfInteger.hxx>
59
60 // Qt includes
61 #include <QApplication>
62 #include <QButtonGroup>
63 #include <QGroupBox>
64 #include <QLabel>
65 #include <QLineEdit>
66 #include <QPushButton>
67 #include <QRadioButton>
68 #include <QCheckBox>
69 #include <QHBoxLayout>
70 #include <QVBoxLayout>
71 #include <QGridLayout>
72 #include <QKeyEvent>
73
74 // IDL includes
75 #include <SALOMEconfig.h>
76 #include CORBA_SERVER_HEADER(SMESH_Group)
77 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
78
79 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
80
81 #define SPACING 8
82 #define MARGIN  11
83
84 //=================================================================================
85 // class    : SMESHGUI_RotationDlg()
86 // purpose  :
87 //=================================================================================
88 SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule )
89   : QDialog( SMESH::GetDesktop( theModule ) ),
90     mySMESHGUI( theModule ),
91     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
92 {
93   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_ROTATION")));
94   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
95
96   setModal(false);
97   setAttribute(Qt::WA_DeleteOnClose, true);
98   setWindowTitle(tr("SMESH_ROTATION_TITLE"));
99   setSizeGripEnabled(true);
100
101   QVBoxLayout* SMESHGUI_RotationDlgLayout = new QVBoxLayout(this);
102   SMESHGUI_RotationDlgLayout->setSpacing(SPACING);
103   SMESHGUI_RotationDlgLayout->setMargin(MARGIN);
104
105   /***************************************************************/
106   GroupConstructors = new QGroupBox(tr("SMESH_ROTATION"), this);
107   QButtonGroup* ButtonGroup = new QButtonGroup(this);
108   QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
109   GroupConstructorsLayout->setSpacing(SPACING);
110   GroupConstructorsLayout->setMargin(MARGIN);
111
112   RadioButton1= new QRadioButton(GroupConstructors);
113   RadioButton1->setIcon(image0);
114
115   GroupConstructorsLayout->addWidget(RadioButton1);
116   ButtonGroup->addButton(RadioButton1, 0);
117
118   /***************************************************************/
119   GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
120   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
121   GroupArgumentsLayout->setSpacing(SPACING);
122   GroupArgumentsLayout->setMargin(MARGIN);
123
124   // Controls for elements selection
125   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
126   SelectElementsButton  = new QPushButton(GroupArguments);
127   SelectElementsButton->setIcon(image1);
128   LineEditElements = new QLineEdit(GroupArguments);
129   LineEditElements->setValidator(new SMESHGUI_IdValidator(this));
130
131   // Control for the whole mesh selection
132   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
133
134   // Controls for axis defining
135   GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
136   QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
137   GroupAxisLayout->setSpacing(SPACING);
138   GroupAxisLayout->setMargin(MARGIN);
139
140   TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
141   SelectPointButton  = new QPushButton(GroupAxis);
142   SelectPointButton->setIcon(image1);
143
144   TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
145   SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
146   TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
147   SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
148   TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
149   SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
150
151   TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
152   SelectVectorButton = new QPushButton(GroupAxis);
153   SelectVectorButton->setIcon(image1);
154
155   TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
156   SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
157   TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
158   SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
159   TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
160   SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
161
162   GroupAxisLayout->addWidget(TextLabelPoint,     0, 0);
163   GroupAxisLayout->addWidget(SelectPointButton,  0, 1);
164   GroupAxisLayout->addWidget(TextLabelX,         0, 2);
165   GroupAxisLayout->addWidget(SpinBox_X,          0, 3);
166   GroupAxisLayout->addWidget(TextLabelY,         0, 4);
167   GroupAxisLayout->addWidget(SpinBox_Y,          0, 5);
168   GroupAxisLayout->addWidget(TextLabelZ,         0, 6);
169   GroupAxisLayout->addWidget(SpinBox_Z,          0, 7);
170   GroupAxisLayout->addWidget(TextLabelVector,    1, 0);
171   GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
172   GroupAxisLayout->addWidget(TextLabelDX,        1, 2);
173   GroupAxisLayout->addWidget(SpinBox_DX,         1, 3);
174   GroupAxisLayout->addWidget(TextLabelDY,        1, 4);
175   GroupAxisLayout->addWidget(SpinBox_DY,         1, 5);
176   GroupAxisLayout->addWidget(TextLabelDZ,        1, 6);
177   GroupAxisLayout->addWidget(SpinBox_DZ,         1, 7);
178
179   // Controls for angle defining
180   TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupArguments);
181   SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments);
182
183   // action switch
184   ActionBox = new QGroupBox(GroupArguments);
185   ActionGroup = new QButtonGroup(GroupArguments);
186   QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
187   ActionBoxLayout->setSpacing(SPACING);
188   ActionBoxLayout->setMargin(MARGIN);
189
190   QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
191   QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
192   QRadioButton* aCreateMesh   = new QRadioButton(tr("SMESH_CREATE_MESH"),   ActionBox);
193
194   ActionBoxLayout->addWidget(aMoveElements);
195   ActionBoxLayout->addWidget(aCopyElements);
196   ActionBoxLayout->addWidget(aCreateMesh);
197   ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
198   ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
199   ActionGroup->addButton(aCreateMesh,   MAKE_MESH_BUTTON);
200
201   // CheckBox for groups generation
202   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
203
204   // Name of a mesh to create
205   LineEditNewMesh = new QLineEdit(GroupArguments);
206
207   GroupArgumentsLayout->addWidget(TextLabelElements,    0, 0);
208   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
209   GroupArgumentsLayout->addWidget(LineEditElements,     0, 2, 1, 2);
210   GroupArgumentsLayout->addWidget(CheckBoxMesh,         1, 0, 1, 4);
211   GroupArgumentsLayout->addWidget(GroupAxis,            2, 0, 1, 4);
212   GroupArgumentsLayout->addWidget(TextLabelAngle,       3, 0, 1, 2);
213   GroupArgumentsLayout->addWidget(SpinBox_Angle,        3, 2);
214   GroupArgumentsLayout->addWidget(ActionBox,            4, 0, 3, 3);
215   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      5, 3);
216   GroupArgumentsLayout->addWidget(LineEditNewMesh,      6, 3);
217
218   /***************************************************************/
219   GroupButtons = new QGroupBox(this);
220   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
221   GroupButtonsLayout->setSpacing(SPACING);
222   GroupButtonsLayout->setMargin(MARGIN);
223
224   buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
225   buttonOk->setAutoDefault(true);
226   buttonOk->setDefault(true);
227   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
228   buttonApply->setAutoDefault(true);
229   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
230   buttonCancel->setAutoDefault(true);
231   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
232   buttonHelp->setAutoDefault(true);
233
234   GroupButtonsLayout->addWidget(buttonOk);
235   GroupButtonsLayout->addSpacing(10);
236   GroupButtonsLayout->addWidget(buttonApply);
237   GroupButtonsLayout->addSpacing(10);
238   GroupButtonsLayout->addStretch();
239   GroupButtonsLayout->addWidget(buttonCancel);
240   GroupButtonsLayout->addWidget(buttonHelp);
241
242   /***************************************************************/
243   SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors);
244   SMESHGUI_RotationDlgLayout->addWidget(GroupArguments);
245   SMESHGUI_RotationDlgLayout->addWidget(GroupButtons);
246
247   /* Initialisations */
248   SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
249   SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
250   SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
251   SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
252   SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
253   SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
254
255   SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, 3);
256
257   myConstructorId = 0;
258   RadioButton1->setChecked(true);
259
260   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
261
262   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
263
264   // Costruction of the logical filter
265   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
266   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
267
268   QList<SUIT_SelectionFilter*> aListOfFilters;
269   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
270   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
271
272   myMeshOrSubMeshOrGroupFilter =
273     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
274
275   myHelpFileName = "rotation_page.html";
276
277   Init();
278
279   /* signals and slots connections */
280   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
281   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
282   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
283   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
284
285   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
286   connect(SelectPointButton, SIGNAL (clicked()),    this, SLOT(SetEditCurrentArgument()));
287   connect(SelectVectorButton, SIGNAL (clicked()),   this, SLOT(SetEditCurrentArgument()));
288
289   connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
290   connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
291   connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
292
293   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
294   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),   this, SLOT(SelectionIntoArgument()));
295   /* to close dialog if study change */
296   connect(mySMESHGUI,       SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
297   connect(LineEditElements, SIGNAL(textChanged(const QString&)),    SLOT(onTextChange(const QString&)));
298   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                  SLOT(onSelectMesh(bool)));
299   connect(ActionGroup,      SIGNAL(buttonClicked(int)),             SLOT(onActionClicked(int)));
300
301   onActionClicked(MOVE_ELEMS_BUTTON);
302 }
303
304 //=================================================================================
305 // function : ~SMESHGUI_RotationDlg()
306 // purpose  : Destroys the object and frees any allocated resources
307 //=================================================================================
308 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
309 {
310 }
311
312 //=================================================================================
313 // function : Init()
314 // purpose  :
315 //=================================================================================
316 void SMESHGUI_RotationDlg::Init (bool ResetControls)
317 {
318   myBusy = false;
319
320   myEditCurrentArgument = (QWidget*)LineEditElements;
321   LineEditElements->setFocus();
322   myElementsId = "";
323   myNbOkElements = 0;
324
325   buttonOk->setEnabled(false);
326   buttonApply->setEnabled(false);
327
328   myActor = 0;
329   myMesh = SMESH::SMESH_Mesh::_nil();
330
331   if (ResetControls) {
332     SpinBox_X->SetValue(0.0);
333     SpinBox_Y->SetValue(0.0);
334     SpinBox_Z->SetValue(0.0);
335     SpinBox_DX->SetValue(0.0);
336     SpinBox_DY->SetValue(0.0);
337     SpinBox_DZ->SetValue(0.0);
338
339     SpinBox_Angle->SetValue(45);
340
341     ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
342     CheckBoxMesh->setChecked(false);
343 //     MakeGroupsCheck->setChecked(false);
344 //     MakeGroupsCheck->setEnabled(false);
345 //    onSelectMesh(false);
346   }
347
348   onSelectMesh(CheckBoxMesh->isChecked());
349 }
350
351 //=================================================================================
352 // function : ClickOnApply()
353 // purpose  :
354 //=================================================================================
355 void SMESHGUI_RotationDlg::ClickOnApply()
356 {
357   if (mySMESHGUI->isActiveStudyLocked())
358     return;
359
360   if (myNbOkElements && IsAxisOk()) {
361     QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
362
363     SMESH::long_array_var anElementsId = new SMESH::long_array;
364
365     anElementsId->length(aListElementsId.count());
366     for (int i = 0; i < aListElementsId.count(); i++)
367       anElementsId[i] = aListElementsId[i].toInt();
368
369     SMESH::AxisStruct anAxis;
370
371     anAxis.x =  SpinBox_X->GetValue();
372     anAxis.y =  SpinBox_Y->GetValue();
373     anAxis.z =  SpinBox_Z->GetValue();;
374     anAxis.vx = SpinBox_DX->GetValue();
375     anAxis.vy = SpinBox_DY->GetValue();
376     anAxis.vz = SpinBox_DZ->GetValue();
377
378     double anAngle = (SpinBox_Angle->GetValue())*PI/180;
379     int actionButton = ActionGroup->checkedId();
380     bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
381     try {
382       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
383       QApplication::setOverrideCursor(Qt::WaitCursor);
384       switch ( actionButton ) {
385       case MOVE_ELEMS_BUTTON:
386         aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
387         break;
388       case COPY_ELEMS_BUTTON:
389         if ( makeGroups )
390           SMESH::ListOfGroups_var groups = 
391             aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
392         else
393           aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
394         break;
395       case MAKE_MESH_BUTTON:
396         SMESH::SMESH_Mesh_var mesh = 
397           aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
398                                       LineEditNewMesh->text().toLatin1().data());
399       }
400       QApplication::restoreOverrideCursor();
401     } catch (...) {
402     }
403
404     SMESH::UpdateView();
405     if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
406          actionButton == MAKE_MESH_BUTTON )
407       mySMESHGUI->updateObjBrowser(true); // new groups may appear
408     Init(false);
409     SelectionIntoArgument();
410   }
411 }
412
413 //=================================================================================
414 // function : ClickOnOk()
415 // purpose  :
416 //=================================================================================
417 void SMESHGUI_RotationDlg::ClickOnOk()
418 {
419   ClickOnApply();
420   ClickOnCancel();
421 }
422
423 //=================================================================================
424 // function : ClickOnCancel()
425 // purpose  :
426 //=================================================================================
427 void SMESHGUI_RotationDlg::ClickOnCancel()
428 {
429   disconnect(mySelectionMgr, 0, this, 0);
430   mySelectionMgr->clearFilters();
431   //mySelectionMgr->clearSelected();
432   SMESH::SetPointRepresentation(false);
433   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
434     aViewWindow->SetSelectionMode(ActorSelection);
435   mySMESHGUI->ResetState();
436   reject();
437 }
438
439 //=================================================================================
440 // function : ClickOnHelp()
441 // purpose  :
442 //=================================================================================
443 void SMESHGUI_RotationDlg::ClickOnHelp()
444 {
445   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
446   if (app) 
447     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
448   else {
449     QString platform;
450 #ifdef WIN32
451     platform = "winapplication";
452 #else
453     platform = "application";
454 #endif
455     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
456                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
457                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
458                                                                  platform)).
459                              arg(myHelpFileName));
460   }
461 }
462
463 //=======================================================================
464 // function : onTextChange()
465 // purpose  :
466 //=======================================================================
467 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
468 {
469   QLineEdit* send = (QLineEdit*)sender();
470
471   if (myBusy) return;
472   myBusy = true;
473
474   if (send == LineEditElements)
475     myNbOkElements = 0;
476
477   buttonOk->setEnabled(false);
478   buttonApply->setEnabled(false);
479
480   // hilight entered elements
481   SMDS_Mesh* aMesh = 0;
482   if (myActor)
483     aMesh = myActor->GetObject()->GetMesh();
484
485   if (aMesh) {
486     if (send == LineEditElements) {
487       Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
488       
489       TColStd_MapOfInteger newIndices;
490       
491       QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
492       for (int i = 0; i < aListId.count(); i++) {
493         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
494         if (e)
495           newIndices.Add(e->GetID());
496         myNbOkElements++;
497       }
498
499       mySelector->AddOrRemoveIndex( anIO, newIndices, false );
500       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
501         aViewWindow->highlight( anIO, true, true );
502       
503       myElementsId = theNewText;
504     }
505   }
506
507   if (myNbOkElements && IsAxisOk()) {
508     buttonOk->setEnabled(true);
509     buttonApply->setEnabled(true);
510   }
511
512   myBusy = false;
513 }
514
515 //=================================================================================
516 // function : SelectionIntoArgument()
517 // purpose  : Called when selection as changed or other case
518 //=================================================================================
519 void SMESHGUI_RotationDlg::SelectionIntoArgument()
520 {
521   if (myBusy) return;
522
523   // clear
524   myActor = 0;
525   QString aString = "";
526
527   myBusy = true;
528   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
529     LineEditElements->setText(aString);
530     myNbOkElements = 0;
531     buttonOk->setEnabled(false);
532     buttonApply->setEnabled(false);
533   }
534   myBusy = false;
535
536   if (!GroupButtons->isEnabled()) // inactive
537     return;
538
539   // get selected mesh
540   SALOME_ListIO aList;
541   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
542
543   int nbSel = aList.Extent();
544   if (nbSel != 1)
545     return;
546
547   Handle(SALOME_InteractiveObject) IO = aList.First();
548   myMesh = SMESH::GetMeshByIO(IO);
549   if (myMesh->_is_nil())
550     return;
551
552   myActor = SMESH::FindActorByObject(myMesh);
553   if (!myActor)
554     myActor = SMESH::FindActorByEntry(IO->getEntry());
555   if (!myActor)
556     return;
557
558   int aNbUnits = 0;
559
560   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
561     myElementsId = "";
562
563     // MakeGroups is available if there are groups and "Copy"
564     if ( myMesh->NbGroups() == 0 ) {
565       MakeGroupsCheck->setChecked(false);
566       MakeGroupsCheck->setEnabled(false);
567     }
568     else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
569       MakeGroupsCheck->setEnabled(true);
570     }
571     if (CheckBoxMesh->isChecked()) {
572       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
573
574       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
575         // get IDs from mesh
576         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
577         if (!aSMDSMesh)
578           return;
579
580         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
581           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
582           if (e) {
583             myElementsId += QString(" %1").arg(i);
584             aNbUnits++;
585           }
586         }
587       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
588         // get submesh
589         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
590
591         // get IDs from submesh
592         SMESH::long_array_var anElementsIds = new SMESH::long_array;
593         anElementsIds = aSubMesh->GetElementsId();
594         for (int i = 0; i < anElementsIds->length(); i++) {
595           myElementsId += QString(" %1").arg(anElementsIds[i]);
596         }
597         aNbUnits = anElementsIds->length();
598       } else { // GROUP
599         // get smesh group
600         SMESH::SMESH_GroupBase_var aGroup =
601           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
602         if (aGroup->_is_nil())
603           return;
604
605         // get IDs from smesh group
606         SMESH::long_array_var anElementsIds = new SMESH::long_array;
607         anElementsIds = aGroup->GetListOfID();
608         for (int i = 0; i < anElementsIds->length(); i++) {
609           myElementsId += QString(" %1").arg(anElementsIds[i]);
610         }
611         aNbUnits = anElementsIds->length();
612       }
613     } else {
614       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
615       myElementsId = aString;
616     }
617
618     if (aNbUnits < 1)
619       return;
620
621     myNbOkElements = true;
622   } else {
623     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
624     if (aNbUnits != 1)
625       return;
626
627     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
628     if (!aMesh)
629       return;
630
631     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
632     if (!n)
633       return;
634
635     double x = n->X();
636     double y = n->Y();
637     double z = n->Z();
638
639     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
640       SpinBox_X->SetValue(x);
641       SpinBox_Y->SetValue(y);
642       SpinBox_Z->SetValue(z);
643     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
644       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
645       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
646       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
647     }
648   }
649
650   myBusy = true;
651   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
652     LineEditElements->setText(aString);
653     setNewMeshName();
654   }
655   myBusy = false;
656
657   // OK
658   if (myNbOkElements && IsAxisOk()) {
659     buttonOk->setEnabled(true);
660     buttonApply->setEnabled(true);
661   }
662 }
663
664 //=================================================================================
665 // function : SetEditCurrentArgument()
666 // purpose  :
667 //=================================================================================
668 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
669 {
670   QPushButton* send = (QPushButton*)sender();
671
672   disconnect(mySelectionMgr, 0, this, 0);
673   mySelectionMgr->clearSelected();
674   mySelectionMgr->clearFilters();
675
676   switch (myConstructorId) {
677   case 0: /* default constructor */
678     {
679       SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
680       if (send == SelectElementsButton) {
681         myEditCurrentArgument = (QWidget*)LineEditElements;
682         SMESH::SetPointRepresentation(false);
683         if (CheckBoxMesh->isChecked()) {
684           if ( aViewWindow )
685             aViewWindow->SetSelectionMode(ActorSelection);
686           mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
687         } else {
688           if ( aViewWindow )
689             aViewWindow->SetSelectionMode( CellSelection );
690         }
691       } else if (send == SelectPointButton) {
692         myEditCurrentArgument = (QWidget*)SpinBox_X;
693         SMESH::SetPointRepresentation(true);
694         if ( aViewWindow )
695           aViewWindow->SetSelectionMode( NodeSelection );
696       } else if (send == SelectVectorButton) {
697         myEditCurrentArgument = (QWidget*)SpinBox_DX;
698         SMESH::SetPointRepresentation(true);
699         if ( aViewWindow )
700           aViewWindow->SetSelectionMode( NodeSelection );
701       }
702       break;
703     }
704   }
705
706   myEditCurrentArgument->setFocus();
707   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
708   SelectionIntoArgument();
709 }
710
711 //=================================================================================
712 // function : DeactivateActiveDialog()
713 // purpose  :
714 //=================================================================================
715 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
716 {
717   if (GroupConstructors->isEnabled()) {
718     GroupConstructors->setEnabled(false);
719     GroupArguments->setEnabled(false);
720     GroupButtons->setEnabled(false);
721     mySMESHGUI->ResetState();
722     mySMESHGUI->SetActiveDialogBox(0);
723   }
724 }
725
726 //=================================================================================
727 // function : ActivateThisDialog()
728 // purpose  :
729 //=================================================================================
730 void SMESHGUI_RotationDlg::ActivateThisDialog()
731 {
732   /* Emit a signal to deactivate the active dialog */
733   mySMESHGUI->EmitSignalDeactivateDialog();
734   GroupConstructors->setEnabled(true);
735   GroupArguments->setEnabled(true);
736   GroupButtons->setEnabled(true);
737
738   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
739
740   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
741     aViewWindow->SetSelectionMode( CellSelection );
742   SelectionIntoArgument();
743 }
744
745 //=================================================================================
746 // function : enterEvent()
747 // purpose  :
748 //=================================================================================
749 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
750 {
751   if (!GroupConstructors->isEnabled())
752     ActivateThisDialog();
753 }
754
755 //=================================================================================
756 // function : closeEvent()
757 // purpose  :
758 //=================================================================================
759 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
760 {
761   /* same than click on cancel button */
762   ClickOnCancel();
763 }
764
765 //=================================================================================
766 // function : hideEvent()
767 // purpose  : caused by ESC key
768 //=================================================================================
769 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
770 {
771   if (!isMinimized())
772     ClickOnCancel();
773 }
774
775 //=================================================================================
776 // function : onSelectMesh()
777 // purpose  :
778 //=================================================================================
779 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
780 {
781   if (toSelectMesh)
782     TextLabelElements->setText(tr("SMESH_NAME"));
783   else
784     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
785
786   if (myEditCurrentArgument != LineEditElements) {
787     LineEditElements->clear();
788     return;
789   }
790
791   mySelectionMgr->clearFilters();
792   SMESH::SetPointRepresentation(false);
793
794   if (toSelectMesh) {
795     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
796       aViewWindow->SetSelectionMode(ActorSelection);
797     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
798     LineEditElements->setReadOnly(true);
799   } else {
800     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
801       aViewWindow->SetSelectionMode( CellSelection );
802     LineEditElements->setReadOnly(false);
803     onTextChange(LineEditElements->text());
804   }
805
806   SelectionIntoArgument();
807 }
808
809 //=================================================================================
810 // function : IsAxisOk()
811 // purpose  :
812 //=================================================================================
813 bool SMESHGUI_RotationDlg::IsAxisOk()
814 {
815   return (SpinBox_DX->GetValue() != 0 ||
816           SpinBox_DY->GetValue() != 0 ||
817           SpinBox_DZ->GetValue() != 0);
818 }
819
820 //=================================================================================
821 // function : onVectorChanged()
822 // purpose  :
823 //=================================================================================
824 void SMESHGUI_RotationDlg::onVectorChanged()
825 {
826   if (IsAxisOk()) {
827     buttonOk->setEnabled(true);
828     buttonApply->setEnabled(true);
829   } else {
830     buttonOk->setEnabled(false);
831     buttonApply->setEnabled(false);
832   }
833 }
834
835
836 //=======================================================================
837 //function : onActionClicked
838 //purpose  : slot called when an action type changed
839 //=======================================================================
840
841 void SMESHGUI_RotationDlg::onActionClicked(int button)
842 {
843   switch ( button ) {
844   case MOVE_ELEMS_BUTTON:
845     MakeGroupsCheck->setEnabled(false);
846     LineEditNewMesh->setEnabled(false);
847     break;
848   case COPY_ELEMS_BUTTON:
849     LineEditNewMesh->setEnabled(false);
850     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
851     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
852       MakeGroupsCheck->setEnabled(true);
853     else
854       MakeGroupsCheck->setEnabled(false);
855     break;
856   case MAKE_MESH_BUTTON:
857     LineEditNewMesh->setEnabled(true);
858     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
859     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
860       MakeGroupsCheck->setEnabled(true);
861     else
862       MakeGroupsCheck->setEnabled(false);
863     break;
864   }
865   setNewMeshName();
866 }
867
868 //=======================================================================
869 //function : setNewMeshName
870 //purpose  : update contents of LineEditNewMesh
871 //=======================================================================
872
873 void SMESHGUI_RotationDlg::setNewMeshName()
874 {
875   LineEditNewMesh->setText("");
876   if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
877     QString name;
878     if ( CheckBoxMesh->isChecked() ) {
879       name = LineEditElements->text();
880     }
881     else {
882       _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
883       name = meshSO->GetName().c_str();
884     }
885     if ( !name.isEmpty() )
886       LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
887   }
888 }
889
890 //=================================================================================
891 // function : keyPressEvent()
892 // purpose  :
893 //=================================================================================
894 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
895 {
896   QDialog::keyPressEvent( e );
897   if ( e->isAccepted() )
898     return;
899
900   if ( e->key() == Qt::Key_F1 ) {
901     e->accept();
902     ClickOnHelp();
903   }
904 }