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