Salome HOME
sources v1.2
[modules/geom.git] / src / GEOMGUI / GeometryGUI_FilletDlg.cxx
1 using namespace std;
2 //  File      : GeometryGUI_FilletDlg.cxx
3 //  Created   : 
4 //  Author    : Damien COQUERET
5 //  Project   : SALOME
6 //  Module    : GEOM
7 //  Copyright : OPEN CASCADE 2002
8 //  $Header$
9
10 #include "GeometryGUI_FilletDlg.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 #include "QAD_RightFrame.h"
18 #include "OCCViewer_Viewer3d.h"
19
20 #include <qbuttongroup.h>
21 #include <qcheckbox.h>
22 #include <qcombobox.h>
23 #include <qgroupbox.h>
24 #include <qlabel.h>
25 #include <qlineedit.h>
26 #include <qpushbutton.h>
27 #include <qradiobutton.h>
28 #include <qlayout.h>
29 #include <qvariant.h>
30 #include <qtooltip.h>
31 #include <qwhatsthis.h>
32 #include <qimage.h>
33 #include <qpixmap.h>
34
35 #include <TopExp_Explorer.hxx>
36 #include <BRepFilletAPI_MakeFillet.hxx>
37
38 #include <Standard_ErrorHandler.hxx> 
39 #include <Standard_Failure.hxx>
40
41
42 //=================================================================================
43 // class    : GeometryGUI_FilletDlg()
44 // purpose  : Constructs a GeometryGUI_FilletDlg which is a child of 'parent', with the 
45 //            name 'name' and widget flags set to 'f'.
46 //            The dialog will by default be modeless, unless you set 'modal' to
47 //            TRUE to construct a modal dialog.
48 //=================================================================================
49 GeometryGUI_FilletDlg::GeometryGUI_FilletDlg( QWidget* parent,
50                                               const char* name,
51                                               SALOME_Selection* Sel,
52                                               Handle (AIS_InteractiveContext) ic, 
53                                               bool modal,
54                                               WFlags fl )
55   : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
56 {
57     /***************************************************************/
58     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_FILLET_ALL")));
59     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
60     QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_FILLET_EDGE")));
61     QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_FILLET_FACE")));
62
63     if ( !name )
64         setName( "GeometryGUI_FilletDlg" );
65     resize( 365, 220 ); 
66     setCaption( tr( "GEOM_FILLET_TITLE"  ) );
67     setSizeGripEnabled( TRUE );
68     GeometryGUI_FilletDlgLayout = new QGridLayout( this ); 
69     GeometryGUI_FilletDlgLayout->setSpacing( 6 );
70     GeometryGUI_FilletDlgLayout->setMargin( 11 );
71
72     /***************************************************************/
73     GroupButtons = new QGroupBox( this, "GroupButtons" );
74     GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
75     GroupButtons->setTitle( tr( ""  ) );
76     GroupButtons->setColumnLayout(0, Qt::Vertical );
77     GroupButtons->layout()->setSpacing( 0 );
78     GroupButtons->layout()->setMargin( 0 );
79     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
80     GroupButtonsLayout->setAlignment( Qt::AlignTop );
81     GroupButtonsLayout->setSpacing( 6 );
82     GroupButtonsLayout->setMargin( 11 );
83     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
84     buttonCancel->setText( tr( "GEOM_BUT_CLOSE"  ) );
85     buttonCancel->setAutoDefault( TRUE );
86     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
87     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
88     buttonApply->setText( tr( "GEOM_BUT_APPLY"  ) );
89     buttonApply->setAutoDefault( TRUE );
90     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
91     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
92     GroupButtonsLayout->addItem( spacer, 0, 2 );
93     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
94     buttonOk->setText( tr( "GEOM_BUT_OK"  ) );
95     buttonOk->setAutoDefault( TRUE );
96     buttonOk->setDefault( TRUE );
97     GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
98     GeometryGUI_FilletDlgLayout->addWidget( GroupButtons, 2, 0 );
99
100     /***************************************************************/
101     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
102     GroupConstructors->setTitle( tr( "GEOM_FILLET"  ) );
103     GroupConstructors->setExclusive( TRUE );
104     GroupConstructors->setColumnLayout(0, Qt::Vertical );
105     GroupConstructors->layout()->setSpacing( 0 );
106     GroupConstructors->layout()->setMargin( 0 );
107     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
108     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
109     GroupConstructorsLayout->setSpacing( 6 );
110     GroupConstructorsLayout->setMargin( 11 );
111     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
112     Constructor1->setText( tr( ""  ) );
113     Constructor1->setPixmap( image0 );
114     Constructor1->setChecked( TRUE );
115     Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
116     Constructor1->setMinimumSize( QSize( 50, 0 ) );
117     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
118     Constructor2 = new QRadioButton( GroupConstructors, "Constructor2" );
119     Constructor2->setText( tr( ""  ) );
120     Constructor2->setPixmap( image2 );
121     Constructor2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor2->sizePolicy().hasHeightForWidth() ) );
122     Constructor2->setMinimumSize( QSize( 50, 0 ) );
123     GroupConstructorsLayout->addWidget( Constructor2, 0, 2 );
124     QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
125     GroupConstructorsLayout->addItem( spacer_2, 0, 3 );
126     QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
127     GroupConstructorsLayout->addItem( spacer_3, 0, 1 );
128     Constructor3 = new QRadioButton( GroupConstructors, "Constructor3" );
129     Constructor3->setText( tr( ""  ) );
130     Constructor3->setPixmap( image3 );
131     Constructor3->setMinimumSize( QSize( 50, 0 ) );
132     GroupConstructorsLayout->addWidget( Constructor3, 0, 4 );
133     QSpacerItem* spacer_4 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
134     GroupConstructorsLayout->addItem( spacer_4, 0, 5 );
135     GeometryGUI_FilletDlgLayout->addWidget( GroupConstructors, 0, 0 );
136
137     /***************************************************************/
138     GroupC1 = new QGroupBox( this, "GroupC1" );
139     GroupC1->setTitle( tr( "GEOM_FILLET_ALL"  ) );
140     GroupC1->setMinimumSize( QSize( 0, 0 ) );
141     GroupC1->setFrameShape( QGroupBox::Box );
142     GroupC1->setFrameShadow( QGroupBox::Sunken );
143     GroupC1->setColumnLayout(0, Qt::Vertical );
144     GroupC1->layout()->setSpacing( 0 );
145     GroupC1->layout()->setMargin( 0 );
146     GroupC1Layout = new QGridLayout( GroupC1->layout() );
147     GroupC1Layout->setAlignment( Qt::AlignTop );
148     GroupC1Layout->setSpacing( 6 );
149     GroupC1Layout->setMargin( 11 );
150     
151     TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
152     TextLabelC1A1->setText( tr( "GEOM_MAIN_OBJECT"  ) );
153     TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
154     TextLabelC1A1->setFrameShape( QLabel::NoFrame );
155     TextLabelC1A1->setFrameShadow( QLabel::Plain );
156     GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
157
158     TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
159     TextLabelC1A2->setText( tr( "GEOM_RADIUS"  ) );
160     TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
161     TextLabelC1A2->setFrameShape( QLabel::NoFrame );
162     TextLabelC1A2->setFrameShadow( QLabel::Plain );
163     GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
164    
165     LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
166     GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
167
168     SpinBox_C1A2 = new GeometryGUI_SpinBox( GroupC1, "GeomSpinBox_C1A2" ) ;
169     SpinBox_C1A2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, SpinBox_C1A2->sizePolicy().hasHeightForWidth() ) );
170     GroupC1Layout->addWidget( SpinBox_C1A2, 1, 2 );
171     
172     SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
173     SelectButtonC1A1->setText( tr( ""  ) );
174     SelectButtonC1A1->setPixmap( image1 );
175     SelectButtonC1A1->setToggleButton( FALSE );
176     SelectButtonC1A1->setMaximumSize( QSize( 28, 32767 ) );
177     GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
178     GeometryGUI_FilletDlgLayout->addWidget( GroupC1, 1, 0 );
179
180     /***************************************************************/
181     GroupC2 = new QGroupBox( this, "GroupC2" );
182     GroupC2->setTitle( tr( "GEOM_FILLET_EDGES"  ) );
183     GroupC2->setMinimumSize( QSize( 0, 0 ) );
184     GroupC2->setFrameShape( QGroupBox::Box );
185     GroupC2->setFrameShadow( QGroupBox::Sunken );
186     GroupC2->setColumnLayout(0, Qt::Vertical );
187     GroupC2->layout()->setSpacing( 0 );
188     GroupC2->layout()->setMargin( 0 );
189     GroupC2Layout = new QGridLayout( GroupC2->layout() );
190     GroupC2Layout->setAlignment( Qt::AlignTop );
191     GroupC2Layout->setSpacing( 6 );
192     GroupC2Layout->setMargin( 11 );
193     
194     TextLabelC2A1 = new QLabel( GroupC2, "TextLabelC2A1" );
195     TextLabelC2A1->setText( tr( "GEOM_MAIN_OBJECT"  ) );
196     TextLabelC2A1->setMinimumSize( QSize( 50, 0 ) );
197     TextLabelC2A1->setFrameShape( QLabel::NoFrame );
198     TextLabelC2A1->setFrameShadow( QLabel::Plain );
199     GroupC2Layout->addWidget( TextLabelC2A1, 0, 0 );
200
201     TextLabelC2A2 = new QLabel( GroupC2, "TextLabelC2A2" );
202     TextLabelC2A2->setText( tr( "GEOM_RADIUS"  ) );
203     TextLabelC2A2->setMinimumSize( QSize( 50, 0 ) );
204     TextLabelC2A2->setFrameShape( QLabel::NoFrame );
205     TextLabelC2A2->setFrameShadow( QLabel::Plain );
206     GroupC2Layout->addWidget( TextLabelC2A2, 1, 0 );
207    
208     LineEditC2A1 = new QLineEdit( GroupC2, "LineEditC2A1" );
209     GroupC2Layout->addWidget( LineEditC2A1, 0, 2 );
210
211     SpinBox_C2A2 = new GeometryGUI_SpinBox( GroupC2, "GeomSpinBox_C2A2" ) ;
212     SpinBox_C2A2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, SpinBox_C2A2->sizePolicy().hasHeightForWidth() ) );
213     GroupC2Layout->addWidget( SpinBox_C2A2, 1, 2 );
214
215     SelectButtonC2A1 = new QPushButton( GroupC2, "SelectButtonC2A1" );
216     SelectButtonC2A1->setText( tr( ""  ) );
217     SelectButtonC2A1->setPixmap( image1 );
218     SelectButtonC2A1->setToggleButton( FALSE );
219     SelectButtonC2A1->setMaximumSize( QSize( 28, 32767 ) );
220     GroupC2Layout->addWidget( SelectButtonC2A1, 0, 1 );
221     GeometryGUI_FilletDlgLayout->addWidget( GroupC2, 1, 0 );
222     
223     /***************************************************************/
224     GroupC3 = new QGroupBox( this, "GroupC3" );
225     GroupC3->setTitle( tr( "GEOM_FILLET_FACES"  ) );
226     GroupC3->setMinimumSize( QSize( 0, 0 ) );
227     GroupC3->setFrameShape( QGroupBox::Box );
228     GroupC3->setFrameShadow( QGroupBox::Sunken );
229     GroupC3->setColumnLayout(0, Qt::Vertical );
230     GroupC3->layout()->setSpacing( 0 );
231     GroupC3->layout()->setMargin( 0 );
232     GroupC3Layout = new QGridLayout( GroupC3->layout() );
233     GroupC3Layout->setAlignment( Qt::AlignTop );
234     GroupC3Layout->setSpacing( 6 );
235     GroupC3Layout->setMargin( 11 );
236     
237     TextLabelC3A1 = new QLabel( GroupC3, "TextLabelC3A1" );
238     TextLabelC3A1->setText( tr( "GEOM_MAIN_OBJECT"  ) );
239     TextLabelC3A1->setMinimumSize( QSize( 50, 0 ) );
240     TextLabelC3A1->setFrameShape( QLabel::NoFrame );
241     TextLabelC3A1->setFrameShadow( QLabel::Plain );
242     GroupC3Layout->addWidget( TextLabelC3A1, 0, 0 );
243
244     TextLabelC3A2 = new QLabel( GroupC3, "TextLabelC3A2" );
245     TextLabelC3A2->setText( tr( "GEOM_RADIUS"  ) );
246     TextLabelC3A2->setMinimumSize( QSize( 50, 0 ) );
247     TextLabelC3A2->setFrameShape( QLabel::NoFrame );
248     TextLabelC3A2->setFrameShadow( QLabel::Plain );
249     GroupC3Layout->addWidget( TextLabelC3A2, 1, 0 );
250    
251     LineEditC3A1 = new QLineEdit( GroupC3, "LineEditC3A1" );
252     GroupC3Layout->addWidget( LineEditC3A1, 0, 2 );
253
254     SpinBox_C3A2 = new GeometryGUI_SpinBox( GroupC3, "GeomSpinBox_C3A2" ) ;
255     SpinBox_C3A2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, SpinBox_C3A2->sizePolicy().hasHeightForWidth() ) );
256     GroupC3Layout->addWidget( SpinBox_C3A2, 1, 2 );
257
258     SelectButtonC3A1 = new QPushButton( GroupC3, "SelectButtonC3A1" );
259     SelectButtonC3A1->setText( tr( ""  ) );
260     SelectButtonC3A1->setPixmap( image1 );
261     SelectButtonC3A1->setToggleButton( FALSE );
262     SelectButtonC3A1->setMaximumSize( QSize( 28, 32767 ) );
263     GroupC3Layout->addWidget( SelectButtonC3A1, 0, 1 );
264     GeometryGUI_FilletDlgLayout->addWidget( GroupC3, 1, 0 );
265
266     /* Initialisation */
267     Init( Sel, ic ) ;
268 }
269
270
271 //=================================================================================
272 // function : ~GeometryGUI_FilletDlg()
273 // purpose  : Destroys the object and frees any allocated resources
274 //=================================================================================
275 GeometryGUI_FilletDlg::~GeometryGUI_FilletDlg()
276 {  
277   /* no need to delete child widgets, Qt does it all for us */
278   this->destroy(TRUE, TRUE) ;
279 }
280
281
282 //=================================================================================
283 // function : Init()
284 // purpose  :
285 //=================================================================================
286 void GeometryGUI_FilletDlg::Init( SALOME_Selection* Sel, Handle (AIS_InteractiveContext) ic )
287 {
288
289   /* Get setting of step value from file configuration */
290   double step ;
291   QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ) ;
292   step = St.toDouble() ;
293
294   /* min, max, step and decimals for spin boxes */
295   SpinBox_C1A2->RangeStepAndValidator( 0.001, 999.999, step, 3 ) ;
296   SpinBox_C1A2->SetValue( 50 ) ;
297   SpinBox_C2A2->RangeStepAndValidator( 0.001, 999.999, step, 3 ) ;
298   SpinBox_C2A2->SetValue( 50 ) ;
299   SpinBox_C3A2->RangeStepAndValidator( 0.001, 999.999, step, 3 ) ;
300   SpinBox_C3A2->SetValue( 50 ) ;
301
302   GroupC1->show();
303   GroupC2->hide() ;
304   GroupC3->hide() ;
305   myConstructorId = 0 ;
306   Constructor1->setChecked( TRUE );
307
308   mySelection = Sel ;
309   myEditCurrentArgument = LineEditC1A1 ;        
310   myShape.Nullify() ;
311   myRadius = 50.0 ;
312   myOkRadius = true ;
313   myIC = ic ;
314   myLocalContextId = -1 ;
315   myUseLocalContext = false ;
316   myOkShape = false ;
317
318   myGeomGUI = GeometryGUI::GetGeometryGUI() ;
319   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
320
321   mySimulationTopoDs.Nullify() ;
322   
323   /* Filters definition */
324   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
325   myGeom = GEOM::GEOM_Gen::_narrow(comp);
326
327   /* signals and slots connections */
328   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
329   connect( buttonApply, SIGNAL( clicked() ),     this, SLOT( ClickOnApply() ) );
330   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
331   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
332   connect( SelectButtonC1A1, SIGNAL (clicked() ),  this, SLOT( SetEditCurrentArgument() ) ) ;
333   connect( SelectButtonC2A1, SIGNAL (clicked() ),  this, SLOT( SetEditCurrentArgument() ) ) ;
334   connect( SelectButtonC3A1, SIGNAL (clicked() ),  this, SLOT( SetEditCurrentArgument() ) ) ;
335
336   connect( SpinBox_C1A2, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
337   connect( SpinBox_C2A2, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
338   connect( SpinBox_C3A2, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
339
340   connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
341   connect( LineEditC2A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
342   connect( LineEditC3A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
343
344   connect( mySelection, SIGNAL( currentSelectionChanged() ),     this, SLOT( SelectionIntoArgument() ) );
345   connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
346   /* to close dialog if study change */
347   connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
348  
349   /* Move widget on the botton right corner of main widget */
350   int x, y ;
351   myGeomGUI->DefineDlgPosition( this, x, y ) ;
352   this->move( x, y ) ;
353   this->show() ; /* Displays Dialog */ 
354
355   return ;
356 }
357
358
359
360 //=================================================================================
361 // function : ConstructorsClicked()
362 // purpose  : Radio button management
363 //=================================================================================
364 void GeometryGUI_FilletDlg::ConstructorsClicked(int constructorId)
365 {
366   myGeomGUI->EraseSimulationShape() ;
367   mySimulationTopoDs.Nullify() ;
368
369   myEditCurrentArgument->setText(tr("")) ;
370
371   if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
372     OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
373     myIC = v3d->getAISContext(); //    myIC = myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getViewerOCC()->getAISContext();
374     if(this->myUseLocalContext) {
375       myIC->CloseLocalContext(this->myLocalContextId) ;
376       myGeomGUI->OnDisplayAll(true) ;
377       this->myUseLocalContext = false ;
378     }
379   }
380
381   myOkShape = false ;
382   myRadius = 50.0 ;
383   myOkRadius = true ;
384   myConstructorId = constructorId ;
385
386   //  connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
387
388   switch (constructorId)
389     {
390     case 0: /* Fillet All */
391       {
392         myShapeType = -1;
393         GroupC1->show();
394         GroupC2->hide() ;
395         GroupC3->hide() ;
396         myEditCurrentArgument = LineEditC1A1 ;  
397         SpinBox_C1A2->SetValue( 50 ) ;;
398         LineEditC1A1->setText(tr("")) ;
399         break;
400       }
401
402     case 1: /* Fillet edges */
403       {
404         myShapeType = 6;
405         GroupC1->hide();
406         GroupC2->show() ;
407         GroupC3->hide() ;
408         myEditCurrentArgument = LineEditC2A1 ;
409         SpinBox_C2A2->SetValue( 50 ) ;;
410         LineEditC2A1->setText(tr("")) ;
411         break ;
412       }
413       
414     case 2: /* Fillet Faces */
415       {
416         myShapeType = 4;
417         GroupC1->hide();
418         GroupC2->hide() ;
419         GroupC3->show() ;
420         myEditCurrentArgument = LineEditC3A1 ;
421         SpinBox_C3A2->SetValue( 50 ) ;;
422         LineEditC3A1->setText(tr("")) ;
423         break ;
424       }
425     }
426   return ;
427 }
428
429
430 //=================================================================================
431 // function : ClickOnApply()
432 // purpose  :
433 //=================================================================================
434 void GeometryGUI_FilletDlg::ClickOnApply()
435 {
436   myGeomGUI->EraseSimulationShape() ;
437   mySimulationTopoDs.Nullify() ;
438
439   bool testResult = false ;
440   myGeomGUI->GetDesktop()->putInfo( tr("") ) ; 
441   switch(myConstructorId)
442     { 
443     case 0 : /* Fillet All */
444       { 
445         if(myOkRadius) {
446           if( myOkShape ) {
447             testResult = myGeomGUI->OnFilletGetAll( myShape, myRadius, myShapeType, myShapeIOR ) ;
448           }
449         }
450         if( !testResult ) {
451           myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_ABORT")) ;
452         } else {
453           myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_DONE")) ;
454         }  
455         /* Reset all arguments and local context to allow user a new selection ...*/
456         this->ResetStateOfDialog() ;
457         break ;
458       }
459       
460     case 1 : /* Fillet Edge */
461       { 
462         if(myOkRadius) {
463           if( myOkShape ) {
464             testResult = myGeomGUI->OnFilletGetSelected( myShape, myShapeIOR, myRadius, myShapeType, myLocalContextId, myUseLocalContext );
465           }
466         }
467         if( !testResult ) {
468           myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_ABORT")) ;
469         } else {
470           myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_DONE")) ;
471         }  
472         /* Reset all arguments and local context to allow user a new selection ...*/
473         this->ResetStateOfDialog() ;
474         break ;
475       }
476       
477     case 2 :  /* Fillet Face */
478       {
479         if(myOkRadius) {
480           if( myOkShape ) {
481             testResult = myGeomGUI->OnFilletGetSelected( myShape, myShapeIOR, myRadius, myShapeType, myLocalContextId, myUseLocalContext ) ;
482           }
483         }
484         if( !testResult ) {
485           myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_ABORT")) ;
486         } else {
487           myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_DONE")) ;
488         }  
489         /* Reset all arguments and local context to allow user a new selection ...*/
490         this->ResetStateOfDialog() ;
491         break ;
492       }
493     }
494
495   // accept();
496   return ;
497 }
498
499
500 //=================================================================================
501 // function : ClickOnCancel()
502 // purpose  :
503 //=================================================================================
504 void GeometryGUI_FilletDlg::ClickOnCancel()
505 {
506   myGeomGUI->EraseSimulationShape() ;
507   mySimulationTopoDs.Nullify() ;
508
509   disconnect( mySelection, 0, this, 0 );
510   myGeomGUI->ResetState() ;
511   if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
512     OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
513     myIC = v3d->getAISContext(); //    myIC = myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getViewerOCC()->getAISContext();
514     if(this->myUseLocalContext) {
515       myIC->CloseLocalContext(this->myLocalContextId) ;
516       this->myUseLocalContext = false ;
517       myGeomGUI->OnDisplayAll(true) ;
518     }
519   }
520   reject() ;
521   return ;
522 }
523
524 //=================================================================================
525 // function : ClickOnOk()
526 // purpose  :
527 //=================================================================================
528 void GeometryGUI_FilletDlg::ClickOnOk()
529 {
530   this->ClickOnApply() ;
531   this->ClickOnCancel() ;
532   return ;
533 }
534
535
536 //=================================================================================
537 // function : LineEditReturnPressed()
538 // purpose  :
539 //=================================================================================
540 void GeometryGUI_FilletDlg::LineEditReturnPressed()
541 {
542   QLineEdit* send = (QLineEdit*)sender();  
543   if( send == LineEditC1A1 )
544     myEditCurrentArgument = LineEditC1A1 ;
545   else if ( send == LineEditC2A1 )
546     myEditCurrentArgument = LineEditC2A1 ; 
547   else if ( send == LineEditC3A1 )
548     myEditCurrentArgument = LineEditC3A1 ; 
549   else
550     return ;
551   
552   /* User name of object input management                          */
553   /* If successfull the selection is changed and signal emitted... */
554   /* so SelectionIntoArgument() is automatically called.           */
555   const QString objectUserName = myEditCurrentArgument->text() ;
556   QWidget* thisWidget = (QWidget*)this ;
557   if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
558     myEditCurrentArgument->setText( objectUserName ) ;
559   }
560   return ;
561 }
562
563
564
565 //=================================================================================
566 // function : SelectionIntoArgument()
567 // purpose  : Called when selection has changed
568 //=================================================================================
569 void GeometryGUI_FilletDlg::SelectionIntoArgument()
570 {
571    myGeomGUI->EraseSimulationShape() ; 
572    mySimulationTopoDs.Nullify() ;
573
574   /* Reset all arguments and local context when selection as changed */
575   this->ResetStateOfDialog() ;
576
577   /* Future name of argument */
578   QString aString = "";
579
580   int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
581   if ( nbSel == 1 ) {
582
583     TopoDS_Shape S ;
584     Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
585     
586     if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
587       return ;
588    
589     if( !IO->hasEntry() ) {
590       myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY")) ;
591       return ;
592     }
593         
594     if ( !S.IsNull() &&  S.ShapeType() <= 2 ) {
595       if ( IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
596         Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IO );
597         myShapeIOR = GIObject->getIOR(); /* the Geom IOR string of selection */
598         myEditCurrentArgument->setText(aString) ;
599         myShape = S ;
600         myOkShape = true ;
601       }
602       
603       if ( IO->hasEntry() ) {
604         SALOMEDS::Study_var aStudy = myGeomGUI->GetActiveStudy()->getStudyDocument();
605         SALOMEDS::SObject_var obj = aStudy->FindObjectID( IO->getEntry() );
606         SALOMEDS::GenericAttribute_var anAttr;
607         SALOMEDS::AttributeIOR_var     anIOR;
608         if ( !obj->_is_nil() ) {
609           if (obj->FindAttribute(anAttr, "AttributeIOR")) {
610             anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
611             myShapeIOR = anIOR->Value();
612             myOkShape = true ;
613             myShape = S ;
614             myEditCurrentArgument->setText(aString) ;
615           }
616         }
617       }
618     }
619
620     MakePreview();
621         
622   } else 
623     return;
624   
625   if( myOkShape && myShapeType!=-1 && myConstructorId != 0 ) {
626     /* local context is defined into the method */
627     myGeomGUI->PrepareSubShapeSelection( this->myShapeType, this->myLocalContextId ) ;  
628     myUseLocalContext = true ;
629     myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_SELECT_EDGE")) ;
630   }
631 }
632
633
634
635 //=================================================================================
636 // function : SetEditCurrentArgument()
637 // purpose  :
638 //=================================================================================
639 void GeometryGUI_FilletDlg::SetEditCurrentArgument()
640 {
641   QPushButton* send = (QPushButton*)sender();  
642
643   switch (myConstructorId)
644     {
645     case 0:
646       { 
647         if(send == SelectButtonC1A1) {
648           LineEditC1A1->setFocus() ;
649           myEditCurrentArgument = LineEditC1A1;
650           SelectionIntoArgument() ;
651         }
652         break;
653       }
654
655     case 1:
656       { 
657         if(send ==SelectButtonC2A1 ) {
658           LineEditC2A1->setFocus() ;
659           myEditCurrentArgument = LineEditC2A1;
660           SelectionIntoArgument() ;
661         }
662         break;
663       }
664     
665     case 2:
666       {
667         if(send ==SelectButtonC3A1 ) {
668           LineEditC3A1->setFocus() ;
669           myEditCurrentArgument = LineEditC3A1;
670           SelectionIntoArgument() ;
671         }
672         break;
673       }
674     }
675   return ;
676 }
677
678 //=================================================================================
679 // function : ValueChangedInSpinBox()
680 // purpose  :
681 //=================================================================================
682 void GeometryGUI_FilletDlg::ValueChangedInSpinBox( double newValue )
683 {
684   myGeomGUI->EraseSimulationShape() ; 
685   mySimulationTopoDs.Nullify() ;
686
687   myRadius = newValue ;
688   myOkRadius = true ;
689
690   MakePreview();
691 }
692
693 //=================================================================================
694 // function : DeactivateActiveDialog()
695 // purpose  :
696 //=================================================================================
697 void GeometryGUI_FilletDlg::DeactivateActiveDialog()
698 {
699   if ( GroupConstructors->isEnabled() ) {
700     this->ResetStateOfDialog() ;
701     GroupConstructors->setEnabled(false) ;
702     GroupC1->setEnabled(false) ;
703     GroupC2->setEnabled(false) ;
704     GroupC3->setEnabled(false) ;
705     GroupButtons->setEnabled(false) ;
706     disconnect( mySelection, 0, this, 0 );
707     myGeomGUI->ResetState() ;    
708     myGeomGUI->SetActiveDialogBox(0) ;
709     myGeomGUI->OnDisplayAll(true) ;
710   }
711   return ;
712 }
713
714
715 //=================================================================================
716 // function : ActivateThisDialog()
717 // purpose  :
718 //=================================================================================
719 void GeometryGUI_FilletDlg::ActivateThisDialog()
720 {
721   /* Emit a signal to deactivate the active dialog */
722   myGeomGUI->EmitSignalDeactivateDialog() ; 
723   
724   GroupConstructors->setEnabled(true) ;
725   GroupC1->setEnabled(true) ;
726   GroupC2->setEnabled(true) ;
727   GroupC3->setEnabled(true) ;
728   GroupButtons->setEnabled(true) ;
729   connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
730   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
731
732   if( !mySimulationTopoDs.IsNull() )
733     myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
734   return ;
735 }
736
737
738 //=================================================================================
739 // function : enterEvent()
740 // purpose  :
741 //=================================================================================
742 void GeometryGUI_FilletDlg::enterEvent( QEvent* e)
743 {
744   if ( GroupConstructors->isEnabled() )
745     return ;  
746   ActivateThisDialog() ;
747   return ;
748 }
749
750
751 //=================================================================================
752 // function : closeEvent()
753 // purpose  :
754 //=================================================================================
755 void GeometryGUI_FilletDlg::closeEvent( QCloseEvent* e )
756
757   /* same than click on cancel button */
758   this->ClickOnCancel() ;
759   return ;
760 }
761
762
763 //=================================================================================
764 // function : ResetStateOfDialog()
765 // purpose  :
766 //=================================================================================
767 void GeometryGUI_FilletDlg::ResetStateOfDialog()
768 {
769   this->myOkShape = false ;
770   this->myEditCurrentArgument->setText("") ;
771
772   /* Close its local contact if opened */
773   if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
774     OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
775     myIC = v3d->getAISContext(); //    myIC = myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getViewerOCC()->getAISContext();
776     if(this->myUseLocalContext) {
777       myIC->CloseLocalContext(this->myLocalContextId) ;
778       this->myUseLocalContext = false ;
779       myGeomGUI->OnDisplayAll(true) ;
780     }
781   }
782   return ;
783 }
784
785
786 void GeometryGUI_FilletDlg::MakePreview()
787 {
788   TopoDS_Shape tds ;
789   try
790   {
791   BRepFilletAPI_MakeFillet fill(myShape);
792   switch (myConstructorId)
793     {
794     case 0: /* Fillet All */
795       {
796         TopExp_Explorer Exp ( myShape, TopAbs_EDGE );
797         for (Exp; Exp.More(); Exp.Next()) 
798           {
799             TopoDS_Edge E =TopoDS::Edge(Exp.Current());
800             fill.Add(E);
801           }
802         for (int i = 1;i<=fill.NbContours();i++) 
803           fill.SetRadius(myRadius,i);
804         
805         tds = fill.Shape();
806       break;
807       }
808 //    case 1: /* Fillet edges */
809 //    case 2: /* Fillet Faces */
810     }
811    if (!tds.IsNull()) 
812     {
813       mySimulationTopoDs = tds;
814       myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ; 
815     }
816   }  
817   catch(Standard_Failure)
818     {
819       myGeomGUI->EraseSimulationShape() ; 
820       mySimulationTopoDs.Nullify() ;
821     }
822 }