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