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