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