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