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