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