Salome HOME
For IMP 16155: use BRep_Tool::IsClosed() instead of TopoDS_Shape::Closed().
[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     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 }