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