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