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