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