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