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