Salome HOME
Merge from V6_3_BR 06/06/2011
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_RotationDlg.cxx
1 // Copyright (C) 2007-2011  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 (MESHorSUBMESH);
285   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (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())*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       switch ( actionButton ) {
437       case MOVE_ELEMS_BUTTON:
438         if(CheckBoxMesh->isChecked())
439           aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, false);
440         else
441             aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false);
442         if( !myMesh->_is_nil())
443           myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
444         break;
445       case COPY_ELEMS_BUTTON:
446         if ( makeGroups ) {
447           SMESH::ListOfGroups_var groups;
448           if(CheckBoxMesh->isChecked())
449             groups = aMeshEditor->RotateObjectMakeGroups(mySelectedObject, anAxis, anAngle);
450           else
451             groups = aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle);
452         }
453         else {
454           if(CheckBoxMesh->isChecked())
455             aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, true);
456           else
457             aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true);
458         }
459         if( !myMesh->_is_nil())
460           myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
461         break;
462       case MAKE_MESH_BUTTON: {
463         SMESH::SMESH_Mesh_var mesh;
464         if (CheckBoxMesh->isChecked())
465           mesh = aMeshEditor->RotateObjectMakeMesh(mySelectedObject, anAxis, anAngle, makeGroups,
466                                                    LineEditNewMesh->text().toLatin1().data());
467         else
468           mesh = aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups,
469                                              LineEditNewMesh->text().toLatin1().data());
470         if (!mesh->_is_nil()) {
471           mesh->SetParameters(aParameters.join(":").toLatin1().constData());
472           if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
473             anEntryList.append( aSObject->GetID().c_str() );
474 #ifdef WITHGENERICOBJ
475           // obj has been published in study. Its refcount has been incremented.
476           // It is safe to decrement its refcount
477           // so that it will be destroyed when the entry in study will be removed
478           mesh->UnRegister();
479 #endif
480         }
481         break;
482       }
483       }
484     } catch (...) {
485     }
486
487     SMESH::UpdateView();
488     if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
489          actionButton == MAKE_MESH_BUTTON ) {
490       mySMESHGUI->updateObjBrowser(true); // new groups may appear
491       if( LightApp_Application* anApp =
492           dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
493         anApp->browseObjects( anEntryList, isApplyAndClose() );
494     }
495     Init(false);
496     mySelectedObject = SMESH::SMESH_IDSource::_nil();
497     SelectionIntoArgument();
498
499     SMESHGUI::Modified();
500   }
501
502   return true;
503 }
504
505 //=================================================================================
506 // function : ClickOnOk()
507 // purpose  :
508 //=================================================================================
509 void SMESHGUI_RotationDlg::ClickOnOk()
510 {
511   setIsApplyAndClose( true );
512   if( ClickOnApply() )
513     ClickOnCancel();
514 }
515
516 //=================================================================================
517 // function : ClickOnCancel()
518 // purpose  :
519 //=================================================================================
520 void SMESHGUI_RotationDlg::ClickOnCancel()
521 {
522   disconnect(mySelectionMgr, 0, this, 0);
523   mySelectionMgr->clearFilters();
524   //mySelectionMgr->clearSelected();
525   if (SMESH::GetCurrentVtkView()) {
526     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
527     SMESH::SetPointRepresentation(false);
528   }
529   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
530     aViewWindow->SetSelectionMode(ActorSelection);
531   mySMESHGUI->ResetState();
532   reject();
533 }
534
535 //=================================================================================
536 // function : ClickOnHelp()
537 // purpose  :
538 //=================================================================================
539 void SMESHGUI_RotationDlg::ClickOnHelp()
540 {
541   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
542   if (app)
543     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
544   else {
545     QString platform;
546 #ifdef WIN32
547     platform = "winapplication";
548 #else
549     platform = "application";
550 #endif
551     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
552                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
553                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
554                                                                  platform)).
555                              arg(myHelpFileName));
556   }
557 }
558
559 //=======================================================================
560 // function : onTextChange()
561 // purpose  :
562 //=======================================================================
563 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
564 {
565   QLineEdit* send = (QLineEdit*)sender();
566
567   if (myBusy) return;
568   myBusy = true;
569
570   if (send == LineEditElements)
571     myNbOkElements = 0;
572
573   buttonOk->setEnabled(false);
574   buttonApply->setEnabled(false);
575
576   // hilight entered elements
577   SMDS_Mesh* aMesh = 0;
578   if (myActor)
579     aMesh = myActor->GetObject()->GetMesh();
580
581   if (aMesh) {
582     if (send == LineEditElements) {
583       Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
584
585       TColStd_MapOfInteger newIndices;
586
587       QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
588       for (int i = 0; i < aListId.count(); i++) {
589         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
590         if (e)
591           newIndices.Add(e->GetID());
592         myNbOkElements++;
593       }
594
595       mySelector->AddOrRemoveIndex( anIO, newIndices, false );
596       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
597         aViewWindow->highlight( anIO, true, true );
598
599       myElementsId = theNewText;
600     }
601   }
602
603   if (myNbOkElements && IsAxisOk()) {
604     buttonOk->setEnabled(true);
605     buttonApply->setEnabled(true);
606   }
607
608   myBusy = false;
609 }
610
611 //=================================================================================
612 // function : SelectionIntoArgument()
613 // purpose  : Called when selection as changed or other case
614 //=================================================================================
615 void SMESHGUI_RotationDlg::SelectionIntoArgument()
616 {
617   if (myBusy) return;
618
619   // clear
620   myActor = 0;
621   QString aString = "";
622
623   myBusy = true;
624   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
625     LineEditElements->setText(aString);
626     myNbOkElements = 0;
627     buttonOk->setEnabled(false);
628     buttonApply->setEnabled(false);
629   }
630   myBusy = false;
631
632   if (!GroupButtons->isEnabled()) // inactive
633     return;
634
635   // get selected mesh
636   SALOME_ListIO aList;
637   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
638
639   int nbSel = aList.Extent();
640   if (nbSel != 1)
641     return;
642
643   Handle(SALOME_InteractiveObject) IO = aList.First();
644   myMesh = SMESH::GetMeshByIO(IO);
645   if (myMesh->_is_nil())
646     return;
647
648   myActor = SMESH::FindActorByObject(myMesh);
649   if (!myActor)
650     myActor = SMESH::FindActorByEntry(IO->getEntry());
651   if (!myActor && !CheckBoxMesh->isChecked())
652     return;
653
654   int aNbUnits = 0;
655
656   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
657     myElementsId = "";
658
659     // MakeGroups is available if there are groups and "Copy"
660     if ( myMesh->NbGroups() == 0 ) {
661       MakeGroupsCheck->setChecked(false);
662       MakeGroupsCheck->setEnabled(false);
663     }
664     else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
665       MakeGroupsCheck->setEnabled(true);
666     }
667     if (CheckBoxMesh->isChecked()) {
668       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
669
670       if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH
671         mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
672       }
673       else
674         return;
675         // get IDs from mesh
676         /*
677           SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
678           if (!aSMDSMesh)
679           return;
680
681           for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
682           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
683           if (e) {
684             myElementsId += QString(" %1").arg(i);
685             aNbUnits++;
686           }
687         }
688       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
689       // get submesh
690         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
691
692         // get IDs from submesh
693         SMESH::long_array_var anElementsIds = new SMESH::long_array;
694         anElementsIds = aSubMesh->GetElementsId();
695         for (int i = 0; i < anElementsIds->length(); i++) {
696         myElementsId += QString(" %1").arg(anElementsIds[i]);
697           }
698         aNbUnits = anElementsIds->length();
699       } else { // GROUP
700         // get smesh group
701         SMESH::SMESH_GroupBase_var aGroup =
702         SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
703         if (aGroup->_is_nil())
704         return;
705
706           // get IDs from smesh group
707         SMESH::long_array_var anElementsIds = new SMESH::long_array;
708         anElementsIds = aGroup->GetListOfID();
709         for (int i = 0; i < anElementsIds->length(); i++) {
710         myElementsId += QString(" %1").arg(anElementsIds[i]);
711           }
712         aNbUnits = anElementsIds->length();
713         }
714         */
715       } else {
716       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
717       myElementsId = aString;
718       if (aNbUnits < 1)
719         return;
720       }
721
722     myNbOkElements = true;
723
724   } else {
725     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
726     if (aNbUnits != 1)
727       return;
728
729     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
730     if (!aMesh)
731       return;
732
733     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
734     if (!n)
735       return;
736
737     double x = n->X();
738     double y = n->Y();
739     double z = n->Z();
740
741     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
742       SpinBox_X->SetValue(x);
743       SpinBox_Y->SetValue(y);
744       SpinBox_Z->SetValue(z);
745     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
746       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
747       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
748       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
749     }
750   }
751
752   myBusy = true;
753   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
754     LineEditElements->setText(aString);
755     LineEditElements->repaint();
756     LineEditElements->setEnabled(false); // to update lineedit IPAL 19809
757     LineEditElements->setEnabled(true);
758     setNewMeshName();
759   }
760   myBusy = false;
761
762   // OK
763   if (myNbOkElements && IsAxisOk()) {
764     buttonOk->setEnabled(true);
765     buttonApply->setEnabled(true);
766   }
767   onDisplaySimulation(true);
768 }
769
770 //=================================================================================
771 // function : SetEditCurrentArgument()
772 // purpose  :
773 //=================================================================================
774 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
775 {
776   QPushButton* send = (QPushButton*)sender();
777
778   disconnect(mySelectionMgr, 0, this, 0);
779   mySelectionMgr->clearSelected();
780   mySelectionMgr->clearFilters();
781
782   switch (myConstructorId) {
783   case 0: /* default constructor */
784     {
785       SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
786       if (send == SelectElementsButton) {
787         myEditCurrentArgument = (QWidget*)LineEditElements;
788         SMESH::SetPointRepresentation(false);
789         if (CheckBoxMesh->isChecked()) {
790           if ( aViewWindow )
791             aViewWindow->SetSelectionMode(ActorSelection);
792           mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
793         } else {
794           if ( aViewWindow )
795             aViewWindow->SetSelectionMode( CellSelection );
796         }
797       } else if (send == SelectPointButton) {
798         myEditCurrentArgument = (QWidget*)SpinBox_X;
799         SMESH::SetPointRepresentation(true);
800         if ( aViewWindow )
801           aViewWindow->SetSelectionMode( NodeSelection );
802       } else if (send == SelectVectorButton) {
803         myEditCurrentArgument = (QWidget*)SpinBox_DX;
804         SMESH::SetPointRepresentation(true);
805         if ( aViewWindow )
806           aViewWindow->SetSelectionMode( NodeSelection );
807       }
808       break;
809     }
810
811   }
812
813   myEditCurrentArgument->setFocus();
814   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
815   SelectionIntoArgument();
816 }
817
818 //=================================================================================
819 // function : DeactivateActiveDialog()
820 // purpose  :
821 //=================================================================================
822 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
823 {
824   if (GroupConstructors->isEnabled()) {
825     GroupConstructors->setEnabled(false);
826     GroupArguments->setEnabled(false);
827     GroupButtons->setEnabled(false);
828     mySMESHGUI->ResetState();
829     mySMESHGUI->SetActiveDialogBox(0);
830   }
831 }
832
833 //=================================================================================
834 // function : ActivateThisDialog()
835 // purpose  :
836 //=================================================================================
837 void SMESHGUI_RotationDlg::ActivateThisDialog()
838 {
839   /* Emit a signal to deactivate the active dialog */
840   mySMESHGUI->EmitSignalDeactivateDialog();
841   GroupConstructors->setEnabled(true);
842   GroupArguments->setEnabled(true);
843   GroupButtons->setEnabled(true);
844
845   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
846
847   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
848     aViewWindow->SetSelectionMode( CellSelection );
849   SelectionIntoArgument();
850 }
851
852 //=================================================================================
853 // function : enterEvent()
854 // purpose  :
855 //=================================================================================
856 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
857 {
858   if (!GroupConstructors->isEnabled())
859     ActivateThisDialog();
860 }
861
862 //=================================================================================
863 // function : closeEvent()
864 // purpose  :
865 //=================================================================================
866 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
867 {
868   /* same than click on cancel button */
869   ClickOnCancel();
870 }
871
872 //=================================================================================
873 // function : hideEvent()
874 // purpose  : caused by ESC key
875 //=================================================================================
876 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
877 {
878   if (!isMinimized())
879     ClickOnCancel();
880 }
881
882 //=================================================================================
883 // function : onSelectMesh()
884 // purpose  :
885 //=================================================================================
886 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
887 {
888   if (toSelectMesh)
889     TextLabelElements->setText(tr("SMESH_NAME"));
890   else
891     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
892   myFilterBtn->setEnabled(!toSelectMesh);
893
894   if (myEditCurrentArgument != LineEditElements) {
895     LineEditElements->clear();
896     return;
897   }
898
899   mySelectionMgr->clearFilters();
900   SMESH::SetPointRepresentation(false);
901
902   if (toSelectMesh) {
903     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
904       aViewWindow->SetSelectionMode(ActorSelection);
905     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
906     LineEditElements->setReadOnly(true);
907     LineEditElements->setValidator(0);
908   } else {
909     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
910       aViewWindow->SetSelectionMode( CellSelection );
911     LineEditElements->setReadOnly(false);
912     LineEditElements->setValidator(myIdValidator);
913     onTextChange(LineEditElements->text());
914     hidePreview();
915   }
916
917   SelectionIntoArgument();
918 }
919
920 //=================================================================================
921 // function : IsAxisOk()
922 // purpose  :
923 //=================================================================================
924 bool SMESHGUI_RotationDlg::IsAxisOk()
925 {
926   return (SpinBox_DX->GetValue() != 0 ||
927           SpinBox_DY->GetValue() != 0 ||
928           SpinBox_DZ->GetValue() != 0);
929 }
930
931 //=================================================================================
932 // function : onVectorChanged()
933 // purpose  :
934 //=================================================================================
935 void SMESHGUI_RotationDlg::onVectorChanged()
936 {
937   if (IsAxisOk()) {
938     buttonOk->setEnabled(true);
939     buttonApply->setEnabled(true);
940   } else {
941     buttonOk->setEnabled(false);
942     buttonApply->setEnabled(false);
943   }
944 }
945
946
947 //=======================================================================
948 //function : onActionClicked
949 //purpose  : slot called when an action type changed
950 //=======================================================================
951
952 void SMESHGUI_RotationDlg::onActionClicked(int button)
953 {
954   switch ( button ) {
955   case MOVE_ELEMS_BUTTON:
956     MakeGroupsCheck->setEnabled(false);
957     LineEditNewMesh->setEnabled(false);
958     break;
959   case COPY_ELEMS_BUTTON:
960     LineEditNewMesh->setEnabled(false);
961     MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
962     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
963       MakeGroupsCheck->setEnabled(true);
964     else
965       MakeGroupsCheck->setEnabled(false);
966     break;
967   case MAKE_MESH_BUTTON:
968     LineEditNewMesh->setEnabled(true);
969     MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
970     if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
971       MakeGroupsCheck->setEnabled(true);
972     else
973       MakeGroupsCheck->setEnabled(false);
974     break;
975   }
976   setNewMeshName();
977   toDisplaySimulation();
978 }
979
980 //=======================================================================
981 //function : setNewMeshName
982 //purpose  : update contents of LineEditNewMesh
983 //=======================================================================
984
985 void SMESHGUI_RotationDlg::setNewMeshName()
986 {
987   LineEditNewMesh->setText("");
988   if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
989     QString name;
990     if ( CheckBoxMesh->isChecked() ) {
991       name = LineEditElements->text();
992     }
993     else {
994       _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
995       name = meshSO->GetName().c_str();
996     }
997     if ( !name.isEmpty() )
998       LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "rotated"));
999   }
1000 }
1001
1002 //=================================================================================
1003 // function : keyPressEvent()
1004 // purpose  :
1005 //=================================================================================
1006 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
1007 {
1008   QDialog::keyPressEvent( e );
1009   if ( e->isAccepted() )
1010     return;
1011
1012   if ( e->key() == Qt::Key_F1 ) {
1013     e->accept();
1014     ClickOnHelp();
1015   }
1016 }
1017
1018 //=================================================================================
1019 // function : setFilters()
1020 // purpose  : SLOT. Called when "Filter" button pressed.
1021 //=================================================================================
1022 void SMESHGUI_RotationDlg::setFilters()
1023 {
1024   if(myMesh->_is_nil()) {
1025     SUIT_MessageBox::critical(this,
1026                               tr("SMESH_ERROR"),
1027                               tr("NO_MESH_SELECTED"));
1028    return;
1029   }
1030   if ( !myFilterDlg )
1031     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1032
1033   myFilterDlg->SetSelection();
1034   myFilterDlg->SetMesh( myMesh );
1035   myFilterDlg->SetSourceWg( LineEditElements );
1036
1037   myFilterDlg->show();
1038 }
1039
1040 //=================================================================================
1041 // function : isValid
1042 // purpose  :
1043 //=================================================================================
1044 bool SMESHGUI_RotationDlg::isValid()
1045 {
1046   bool ok = true;
1047   QString msg;
1048
1049   ok = SpinBox_X->isValid( msg, true ) && ok;
1050   ok = SpinBox_Y->isValid( msg, true ) && ok;
1051   ok = SpinBox_Z->isValid( msg, true ) && ok;
1052   ok = SpinBox_DX->isValid( msg, true ) && ok;
1053   ok = SpinBox_DY->isValid( msg, true ) && ok;
1054   ok = SpinBox_DZ->isValid( msg, true ) && ok;
1055   ok = SpinBox_Angle->isValid( msg, true ) && ok;
1056
1057   if( !ok ) {
1058     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1059     if ( !msg.isEmpty() )
1060       str += "\n" + msg;
1061     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1062     return false;
1063   }
1064   return true;
1065 }
1066
1067
1068 //=================================================================================
1069 // function : onDisplaySimulation
1070 // purpose  : Show/Hide preview
1071 //=================================================================================
1072 void SMESHGUI_RotationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1073   if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1074     if(myNbOkElements && isValid() && IsAxisOk()) {
1075       QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1076       SMESH::long_array_var anElementsId = new SMESH::long_array;
1077       
1078       anElementsId->length(aListElementsId.count());
1079       for (int i = 0; i < aListElementsId.count(); i++)
1080         anElementsId[i] = aListElementsId[i].toInt();
1081       
1082       SMESH::AxisStruct anAxis;
1083       
1084       anAxis.x =  SpinBox_X->GetValue();
1085       anAxis.y =  SpinBox_Y->GetValue();
1086       anAxis.z =  SpinBox_Z->GetValue();;
1087       anAxis.vx = SpinBox_DX->GetValue();
1088       anAxis.vy = SpinBox_DY->GetValue();
1089       anAxis.vz = SpinBox_DZ->GetValue();
1090       double anAngle = (SpinBox_Angle->GetValue())*PI/180;
1091       
1092       try {
1093         SUIT_OverrideCursor aWaitCursor;
1094         bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON  ||
1095                       ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1096         SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1097         if(CheckBoxMesh->isChecked())
1098           aMeshEditor->RotateObject(mySelectedObject, anAxis, anAngle, copy);
1099         else
1100           aMeshEditor->Rotate(anElementsId, anAxis, anAngle, copy);
1101
1102         SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1103         mySimulation->SetData(aMeshPreviewStruct._retn());      
1104       } catch (...) {
1105         hidePreview();
1106       }
1107     }
1108     else {
1109       hidePreview();
1110     }
1111   } else {
1112     hidePreview();
1113   }
1114 }