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