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