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