Salome HOME
79678b359ec0c39155681a521a1c8190a4cc2979
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : OperationGUI_ChamferDlg.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27
28 //  $Header$
29
30 #include "OperationGUI_ChamferDlg.h"
31 #include "DlgRef_SpinBox.h"
32
33 #include "SUIT_Desktop.h"
34 #include "SUIT_Session.h"
35 #include "SalomeApp_Application.h"
36 #include "LightApp_SelectionMgr.h"
37 #include "OCCViewer_ViewModel.h"
38
39 #include <TColStd_MapOfInteger.hxx>
40
41 #include <qlabel.h>
42 #include "qpixmap.h"
43 #include <list>
44
45 #include "GEOMImpl_Types.hxx"
46
47 //=================================================================================
48 // class    : OperationGUI_ChamferDlg()
49 // purpose  : Constructs a OperationGUI_ChamferDlg which is a child of 'parent', with the
50 //            name 'name' and widget flags set to 'f'.
51 //            The dialog will by default be modeless, unless you set 'modal' to
52 //            TRUE to construct a modal dialog.
53 //=================================================================================
54 OperationGUI_ChamferDlg::OperationGUI_ChamferDlg( QWidget* parent )
55 : GEOMBase_Skeleton(parent, "ChamferDlg", false,
56     WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
57 {
58   myConstructorId = -1;
59
60   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_ALL")));
61   QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_EDGE")));
62   QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_FACE")));
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
73   // Create first group
74
75   myGrp1 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_ALL" ), this );
76
77   QGroupBox* aSelGrp1 = new QGroupBox( 3, Qt::Horizontal, myGrp1 );
78   aSelGrp1->setFrameStyle( QFrame::NoFrame );
79   aSelGrp1->setInsideMargin( 0 );
80
81   createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp1, MainObj1 );
82
83   QGroupBox* aSpinGrp = new QGroupBox( 1, Qt::Vertical, myGrp1 );
84   aSpinGrp->setFrameStyle( QFrame::NoFrame );
85   aSpinGrp->setInsideMargin( 0 );
86
87   new QLabel( tr( "D" ), aSpinGrp );
88   mySpinBox[ SpinBox1 ] = new DlgRef_SpinBox( aSpinGrp );
89
90   ( new QFrame( myGrp1 ) )->setSizePolicy(
91     QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
92
93   // Create second group
94
95   myGrp2 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_EDGES" ), this );
96
97   QGroupBox* aSelGrp2 = new QGroupBox( 3, Qt::Horizontal, myGrp2 );
98   aSelGrp2->setFrameStyle( QFrame::NoFrame );
99   aSelGrp2->setInsideMargin( 0 );
100
101   createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp2, MainObj2 );
102   createSelWg( tr( "FACE_1" ), iconSelect, aSelGrp2, Face1 );
103   createSelWg( tr( "FACE_2" ), iconSelect, aSelGrp2, Face2 );
104
105   aSpinGrp = new QGroupBox( 1, Qt::Vertical, myGrp2 );
106   aSpinGrp->setFrameStyle( QFrame::NoFrame );
107   aSpinGrp->setInsideMargin( 0 );
108
109   new QLabel( tr( "GEOM_D1" ), aSpinGrp );
110   mySpinBox[ SpinBox21 ] = new DlgRef_SpinBox( aSpinGrp );
111
112   new QLabel( tr( "GEOM_D2" ), aSpinGrp );
113   mySpinBox[ SpinBox22 ] = new DlgRef_SpinBox( aSpinGrp );
114
115   // Create third group
116
117   myGrp3 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_FACES" ), this );
118
119   QGroupBox* aSelGrp3 = new QGroupBox( 3, Qt::Horizontal, myGrp3 );
120   aSelGrp3->setFrameStyle( QFrame::NoFrame );
121   aSelGrp3->setInsideMargin( 0 );
122
123   createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp3, MainObj3 );
124   createSelWg( tr( "SELECTED_FACES" ), iconSelect, aSelGrp3, Faces );
125
126   aSpinGrp = new QGroupBox( 1, Qt::Vertical, myGrp3 );
127   aSpinGrp->setFrameStyle( QFrame::NoFrame );
128   aSpinGrp->setInsideMargin( 0 );
129
130   new QLabel( tr( "GEOM_D1" ), aSpinGrp );
131   mySpinBox[ SpinBox31 ] = new DlgRef_SpinBox( aSpinGrp );
132
133   new QLabel( tr( "GEOM_D2" ), aSpinGrp );
134   mySpinBox[ SpinBox32 ] = new DlgRef_SpinBox( aSpinGrp );
135
136   ( new QLabel( myGrp3 ) )->setSizePolicy(
137     QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
138
139   // Add groups to layout
140
141   Layout1->addWidget( myGrp1, 2, 0 );
142   Layout1->addWidget( myGrp2, 2, 0 );
143   Layout1->addWidget( myGrp3, 2, 0 );
144
145   // Set range of spinboxes
146
147   double SpecificStep = 10.0;
148   QMap< int, DlgRef_SpinBox* >::iterator anIter;
149   for ( anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter )
150     anIter.data()->RangeStepAndValidator( 0.001, 999.999, SpecificStep, 3 );
151
152   /* Initialisations */
153   Init();
154 }
155
156
157 //=================================================================================
158 // function : ~OperationGUI_ChamferDlg()
159 // purpose  : Destroys the object and frees any allocated resources
160 //=================================================================================
161 OperationGUI_ChamferDlg::~OperationGUI_ChamferDlg()
162 {
163 }
164
165
166 //=================================================================================
167 // function : Init()
168 // purpose  :
169 //=================================================================================
170 void OperationGUI_ChamferDlg::Init()
171 {
172   myConstructorId = -1;
173   reset();
174   RadioButton1->setChecked( true );
175   myEditCurrentArgument = mySelName[ MainObj1 ];
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( GroupConstructors, SIGNAL( clicked( int ) ),
185            this, SLOT( ConstructorsClicked( int ) ) );
186
187   // push buttons
188   QMap< int, QPushButton* >::iterator anIterBtn;
189   for ( anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn )
190     connect( anIterBtn.data(), SIGNAL( clicked() ),
191              this, SLOT( SetEditCurrentArgument() ) );
192
193   // line edits
194   QMap< int, QLineEdit* >::iterator anIterLE2;
195   for ( anIterLE2 = mySelName.begin(); anIterLE2 != mySelName.end(); ++anIterLE2 )
196     connect( anIterLE2.data(), SIGNAL( returnPressed() ),
197              this, SLOT( LineEditReturnPressed() ) );
198
199   // spin boxes
200   QMap< int, DlgRef_SpinBox* >::iterator anIterSpin;
201   for ( anIterSpin = mySpinBox.begin(); anIterSpin != mySpinBox.end(); ++anIterSpin )
202     connect( anIterSpin.data(), SIGNAL( valueChanged( double ) ),
203              this, SLOT( ValueChangedInSpinBox( double ) ) );
204
205   // selection
206   connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
207            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
208
209   initName( tr( "GEOM_CHAMFER" ) );
210
211   myGrp2->hide();
212   myGrp3->hide();
213   myGrp1->show();
214
215   this->show();
216 }
217
218
219 //=================================================================================
220 // function : ConstructorsClicked()
221 // purpose  : Radio button management
222 //=================================================================================
223 void OperationGUI_ChamferDlg::ConstructorsClicked( int constructorId )
224 {
225    // Activate next widget
226   if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() 
227        != OCCViewer_Viewer::Type() )
228     {
229       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;
238   if ( myConstructorId == 0 )
239     D1 = D2 = mySpinBox[ SpinBox1 ]->GetValue();
240   else if ( myConstructorId == 1 )
241   {
242     D1 = mySpinBox[ SpinBox21 ]->GetValue();
243     D2 = mySpinBox[ SpinBox22 ]->GetValue();
244   }
245   else if ( myConstructorId == 2 )
246   {
247     D1 = mySpinBox[ SpinBox31 ]->GetValue();
248     D2 = mySpinBox[ SpinBox32 ]->GetValue();
249   }
250
251   myConstructorId = constructorId;
252
253    switch ( constructorId )
254   {
255     case 0:
256         myGrp1->show();
257         myGrp2->hide();
258         myGrp3->hide();
259         mySpinBox[ SpinBox1 ]->SetValue( D1 );
260     break;
261     case 1:
262         myGrp1->hide();
263         myGrp2->show();
264         myGrp3->hide();
265         mySpinBox[ SpinBox21 ]->SetValue( D1 );
266         mySpinBox[ SpinBox22 ]->SetValue( D2 );
267     break;
268     case 2:
269         myGrp1->hide();
270         myGrp2->hide();
271         myGrp3->show();
272         mySpinBox[ SpinBox31 ]->SetValue( D1 );
273         mySpinBox[ SpinBox32 ]->SetValue( D2 );        
274     break;
275     default:
276     break;
277   }
278
279   if      ( constructorId == 0 ) myEditCurrentArgument = mySelName[ MainObj1 ];
280   else if ( constructorId == 1 ) myEditCurrentArgument = mySelName[ MainObj2 ];
281   else                           myEditCurrentArgument = mySelName[ MainObj3 ];
282
283   activateSelection(); 
284   enableWidgets();
285   
286   if ( !myShape->_is_nil() )
287   {
288     myEditCurrentArgument->setText( GEOMBase::GetName( myShape ) );
289     GEOMBase_Skeleton::LineEditReturnPressed();
290   }
291   else
292     myEditCurrentArgument->setText( "" );
293
294   displayPreview();
295 }
296
297
298 //=================================================================================
299 // function : ClickOnOk()
300 // purpose  :
301 //=================================================================================
302 void OperationGUI_ChamferDlg::ClickOnOk()
303 {
304   if ( ClickOnApply() )
305     ClickOnCancel();
306 }
307
308 //=================================================================================
309 // function : ClickOnApply()
310 // purpose  :
311 //=================================================================================
312 bool OperationGUI_ChamferDlg::ClickOnApply()
313 {
314   if ( !onAccept() )
315     return false;
316
317   initName();
318   return true;
319 }
320
321
322 //=================================================================================
323 // function : SelectionIntoArgument()
324 // purpose  : Called when selection has changed
325 //=================================================================================
326 void OperationGUI_ChamferDlg::SelectionIntoArgument()
327 {
328   erasePreview();
329   myEditCurrentArgument->setText( "" );
330
331   // Get index of current selection focus
332   int aCurrFocus = -1;
333   QMap< int, QLineEdit* >::iterator anIter;
334   for ( anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter )
335     if ( myEditCurrentArgument == anIter.data() )
336     {
337       aCurrFocus = anIter.key();
338       break;
339     }
340
341   // If selection of main object is activated
342   if ( aCurrFocus == MainObj1 || aCurrFocus == MainObj2 || aCurrFocus == MainObj3 )
343   {
344     if ( IObjectCount() == 1 )
345     {
346       Standard_Boolean aResult = Standard_False;
347       GEOM::GEOM_Object_var anObj =
348         GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
349
350       if ( aResult && !anObj->_is_nil() )
351       {
352         myShape = anObj;
353         mySelName[ aCurrFocus ]->setText( GEOMBase::GetName( anObj ) );
354         displayPreview();
355         enableWidgets();
356         return;
357       }
358     }
359
360     myShape = GEOM::GEOM_Object::_nil();
361     enableWidgets();
362   }
363   // If face selection of second tab is activated
364   else if ( aCurrFocus == Face1 || aCurrFocus == Face2 )
365   {
366     if ( IObjectCount() == 1 )
367     {
368       Standard_Boolean aResult = Standard_False;
369       GEOM::GEOM_Object_var anObj =
370         GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
371
372       if ( aResult && !anObj->_is_nil() )
373       {
374          TColStd_IndexedMapOfInteger anIndexes;
375          ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
376
377          if ( anIndexes.Extent() == 1 )
378          {
379             int anIndex = anIndexes( 1 );
380             QString aFaceName = QString( GEOMBase::GetName( anObj ) ) + ":%1";
381             myEditCurrentArgument->setText( aFaceName.arg( anIndex ) );
382             myFace[ aCurrFocus ] = anIndex;
383             displayPreview();
384             return;
385          }
386       }
387     }
388
389     myFace[ aCurrFocus ] = -1;
390   }
391   // If face selection of third tab is activated
392   else if ( aCurrFocus == Faces )
393   {
394     if ( IObjectCount() == 1 )
395     {
396       Standard_Boolean aResult = Standard_False;
397       GEOM::GEOM_Object_var anObj =
398         GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
399
400       if ( aResult && !anObj->_is_nil() )
401       {
402          TColStd_IndexedMapOfInteger anIndexes;
403          ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
404
405          if ( anIndexes.Extent() > 0 )
406          {
407            QString aFaceName;
408            if ( anIndexes.Extent() == 1 )
409            {
410              int anIndex = anIndexes( 1 );
411
412              aFaceName = QString( GEOMBase::GetName( anObj ) ) + QString( ":%1" ).arg( anIndex );
413            }
414            else
415              aFaceName = tr( "GEOM_MEN_POPUP_NAME" ).arg( anIndexes.Extent() );
416
417            myEditCurrentArgument->setText( aFaceName );
418            myFaces = anIndexes;
419            displayPreview();
420            return;
421          }
422       }
423     }
424     myFaces.Clear();
425   }
426 }
427
428
429 //=================================================================================
430 // function : LineEditReturnPressed()
431 // purpose  :
432 //=================================================================================
433 void OperationGUI_ChamferDlg::LineEditReturnPressed()
434 {
435   QLineEdit* aSender = ( QLineEdit* )sender();
436
437   QMap< int, QLineEdit* >::iterator anIterLE;
438   for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
439     if ( anIterLE.data() == aSender )
440       myEditCurrentArgument = anIterLE.data();
441
442   GEOMBase_Skeleton::LineEditReturnPressed();
443 }
444
445
446 //=================================================================================
447 // function : SetEditCurrentArgument()
448 // purpose  :
449 //=================================================================================
450 void OperationGUI_ChamferDlg::SetEditCurrentArgument()
451 {
452   QPushButton* aSender = ( QPushButton* )sender();
453
454   QMap< int, QPushButton* >::iterator anIter;
455   for ( anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter )
456     if ( anIter.data() == aSender )
457     {
458       mySelName[ anIter.key() ]->setFocus();
459       myEditCurrentArgument = mySelName[ anIter.key() ];
460     }
461
462   activateSelection();
463 }
464
465
466 //=================================================================================
467 // function : DeactivateActiveDialog()
468 // purpose  :
469 //=================================================================================
470 void OperationGUI_ChamferDlg::DeactivateActiveDialog()
471 {
472   // disconnect selection
473   GEOMBase_Skeleton::DeactivateActiveDialog();
474 }
475
476
477 //=================================================================================
478 // function : ActivateThisDialog()
479 // purpose  :
480 //=================================================================================
481 void OperationGUI_ChamferDlg::ActivateThisDialog()
482 {
483   GEOMBase_Skeleton::ActivateThisDialog();
484
485   connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
486            SIGNAL(currentSelectionChanged()), this, SLOT( SelectionIntoArgument() ) );
487
488   activateSelection();
489   displayPreview();
490 }
491
492
493 //=================================================================================
494 // function : enterEvent()
495 // purpose  :
496 //=================================================================================
497 void OperationGUI_ChamferDlg::enterEvent(QEvent* e)
498 {
499   if ( !GroupConstructors->isEnabled() )
500     this->ActivateThisDialog();
501 }
502
503
504 //=================================================================================
505 // function : ValueChangedInSpinBox()
506 // purpose  :
507 //=================================================================================
508 void OperationGUI_ChamferDlg::ValueChangedInSpinBox( double newValue )
509 {
510   displayPreview();
511 }
512
513
514 //=================================================================================
515 // function : createSelWg()
516 // purpose  :
517 //=================================================================================
518 void OperationGUI_ChamferDlg::createSelWg( const QString& theLbl,
519                                            QPixmap&       thePix,
520                                            QWidget*       theParent,
521                                            const int      theId )
522 {
523   new QLabel( theLbl, theParent );
524   mySelBtn[ theId ] = new QPushButton( theParent );
525   mySelBtn[ theId ]->setPixmap( thePix );
526   mySelName[ theId ] = new QLineEdit( theParent );
527   mySelName[ theId ]->setReadOnly( true );
528 }
529
530 //=================================================================================
531 // function : reset()
532 // purpose  :
533 //=================================================================================
534 void OperationGUI_ChamferDlg::reset()
535 {
536   // Set Initial values of spinboxes
537   QMap< int, DlgRef_SpinBox* >::iterator anIter;
538   for ( anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter )
539     anIter.data()->SetValue( 5 );
540
541   // clear line edits
542   QMap< int, QLineEdit* >::iterator anIterLE;
543   for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
544     anIterLE.data()->setText( "" );
545
546   // constructor id
547   int aConstructorId = getConstructorId();
548
549   if      ( aConstructorId == 0 ) myEditCurrentArgument = mySelName[ MainObj1 ];
550   else if ( aConstructorId == 1 ) myEditCurrentArgument = mySelName[ MainObj2 ];
551   else                            myEditCurrentArgument = mySelName[ MainObj3 ];
552
553   myShape = GEOM::GEOM_Object::_nil();
554
555   myFaces.Clear();
556   myFace[ Face1 ] = -1;
557   myFace[ Face2 ] = -1;
558
559   erasePreview( true );
560
561   activateSelection();
562
563   enableWidgets();
564 }
565
566 //=================================================================================
567 // function : getConstructorId()
568 // purpose  :
569 //=================================================================================
570 int OperationGUI_ChamferDlg::getConstructorId() const
571 {
572   return GroupConstructors->id( GroupConstructors->selected() );
573 }
574
575 //=================================================================================
576 // function : activateSelection
577 // purpose  : Activate selection in accordance with myEditCurrentArgument
578 //=================================================================================
579 void OperationGUI_ChamferDlg::activateSelection()
580 {
581   if (  !myShape->_is_nil() &&
582        ( myEditCurrentArgument == mySelName[ Face1 ] ||
583          myEditCurrentArgument == mySelName[ Face2 ] ||
584          myEditCurrentArgument == mySelName[ Faces ] ) )
585     localSelection( myShape, TopAbs_FACE );
586   else
587   {
588     TColStd_MapOfInteger aMap;
589     aMap.Add( GEOM_SHELL );
590     aMap.Add( GEOM_SOLID );
591     aMap.Add( GEOM_COMPOUND );
592     globalSelection( aMap );
593   }
594
595   SelectionIntoArgument();
596 }
597
598 //=================================================================================
599 // function : enableWidgets
600 // purpose  : Enable widgets of faces in accordance with value of main object
601 //=================================================================================
602 void OperationGUI_ChamferDlg::enableWidgets()
603 {
604   int anId = getConstructorId();
605
606   bool toEnable = !myShape->_is_nil();
607   
608   if ( anId == 1 )
609   {
610     mySelName[ Face1 ]->setEnabled( toEnable );
611     mySelName[ Face2 ]->setEnabled( toEnable );
612     mySelBtn[ Face1 ]->setEnabled( toEnable );
613     mySelBtn[ Face2 ]->setEnabled( toEnable );
614
615     if ( !toEnable )
616     {
617       mySelName[ Face1 ]->setText( "" );
618       mySelName[ Face2 ]->setText( "" );
619       myFace[ Face1 ] = -1;
620       myFace[ Face2 ] = -1;
621     }
622   }
623   else if ( anId == 2 )
624   {
625     mySelName[ Faces ]->setEnabled( toEnable );
626
627     if ( !toEnable )
628       myFaces.Clear();
629   }
630 }
631
632 //=================================================================================
633 // function : createOperation
634 // purpose  :
635 //=================================================================================
636 GEOM::GEOM_IOperations_ptr OperationGUI_ChamferDlg::createOperation()
637 {
638   return getGeomEngine()->GetILocalOperations( getStudyId() );
639 }
640
641 //=================================================================================
642 // function : ClickOnApply()
643 // purpose  : Verify validity of input data
644 //=================================================================================
645 bool OperationGUI_ChamferDlg::isValid( QString& )
646 {
647   switch ( getConstructorId() )
648   {
649     case 0: return !myShape->_is_nil();
650     case 1: return !myShape->_is_nil() && myFace[ Face1 ] > 0 && myFace[ Face2 ] > 0;
651     case 2: return !myShape->_is_nil() && myFaces.Extent() > 0;
652     default: return false;
653   }
654 }
655
656 //=================================================================================
657 // function : execute
658 // purpose  :
659 //=================================================================================
660 bool OperationGUI_ChamferDlg::execute( ObjectList& objects )
661 {
662   GEOM::GEOM_Object_var anObj;
663
664   int anId = getConstructorId();
665   if ( anId == 0 )
666     anObj = GEOM::GEOM_ILocalOperations::_narrow(
667       getOperation() )->MakeChamferAll( myShape,
668                                         mySpinBox[ SpinBox1 ]->GetValue() );
669   else if ( anId == 1 )
670     anObj = GEOM::GEOM_ILocalOperations::_narrow(
671       getOperation() )->MakeChamferEdge( myShape,
672                                          mySpinBox[ SpinBox21 ]->GetValue(),
673                                          mySpinBox[ SpinBox22 ]->GetValue(),
674                                          myFace[ Face1 ],
675                                          myFace[ Face2 ] );
676   else if ( anId == 2 )
677   {
678
679     int i = 0;
680     GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
681     anArray->length( myFaces.Extent() );
682
683
684     for ( int i = 1, n = myFaces.Extent(); i <= n; i++ )
685       anArray[ i - 1 ] = myFaces( i );             
686     
687     anObj = GEOM::GEOM_ILocalOperations::_narrow(
688       getOperation() )->MakeChamferFaces( myShape,
689                                           mySpinBox[ SpinBox31 ]->GetValue(),
690                                           mySpinBox[ SpinBox32 ]->GetValue(),
691                                           anArray );
692   }
693
694
695   if ( !anObj->_is_nil() )
696     objects.push_back( anObj._retn() );
697
698   return true;
699 }
700
701
702
703
704
705
706
707
708