Salome HOME
GEOM: It should be forbidden creation of primitives with zero dimensions.
[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       if ( anIter.key() == SpinBox44 || anIter.key() == SpinBox34 || anIter.key() == SpinBox24 )
224            anIter.data()->RangeStepAndValidator( 0.001, 89.999, 5, 0 );
225       else
226            anIter.data()->RangeStepAndValidator( 0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY );
227     }
228
229   setHelpFileName("chamfer_operation_page.html");
230
231   /* Initialisations */
232   RadioButtonPressed();
233   Init();
234 }
235
236
237 //=================================================================================
238 // function : ~OperationGUI_ChamferDlg()
239 // purpose  : Destroys the object and frees any allocated resources
240 //=================================================================================
241 OperationGUI_ChamferDlg::~OperationGUI_ChamferDlg()
242 {
243 }
244
245
246 //=================================================================================
247 // function : Init()
248 // purpose  :
249 //=================================================================================
250 void OperationGUI_ChamferDlg::Init()
251 {
252   myConstructorId = -1;
253   reset();
254   RadioButton1->setChecked( true );
255   myEditCurrentArgument = mySelName[ MainObj1 ];
256
257   /* signals and slots connections */
258
259   // main buttons
260   connect( buttonOk   , SIGNAL( clicked() ), this, SLOT( ClickOnOk()    ) );
261   connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
262
263   // group box
264   connect( GroupConstructors, SIGNAL( clicked( int ) ),
265            this, SLOT( ConstructorsClicked( int ) ) );
266
267   // push buttons
268   QMap< int, QPushButton* >::iterator anIterBtn;
269   for ( anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn )
270     connect( anIterBtn.data(), SIGNAL( clicked() ),
271              this, SLOT( SetEditCurrentArgument() ) );
272
273   // line edits
274   QMap< int, QLineEdit* >::iterator anIterLE2;
275   for ( anIterLE2 = mySelName.begin(); anIterLE2 != mySelName.end(); ++anIterLE2 )
276     connect( anIterLE2.data(), SIGNAL( returnPressed() ),
277              this, SLOT( LineEditReturnPressed() ) );
278
279   // spin boxes
280   QMap< int, DlgRef_SpinBox* >::iterator anIterSpin;
281   for ( anIterSpin = mySpinBox.begin(); anIterSpin != mySpinBox.end(); ++anIterSpin )
282     connect( anIterSpin.data(), SIGNAL( valueChanged( double ) ),
283              this, SLOT( ValueChangedInSpinBox( double ) ) );
284
285   // radio buttons
286   QMap< int, QRadioButton* >::iterator anIterRadio;
287   for ( anIterRadio = myRadioButton.begin(); anIterRadio != myRadioButton.end(); ++anIterRadio )
288     connect( anIterRadio.data(), SIGNAL( clicked() ),
289              this, SLOT( RadioButtonPressed() ) );
290
291   // selection
292   connect(myGeomGUI->getApp()->selectionMgr(), 
293           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
294
295   initName( tr( "GEOM_CHAMFER" ) );
296
297   myGrp4->hide();
298   myGrp3->hide();
299   myGrp2->hide();
300   myGrp1->show();
301 }
302
303
304 //=================================================================================
305 // function : ConstructorsClicked()
306 // purpose  : Radio button management
307 //=================================================================================
308 void OperationGUI_ChamferDlg::ConstructorsClicked( int constructorId )
309 {
310    // Activate next widget
311   if (myGeomGUI->getApp()->desktop()->activeWindow()->getViewManager()->getType() 
312       != OCCViewer_Viewer::Type())
313   {
314     RadioButton1->setChecked( true );
315     return;
316   }
317
318   if (myConstructorId == constructorId)
319     return;
320
321   // Get values from previous widget
322   double D1 = 5, D2 = 5, D = 5, Angle = 5;
323   if ( myConstructorId == 0 )
324     D1 = D2 = mySpinBox[ SpinBox1 ]->GetValue();
325   else if ( myConstructorId == 1 )
326   {
327     D1 = mySpinBox[ SpinBox21 ]->GetValue();
328     D2 = mySpinBox[ SpinBox22 ]->GetValue();
329     D =  mySpinBox[ SpinBox23 ]->GetValue();
330     Angle = mySpinBox[ SpinBox24 ]->GetValue();
331   }
332   else if ( myConstructorId == 2 )
333   {
334     D1 = mySpinBox[ SpinBox31 ]->GetValue();
335     D2 = mySpinBox[ SpinBox32 ]->GetValue();
336     D =  mySpinBox[ SpinBox33 ]->GetValue();
337     Angle = mySpinBox[ SpinBox34 ]->GetValue();
338   }
339   else if ( myConstructorId == 3 )
340   {
341     D1 = mySpinBox[ SpinBox41 ]->GetValue();
342     D2 = mySpinBox[ SpinBox42 ]->GetValue();
343     D =  mySpinBox[ SpinBox43 ]->GetValue();
344     Angle = mySpinBox[ SpinBox44 ]->GetValue();
345   }
346
347   myConstructorId = constructorId;
348
349    switch ( constructorId )
350   {
351     case 0:
352         myGrp1->show();
353         myGrp2->hide();
354         myGrp3->hide();
355         myGrp4->hide();
356         mySpinBox[ SpinBox1 ]->SetValue( D1 );
357     break;
358     case 1:
359         myGrp1->hide();
360         myGrp2->show();
361         myGrp3->hide();
362         myGrp4->hide();
363         mySpinBox[ SpinBox21 ]->SetValue( D1 );
364         mySpinBox[ SpinBox22 ]->SetValue( D2 );
365         mySpinBox[ SpinBox23 ]->SetValue( D );
366         mySpinBox[ SpinBox24 ]->SetValue( Angle );
367     break;
368     case 2:
369         myGrp1->hide();
370         myGrp2->hide();
371         myGrp3->show();
372         myGrp4->hide();
373         mySpinBox[ SpinBox31 ]->SetValue( D1 );
374         mySpinBox[ SpinBox32 ]->SetValue( D2 );
375         mySpinBox[ SpinBox33 ]->SetValue( D );
376         mySpinBox[ SpinBox34 ]->SetValue( Angle );
377     break;
378         case 3:
379         myGrp1->hide();
380         myGrp2->hide();
381         myGrp3->hide();
382         myGrp4->show();
383         mySpinBox[ SpinBox41 ]->SetValue( D1 );
384         mySpinBox[ SpinBox42 ]->SetValue( D2 );        
385         mySpinBox[ SpinBox43 ]->SetValue( D );
386         mySpinBox[ SpinBox44 ]->SetValue( Angle );
387     break;
388     default:
389     break;
390   }
391
392   if      ( constructorId == 0 ) myEditCurrentArgument = mySelName[ MainObj1 ];
393   else if ( constructorId == 1 ) myEditCurrentArgument = mySelName[ MainObj2 ];
394   else if ( constructorId == 2 ) myEditCurrentArgument = mySelName[ MainObj3 ];
395   else                           myEditCurrentArgument = mySelName[ MainObj4 ];
396
397   activateSelection(); 
398   enableWidgets();
399   
400   if ( !myShape->_is_nil() )
401   {
402     myEditCurrentArgument->setText( GEOMBase::GetName( myShape ) );
403     GEOMBase_Skeleton::LineEditReturnPressed();
404   }
405   else
406     myEditCurrentArgument->setText( "" );
407
408   displayPreview();
409 }
410
411
412 //=================================================================================
413 // function : ClickOnOk()
414 // purpose  :
415 //=================================================================================
416 void OperationGUI_ChamferDlg::ClickOnOk()
417 {
418   if ( ClickOnApply() )
419     ClickOnCancel();
420 }
421
422 //=================================================================================
423 // function : ClickOnApply()
424 // purpose  :
425 //=================================================================================
426 bool OperationGUI_ChamferDlg::ClickOnApply()
427 {
428   if ( !onAccept() )
429     return false;
430
431   initName();
432   return true;
433 }
434
435 //=================================================================================
436 // function : SelectionIntoArgument()
437 // purpose  : Called when selection has changed
438 //=================================================================================
439 void OperationGUI_ChamferDlg::SelectionIntoArgument()
440 {
441   erasePreview();
442   myEditCurrentArgument->setText( "" );
443
444   // Get index of current selection focus
445   int aCurrFocus = -1;
446   QMap< int, QLineEdit* >::iterator anIter;
447   for ( anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter )
448     if ( myEditCurrentArgument == anIter.data() )
449     {
450       aCurrFocus = anIter.key();
451       break;
452     }
453
454   // If selection of main object is activated
455   if ( aCurrFocus == MainObj1 || aCurrFocus == MainObj2 || aCurrFocus == MainObj3 || aCurrFocus == MainObj4)
456   {
457     if ( IObjectCount() == 1 )
458     {
459       Standard_Boolean aResult = Standard_False;
460       GEOM::GEOM_Object_var anObj =
461         GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
462
463       if ( aResult && !anObj->_is_nil() )
464       {
465         myShape = anObj;
466         mySelName[ aCurrFocus ]->setText( GEOMBase::GetName( anObj ) );
467         displayPreview();
468         enableWidgets();
469         return;
470       }
471     }
472
473     myShape = GEOM::GEOM_Object::_nil();
474     enableWidgets();
475   }
476   // If face selection of second tab is activated
477   else if ( aCurrFocus == Face1 || aCurrFocus == Face2 )
478   {
479     if ( IObjectCount() == 1 )
480     {
481       Standard_Boolean aResult = Standard_False;
482       GEOM::GEOM_Object_var anObj =
483         GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
484
485       if ( aResult && !anObj->_is_nil() )
486       {
487          TColStd_IndexedMapOfInteger anIndexes;
488          ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
489
490          if ( anIndexes.Extent() == 1 )
491          {
492             int anIndex = anIndexes( 1 );
493             QString aFaceName = QString( GEOMBase::GetName( anObj ) ) + ":%1";
494             myEditCurrentArgument->setText( aFaceName.arg( anIndex ) );
495             myFace[ aCurrFocus ] = anIndex;
496             displayPreview();
497             return;
498          }
499       }
500     }
501
502     myFace[ aCurrFocus ] = -1;
503   }
504   // If face selection of third or fourth tab is activated
505   else if ( aCurrFocus == Faces  || aCurrFocus == Edges )
506   {
507     if ( IObjectCount() == 1 )
508     {
509       Standard_Boolean aResult = Standard_False;
510       GEOM::GEOM_Object_var anObj =
511         GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
512
513       if ( aResult && !anObj->_is_nil() )
514       {
515          TColStd_IndexedMapOfInteger anIndexes;
516          ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
517
518          if ( anIndexes.Extent() > 0 )
519          {
520            QString aName;
521            if ( anIndexes.Extent() == 1 )
522            {
523              int anIndex = anIndexes( 1 );
524
525              aName = QString( GEOMBase::GetName( anObj ) ) + QString( ":%1" ).arg( anIndex );
526            }
527            else
528              aName = tr( "GEOM_MEN_POPUP_NAME" ).arg( anIndexes.Extent() );
529
530            myEditCurrentArgument->setText( aName );
531            int aConstructorId = getConstructorId();
532            if ( aConstructorId == 2)
533              myFaces = anIndexes;
534            else if (aConstructorId == 3)
535              myEdges = anIndexes;
536              
537            displayPreview();
538            return;
539          }
540       }
541     }
542     myFaces.Clear();
543     myEdges.Clear();
544   }
545 }
546
547
548 //=================================================================================
549 // function : LineEditReturnPressed()
550 // purpose  :
551 //=================================================================================
552 void OperationGUI_ChamferDlg::LineEditReturnPressed()
553 {
554   QLineEdit* aSender = ( QLineEdit* )sender();
555
556   QMap< int, QLineEdit* >::iterator anIterLE;
557   for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
558     if ( anIterLE.data() == aSender )
559       myEditCurrentArgument = anIterLE.data();
560
561   GEOMBase_Skeleton::LineEditReturnPressed();
562 }
563
564 //=================================================================================
565 // function : RadioButtonPressed()
566 // purpose  :
567 //=================================================================================
568 void OperationGUI_ChamferDlg::RadioButtonPressed()
569 {
570   bool flag;
571   flag = ( myRadioButton[ RadioButton21 ]->isChecked() &&
572            myRadioButton[ RadioButton31 ]->isChecked() &&
573            myRadioButton[ RadioButton41 ]->isChecked() );
574     
575   myRadioButton[ RadioButton21 ]->setChecked(!flag);
576   myRadioButton[ RadioButton31 ]->setChecked(!flag);
577   myRadioButton[ RadioButton41 ]->setChecked(!flag);
578   myRadioButton[ RadioButton22 ]->setChecked(flag);
579   myRadioButton[ RadioButton32 ]->setChecked(flag);
580   myRadioButton[ RadioButton42 ]->setChecked(flag);
581   mySpinBox[ SpinBox21 ]->setDisabled(flag);
582   mySpinBox[ SpinBox22 ]->setDisabled(flag); 
583   mySpinBox[ SpinBox31 ]->setDisabled(flag); 
584   mySpinBox[ SpinBox32 ]->setDisabled(flag); 
585   mySpinBox[ SpinBox41 ]->setDisabled(flag); 
586   mySpinBox[ SpinBox42 ]->setDisabled(flag);
587   mySpinBox[ SpinBox23 ]->setDisabled(!flag);
588   mySpinBox[ SpinBox24 ]->setDisabled(!flag); 
589   mySpinBox[ SpinBox33 ]->setDisabled(!flag); 
590   mySpinBox[ SpinBox34 ]->setDisabled(!flag); 
591   mySpinBox[ SpinBox43 ]->setDisabled(!flag); 
592   mySpinBox[ SpinBox44 ]->setDisabled(!flag);
593   displayPreview();
594 }
595
596
597 //=================================================================================
598 // function : SetEditCurrentArgument()
599 // purpose  :
600 //=================================================================================
601 void OperationGUI_ChamferDlg::SetEditCurrentArgument()
602 {
603  QPushButton* aSender = ( QPushButton* )sender();
604
605   QMap< int, QPushButton* >::iterator anIter;
606   for ( anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter )
607     if ( anIter.data() == aSender )
608     {
609       mySelName[ anIter.key() ]->setFocus();
610       myEditCurrentArgument = mySelName[ anIter.key() ];
611     }
612
613   activateSelection();
614 }
615
616
617 //=================================================================================
618 // function : ActivateThisDialog()
619 // purpose  :
620 //=================================================================================
621 void OperationGUI_ChamferDlg::ActivateThisDialog()
622 {
623   GEOMBase_Skeleton::ActivateThisDialog();
624
625   connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
626            SIGNAL(currentSelectionChanged()), this, SLOT( SelectionIntoArgument() ) );
627
628   activateSelection();
629   displayPreview();
630 }
631
632
633 //=================================================================================
634 // function : enterEvent()
635 // purpose  :
636 //=================================================================================
637 void OperationGUI_ChamferDlg::enterEvent(QEvent* e)
638 {
639   if ( !GroupConstructors->isEnabled() )
640     this->ActivateThisDialog();
641 }
642
643
644 //=================================================================================
645 // function : ValueChangedInSpinBox()
646 // purpose  :
647 //=================================================================================
648 void OperationGUI_ChamferDlg::ValueChangedInSpinBox( double newValue )
649 {
650   displayPreview();
651 }
652
653
654 //=================================================================================
655 // function : createSelWg()
656 // purpose  :
657 //=================================================================================
658 void OperationGUI_ChamferDlg::createSelWg( const QString& theLbl,
659                                            QPixmap&       thePix,
660                                            QWidget*       theParent,
661                                            const int      theId )
662 {
663   new QLabel( theLbl, theParent );
664   mySelBtn[ theId ] = new QPushButton( theParent );
665   mySelBtn[ theId ]->setPixmap( thePix );
666   mySelName[ theId ] = new QLineEdit( theParent );
667   mySelName[ theId ]->setReadOnly( true );
668 }
669
670 //=================================================================================
671 // function : reset()
672 // purpose  :
673 //=================================================================================
674 void OperationGUI_ChamferDlg::reset()
675 {
676  // Set Initial values of spinboxes
677   QMap< int, DlgRef_SpinBox* >::iterator anIter;
678   for ( anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter )
679     anIter.data()->SetValue( 5 );
680
681   // clear line edits
682   QMap< int, QLineEdit* >::iterator anIterLE;
683   for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
684     anIterLE.data()->setText( "" );
685
686   // constructor id
687   int aConstructorId = getConstructorId();
688
689   if      ( aConstructorId == 0 ) myEditCurrentArgument = mySelName[ MainObj1 ];
690   else if ( aConstructorId == 1 ) myEditCurrentArgument = mySelName[ MainObj2 ];
691   else if ( aConstructorId == 2 ) myEditCurrentArgument = mySelName[ MainObj3 ];
692   else                            myEditCurrentArgument = mySelName[ MainObj4 ];
693
694   myShape = GEOM::GEOM_Object::_nil();
695
696   myFaces.Clear();
697   myEdges.Clear();
698   myFace[ Face1 ] = -1;
699   myFace[ Face2 ] = -1;
700
701   erasePreview( true );
702
703   activateSelection();
704
705   enableWidgets();
706 }
707
708 //=================================================================================
709 // function : getConstructorId()
710 // purpose  :
711 //=================================================================================
712 int OperationGUI_ChamferDlg::getConstructorId() const
713 {
714   return GroupConstructors->id( GroupConstructors->selected() );
715 }
716
717 //=================================================================================
718 // function : activateSelection
719 // purpose  : Activate selection in accordance with myEditCurrentArgument
720 //=================================================================================
721 void OperationGUI_ChamferDlg::activateSelection()
722 {
723   if (  !myShape->_is_nil() &&
724        ( myEditCurrentArgument == mySelName[ Face1 ] ||
725          myEditCurrentArgument == mySelName[ Face2 ] ||
726                  myEditCurrentArgument == mySelName[ Faces ] ) )
727     localSelection( myShape, TopAbs_FACE );
728   else if (!myShape->_is_nil() && myEditCurrentArgument == mySelName[ Edges ] )
729     localSelection( myShape, TopAbs_EDGE );
730   else
731   {
732     TColStd_MapOfInteger aMap;
733     aMap.Add( GEOM_SHELL );
734     aMap.Add( GEOM_SOLID );
735     aMap.Add( GEOM_COMPOUND );
736     globalSelection( aMap );
737   }
738
739   SelectionIntoArgument();
740 }
741
742 //=================================================================================
743 // function : enableWidgets
744 // purpose  : Enable widgets of faces in accordance with value of main object
745 //=================================================================================
746 void OperationGUI_ChamferDlg::enableWidgets()
747 {
748   int anId = getConstructorId();
749
750   bool toEnable = !myShape->_is_nil();
751   
752   if ( anId == 1 )
753   {
754     mySelName[ Face1 ]->setEnabled( toEnable );
755     mySelName[ Face2 ]->setEnabled( toEnable );
756     mySelBtn[ Face1 ]->setEnabled( toEnable );
757     mySelBtn[ Face2 ]->setEnabled( toEnable );
758
759     if ( !toEnable )
760     {
761       mySelName[ Face1 ]->setText( "" );
762       mySelName[ Face2 ]->setText( "" );
763       myFace[ Face1 ] = -1;
764       myFace[ Face2 ] = -1;
765     }
766   }
767   else if ( anId == 2 )
768   {
769     mySelName[ Faces ]->setEnabled( toEnable );
770     if ( !toEnable )
771         {
772           mySelName[ Faces ]->setText( "" );
773           myFaces = -1;
774         }
775   }
776   else if ( anId == 3 )
777   {
778     mySelName[ Edges ]->setEnabled( toEnable );
779
780     if ( !toEnable )
781         {
782           mySelName[ Edges ]->setText( "" );
783           myEdges = -1;
784         }
785   }
786 }
787
788 //=================================================================================
789 // function : createOperation
790 // purpose  :
791 //=================================================================================
792 GEOM::GEOM_IOperations_ptr OperationGUI_ChamferDlg::createOperation()
793 {
794   return getGeomEngine()->GetILocalOperations( getStudyId() );
795 }
796 //=================================================================================
797 // function : ClickOnApply()
798 // purpose  : Verify validity of input data
799 //=================================================================================
800 bool OperationGUI_ChamferDlg::isValid( QString& )
801 {
802   switch ( getConstructorId() )
803   {
804     case 0: return !myShape->_is_nil();
805     case 1: return !myShape->_is_nil() && myFace[ Face1 ] > 0 && myFace[ Face2 ] > 0;
806     case 2: return !myShape->_is_nil() && myFaces.Extent() > 0;
807     case 3: return !myShape->_is_nil() && myEdges.Extent() > 0;
808     default: return false;
809   }
810 }
811
812 //=================================================================================
813 // function : execute
814 // purpose  :
815 //=================================================================================
816 bool OperationGUI_ChamferDlg::execute( ObjectList& objects )
817 {
818   GEOM::GEOM_Object_var anObj;
819   bool flag = ( myRadioButton[ RadioButton21 ]->isChecked() &&
820                 myRadioButton[ RadioButton31 ]->isChecked() &&
821                 myRadioButton[ RadioButton41 ]->isChecked() );
822
823   int anId = getConstructorId();
824   if ( anId == 0 )
825     anObj = GEOM::GEOM_ILocalOperations::_narrow(
826       getOperation() )->MakeChamferAll( myShape,
827                                         mySpinBox[ SpinBox1 ]->GetValue() );
828   else if ( anId == 1 )
829     {
830       if ( flag )
831           anObj = GEOM::GEOM_ILocalOperations::_narrow(
832                   getOperation() )->MakeChamferEdge( myShape,
833                                                      mySpinBox[ SpinBox21 ]->GetValue(),
834                                                      mySpinBox[ SpinBox22 ]->GetValue(),
835                                                      myFace[ Face1 ],
836                                                      myFace[ Face2 ] );
837       else
838           anObj = GEOM::GEOM_ILocalOperations::_narrow(
839                   getOperation() )->MakeChamferEdgeAD( myShape,
840                                                        mySpinBox[ SpinBox23 ]->GetValue(),
841                                                        mySpinBox[ SpinBox24 ]->GetValue() * PI180,
842                                                        myFace[ Face1 ],
843                                                        myFace[ Face2 ]);
844     }
845   else if ( anId == 2 )
846   {
847     GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
848     anArray->length( myFaces.Extent() );
849     for ( int i = 1, n = myFaces.Extent(); i <= n; i++ )
850       anArray[ i - 1 ] = myFaces( i );
851     if ( flag )
852     anObj = GEOM::GEOM_ILocalOperations::_narrow(
853       getOperation() )->MakeChamferFaces( myShape,
854                                           mySpinBox[ SpinBox31 ]->GetValue(),
855                                           mySpinBox[ SpinBox32 ]->GetValue(),
856                                           anArray );
857     else
858     anObj = GEOM::GEOM_ILocalOperations::_narrow(
859       getOperation() )->MakeChamferFacesAD( myShape,
860                                             mySpinBox[ SpinBox33 ]->GetValue(),
861                                             mySpinBox[ SpinBox34 ]->GetValue() * PI180,
862                                             anArray );
863   }
864   else if ( anId == 3 )
865   {
866     GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
867     anArray->length( myEdges.Extent() );
868     for ( int i = 1, n = myEdges.Extent(); i <= n; i++ )
869       anArray[ i - 1 ] = myEdges( i );             
870     if ( flag )
871       anObj = GEOM::GEOM_ILocalOperations::_narrow(
872       getOperation() )->MakeChamferEdges( myShape, mySpinBox[ SpinBox41 ]->GetValue(),
873                                           mySpinBox[ SpinBox42 ]->GetValue(), anArray );
874     else
875       anObj = GEOM::GEOM_ILocalOperations::_narrow(
876       getOperation() )->MakeChamferEdgesAD( myShape, mySpinBox[ SpinBox43 ]->GetValue(),
877                                             mySpinBox[ SpinBox44 ]->GetValue() * PI180, anArray );
878   }
879
880   if ( !anObj->_is_nil() )
881     objects.push_back( anObj._retn() );
882
883   return true;
884 }