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