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