]> SALOME platform Git repositories - modules/geom.git/blob - src/OperationGUI/OperationGUI_ChamferDlg.cxx
Salome HOME
Update for bug IPAL19949.
[modules/geom.git] / src / OperationGUI / OperationGUI_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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : OperationGUI_ChamferDlg.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header$
28
29 #include "OperationGUI_ChamferDlg.h"
30 #include "DlgRef_SpinBox.h"
31
32 #include "SUIT_Desktop.h"
33 #include "SUIT_Session.h"
34 #include "SalomeApp_Application.h"
35 #include "LightApp_SelectionMgr.h"
36 #include "OCCViewer_ViewModel.h"
37
38 #include <TColStd_MapOfInteger.hxx>
39
40 #include <qlabel.h>
41 #include "qpixmap.h"
42 #include <list>
43
44 #include "GEOMImpl_Types.hxx"
45
46 //=================================================================================
47 // class    : OperationGUI_ChamferDlg()
48 // purpose  : Constructs a OperationGUI_ChamferDlg which is a child of 'parent', with the
49 //            name 'name' and widget flags set to 'f'.
50 //            The dialog will by default be modeless, unless you set 'modal' to
51 //            TRUE to construct a modal dialog.
52 //=================================================================================
53 OperationGUI_ChamferDlg::OperationGUI_ChamferDlg(GeometryGUI* theGeometryGUI, QWidget* parent)
54   : GEOMBase_Skeleton(theGeometryGUI, parent, "ChamferDlg", false,
55                       WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
56 {
57   myConstructorId = -1;
58
59   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_ALL")));
60   QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_EDGE_FROM_FACE")));
61   QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_FACE")));
62   QPixmap image4(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_EDGE")));
63   QPixmap iconSelect(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
64
65   setCaption( tr( "GEOM_CHAMFER_TITLE" ) );
66
67   GroupConstructors->setTitle( tr( "GEOM_CHAMFER" ) );
68
69   RadioButton1->setPixmap( image1 );
70   RadioButton2->setPixmap( image2 );
71   RadioButton3->setPixmap( image3 );
72   RadioButton4->show();
73   RadioButton4->setPixmap( image4 );
74
75   // Create first group
76
77   myGrp1 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_ALL" ), this );
78
79   QGroupBox* aSelGrp1 = new QGroupBox( 3, Qt::Horizontal, myGrp1 );
80   aSelGrp1->setFrameStyle( QFrame::NoFrame );
81   aSelGrp1->setInsideMargin( 0 );
82
83   createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp1, MainObj1 );
84
85   QGroupBox* aSpinGrp = new QGroupBox( 1, Qt::Vertical, myGrp1 );
86   aSpinGrp->setFrameStyle( QFrame::NoFrame );
87   aSpinGrp->setInsideMargin( 0 );
88   
89   new QLabel( tr( "D" ), aSpinGrp );
90   mySpinBox[ SpinBox1 ] = new DlgRef_SpinBox( aSpinGrp );
91
92   ( new QFrame( myGrp1 ) )->setSizePolicy(
93     QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
94
95   // Create second group
96
97   myGrp2 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_EDGES" ), this );
98
99   QGroupBox* aSelGrp2 = new QGroupBox( 3, Qt::Horizontal, myGrp2 );
100   aSelGrp2->setFrameStyle( QFrame::NoFrame );
101   aSelGrp2->setInsideMargin( 0 );
102
103   createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp2, MainObj2 );
104   createSelWg( tr( "FACE_1" ), iconSelect, aSelGrp2, Face1 );
105   createSelWg( tr( "FACE_2" ), iconSelect, aSelGrp2, Face2 );
106
107   QGroupBox* aSpinGrp1 = new QGroupBox( 1, Qt::Vertical, myGrp2 );
108   aSpinGrp1->setFrameStyle( QFrame::NoFrame );
109   aSpinGrp1->setInsideMargin( 0 );
110   
111   myRadioButton[ RadioButton21] = new QRadioButton( aSpinGrp1 );
112
113   new QLabel( tr( "GEOM_D1" ), aSpinGrp1 );
114   mySpinBox[ SpinBox21 ] = new DlgRef_SpinBox( aSpinGrp1 );
115
116   new QLabel( tr( "GEOM_D2" ), aSpinGrp1 );
117   mySpinBox[ SpinBox22 ] = new DlgRef_SpinBox( aSpinGrp1 );
118
119   QGroupBox* aSpinGrp2 = new QGroupBox( 1, Qt::Vertical, myGrp2 );
120   aSpinGrp2->setFrameStyle( QFrame::NoFrame );
121   aSpinGrp2->setInsideMargin( 0 );
122
123   myRadioButton[ RadioButton22] = new QRadioButton( aSpinGrp2 );
124
125   new QLabel( tr( "GEOM_D" ), aSpinGrp2 );
126   mySpinBox[ SpinBox23 ] = new DlgRef_SpinBox( aSpinGrp2 );
127
128   new QLabel( tr( "GEOM_ANGLE" ), aSpinGrp2 );
129   mySpinBox[ SpinBox24 ] = new DlgRef_SpinBox( aSpinGrp2 );
130
131  ( new QLabel( myGrp2 ) )->setSizePolicy(
132         QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
133
134   // Create third group
135
136   myGrp3 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_FACES" ), this );
137
138   QGroupBox* aSelGrp3 = new QGroupBox( 3, Qt::Horizontal, myGrp3 );
139   aSelGrp3->setFrameStyle( QFrame::NoFrame );
140   aSelGrp3->setInsideMargin( 0 );
141
142   createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp3, MainObj3 );
143   createSelWg( tr( "SELECTED_FACES" ), iconSelect, aSelGrp3, Faces );
144
145   aSpinGrp1 = new QGroupBox( 1, Qt::Vertical, myGrp3 );
146   aSpinGrp1->setFrameStyle( QFrame::NoFrame );
147   aSpinGrp1->setInsideMargin( 0 );
148
149   myRadioButton[ RadioButton31] = new QRadioButton( aSpinGrp1 );
150
151   new QLabel( tr( "GEOM_D1" ), aSpinGrp1 );
152   mySpinBox[ SpinBox31 ] = new DlgRef_SpinBox( aSpinGrp1 );
153
154   new QLabel( tr( "GEOM_D2" ), aSpinGrp1 );
155   mySpinBox[ SpinBox32 ] = new DlgRef_SpinBox( aSpinGrp1 );
156
157   aSpinGrp2 = new QGroupBox( 1, Qt::Vertical, myGrp3 );
158   aSpinGrp2->setFrameStyle( QFrame::NoFrame );
159   aSpinGrp2->setInsideMargin( 0 );
160
161   myRadioButton[ RadioButton32] = new QRadioButton( aSpinGrp2 );
162
163   new QLabel( tr( "GEOM_D" ), aSpinGrp2 );
164   mySpinBox[ SpinBox33 ] = new DlgRef_SpinBox( aSpinGrp2 );
165
166   new QLabel( tr( "GEOM_ANGLE" ), aSpinGrp2 );
167   mySpinBox[ SpinBox34 ] = new DlgRef_SpinBox( aSpinGrp2 );
168
169   ( new QLabel( myGrp3 ) )->setSizePolicy(
170         QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
171
172   // Create fourth group
173
174   myGrp4 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_EDGE" ), this );
175
176   QGroupBox* aSelGrp4 = new QGroupBox( 3, Qt::Horizontal, myGrp4 );
177   aSelGrp4->setFrameStyle( QFrame::NoFrame );
178   aSelGrp4->setInsideMargin( 0 );
179
180   createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp4, MainObj4 );
181   createSelWg( tr( "SELECTED_EDGE" ), iconSelect, aSelGrp4, Edges );
182
183   aSpinGrp1 = new QGroupBox( 1, Qt::Vertical, myGrp4 );
184   aSpinGrp1->setFrameStyle( QFrame::NoFrame );
185   aSpinGrp1->setInsideMargin( 0 );
186
187   myRadioButton[ RadioButton41] = new QRadioButton( aSpinGrp1 );
188
189   new QLabel( tr( "GEOM_D1" ), aSpinGrp1 );
190   mySpinBox[ SpinBox41 ] = new DlgRef_SpinBox( aSpinGrp1 );
191
192   new QLabel( tr( "GEOM_D2" ), aSpinGrp1 );
193   mySpinBox[ SpinBox42 ] = new DlgRef_SpinBox( aSpinGrp1 );
194
195   aSpinGrp2 = new QGroupBox( 1, Qt::Vertical, myGrp4 );
196   aSpinGrp2->setFrameStyle( QFrame::NoFrame );
197   aSpinGrp2->setInsideMargin( 0 );
198
199   myRadioButton[ RadioButton42] = new QRadioButton( aSpinGrp2 );
200
201   new QLabel( tr( "GEOM_D" ), aSpinGrp2 );
202   mySpinBox[ SpinBox43 ] = new DlgRef_SpinBox( aSpinGrp2 );
203
204   new QLabel( tr( "GEOM_ANGLE" ), aSpinGrp2 );
205   mySpinBox[ SpinBox44 ] = new DlgRef_SpinBox( aSpinGrp2 );
206
207   ( new QLabel( myGrp4 ) )->setSizePolicy(
208     QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
209
210   // Add groups to layout
211
212   Layout1->addWidget( myGrp1, 2, 0 );
213   Layout1->addWidget( myGrp2, 2, 0 );
214   Layout1->addWidget( myGrp3, 2, 0 );
215   Layout1->addWidget( myGrp4, 2, 0 );
216
217   // Set range of spinboxes
218   
219   double SpecificStep = 10.0;
220   QMap< int, DlgRef_SpinBox* >::iterator anIter;
221   for ( anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter )
222     {
223       anIter.data()->RangeStepAndValidator( 0.001, COORD_MAX, SpecificStep, 3 );
224       if ( anIter.key() == SpinBox44 || anIter.key() == SpinBox34 || anIter.key() == SpinBox24 )
225            anIter.data()->RangeStepAndValidator( 0.001, 89.999, 5, 0 );
226     }
227
228   setHelpFileName("chamfer_operation_page.html");
229
230   /* Initialisations */
231   RadioButtonPressed();
232   Init();
233 }
234
235
236 //=================================================================================
237 // function : ~OperationGUI_ChamferDlg()
238 // purpose  : Destroys the object and frees any allocated resources
239 //=================================================================================
240 OperationGUI_ChamferDlg::~OperationGUI_ChamferDlg()
241 {
242 }
243
244
245 //=================================================================================
246 // function : Init()
247 // purpose  :
248 //=================================================================================
249 void OperationGUI_ChamferDlg::Init()
250 {
251   myConstructorId = -1;
252   reset();
253   RadioButton1->setChecked( true );
254   myEditCurrentArgument = mySelName[ MainObj1 ];
255
256   /* signals and slots connections */
257
258   // main buttons
259   connect( buttonOk   , SIGNAL( clicked() ), this, SLOT( ClickOnOk()    ) );
260   connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
261
262   // group box
263   connect( GroupConstructors, SIGNAL( clicked( int ) ),
264            this, SLOT( ConstructorsClicked( int ) ) );
265
266   // push buttons
267   QMap< int, QPushButton* >::iterator anIterBtn;
268   for ( anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn )
269     connect( anIterBtn.data(), SIGNAL( clicked() ),
270              this, SLOT( SetEditCurrentArgument() ) );
271
272   // line edits
273   QMap< int, QLineEdit* >::iterator anIterLE2;
274   for ( anIterLE2 = mySelName.begin(); anIterLE2 != mySelName.end(); ++anIterLE2 )
275     connect( anIterLE2.data(), SIGNAL( returnPressed() ),
276              this, SLOT( LineEditReturnPressed() ) );
277
278   // spin boxes
279   QMap< int, DlgRef_SpinBox* >::iterator anIterSpin;
280   for ( anIterSpin = mySpinBox.begin(); anIterSpin != mySpinBox.end(); ++anIterSpin )
281     connect( anIterSpin.data(), SIGNAL( valueChanged( double ) ),
282              this, SLOT( ValueChangedInSpinBox( double ) ) );
283
284   // radio buttons
285   QMap< int, QRadioButton* >::iterator anIterRadio;
286   for ( anIterRadio = myRadioButton.begin(); anIterRadio != myRadioButton.end(); ++anIterRadio )
287     connect( anIterRadio.data(), SIGNAL( clicked() ),
288              this, SLOT( RadioButtonPressed() ) );
289
290   // selection
291   connect(myGeomGUI->getApp()->selectionMgr(), 
292           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
293
294   initName( tr( "GEOM_CHAMFER" ) );
295
296   myGrp4->hide();
297   myGrp3->hide();
298   myGrp2->hide();
299   myGrp1->show();
300 }
301
302
303 //=================================================================================
304 // function : ConstructorsClicked()
305 // purpose  : Radio button management
306 //=================================================================================
307 void OperationGUI_ChamferDlg::ConstructorsClicked( int constructorId )
308 {
309    // Activate next widget
310   if (myGeomGUI->getApp()->desktop()->activeWindow()->getViewManager()->getType() 
311       != OCCViewer_Viewer::Type())
312   {
313     RadioButton1->setChecked( true );
314     return;
315   }
316
317   if (myConstructorId == constructorId)
318     return;
319
320   // Get values from previous widget
321   double D1 = 5, D2 = 5, D = 5, Angle = 5;
322   if ( myConstructorId == 0 )
323     D1 = D2 = mySpinBox[ SpinBox1 ]->GetValue();
324   else if ( myConstructorId == 1 )
325   {
326     D1 = mySpinBox[ SpinBox21 ]->GetValue();
327     D2 = mySpinBox[ SpinBox22 ]->GetValue();
328     D =  mySpinBox[ SpinBox23 ]->GetValue();
329     Angle = mySpinBox[ SpinBox24 ]->GetValue();
330   }
331   else if ( myConstructorId == 2 )
332   {
333     D1 = mySpinBox[ SpinBox31 ]->GetValue();
334     D2 = mySpinBox[ SpinBox32 ]->GetValue();
335     D =  mySpinBox[ SpinBox33 ]->GetValue();
336     Angle = mySpinBox[ SpinBox34 ]->GetValue();
337   }
338   else if ( myConstructorId == 3 )
339   {
340     D1 = mySpinBox[ SpinBox41 ]->GetValue();
341     D2 = mySpinBox[ SpinBox42 ]->GetValue();
342     D =  mySpinBox[ SpinBox43 ]->GetValue();
343     Angle = mySpinBox[ SpinBox44 ]->GetValue();
344   }
345
346   myConstructorId = constructorId;
347
348    switch ( constructorId )
349   {
350     case 0:
351         myGrp1->show();
352         myGrp2->hide();
353         myGrp3->hide();
354         myGrp4->hide();
355         mySpinBox[ SpinBox1 ]->SetValue( D1 );
356     break;
357     case 1:
358         myGrp1->hide();
359         myGrp2->show();
360         myGrp3->hide();
361         myGrp4->hide();
362         mySpinBox[ SpinBox21 ]->SetValue( D1 );
363         mySpinBox[ SpinBox22 ]->SetValue( D2 );
364         mySpinBox[ SpinBox23 ]->SetValue( D );
365         mySpinBox[ SpinBox24 ]->SetValue( Angle );
366     break;
367     case 2:
368         myGrp1->hide();
369         myGrp2->hide();
370         myGrp3->show();
371         myGrp4->hide();
372         mySpinBox[ SpinBox31 ]->SetValue( D1 );
373         mySpinBox[ SpinBox32 ]->SetValue( D2 );
374         mySpinBox[ SpinBox33 ]->SetValue( D );
375         mySpinBox[ SpinBox34 ]->SetValue( Angle );
376     break;
377         case 3:
378         myGrp1->hide();
379         myGrp2->hide();
380         myGrp3->hide();
381         myGrp4->show();
382         mySpinBox[ SpinBox41 ]->SetValue( D1 );
383         mySpinBox[ SpinBox42 ]->SetValue( D2 );        
384         mySpinBox[ SpinBox43 ]->SetValue( D );
385         mySpinBox[ SpinBox44 ]->SetValue( Angle );
386     break;
387     default:
388     break;
389   }
390
391   if      ( constructorId == 0 ) myEditCurrentArgument = mySelName[ MainObj1 ];
392   else if ( constructorId == 1 ) myEditCurrentArgument = mySelName[ MainObj2 ];
393   else if ( constructorId == 2 ) myEditCurrentArgument = mySelName[ MainObj3 ];
394   else                           myEditCurrentArgument = mySelName[ MainObj4 ];
395
396   activateSelection(); 
397   enableWidgets();
398   
399   if ( !myShape->_is_nil() )
400   {
401     myEditCurrentArgument->setText( GEOMBase::GetName( myShape ) );
402     GEOMBase_Skeleton::LineEditReturnPressed();
403   }
404   else
405     myEditCurrentArgument->setText( "" );
406
407   displayPreview();
408 }
409
410
411 //=================================================================================
412 // function : ClickOnOk()
413 // purpose  :
414 //=================================================================================
415 void OperationGUI_ChamferDlg::ClickOnOk()
416 {
417   if ( ClickOnApply() )
418     ClickOnCancel();
419 }
420
421 //=================================================================================
422 // function : ClickOnApply()
423 // purpose  :
424 //=================================================================================
425 bool OperationGUI_ChamferDlg::ClickOnApply()
426 {
427   if ( !onAccept() )
428     return false;
429
430   initName();
431   return true;
432 }
433
434 //=================================================================================
435 // function : SelectionIntoArgument()
436 // purpose  : Called when selection has changed
437 //=================================================================================
438 void OperationGUI_ChamferDlg::SelectionIntoArgument()
439 {
440   erasePreview();
441   myEditCurrentArgument->setText( "" );
442
443   // Get index of current selection focus
444   int aCurrFocus = -1;
445   QMap< int, QLineEdit* >::iterator anIter;
446   for ( anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter )
447     if ( myEditCurrentArgument == anIter.data() )
448     {
449       aCurrFocus = anIter.key();
450       break;
451     }
452
453   // If selection of main object is activated
454   if ( aCurrFocus == MainObj1 || aCurrFocus == MainObj2 || aCurrFocus == MainObj3 || aCurrFocus == MainObj4)
455   {
456     if ( IObjectCount() == 1 )
457     {
458       Standard_Boolean aResult = Standard_False;
459       GEOM::GEOM_Object_var anObj =
460         GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
461
462       if ( aResult && !anObj->_is_nil() )
463       {
464         myShape = anObj;
465         mySelName[ aCurrFocus ]->setText( GEOMBase::GetName( anObj ) );
466         displayPreview();
467         enableWidgets();
468         return;
469       }
470     }
471
472     myShape = GEOM::GEOM_Object::_nil();
473     enableWidgets();
474   }
475   // If face selection of second tab is activated
476   else if ( aCurrFocus == Face1 || aCurrFocus == Face2 )
477   {
478     if ( IObjectCount() == 1 )
479     {
480       Standard_Boolean aResult = Standard_False;
481       GEOM::GEOM_Object_var anObj =
482         GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
483
484       if ( aResult && !anObj->_is_nil() )
485       {
486          TColStd_IndexedMapOfInteger anIndexes;
487          ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
488
489          if ( anIndexes.Extent() == 1 )
490          {
491             int anIndex = anIndexes( 1 );
492             QString aFaceName = QString( GEOMBase::GetName( anObj ) ) + ":%1";
493             myEditCurrentArgument->setText( aFaceName.arg( anIndex ) );
494             myFace[ aCurrFocus ] = anIndex;
495             displayPreview();
496             return;
497          }
498       }
499     }
500
501     myFace[ aCurrFocus ] = -1;
502   }
503   // If face selection of third or fourth tab is activated
504   else if ( aCurrFocus == Faces  || aCurrFocus == Edges )
505   {
506     if ( IObjectCount() == 1 )
507     {
508       Standard_Boolean aResult = Standard_False;
509       GEOM::GEOM_Object_var anObj =
510         GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
511
512       if ( aResult && !anObj->_is_nil() )
513       {
514          TColStd_IndexedMapOfInteger anIndexes;
515          ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
516
517          if ( anIndexes.Extent() > 0 )
518          {
519            QString aName;
520            if ( anIndexes.Extent() == 1 )
521            {
522              int anIndex = anIndexes( 1 );
523
524              aName = QString( GEOMBase::GetName( anObj ) ) + QString( ":%1" ).arg( anIndex );
525            }
526            else
527              aName = tr( "GEOM_MEN_POPUP_NAME" ).arg( anIndexes.Extent() );
528
529            myEditCurrentArgument->setText( aName );
530            int aConstructorId = getConstructorId();
531            if ( aConstructorId == 2)
532              myFaces = anIndexes;
533            else if (aConstructorId == 3)
534              myEdges = anIndexes;
535              
536            displayPreview();
537            return;
538          }
539       }
540     }
541     myFaces.Clear();
542     myEdges.Clear();
543   }
544 }
545
546
547 //=================================================================================
548 // function : LineEditReturnPressed()
549 // purpose  :
550 //=================================================================================
551 void OperationGUI_ChamferDlg::LineEditReturnPressed()
552 {
553   QLineEdit* aSender = ( QLineEdit* )sender();
554
555   QMap< int, QLineEdit* >::iterator anIterLE;
556   for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
557     if ( anIterLE.data() == aSender )
558       myEditCurrentArgument = anIterLE.data();
559
560   GEOMBase_Skeleton::LineEditReturnPressed();
561 }
562
563 //=================================================================================
564 // function : RadioButtonPressed()
565 // purpose  :
566 //=================================================================================
567 void OperationGUI_ChamferDlg::RadioButtonPressed()
568 {
569   bool flag;
570   flag = ( myRadioButton[ RadioButton21 ]->isChecked() &&
571            myRadioButton[ RadioButton31 ]->isChecked() &&
572            myRadioButton[ RadioButton41 ]->isChecked() );
573     
574   myRadioButton[ RadioButton21 ]->setChecked(!flag);
575   myRadioButton[ RadioButton31 ]->setChecked(!flag);
576   myRadioButton[ RadioButton41 ]->setChecked(!flag);
577   myRadioButton[ RadioButton22 ]->setChecked(flag);
578   myRadioButton[ RadioButton32 ]->setChecked(flag);
579   myRadioButton[ RadioButton42 ]->setChecked(flag);
580   mySpinBox[ SpinBox21 ]->setDisabled(flag);
581   mySpinBox[ SpinBox22 ]->setDisabled(flag); 
582   mySpinBox[ SpinBox31 ]->setDisabled(flag); 
583   mySpinBox[ SpinBox32 ]->setDisabled(flag); 
584   mySpinBox[ SpinBox41 ]->setDisabled(flag); 
585   mySpinBox[ SpinBox42 ]->setDisabled(flag);
586   mySpinBox[ SpinBox23 ]->setDisabled(!flag);
587   mySpinBox[ SpinBox24 ]->setDisabled(!flag); 
588   mySpinBox[ SpinBox33 ]->setDisabled(!flag); 
589   mySpinBox[ SpinBox34 ]->setDisabled(!flag); 
590   mySpinBox[ SpinBox43 ]->setDisabled(!flag); 
591   mySpinBox[ SpinBox44 ]->setDisabled(!flag);
592   displayPreview();
593 }
594
595
596 //=================================================================================
597 // function : SetEditCurrentArgument()
598 // purpose  :
599 //=================================================================================
600 void OperationGUI_ChamferDlg::SetEditCurrentArgument()
601 {
602  QPushButton* aSender = ( QPushButton* )sender();
603
604   QMap< int, QPushButton* >::iterator anIter;
605   for ( anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter )
606     if ( anIter.data() == aSender )
607     {
608       mySelName[ anIter.key() ]->setFocus();
609       myEditCurrentArgument = mySelName[ anIter.key() ];
610     }
611
612   activateSelection();
613 }
614
615
616 //=================================================================================
617 // function : ActivateThisDialog()
618 // purpose  :
619 //=================================================================================
620 void OperationGUI_ChamferDlg::ActivateThisDialog()
621 {
622   GEOMBase_Skeleton::ActivateThisDialog();
623
624   connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
625            SIGNAL(currentSelectionChanged()), this, SLOT( SelectionIntoArgument() ) );
626
627   activateSelection();
628   displayPreview();
629 }
630
631
632 //=================================================================================
633 // function : enterEvent()
634 // purpose  :
635 //=================================================================================
636 void OperationGUI_ChamferDlg::enterEvent(QEvent* e)
637 {
638   if ( !GroupConstructors->isEnabled() )
639     this->ActivateThisDialog();
640 }
641
642
643 //=================================================================================
644 // function : ValueChangedInSpinBox()
645 // purpose  :
646 //=================================================================================
647 void OperationGUI_ChamferDlg::ValueChangedInSpinBox( double newValue )
648 {
649   displayPreview();
650 }
651
652
653 //=================================================================================
654 // function : createSelWg()
655 // purpose  :
656 //=================================================================================
657 void OperationGUI_ChamferDlg::createSelWg( const QString& theLbl,
658                                            QPixmap&       thePix,
659                                            QWidget*       theParent,
660                                            const int      theId )
661 {
662   new QLabel( theLbl, theParent );
663   mySelBtn[ theId ] = new QPushButton( theParent );
664   mySelBtn[ theId ]->setPixmap( thePix );
665   mySelName[ theId ] = new QLineEdit( theParent );
666   mySelName[ theId ]->setReadOnly( true );
667 }
668
669 //=================================================================================
670 // function : reset()
671 // purpose  :
672 //=================================================================================
673 void OperationGUI_ChamferDlg::reset()
674 {
675  // Set Initial values of spinboxes
676   QMap< int, DlgRef_SpinBox* >::iterator anIter;
677   for ( anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter )
678     anIter.data()->SetValue( 5 );
679
680   // clear line edits
681   QMap< int, QLineEdit* >::iterator anIterLE;
682   for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
683     anIterLE.data()->setText( "" );
684
685   // constructor id
686   int aConstructorId = getConstructorId();
687
688   if      ( aConstructorId == 0 ) myEditCurrentArgument = mySelName[ MainObj1 ];
689   else if ( aConstructorId == 1 ) myEditCurrentArgument = mySelName[ MainObj2 ];
690   else if ( aConstructorId == 2 ) myEditCurrentArgument = mySelName[ MainObj3 ];
691   else                            myEditCurrentArgument = mySelName[ MainObj4 ];
692
693   myShape = GEOM::GEOM_Object::_nil();
694
695   myFaces.Clear();
696   myEdges.Clear();
697   myFace[ Face1 ] = -1;
698   myFace[ Face2 ] = -1;
699
700   erasePreview( true );
701
702   activateSelection();
703
704   enableWidgets();
705 }
706
707 //=================================================================================
708 // function : getConstructorId()
709 // purpose  :
710 //=================================================================================
711 int OperationGUI_ChamferDlg::getConstructorId() const
712 {
713   return GroupConstructors->id( GroupConstructors->selected() );
714 }
715
716 //=================================================================================
717 // function : activateSelection
718 // purpose  : Activate selection in accordance with myEditCurrentArgument
719 //=================================================================================
720 void OperationGUI_ChamferDlg::activateSelection()
721 {
722   if (  !myShape->_is_nil() &&
723        ( myEditCurrentArgument == mySelName[ Face1 ] ||
724          myEditCurrentArgument == mySelName[ Face2 ] ||
725                  myEditCurrentArgument == mySelName[ Faces ] ) )
726     localSelection( myShape, TopAbs_FACE );
727   else if (!myShape->_is_nil() && myEditCurrentArgument == mySelName[ Edges ] )
728     localSelection( myShape, TopAbs_EDGE );
729   else
730   {
731     TColStd_MapOfInteger aMap;
732     aMap.Add( GEOM_SHELL );
733     aMap.Add( GEOM_SOLID );
734     aMap.Add( GEOM_COMPOUND );
735     globalSelection( aMap );
736   }
737
738   SelectionIntoArgument();
739 }
740
741 //=================================================================================
742 // function : enableWidgets
743 // purpose  : Enable widgets of faces in accordance with value of main object
744 //=================================================================================
745 void OperationGUI_ChamferDlg::enableWidgets()
746 {
747   int anId = getConstructorId();
748
749   bool toEnable = !myShape->_is_nil();
750   
751   if ( anId == 1 )
752   {
753     mySelName[ Face1 ]->setEnabled( toEnable );
754     mySelName[ Face2 ]->setEnabled( toEnable );
755     mySelBtn[ Face1 ]->setEnabled( toEnable );
756     mySelBtn[ Face2 ]->setEnabled( toEnable );
757
758     if ( !toEnable )
759     {
760       mySelName[ Face1 ]->setText( "" );
761       mySelName[ Face2 ]->setText( "" );
762       myFace[ Face1 ] = -1;
763       myFace[ Face2 ] = -1;
764     }
765   }
766   else if ( anId == 2 )
767   {
768     mySelName[ Faces ]->setEnabled( toEnable );
769     if ( !toEnable )
770         {
771           mySelName[ Faces ]->setText( "" );
772           myFaces = -1;
773         }
774   }
775   else if ( anId == 3 )
776   {
777     mySelName[ Edges ]->setEnabled( toEnable );
778
779     if ( !toEnable )
780         {
781           mySelName[ Edges ]->setText( "" );
782           myEdges = -1;
783         }
784   }
785 }
786
787 //=================================================================================
788 // function : createOperation
789 // purpose  :
790 //=================================================================================
791 GEOM::GEOM_IOperations_ptr OperationGUI_ChamferDlg::createOperation()
792 {
793   return getGeomEngine()->GetILocalOperations( getStudyId() );
794 }
795 //=================================================================================
796 // function : ClickOnApply()
797 // purpose  : Verify validity of input data
798 //=================================================================================
799 bool OperationGUI_ChamferDlg::isValid( QString& )
800 {
801   switch ( getConstructorId() )
802   {
803     case 0: return !myShape->_is_nil();
804     case 1: return !myShape->_is_nil() && myFace[ Face1 ] > 0 && myFace[ Face2 ] > 0;
805     case 2: return !myShape->_is_nil() && myFaces.Extent() > 0;
806     case 3: return !myShape->_is_nil() && myEdges.Extent() > 0;
807     default: return false;
808   }
809 }
810
811 //=================================================================================
812 // function : execute
813 // purpose  :
814 //=================================================================================
815 bool OperationGUI_ChamferDlg::execute( ObjectList& objects )
816 {
817   GEOM::GEOM_Object_var anObj;
818   bool flag = ( myRadioButton[ RadioButton21 ]->isChecked() &&
819                 myRadioButton[ RadioButton31 ]->isChecked() &&
820                 myRadioButton[ RadioButton41 ]->isChecked() );
821
822   int anId = getConstructorId();
823   if ( anId == 0 )
824     anObj = GEOM::GEOM_ILocalOperations::_narrow(
825       getOperation() )->MakeChamferAll( myShape,
826                                         mySpinBox[ SpinBox1 ]->GetValue() );
827   else if ( anId == 1 )
828     {
829       if ( flag )
830           anObj = GEOM::GEOM_ILocalOperations::_narrow(
831                   getOperation() )->MakeChamferEdge( myShape,
832                                                      mySpinBox[ SpinBox21 ]->GetValue(),
833                                                      mySpinBox[ SpinBox22 ]->GetValue(),
834                                                      myFace[ Face1 ],
835                                                      myFace[ Face2 ] );
836       else
837           anObj = GEOM::GEOM_ILocalOperations::_narrow(
838                   getOperation() )->MakeChamferEdgeAD( myShape,
839                                                        mySpinBox[ SpinBox23 ]->GetValue(),
840                                                        mySpinBox[ SpinBox24 ]->GetValue() * PI180,
841                                                        myFace[ Face1 ],
842                                                        myFace[ Face2 ]);
843     }
844   else if ( anId == 2 )
845   {
846     GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
847     anArray->length( myFaces.Extent() );
848     for ( int i = 1, n = myFaces.Extent(); i <= n; i++ )
849       anArray[ i - 1 ] = myFaces( i );
850     if ( flag )
851     anObj = GEOM::GEOM_ILocalOperations::_narrow(
852       getOperation() )->MakeChamferFaces( myShape,
853                                           mySpinBox[ SpinBox31 ]->GetValue(),
854                                           mySpinBox[ SpinBox32 ]->GetValue(),
855                                           anArray );
856     else
857     anObj = GEOM::GEOM_ILocalOperations::_narrow(
858       getOperation() )->MakeChamferFacesAD( myShape,
859                                             mySpinBox[ SpinBox33 ]->GetValue(),
860                                             mySpinBox[ SpinBox34 ]->GetValue() * PI180,
861                                             anArray );
862   }
863   else if ( anId == 3 )
864   {
865     GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
866     anArray->length( myEdges.Extent() );
867     for ( int i = 1, n = myEdges.Extent(); i <= n; i++ )
868       anArray[ i - 1 ] = myEdges( i );             
869     if ( flag )
870       anObj = GEOM::GEOM_ILocalOperations::_narrow(
871       getOperation() )->MakeChamferEdges( myShape, mySpinBox[ SpinBox41 ]->GetValue(),
872                                           mySpinBox[ SpinBox42 ]->GetValue(), anArray );
873     else
874       anObj = GEOM::GEOM_ILocalOperations::_narrow(
875       getOperation() )->MakeChamferEdgesAD( myShape, mySpinBox[ SpinBox43 ]->GetValue(),
876                                             mySpinBox[ SpinBox44 ]->GetValue() * PI180, anArray );
877   }
878
879   if ( !anObj->_is_nil() )
880     objects.push_back( anObj._retn() );
881
882   return true;
883 }