Salome HOME
0e0690c018c93550cdd9f6a0094cd2776bf65fa9
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_RotationDlg.cxx
1 // Copyright (C) 2007-2012  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 //  File   : SMESHGUI_RotationDlg.cxx
23 //  Author : Michael ZORIN, Open CASCADE S.A.S.
24 //  SMESH includes
25
26 #include "SMESHGUI_RotationDlg.h"
27
28 #include "SMESHGUI.h"
29 #include "SMESHGUI_SpinBox.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_IdValidator.h"
34 #include "SMESHGUI_FilterDlg.h"
35 #include "SMESHGUI_MeshEditPreview.h"
36
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_LogicalFilter.hxx>
40 #include <SMDS_Mesh.hxx>
41
42 // SALOME GUI includes
43 #include <SUIT_Desktop.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_OverrideCursor.h>
48
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
51
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <SALOME_ListIO.hxx>
55
56 // SALOME KERNEL includes
57 #include <SALOMEDSClient_SObject.hxx>
58
59 // OCCT includes
60 #include <TColStd_MapOfInteger.hxx>
61
62 // Qt includes
63 #include <QApplication>
64 #include <QButtonGroup>
65 #include <QGroupBox>
66 #include <QLabel>
67 #include <QLineEdit>
68 #include <QPushButton>
69 #include <QRadioButton>
70 #include <QCheckBox>
71 #include <QHBoxLayout>
72 #include <QVBoxLayout>
73 #include <QGridLayout>
74 #include <QKeyEvent>
75
76 // IDL includes
77 #include <SALOMEconfig.h>
78 #include CORBA_SERVER_HEADER(SMESH_Group)
79 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
80
81 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
82
83 #define SPACING 8
84 #define MARGIN  11
85
86 //To disable automatic genericobj management, the following line should be commented.
87 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
88 #define WITHGENERICOBJ
89
90 //=================================================================================
91 // class    : SMESHGUI_RotationDlg()
92 // purpose  :
93 //=================================================================================
94 SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule ) :
95     SMESHGUI_PreviewDlg( theModule ),
96     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
97     myFilterDlg(0),
98     mySelectedObject(SMESH::SMESH_IDSource::_nil())
99 {
100   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_ROTATION")));
101   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
102
103   setModal(false);
104   setAttribute(Qt::WA_DeleteOnClose, true);
105   setWindowTitle(tr("SMESH_ROTATION_TITLE"));
106   setSizeGripEnabled(true);
107
108   QVBoxLayout* SMESHGUI_RotationDlgLayout = new QVBoxLayout(this);
109   SMESHGUI_RotationDlgLayout->setSpacing(SPACING);
110   SMESHGUI_RotationDlgLayout->setMargin(MARGIN);
111
112   /***************************************************************/
113   GroupConstructors = new QGroupBox(tr("SMESH_ROTATION"), this);
114   QButtonGroup* ButtonGroup = new QButtonGroup(this);
115   QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
116   GroupConstructorsLayout->setSpacing(SPACING);
117   GroupConstructorsLayout->setMargin(MARGIN);
118
119   RadioButton1= new QRadioButton(GroupConstructors);
120   RadioButton1->setIcon(image0);
121
122   GroupConstructorsLayout->addWidget(RadioButton1);
123   ButtonGroup->addButton(RadioButton1, 0);
124
125   /***************************************************************/
126   GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
127   QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
128   GroupArgumentsLayout->setSpacing(SPACING);
129   GroupArgumentsLayout->setMargin(MARGIN);
130
131   myIdValidator = new SMESHGUI_IdValidator(this);
132
133   // Controls for elements selection
134   TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
135   SelectElementsButton  = new QPushButton(GroupArguments);
136   SelectElementsButton->setIcon(image1);
137   LineEditElements = new QLineEdit(GroupArguments);
138   LineEditElements->setValidator(myIdValidator);
139   LineEditElements->setMaxLength(-1);
140   myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
141   connect(myFilterBtn,   SIGNAL(clicked()), this, SLOT(setFilters()));
142
143   // Control for the whole mesh selection
144   CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
145
146   // Controls for axis defining
147   GroupAxis = new QGroupBox(tr("SMESH_AXIS"), GroupArguments);
148   QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis);
149   GroupAxisLayout->setSpacing(SPACING);
150   GroupAxisLayout->setMargin(MARGIN);
151
152   TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupAxis);
153   SelectPointButton  = new QPushButton(GroupAxis);
154   SelectPointButton->setIcon(image1);
155
156   TextLabelX = new QLabel(tr("SMESH_X"), GroupAxis);
157   SpinBox_X = new SMESHGUI_SpinBox(GroupAxis);
158   TextLabelY = new QLabel(tr("SMESH_Y"), GroupAxis);
159   SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis);
160   TextLabelZ = new QLabel(tr("SMESH_Z"), GroupAxis);
161   SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis);
162
163   TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupAxis);
164   SelectVectorButton = new QPushButton(GroupAxis);
165   SelectVectorButton->setIcon(image1);
166
167   TextLabelDX = new QLabel(tr("SMESH_DX"), GroupAxis);
168   SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis);
169   TextLabelDY = new QLabel(tr("SMESH_DY"), GroupAxis);
170   SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis);
171   TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupAxis);
172   SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis);
173
174   GroupAxisLayout->addWidget(TextLabelPoint,     0, 0);
175   GroupAxisLayout->addWidget(SelectPointButton,  0, 1);
176   GroupAxisLayout->addWidget(TextLabelX,         0, 2);
177   GroupAxisLayout->addWidget(SpinBox_X,          0, 3);
178   GroupAxisLayout->addWidget(TextLabelY,         0, 4);
179   GroupAxisLayout->addWidget(SpinBox_Y,          0, 5);
180   GroupAxisLayout->addWidget(TextLabelZ,         0, 6);
181   GroupAxisLayout->addWidget(SpinBox_Z,          0, 7);
182   GroupAxisLayout->addWidget(TextLabelVector,    1, 0);
183   GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
184   GroupAxisLayout->addWidget(TextLabelDX,        1, 2);
185   GroupAxisLayout->addWidget(SpinBox_DX,         1, 3);
186   GroupAxisLayout->addWidget(TextLabelDY,        1, 4);
187   GroupAxisLayout->addWidget(SpinBox_DY,         1, 5);
188   GroupAxisLayout->addWidget(TextLabelDZ,        1, 6);
189   GroupAxisLayout->addWidget(SpinBox_DZ,         1, 7);
190
191   // Controls for angle defining
192   TextLabelAngle = new QLabel(tr("SMESH_ANGLE"), GroupArguments);
193   SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments);
194
195   // action switch
196   ActionBox = new QGroupBox(GroupArguments);
197   ActionGroup = new QButtonGroup(GroupArguments);
198   QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
199   ActionBoxLayout->setSpacing(SPACING);
200   ActionBoxLayout->setMargin(MARGIN);
201
202   QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
203   QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
204   QRadioButton* aCreateMesh   = new QRadioButton(tr("SMESH_CREATE_MESH"),   ActionBox);
205
206   ActionBoxLayout->addWidget(aMoveElements);
207   ActionBoxLayout->addWidget(aCopyElements);
208   ActionBoxLayout->addWidget(aCreateMesh);
209   ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
210   ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
211   ActionGroup->addButton(aCreateMesh,   MAKE_MESH_BUTTON);
212
213   // CheckBox for groups generation
214   MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
215
216   // Name of a mesh to create
217   LineEditNewMesh = new QLineEdit(GroupArguments);
218
219
220   //Preview check box
221   myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
222
223   GroupArgumentsLayout->addWidget(TextLabelElements,    0, 0);
224   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
225   GroupArgumentsLayout->addWidget(LineEditElements,     0, 2, 1, 1);
226   GroupArgumentsLayout->addWidget(myFilterBtn,          0, 3);
227   GroupArgumentsLayout->addWidget(CheckBoxMesh,         1, 0, 1, 4);
228   GroupArgumentsLayout->addWidget(GroupAxis,            2, 0, 1, 4);
229   GroupArgumentsLayout->addWidget(TextLabelAngle,       3, 0, 1, 2);
230   GroupArgumentsLayout->addWidget(SpinBox_Angle,        3, 2);
231   GroupArgumentsLayout->addWidget(ActionBox,            4, 0, 3, 3);
232   GroupArgumentsLayout->addWidget(MakeGroupsCheck,      5, 3);
233   GroupArgumentsLayout->addWidget(LineEditNewMesh,      6, 3);
234   GroupArgumentsLayout->addWidget(myPreviewCheckBox,    7, 0);
235
236
237   /***************************************************************/
238   GroupButtons = new QGroupBox(this);
239   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
240   GroupButtonsLayout->setSpacing(SPACING);
241   GroupButtonsLayout->setMargin(MARGIN);
242
243   buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
244   buttonOk->setAutoDefault(true);
245   buttonOk->setDefault(true);
246   buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
247   buttonApply->setAutoDefault(true);
248   buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
249   buttonCancel->setAutoDefault(true);
250   buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
251   buttonHelp->setAutoDefault(true);
252
253   GroupButtonsLayout->addWidget(buttonOk);
254   GroupButtonsLayout->addSpacing(10);
255   GroupButtonsLayout->addWidget(buttonApply);
256   GroupButtonsLayout->addSpacing(10);
257   GroupButtonsLayout->addStretch();
258   GroupButtonsLayout->addWidget(buttonCancel);
259   GroupButtonsLayout->addWidget(buttonHelp);
260
261   /***************************************************************/
262   SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors);
263   SMESHGUI_RotationDlgLayout->addWidget(GroupArguments);
264   SMESHGUI_RotationDlgLayout->addWidget(GroupButtons);
265
266   /* Initialisations */
267   SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
268   SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
269   SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
270   SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
271   SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
272   SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
273
274   SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, "angle_precision");
275
276   myConstructorId = 0;
277   RadioButton1->setChecked(true);
278
279   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
280
281   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
282
283   // Costruction of the logical filter
284   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
285   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (SMESH::GROUP);
286
287   QList<SUIT_SelectionFilter*> aListOfFilters;
288   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
289   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
290
291   myMeshOrSubMeshOrGroupFilter =
292     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
293
294   myHelpFileName = "rotation_page.html";
295
296   Init();
297
298   /* signals and slots connections */
299   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
300   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
301   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
302   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
303
304   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
305   connect(SelectPointButton, SIGNAL (clicked()),    this, SLOT(SetEditCurrentArgument()));
306   connect(SelectVectorButton, SIGNAL (clicked()),   this, SLOT(SetEditCurrentArgument()));
307
308   connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
309   connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
310   connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
311
312   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
313   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),   this, SLOT(SelectionIntoArgument()));
314   /* to close dialog if study change */
315   connect(mySMESHGUI,       SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
316   connect(LineEditElements, SIGNAL(textChanged(const QString&)),    SLOT(onTextChange(const QString&)));
317   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                  SLOT(onSelectMesh(bool)));
318   connect(ActionGroup,      SIGNAL(buttonClicked(int)),             SLOT(onActionClicked(int)));
319
320   connect(SpinBox_X,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
321   connect(SpinBox_Y,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
322   connect(SpinBox_Z,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
323   connect(SpinBox_DX,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
324   connect(SpinBox_DY,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
325   connect(SpinBox_DZ,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326   connect(SpinBox_Angle,  SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
327
328   //To Connect preview check box
329   connectPreviewControl();
330
331   onActionClicked(MOVE_ELEMS_BUTTON);
332 }
333
334 //=================================================================================
335 // function : ~SMESHGUI_RotationDlg()
336 // purpose  : Destroys the object and frees any allocated resources
337 //=================================================================================
338 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
339 {
340   if ( myFilterDlg ) {
341     myFilterDlg->setParent( 0 );
342     delete myFilterDlg;
343     myFilterDlg = 0;
344   }
345 }
346
347 //=================================================================================
348 // function : Init()
349 // purpose  :
350 //=================================================================================
351 void SMESHGUI_RotationDlg::Init (bool ResetControls)
352 {
353   myBusy = false;
354
355   myEditCurrentArgument = (QWidget*)LineEditElements;
356   LineEditElements->setFocus();
357   myElementsId = "";
358   myNbOkElements = 0;
359
360   buttonOk->setEnabled(false);
361   buttonApply->setEnabled(false);
362
363   myActor = 0;
364   myMesh = SMESH::SMESH_Mesh::_nil();
365
366   if (ResetControls) {
367     SpinBox_X->SetValue(0.0);
368     SpinBox_Y->SetValue(0.0);
369     SpinBox_Z->SetValue(0.0);
370     SpinBox_DX->SetValue(0.0);
371     SpinBox_DY->SetValue(0.0);
372     SpinBox_DZ->SetValue(0.0);
373
374     SpinBox_Angle->SetValue(45);
375
376     ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
377     CheckBoxMesh->setChecked(false);
378     myPreviewCheckBox->setChecked(false);
379     onDisplaySimulation(false);
380
381 //     MakeGroupsCheck->setChecked(false);
382 //     MakeGroupsCheck->setEnabled(false);
383 //    onSelectMesh(false);
384   }
385
386   onSelectMesh(CheckBoxMesh->isChecked());
387 }
388
389 //=================================================================================
390 // function : ClickOnApply()
391 // purpose  :
392 //=================================================================================
393 bool SMESHGUI_RotationDlg::ClickOnApply()
394 {
395   if (mySMESHGUI->isActiveStudyLocked())
396     return false;
397
398   if( !isValid() )
399     return false;
400
401   if (myNbOkElements && IsAxisOk()) {
402     QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
403
404     SMESH::long_array_var anElementsId = new SMESH::long_array;
405
406     anElementsId->length(aListElementsId.count());
407     for (int i = 0; i < aListElementsId.count(); i++)
408       anElementsId[i] = aListElementsId[i].toInt();
409
410     SMESH::AxisStruct anAxis;
411
412     anAxis.x =  SpinBox_X->GetValue();
413     anAxis.y =  SpinBox_Y->GetValue();
414     anAxis.z =  SpinBox_Z->GetValue();;
415     anAxis.vx = SpinBox_DX->GetValue();
416     anAxis.vy = SpinBox_DY->GetValue();
417     anAxis.vz = SpinBox_DZ->GetValue();
418
419     double anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
420
421     QStringList aParameters;
422     aParameters << SpinBox_X->text();
423     aParameters << SpinBox_Y->text();
424     aParameters << SpinBox_Z->text();
425     aParameters << SpinBox_DX->text();
426     aParameters << SpinBox_DY->text();
427     aParameters << SpinBox_DZ->text();
428     aParameters << SpinBox_Angle->text();
429
430     int actionButton = ActionGroup->checkedId();
431     bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
432     QStringList anEntryList;
433     try {
434       SUIT_OverrideCursor aWaitCursor;
435       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
436
437       myMesh->SetParameters(aParameters.join(":").toLatin1().constData());
438
439       switch ( actionButton ) {
440       case MOVE_ELEMS_BUTTON:
441         if(CheckBoxMesh->isChecked())
442           aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, false);
443         else
444             aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
445         break;
446       case COPY_ELEMS_BUTTON:
447         if ( makeGroups ) {
448           SMESH::ListOfGroups_var groups;
449           if(CheckBoxMesh->isChecked())
450             groups = aMeshEditor->RotateObjectMakeGroups(mySelectedObject, anAxis, anAngle);
451           else
452             groups = aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
453         }
454         else {
455           if(CheckBoxMesh->isChecked())
456             aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, true);
457           else
458             aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
459         }
460         break;
461       case MAKE_MESH_BUTTON: {
462         SMESH::SMESH_Mesh_var mesh;
463         if (CheckBoxMesh->isChecked())
464           mesh = aMeshEditor->RotateObjectMakeMesh(mySelectedObject, anAxis, anAngle, makeGroups,
465                                                    LineEditNewMesh->text().toLatin1().data());
466         else
467           mesh = aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
468                                              LineEditNewMesh->text().toLatin1().data());
469         if (!mesh->_is_nil()) {
470           if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
471             anEntryList.append( aSObject->GetID().c_str() );
472 #ifdef WITHGENERICOBJ
473           // obj has been published in study. Its refcount has been incremented.
474           // It is safe to decrement its refcount
475           // so that it will be destroyed when the entry in study will be removed
476           mesh->UnRegister();
477 #endif
478         }
479         break;
480       }
481       }
482     } catch (...) {
483     }
484
485     SMESH::UpdateView();
486     if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
487          actionButton == MAKE_MESH_BUTTON ) {
488       mySMESHGUI->updateObjBrowser(true); // new groups may appear
489       if( LightApp_Application* anApp =
490           dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
491         anApp->browseObjects( anEntryList, isApplyAndClose() );
492     }
493     Init(false);
494     mySelectedObject = SMESH::SMESH_IDSource::_nil();
495     SelectionIntoArgument();
496
497     SMESHGUI::Modified();
498   }
499
500   return true;
501 }
502
503 //=================================================================================
504 // function : ClickOnOk()
505 // purpose  :
506 //=================================================================================
507 void SMESHGUI_RotationDlg::ClickOnOk()
508 {
509   setIsApplyAndClose( true );
510   if( ClickOnApply() )
511     ClickOnCancel();
512 }
513
514 //=================================================================================
515 // function : ClickOnCancel()
516 // purpose  :
517 //=================================================================================
518 void SMESHGUI_RotationDlg::ClickOnCancel()
519 {
520   disconnect(mySelectionMgr, 0, this, 0);
521   mySelectionMgr->clearFilters();
522   //mySelectionMgr->clearSelected();
523   if (SMESH::GetCurrentVtkView()) {
524     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
525     SMESH::SetPointRepresentation(false);
526   }
527   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
528     aViewWindow->SetSelectionMode(ActorSelection);
529   mySMESHGUI->ResetState();
530   reject();
531 }
532
533 //=================================================================================
534 // function : ClickOnHelp()
535 // purpose  :
536 //=================================================================================
537 void SMESHGUI_RotationDlg::ClickOnHelp()
538 {
539   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
540   if (app)
541     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
542   else {
543     QString platform;
544 #ifdef WIN32
545     platform = "winapplication";
546 #else
547     platform = "application";
548 #endif
549     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
550                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
551                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
552                                                                  platform)).
553                              arg(myHelpFileName));
554   }
555 }
556
557 //=======================================================================
558 // function : onTextChange()
559 // purpose  :
560 //=======================================================================
561 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
562 {
563   QLineEdit* send = (QLineEdit*)sender();
564
565   if (myBusy) return;
566   myBusy = true;
567
568   if (send == LineEditElements)
569     myNbOkElements = 0;
570
571   buttonOk->setEnabled(false);
572   buttonApply->setEnabled(false);
573
574   // hilight entered elements
575   SMDS_Mesh* aMesh = 0;
576   if (myActor)
577     aMesh = myActor->GetObject()->GetMesh();
578
579   if (aMesh) {
580     if (send == LineEditElements) {
581       Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
582
583       TColStd_MapOfInteger newIndices;
584
585       QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
586       for (int i = 0; i < aListId.count(); i++) {
587         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
588         if (e)
589           newIndices.Add(e->GetID());
590         myNbOkElements++;
591       }
592
593       mySelector->AddOrRemoveIndex( anIO, newIndices, false );
594       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
595         aViewWindow->highlight( anIO, true, true );
596
597       myElementsId = theNewText;
598     }
599   }
600
601   if (myNbOkElements && IsAxisOk()) {
602     buttonOk->setEnabled(true);
603     buttonApply->setEnabled(true);
604   }
605
606   myBusy = false;
607 }
608
609 //=================================================================================
610 // function : SelectionIntoArgument()
611 // purpose  : Called when selection as changed or other case
612 //=================================================================================
613 void SMESHGUI_RotationDlg::SelectionIntoArgument()
614 {
615   if (myBusy) return;
616
617   // clear
618   myActor = 0;
619   QString aString = "";
620
621   myBusy = true;
622   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
623     LineEditElements->setText(aString);
624     myNbOkElements = 0;
625     buttonOk->setEnabled(false);
626     buttonApply->setEnabled(false);
627   }
628   myBusy = false;
629
630   if (!GroupButtons->isEnabled()) // inactive
631     return;
632
633   // get selected mesh
634   SALOME_ListIO aList;
635   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
636
637   int nbSel = aList.Extent();
638   if (nbSel != 1)
639     return;
640
641   Handle(SALOME_InteractiveObject) IO = aList.First();
642   myMesh = SMESH::GetMeshByIO(IO);
643   if (myMesh->_is_nil())
644     return;
645
646   myActor = SMESH::FindActorByObject(myMesh);
647   if (!myActor)
648     myActor = SMESH::FindActorByEntry(IO->getEntry());
649   if (!myActor && !CheckBoxMesh->isChecked())
650     return;
651
652   int aNbUnits = 0;
653
654   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
655     myElementsId = "";
656
657     // MakeGroups is available if there are groups and "Copy"
658     if ( myMesh->NbGroups() == 0 ) {
659       MakeGroupsCheck->setChecked(false);
660       MakeGroupsCheck->setEnabled(false);
661     }
662     else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
663       MakeGroupsCheck->setEnabled(true);
664     }
665     if (CheckBoxMesh->isChecked()) {
666       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
667
668       if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
669         mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
670       }
671       else
672         return;
673         // get IDs from mesh
674         /*
675           SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
676           if (!aSMDSMesh)
677           return;
678
679           for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
680           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
681           if (e) {
682             myElementsId += QString(" %1").arg(i);
683             aNbUnits++;
684           }
685         }
686       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
687       // get submesh
688         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
689
690         // get IDs from submesh
691         SMESH::long_array_var anElementsIds = new SMESH::long_array;
692         anElementsIds = aSubMesh->GetElementsId();
693         for (int i = 0; i < anElementsIds->length(); i++) {
694         myElementsId += QString(" %1").arg(anElementsIds[i]);
695           }
696         aNbUnits = anElementsIds->length();
697       } else { // GROUP
698         // get smesh group
699         SMESH::SMESH_GroupBase_var aGroup =
700         SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
701         if (aGroup->_is_nil())
702         return;
703
704           // get IDs from smesh group
705         SMESH::long_array_var anElementsIds = new SMESH::long_array;
706         anElementsIds = aGroup->GetListOfID();
707         for (int i = 0; i < anElementsIds->length(); i++) {
708         myElementsId += QString(" %1").arg(anElementsIds[i]);
709           }
710         aNbUnits = anElementsIds->length();
711         }
712         */
713       } else {
714       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
715       myElementsId = aString;
716       if (aNbUnits < 1)
717         return;
718       }
719
720     myNbOkElements = true;
721
722   } else {
723     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
724     if (aNbUnits != 1)
725       return;
726
727     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
728     if (!aMesh)
729       return;
730
731     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
732     if (!n)
733       return;
734
735     double x = n->X();
736     double y = n->Y();
737     double z = n->Z();
738
739     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
740       SpinBox_X->SetValue(x);
741       SpinBox_Y->SetValue(y);
742       SpinBox_Z->SetValue(z);
743     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
744       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
745       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
746       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
747     }
748   }
749
750   myBusy = true;
751   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
752     LineEditElements->setText(aString);
753     LineEditElements->repaint();
754     LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
755     LineEditElements->setEnabled(true);
756     setNewMeshName();
757   }
758   myBusy = false;
759
760   // OK
761   if (myNbOkElements && IsAxisOk()) {
762     buttonOk->setEnabled(true);
763     buttonApply->setEnabled(true);
764   }
765   onDisplaySimulation(true);
766 }
767
768 //=================================================================================
769 // function : SetEditCurrentArgument()
770 // purpose  :
771 //=================================================================================
772 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
773 {
774   QPushButton* send = (QPushButton*)sender();
775
776   disconnect(mySelectionMgr, 0, this, 0);
777   mySelectionMgr->clearSelected();
778   mySelectionMgr->clearFilters();
779
780   switch (myConstructorId) {
781   case 0: /* default constructor */
782     {
783       SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
784       if (send == SelectElementsButton) {
785         myEditCurrentArgument = (QWidget*)LineEditElements;
786         SMESH::SetPointRepresentation(false);
787         if (CheckBoxMesh->isChecked()) {
788           if ( aViewWindow )
789             aViewWindow->SetSelectionMode(ActorSelection);
790           mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
791         } else {
792           if ( aViewWindow )
793             aViewWindow->SetSelectionMode( CellSelection );
794         }
795       } else if (send == SelectPointButton) {
796         myEditCurrentArgument = (QWidget*)SpinBox_X;
797         SMESH::SetPointRepresentation(true);
798         if ( aViewWindow )
799           aViewWindow->SetSelectionMode( NodeSelection );
800       } else if (send == SelectVectorButton) {
801         myEditCurrentArgument = (QWidget*)SpinBox_DX;
802         SMESH::SetPointRepresentation(true);
803         if ( aViewWindow )
804           aViewWindow->SetSelectionMode( NodeSelection );
805       }
806       break;
807     }
808
809   }
810
811   myEditCurrentArgument->setFocus();
812   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
813   SelectionIntoArgument();
814 }
815
816 //=================================================================================
817 // function : DeactivateActiveDialog()
818 // purpose  :
819 //=================================================================================
820 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
821 {
822   if (GroupConstructors->isEnabled()) {
823     GroupConstructors->setEnabled(false);
824     GroupArguments->setEnabled(false);
825     GroupButtons->setEnabled(false);
826     mySMESHGUI->ResetState();
827     mySMESHGUI->SetActiveDialogBox(0);
828   }
829 }
830
831 //=================================================================================
832 // function : ActivateThisDialog()
833 // purpose  :
834 //=================================================================================
835 void SMESHGUI_RotationDlg::ActivateThisDialog()
836 {
837   /* Emit a signal to deactivate the active dialog */
838   mySMESHGUI->EmitSignalDeactivateDialog();
839   GroupConstructors->setEnabled(true);
840   GroupArguments->setEnabled(true);
841   GroupButtons->setEnabled(true);
842
843   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
844
845   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
846     aViewWindow->SetSelectionMode( CellSelection );
847   SelectionIntoArgument();
848 }
849
850 //=================================================================================
851 // function : enterEvent()
852 // purpose  :
853 //=================================================================================
854 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
855 {
856   if (!GroupConstructors->isEnabled())
857     ActivateThisDialog();
858 }
859
860 //=================================================================================
861 // function : closeEvent()
862 // purpose  :
863 //=================================================================================
864 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
865 {
866   /* same than click on cancel button */
867   ClickOnCancel();
868 }
869
870 //=================================================================================
871 // function : hideEvent()
872 // purpose  : caused by ESC key
873 //=================================================================================
874 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
875 {
876   if (!isMinimized())
877     ClickOnCancel();
878 }
879
880 //=================================================================================
881 // function : onSelectMesh()
882 // purpose  :
883 //=================================================================================
884 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
885 {
886   if (toSelectMesh)
887     TextLabelElements->setText(tr("SMESH_NAME"));
888   else
889     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
890   myFilterBtn->setEnabled(!toSelectMesh);
891
892   if (myEditCurrentArgument != LineEditElements) {
893     LineEditElements->clear();
894     return;
895   }
896
897   mySelectionMgr->clearFilters();
898   SMESH::SetPointRepresentation(false);
899
900   if (toSelectMesh) {
901     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
902       aViewWindow->SetSelectionMode(ActorSelection);
903     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
904     LineEditElements->setReadOnly(true);
905     LineEditElements->setValidator(0);
906   } else {
907     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
908       aViewWindow->SetSelectionMode( CellSelection );
909     LineEditElements->setReadOnly(false);
910     LineEditElements->setValidator(myIdValidator);
911     onTextChange(LineEditElements->text());
912     hidePreview();
913   }
914
915   SelectionIntoArgument();
916 }
917
918 //=================================================================================
919 // function : IsAxisOk()
920 // purpose  :
921 //=================================================================================
922 bool SMESHGUI_RotationDlg::IsAxisOk()
923 {
924   return (SpinBox_DX->GetValue() != 0 ||
925           SpinBox_DY->GetValue() != 0 ||
926           SpinBox_DZ->GetValue() != 0);
927 }
928
929 //=================================================================================
930 // function : onVectorChanged()
931 // purpose  :
932 //=================================================================================
933 void SMESHGUI_RotationDlg::onVectorChanged()
934 {
935   if (IsAxisOk()) {
936     buttonOk->setEnabled(true);
937     buttonApply->setEnabled(true);
938   } else {
939     buttonOk->setEnabled(false);
940     buttonApply->setEnabled(false);
941   }
942 }
943
944
945 //=======================================================================
946 //function : onActionClicked
947 //purpose  : slot called when an action type changed
948 //=======================================================================
949
950 void SMESHGUI_RotationDlg::onActionClicked(int button)
951 {
952   switch ( button ) {
953   case MOVE_ELEMS_BUTTON:
954     MakeGroupsCheck->setEnabled(false);
955     LineEditNewMesh->setEnabled(false);
956     break;
957   case COPY_ELEMS_BUTTON:
958     LineEditNewMesh->setEnabled(false);
959     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
960     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
961       MakeGroupsCheck->setEnabled(true);
962     else
963       MakeGroupsCheck->setEnabled(false);
964     break;
965   case MAKE_MESH_BUTTON:
966     LineEditNewMesh->setEnabled(true);
967     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
968     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
969       MakeGroupsCheck->setEnabled(true);
970     else
971       MakeGroupsCheck->setEnabled(false);
972     break;
973   }
974   setNewMeshName();
975   toDisplaySimulation();
976 }
977
978 //=======================================================================
979 //function : setNewMeshName
980 //purpose  : update contents of LineEditNewMesh
981 //=======================================================================
982
983 void SMESHGUI_RotationDlg::setNewMeshName()
984 {
985   LineEditNewMesh->setText("");
986   if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
987     QString name;
988     if ( CheckBoxMesh->isChecked() ) {
989       name = LineEditElements->text();
990     }
991     else {
992       _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
993       name = meshSO->GetName().c_str();
994     }
995     if ( !name.isEmpty() )
996       LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
997   }
998 }
999
1000 //=================================================================================
1001 // function : keyPressEvent()
1002 // purpose  :
1003 //=================================================================================
1004 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
1005 {
1006   QDialog::keyPressEvent( e );
1007   if ( e->isAccepted() )
1008     return;
1009
1010   if ( e->key() == Qt::Key_F1 ) {
1011     e->accept();
1012     ClickOnHelp();
1013   }
1014 }
1015
1016 //=================================================================================
1017 // function : setFilters()
1018 // purpose  : SLOT. Called when "Filter" button pressed.
1019 //=================================================================================
1020 void SMESHGUI_RotationDlg::setFilters()
1021 {
1022   if(myMesh->_is_nil()) {
1023     SUIT_MessageBox::critical(this,
1024                               tr("SMESH_ERROR"),
1025                               tr("NO_MESH_SELECTED"));
1026    return;
1027   }
1028   if ( !myFilterDlg )
1029     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1030
1031   myFilterDlg->SetSelection();
1032   myFilterDlg->SetMesh( myMesh );
1033   myFilterDlg->SetSourceWg( LineEditElements );
1034
1035   myFilterDlg->show();
1036 }
1037
1038 //=================================================================================
1039 // function : isValid
1040 // purpose  :
1041 //=================================================================================
1042 bool SMESHGUI_RotationDlg::isValid()
1043 {
1044   bool ok = true;
1045   QString msg;
1046
1047   ok = SpinBox_X->isValid( msg, true ) && ok;
1048   ok = SpinBox_Y->isValid( msg, true ) && ok;
1049   ok = SpinBox_Z->isValid( msg, true ) && ok;
1050   ok = SpinBox_DX->isValid( msg, true ) && ok;
1051   ok = SpinBox_DY->isValid( msg, true ) && ok;
1052   ok = SpinBox_DZ->isValid( msg, true ) && ok;
1053   ok = SpinBox_Angle->isValid( msg, true ) && ok;
1054
1055   if( !ok ) {
1056     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1057     if ( !msg.isEmpty() )
1058       str += "\n" + msg;
1059     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1060     return false;
1061   }
1062   return true;
1063 }
1064
1065
1066 //=================================================================================
1067 // function : onDisplaySimulation
1068 // purpose  : Show/Hide preview
1069 //=================================================================================
1070 void SMESHGUI_RotationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1071   if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1072     if(myNbOkElements && isValid() && IsAxisOk()) {
1073       QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1074       SMESH::long_array_var anElementsId = new SMESH::long_array;
1075       
1076       anElementsId->length(aListElementsId.count());
1077       for (int i = 0; i < aListElementsId.count(); i++)
1078         anElementsId[i] = aListElementsId[i].toInt();
1079       
1080       SMESH::AxisStruct anAxis;
1081       
1082       anAxis.x =  SpinBox_X->GetValue();
1083       anAxis.y =  SpinBox_Y->GetValue();
1084       anAxis.z =  SpinBox_Z->GetValue();;
1085       anAxis.vx = SpinBox_DX->GetValue();
1086       anAxis.vy = SpinBox_DY->GetValue();
1087       anAxis.vz = SpinBox_DZ->GetValue();
1088       double anAngle = (SpinBox_Angle->GetValue())*M_PI/180.;
1089       
1090       try {
1091         SUIT_OverrideCursor aWaitCursor;
1092         bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON  ||
1093                       ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1094         SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1095         if(CheckBoxMesh->isChecked())
1096           aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, copy);
1097         else
1098           aMeshEditor->Rotate(anElementsId, anAxis, anAngle, copy);
1099
1100         SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1101         mySimulation->SetData(aMeshPreviewStruct._retn());      
1102       } catch (...) {
1103         hidePreview();
1104       }
1105     }
1106     else {
1107       hidePreview();
1108     }
1109   } else {
1110     hidePreview();
1111   }
1112 }