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