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