Salome HOME
d187afae3536599149cc211ba29dc17b4ecebe74
[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 #include <SUIT_OverrideCursor.h>
47
48 #include <LightApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
50
51 #include <SVTK_ViewModel.h>
52 #include <SVTK_ViewWindow.h>
53 #include <SALOME_ListIO.hxx>
54
55 // SALOME KERNEL includes
56 #include <SALOMEDSClient_SObject.hxx>
57
58 // OCCT includes
59 #include <TColStd_MapOfInteger.hxx>
60
61 // Qt includes
62 #include <QApplication>
63 #include <QButtonGroup>
64 #include <QGroupBox>
65 #include <QLabel>
66 #include <QLineEdit>
67 #include <QPushButton>
68 #include <QRadioButton>
69 #include <QCheckBox>
70 #include <QHBoxLayout>
71 #include <QVBoxLayout>
72 #include <QGridLayout>
73 #include <QKeyEvent>
74
75 // IDL includes
76 #include <SALOMEconfig.h>
77 #include CORBA_SERVER_HEADER(SMESH_Group)
78 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
79
80 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
81
82 #define SPACING 8
83 #define MARGIN  11
84
85 //=================================================================================
86 // class    : SMESHGUI_RotationDlg()
87 // purpose  :
88 //=================================================================================
89 SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule )
90   : QDialog( SMESH::GetDesktop( theModule ) ),
91     mySMESHGUI( theModule ),
92     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
93 {
94   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_ROTATION")));
95   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
96
97   setModal(false);
98   setAttribute(Qt::WA_DeleteOnClose, true);
99   setWindowTitle(tr("SMESH_ROTATION_TITLE"));
100   setSizeGripEnabled(true);
101
102   QVBoxLayout* SMESHGUI_RotationDlgLayout = new QVBoxLayout(this);
103   SMESHGUI_RotationDlgLayout->setSpacing(SPACING);
104   SMESHGUI_RotationDlgLayout->setMargin(MARGIN);
105
106   /***************************************************************/
107   GroupConstructors = new QGroupBox(tr("SMESH_ROTATION"), this);
108   QButtonGroup* ButtonGroup = new QButtonGroup(this);
109   QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
110   GroupConstructorsLayout->setSpacing(SPACING);
111   GroupConstructorsLayout->setMargin(MARGIN);
112
113   RadioButton1= new QRadioButton(GroupConstructors);
114   RadioButton1->setIcon(image0);
115
116   GroupConstructorsLayout->addWidget(RadioButton1);
117   ButtonGroup->addButton(RadioButton1, 0);
118
119   /***************************************************************/
120   GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
121   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
122   GroupArgumentsLayout->setSpacing(SPACING);
123   GroupArgumentsLayout->setMargin(MARGIN);
124
125   myIdValidator = new SMESHGUI_IdValidator(this);
126
127   // Controls for elements selection
128   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
129   SelectElementsButton  = new QPushButton(GroupArguments);
130   SelectElementsButton->setIcon(image1);
131   LineEditElements = new QLineEdit(GroupArguments);
132   LineEditElements->setValidator(myIdValidator);
133
134   // Control for the whole mesh selection
135   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
136
137   // Controls for axis defining
138   GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
139   QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
140   GroupAxisLayout->setSpacing(SPACING);
141   GroupAxisLayout->setMargin(MARGIN);
142
143   TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
144   SelectPointButton  = new QPushButton(GroupAxis);
145   SelectPointButton->setIcon(image1);
146
147   TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
148   SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
149   TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
150   SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
151   TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
152   SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
153
154   TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
155   SelectVectorButton = new QPushButton(GroupAxis);
156   SelectVectorButton->setIcon(image1);
157
158   TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
159   SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
160   TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
161   SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
162   TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
163   SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
164
165   GroupAxisLayout->addWidget(TextLabelPoint,     0, 0);
166   GroupAxisLayout->addWidget(SelectPointButton,  0, 1);
167   GroupAxisLayout->addWidget(TextLabelX,         0, 2);
168   GroupAxisLayout->addWidget(SpinBox_X,          0, 3);
169   GroupAxisLayout->addWidget(TextLabelY,         0, 4);
170   GroupAxisLayout->addWidget(SpinBox_Y,          0, 5);
171   GroupAxisLayout->addWidget(TextLabelZ,         0, 6);
172   GroupAxisLayout->addWidget(SpinBox_Z,          0, 7);
173   GroupAxisLayout->addWidget(TextLabelVector,    1, 0);
174   GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
175   GroupAxisLayout->addWidget(TextLabelDX,        1, 2);
176   GroupAxisLayout->addWidget(SpinBox_DX,         1, 3);
177   GroupAxisLayout->addWidget(TextLabelDY,        1, 4);
178   GroupAxisLayout->addWidget(SpinBox_DY,         1, 5);
179   GroupAxisLayout->addWidget(TextLabelDZ,        1, 6);
180   GroupAxisLayout->addWidget(SpinBox_DZ,         1, 7);
181
182   // Controls for angle defining
183   TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupArguments);
184   SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments);
185
186   // action switch
187   ActionBox = new QGroupBox(GroupArguments);
188   ActionGroup = new QButtonGroup(GroupArguments);
189   QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
190   ActionBoxLayout->setSpacing(SPACING);
191   ActionBoxLayout->setMargin(MARGIN);
192
193   QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
194   QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
195   QRadioButton* aCreateMesh   = new QRadioButton(tr("SMESH_CREATE_MESH"),   ActionBox);
196
197   ActionBoxLayout->addWidget(aMoveElements);
198   ActionBoxLayout->addWidget(aCopyElements);
199   ActionBoxLayout->addWidget(aCreateMesh);
200   ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
201   ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
202   ActionGroup->addButton(aCreateMesh,   MAKE_MESH_BUTTON);
203
204   // CheckBox for groups generation
205   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
206
207   // Name of a mesh to create
208   LineEditNewMesh = new QLineEdit(GroupArguments);
209
210   GroupArgumentsLayout->addWidget(TextLabelElements,    0, 0);
211   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
212   GroupArgumentsLayout->addWidget(LineEditElements,     0, 2, 1, 2);
213   GroupArgumentsLayout->addWidget(CheckBoxMesh,         1, 0, 1, 4);
214   GroupArgumentsLayout->addWidget(GroupAxis,            2, 0, 1, 4);
215   GroupArgumentsLayout->addWidget(TextLabelAngle,       3, 0, 1, 2);
216   GroupArgumentsLayout->addWidget(SpinBox_Angle,        3, 2);
217   GroupArgumentsLayout->addWidget(ActionBox,            4, 0, 3, 3);
218   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      5, 3);
219   GroupArgumentsLayout->addWidget(LineEditNewMesh,      6, 3);
220
221   /***************************************************************/
222   GroupButtons = new QGroupBox(this);
223   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
224   GroupButtonsLayout->setSpacing(SPACING);
225   GroupButtonsLayout->setMargin(MARGIN);
226
227   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
228   buttonOk->setAutoDefault(true);
229   buttonOk->setDefault(true);
230   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
231   buttonApply->setAutoDefault(true);
232   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
233   buttonCancel->setAutoDefault(true);
234   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
235   buttonHelp->setAutoDefault(true);
236
237   GroupButtonsLayout->addWidget(buttonOk);
238   GroupButtonsLayout->addSpacing(10);
239   GroupButtonsLayout->addWidget(buttonApply);
240   GroupButtonsLayout->addSpacing(10);
241   GroupButtonsLayout->addStretch();
242   GroupButtonsLayout->addWidget(buttonCancel);
243   GroupButtonsLayout->addWidget(buttonHelp);
244
245   /***************************************************************/
246   SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors);
247   SMESHGUI_RotationDlgLayout->addWidget(GroupArguments);
248   SMESHGUI_RotationDlgLayout->addWidget(GroupButtons);
249
250   /* Initialisations */
251   SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
252   SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
253   SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
254   SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
255   SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
256   SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
257
258   SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, 3);
259
260   myConstructorId = 0;
261   RadioButton1->setChecked(true);
262
263   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
264
265   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
266
267   // Costruction of the logical filter
268   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
269   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
270
271   QList<SUIT_SelectionFilter*> aListOfFilters;
272   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
273   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
274
275   myMeshOrSubMeshOrGroupFilter =
276     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
277
278   myHelpFileName = "rotation_page.html";
279
280   Init();
281
282   /* signals and slots connections */
283   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
284   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
285   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
286   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
287
288   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
289   connect(SelectPointButton, SIGNAL (clicked()),    this, SLOT(SetEditCurrentArgument()));
290   connect(SelectVectorButton, SIGNAL (clicked()),   this, SLOT(SetEditCurrentArgument()));
291
292   connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
293   connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
294   connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
295
296   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
297   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),   this, SLOT(SelectionIntoArgument()));
298   /* to close dialog if study change */
299   connect(mySMESHGUI,       SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
300   connect(LineEditElements, SIGNAL(textChanged(const QString&)),    SLOT(onTextChange(const QString&)));
301   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                  SLOT(onSelectMesh(bool)));
302   connect(ActionGroup,      SIGNAL(buttonClicked(int)),             SLOT(onActionClicked(int)));
303
304   onActionClicked(MOVE_ELEMS_BUTTON);
305 }
306
307 //=================================================================================
308 // function : ~SMESHGUI_RotationDlg()
309 // purpose  : Destroys the object and frees any allocated resources
310 //=================================================================================
311 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
312 {
313 }
314
315 //=================================================================================
316 // function : Init()
317 // purpose  :
318 //=================================================================================
319 void SMESHGUI_RotationDlg::Init (bool ResetControls)
320 {
321   myBusy = false;
322
323   myEditCurrentArgument = (QWidget*)LineEditElements;
324   LineEditElements->setFocus();
325   myElementsId = "";
326   myNbOkElements = 0;
327
328   buttonOk->setEnabled(false);
329   buttonApply->setEnabled(false);
330
331   myActor = 0;
332   myMesh = SMESH::SMESH_Mesh::_nil();
333
334   if (ResetControls) {
335     SpinBox_X->SetValue(0.0);
336     SpinBox_Y->SetValue(0.0);
337     SpinBox_Z->SetValue(0.0);
338     SpinBox_DX->SetValue(0.0);
339     SpinBox_DY->SetValue(0.0);
340     SpinBox_DZ->SetValue(0.0);
341
342     SpinBox_Angle->SetValue(45);
343
344     ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
345     CheckBoxMesh->setChecked(false);
346 //     MakeGroupsCheck->setChecked(false);
347 //     MakeGroupsCheck->setEnabled(false);
348 //    onSelectMesh(false);
349   }
350
351   onSelectMesh(CheckBoxMesh->isChecked());
352 }
353
354 //=================================================================================
355 // function : ClickOnApply()
356 // purpose  :
357 //=================================================================================
358 void SMESHGUI_RotationDlg::ClickOnApply()
359 {
360   if (mySMESHGUI->isActiveStudyLocked())
361     return;
362
363   if (myNbOkElements && IsAxisOk()) {
364     QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
365
366     SMESH::long_array_var anElementsId = new SMESH::long_array;
367
368     anElementsId->length(aListElementsId.count());
369     for (int i = 0; i < aListElementsId.count(); i++)
370       anElementsId[i] = aListElementsId[i].toInt();
371
372     SMESH::AxisStruct anAxis;
373
374     anAxis.x =  SpinBox_X->GetValue();
375     anAxis.y =  SpinBox_Y->GetValue();
376     anAxis.z =  SpinBox_Z->GetValue();;
377     anAxis.vx = SpinBox_DX->GetValue();
378     anAxis.vy = SpinBox_DY->GetValue();
379     anAxis.vz = SpinBox_DZ->GetValue();
380
381     double anAngle = (SpinBox_Angle->GetValue())*PI/180;
382     int actionButton = ActionGroup->checkedId();
383     bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
384     try {
385       SUIT_OverrideCursor aWaitCursor;
386       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
387       switch ( actionButton ) {
388       case MOVE_ELEMS_BUTTON:
389         aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
390         break;
391       case COPY_ELEMS_BUTTON:
392         if ( makeGroups )
393           SMESH::ListOfGroups_var groups = 
394             aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
395         else
396           aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
397         break;
398       case MAKE_MESH_BUTTON:
399         SMESH::SMESH_Mesh_var mesh = 
400           aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
401                                       LineEditNewMesh->text().toLatin1().data());
402       }
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     LineEditElements->repaint();
656     LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
657     LineEditElements->setEnabled(true); 
658     setNewMeshName();
659   }
660   myBusy = false;
661
662   // OK
663   if (myNbOkElements && IsAxisOk()) {
664     buttonOk->setEnabled(true);
665     buttonApply->setEnabled(true);
666   }
667 }
668
669 //=================================================================================
670 // function : SetEditCurrentArgument()
671 // purpose  :
672 //=================================================================================
673 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
674 {
675   QPushButton* send = (QPushButton*)sender();
676
677   disconnect(mySelectionMgr, 0, this, 0);
678   mySelectionMgr->clearSelected();
679   mySelectionMgr->clearFilters();
680
681   switch (myConstructorId) {
682   case 0: /* default constructor */
683     {
684       SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
685       if (send == SelectElementsButton) {
686         myEditCurrentArgument = (QWidget*)LineEditElements;
687         SMESH::SetPointRepresentation(false);
688         if (CheckBoxMesh->isChecked()) {
689           if ( aViewWindow )
690             aViewWindow->SetSelectionMode(ActorSelection);
691           mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
692         } else {
693           if ( aViewWindow )
694             aViewWindow->SetSelectionMode( CellSelection );
695         }
696       } else if (send == SelectPointButton) {
697         myEditCurrentArgument = (QWidget*)SpinBox_X;
698         SMESH::SetPointRepresentation(true);
699         if ( aViewWindow )
700           aViewWindow->SetSelectionMode( NodeSelection );
701       } else if (send == SelectVectorButton) {
702         myEditCurrentArgument = (QWidget*)SpinBox_DX;
703         SMESH::SetPointRepresentation(true);
704         if ( aViewWindow )
705           aViewWindow->SetSelectionMode( NodeSelection );
706       }
707       break;
708     }
709   }
710
711   myEditCurrentArgument->setFocus();
712   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
713   SelectionIntoArgument();
714 }
715
716 //=================================================================================
717 // function : DeactivateActiveDialog()
718 // purpose  :
719 //=================================================================================
720 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
721 {
722   if (GroupConstructors->isEnabled()) {
723     GroupConstructors->setEnabled(false);
724     GroupArguments->setEnabled(false);
725     GroupButtons->setEnabled(false);
726     mySMESHGUI->ResetState();
727     mySMESHGUI->SetActiveDialogBox(0);
728   }
729 }
730
731 //=================================================================================
732 // function : ActivateThisDialog()
733 // purpose  :
734 //=================================================================================
735 void SMESHGUI_RotationDlg::ActivateThisDialog()
736 {
737   /* Emit a signal to deactivate the active dialog */
738   mySMESHGUI->EmitSignalDeactivateDialog();
739   GroupConstructors->setEnabled(true);
740   GroupArguments->setEnabled(true);
741   GroupButtons->setEnabled(true);
742
743   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
744
745   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
746     aViewWindow->SetSelectionMode( CellSelection );
747   SelectionIntoArgument();
748 }
749
750 //=================================================================================
751 // function : enterEvent()
752 // purpose  :
753 //=================================================================================
754 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
755 {
756   if (!GroupConstructors->isEnabled())
757     ActivateThisDialog();
758 }
759
760 //=================================================================================
761 // function : closeEvent()
762 // purpose  :
763 //=================================================================================
764 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
765 {
766   /* same than click on cancel button */
767   ClickOnCancel();
768 }
769
770 //=================================================================================
771 // function : hideEvent()
772 // purpose  : caused by ESC key
773 //=================================================================================
774 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
775 {
776   if (!isMinimized())
777     ClickOnCancel();
778 }
779
780 //=================================================================================
781 // function : onSelectMesh()
782 // purpose  :
783 //=================================================================================
784 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
785 {
786   if (toSelectMesh)
787     TextLabelElements->setText(tr("SMESH_NAME"));
788   else
789     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
790
791   if (myEditCurrentArgument != LineEditElements) {
792     LineEditElements->clear();
793     return;
794   }
795
796   mySelectionMgr->clearFilters();
797   SMESH::SetPointRepresentation(false);
798
799   if (toSelectMesh) {
800     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
801       aViewWindow->SetSelectionMode(ActorSelection);
802     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
803     LineEditElements->setReadOnly(true);
804     LineEditElements->setValidator(0);
805   } else {
806     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
807       aViewWindow->SetSelectionMode( CellSelection );
808     LineEditElements->setReadOnly(false);
809     LineEditElements->setValidator(myIdValidator);
810     onTextChange(LineEditElements->text());
811   }
812
813   SelectionIntoArgument();
814 }
815
816 //=================================================================================
817 // function : IsAxisOk()
818 // purpose  :
819 //=================================================================================
820 bool SMESHGUI_RotationDlg::IsAxisOk()
821 {
822   return (SpinBox_DX->GetValue() != 0 ||
823           SpinBox_DY->GetValue() != 0 ||
824           SpinBox_DZ->GetValue() != 0);
825 }
826
827 //=================================================================================
828 // function : onVectorChanged()
829 // purpose  :
830 //=================================================================================
831 void SMESHGUI_RotationDlg::onVectorChanged()
832 {
833   if (IsAxisOk()) {
834     buttonOk->setEnabled(true);
835     buttonApply->setEnabled(true);
836   } else {
837     buttonOk->setEnabled(false);
838     buttonApply->setEnabled(false);
839   }
840 }
841
842
843 //=======================================================================
844 //function : onActionClicked
845 //purpose  : slot called when an action type changed
846 //=======================================================================
847
848 void SMESHGUI_RotationDlg::onActionClicked(int button)
849 {
850   switch ( button ) {
851   case MOVE_ELEMS_BUTTON:
852     MakeGroupsCheck->setEnabled(false);
853     LineEditNewMesh->setEnabled(false);
854     break;
855   case COPY_ELEMS_BUTTON:
856     LineEditNewMesh->setEnabled(false);
857     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
858     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
859       MakeGroupsCheck->setEnabled(true);
860     else
861       MakeGroupsCheck->setEnabled(false);
862     break;
863   case MAKE_MESH_BUTTON:
864     LineEditNewMesh->setEnabled(true);
865     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
866     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
867       MakeGroupsCheck->setEnabled(true);
868     else
869       MakeGroupsCheck->setEnabled(false);
870     break;
871   }
872   setNewMeshName();
873 }
874
875 //=======================================================================
876 //function : setNewMeshName
877 //purpose  : update contents of LineEditNewMesh
878 //=======================================================================
879
880 void SMESHGUI_RotationDlg::setNewMeshName()
881 {
882   LineEditNewMesh->setText("");
883   if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
884     QString name;
885     if ( CheckBoxMesh->isChecked() ) {
886       name = LineEditElements->text();
887     }
888     else {
889       _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
890       name = meshSO->GetName().c_str();
891     }
892     if ( !name.isEmpty() )
893       LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
894   }
895 }
896
897 //=================================================================================
898 // function : keyPressEvent()
899 // purpose  :
900 //=================================================================================
901 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
902 {
903   QDialog::keyPressEvent( e );
904   if ( e->isAccepted() )
905     return;
906
907   if ( e->key() == Qt::Key_F1 ) {
908     e->accept();
909     ClickOnHelp();
910   }
911 }