Salome HOME
PAL8769: Limitation to give values in Spin boxes. Now coordinates and displacements...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_RevolutionDlg.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_RevolutionDlg.cxx
25 //  Author : Michael ZORIN
26 //  Module : SMESH
27 //  $Header: 
28
29 #include "SMESHGUI_RevolutionDlg.h"
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_SpinBox.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_IdValidator.h"
36 #include "SMESH_Actor.h"
37 #include "SMESH_TypeFilter.hxx"
38 #include "SMDS_Mesh.hxx"
39
40 #include "QAD_Application.h"
41 #include "QAD_Desktop.h"
42 #include "QAD_MessageBox.h"
43 #include "utilities.h"
44
45 // QT Includes
46 #include <qapplication.h>
47 #include <qbuttongroup.h>
48 #include <qgroupbox.h>
49 #include <qlabel.h>
50 #include <qlineedit.h>
51 #include <qpushbutton.h>
52 #include <qradiobutton.h>
53 #include <qcheckbox.h>
54 #include <qlayout.h>
55 #include <qspinbox.h> 
56 #include <qvalidator.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_RevolutionDlg()
67 // purpose  : 
68 //=================================================================================
69 SMESHGUI_RevolutionDlg::SMESHGUI_RevolutionDlg( 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_EDGE")));
75   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_TRIANGLE")));
76   QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
77
78   if ( !name )
79     setName( "SMESHGUI_RevolutionDlg" );
80   resize( 303, 185 ); 
81   setCaption( tr( "REVOLUTION_AROUND_AXIS" ) );
82   setSizeGripEnabled( TRUE );
83   SMESHGUI_RevolutionDlgLayout = new QGridLayout( this ); 
84   SMESHGUI_RevolutionDlgLayout->setSpacing( 6 );
85   SMESHGUI_RevolutionDlgLayout->setMargin( 11 );
86
87   /***************************************************************/
88   GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
89   GroupConstructors->setTitle( tr( "SMESH_REVOLUTION"  ) );
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   GroupConstructorsLayout->addWidget( RadioButton1, 0, 0 );
102   RadioButton2= new QRadioButton( GroupConstructors, "RadioButton2" );
103   RadioButton2->setText( tr( ""  ) );
104   RadioButton2->setPixmap( image1 );
105   GroupConstructorsLayout->addWidget( RadioButton2, 0, 2 );
106   SMESHGUI_RevolutionDlgLayout->addWidget( GroupConstructors, 0, 0 );
107   
108   /***************************************************************/
109   GroupButtons = new QGroupBox( this, "GroupButtons" );
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_RevolutionDlgLayout->addWidget( GroupButtons, 2, 0 );
135
136   /***************************************************************/
137   GroupArguments = new QGroupBox( this, "GroupArguments" );
138   GroupArguments->setTitle( tr( "REVOLUTION_1D"  ) );
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( image2 );
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, 3 );
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( image2 );
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( image2 );
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, 3 );
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 nb. steps defining
248   TextLabelNbSteps = new QLabel( GroupArguments, "TextLabelNbSteps" );
249   TextLabelNbSteps->setText( tr( "SMESH_NUMBEROFSTEPS"  ) );
250   GroupArgumentsLayout->addMultiCellWidget( TextLabelNbSteps, 4, 4, 0, 1 );
251
252   SpinBox_NbSteps = new QSpinBox(GroupArguments, "SpinBox_NbSteps");
253   GroupArgumentsLayout->addWidget( SpinBox_NbSteps, 4, 2 );
254   
255   // Controls for tolerance defining
256   TextLabelTolerance = new QLabel( GroupArguments, "TextLabelTolerance" );
257   TextLabelTolerance->setText( tr( "SMESH_TOLERANCE" ) );
258   GroupArgumentsLayout->addMultiCellWidget( TextLabelTolerance, 5, 5, 0, 1 );
259
260   SpinBox_Tolerance = new SMESHGUI_SpinBox(GroupArguments, "SpinBox_Tolerance");
261   GroupArgumentsLayout->addWidget( SpinBox_Tolerance, 5, 2 );
262
263   SMESHGUI_RevolutionDlgLayout->addWidget( GroupArguments, 1, 0 );
264   
265   /* Initialisations */
266   SpinBox_X->RangeStepAndValidator ( COORD_MIN, COORD_MAX, 10.0, 3 );
267   SpinBox_Y->RangeStepAndValidator ( COORD_MIN, COORD_MAX, 10.0, 3 );
268   SpinBox_Z->RangeStepAndValidator ( COORD_MIN, COORD_MAX, 10.0, 3 );
269   SpinBox_DX->RangeStepAndValidator( COORD_MIN, COORD_MAX, 10.0, 3 );
270   SpinBox_DY->RangeStepAndValidator( COORD_MIN, COORD_MAX, 10.0, 3 );
271   SpinBox_DZ->RangeStepAndValidator( COORD_MIN, COORD_MAX, 10.0, 3 );
272
273   SpinBox_Angle->RangeStepAndValidator( COORD_MIN, COORD_MAX, 5.0, 3 );
274   //??SpinBox_Angle->RangeStepAndValidator( -360., +360., 5.0, 3 );
275   
276   QIntValidator* anIntValidator = new QIntValidator(SpinBox_NbSteps);
277   SpinBox_NbSteps->setValidator(anIntValidator);
278   SpinBox_NbSteps->setRange( 1, 999999 );
279   
280   SpinBox_Tolerance->RangeStepAndValidator( 0.0, COORD_MAX, 0.1, 6 );
281  
282   GroupArguments->show();
283   RadioButton1->setChecked( TRUE );
284   mySelection = Sel;  
285
286   mySMESHGUI  = SMESHGUI::GetSMESHGUI() ;
287   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
288   
289   // Costruction of the logical filter
290   SMESH_ListOfFilter aListOfFilters;
291   Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
292   if ( !aMeshOrSubMeshFilter.IsNull() )
293     aListOfFilters.Append( aMeshOrSubMeshFilter );
294   Handle(SMESH_TypeFilter) aSmeshGroupFilter = new SMESH_TypeFilter( GROUP );
295   if ( !aSmeshGroupFilter.IsNull() )
296     aListOfFilters.Append( aSmeshGroupFilter );
297   
298   myMeshOrSubMeshOrGroupFilter = new SMESH_LogicalFilter( aListOfFilters, SMESH_LogicalFilter::LO_OR );
299   
300   Init();
301   /* signals and slots connections */
302   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
303   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
304   connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
305   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
306   
307   connect( SelectElementsButton, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
308   connect( SelectPointButton, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
309   connect( SelectVectorButton, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
310
311   connect( SpinBox_DX, SIGNAL( valueChanged( double )), this, SLOT(onVectorChanged() ) );
312   connect( SpinBox_DY, SIGNAL( valueChanged( double )), this, SLOT(onVectorChanged() ) );
313   connect( SpinBox_DZ, SIGNAL( valueChanged( double )), this, SLOT(onVectorChanged() ) );
314
315   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
316   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
317   /* to close dialog if study change */
318   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
319   connect( LineEditElements, SIGNAL( textChanged( const QString& )),
320            SLOT( onTextChange( const QString& )));
321   connect( CheckBoxMesh, SIGNAL( toggled( bool )),
322            SLOT( onSelectMesh( bool )));
323   
324   /* Move widget on the botton right corner of main widget */
325   int x, y ;
326   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
327   this->move( x, y ) ;
328   this->show() ; /* displays Dialog */
329
330   ConstructorsClicked(0);
331 }
332
333 //=================================================================================
334 // function : ~SMESHGUI_RevolutionDlg()
335 // purpose  : Destroys the object and frees any allocated resources
336 //=================================================================================
337 SMESHGUI_RevolutionDlg::~SMESHGUI_RevolutionDlg()
338 {
339   // no need to delete child widgets, Qt does it all for us
340 }
341
342
343 //=================================================================================
344 // function : Init()
345 // purpose  :
346 //=================================================================================
347 void SMESHGUI_RevolutionDlg::Init( bool ResetControls )
348 {
349   myBusy = false;
350   
351   myEditCurrentArgument = 0;
352   LineEditElements->clear();
353   myElementsId = "";
354   myNbOkElements = 0 ;
355   
356   myActor     = 0;
357   myMesh = SMESH::SMESH_Mesh::_nil();
358   
359   if( ResetControls )
360     {
361       SpinBox_X->SetValue(0.0);
362       SpinBox_Y->SetValue(0.0);
363       SpinBox_Z->SetValue(0.0);
364       SpinBox_DX->SetValue(0.0);
365       SpinBox_DY->SetValue(0.0);
366       SpinBox_DZ->SetValue(0.0);
367       
368       SpinBox_Angle->SetValue(45);
369       SpinBox_NbSteps->setValue(1);
370       SpinBox_Tolerance->SetValue(1e-05);
371       
372       CheckBoxMesh->setChecked(false);
373       onSelectMesh( false );
374     }
375 }
376
377
378 //=================================================================================
379 // function : ConstructorsClicked()
380 // purpose  : Radio button management
381 //=================================================================================
382 void SMESHGUI_RevolutionDlg::ConstructorsClicked(int constructorId)
383 {
384   disconnect(mySelection, 0, this, 0);
385   
386   Selection_Mode aSelMode = ActorSelection;
387
388   switch(constructorId)
389     { 
390     case 0 :
391       {
392         GroupArguments->setTitle( tr( "REVOLUTION_1D" ) );
393         aSelMode = EdgeSelection;
394         break;
395       }
396     case 1 :
397       { 
398         GroupArguments->setTitle( tr( "REVOLUTION_2D" ) );
399         aSelMode = FaceSelection;
400         break;
401       }
402     }
403   
404   if (myEditCurrentArgument != (QWidget*)LineEditElements)
405     SMESH::SetPointRepresentation(false);
406     
407   if (!CheckBoxMesh->isChecked())
408     QAD_Application::getDesktop()->SetSelectionMode( aSelMode, true );
409   
410   myEditCurrentArgument = (QWidget*)LineEditElements;
411   LineEditElements->setFocus();
412   
413   if (CheckBoxMesh->isChecked())
414     onSelectMesh(true);
415   
416   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
417 }
418
419
420 //=================================================================================
421 // function : ClickOnApply()
422 // purpose  :
423 //=================================================================================
424 void SMESHGUI_RevolutionDlg::ClickOnApply()
425 {
426   if (mySMESHGUI->ActiveStudyLocked())
427     return;
428   
429   if ( myNbOkElements  && IsAxisOk())
430     {
431       QStringList aListElementsId = QStringList::split( " ", myElementsId, false);
432       
433       SMESH::long_array_var anElementsId = new SMESH::long_array;
434       
435       anElementsId->length( aListElementsId.count() );
436       for ( int i = 0; i < aListElementsId.count(); i++ )
437         anElementsId[i] = aListElementsId[i].toInt();
438       
439       SMESH::AxisStruct anAxis;
440       
441       anAxis.x =  SpinBox_X->GetValue();
442       anAxis.y =  SpinBox_Y->GetValue();
443       anAxis.z =  SpinBox_Z->GetValue();;
444       anAxis.vx = SpinBox_DX->GetValue();
445       anAxis.vy = SpinBox_DY->GetValue();
446       anAxis.vz = SpinBox_DZ->GetValue();
447
448       double anAngle = (SpinBox_Angle->GetValue())*PI/180; 
449       long aNbSteps = (long)SpinBox_NbSteps->value();
450       double aTolerance = SpinBox_Tolerance->GetValue();
451
452       try
453         {
454           SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
455           QApplication::setOverrideCursor(Qt::waitCursor);
456           aMeshEditor->RotationSweep(anElementsId.inout(), anAxis, anAngle, aNbSteps, aTolerance);
457           QApplication::restoreOverrideCursor();
458         }
459       catch( ... )
460         {
461         }
462       
463       mySelection->ClearIObjects();
464       SMESH::UpdateView();
465       Init( false);
466       ConstructorsClicked( GetConstructorId() );
467     }
468 }
469
470 //=================================================================================
471 // function : ClickOnOk()
472 // purpose  :
473 //=================================================================================
474 void SMESHGUI_RevolutionDlg::ClickOnOk()
475 {
476   ClickOnApply() ;
477   ClickOnCancel() ;
478 }
479
480         
481 //=================================================================================
482 // function : ClickOnCancel()
483 // purpose  :
484 //=================================================================================
485 void SMESHGUI_RevolutionDlg::ClickOnCancel()
486 {
487   mySelection->ClearFilters();
488   mySelection->ClearIObjects();
489   SMESH::SetPointRepresentation(false);
490   QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
491   disconnect( mySelection, 0, this, 0 );
492   mySMESHGUI->ResetState() ;
493   reject() ;
494 }
495
496 //=======================================================================
497 //function : onTextChange
498 //purpose  : 
499 //=======================================================================
500
501 void SMESHGUI_RevolutionDlg::onTextChange(const QString& theNewText)
502 {
503   QLineEdit* send = (QLineEdit*)sender();
504
505   if ( myBusy ) return;
506   myBusy = true;
507   
508   if (send == LineEditElements)
509     myNbOkElements = 0;
510   
511   buttonOk->setEnabled( false );
512   buttonApply->setEnabled( false );
513   
514   // hilight entered elements
515   SMDS_Mesh* aMesh = 0;
516   if ( myActor )
517     aMesh = myActor->GetObject()->GetMesh();
518   
519   if ( aMesh ) {
520     mySelection->ClearIObjects();
521     mySelection->AddIObject( myActor->getIO() );
522     
523     QStringList aListId = QStringList::split( " ", theNewText, false);
524     
525     if (send == LineEditElements) {
526       for ( int i = 0; i < aListId.count(); i++ ) {
527         const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
528         if ( e ) {
529           if ( !mySelection->IsIndexSelected( myActor->getIO(), e->GetID() ))
530             mySelection->AddOrRemoveIndex (myActor->getIO(), e->GetID(), true);
531           myNbOkElements++;
532         }
533       }
534       myElementsId = theNewText;
535     }
536   }
537   
538   if ( myNbOkElements &&  IsAxisOk() ) {
539     buttonOk->setEnabled( true );
540     buttonApply->setEnabled( true );
541   }
542   
543   myBusy = false;
544 }
545
546 //=================================================================================
547 // function : SelectionIntoArgument()
548 // purpose  : Called when selection as changed or other case
549 //=================================================================================
550 void SMESHGUI_RevolutionDlg::SelectionIntoArgument()
551 {
552   if ( myBusy ) return;
553   
554   // clear
555   myActor = 0;
556   QString aString = "";
557
558   myBusy = true;
559   if (myEditCurrentArgument == (QWidget*)LineEditElements)
560     {
561       LineEditElements->setText( aString );
562       myNbOkElements = 0;
563       buttonOk->setEnabled( false );
564       buttonApply->setEnabled( false );
565     }
566   myBusy = false;
567   
568   if ( !GroupButtons->isEnabled() ) // inactive
569     return;
570   
571   // get selected mesh
572   int nbSel = mySelection->IObjectCount();
573   if(nbSel != 1)
574     return;
575   
576   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
577   myMesh = SMESH::GetMeshByIO(IO);
578   if(myMesh->_is_nil())
579     return;
580   myActor = SMESH::FindActorByObject(myMesh);
581   if (!myActor)
582     return;
583   
584   int aNbUnits = 0;
585
586   if (myEditCurrentArgument == (QWidget*)LineEditElements)
587     {
588       myElementsId = "";
589       
590       if (CheckBoxMesh->isChecked())
591         {
592           SMESH::GetNameOfSelectedIObjects(mySelection, aString);
593         
594           int aConstructorId = GetConstructorId();
595
596           if(!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) //MESH
597             {
598               // get IDs from mesh
599               SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
600               if (!aSMDSMesh)
601                 return;
602               
603               if (aConstructorId == 0)
604                 {
605                   SMDS_EdgeIteratorPtr anIter = aSMDSMesh->edgesIterator();
606                   
607                   while ( anIter->more() )
608                     {
609                       const SMDS_MeshEdge * edge = anIter->next();
610                       if ( edge ) {
611                         myElementsId += QString(" %1").arg(edge->GetID());
612                         aNbUnits++;
613                       }
614                     }
615                 }
616               else if (aConstructorId == 1)
617                 {
618                   SMDS_FaceIteratorPtr anIter = aSMDSMesh->facesIterator();               
619                   while ( anIter->more() )
620                     {
621                       const SMDS_MeshFace * face = anIter->next();
622                       if ( face ) {
623                         myElementsId += QString(" %1").arg(face->GetID());
624                         aNbUnits++;
625                       }
626                     }
627                 }
628             }
629           else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) //SUBMESH
630             {
631               // get submesh
632               SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO) ;
633               
634               // get IDs from submesh
635               SMESH::long_array_var anElementsIds = new SMESH::long_array;
636               if (aConstructorId == 0)
637                 anElementsIds = aSubMesh->GetElementsByType(SMESH::EDGE);
638               else if (aConstructorId == 1)
639                 anElementsIds = aSubMesh->GetElementsByType(SMESH::FACE);
640               
641               for ( int i = 0; i < anElementsIds->length(); i++ )
642                 myElementsId += QString(" %1").arg(anElementsIds[i]);
643               aNbUnits = anElementsIds->length();
644             }
645           else // GROUP
646             {
647               // get smesh group
648               SMESH::SMESH_GroupBase_var aGroup =
649                 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
650               if (aGroup->_is_nil())
651                 return;
652               
653               if ( (aConstructorId == 0 && aGroup->GetType()!= SMESH::EDGE) ||
654                    (aConstructorId == 1 && aGroup->GetType()!= SMESH::FACE) )
655                 return;
656               
657               // get IDs from smesh group
658               SMESH::long_array_var anElementsIds = new SMESH::long_array;
659               anElementsIds = aGroup->GetListOfID();
660               for ( int i = 0; i < anElementsIds->length(); i++ )
661                 myElementsId += QString(" %1").arg(anElementsIds[i]);
662               aNbUnits = anElementsIds->length();
663             }
664         }
665       else
666         {
667           aNbUnits = SMESH::GetNameOfSelectedElements(mySelection, aString) ;
668           myElementsId = aString;
669         }
670       
671       if(aNbUnits < 1)
672         return ;
673       
674       myNbOkElements = true;
675     }
676   else 
677     {
678       aNbUnits = SMESH::GetNameOfSelectedNodes(mySelection, aString);
679       if(aNbUnits != 1)
680         return;
681       
682       SMDS_Mesh* aMesh =  myActor->GetObject()->GetMesh();
683       if (!aMesh)
684         return;
685
686       const SMDS_MeshNode * n = aMesh->FindNode( aString.toInt() );
687       if ( !n )
688         return;
689       
690       double x = n->X();
691       double y = n->Y();
692       double z = n->Z();
693
694       if (myEditCurrentArgument == (QWidget*)SpinBox_X)
695         {
696           SpinBox_X->SetValue(x);
697           SpinBox_Y->SetValue(y);
698           SpinBox_Z->SetValue(z);
699         }
700       else if (myEditCurrentArgument == (QWidget*)SpinBox_DX)
701         {
702           SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
703           SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
704           SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
705         }
706     }
707   
708   myBusy = true;
709   if (myEditCurrentArgument == (QWidget*)LineEditElements)
710     LineEditElements->setText( aString );
711   myBusy = false;
712   
713   // OK
714   if(myNbOkElements && IsAxisOk())
715     {
716       buttonOk->setEnabled( true );
717       buttonApply->setEnabled( true );
718     }
719 }
720
721
722 //=================================================================================
723 // function : SetEditCurrentArgument()
724 // purpose  :
725 //=================================================================================
726 void SMESHGUI_RevolutionDlg::SetEditCurrentArgument()
727 {
728   QPushButton* send = (QPushButton*)sender();
729   
730   disconnect( mySelection, 0, this, 0 );
731   mySelection->ClearIObjects();
732   mySelection->ClearFilters();
733   
734   if(send == SelectElementsButton) {
735     myEditCurrentArgument = (QWidget*)LineEditElements;
736     SMESH::SetPointRepresentation(false);
737     if (CheckBoxMesh->isChecked())
738       {
739         QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
740         mySelection->AddFilter(myMeshOrSubMeshOrGroupFilter);
741       }
742     else
743       {
744         int aConstructorId = GetConstructorId();
745         if (aConstructorId == 0)
746           QAD_Application::getDesktop()->SetSelectionMode( EdgeSelection, true );
747         else if (aConstructorId == 1)
748           QAD_Application::getDesktop()->SetSelectionMode( FaceSelection, true );
749       }
750   }
751   else if (send == SelectPointButton)
752     {
753       myEditCurrentArgument = (QWidget*)SpinBox_X;
754       SMESH::SetPointRepresentation(true);
755       QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
756     }
757   else if (send == SelectVectorButton)
758     {
759       myEditCurrentArgument = (QWidget*)SpinBox_DX;
760       SMESH::SetPointRepresentation(true);
761       QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
762     }
763   
764   myEditCurrentArgument->setFocus();
765   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
766   SelectionIntoArgument() ;
767 }
768
769 //=================================================================================
770 // function : DeactivateActiveDialog()
771 // purpose  :
772 //=================================================================================
773 void SMESHGUI_RevolutionDlg::DeactivateActiveDialog()
774 {
775   if ( GroupConstructors->isEnabled() ) {
776     GroupConstructors->setEnabled(false) ;
777     GroupArguments->setEnabled(false) ;
778     GroupButtons->setEnabled(false) ;
779     mySMESHGUI->ResetState() ;    
780     mySMESHGUI->SetActiveDialogBox(0) ;
781   }
782 }
783
784
785 //=================================================================================
786 // function : ActivateThisDialog()
787 // purpose  :
788 //=================================================================================
789 void SMESHGUI_RevolutionDlg::ActivateThisDialog()
790 {
791   /* Emit a signal to deactivate the active dialog */
792   mySMESHGUI->EmitSignalDeactivateDialog() ;   
793   GroupConstructors->setEnabled(true) ;
794   GroupArguments->setEnabled(true) ;
795   GroupButtons->setEnabled(true) ;
796   
797   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
798
799   ConstructorsClicked(GetConstructorId());
800   SelectionIntoArgument();
801 }
802
803
804 //=================================================================================
805 // function : enterEvent()
806 // purpose  :
807 //=================================================================================
808 void SMESHGUI_RevolutionDlg::enterEvent(QEvent* e)
809 {
810   if ( GroupConstructors->isEnabled() )
811     return ;  
812   ActivateThisDialog() ;
813 }
814
815
816 //=================================================================================
817 // function : closeEvent()
818 // purpose  :
819 //=================================================================================
820 void SMESHGUI_RevolutionDlg::closeEvent( QCloseEvent* e )
821 {
822   /* same than click on cancel button */
823   this->ClickOnCancel() ;
824   return ;
825 }
826
827
828 //=======================================================================
829 //function : hideEvent
830 //purpose  : caused by ESC key
831 //=======================================================================
832
833 void SMESHGUI_RevolutionDlg::hideEvent ( QHideEvent * e )
834 {
835   if ( !isMinimized() )
836     ClickOnCancel();
837 }
838
839
840 //=================================================================================
841 // function : GetConstructorId()
842 // purpose  : 
843 //=================================================================================
844 int SMESHGUI_RevolutionDlg::GetConstructorId()
845
846   if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
847     return GroupConstructors->id( GroupConstructors->selected() );
848   return -1;
849 }
850
851
852 //=================================================================================
853 // function : IsAxisOk()
854 // purpose  : 
855 //=================================================================================
856 bool SMESHGUI_RevolutionDlg::IsAxisOk()
857 {
858   return (SpinBox_DX->GetValue() != 0 || 
859           SpinBox_DY->GetValue() != 0 ||
860           SpinBox_DZ->GetValue() != 0); 
861 }
862
863
864 //=================================================================================
865 // function : onVectorChanged()
866 // purpose  : 
867 //=================================================================================
868 void SMESHGUI_RevolutionDlg::onVectorChanged()
869 {
870   if (IsAxisOk())
871     {
872       buttonOk->setEnabled( true );
873       buttonApply->setEnabled( true );
874     }
875   else
876     {
877       buttonOk->setEnabled( false );
878       buttonApply->setEnabled( false );
879     }
880 }
881
882
883 //=======================================================================
884 //function : onSelectMesh
885 //purpose  :
886 //=======================================================================
887 void SMESHGUI_RevolutionDlg::onSelectMesh ( bool toSelectMesh )
888 {
889   if (toSelectMesh)
890     TextLabelElements->setText( tr( "SMESH_NAME" ) );
891   else
892     TextLabelElements->setText( tr( "SMESH_ID_ELEMENTS" ) );
893   
894   if (myEditCurrentArgument != LineEditElements)
895     {
896       LineEditElements->clear();
897       return;
898     }
899   
900   mySelection->ClearFilters() ;
901   SMESH::SetPointRepresentation(false);
902   
903   if (toSelectMesh)
904     {
905       QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
906       mySelection->AddFilter(myMeshOrSubMeshOrGroupFilter);
907       LineEditElements->setReadOnly(true);
908     }
909   else
910     {
911       int aConstructorId = GetConstructorId();
912       if (aConstructorId == 0)
913         QAD_Application::getDesktop()->SetSelectionMode( EdgeSelection, true );
914       else if (aConstructorId == 0)
915         QAD_Application::getDesktop()->SetSelectionMode( FaceSelection, true );
916       
917       LineEditElements->setReadOnly(false);
918       onTextChange(LineEditElements->text());
919     }
920   
921   SelectionIntoArgument();
922 }