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