Salome HOME
NRI : 1_3_0 version.
[modules/geom.git] / src / GEOMGUI / GeometryGUI_CylinderDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry 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   : GeometryGUI_CylinderDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "GeometryGUI_CylinderDlg.h"
31
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_Config.h"
36 #include "utilities.h"
37
38 #include <BRepAdaptor_Curve.hxx>
39
40 #include <qbuttongroup.h>
41 #include <qgroupbox.h>
42 #include <qlabel.h>
43 #include <qlineedit.h>
44 #include <qpushbutton.h>
45 #include <qradiobutton.h>
46 #include <qlayout.h>
47 #include <qvariant.h>
48 #include <qtooltip.h>
49 #include <qwhatsthis.h>
50 #include <qimage.h>
51 #include <qpixmap.h>
52
53 //=================================================================================
54 // class    : GeometryGUI_CylinderDlg()
55 // purpose  : Constructs a GeometryGUI_CylinderDlg which is a child of 'parent', with the 
56 //            name 'name' and widget flags set to 'f'.
57 //            The dialog will by default be modeless, unless you set 'modal' to
58 //            TRUE to construct a modal dialog.
59 //=================================================================================
60 GeometryGUI_CylinderDlg::GeometryGUI_CylinderDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
61     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
62 {
63     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_CYLINDER_PV")));
64     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
65     QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_CYLINDER_DXYZ")));
66     
67     if ( !name )
68       setName( "GeometryGUI_CylinderDlg" );
69     resize( 303, 281 ); 
70     setCaption( tr( "GEOM_CYLINDER_TITLE"  ) );
71     setSizeGripEnabled( TRUE );
72     GeometryGUI_CylinderDlgLayout = new QGridLayout( this ); 
73     GeometryGUI_CylinderDlgLayout->setSpacing( 6 );
74     GeometryGUI_CylinderDlgLayout->setMargin( 11 );
75
76     /***************************************************************/
77     GroupButtons = new QGroupBox( this, "GroupButtons" );
78     GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
79     GroupButtons->setTitle( tr( ""  ) );
80     GroupButtons->setColumnLayout(0, Qt::Vertical );
81     GroupButtons->layout()->setSpacing( 0 );
82     GroupButtons->layout()->setMargin( 0 );
83     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
84     GroupButtonsLayout->setAlignment( Qt::AlignTop );
85     GroupButtonsLayout->setSpacing( 6 );
86     GroupButtonsLayout->setMargin( 11 );
87     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
88     buttonCancel->setText( tr( "GEOM_BUT_CLOSE"  ) );
89     buttonCancel->setAutoDefault( TRUE );
90     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
91     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
92     buttonApply->setText( tr( "GEOM_BUT_APPLY"  ) );
93     buttonApply->setAutoDefault( TRUE );
94     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
95     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
96     GroupButtonsLayout->addItem( spacer, 0, 2 );
97     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
98     buttonOk->setText( tr( "GEOM_BUT_OK"  ) );
99     buttonOk->setAutoDefault( TRUE );
100     buttonOk->setDefault( TRUE );
101     GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
102     GeometryGUI_CylinderDlgLayout->addWidget( GroupButtons, 2, 0 );
103
104     /***************************************************************/
105     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
106     GroupConstructors->setTitle( tr( "GEOM_CYLINDER"  ) );
107     GroupConstructors->setExclusive( TRUE );
108     GroupConstructors->setColumnLayout(0, Qt::Vertical );
109     GroupConstructors->layout()->setSpacing( 0 );
110     GroupConstructors->layout()->setMargin( 0 );
111     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
112     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
113     GroupConstructorsLayout->setSpacing( 6 );
114     GroupConstructorsLayout->setMargin( 11 );
115     QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
116     GroupConstructorsLayout->addItem( spacer_2, 0, 1 );
117     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
118     Constructor1->setText( tr( ""  ) );
119     Constructor1->setPixmap( image0 );
120     Constructor1->setChecked( TRUE );
121     Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
122     Constructor1->setMinimumSize( QSize( 50, 0 ) );
123     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
124     Constructor2 = new QRadioButton( GroupConstructors, "Constructor2" );
125     Constructor2->setText( tr( ""  ) );
126     Constructor2->setMinimumSize( QSize( 50, 0 ) );
127     Constructor2->setPixmap( image2 );
128     Constructor2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
129     GroupConstructorsLayout->addWidget( Constructor2, 0, 2 );
130     QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
131     GroupConstructorsLayout->addItem( spacer_3, 0, 3 );
132     GeometryGUI_CylinderDlgLayout->addWidget( GroupConstructors, 0, 0 );
133     
134     /***************************************************************/
135     GroupC1 = new QGroupBox( this, "GroupC1" );
136     GroupC1->setTitle( tr( "GEOM_ARGUMENTS"  ) );
137     GroupC1->setColumnLayout(0, Qt::Vertical );
138     GroupC1->layout()->setSpacing( 0 );
139     GroupC1->layout()->setMargin( 0 );
140     GroupC1Layout = new QGridLayout( GroupC1->layout() );
141     GroupC1Layout->setAlignment( Qt::AlignTop );
142     GroupC1Layout->setSpacing( 6 );
143     GroupC1Layout->setMargin( 11 );
144     SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
145     SelectButtonC1A1->setText( tr( ""  ) );
146     SelectButtonC1A1->setPixmap( image1 );
147     GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
148     LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
149     LineEditC1A1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1->sizePolicy().hasHeightForWidth() ) );
150     GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
151     TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
152     TextLabelC1A1->setText( tr( "GEOM_BASE_POINT"  ) );
153     TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
154     TextLabelC1A1->setFrameShape( QLabel::NoFrame );
155     TextLabelC1A1->setFrameShadow( QLabel::Plain );
156     GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
157     SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
158     SelectButtonC1A2->setText( tr( ""  ) );
159     SelectButtonC1A2->setMinimumSize( QSize( 0, 0 ) );
160     SelectButtonC1A2->setPixmap( image1 );
161     GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
162     LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
163     LineEditC1A2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A2->sizePolicy().hasHeightForWidth() ) );
164     GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
165     TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
166     TextLabelC1A2->setText( tr( "GEOM_VECTOR"  ) );
167     TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
168     TextLabelC1A2->setFrameShape( QLabel::NoFrame );
169     TextLabelC1A2->setFrameShadow( QLabel::Plain );
170     GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
171     TextLabelC1A3 = new QLabel( GroupC1, "TextLabelC1A3" );
172     TextLabelC1A3->setText( tr( "GEOM_RADIUS"  ) );
173     TextLabelC1A3->setMinimumSize( QSize( 50, 0 ) );
174     TextLabelC1A3->setFrameShape( QLabel::NoFrame );
175     TextLabelC1A3->setFrameShadow( QLabel::Plain );
176     GroupC1Layout->addWidget( TextLabelC1A3, 2, 0 );
177  
178     SpinBox_C1A3 = new GeometryGUI_SpinBox( GroupC1, "GeomSpinBox_C1A3" ) ;
179     GroupC1Layout->addWidget( SpinBox_C1A3, 2, 2 ) ;
180     
181     TextLabelC1A4 = new QLabel( GroupC1, "TextLabelC1A4" );
182     TextLabelC1A4->setText( tr( "GEOM_HEIGHT"  ) );
183     TextLabelC1A4->setMinimumSize( QSize( 50, 0 ) );
184     TextLabelC1A4->setFrameShape( QLabel::NoFrame );
185     TextLabelC1A4->setFrameShadow( QLabel::Plain );
186     GroupC1Layout->addWidget( TextLabelC1A4, 3, 0 );
187
188     SpinBox_C1A4 = new GeometryGUI_SpinBox( GroupC1, "GeomSpinBox_C1A4" ) ;
189     GroupC1Layout->addWidget( SpinBox_C1A4, 3, 2 );
190     
191     GeometryGUI_CylinderDlgLayout->addWidget( GroupC1, 1, 0 );
192
193     /***************************************************************/
194     GroupC2 = new QGroupBox( this, "GroupC2" );
195     GroupC2->setTitle( tr( "GEOM_BOX_OBJ"  ) );
196     GroupC2->setColumnLayout(0, Qt::Vertical );
197     GroupC2->layout()->setSpacing( 0 );
198     GroupC2->layout()->setMargin( 0 );
199     GroupC2Layout = new QGridLayout( GroupC2->layout() );
200     GroupC2Layout->setAlignment( Qt::AlignTop );
201     GroupC2Layout->setSpacing( 6 );
202     GroupC2Layout->setMargin( 11 );
203     TextLabel_Height = new QLabel(GroupC2 , "TextLabel_Height" );
204     TextLabel_Height->setText( tr( "GEOM_HEIGHT"  ) );
205     GroupC2Layout->addWidget( TextLabel_Height, 1, 0 );
206     TextLabel_Radius = new QLabel( GroupC2, "TextLabel_Radius" );
207     TextLabel_Radius->setText( tr( "GEOM_RADIUS"  ) );
208     GroupC2Layout->addWidget( TextLabel_Radius, 0, 0 );
209
210     SpinBox_Height = new GeometryGUI_SpinBox( GroupC2, "GeomSpinBox_Height" ) ;
211     SpinBox_Height->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, SpinBox_Height->sizePolicy().hasHeightForWidth() ) );
212     GroupC2Layout->addWidget( SpinBox_Height, 1, 1 ) ;
213
214     SpinBox_Radius = new GeometryGUI_SpinBox( GroupC2, "GeomSpinBox_Radius" ) ;
215     SpinBox_Radius->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, SpinBox_Radius->sizePolicy().hasHeightForWidth() ) );
216     GroupC2Layout->addWidget( SpinBox_Radius, 0, 1 ) ;
217
218     QSpacerItem* spacer1 = new QSpacerItem( 20, 62, QSizePolicy::Minimum, QSizePolicy::Fixed );
219     GroupC2Layout->addItem( spacer1 );
220
221     GeometryGUI_CylinderDlgLayout->addWidget(GroupC2 , 1, 0 );
222     /***************************************************************/
223
224     Init(Sel) ; /* Initialisations */
225 }
226
227
228 //=================================================================================
229 // function : ~GeometryGUI_CylinderDlg()
230 // purpose  : Destroys the object and frees any allocated resources
231 //=================================================================================
232 GeometryGUI_CylinderDlg::~GeometryGUI_CylinderDlg()
233 {
234     // no need to delete child widgets, Qt does it all for us
235 }
236
237
238 //=================================================================================
239 // function : Init()
240 // purpose  :
241 //=================================================================================
242 void GeometryGUI_CylinderDlg::Init( SALOME_Selection* Sel )
243 {
244
245   /* Get setting of step value from file configuration */
246   double step ;
247   QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" );
248   step = St.toDouble() ;
249
250   /* min, max, step and decimals for spin boxes & initial values */
251   /* First constructor : radius */
252   SpinBox_C1A3->RangeStepAndValidator( 0.001, 999.999, step, 3 ) ;
253   /* First constructor : algebric height */
254   SpinBox_C1A4->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
255   /* Second constructor : radius */
256   SpinBox_Radius->RangeStepAndValidator( 0.001, 999.999, step, 3 ) ;
257   /* Second constructor : algebric height */
258   SpinBox_Height->RangeStepAndValidator( -999.999, 999.999, step, 3 ) ;
259
260   GroupC1->show();
261   GroupC2->hide();
262   myConstructorId = 0 ;
263   Constructor1->setChecked( TRUE );
264   myEditCurrentArgument = LineEditC1A1 ;        
265   mySelection = Sel;
266   myGeomGUI = GeometryGUI::GetGeometryGUI() ;
267
268   SpinBox_C1A3->SetValue( 100.0 ) ;  
269   SpinBox_C1A4->SetValue( 300.0 ) ;
270   SpinBox_Radius->SetValue( 100.0 ) ;  
271   SpinBox_Height->SetValue( 300.0 ) ;  
272   myRadius = 100.0 ;
273   myHeight = 300.0 ;
274
275   myOkRadius = true ;
276   myOkHeight = true ;  
277   myOkPoint1 = false ;
278   myOkDir    = false ;
279
280   mySimulationTopoDs.Nullify() ;
281   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
282
283   // TODO : previous selection into argument ?
284
285   /* Filter definitions */
286   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
287   myGeom = GEOM::GEOM_Gen::_narrow(comp);  
288   myEdgeFilter   = new GEOM_EdgeFilter( StdSelect_Line, myGeom );
289   myVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX, myGeom );
290
291   /* first filter used */
292   mySelection->AddFilter(myVertexFilter) ;
293
294   /* signals and slots connections */
295   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
296   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
297   connect( buttonApply,  SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
298   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );  
299   connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
300   connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
301
302   connect( SpinBox_C1A3,   SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
303   connect( SpinBox_C1A4,   SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
304   connect( SpinBox_Radius, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
305   connect( SpinBox_Height, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
306
307   connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
308   connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
309
310   connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;  
311   connect( mySelection, SIGNAL( currentSelectionChanged() ),     this, SLOT( SelectionIntoArgument() ) );
312   /* to close dialog if study change */
313   connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
314
315   /* Move widget on the botton right corner of main widget */
316   int x, y ;
317   myGeomGUI->DefineDlgPosition( this, x, y ) ;
318   this->move( x, y ) ; 
319   this->show() ; /* displays Dialog */
320
321   return ;
322 }
323
324
325
326 //=================================================================================
327 // function : ConstructorsClicked()
328 // purpose  : Radio button management
329 //=================================================================================
330 void GeometryGUI_CylinderDlg::ConstructorsClicked(int constructorId)
331 {
332   mySelection->ClearFilters() ;
333   myGeomGUI->EraseSimulationShape() ;
334
335   switch(myConstructorId)
336     { 
337     case 0 :
338       { 
339         GroupC1->hide();
340         GroupC2->show();
341         myConstructorId = constructorId ;
342         myOkHeight = myOkRadius = myOkPoint1 = myOkDir = true ;
343         
344         SpinBox_Radius->SetValue( 100.0 ) ;  
345         SpinBox_Height->SetValue( 300.0 ) ; 
346         myRadius = 100.0 ;
347         myHeight = 300.0 ;
348
349         disconnect( mySelection, 0, this, 0 );
350
351         myPoint1.SetCoord( 0.0, 0.0, 0.0 ) ;
352         myDir.SetCoord( 0.0, 0.0, 1.0 ) ;
353
354         if( myOkPoint1 && myOkDir && myOkRadius && myOkHeight ) {
355           gp_Dir aDir = myDir ;
356           /* allows user to reverse direction of construction with a negative height */
357           if( this->myHeight < -Precision::Confusion() ) {
358             aDir.Reverse() ;
359           }
360           MakeCylinderSimulationAndDisplay() ;
361         } 
362         break ;
363       }
364     case 1 :
365       { 
366         GroupC2->hide();
367         GroupC1->show();
368         myConstructorId = constructorId ;
369         myEditCurrentArgument = LineEditC1A1 ;
370         myOkHeight = myOkRadius = true ;
371         myOkPoint1 = myOkDir = false ;
372         LineEditC1A1->setText( tr("") );
373         
374         SpinBox_C1A3->SetValue( 100.0 ) ;  
375         SpinBox_C1A4->SetValue( 300.0 ) ; 
376         myRadius = 100.0 ;
377         myHeight = 300.0 ;
378         disconnect( mySelection, 0, this, 0 );
379         break ;
380       }
381     }
382   return ;
383 }
384
385 //=================================================================================
386 // function : ClickOnOk()
387 // purpose  :
388 //=================================================================================
389 void GeometryGUI_CylinderDlg::ClickOnOk()
390 {
391   this->ClickOnApply() ;
392   this->ClickOnCancel() ;
393
394   return ;
395 }
396
397 //=================================================================================
398 // function : ClickOnApply()
399 // purpose  :
400 //=================================================================================
401 void GeometryGUI_CylinderDlg::ClickOnApply()
402 {
403   myGeomGUI->EraseSimulationShape() ;
404   mySimulationTopoDs.Nullify() ;
405   myGeomGUI->GetDesktop()->putInfo( tr("") ) ; 
406   switch(myConstructorId)
407     { 
408     case 0 :
409       { 
410         if( myOkPoint1 && myOkDir && myOkRadius && myOkHeight ) {
411           gp_Dir aDir = myDir ;
412           /* allows user to reverse direction of construction with a negative height */
413           if( this->myHeight < -Precision::Confusion() ) {
414             aDir.Reverse() ;
415           }
416           myGeomGUI->MakeCylinderAndDisplay( myPoint1, aDir, myRadius, fabs(myHeight) ) ; 
417         }
418         break ;
419       }
420     case 1 :
421       { 
422         if( myOkPoint1 && myOkDir && myOkRadius && myOkHeight ) {
423           gp_Dir aDir = myDir ;
424           /* allows user to reverse direction of construction with a negative height */
425           if( this->myHeight < -Precision::Confusion() ) {
426             aDir.Reverse() ;
427           }
428           myGeomGUI->MakeCylinderAndDisplay( myPoint1, aDir, myRadius, fabs(myHeight) ) ; 
429         }
430         break ;
431       }
432     }
433   // accept();
434   return ;
435 }
436
437
438 //=================================================================================
439 // function : ClickOnCancel()
440 // purpose  :
441 //=================================================================================
442 void GeometryGUI_CylinderDlg::ClickOnCancel()
443 {
444   mySelection->ClearFilters() ;
445   myGeomGUI->EraseSimulationShape() ;
446   mySimulationTopoDs.Nullify() ;
447   disconnect( mySelection, 0, this, 0 );
448   myGeomGUI->ResetState() ;
449   reject() ;
450   return ;
451 }
452
453
454 //=================================================================================
455 // function : SelectionIntoArgument()
456 // purpose  : Called when selection as changed or other case
457 //=================================================================================
458 void GeometryGUI_CylinderDlg::SelectionIntoArgument()
459 {
460   myGeomGUI->EraseSimulationShape() ; 
461   mySimulationTopoDs.Nullify() ;
462   
463   QString aString = ""; /* name of future selection */
464
465   int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
466   if ( nbSel != 1 ) {
467     if ( myEditCurrentArgument == LineEditC1A1 ) {
468       LineEditC1A1->setText("") ;
469       myOkPoint1 = false ;
470     }
471     else if ( myEditCurrentArgument == LineEditC1A2 ) { 
472       LineEditC1A2->setText("") ;
473       myOkDir = false ;
474     }
475     return ;
476   }
477
478   /* nbSel == 1 */
479   TopoDS_Shape S;  
480   if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
481     return ;  
482  
483   /*  gp_Pnt : not used */
484   if ( myEditCurrentArgument == LineEditC1A1 && myGeomGUI->VertexToPoint(S, myPoint1) ) {
485     LineEditC1A1->setText(aString) ;
486     myOkPoint1 = true ;
487   }    
488   else if ( myEditCurrentArgument == LineEditC1A2 /*&& myGeomGUI->LinearLocationAndDirection(S, notUsed, myDir)*/ ) {
489     BRepAdaptor_Curve curv(TopoDS::Edge(S));
490     myDir = curv.Line().Direction();
491
492     LineEditC1A2->setText(aString) ;
493     myOkDir = true ;
494   }
495   
496   if( myOkPoint1 && myOkDir && myOkRadius && myOkHeight ) {
497     MakeCylinderSimulationAndDisplay() ;
498   }
499   return ;
500 }
501
502 //=================================================================================
503 // function : SetEditCurrentArgument()
504 // purpose  :
505 //=================================================================================
506 void GeometryGUI_CylinderDlg::SetEditCurrentArgument()
507 {
508   QPushButton* send = (QPushButton*)sender();
509   mySelection->ClearFilters() ;
510   switch (myConstructorId)
511     {
512     case 0: /* default constructor */
513       { 
514         if(send == SelectButtonC1A1) {
515           LineEditC1A1->setFocus() ;
516           myEditCurrentArgument = LineEditC1A1;
517           mySelection->AddFilter(myVertexFilter) ;
518         }
519         else if(send == SelectButtonC1A2) {
520           LineEditC1A2->setFocus() ;      
521           myEditCurrentArgument = LineEditC1A2;
522           mySelection->AddFilter(myEdgeFilter) ;
523         }       
524         SelectionIntoArgument() ;
525         break;
526       }
527      case 1:
528       { 
529         break ;
530       }
531     }
532
533   return ;
534 }
535
536 //=================================================================================
537 // function : LineEditReturnPressed()
538 // purpose  :
539 //=================================================================================
540 void GeometryGUI_CylinderDlg::LineEditReturnPressed()
541 {  
542   QLineEdit* send = (QLineEdit*)sender();  
543   if( send == LineEditC1A1 )
544     myEditCurrentArgument = LineEditC1A1 ;
545   else if ( send == LineEditC1A2 )
546     myEditCurrentArgument = LineEditC1A2 ; 
547   else
548     return ;
549   
550   /* User name of object input management                          */
551   /* If successfull the selection is changed and signal emitted... */
552   /* so SelectionIntoArgument() is automatically called.           */
553   QLineEdit* LE = (QLineEdit*)myEditCurrentArgument ;
554   const QString objectUserName = LE->text() ;
555   QWidget* thisWidget = (QWidget*)this ;
556   if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
557     LE->setText( objectUserName ) ;
558   }
559   return ;
560 }
561
562
563 //=================================================================================
564 // function : ValueChangedInSpinBox
565 // purpose  :
566 //=================================================================================
567 void GeometryGUI_CylinderDlg::ValueChangedInSpinBox( double newValue )
568 {  
569   
570   myGeomGUI->EraseSimulationShape() ; 
571   mySimulationTopoDs.Nullify() ;
572   QObject* send = (QObject*)sender();
573   
574   if(send == SpinBox_C1A3 ) { /* radius */
575
576     myRadius = newValue ;
577     myOkRadius = true ;
578     if (myOkPoint1 && myOkDir && myOkRadius && myOkHeight ) {
579       MakeCylinderSimulationAndDisplay() ;
580     }
581   } else if (send == SpinBox_C1A4 ) { /* algebric height */    
582     
583     myHeight = newValue ;
584     myOkHeight = true ;
585     if (myOkPoint1 && myOkDir && myOkRadius && myOkHeight ) {
586       MakeCylinderSimulationAndDisplay() ;
587     }
588   } 
589   else if (send == SpinBox_Height) { /* algebric height */
590
591     myOkHeight = true ;
592     myHeight = newValue ;
593     if (myOkPoint1 && myOkDir && myOkRadius && myOkHeight ) {
594       MakeCylinderSimulationAndDisplay() ;
595     }
596   } 
597   else if (send == SpinBox_Radius) { /* radius */
598     myRadius = newValue ;
599     myOkRadius = true ;
600     if (myOkPoint1 && myOkDir && myOkRadius && myOkHeight ) {
601       MakeCylinderSimulationAndDisplay() ;
602     }
603   } 
604   return ;
605 }
606
607 //=================================================================================
608 // function : DeactivateActiveDialog()
609 // purpose  :
610 //=================================================================================
611 void GeometryGUI_CylinderDlg::DeactivateActiveDialog()
612 {
613   if ( GroupConstructors->isEnabled() ) {
614     GroupConstructors->setEnabled(false) ;
615     GroupC1->setEnabled(false) ;
616     GroupC2->setEnabled(false) ;
617     GroupButtons->setEnabled(false) ;
618     disconnect( mySelection, 0, this, 0 );
619     myGeomGUI->EraseSimulationShape() ;
620     mySelection->ClearFilters() ;
621   }
622   return ;
623 }
624
625
626 //=================================================================================
627 // function : ActivateThisDialog()
628 // purpose  :
629 //=================================================================================
630 void GeometryGUI_CylinderDlg::ActivateThisDialog()
631 {
632   /* Emit a signal to deactivate the active dialog */
633   myGeomGUI->EmitSignalDeactivateDialog() ;   
634   GroupConstructors->setEnabled(true) ;
635   GroupC1->setEnabled(true) ;
636   GroupC2->setEnabled(true) ;
637   GroupButtons->setEnabled(true) ;
638   connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
639   if( !mySimulationTopoDs.IsNull() )
640     myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
641   return ;
642 }
643
644
645 //=================================================================================
646 // function : enterEvent()
647 // purpose  :
648 //=================================================================================
649 void GeometryGUI_CylinderDlg::enterEvent(QEvent* e)
650 {
651   if ( GroupConstructors->isEnabled() )
652     return ;  
653   ActivateThisDialog() ;
654   return ;
655 }
656
657
658 //=================================================================================
659 // function : closeEvent()
660 // purpose  :
661 //=================================================================================
662 void GeometryGUI_CylinderDlg::closeEvent( QCloseEvent* e )
663 {
664   /* same than click on cancel button */
665   this->ClickOnCancel() ;
666   return ;
667 }
668
669
670 //=================================================================================
671 // function : MakeCylinderSimulationAndDisplay()
672 // purpose  :
673 //=================================================================================
674 void GeometryGUI_CylinderDlg::MakeCylinderSimulationAndDisplay() 
675 {
676   myGeomGUI->EraseSimulationShape() ;
677   mySimulationTopoDs.Nullify() ;
678   gp_Dir aDir = this->myDir ;
679   
680   try {
681     /* allows user to reverse direction of construction with a negative height */
682     if( this->myHeight < -Precision::Confusion() ) {
683       aDir.Reverse() ;
684     }
685     gp_Ax2 anAxis(this->myPoint1, aDir) ;
686
687     mySimulationTopoDs = BRepPrimAPI_MakeCylinder( anAxis, this->myRadius, fabs(myHeight) ).Shape() ;
688     myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
689   }
690   catch(Standard_Failure) {
691     MESSAGE( "Exception catched in MakeCylinderSimulationAndDisplay" ) ;
692   }
693   return ;
694 }
695