1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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
24 // File : OperationGUI_ChamferDlg.cxx
25 // Author : Damien COQUERET
29 #include "OperationGUI_ChamferDlg.h"
30 #include "DlgRef_SpinBox.h"
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"
38 #include <TColStd_MapOfInteger.hxx>
44 #include "GEOMImpl_Types.hxx"
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)
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")));
61 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_FACE")));
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 );
74 myGrp1 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_ALL" ), this );
76 QGroupBox* aSelGrp1 = new QGroupBox( 3, Qt::Horizontal, myGrp1 );
77 aSelGrp1->setFrameStyle( QFrame::NoFrame );
78 aSelGrp1->setInsideMargin( 0 );
80 createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp1, MainObj1 );
82 QGroupBox* aSpinGrp = new QGroupBox( 1, Qt::Vertical, myGrp1 );
83 aSpinGrp->setFrameStyle( QFrame::NoFrame );
84 aSpinGrp->setInsideMargin( 0 );
86 new QLabel( tr( "D" ), aSpinGrp );
87 mySpinBox[ SpinBox1 ] = new DlgRef_SpinBox( aSpinGrp );
89 ( new QFrame( myGrp1 ) )->setSizePolicy(
90 QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
92 // Create second group
94 myGrp2 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_EDGES" ), this );
96 QGroupBox* aSelGrp2 = new QGroupBox( 3, Qt::Horizontal, myGrp2 );
97 aSelGrp2->setFrameStyle( QFrame::NoFrame );
98 aSelGrp2->setInsideMargin( 0 );
100 createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp2, MainObj2 );
101 createSelWg( tr( "FACE_1" ), iconSelect, aSelGrp2, Face1 );
102 createSelWg( tr( "FACE_2" ), iconSelect, aSelGrp2, Face2 );
104 aSpinGrp = new QGroupBox( 1, Qt::Vertical, myGrp2 );
105 aSpinGrp->setFrameStyle( QFrame::NoFrame );
106 aSpinGrp->setInsideMargin( 0 );
108 new QLabel( tr( "GEOM_D1" ), aSpinGrp );
109 mySpinBox[ SpinBox21 ] = new DlgRef_SpinBox( aSpinGrp );
111 new QLabel( tr( "GEOM_D2" ), aSpinGrp );
112 mySpinBox[ SpinBox22 ] = new DlgRef_SpinBox( aSpinGrp );
114 // Create third group
116 myGrp3 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_FACES" ), this );
118 QGroupBox* aSelGrp3 = new QGroupBox( 3, Qt::Horizontal, myGrp3 );
119 aSelGrp3->setFrameStyle( QFrame::NoFrame );
120 aSelGrp3->setInsideMargin( 0 );
122 createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp3, MainObj3 );
123 createSelWg( tr( "SELECTED_FACES" ), iconSelect, aSelGrp3, Faces );
125 aSpinGrp = new QGroupBox( 1, Qt::Vertical, myGrp3 );
126 aSpinGrp->setFrameStyle( QFrame::NoFrame );
127 aSpinGrp->setInsideMargin( 0 );
129 new QLabel( tr( "GEOM_D1" ), aSpinGrp );
130 mySpinBox[ SpinBox31 ] = new DlgRef_SpinBox( aSpinGrp );
132 new QLabel( tr( "GEOM_D2" ), aSpinGrp );
133 mySpinBox[ SpinBox32 ] = new DlgRef_SpinBox( aSpinGrp );
135 ( new QLabel( myGrp3 ) )->setSizePolicy(
136 QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
138 // Add groups to layout
140 Layout1->addWidget( myGrp1, 2, 0 );
141 Layout1->addWidget( myGrp2, 2, 0 );
142 Layout1->addWidget( myGrp3, 2, 0 );
144 // Set range of spinboxes
146 double SpecificStep = 10.0;
147 QMap< int, DlgRef_SpinBox* >::iterator anIter;
148 for ( anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter )
149 anIter.data()->RangeStepAndValidator( 0.001, 999.999, SpecificStep, 3 );
151 setHelpFileName("chamfer.htm");
153 /* Initialisations */
158 //=================================================================================
159 // function : ~OperationGUI_ChamferDlg()
160 // purpose : Destroys the object and frees any allocated resources
161 //=================================================================================
162 OperationGUI_ChamferDlg::~OperationGUI_ChamferDlg()
167 //=================================================================================
170 //=================================================================================
171 void OperationGUI_ChamferDlg::Init()
173 myConstructorId = -1;
175 RadioButton1->setChecked( true );
176 myEditCurrentArgument = mySelName[ MainObj1 ];
178 /* signals and slots connections */
181 connect( buttonOk , SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
182 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
185 connect( GroupConstructors, SIGNAL( clicked( int ) ),
186 this, SLOT( ConstructorsClicked( int ) ) );
189 QMap< int, QPushButton* >::iterator anIterBtn;
190 for ( anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn )
191 connect( anIterBtn.data(), SIGNAL( clicked() ),
192 this, SLOT( SetEditCurrentArgument() ) );
195 QMap< int, QLineEdit* >::iterator anIterLE2;
196 for ( anIterLE2 = mySelName.begin(); anIterLE2 != mySelName.end(); ++anIterLE2 )
197 connect( anIterLE2.data(), SIGNAL( returnPressed() ),
198 this, SLOT( LineEditReturnPressed() ) );
201 QMap< int, DlgRef_SpinBox* >::iterator anIterSpin;
202 for ( anIterSpin = mySpinBox.begin(); anIterSpin != mySpinBox.end(); ++anIterSpin )
203 connect( anIterSpin.data(), SIGNAL( valueChanged( double ) ),
204 this, SLOT( ValueChangedInSpinBox( double ) ) );
207 connect(myGeomGUI->getApp()->selectionMgr(),
208 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
210 initName( tr( "GEOM_CHAMFER" ) );
218 //=================================================================================
219 // function : ConstructorsClicked()
220 // purpose : Radio button management
221 //=================================================================================
222 void OperationGUI_ChamferDlg::ConstructorsClicked( int constructorId )
224 // Activate next widget
225 if (myGeomGUI->getApp()->desktop()->activeWindow()->getViewManager()->getType()
226 != OCCViewer_Viewer::Type())
228 RadioButton1->setChecked( true );
232 if (myConstructorId == constructorId)
235 // Get values from previous widget
236 double D1 = 5, D2 = 5;
237 if ( myConstructorId == 0 )
238 D1 = D2 = mySpinBox[ SpinBox1 ]->GetValue();
239 else if ( myConstructorId == 1 )
241 D1 = mySpinBox[ SpinBox21 ]->GetValue();
242 D2 = mySpinBox[ SpinBox22 ]->GetValue();
244 else if ( myConstructorId == 2 )
246 D1 = mySpinBox[ SpinBox31 ]->GetValue();
247 D2 = mySpinBox[ SpinBox32 ]->GetValue();
250 myConstructorId = constructorId;
252 switch ( constructorId )
258 mySpinBox[ SpinBox1 ]->SetValue( D1 );
264 mySpinBox[ SpinBox21 ]->SetValue( D1 );
265 mySpinBox[ SpinBox22 ]->SetValue( D2 );
271 mySpinBox[ SpinBox31 ]->SetValue( D1 );
272 mySpinBox[ SpinBox32 ]->SetValue( D2 );
278 if ( constructorId == 0 ) myEditCurrentArgument = mySelName[ MainObj1 ];
279 else if ( constructorId == 1 ) myEditCurrentArgument = mySelName[ MainObj2 ];
280 else myEditCurrentArgument = mySelName[ MainObj3 ];
285 if ( !myShape->_is_nil() )
287 myEditCurrentArgument->setText( GEOMBase::GetName( myShape ) );
288 GEOMBase_Skeleton::LineEditReturnPressed();
291 myEditCurrentArgument->setText( "" );
297 //=================================================================================
298 // function : ClickOnOk()
300 //=================================================================================
301 void OperationGUI_ChamferDlg::ClickOnOk()
303 if ( ClickOnApply() )
307 //=================================================================================
308 // function : ClickOnApply()
310 //=================================================================================
311 bool OperationGUI_ChamferDlg::ClickOnApply()
321 //=================================================================================
322 // function : SelectionIntoArgument()
323 // purpose : Called when selection has changed
324 //=================================================================================
325 void OperationGUI_ChamferDlg::SelectionIntoArgument()
328 myEditCurrentArgument->setText( "" );
330 // Get index of current selection focus
332 QMap< int, QLineEdit* >::iterator anIter;
333 for ( anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter )
334 if ( myEditCurrentArgument == anIter.data() )
336 aCurrFocus = anIter.key();
340 // If selection of main object is activated
341 if ( aCurrFocus == MainObj1 || aCurrFocus == MainObj2 || aCurrFocus == MainObj3 )
343 if ( IObjectCount() == 1 )
345 Standard_Boolean aResult = Standard_False;
346 GEOM::GEOM_Object_var anObj =
347 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
349 if ( aResult && !anObj->_is_nil() )
352 mySelName[ aCurrFocus ]->setText( GEOMBase::GetName( anObj ) );
359 myShape = GEOM::GEOM_Object::_nil();
362 // If face selection of second tab is activated
363 else if ( aCurrFocus == Face1 || aCurrFocus == Face2 )
365 if ( IObjectCount() == 1 )
367 Standard_Boolean aResult = Standard_False;
368 GEOM::GEOM_Object_var anObj =
369 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
371 if ( aResult && !anObj->_is_nil() )
373 TColStd_IndexedMapOfInteger anIndexes;
374 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
376 if ( anIndexes.Extent() == 1 )
378 int anIndex = anIndexes( 1 );
379 QString aFaceName = QString( GEOMBase::GetName( anObj ) ) + ":%1";
380 myEditCurrentArgument->setText( aFaceName.arg( anIndex ) );
381 myFace[ aCurrFocus ] = anIndex;
388 myFace[ aCurrFocus ] = -1;
390 // If face selection of third tab is activated
391 else if ( aCurrFocus == Faces )
393 if ( IObjectCount() == 1 )
395 Standard_Boolean aResult = Standard_False;
396 GEOM::GEOM_Object_var anObj =
397 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
399 if ( aResult && !anObj->_is_nil() )
401 TColStd_IndexedMapOfInteger anIndexes;
402 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
404 if ( anIndexes.Extent() > 0 )
407 if ( anIndexes.Extent() == 1 )
409 int anIndex = anIndexes( 1 );
411 aFaceName = QString( GEOMBase::GetName( anObj ) ) + QString( ":%1" ).arg( anIndex );
414 aFaceName = tr( "GEOM_MEN_POPUP_NAME" ).arg( anIndexes.Extent() );
416 myEditCurrentArgument->setText( aFaceName );
428 //=================================================================================
429 // function : LineEditReturnPressed()
431 //=================================================================================
432 void OperationGUI_ChamferDlg::LineEditReturnPressed()
434 QLineEdit* aSender = ( QLineEdit* )sender();
436 QMap< int, QLineEdit* >::iterator anIterLE;
437 for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
438 if ( anIterLE.data() == aSender )
439 myEditCurrentArgument = anIterLE.data();
441 GEOMBase_Skeleton::LineEditReturnPressed();
445 //=================================================================================
446 // function : SetEditCurrentArgument()
448 //=================================================================================
449 void OperationGUI_ChamferDlg::SetEditCurrentArgument()
451 QPushButton* aSender = ( QPushButton* )sender();
453 QMap< int, QPushButton* >::iterator anIter;
454 for ( anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter )
455 if ( anIter.data() == aSender )
457 mySelName[ anIter.key() ]->setFocus();
458 myEditCurrentArgument = mySelName[ anIter.key() ];
465 //=================================================================================
466 // function : ActivateThisDialog()
468 //=================================================================================
469 void OperationGUI_ChamferDlg::ActivateThisDialog()
471 GEOMBase_Skeleton::ActivateThisDialog();
473 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
474 SIGNAL(currentSelectionChanged()), this, SLOT( SelectionIntoArgument() ) );
481 //=================================================================================
482 // function : enterEvent()
484 //=================================================================================
485 void OperationGUI_ChamferDlg::enterEvent(QEvent* e)
487 if ( !GroupConstructors->isEnabled() )
488 this->ActivateThisDialog();
492 //=================================================================================
493 // function : ValueChangedInSpinBox()
495 //=================================================================================
496 void OperationGUI_ChamferDlg::ValueChangedInSpinBox( double newValue )
502 //=================================================================================
503 // function : createSelWg()
505 //=================================================================================
506 void OperationGUI_ChamferDlg::createSelWg( const QString& theLbl,
511 new QLabel( theLbl, theParent );
512 mySelBtn[ theId ] = new QPushButton( theParent );
513 mySelBtn[ theId ]->setPixmap( thePix );
514 mySelName[ theId ] = new QLineEdit( theParent );
515 mySelName[ theId ]->setReadOnly( true );
518 //=================================================================================
519 // function : reset()
521 //=================================================================================
522 void OperationGUI_ChamferDlg::reset()
524 // Set Initial values of spinboxes
525 QMap< int, DlgRef_SpinBox* >::iterator anIter;
526 for ( anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter )
527 anIter.data()->SetValue( 5 );
530 QMap< int, QLineEdit* >::iterator anIterLE;
531 for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
532 anIterLE.data()->setText( "" );
535 int aConstructorId = getConstructorId();
537 if ( aConstructorId == 0 ) myEditCurrentArgument = mySelName[ MainObj1 ];
538 else if ( aConstructorId == 1 ) myEditCurrentArgument = mySelName[ MainObj2 ];
539 else myEditCurrentArgument = mySelName[ MainObj3 ];
541 myShape = GEOM::GEOM_Object::_nil();
544 myFace[ Face1 ] = -1;
545 myFace[ Face2 ] = -1;
547 erasePreview( true );
554 //=================================================================================
555 // function : getConstructorId()
557 //=================================================================================
558 int OperationGUI_ChamferDlg::getConstructorId() const
560 return GroupConstructors->id( GroupConstructors->selected() );
563 //=================================================================================
564 // function : activateSelection
565 // purpose : Activate selection in accordance with myEditCurrentArgument
566 //=================================================================================
567 void OperationGUI_ChamferDlg::activateSelection()
569 if ( !myShape->_is_nil() &&
570 ( myEditCurrentArgument == mySelName[ Face1 ] ||
571 myEditCurrentArgument == mySelName[ Face2 ] ||
572 myEditCurrentArgument == mySelName[ Faces ] ) )
573 localSelection( myShape, TopAbs_FACE );
576 TColStd_MapOfInteger aMap;
577 aMap.Add( GEOM_SHELL );
578 aMap.Add( GEOM_SOLID );
579 aMap.Add( GEOM_COMPOUND );
580 globalSelection( aMap );
583 SelectionIntoArgument();
586 //=================================================================================
587 // function : enableWidgets
588 // purpose : Enable widgets of faces in accordance with value of main object
589 //=================================================================================
590 void OperationGUI_ChamferDlg::enableWidgets()
592 int anId = getConstructorId();
594 bool toEnable = !myShape->_is_nil();
598 mySelName[ Face1 ]->setEnabled( toEnable );
599 mySelName[ Face2 ]->setEnabled( toEnable );
600 mySelBtn[ Face1 ]->setEnabled( toEnable );
601 mySelBtn[ Face2 ]->setEnabled( toEnable );
605 mySelName[ Face1 ]->setText( "" );
606 mySelName[ Face2 ]->setText( "" );
607 myFace[ Face1 ] = -1;
608 myFace[ Face2 ] = -1;
611 else if ( anId == 2 )
613 mySelName[ Faces ]->setEnabled( toEnable );
620 //=================================================================================
621 // function : createOperation
623 //=================================================================================
624 GEOM::GEOM_IOperations_ptr OperationGUI_ChamferDlg::createOperation()
626 return getGeomEngine()->GetILocalOperations( getStudyId() );
629 //=================================================================================
630 // function : ClickOnApply()
631 // purpose : Verify validity of input data
632 //=================================================================================
633 bool OperationGUI_ChamferDlg::isValid( QString& )
635 switch ( getConstructorId() )
637 case 0: return !myShape->_is_nil();
638 case 1: return !myShape->_is_nil() && myFace[ Face1 ] > 0 && myFace[ Face2 ] > 0;
639 case 2: return !myShape->_is_nil() && myFaces.Extent() > 0;
640 default: return false;
644 //=================================================================================
645 // function : execute
647 //=================================================================================
648 bool OperationGUI_ChamferDlg::execute( ObjectList& objects )
650 GEOM::GEOM_Object_var anObj;
652 int anId = getConstructorId();
654 anObj = GEOM::GEOM_ILocalOperations::_narrow(
655 getOperation() )->MakeChamferAll( myShape,
656 mySpinBox[ SpinBox1 ]->GetValue() );
657 else if ( anId == 1 )
658 anObj = GEOM::GEOM_ILocalOperations::_narrow(
659 getOperation() )->MakeChamferEdge( myShape,
660 mySpinBox[ SpinBox21 ]->GetValue(),
661 mySpinBox[ SpinBox22 ]->GetValue(),
664 else if ( anId == 2 )
668 GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
669 anArray->length( myFaces.Extent() );
672 for ( int i = 1, n = myFaces.Extent(); i <= n; i++ )
673 anArray[ i - 1 ] = myFaces( i );
675 anObj = GEOM::GEOM_ILocalOperations::_narrow(
676 getOperation() )->MakeChamferFaces( myShape,
677 mySpinBox[ SpinBox31 ]->GetValue(),
678 mySpinBox[ SpinBox32 ]->GetValue(),
683 if ( !anObj->_is_nil() )
684 objects.push_back( anObj._retn() );