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