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