Salome HOME
Join modifications from V3_2_0_maintainance (V3_2_6pre4 - T32x_16Aug2007_16h00m)
[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   SMESHGUI_RotationDlgLayout->addWidget(GroupArguments, 1, 0);
287
288   /* Initialisations */
289   SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
290   SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
291   SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
292   SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
293   SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
294   SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, 3);
295
296   SpinBox_Angle->RangeStepAndValidator(-360.0, +360.0, 5.0, 3);
297
298   GroupArguments->show();
299   myConstructorId = 0;
300   RadioButton1->setChecked(TRUE);
301
302   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
303
304   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
305
306   // Costruction of the logical filter
307   SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
308   SMESH_TypeFilter* aSmeshGroupFilter    = new SMESH_TypeFilter (GROUP);
309
310   QPtrList<SUIT_SelectionFilter> aListOfFilters;
311   if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
312   if (aSmeshGroupFilter)    aListOfFilters.append(aSmeshGroupFilter);
313
314   myMeshOrSubMeshOrGroupFilter =
315     new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
316
317   myHelpFileName = "/files/rotation.htm";
318
319   Init();
320
321   /* signals and slots connections */
322   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
323   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
324   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
325   connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
326   connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
327
328   connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
329   connect(SelectPointButton, SIGNAL (clicked()),    this, SLOT(SetEditCurrentArgument()));
330   connect(SelectVectorButton, SIGNAL (clicked()),   this, SLOT(SetEditCurrentArgument()));
331
332   connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
333   connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
334   connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
335
336   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
337   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()),   this, SLOT(SelectionIntoArgument()));
338   /* to close dialog if study change */
339   connect(mySMESHGUI,       SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
340   connect(LineEditElements, SIGNAL(textChanged(const QString&)),    SLOT(onTextChange(const QString&)));
341   connect(CheckBoxMesh,     SIGNAL(toggled(bool)),                  SLOT(onSelectMesh(bool)));
342
343   this->show(); /* displays Dialog */
344
345   ConstructorsClicked(0);
346   resize(0,0); // ??
347 }
348
349 //=================================================================================
350 // function : ~SMESHGUI_RotationDlg()
351 // purpose  : Destroys the object and frees any allocated resources
352 //=================================================================================
353 SMESHGUI_RotationDlg::~SMESHGUI_RotationDlg()
354 {
355   // no need to delete child widgets, Qt does it all for us
356 }
357
358 //=================================================================================
359 // function : Init()
360 // purpose  :
361 //=================================================================================
362 void SMESHGUI_RotationDlg::Init (bool ResetControls)
363 {
364   myBusy = false;
365
366   myEditCurrentArgument = (QWidget*)LineEditElements;
367   LineEditElements->setFocus();
368   myElementsId = "";
369   myNbOkElements = 0;
370
371   buttonOk->setEnabled(false);
372   buttonApply->setEnabled(false);
373
374   myActor = 0;
375   myMesh = SMESH::SMESH_Mesh::_nil();
376
377   if (ResetControls) {
378     SpinBox_X->SetValue(0.0);
379     SpinBox_Y->SetValue(0.0);
380     SpinBox_Z->SetValue(0.0);
381     SpinBox_DX->SetValue(0.0);
382     SpinBox_DY->SetValue(0.0);
383     SpinBox_DZ->SetValue(0.0);
384
385     SpinBox_Angle->SetValue(45);
386
387     CheckBoxCopy->setChecked(false);
388     CheckBoxMesh->setChecked(false);
389   }
390
391   onSelectMesh(CheckBoxMesh->isChecked());
392 }
393
394 //=================================================================================
395 // function : ConstructorsClicked()
396 // purpose  : Radio button management
397 //=================================================================================
398 void SMESHGUI_RotationDlg::ConstructorsClicked (int constructorId)
399 {
400 }
401
402 //=================================================================================
403 // function : ClickOnApply()
404 // purpose  :
405 //=================================================================================
406 void SMESHGUI_RotationDlg::ClickOnApply()
407 {
408   if (mySMESHGUI->isActiveStudyLocked())
409     return;
410
411   if (myNbOkElements && IsAxisOk()) {
412     QStringList aListElementsId = QStringList::split(" ", myElementsId, false);
413
414     SMESH::long_array_var anElementsId = new SMESH::long_array;
415
416     anElementsId->length(aListElementsId.count());
417     for (int i = 0; i < aListElementsId.count(); i++)
418       anElementsId[i] = aListElementsId[i].toInt();
419
420     SMESH::AxisStruct anAxis;
421
422     anAxis.x =  SpinBox_X->GetValue();
423     anAxis.y =  SpinBox_Y->GetValue();
424     anAxis.z =  SpinBox_Z->GetValue();;
425     anAxis.vx = SpinBox_DX->GetValue();
426     anAxis.vy = SpinBox_DY->GetValue();
427     anAxis.vz = SpinBox_DZ->GetValue();
428
429     double anAngle = (SpinBox_Angle->GetValue())*PI/180;
430     bool toCreateCopy = CheckBoxCopy->isChecked();
431
432     try {
433       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
434       QApplication::setOverrideCursor(Qt::waitCursor);
435       aMeshEditor->Rotate(anElementsId.inout(), anAxis, anAngle, toCreateCopy);
436       QApplication::restoreOverrideCursor();
437     } catch (...) {
438     }
439
440     SMESH::UpdateView();
441     Init(false);
442     SelectionIntoArgument();
443   }
444 }
445
446 //=================================================================================
447 // function : ClickOnOk()
448 // purpose  :
449 //=================================================================================
450 void SMESHGUI_RotationDlg::ClickOnOk()
451 {
452   ClickOnApply();
453   ClickOnCancel();
454 }
455
456 //=================================================================================
457 // function : ClickOnCancel()
458 // purpose  :
459 //=================================================================================
460 void SMESHGUI_RotationDlg::ClickOnCancel()
461 {
462   disconnect(mySelectionMgr, 0, this, 0);
463   mySelectionMgr->clearFilters();
464   //mySelectionMgr->clearSelected();
465   SMESH::SetPointRepresentation(false);
466   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
467     aViewWindow->SetSelectionMode(ActorSelection);
468   mySMESHGUI->ResetState();
469   reject();
470 }
471
472 //=================================================================================
473 // function : ClickOnHelp()
474 // purpose  :
475 //=================================================================================
476 void SMESHGUI_RotationDlg::ClickOnHelp()
477 {
478   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
479   if (app) 
480     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
481   else {
482                 QString platform;
483 #ifdef WIN32
484                 platform = "winapplication";
485 #else
486                 platform = "application";
487 #endif
488     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
489                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
490                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
491                            QObject::tr("BUT_OK"));
492   }
493 }
494
495 //=======================================================================
496 // function : onTextChange()
497 // purpose  :
498 //=======================================================================
499 void SMESHGUI_RotationDlg::onTextChange (const QString& theNewText)
500 {
501   QLineEdit* send = (QLineEdit*)sender();
502
503   if (myBusy) return;
504   myBusy = true;
505
506   if (send == LineEditElements)
507     myNbOkElements = 0;
508
509   buttonOk->setEnabled(false);
510   buttonApply->setEnabled(false);
511
512   // hilight entered elements
513   SMDS_Mesh* aMesh = 0;
514   if (myActor)
515     aMesh = myActor->GetObject()->GetMesh();
516
517   if (aMesh) {
518     if (send == LineEditElements) {
519       Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
520       
521       TColStd_MapOfInteger newIndices;
522       
523       QStringList aListId = QStringList::split(" ", theNewText, false);
524       for (int i = 0; i < aListId.count(); i++) {
525         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
526         if (e)
527           newIndices.Add(e->GetID());
528         myNbOkElements++;
529       }
530
531       mySelector->AddOrRemoveIndex( anIO, newIndices, false );
532       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
533         aViewWindow->highlight( anIO, true, true );
534       
535       myElementsId = theNewText;
536     }
537   }
538
539   if (myNbOkElements && IsAxisOk()) {
540     buttonOk->setEnabled(true);
541     buttonApply->setEnabled(true);
542   }
543
544   myBusy = false;
545 }
546
547 //=================================================================================
548 // function : SelectionIntoArgument()
549 // purpose  : Called when selection as changed or other case
550 //=================================================================================
551 void SMESHGUI_RotationDlg::SelectionIntoArgument()
552 {
553   if (myBusy) return;
554
555   // clear
556   myActor = 0;
557   QString aString = "";
558
559   myBusy = true;
560   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
561     LineEditElements->setText(aString);
562     myNbOkElements = 0;
563     buttonOk->setEnabled(false);
564     buttonApply->setEnabled(false);
565   }
566   myBusy = false;
567
568   if (!GroupButtons->isEnabled()) // inactive
569     return;
570
571   // get selected mesh
572   SALOME_ListIO aList;
573   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
574
575   int nbSel = aList.Extent();
576   if (nbSel != 1)
577     return;
578
579   Handle(SALOME_InteractiveObject) IO = aList.First();
580   myMesh = SMESH::GetMeshByIO(IO);
581   if (myMesh->_is_nil())
582     return;
583
584   myActor = SMESH::FindActorByObject(myMesh);
585   if (!myActor)
586     myActor = SMESH::FindActorByEntry(IO->getEntry());
587   if (!myActor)
588     return;
589
590   int aNbUnits = 0;
591
592   if (myEditCurrentArgument == (QWidget*)LineEditElements) {
593     myElementsId = "";
594
595     if (CheckBoxMesh->isChecked()) {
596       SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
597
598       if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
599         // get IDs from mesh
600         SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
601         if (!aSMDSMesh)
602           return;
603
604         for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
605           const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
606           if (e) {
607             myElementsId += QString(" %1").arg(i);
608             aNbUnits++;
609           }
610         }
611       } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
612         // get submesh
613         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
614
615         // get IDs from submesh
616         SMESH::long_array_var anElementsIds = new SMESH::long_array;
617         anElementsIds = aSubMesh->GetElementsId();
618         for (int i = 0; i < anElementsIds->length(); i++) {
619           myElementsId += QString(" %1").arg(anElementsIds[i]);
620         }
621         aNbUnits = anElementsIds->length();
622       } else { // GROUP
623         // get smesh group
624         SMESH::SMESH_GroupBase_var aGroup =
625           SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
626         if (aGroup->_is_nil())
627           return;
628
629         // get IDs from smesh group
630         SMESH::long_array_var anElementsIds = new SMESH::long_array;
631         anElementsIds = aGroup->GetListOfID();
632         for (int i = 0; i < anElementsIds->length(); i++) {
633           myElementsId += QString(" %1").arg(anElementsIds[i]);
634         }
635         aNbUnits = anElementsIds->length();
636       }
637     } else {
638       aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
639       myElementsId = aString;
640     }
641
642     if (aNbUnits < 1)
643       return;
644
645     myNbOkElements = true;
646   } else {
647     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
648     if (aNbUnits != 1)
649       return;
650
651     SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
652     if (!aMesh)
653       return;
654
655     const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
656     if (!n)
657       return;
658
659     double x = n->X();
660     double y = n->Y();
661     double z = n->Z();
662
663     if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
664       SpinBox_X->SetValue(x);
665       SpinBox_Y->SetValue(y);
666       SpinBox_Z->SetValue(z);
667     } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
668       SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
669       SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
670       SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
671     }
672   }
673
674   myBusy = true;
675   if (myEditCurrentArgument == (QWidget*)LineEditElements)
676     LineEditElements->setText(aString);
677   myBusy = false;
678
679   // OK
680   if (myNbOkElements && IsAxisOk()) {
681     buttonOk->setEnabled(true);
682     buttonApply->setEnabled(true);
683   }
684 }
685
686 //=================================================================================
687 // function : SetEditCurrentArgument()
688 // purpose  :
689 //=================================================================================
690 void SMESHGUI_RotationDlg::SetEditCurrentArgument()
691 {
692   QPushButton* send = (QPushButton*)sender();
693
694   disconnect(mySelectionMgr, 0, this, 0);
695   mySelectionMgr->clearSelected();
696   mySelectionMgr->clearFilters();
697
698   switch (myConstructorId) {
699   case 0: /* default constructor */
700     {
701       SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
702       if (send == SelectElementsButton) {
703         myEditCurrentArgument = (QWidget*)LineEditElements;
704         SMESH::SetPointRepresentation(false);
705         if (CheckBoxMesh->isChecked()) {
706           if ( aViewWindow )
707             aViewWindow->SetSelectionMode(ActorSelection);
708           mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
709         } else {
710           if ( aViewWindow )
711             aViewWindow->SetSelectionMode( CellSelection );
712         }
713       } else if (send == SelectPointButton) {
714         myEditCurrentArgument = (QWidget*)SpinBox_X;
715         SMESH::SetPointRepresentation(true);
716         if ( aViewWindow )
717           aViewWindow->SetSelectionMode( NodeSelection );
718       } else if (send == SelectVectorButton) {
719         myEditCurrentArgument = (QWidget*)SpinBox_DX;
720         SMESH::SetPointRepresentation(true);
721         if ( aViewWindow )
722           aViewWindow->SetSelectionMode( NodeSelection );
723       }
724       break;
725     }
726   }
727
728   myEditCurrentArgument->setFocus();
729   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
730   SelectionIntoArgument();
731 }
732
733 //=================================================================================
734 // function : DeactivateActiveDialog()
735 // purpose  :
736 //=================================================================================
737 void SMESHGUI_RotationDlg::DeactivateActiveDialog()
738 {
739   if (GroupConstructors->isEnabled()) {
740     GroupConstructors->setEnabled(false);
741     GroupArguments->setEnabled(false);
742     GroupButtons->setEnabled(false);
743     mySMESHGUI->ResetState();
744     mySMESHGUI->SetActiveDialogBox(0);
745   }
746 }
747
748 //=================================================================================
749 // function : ActivateThisDialog()
750 // purpose  :
751 //=================================================================================
752 void SMESHGUI_RotationDlg::ActivateThisDialog()
753 {
754   /* Emit a signal to deactivate the active dialog */
755   mySMESHGUI->EmitSignalDeactivateDialog();
756   GroupConstructors->setEnabled(true);
757   GroupArguments->setEnabled(true);
758   GroupButtons->setEnabled(true);
759
760   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
761
762   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
763     aViewWindow->SetSelectionMode( CellSelection );
764   SelectionIntoArgument();
765 }
766
767 //=================================================================================
768 // function : enterEvent()
769 // purpose  :
770 //=================================================================================
771 void SMESHGUI_RotationDlg::enterEvent (QEvent*)
772 {
773   if (!GroupConstructors->isEnabled())
774     ActivateThisDialog();
775 }
776
777 //=================================================================================
778 // function : closeEvent()
779 // purpose  :
780 //=================================================================================
781 void SMESHGUI_RotationDlg::closeEvent (QCloseEvent*)
782 {
783   /* same than click on cancel button */
784   this->ClickOnCancel();
785 }
786
787 //=================================================================================
788 // function : hideEvent()
789 // purpose  : caused by ESC key
790 //=================================================================================
791 void SMESHGUI_RotationDlg::hideEvent (QHideEvent*)
792 {
793   if (!isMinimized())
794     ClickOnCancel();
795 }
796
797 //=================================================================================
798 // function : onSelectMesh()
799 // purpose  :
800 //=================================================================================
801 void SMESHGUI_RotationDlg::onSelectMesh (bool toSelectMesh)
802 {
803   if (toSelectMesh)
804     TextLabelElements->setText(tr("SMESH_NAME"));
805   else
806     TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
807
808   if (myEditCurrentArgument != LineEditElements) {
809     LineEditElements->clear();
810     return;
811   }
812
813   mySelectionMgr->clearFilters();
814   SMESH::SetPointRepresentation(false);
815
816   if (toSelectMesh) {
817     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
818       aViewWindow->SetSelectionMode(ActorSelection);
819     mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
820     LineEditElements->setReadOnly(true);
821   } else {
822     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
823       aViewWindow->SetSelectionMode( CellSelection );
824     LineEditElements->setReadOnly(false);
825     onTextChange(LineEditElements->text());
826   }
827
828   SelectionIntoArgument();
829 }
830
831 //=================================================================================
832 // function : IsAxisOk()
833 // purpose  :
834 //=================================================================================
835 bool SMESHGUI_RotationDlg::IsAxisOk()
836 {
837   return (SpinBox_DX->GetValue() != 0 ||
838           SpinBox_DY->GetValue() != 0 ||
839           SpinBox_DZ->GetValue() != 0);
840 }
841
842 //=================================================================================
843 // function : onVectorChanged()
844 // purpose  :
845 //=================================================================================
846 void SMESHGUI_RotationDlg::onVectorChanged()
847 {
848   if (IsAxisOk()) {
849     buttonOk->setEnabled(true);
850     buttonApply->setEnabled(true);
851   } else {
852     buttonOk->setEnabled(false);
853     buttonApply->setEnabled(false);
854   }
855 }
856
857 //=================================================================================
858 // function : keyPressEvent()
859 // purpose  :
860 //=================================================================================
861 void SMESHGUI_RotationDlg::keyPressEvent( QKeyEvent* e )
862 {
863   QDialog::keyPressEvent( e );
864   if ( e->isAccepted() )
865     return;
866
867   if ( e->key() == Key_F1 )
868     {
869       e->accept();
870       ClickOnHelp();
871     }
872 }