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