Salome HOME
Additional fix for bug IPAL9834(selection in transformation does not work for group...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_RotationDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  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 //
24 //  File   : SMESHGUI_RotationDlg.cxx
25 //  Author : Michael ZORIN
26 //  Module : SMESH
27 //  $Header:
28
29 #include "SMESHGUI_RotationDlg.h"
30
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_SpinBox.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_VTKUtils.h"
35 #include "SMESHGUI_MeshUtils.h"
36 #include "SMESHGUI_IdValidator.h"
37
38 #include "SMESH_Actor.h"
39 #include "SMESH_TypeFilter.hxx"
40 #include "SMESH_LogicalFilter.hxx"
41 #include "SMDS_Mesh.hxx"
42
43 #include "SUIT_Desktop.h"
44 #include "SUIT_Session.h"
45 #include "SUIT_MessageBox.h"
46
47 #include "LightApp_Application.h"
48
49 #include "SVTK_ViewModel.h"
50 #include "SVTK_ViewWindow.h"
51 #include "SVTK_Selector.h"
52 #include "SVTK_Selection.h"
53 #include "SALOME_ListIO.hxx"
54
55 #include "utilities.h"
56
57 // OCCT Includes
58 #include <TColStd_MapOfInteger.hxx>
59 #include <TColStd_IndexedMapOfInteger.hxx>
60
61 // QT Includes
62 #include <qapplication.h>
63 #include <qbuttongroup.h>
64 #include <qgroupbox.h>
65 #include <qlabel.h>
66 #include <qlineedit.h>
67 #include <qpushbutton.h>
68 #include <qradiobutton.h>
69 #include <qcheckbox.h>
70 #include <qlayout.h>
71 #include <qpixmap.h>
72
73 // IDL Headers
74 #include "SALOMEconfig.h"
75 #include CORBA_SERVER_HEADER(SMESH_Group)
76
77 using namespace std;
78
79 //=================================================================================
80 // class    : SMESHGUI_RotationDlg()
81 // purpose  :
82 //=================================================================================
83 SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule, const char* name,
84                                             bool modal, WFlags fl)
85      : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
86                WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
87      mySMESHGUI( theModule ),
88      mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
89 {
90   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_ROTATION")));
91   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
92
93   if (!name)
94     setName("SMESHGUI_RotationDlg");
95   resize(303, 185);
96   setCaption(tr("SMESH_ROTATION_TITLE"));
97   setSizeGripEnabled(TRUE);
98   SMESHGUI_RotationDlgLayout = new QGridLayout(this);
99   SMESHGUI_RotationDlgLayout->setSpacing(6);
100   SMESHGUI_RotationDlgLayout->setMargin(11);
101
102   /***************************************************************/
103   GroupConstructors = new QButtonGroup(this, "GroupConstructors");
104   GroupConstructors->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5,
105                                                (QSizePolicy::SizeType)0, 0, 0,
106                                                GroupConstructors->sizePolicy().hasHeightForWidth()));
107   GroupConstructors->setTitle(tr("SMESH_ROTATION"));
108   GroupConstructors->setExclusive(TRUE);
109   GroupConstructors->setColumnLayout(0, Qt::Vertical);
110   GroupConstructors->layout()->setSpacing(0);
111   GroupConstructors->layout()->setMargin(0);
112   GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
113   GroupConstructorsLayout->setAlignment(Qt::AlignTop);
114   GroupConstructorsLayout->setSpacing(6);
115   GroupConstructorsLayout->setMargin(11);
116   RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
117   RadioButton1->setText(tr("" ));
118   RadioButton1->setPixmap(image0);
119   RadioButton1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)1,
120                                           (QSizePolicy::SizeType)0,
121                                           RadioButton1->sizePolicy().hasHeightForWidth()));
122   RadioButton1->setMinimumSize(QSize(50, 0));
123   GroupConstructorsLayout->addWidget(RadioButton1, 0, 0);
124   QSpacerItem* spacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
125   GroupConstructorsLayout->addItem(spacer, 0, 1);
126   SMESHGUI_RotationDlgLayout->addWidget(GroupConstructors, 0, 0);
127
128   /***************************************************************/
129   GroupButtons = new QGroupBox(this, "GroupButtons");
130   GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
131                                           (QSizePolicy::SizeType)0, 0, 0,
132                                           GroupButtons->sizePolicy().hasHeightForWidth()));
133   GroupButtons->setGeometry(QRect(10, 10, 281, 48));
134   GroupButtons->setTitle(tr("" ));
135   GroupButtons->setColumnLayout(0, Qt::Vertical);
136   GroupButtons->layout()->setSpacing(0);
137   GroupButtons->layout()->setMargin(0);
138   GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
139   GroupButtonsLayout->setAlignment(Qt::AlignTop);
140   GroupButtonsLayout->setSpacing(6);
141   GroupButtonsLayout->setMargin(11);
142   buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
143   buttonHelp->setText(tr("SMESH_BUT_HELP" ));
144   buttonHelp->setAutoDefault(TRUE);
145   GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
146   buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
147   buttonCancel->setText(tr("SMESH_BUT_CLOSE"));
148   buttonCancel->setAutoDefault(TRUE);
149   GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
150   buttonApply = new QPushButton(GroupButtons, "buttonApply");
151   buttonApply->setText(tr("SMESH_BUT_APPLY"));
152   buttonApply->setAutoDefault(TRUE);
153   GroupButtonsLayout->addWidget(buttonApply, 0, 1);
154   QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
155   GroupButtonsLayout->addItem(spacer_9, 0, 2);
156   buttonOk = new QPushButton(GroupButtons, "buttonOk");
157   buttonOk->setText(tr("SMESH_BUT_OK"));
158   buttonOk->setAutoDefault(TRUE);
159   buttonOk->setDefault(TRUE);
160   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
161   SMESHGUI_RotationDlgLayout->addWidget(GroupButtons, 2, 0);
162
163   /***************************************************************/
164   GroupArguments = new QGroupBox(this, "GroupArguments");
165   GroupArguments->setTitle(tr("SMESH_ARGUMENTS"));
166   GroupArguments->setColumnLayout(0, Qt::Vertical);
167   GroupArguments->layout()->setSpacing(0);
168   GroupArguments->layout()->setMargin(0);
169   GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
170   GroupArgumentsLayout->setAlignment(Qt::AlignTop);
171   GroupArgumentsLayout->setSpacing(6);
172   GroupArgumentsLayout->setMargin(11);
173
174   // Controls for elements selection
175   TextLabelElements  = new QLabel(GroupArguments, "TextLabelElements");
176   TextLabelElements->setText(tr("SMESH_ID_ELEMENTS" ));
177   TextLabelElements->setFixedWidth(74);
178   GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
179
180   SelectElementsButton  = new QPushButton(GroupArguments, "SelectElementsButton");
181   SelectElementsButton->setText(tr("" ));
182   SelectElementsButton->setPixmap(image1);
183   SelectElementsButton->setToggleButton(FALSE);
184   GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
185
186   LineEditElements  = new QLineEdit(GroupArguments, "LineEditElements");
187   LineEditElements->setValidator(new SMESHGUI_IdValidator(this, "validator"));
188   GroupArgumentsLayout->addWidget(LineEditElements, 0, 2);
189
190   // Control for the whole mesh selection
191   CheckBoxMesh = new QCheckBox(GroupArguments, "CheckBoxMesh");
192   CheckBoxMesh->setText(tr("SMESH_SELECT_WHOLE_MESH" ));
193   GroupArgumentsLayout->addMultiCellWidget(CheckBoxMesh, 1, 1, 0, 2);
194
195   // Controls for axis defining
196   GroupAxis = new QGroupBox(GroupArguments, "GroupAxis");
197   GroupAxis->setTitle(tr("SMESH_AXIS"));
198   GroupAxis->setColumnLayout(0, Qt::Vertical);
199   GroupAxis->layout()->setSpacing(0);
200   GroupAxis->layout()->setMargin(0);
201   QGridLayout* GroupAxisLayout = new QGridLayout(GroupAxis->layout());
202   GroupAxisLayout->setAlignment(Qt::AlignTop);
203   GroupAxisLayout->setSpacing(6);
204   GroupAxisLayout->setMargin(11);
205
206   TextLabelPoint = new QLabel(GroupAxis, "TextLabelPoint");
207   TextLabelPoint->setText(tr("SMESH_POINT"));
208   GroupAxisLayout->addWidget(TextLabelPoint, 0, 0);
209
210   SelectPointButton  = new QPushButton(GroupAxis, "SelectPointButton");
211   SelectPointButton->setPixmap(image1);
212   GroupAxisLayout->addWidget(SelectPointButton, 0, 1);
213
214   TextLabelX = new QLabel(GroupAxis, "TextLabelX");
215   TextLabelX->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
216   TextLabelX->setText(tr("SMESH_X"));
217   GroupAxisLayout->addWidget(TextLabelX, 0, 2);
218
219   SpinBox_X = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_X");
220   GroupAxisLayout->addWidget(SpinBox_X, 0, 3);
221
222   TextLabelY = new QLabel(GroupAxis, "TextLabelY");
223   TextLabelY->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
224   TextLabelY->setText(tr("SMESH_Y"));
225   GroupAxisLayout->addWidget(TextLabelY, 0, 4);
226
227   SpinBox_Y = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_Y");
228   GroupAxisLayout->addWidget(SpinBox_Y, 0, 5);
229
230   TextLabelZ = new QLabel(GroupAxis, "TextLabelZ");
231   TextLabelZ->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
232   TextLabelZ->setText(tr("SMESH_Z"));
233   GroupAxisLayout->addWidget(TextLabelZ, 0, 6);
234
235   SpinBox_Z = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_Z");
236   GroupAxisLayout->addWidget(SpinBox_Z, 0, 7);
237
238   TextLabelVector = new QLabel(GroupAxis, "TextLabelVector");
239   TextLabelVector->setText(tr("SMESH_VECTOR"));
240   GroupAxisLayout->addWidget(TextLabelVector, 1, 0);
241
242   SelectVectorButton = new QPushButton(GroupAxis, "SelectVectorButton");
243   SelectVectorButton->setPixmap(image1);
244   GroupAxisLayout->addWidget(SelectVectorButton, 1, 1);
245
246   TextLabelDX = new QLabel(GroupAxis, "TextLabelDX");
247   TextLabelDX->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
248   TextLabelDX->setText(tr("SMESH_DX"));
249   GroupAxisLayout->addWidget(TextLabelDX, 1, 2);
250
251   SpinBox_DX = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_DX");
252   GroupAxisLayout->addWidget(SpinBox_DX, 1, 3);
253
254   TextLabelDY = new QLabel(GroupAxis, "TextLabelDY");
255   TextLabelDY->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
256   TextLabelDY->setText(tr("SMESH_DY"));
257   GroupAxisLayout->addWidget(TextLabelDY, 1, 4);
258
259   SpinBox_DY = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_DY");
260   GroupAxisLayout->addWidget(SpinBox_DY, 1, 5);
261
262   TextLabelDZ = new QLabel(GroupAxis, "TextLabelDZ");
263   TextLabelDZ->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
264   TextLabelDZ->setText(tr("SMESH_DZ"));
265   GroupAxisLayout->addWidget(TextLabelDZ, 1, 6);
266
267   SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_DZ");
268   GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7);
269
270   GroupArgumentsLayout->addMultiCellWidget(GroupAxis, 2, 2, 0, 2);
271
272   // Controls for angle defining
273   TextLabelAngle = new QLabel(GroupArguments, "TextLabelAngle");
274   TextLabelAngle->setText(tr("SMESH_ANGLE"));
275   GroupArgumentsLayout->addMultiCellWidget(TextLabelAngle, 3, 3, 0, 1);
276
277   SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments, "SpinBox_Angle");
278   GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2);
279
280   // Controls for "Create a copy" option
281   CheckBoxCopy = new QCheckBox(GroupArguments, "CheckBoxCopy");
282   CheckBoxCopy->setText(tr("SMESH_CREATE_COPY"));
283   GroupArgumentsLayout->addMultiCellWidget(CheckBoxCopy, 4, 4, 0, 2);
284
285   SMESHGUI_RotationDlgLayout->addWidget(GroupArguments, 1, 0);
286
287   /* Initialisations */
288   SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
289   SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
290   SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
291   SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
292   SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
293   SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
294
295   SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, 3);
296
297   GroupArguments->show();
298   myConstructorId = 0;
299   RadioButton1->setChecked(TRUE);
300
301   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
302
303   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
304
305   // Costruction of the logical filter
306   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
307   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
308
309   QPtrList<SUIT_SelectionFilter> aListOfFilters;
310   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
311   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
312
313   myMeshOrSubMeshOrGroupFilter =
314     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
315
316   myHelpFileName = "/files/rotation.htm";
317
318   Init();
319
320   /* signals and slots connections */
321   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
322   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
323   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
324   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
325   connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
326
327   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
328   connect(SelectPointButton, SIGNAL (clicked()),    this, SLOT(SetEditCurrentArgument()));
329   connect(SelectVectorButton, SIGNAL (clicked()),   this, SLOT(SetEditCurrentArgument()));
330
331   connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
332   connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
333   connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
334
335   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
336   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),   this, SLOT(SelectionIntoArgument()));
337   /* to close dialog if study change */
338   connect(mySMESHGUI,       SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
339   connect(LineEditElements, SIGNAL(textChanged(const QString&)),    SLOT(onTextChange(const QString&)));
340   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                  SLOT(onSelectMesh(bool)));
341
342   this->show(); /* displays Dialog */
343
344   ConstructorsClicked(0);
345   resize(0,0); // ??
346 }
347
348 //=================================================================================
349 // function : ~SMESHGUI_RotationDlg()
350 // purpose  : Destroys the object and frees any allocated resources
351 //=================================================================================
352 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
353 {
354   // no need to delete child widgets, Qt does it all for us
355 }
356
357 //=================================================================================
358 // function : Init()
359 // purpose  :
360 //=================================================================================
361 void SMESHGUI_RotationDlg::Init (bool ResetControls)
362 {
363   myBusy = false;
364
365   myEditCurrentArgument = (QWidget*)LineEditElements;
366   LineEditElements->setFocus();
367   myElementsId = "";
368   myNbOkElements = 0;
369
370   buttonOk->setEnabled(false);
371   buttonApply->setEnabled(false);
372
373   myActor = 0;
374   myMesh = SMESH::SMESH_Mesh::_nil();
375
376   if (ResetControls) {
377     SpinBox_X->SetValue(0.0);
378     SpinBox_Y->SetValue(0.0);
379     SpinBox_Z->SetValue(0.0);
380     SpinBox_DX->SetValue(0.0);
381     SpinBox_DY->SetValue(0.0);
382     SpinBox_DZ->SetValue(0.0);
383
384     SpinBox_Angle->SetValue(45);
385
386     CheckBoxCopy->setChecked(false);
387     CheckBoxMesh->setChecked(false);
388   }
389
390   onSelectMesh(CheckBoxMesh->isChecked());
391 }
392
393 //=================================================================================
394 // function : ConstructorsClicked()
395 // purpose  : Radio button management
396 //=================================================================================
397 void SMESHGUI_RotationDlg::ConstructorsClicked (int constructorId)
398 {
399 }
400
401 //=================================================================================
402 // function : ClickOnApply()
403 // purpose  :
404 //=================================================================================
405 void SMESHGUI_RotationDlg::ClickOnApply()
406 {
407   if (mySMESHGUI->isActiveStudyLocked())
408     return;
409
410   if (myNbOkElements && IsAxisOk()) {
411     QStringList aListElementsId = QStringList::split(" ", myElementsId, false);
412
413     SMESH::long_array_var anElementsId = new SMESH::long_array;
414
415     anElementsId->length(aListElementsId.count());
416     for (int i = 0; i < aListElementsId.count(); i++)
417       anElementsId[i] = aListElementsId[i].toInt();
418
419     SMESH::AxisStruct anAxis;
420
421     anAxis.x =  SpinBox_X->GetValue();
422     anAxis.y =  SpinBox_Y->GetValue();
423     anAxis.z =  SpinBox_Z->GetValue();;
424     anAxis.vx = SpinBox_DX->GetValue();
425     anAxis.vy = SpinBox_DY->GetValue();
426     anAxis.vz = SpinBox_DZ->GetValue();
427
428     double anAngle = (SpinBox_Angle->GetValue())*PI/180;
429     bool toCreateCopy = CheckBoxCopy->isChecked();
430
431     try {
432       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
433       QApplication::setOverrideCursor(Qt::waitCursor);
434       aMeshEditor->Rotate(anElementsId.inout(), anAxis, anAngle, toCreateCopy);
435       QApplication::restoreOverrideCursor();
436     } catch (...) {
437     }
438
439     SMESH::UpdateView();
440     Init(false);
441     SelectionIntoArgument();
442   }
443 }
444
445 //=================================================================================
446 // function : ClickOnOk()
447 // purpose  :
448 //=================================================================================
449 void SMESHGUI_RotationDlg::ClickOnOk()
450 {
451   ClickOnApply();
452   ClickOnCancel();
453 }
454
455 //=================================================================================
456 // function : ClickOnCancel()
457 // purpose  :
458 //=================================================================================
459 void SMESHGUI_RotationDlg::ClickOnCancel()
460 {
461   disconnect(mySelectionMgr, 0, this, 0);
462   mySelectionMgr->clearFilters();
463   //mySelectionMgr->clearSelected();
464   SMESH::SetPointRepresentation(false);
465   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
466     aViewWindow->SetSelectionMode(ActorSelection);
467   mySMESHGUI->ResetState();
468   reject();
469 }
470
471 //=================================================================================
472 // function : ClickOnHelp()
473 // purpose  :
474 //=================================================================================
475 void SMESHGUI_RotationDlg::ClickOnHelp()
476 {
477   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
478   if (app) 
479     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
480   else {
481     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
482                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
483                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
484                            QObject::tr("BUT_OK"));
485   }
486 }
487
488 //=======================================================================
489 // function : onTextChange()
490 // purpose  :
491 //=======================================================================
492 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
493 {
494   QLineEdit* send = (QLineEdit*)sender();
495
496   if (myBusy) return;
497   myBusy = true;
498
499   if (send == LineEditElements)
500     myNbOkElements = 0;
501
502   buttonOk->setEnabled(false);
503   buttonApply->setEnabled(false);
504
505   // hilight entered elements
506   SMDS_Mesh* aMesh = 0;
507   if (myActor)
508     aMesh = myActor->GetObject()->GetMesh();
509
510   if (aMesh) {
511     if (send == LineEditElements) {
512       Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
513       
514       TColStd_MapOfInteger newIndices;
515       
516       QStringList aListId = QStringList::split(" ", theNewText, false);
517       for (int i = 0; i < aListId.count(); i++) {
518         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
519         if (e)
520           newIndices.Add(e->GetID());
521         myNbOkElements++;
522       }
523
524       mySelector->AddOrRemoveIndex( anIO, newIndices, false );
525       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
526         aViewWindow->highlight( anIO, true, true );
527       
528       myElementsId = theNewText;
529     }
530   }
531
532   if (myNbOkElements && IsAxisOk()) {
533     buttonOk->setEnabled(true);
534     buttonApply->setEnabled(true);
535   }
536
537   myBusy = false;
538 }
539
540 //=================================================================================
541 // function : SelectionIntoArgument()
542 // purpose  : Called when selection as changed or other case
543 //=================================================================================
544 void SMESHGUI_RotationDlg::SelectionIntoArgument()
545 {
546   if (myBusy) return;
547
548   // clear
549   myActor = 0;
550   QString aString = "";
551
552   myBusy = true;
553   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
554     LineEditElements->setText(aString);
555     myNbOkElements = 0;
556     buttonOk->setEnabled(false);
557     buttonApply->setEnabled(false);
558   }
559   myBusy = false;
560
561   if (!GroupButtons->isEnabled()) // inactive
562     return;
563
564   // get selected mesh
565   SALOME_ListIO aList;
566   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
567
568   int nbSel = aList.Extent();
569   if (nbSel != 1)
570     return;
571
572   Handle(SALOME_InteractiveObject) IO = aList.First();
573   myMesh = SMESH::GetMeshByIO(IO);
574   if (myMesh->_is_nil())
575     return;
576
577   myActor = SMESH::FindActorByObject(myMesh);
578   if (!myActor)
579     myActor = SMESH::FindActorByEntry(IO->getEntry());
580   if (!myActor)
581     return;
582
583   int aNbUnits = 0;
584
585   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
586     myElementsId = "";
587
588     if (CheckBoxMesh->isChecked()) {
589       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
590
591       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
592         // get IDs from mesh
593         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
594         if (!aSMDSMesh)
595           return;
596
597         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
598           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
599           if (e) {
600             myElementsId += QString(" %1").arg(i);
601             aNbUnits++;
602           }
603         }
604       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
605         // get submesh
606         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
607
608         // get IDs from submesh
609         SMESH::long_array_var anElementsIds = new SMESH::long_array;
610         anElementsIds = aSubMesh->GetElementsId();
611         for (int i = 0; i < anElementsIds->length(); i++) {
612           myElementsId += QString(" %1").arg(anElementsIds[i]);
613         }
614         aNbUnits = anElementsIds->length();
615       } else { // GROUP
616         // get smesh group
617         SMESH::SMESH_GroupBase_var aGroup =
618           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
619         if (aGroup->_is_nil())
620           return;
621
622         // get IDs from smesh group
623         SMESH::long_array_var anElementsIds = new SMESH::long_array;
624         anElementsIds = aGroup->GetListOfID();
625         for (int i = 0; i < anElementsIds->length(); i++) {
626           myElementsId += QString(" %1").arg(anElementsIds[i]);
627         }
628         aNbUnits = anElementsIds->length();
629       }
630     } else {
631       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
632       myElementsId = aString;
633     }
634
635     if (aNbUnits < 1)
636       return;
637
638     myNbOkElements = true;
639   } else {
640     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
641     if (aNbUnits != 1)
642       return;
643
644     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
645     if (!aMesh)
646       return;
647
648     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
649     if (!n)
650       return;
651
652     double x = n->X();
653     double y = n->Y();
654     double z = n->Z();
655
656     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
657       SpinBox_X->SetValue(x);
658       SpinBox_Y->SetValue(y);
659       SpinBox_Z->SetValue(z);
660     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
661       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
662       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
663       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
664     }
665   }
666
667   myBusy = true;
668   if (myEditCurrentArgument == (QWidget*)LineEditElements)
669     LineEditElements->setText(aString);
670   myBusy = false;
671
672   // OK
673   if (myNbOkElements && IsAxisOk()) {
674     buttonOk->setEnabled(true);
675     buttonApply->setEnabled(true);
676   }
677 }
678
679 //=================================================================================
680 // function : SetEditCurrentArgument()
681 // purpose  :
682 //=================================================================================
683 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
684 {
685   QPushButton* send = (QPushButton*)sender();
686
687   disconnect(mySelectionMgr, 0, this, 0);
688   mySelectionMgr->clearSelected();
689   mySelectionMgr->clearFilters();
690
691   switch (myConstructorId) {
692   case 0: /* default constructor */
693     {
694       SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
695       if (send == SelectElementsButton) {
696         myEditCurrentArgument = (QWidget*)LineEditElements;
697         SMESH::SetPointRepresentation(false);
698         if (CheckBoxMesh->isChecked()) {
699           if ( aViewWindow )
700             aViewWindow->SetSelectionMode(ActorSelection);
701           mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
702         } else {
703           if ( aViewWindow )
704             aViewWindow->SetSelectionMode( CellSelection );
705         }
706       } else if (send == SelectPointButton) {
707         myEditCurrentArgument = (QWidget*)SpinBox_X;
708         SMESH::SetPointRepresentation(true);
709         if ( aViewWindow )
710           aViewWindow->SetSelectionMode( NodeSelection );
711       } else if (send == SelectVectorButton) {
712         myEditCurrentArgument = (QWidget*)SpinBox_DX;
713         SMESH::SetPointRepresentation(true);
714         if ( aViewWindow )
715           aViewWindow->SetSelectionMode( NodeSelection );
716       }
717       break;
718     }
719   }
720
721   myEditCurrentArgument->setFocus();
722   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
723   SelectionIntoArgument();
724 }
725
726 //=================================================================================
727 // function : DeactivateActiveDialog()
728 // purpose  :
729 //=================================================================================
730 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
731 {
732   if (GroupConstructors->isEnabled()) {
733     GroupConstructors->setEnabled(false);
734     GroupArguments->setEnabled(false);
735     GroupButtons->setEnabled(false);
736     mySMESHGUI->ResetState();
737     mySMESHGUI->SetActiveDialogBox(0);
738   }
739 }
740
741 //=================================================================================
742 // function : ActivateThisDialog()
743 // purpose  :
744 //=================================================================================
745 void SMESHGUI_RotationDlg::ActivateThisDialog()
746 {
747   /* Emit a signal to deactivate the active dialog */
748   mySMESHGUI->EmitSignalDeactivateDialog();
749   GroupConstructors->setEnabled(true);
750   GroupArguments->setEnabled(true);
751   GroupButtons->setEnabled(true);
752
753   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
754
755   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
756     aViewWindow->SetSelectionMode( CellSelection );
757   SelectionIntoArgument();
758 }
759
760 //=================================================================================
761 // function : enterEvent()
762 // purpose  :
763 //=================================================================================
764 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
765 {
766   if (!GroupConstructors->isEnabled())
767     ActivateThisDialog();
768 }
769
770 //=================================================================================
771 // function : closeEvent()
772 // purpose  :
773 //=================================================================================
774 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
775 {
776   /* same than click on cancel button */
777   this->ClickOnCancel();
778 }
779
780 //=================================================================================
781 // function : hideEvent()
782 // purpose  : caused by ESC key
783 //=================================================================================
784 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
785 {
786   if (!isMinimized())
787     ClickOnCancel();
788 }
789
790 //=================================================================================
791 // function : onSelectMesh()
792 // purpose  :
793 //=================================================================================
794 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
795 {
796   if (toSelectMesh)
797     TextLabelElements->setText(tr("SMESH_NAME"));
798   else
799     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
800
801   if (myEditCurrentArgument != LineEditElements) {
802     LineEditElements->clear();
803     return;
804   }
805
806   mySelectionMgr->clearFilters();
807   SMESH::SetPointRepresentation(false);
808
809   if (toSelectMesh) {
810     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
811       aViewWindow->SetSelectionMode(ActorSelection);
812     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
813     LineEditElements->setReadOnly(true);
814   } else {
815     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
816       aViewWindow->SetSelectionMode( CellSelection );
817     LineEditElements->setReadOnly(false);
818     onTextChange(LineEditElements->text());
819   }
820
821   SelectionIntoArgument();
822 }
823
824 //=================================================================================
825 // function : IsAxisOk()
826 // purpose  :
827 //=================================================================================
828 bool SMESHGUI_RotationDlg::IsAxisOk()
829 {
830   return (SpinBox_DX->GetValue() != 0 ||
831           SpinBox_DY->GetValue() != 0 ||
832           SpinBox_DZ->GetValue() != 0);
833 }
834
835 //=================================================================================
836 // function : onVectorChanged()
837 // purpose  :
838 //=================================================================================
839 void SMESHGUI_RotationDlg::onVectorChanged()
840 {
841   if (IsAxisOk()) {
842     buttonOk->setEnabled(true);
843     buttonApply->setEnabled(true);
844   } else {
845     buttonOk->setEnabled(false);
846     buttonApply->setEnabled(false);
847   }
848 }
849
850 //=================================================================================
851 // function : keyPressEvent()
852 // purpose  :
853 //=================================================================================
854 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
855 {
856   QDialog::keyPressEvent( e );
857   if ( e->isAccepted() )
858     return;
859
860   if ( e->key() == Key_F1 )
861     {
862       e->accept();
863       ClickOnHelp();
864     }
865 }