1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : OperationGUI_ChamferDlg.cxx
24 // Author : Damien COQUERET
28 #include "OperationGUI_ChamferDlg.h"
29 #include "DlgRef_SpinBox.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
35 #include "OCCViewer_ViewModel.h"
37 #include <TColStd_MapOfInteger.hxx>
43 #include "GEOMImpl_Types.hxx"
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, "ChamferDlg", false,
54 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
58 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_ALL")));
59 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_EDGE_FROM_FACE")));
60 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_FACE")));
61 QPixmap image4(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_EDGE")));
62 QPixmap iconSelect(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
64 setCaption( tr( "GEOM_CHAMFER_TITLE" ) );
66 GroupConstructors->setTitle( tr( "GEOM_CHAMFER" ) );
68 RadioButton1->setPixmap( image1 );
69 RadioButton2->setPixmap( image2 );
70 RadioButton3->setPixmap( image3 );
72 RadioButton4->setPixmap( image4 );
76 myGrp1 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_ALL" ), this );
78 QGroupBox* aSelGrp1 = new QGroupBox( 3, Qt::Horizontal, myGrp1 );
79 aSelGrp1->setFrameStyle( QFrame::NoFrame );
80 aSelGrp1->setInsideMargin( 0 );
82 createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp1, MainObj1 );
84 QGroupBox* aSpinGrp = new QGroupBox( 1, Qt::Vertical, myGrp1 );
85 aSpinGrp->setFrameStyle( QFrame::NoFrame );
86 aSpinGrp->setInsideMargin( 0 );
88 new QLabel( tr( "D" ), aSpinGrp );
89 mySpinBox[ SpinBox1 ] = new DlgRef_SpinBox( aSpinGrp );
91 ( new QFrame( myGrp1 ) )->setSizePolicy(
92 QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
94 // Create second group
96 myGrp2 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_EDGES" ), this );
98 QGroupBox* aSelGrp2 = new QGroupBox( 3, Qt::Horizontal, myGrp2 );
99 aSelGrp2->setFrameStyle( QFrame::NoFrame );
100 aSelGrp2->setInsideMargin( 0 );
102 createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp2, MainObj2 );
103 createSelWg( tr( "FACE_1" ), iconSelect, aSelGrp2, Face1 );
104 createSelWg( tr( "FACE_2" ), iconSelect, aSelGrp2, Face2 );
106 QGroupBox* aSpinGrp1 = new QGroupBox( 1, Qt::Vertical, myGrp2 );
107 aSpinGrp1->setFrameStyle( QFrame::NoFrame );
108 aSpinGrp1->setInsideMargin( 0 );
110 myRadioButton[ RadioButton21] = new QRadioButton( aSpinGrp1 );
112 new QLabel( tr( "GEOM_D1" ), aSpinGrp1 );
113 mySpinBox[ SpinBox21 ] = new DlgRef_SpinBox( aSpinGrp1 );
115 new QLabel( tr( "GEOM_D2" ), aSpinGrp1 );
116 mySpinBox[ SpinBox22 ] = new DlgRef_SpinBox( aSpinGrp1 );
118 QGroupBox* aSpinGrp2 = new QGroupBox( 1, Qt::Vertical, myGrp2 );
119 aSpinGrp2->setFrameStyle( QFrame::NoFrame );
120 aSpinGrp2->setInsideMargin( 0 );
122 myRadioButton[ RadioButton22] = new QRadioButton( aSpinGrp2 );
124 new QLabel( tr( "GEOM_D" ), aSpinGrp2 );
125 mySpinBox[ SpinBox23 ] = new DlgRef_SpinBox( aSpinGrp2 );
127 new QLabel( tr( "GEOM_ANGLE" ), aSpinGrp2 );
128 mySpinBox[ SpinBox24 ] = new DlgRef_SpinBox( aSpinGrp2 );
130 ( new QLabel( myGrp2 ) )->setSizePolicy(
131 QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
133 // Create third group
135 myGrp3 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_FACES" ), this );
137 QGroupBox* aSelGrp3 = new QGroupBox( 3, Qt::Horizontal, myGrp3 );
138 aSelGrp3->setFrameStyle( QFrame::NoFrame );
139 aSelGrp3->setInsideMargin( 0 );
141 createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp3, MainObj3 );
142 createSelWg( tr( "SELECTED_FACES" ), iconSelect, aSelGrp3, Faces );
144 aSpinGrp1 = new QGroupBox( 1, Qt::Vertical, myGrp3 );
145 aSpinGrp1->setFrameStyle( QFrame::NoFrame );
146 aSpinGrp1->setInsideMargin( 0 );
148 myRadioButton[ RadioButton31] = new QRadioButton( aSpinGrp1 );
150 new QLabel( tr( "GEOM_D1" ), aSpinGrp1 );
151 mySpinBox[ SpinBox31 ] = new DlgRef_SpinBox( aSpinGrp1 );
153 new QLabel( tr( "GEOM_D2" ), aSpinGrp1 );
154 mySpinBox[ SpinBox32 ] = new DlgRef_SpinBox( aSpinGrp1 );
156 aSpinGrp2 = new QGroupBox( 1, Qt::Vertical, myGrp3 );
157 aSpinGrp2->setFrameStyle( QFrame::NoFrame );
158 aSpinGrp2->setInsideMargin( 0 );
160 myRadioButton[ RadioButton32] = new QRadioButton( aSpinGrp2 );
162 new QLabel( tr( "GEOM_D" ), aSpinGrp2 );
163 mySpinBox[ SpinBox33 ] = new DlgRef_SpinBox( aSpinGrp2 );
165 new QLabel( tr( "GEOM_ANGLE" ), aSpinGrp2 );
166 mySpinBox[ SpinBox34 ] = new DlgRef_SpinBox( aSpinGrp2 );
168 ( new QLabel( myGrp3 ) )->setSizePolicy(
169 QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
171 // Create fourth group
173 myGrp4 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_EDGE" ), this );
175 QGroupBox* aSelGrp4 = new QGroupBox( 3, Qt::Horizontal, myGrp4 );
176 aSelGrp4->setFrameStyle( QFrame::NoFrame );
177 aSelGrp4->setInsideMargin( 0 );
179 createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp4, MainObj4 );
180 createSelWg( tr( "SELECTED_EDGE" ), iconSelect, aSelGrp4, Edges );
182 aSpinGrp1 = new QGroupBox( 1, Qt::Vertical, myGrp4 );
183 aSpinGrp1->setFrameStyle( QFrame::NoFrame );
184 aSpinGrp1->setInsideMargin( 0 );
186 myRadioButton[ RadioButton41] = new QRadioButton( aSpinGrp1 );
188 new QLabel( tr( "GEOM_D1" ), aSpinGrp1 );
189 mySpinBox[ SpinBox41 ] = new DlgRef_SpinBox( aSpinGrp1 );
191 new QLabel( tr( "GEOM_D2" ), aSpinGrp1 );
192 mySpinBox[ SpinBox42 ] = new DlgRef_SpinBox( aSpinGrp1 );
194 aSpinGrp2 = new QGroupBox( 1, Qt::Vertical, myGrp4 );
195 aSpinGrp2->setFrameStyle( QFrame::NoFrame );
196 aSpinGrp2->setInsideMargin( 0 );
198 myRadioButton[ RadioButton42] = new QRadioButton( aSpinGrp2 );
200 new QLabel( tr( "GEOM_D" ), aSpinGrp2 );
201 mySpinBox[ SpinBox43 ] = new DlgRef_SpinBox( aSpinGrp2 );
203 new QLabel( tr( "GEOM_ANGLE" ), aSpinGrp2 );
204 mySpinBox[ SpinBox44 ] = new DlgRef_SpinBox( aSpinGrp2 );
206 ( new QLabel( myGrp4 ) )->setSizePolicy(
207 QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
209 // Add groups to layout
211 Layout1->addWidget( myGrp1, 2, 0 );
212 Layout1->addWidget( myGrp2, 2, 0 );
213 Layout1->addWidget( myGrp3, 2, 0 );
214 Layout1->addWidget( myGrp4, 2, 0 );
216 // Set range of spinboxes
218 double SpecificStep = 10.0;
219 QMap< int, DlgRef_SpinBox* >::iterator anIter;
220 for ( anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter )
222 if ( anIter.key() == SpinBox44 || anIter.key() == SpinBox34 || anIter.key() == SpinBox24 )
223 anIter.data()->RangeStepAndValidator( 0.001, 89.999, 5, 0 );
225 anIter.data()->RangeStepAndValidator( 0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY );
228 setHelpFileName("chamfer_operation_page.html");
230 /* Initialisations */
231 RadioButtonPressed();
236 //=================================================================================
237 // function : ~OperationGUI_ChamferDlg()
238 // purpose : Destroys the object and frees any allocated resources
239 //=================================================================================
240 OperationGUI_ChamferDlg::~OperationGUI_ChamferDlg()
245 //=================================================================================
248 //=================================================================================
249 void OperationGUI_ChamferDlg::Init()
251 myConstructorId = -1;
253 RadioButton1->setChecked( true );
254 myEditCurrentArgument = mySelName[ MainObj1 ];
256 /* signals and slots connections */
259 connect( buttonOk , SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
260 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
263 connect( GroupConstructors, SIGNAL( clicked( int ) ),
264 this, SLOT( ConstructorsClicked( int ) ) );
267 QMap< int, QPushButton* >::iterator anIterBtn;
268 for ( anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn )
269 connect( anIterBtn.data(), SIGNAL( clicked() ),
270 this, SLOT( SetEditCurrentArgument() ) );
273 QMap< int, QLineEdit* >::iterator anIterLE2;
274 for ( anIterLE2 = mySelName.begin(); anIterLE2 != mySelName.end(); ++anIterLE2 )
275 connect( anIterLE2.data(), SIGNAL( returnPressed() ),
276 this, SLOT( LineEditReturnPressed() ) );
279 QMap< int, DlgRef_SpinBox* >::iterator anIterSpin;
280 for ( anIterSpin = mySpinBox.begin(); anIterSpin != mySpinBox.end(); ++anIterSpin )
281 connect( anIterSpin.data(), SIGNAL( valueChanged( double ) ),
282 this, SLOT( ValueChangedInSpinBox( double ) ) );
285 QMap< int, QRadioButton* >::iterator anIterRadio;
286 for ( anIterRadio = myRadioButton.begin(); anIterRadio != myRadioButton.end(); ++anIterRadio )
287 connect( anIterRadio.data(), SIGNAL( clicked() ),
288 this, SLOT( RadioButtonPressed() ) );
291 connect(myGeomGUI->getApp()->selectionMgr(),
292 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
294 initName( tr( "GEOM_CHAMFER" ) );
303 //=================================================================================
304 // function : ConstructorsClicked()
305 // purpose : Radio button management
306 //=================================================================================
307 void OperationGUI_ChamferDlg::ConstructorsClicked( int constructorId )
309 // Activate next widget
310 if (myGeomGUI->getApp()->desktop()->activeWindow()->getViewManager()->getType()
311 != OCCViewer_Viewer::Type())
313 RadioButton1->setChecked( true );
317 if (myConstructorId == constructorId)
320 // Get values from previous widget
321 double D1 = 5, D2 = 5, D = 5, Angle = 5;
322 if ( myConstructorId == 0 )
323 D1 = D2 = mySpinBox[ SpinBox1 ]->GetValue();
324 else if ( myConstructorId == 1 )
326 D1 = mySpinBox[ SpinBox21 ]->GetValue();
327 D2 = mySpinBox[ SpinBox22 ]->GetValue();
328 D = mySpinBox[ SpinBox23 ]->GetValue();
329 Angle = mySpinBox[ SpinBox24 ]->GetValue();
331 else if ( myConstructorId == 2 )
333 D1 = mySpinBox[ SpinBox31 ]->GetValue();
334 D2 = mySpinBox[ SpinBox32 ]->GetValue();
335 D = mySpinBox[ SpinBox33 ]->GetValue();
336 Angle = mySpinBox[ SpinBox34 ]->GetValue();
338 else if ( myConstructorId == 3 )
340 D1 = mySpinBox[ SpinBox41 ]->GetValue();
341 D2 = mySpinBox[ SpinBox42 ]->GetValue();
342 D = mySpinBox[ SpinBox43 ]->GetValue();
343 Angle = mySpinBox[ SpinBox44 ]->GetValue();
346 myConstructorId = constructorId;
348 switch ( constructorId )
355 mySpinBox[ SpinBox1 ]->SetValue( D1 );
362 mySpinBox[ SpinBox21 ]->SetValue( D1 );
363 mySpinBox[ SpinBox22 ]->SetValue( D2 );
364 mySpinBox[ SpinBox23 ]->SetValue( D );
365 mySpinBox[ SpinBox24 ]->SetValue( Angle );
372 mySpinBox[ SpinBox31 ]->SetValue( D1 );
373 mySpinBox[ SpinBox32 ]->SetValue( D2 );
374 mySpinBox[ SpinBox33 ]->SetValue( D );
375 mySpinBox[ SpinBox34 ]->SetValue( Angle );
382 mySpinBox[ SpinBox41 ]->SetValue( D1 );
383 mySpinBox[ SpinBox42 ]->SetValue( D2 );
384 mySpinBox[ SpinBox43 ]->SetValue( D );
385 mySpinBox[ SpinBox44 ]->SetValue( Angle );
391 if ( constructorId == 0 ) myEditCurrentArgument = mySelName[ MainObj1 ];
392 else if ( constructorId == 1 ) myEditCurrentArgument = mySelName[ MainObj2 ];
393 else if ( constructorId == 2 ) myEditCurrentArgument = mySelName[ MainObj3 ];
394 else myEditCurrentArgument = mySelName[ MainObj4 ];
399 if ( !myShape->_is_nil() )
401 myEditCurrentArgument->setText( GEOMBase::GetName( myShape ) );
402 GEOMBase_Skeleton::LineEditReturnPressed();
405 myEditCurrentArgument->setText( "" );
411 //=================================================================================
412 // function : ClickOnOk()
414 //=================================================================================
415 void OperationGUI_ChamferDlg::ClickOnOk()
417 if ( ClickOnApply() )
421 //=================================================================================
422 // function : ClickOnApply()
424 //=================================================================================
425 bool OperationGUI_ChamferDlg::ClickOnApply()
434 //=================================================================================
435 // function : SelectionIntoArgument()
436 // purpose : Called when selection has changed
437 //=================================================================================
438 void OperationGUI_ChamferDlg::SelectionIntoArgument()
441 myEditCurrentArgument->setText( "" );
443 // Get index of current selection focus
445 QMap< int, QLineEdit* >::iterator anIter;
446 for ( anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter )
447 if ( myEditCurrentArgument == anIter.data() )
449 aCurrFocus = anIter.key();
453 // If selection of main object is activated
454 if ( aCurrFocus == MainObj1 || aCurrFocus == MainObj2 || aCurrFocus == MainObj3 || aCurrFocus == MainObj4)
456 if ( IObjectCount() == 1 )
458 Standard_Boolean aResult = Standard_False;
459 GEOM::GEOM_Object_var anObj =
460 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
462 if ( aResult && !anObj->_is_nil() )
465 mySelName[ aCurrFocus ]->setText( GEOMBase::GetName( anObj ) );
472 myShape = GEOM::GEOM_Object::_nil();
475 // If face selection of second tab is activated
476 else if ( aCurrFocus == Face1 || aCurrFocus == Face2 )
478 if ( IObjectCount() == 1 )
480 Standard_Boolean aResult = Standard_False;
481 GEOM::GEOM_Object_var anObj =
482 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
484 if ( aResult && !anObj->_is_nil() )
486 TColStd_IndexedMapOfInteger anIndexes;
487 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
489 if ( anIndexes.Extent() == 1 )
491 int anIndex = anIndexes( 1 );
492 QString aFaceName = QString( GEOMBase::GetName( anObj ) ) + ":%1";
493 myEditCurrentArgument->setText( aFaceName.arg( anIndex ) );
494 myFace[ aCurrFocus ] = anIndex;
501 myFace[ aCurrFocus ] = -1;
503 // If face selection of third or fourth tab is activated
504 else if ( aCurrFocus == Faces || aCurrFocus == Edges )
506 if ( IObjectCount() == 1 )
508 Standard_Boolean aResult = Standard_False;
509 GEOM::GEOM_Object_var anObj =
510 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
512 if ( aResult && !anObj->_is_nil() )
514 TColStd_IndexedMapOfInteger anIndexes;
515 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
517 if ( anIndexes.Extent() > 0 )
520 if ( anIndexes.Extent() == 1 )
522 int anIndex = anIndexes( 1 );
524 aName = QString( GEOMBase::GetName( anObj ) ) + QString( ":%1" ).arg( anIndex );
527 aName = tr( "GEOM_MEN_POPUP_NAME" ).arg( anIndexes.Extent() );
529 myEditCurrentArgument->setText( aName );
530 int aConstructorId = getConstructorId();
531 if ( aConstructorId == 2)
533 else if (aConstructorId == 3)
547 //=================================================================================
548 // function : LineEditReturnPressed()
550 //=================================================================================
551 void OperationGUI_ChamferDlg::LineEditReturnPressed()
553 QLineEdit* aSender = ( QLineEdit* )sender();
555 QMap< int, QLineEdit* >::iterator anIterLE;
556 for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
557 if ( anIterLE.data() == aSender )
558 myEditCurrentArgument = anIterLE.data();
560 GEOMBase_Skeleton::LineEditReturnPressed();
563 //=================================================================================
564 // function : RadioButtonPressed()
566 //=================================================================================
567 void OperationGUI_ChamferDlg::RadioButtonPressed()
570 flag = ( myRadioButton[ RadioButton21 ]->isChecked() &&
571 myRadioButton[ RadioButton31 ]->isChecked() &&
572 myRadioButton[ RadioButton41 ]->isChecked() );
574 myRadioButton[ RadioButton21 ]->setChecked(!flag);
575 myRadioButton[ RadioButton31 ]->setChecked(!flag);
576 myRadioButton[ RadioButton41 ]->setChecked(!flag);
577 myRadioButton[ RadioButton22 ]->setChecked(flag);
578 myRadioButton[ RadioButton32 ]->setChecked(flag);
579 myRadioButton[ RadioButton42 ]->setChecked(flag);
580 mySpinBox[ SpinBox21 ]->setDisabled(flag);
581 mySpinBox[ SpinBox22 ]->setDisabled(flag);
582 mySpinBox[ SpinBox31 ]->setDisabled(flag);
583 mySpinBox[ SpinBox32 ]->setDisabled(flag);
584 mySpinBox[ SpinBox41 ]->setDisabled(flag);
585 mySpinBox[ SpinBox42 ]->setDisabled(flag);
586 mySpinBox[ SpinBox23 ]->setDisabled(!flag);
587 mySpinBox[ SpinBox24 ]->setDisabled(!flag);
588 mySpinBox[ SpinBox33 ]->setDisabled(!flag);
589 mySpinBox[ SpinBox34 ]->setDisabled(!flag);
590 mySpinBox[ SpinBox43 ]->setDisabled(!flag);
591 mySpinBox[ SpinBox44 ]->setDisabled(!flag);
596 //=================================================================================
597 // function : SetEditCurrentArgument()
599 //=================================================================================
600 void OperationGUI_ChamferDlg::SetEditCurrentArgument()
602 QPushButton* aSender = ( QPushButton* )sender();
604 QMap< int, QPushButton* >::iterator anIter;
605 for ( anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter )
606 if ( anIter.data() == aSender )
608 mySelName[ anIter.key() ]->setFocus();
609 myEditCurrentArgument = mySelName[ anIter.key() ];
616 //=================================================================================
617 // function : ActivateThisDialog()
619 //=================================================================================
620 void OperationGUI_ChamferDlg::ActivateThisDialog()
622 GEOMBase_Skeleton::ActivateThisDialog();
624 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
625 SIGNAL(currentSelectionChanged()), this, SLOT( SelectionIntoArgument() ) );
632 //=================================================================================
633 // function : enterEvent()
635 //=================================================================================
636 void OperationGUI_ChamferDlg::enterEvent(QEvent* e)
638 if ( !GroupConstructors->isEnabled() )
639 this->ActivateThisDialog();
643 //=================================================================================
644 // function : ValueChangedInSpinBox()
646 //=================================================================================
647 void OperationGUI_ChamferDlg::ValueChangedInSpinBox( double newValue )
653 //=================================================================================
654 // function : createSelWg()
656 //=================================================================================
657 void OperationGUI_ChamferDlg::createSelWg( const QString& theLbl,
662 new QLabel( theLbl, theParent );
663 mySelBtn[ theId ] = new QPushButton( theParent );
664 mySelBtn[ theId ]->setPixmap( thePix );
665 mySelName[ theId ] = new QLineEdit( theParent );
666 mySelName[ theId ]->setReadOnly( true );
669 //=================================================================================
670 // function : reset()
672 //=================================================================================
673 void OperationGUI_ChamferDlg::reset()
675 // Set Initial values of spinboxes
676 QMap< int, DlgRef_SpinBox* >::iterator anIter;
677 for ( anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter )
678 anIter.data()->SetValue( 5 );
681 QMap< int, QLineEdit* >::iterator anIterLE;
682 for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
683 anIterLE.data()->setText( "" );
686 int aConstructorId = getConstructorId();
688 if ( aConstructorId == 0 ) myEditCurrentArgument = mySelName[ MainObj1 ];
689 else if ( aConstructorId == 1 ) myEditCurrentArgument = mySelName[ MainObj2 ];
690 else if ( aConstructorId == 2 ) myEditCurrentArgument = mySelName[ MainObj3 ];
691 else myEditCurrentArgument = mySelName[ MainObj4 ];
693 myShape = GEOM::GEOM_Object::_nil();
697 myFace[ Face1 ] = -1;
698 myFace[ Face2 ] = -1;
700 erasePreview( true );
707 //=================================================================================
708 // function : getConstructorId()
710 //=================================================================================
711 int OperationGUI_ChamferDlg::getConstructorId() const
713 return GroupConstructors->id( GroupConstructors->selected() );
716 //=================================================================================
717 // function : activateSelection
718 // purpose : Activate selection in accordance with myEditCurrentArgument
719 //=================================================================================
720 void OperationGUI_ChamferDlg::activateSelection()
722 if ( !myShape->_is_nil() &&
723 ( myEditCurrentArgument == mySelName[ Face1 ] ||
724 myEditCurrentArgument == mySelName[ Face2 ] ||
725 myEditCurrentArgument == mySelName[ Faces ] ) )
726 localSelection( myShape, TopAbs_FACE );
727 else if (!myShape->_is_nil() && myEditCurrentArgument == mySelName[ Edges ] )
728 localSelection( myShape, TopAbs_EDGE );
731 TColStd_MapOfInteger aMap;
732 aMap.Add( GEOM_SHELL );
733 aMap.Add( GEOM_SOLID );
734 aMap.Add( GEOM_COMPOUND );
735 globalSelection( aMap );
738 SelectionIntoArgument();
741 //=================================================================================
742 // function : enableWidgets
743 // purpose : Enable widgets of faces in accordance with value of main object
744 //=================================================================================
745 void OperationGUI_ChamferDlg::enableWidgets()
747 int anId = getConstructorId();
749 bool toEnable = !myShape->_is_nil();
753 mySelName[ Face1 ]->setEnabled( toEnable );
754 mySelName[ Face2 ]->setEnabled( toEnable );
755 mySelBtn[ Face1 ]->setEnabled( toEnable );
756 mySelBtn[ Face2 ]->setEnabled( toEnable );
760 mySelName[ Face1 ]->setText( "" );
761 mySelName[ Face2 ]->setText( "" );
762 myFace[ Face1 ] = -1;
763 myFace[ Face2 ] = -1;
766 else if ( anId == 2 )
768 mySelName[ Faces ]->setEnabled( toEnable );
771 mySelName[ Faces ]->setText( "" );
775 else if ( anId == 3 )
777 mySelName[ Edges ]->setEnabled( toEnable );
781 mySelName[ Edges ]->setText( "" );
787 //=================================================================================
788 // function : createOperation
790 //=================================================================================
791 GEOM::GEOM_IOperations_ptr OperationGUI_ChamferDlg::createOperation()
793 return getGeomEngine()->GetILocalOperations( getStudyId() );
795 //=================================================================================
796 // function : ClickOnApply()
797 // purpose : Verify validity of input data
798 //=================================================================================
799 bool OperationGUI_ChamferDlg::isValid( QString& )
801 switch ( getConstructorId() )
803 case 0: return !myShape->_is_nil();
804 case 1: return !myShape->_is_nil() && myFace[ Face1 ] > 0 && myFace[ Face2 ] > 0;
805 case 2: return !myShape->_is_nil() && myFaces.Extent() > 0;
806 case 3: return !myShape->_is_nil() && myEdges.Extent() > 0;
807 default: return false;
811 //=================================================================================
812 // function : execute
814 //=================================================================================
815 bool OperationGUI_ChamferDlg::execute( ObjectList& objects )
817 GEOM::GEOM_Object_var anObj;
818 bool flag = ( myRadioButton[ RadioButton21 ]->isChecked() &&
819 myRadioButton[ RadioButton31 ]->isChecked() &&
820 myRadioButton[ RadioButton41 ]->isChecked() );
822 int anId = getConstructorId();
824 anObj = GEOM::GEOM_ILocalOperations::_narrow(
825 getOperation() )->MakeChamferAll( myShape,
826 mySpinBox[ SpinBox1 ]->GetValue() );
827 else if ( anId == 1 )
830 anObj = GEOM::GEOM_ILocalOperations::_narrow(
831 getOperation() )->MakeChamferEdge( myShape,
832 mySpinBox[ SpinBox21 ]->GetValue(),
833 mySpinBox[ SpinBox22 ]->GetValue(),
837 anObj = GEOM::GEOM_ILocalOperations::_narrow(
838 getOperation() )->MakeChamferEdgeAD( myShape,
839 mySpinBox[ SpinBox23 ]->GetValue(),
840 mySpinBox[ SpinBox24 ]->GetValue() * PI180,
844 else if ( anId == 2 )
846 GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
847 anArray->length( myFaces.Extent() );
848 for ( int i = 1, n = myFaces.Extent(); i <= n; i++ )
849 anArray[ i - 1 ] = myFaces( i );
851 anObj = GEOM::GEOM_ILocalOperations::_narrow(
852 getOperation() )->MakeChamferFaces( myShape,
853 mySpinBox[ SpinBox31 ]->GetValue(),
854 mySpinBox[ SpinBox32 ]->GetValue(),
857 anObj = GEOM::GEOM_ILocalOperations::_narrow(
858 getOperation() )->MakeChamferFacesAD( myShape,
859 mySpinBox[ SpinBox33 ]->GetValue(),
860 mySpinBox[ SpinBox34 ]->GetValue() * PI180,
863 else if ( anId == 3 )
865 GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
866 anArray->length( myEdges.Extent() );
867 for ( int i = 1, n = myEdges.Extent(); i <= n; i++ )
868 anArray[ i - 1 ] = myEdges( i );
870 anObj = GEOM::GEOM_ILocalOperations::_narrow(
871 getOperation() )->MakeChamferEdges( myShape, mySpinBox[ SpinBox41 ]->GetValue(),
872 mySpinBox[ SpinBox42 ]->GetValue(), anArray );
874 anObj = GEOM::GEOM_ILocalOperations::_narrow(
875 getOperation() )->MakeChamferEdgesAD( myShape, mySpinBox[ SpinBox43 ]->GetValue(),
876 mySpinBox[ SpinBox44 ]->GetValue() * PI180, anArray );
879 if ( !anObj->_is_nil() )
880 objects.push_back( anObj._retn() );