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