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