]> SALOME platform Git repositories - modules/geom.git/blob - src/OperationGUI/OperationGUI_ChamferDlg.cxx
Salome HOME
Remove some methods of GEOMBase_Helper (IObjectCount(), firstIObject(), lastIObject...
[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 // function : SelectionIntoArgument()
353 // purpose  : Called when selection has changed
354 //=================================================================================
355 void OperationGUI_ChamferDlg::SelectionIntoArgument()
356 {
357   erasePreview();
358   myEditCurrentArgument->setText("");
359
360   // Get index of current selection focus
361   int aCurrFocus = -1;
362   QMap< int, QLineEdit* >::iterator anIter;
363   for ( anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter ) {
364     if ( myEditCurrentArgument == anIter.value() ) {
365       aCurrFocus = anIter.key();
366       break;
367     }
368   }
369
370   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
371   SALOME_ListIO aSelList;
372   aSelMgr->selectedObjects(aSelList);
373
374   // If selection of main object is activated
375   if (aCurrFocus == MainObj1 || aCurrFocus == MainObj2 || aCurrFocus == MainObj3 || aCurrFocus == MainObj4)
376   {
377     if (aSelList.Extent() == 1) {
378       Standard_Boolean aResult = Standard_False;
379       GEOM::GEOM_Object_var anObj =
380         GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
381
382       if ( aResult && !anObj->_is_nil() ) {
383         myShape = anObj;
384         mySelName[ aCurrFocus ]->setText( GEOMBase::GetName( anObj ) );
385         displayPreview();
386         enableWidgets();
387         return;
388       }
389     }
390
391     myShape = GEOM::GEOM_Object::_nil();
392     enableWidgets();
393   }
394   // If face selection of second tab is activated
395   else if (aCurrFocus == Face1 || aCurrFocus == Face2)
396   {
397     if (aSelList.Extent() == 1) {
398       Standard_Boolean aResult = Standard_False;
399       GEOM::GEOM_Object_var anObj =
400         GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
401
402       if ( aResult && !anObj->_is_nil() ) {
403          TColStd_IndexedMapOfInteger anIndexes;
404          aSelMgr->GetIndexes(aSelList.First(), anIndexes);
405
406          if (anIndexes.Extent() == 1) {
407             int anIndex = anIndexes(1);
408             QString aFaceName = QString( GEOMBase::GetName( anObj ) ) + ":%1";
409             myEditCurrentArgument->setText( aFaceName.arg( anIndex ) );
410             myFace[ aCurrFocus ] = anIndex;
411             displayPreview();
412             return;
413          }
414       }
415     }
416
417     myFace[ aCurrFocus ] = -1;
418   }
419   // If face selection of third or fourth tab is activated
420   else if (aCurrFocus == Faces || aCurrFocus == Edges) {
421     if (aSelList.Extent() == 1) {
422       Standard_Boolean aResult = Standard_False;
423       GEOM::GEOM_Object_var anObj =
424         GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
425
426       if ( aResult && !anObj->_is_nil() ) {
427         TColStd_IndexedMapOfInteger anIndexes;
428         aSelMgr->GetIndexes(aSelList.First(), anIndexes);
429         
430         if (anIndexes.Extent() > 0) {
431           QString aName;
432           if (anIndexes.Extent() == 1) {
433             int anIndex = anIndexes(1);
434             
435             aName = QString( GEOMBase::GetName( anObj ) ) + QString( ":%1" ).arg( anIndex );
436           }
437           else {
438             aName = tr( "GEOM_MEN_POPUP_NAME" ).arg( anIndexes.Extent() );
439           }
440           
441           myEditCurrentArgument->setText( aName );
442           int aConstructorId = getConstructorId();
443           if ( aConstructorId == 2)
444             myFaces = anIndexes;
445           else if ( aConstructorId == 3 )
446             myEdges = anIndexes;
447              
448           displayPreview();
449           return;
450         }
451       }
452     }
453     myFaces.Clear();
454     myEdges.Clear();
455   }
456 }
457
458
459 //=================================================================================
460 // function : LineEditReturnPressed()
461 // purpose  :
462 //=================================================================================
463 void OperationGUI_ChamferDlg::LineEditReturnPressed()
464 {
465   QLineEdit* aSender = ( QLineEdit* )sender();
466
467   QMap< int, QLineEdit* >::iterator anIterLE;
468   for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
469     if ( anIterLE.value() == aSender )
470       myEditCurrentArgument = anIterLE.value();
471
472   GEOMBase_Skeleton::LineEditReturnPressed();
473 }
474
475
476 //=================================================================================
477 // function : RadioButtonPressed()
478 // purpose  :
479 //=================================================================================
480 void OperationGUI_ChamferDlg::RadioButtonPressed()
481 {
482   const QObject* s = sender();
483   bool flag = s == myRadioButton[ RadioButton21 ] || 
484               s == myRadioButton[ RadioButton31 ] ||
485               s == myRadioButton[ RadioButton41 ];
486
487   myRadioButton[ RadioButton21 ]->blockSignals( true );
488   myRadioButton[ RadioButton22 ]->blockSignals( true );
489   myRadioButton[ RadioButton31 ]->blockSignals( true );
490   myRadioButton[ RadioButton32 ]->blockSignals( true );
491   myRadioButton[ RadioButton41 ]->blockSignals( true );
492   myRadioButton[ RadioButton42 ]->blockSignals( true );
493
494   myRadioButton[ RadioButton21 ]->setChecked( flag );
495   myRadioButton[ RadioButton31 ]->setChecked( flag );
496   myRadioButton[ RadioButton41 ]->setChecked( flag );
497   myRadioButton[ RadioButton22 ]->setChecked( !flag );
498   myRadioButton[ RadioButton32 ]->setChecked( !flag );
499   myRadioButton[ RadioButton42 ]->setChecked( !flag );
500   mySpinBox[ SpinBox21 ]->setEnabled( flag );
501   mySpinBox[ SpinBox22 ]->setEnabled( flag ); 
502   mySpinBox[ SpinBox31 ]->setEnabled( flag ); 
503   mySpinBox[ SpinBox32 ]->setEnabled( flag ); 
504   mySpinBox[ SpinBox41 ]->setEnabled( flag ); 
505   mySpinBox[ SpinBox42 ]->setEnabled( flag );
506   mySpinBox[ SpinBox23 ]->setEnabled( !flag );
507   mySpinBox[ SpinBox24 ]->setEnabled( !flag ); 
508   mySpinBox[ SpinBox33 ]->setEnabled( !flag ); 
509   mySpinBox[ SpinBox34 ]->setEnabled( !flag ); 
510   mySpinBox[ SpinBox43 ]->setEnabled( !flag ); 
511   mySpinBox[ SpinBox44 ]->setEnabled( !flag );
512
513   myRadioButton[ RadioButton21 ]->blockSignals( false );
514   myRadioButton[ RadioButton22 ]->blockSignals( false );
515   myRadioButton[ RadioButton31 ]->blockSignals( false );
516   myRadioButton[ RadioButton32 ]->blockSignals( false );
517   myRadioButton[ RadioButton41 ]->blockSignals( false );
518   myRadioButton[ RadioButton42 ]->blockSignals( false );
519
520   displayPreview();
521 }
522
523
524 //=================================================================================
525 // function : SetEditCurrentArgument()
526 // purpose  :
527 //=================================================================================
528 void OperationGUI_ChamferDlg::SetEditCurrentArgument()
529 {
530   QPushButton* aSender = ( QPushButton* )sender();
531
532   QMap< int, QPushButton* >::iterator anIter;
533   for ( anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter ) {
534     if ( anIter.value() == aSender ) {
535       mySelName[ anIter.key() ]->setFocus();
536       myEditCurrentArgument = mySelName[ anIter.key() ];
537     }
538   }
539
540   activateSelection();
541 }
542
543
544 //=================================================================================
545 // function : ActivateThisDialog()
546 // purpose  :
547 //=================================================================================
548 void OperationGUI_ChamferDlg::ActivateThisDialog()
549 {
550   GEOMBase_Skeleton::ActivateThisDialog();
551
552   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
553            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
554
555   activateSelection();
556   displayPreview();
557 }
558
559
560 //=================================================================================
561 // function : enterEvent()
562 // purpose  :
563 //=================================================================================
564 void OperationGUI_ChamferDlg::enterEvent( QEvent* )
565 {
566   if ( !mainFrame()->GroupConstructors->isEnabled() )
567     this->ActivateThisDialog();
568 }
569
570
571 //=================================================================================
572 // function : ValueChangedInSpinBox()
573 // purpose  :
574 //=================================================================================
575 void OperationGUI_ChamferDlg::ValueChangedInSpinBox( double )
576 {
577   displayPreview();
578 }
579
580
581 //=================================================================================
582 // function : createSelWg()
583 // purpose  :
584 //=================================================================================
585 void OperationGUI_ChamferDlg::createSelWg( const QString& theLbl,
586                                            QPixmap&       thePix,
587                                            QWidget*       theParent,
588                                            QGridLayout*   theLayout,
589                                            const int      theId )
590 {
591   QLabel* lab = new QLabel( theLbl, theParent );
592   mySelBtn[ theId ] = new QPushButton( theParent );
593   mySelBtn[ theId ]->setIcon( thePix );
594   mySelName[ theId ] = new QLineEdit( theParent );
595   mySelName[ theId ]->setReadOnly( true );
596   int row = theLayout->rowCount();
597   theLayout->addWidget( lab,                row, 0 );
598   theLayout->addWidget( mySelBtn[ theId ],  row, 1 );
599   theLayout->addWidget( mySelName[ theId ], row, 2, 1, 4 ); // take into account createRadioWg()
600 }
601
602 //=================================================================================
603 // function : createRadioWg()
604 // purpose  :
605 //=================================================================================
606 void OperationGUI_ChamferDlg::createRadioWg( const QString& theLbl1, 
607                                              const QString& theLbl2, 
608                                              QWidget*       theParent, 
609                                              QGridLayout*   theLayout, 
610                                              const int      theRbId,
611                                              const int      theSpin1Id,
612                                              const int      theSpin2Id )
613 {
614   myRadioButton[ theRbId ] = new QRadioButton( theParent );
615   QLabel* lab1 = new QLabel( theLbl1, theParent ); 
616   QLabel* lab2 = new QLabel( theLbl2, theParent ); 
617   mySpinBox[ theSpin1Id ]  = new QDoubleSpinBox( theParent );
618   mySpinBox[ theSpin2Id ]  = new QDoubleSpinBox( theParent );
619   int row = theLayout->rowCount();
620   theLayout->addWidget( myRadioButton[ theRbId ], row, 0 );
621   theLayout->addWidget( lab1,                     row, 2 );
622   theLayout->addWidget( mySpinBox[ theSpin1Id ],  row, 3 );
623   theLayout->addWidget( lab2,                     row, 4 );
624   theLayout->addWidget( mySpinBox[ theSpin2Id ],  row, 5 );
625 }
626
627 //=================================================================================
628 // function : reset()
629 // purpose  :
630 //=================================================================================
631 void OperationGUI_ChamferDlg::reset()
632 {
633   // Set Initial values of spinboxes
634   QMap< int, QDoubleSpinBox* >::iterator anIter;
635   for ( anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter )
636     anIter.value()->setValue( 5 );
637
638   // clear line edits
639   QMap< int, QLineEdit* >::iterator anIterLE;
640   for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
641     anIterLE.value()->setText( "" );
642
643   // constructor id
644   int aConstructorId = getConstructorId();
645
646   if      ( aConstructorId == 0 ) myEditCurrentArgument = mySelName[ MainObj1 ];
647   else if ( aConstructorId == 1 ) myEditCurrentArgument = mySelName[ MainObj2 ];
648   else if ( aConstructorId == 2 ) myEditCurrentArgument = mySelName[ MainObj3 ];
649   else                            myEditCurrentArgument = mySelName[ MainObj4 ];
650
651   myShape = GEOM::GEOM_Object::_nil();
652
653   myFaces.Clear();
654   myEdges.Clear();
655   myFace[ Face1 ] = -1;
656   myFace[ Face2 ] = -1;
657
658   erasePreview( true );
659
660   activateSelection();
661
662   enableWidgets();
663 }
664
665 //=================================================================================
666 // function : activateSelection
667 // purpose  : Activate selection in accordance with myEditCurrentArgument
668 //=================================================================================
669 void OperationGUI_ChamferDlg::activateSelection()
670 {
671   if (  !myShape->_is_nil() &&
672        ( myEditCurrentArgument == mySelName[ Face1 ] ||
673          myEditCurrentArgument == mySelName[ Face2 ] ||
674          myEditCurrentArgument == mySelName[ Faces ] ) ) {
675     localSelection( myShape, TopAbs_FACE );
676   }
677   else if ( !myShape->_is_nil() && myEditCurrentArgument == mySelName[ Edges ] ) {
678     localSelection( myShape, TopAbs_EDGE );
679   }
680   else {
681     TColStd_MapOfInteger aMap;
682     aMap.Add( GEOM_SHELL );
683     aMap.Add( GEOM_SOLID );
684     aMap.Add( GEOM_COMPOUND );
685     globalSelection( aMap );
686   }
687
688   SelectionIntoArgument();
689 }
690
691 //=================================================================================
692 // function : enableWidgets
693 // purpose  : Enable widgets of faces in accordance with value of main object
694 //=================================================================================
695 void OperationGUI_ChamferDlg::enableWidgets()
696 {
697   int anId = getConstructorId();
698
699   bool toEnable = !myShape->_is_nil();
700   
701   if ( anId == 1 )
702   {
703     mySelName[ Face1 ]->setEnabled( toEnable );
704     mySelName[ Face2 ]->setEnabled( toEnable );
705     mySelBtn[ Face1 ]->setEnabled( toEnable );
706     mySelBtn[ Face2 ]->setEnabled( toEnable );
707
708     if ( !toEnable )
709     {
710       mySelName[ Face1 ]->setText( "" );
711       mySelName[ Face2 ]->setText( "" );
712       myFace[ Face1 ] = -1;
713       myFace[ Face2 ] = -1;
714     }
715   }
716   else if ( anId == 2 )
717   {
718     mySelName[ Faces ]->setEnabled( toEnable );
719     if ( !toEnable ) {
720       mySelName[ Faces ]->setText( "" );
721       myFaces = -1;
722     }
723   }
724   else if ( anId == 3 ) {
725     mySelName[ Edges ]->setEnabled( toEnable );
726     
727     if ( !toEnable ) {
728       mySelName[ Edges ]->setText( "" );
729       myEdges = -1;
730     }
731   }
732 }
733
734 //=================================================================================
735 // function : createOperation
736 // purpose  :
737 //=================================================================================
738 GEOM::GEOM_IOperations_ptr OperationGUI_ChamferDlg::createOperation()
739 {
740   return getGeomEngine()->GetILocalOperations( getStudyId() );
741 }
742
743 //=================================================================================
744 // function : ClickOnApply()
745 // purpose  : Verify validity of input data
746 //=================================================================================
747 bool OperationGUI_ChamferDlg::isValid( QString& )
748 {
749   switch ( getConstructorId() )
750   {
751     case 0: return !myShape->_is_nil();
752     case 1: return !myShape->_is_nil() && myFace[ Face1 ] > 0 && myFace[ Face2 ] > 0;
753     case 2: return !myShape->_is_nil() && myFaces.Extent() > 0;
754     case 3: return !myShape->_is_nil() && myEdges.Extent() > 0;
755     default: return false;
756   }
757 }
758
759 //=================================================================================
760 // function : execute
761 // purpose  :
762 //=================================================================================
763 bool OperationGUI_ChamferDlg::execute( ObjectList& objects )
764 {
765   GEOM::GEOM_Object_var anObj;
766   bool flag = ( myRadioButton[ RadioButton21 ]->isChecked() &&
767                 myRadioButton[ RadioButton31 ]->isChecked() &&
768                 myRadioButton[ RadioButton41 ]->isChecked() );
769
770   int anId = getConstructorId();
771   if ( anId == 0 ) {
772     anObj = GEOM::GEOM_ILocalOperations::_narrow(
773       getOperation() )->MakeChamferAll( myShape,
774                                         mySpinBox[ SpinBox1 ]->value() );
775   }
776   else if ( anId == 1 ) {
777     if ( flag ) {
778       anObj = GEOM::GEOM_ILocalOperations::_narrow( getOperation() )->
779         MakeChamferEdge( myShape,
780                          mySpinBox[ SpinBox21 ]->value(),
781                          mySpinBox[ SpinBox22 ]->value(),
782                          myFace[ Face1 ],
783                          myFace[ Face2 ] );
784     }
785     else {
786       anObj = GEOM::GEOM_ILocalOperations::_narrow( getOperation() )->
787         MakeChamferEdgeAD( myShape,
788                            mySpinBox[ SpinBox23 ]->value(),
789                            mySpinBox[ SpinBox24 ]->value() * PI180,
790                            myFace[ Face1 ],
791                            myFace[ Face2 ]);
792     }
793   }
794   else if ( anId == 2 )
795   {
796     GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
797     anArray->length( myFaces.Extent() );
798
799     for ( int i = 1, n = myFaces.Extent(); i <= n; i++ )
800       anArray[ i - 1 ] = myFaces( i );             
801     
802     if ( flag )
803     anObj = GEOM::GEOM_ILocalOperations::_narrow(
804       getOperation() )->MakeChamferFaces( myShape,
805                                           mySpinBox[ SpinBox31 ]->value(),
806                                           mySpinBox[ SpinBox32 ]->value(),
807                                           anArray );
808     else
809     anObj = GEOM::GEOM_ILocalOperations::_narrow(
810       getOperation() )->MakeChamferFacesAD( myShape,
811                                             mySpinBox[ SpinBox33 ]->value(),
812                                             mySpinBox[ SpinBox34 ]->value() * PI180,
813                                             anArray );
814   }
815   else if ( anId == 3 ) {
816     GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
817     anArray->length( myEdges.Extent() );
818     for ( int i = 1, n = myEdges.Extent(); i <= n; i++ )
819       anArray[ i - 1 ] = myEdges( i );             
820     if ( flag ) {
821       anObj = GEOM::GEOM_ILocalOperations::_narrow( getOperation() )->
822         MakeChamferEdges( myShape, mySpinBox[ SpinBox41 ]->value(),
823                           mySpinBox[ SpinBox42 ]->value(), anArray );
824     }
825     else {
826       anObj = GEOM::GEOM_ILocalOperations::_narrow( getOperation() )->
827         MakeChamferEdgesAD( myShape, mySpinBox[ SpinBox43 ]->value(),
828                             mySpinBox[ SpinBox44 ]->value() * PI180, anArray );
829     }
830   }
831
832   if ( !anObj->_is_nil() )
833     objects.push_back( anObj._retn() );
834
835   return true;
836 }