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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : OperationGUI_ChamferDlg.cxx
25 // Author : Damien COQUERET
30 #include "OperationGUI_ChamferDlg.h"
31 #include "DlgRef_SpinBox.h"
32 #include "QAD_Desktop.h"
36 #include "GEOMImpl_Types.hxx"
38 //=================================================================================
39 // class : OperationGUI_ChamferDlg()
40 // purpose : Constructs a OperationGUI_ChamferDlg which is a child of 'parent', with the
41 // name 'name' and widget flags set to 'f'.
42 // The dialog will by default be modeless, unless you set 'modal' to
43 // TRUE to construct a modal dialog.
44 //=================================================================================
45 OperationGUI_ChamferDlg::OperationGUI_ChamferDlg( QWidget* parent, SALOME_Selection* Sel )
46 : GEOMBase_Skeleton(parent, "ChamferDlg", Sel, false,
47 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
53 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_ALL")));
54 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_EDGE")));
55 QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CHAMFER_FACE")));
56 QPixmap iconSelect(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption( tr( "GEOM_CHAMFER_TITLE" ) );
60 GroupConstructors->setTitle( tr( "GEOM_CHAMFER" ) );
62 RadioButton1->setPixmap( image1 );
63 RadioButton2->setPixmap( image2 );
64 RadioButton3->setPixmap( image3 );
68 myGrp1 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_ALL" ), this );
70 QGroupBox* aSelGrp1 = new QGroupBox( 3, Qt::Horizontal, myGrp1 );
71 aSelGrp1->setFrameStyle( QFrame::NoFrame );
72 aSelGrp1->setInsideMargin( 0 );
74 createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp1, MainObj1 );
76 QGroupBox* aSpinGrp = new QGroupBox( 1, Qt::Vertical, myGrp1 );
77 aSpinGrp->setFrameStyle( QFrame::NoFrame );
78 aSpinGrp->setInsideMargin( 0 );
80 new QLabel( tr( "D" ), aSpinGrp );
81 mySpinBox[ SpinBox1 ] = new DlgRef_SpinBox( aSpinGrp );
83 ( new QFrame( myGrp1 ) )->setSizePolicy(
84 QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
86 // Create second group
88 myGrp2 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_EDGES" ), this );
90 QGroupBox* aSelGrp2 = new QGroupBox( 3, Qt::Horizontal, myGrp2 );
91 aSelGrp2->setFrameStyle( QFrame::NoFrame );
92 aSelGrp2->setInsideMargin( 0 );
94 createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp2, MainObj2 );
95 createSelWg( tr( "FACE_1" ), iconSelect, aSelGrp2, Face1 );
96 createSelWg( tr( "FACE_2" ), iconSelect, aSelGrp2, Face2 );
98 aSpinGrp = new QGroupBox( 1, Qt::Vertical, myGrp2 );
99 aSpinGrp->setFrameStyle( QFrame::NoFrame );
100 aSpinGrp->setInsideMargin( 0 );
102 new QLabel( tr( "GEOM_D1" ), aSpinGrp );
103 mySpinBox[ SpinBox21 ] = new DlgRef_SpinBox( aSpinGrp );
105 new QLabel( tr( "GEOM_D2" ), aSpinGrp );
106 mySpinBox[ SpinBox22 ] = new DlgRef_SpinBox( aSpinGrp );
108 // Create third group
110 myGrp3 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_FACES" ), this );
112 QGroupBox* aSelGrp3 = new QGroupBox( 3, Qt::Horizontal, myGrp3 );
113 aSelGrp3->setFrameStyle( QFrame::NoFrame );
114 aSelGrp3->setInsideMargin( 0 );
116 createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp3, MainObj3 );
117 createSelWg( tr( "SELECTED_FACES" ), iconSelect, aSelGrp3, Faces );
119 aSpinGrp = new QGroupBox( 1, Qt::Vertical, myGrp3 );
120 aSpinGrp->setFrameStyle( QFrame::NoFrame );
121 aSpinGrp->setInsideMargin( 0 );
123 new QLabel( tr( "GEOM_D1" ), aSpinGrp );
124 mySpinBox[ SpinBox31 ] = new DlgRef_SpinBox( aSpinGrp );
126 new QLabel( tr( "GEOM_D2" ), aSpinGrp );
127 mySpinBox[ SpinBox32 ] = new DlgRef_SpinBox( aSpinGrp );
129 ( new QLabel( myGrp3 ) )->setSizePolicy(
130 QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
132 // Add groups to layout
134 Layout1->addWidget( myGrp1, 2, 0 );
135 Layout1->addWidget( myGrp2, 2, 0 );
136 Layout1->addWidget( myGrp3, 2, 0 );
138 // Set range of spinboxes
140 double SpecificStep = 10.0;
141 QMap< int, DlgRef_SpinBox* >::iterator anIter;
142 for ( anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter )
143 anIter.data()->RangeStepAndValidator( 0.001, 999.999, SpecificStep, 3 );
145 /* Initialisations */
150 //=================================================================================
151 // function : ~OperationGUI_ChamferDlg()
152 // purpose : Destroys the object and frees any allocated resources
153 //=================================================================================
154 OperationGUI_ChamferDlg::~OperationGUI_ChamferDlg()
159 //=================================================================================
162 //=================================================================================
163 void OperationGUI_ChamferDlg::Init( SALOME_Selection* Sel )
166 myConstructorId = -1;
168 RadioButton1->setChecked( true );
169 myEditCurrentArgument = mySelName[ MainObj1 ];
171 /* signals and slots connections */
174 connect( buttonOk , SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
175 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
178 connect( GroupConstructors, SIGNAL( clicked( int ) ),
179 this, SLOT( ConstructorsClicked( int ) ) );
182 QMap< int, QPushButton* >::iterator anIterBtn;
183 for ( anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn )
184 connect( anIterBtn.data(), SIGNAL( clicked() ),
185 this, SLOT( SetEditCurrentArgument() ) );
188 QMap< int, QLineEdit* >::iterator anIterLE2;
189 for ( anIterLE2 = mySelName.begin(); anIterLE2 != mySelName.end(); ++anIterLE2 )
190 connect( anIterLE2.data(), SIGNAL( returnPressed() ),
191 this, SLOT( LineEditReturnPressed() ) );
194 QMap< int, DlgRef_SpinBox* >::iterator anIterSpin;
195 for ( anIterSpin = mySpinBox.begin(); anIterSpin != mySpinBox.end(); ++anIterSpin )
196 connect( anIterSpin.data(), SIGNAL( valueChanged( double ) ),
197 this, SLOT( ValueChangedInSpinBox( double ) ) );
200 connect( mySelection, SIGNAL( currentSelectionChanged() ),
201 this, SLOT( SelectionIntoArgument() ) );
203 initName( tr( "GEOM_CHAMFER" ) );
213 //=================================================================================
214 // function : ConstructorsClicked()
215 // purpose : Radio button management
216 //=================================================================================
217 void OperationGUI_ChamferDlg::ConstructorsClicked( int constructorId )
219 // Activate next widget
220 if ( QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC )
222 RadioButton1->setChecked( true );
226 if ( myConstructorId == constructorId )
229 // Get values from previous widget
230 double D1 = 5, D2 = 5;
231 if ( myConstructorId == 0 )
232 D1 = D2 = mySpinBox[ SpinBox1 ]->GetValue();
233 else if ( myConstructorId == 1 )
235 D1 = mySpinBox[ SpinBox21 ]->GetValue();
236 D2 = mySpinBox[ SpinBox22 ]->GetValue();
238 else if ( myConstructorId == 2 )
240 D1 = mySpinBox[ SpinBox31 ]->GetValue();
241 D2 = mySpinBox[ SpinBox32 ]->GetValue();
244 myConstructorId = constructorId;
246 switch ( constructorId )
252 mySpinBox[ SpinBox1 ]->SetValue( D1 );
258 mySpinBox[ SpinBox21 ]->SetValue( D1 );
259 mySpinBox[ SpinBox22 ]->SetValue( D2 );
265 mySpinBox[ SpinBox31 ]->SetValue( D1 );
266 mySpinBox[ SpinBox32 ]->SetValue( D2 );
272 if ( constructorId == 0 ) myEditCurrentArgument = mySelName[ MainObj1 ];
273 else if ( constructorId == 1 ) myEditCurrentArgument = mySelName[ MainObj2 ];
274 else myEditCurrentArgument = mySelName[ MainObj3 ];
279 if ( !myShape->_is_nil() )
281 myEditCurrentArgument->setText( GEOMBase::GetName( myShape ) );
282 GEOMBase_Skeleton::LineEditReturnPressed();
285 myEditCurrentArgument->setText( "" );
291 //=================================================================================
292 // function : ClickOnOk()
294 //=================================================================================
295 void OperationGUI_ChamferDlg::ClickOnOk()
297 if ( ClickOnApply() )
301 //=================================================================================
302 // function : ClickOnApply()
304 //=================================================================================
305 bool OperationGUI_ChamferDlg::ClickOnApply()
315 //=================================================================================
316 // function : SelectionIntoArgument()
317 // purpose : Called when selection has changed
318 //=================================================================================
319 void OperationGUI_ChamferDlg::SelectionIntoArgument()
322 myEditCurrentArgument->setText( "" );
324 // Get index of current selection focus
326 QMap< int, QLineEdit* >::iterator anIter;
327 for ( anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter )
328 if ( myEditCurrentArgument == anIter.data() )
330 aCurrFocus = anIter.key();
334 // If selection of main object is activated
335 if ( aCurrFocus == MainObj1 || aCurrFocus == MainObj2 || aCurrFocus == MainObj3 )
337 if ( mySelection->IObjectCount() == 1 )
339 Standard_Boolean aResult = Standard_False;
340 GEOM::GEOM_Object_var anObj =
341 GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aResult );
343 if ( aResult && !anObj->_is_nil() )
346 mySelName[ aCurrFocus ]->setText( GEOMBase::GetName( anObj ) );
353 myShape = GEOM::GEOM_Object::_nil();
356 // If face selection of second tab is activated
357 else if ( aCurrFocus == Face1 || aCurrFocus == Face2 )
359 if ( mySelection->IObjectCount() == 1 )
361 Standard_Boolean aResult = Standard_False;
362 GEOM::GEOM_Object_var anObj =
363 GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aResult );
365 if ( aResult && !anObj->_is_nil() )
367 TColStd_IndexedMapOfInteger anIndexes;
368 mySelection->GetIndex( mySelection->firstIObject(), anIndexes );
370 if ( anIndexes.Extent() == 1 )
372 int anIndex = anIndexes( 1 );
373 QString aFaceName = QString( GEOMBase::GetName( anObj ) ) + ":%1";
374 myEditCurrentArgument->setText( aFaceName.arg( anIndex ) );
375 myFace[ aCurrFocus ] = anIndex;
382 myFace[ aCurrFocus ] = -1;
384 // If face selection of third tab is activated
385 else if ( aCurrFocus == Faces )
387 if ( mySelection->IObjectCount() == 1 )
389 Standard_Boolean aResult = Standard_False;
390 GEOM::GEOM_Object_var anObj =
391 GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aResult );
393 if ( aResult && !anObj->_is_nil() )
395 TColStd_IndexedMapOfInteger anIndexes;
396 mySelection->GetIndex( mySelection->firstIObject(), anIndexes );
398 if ( anIndexes.Extent() > 0 )
401 if ( anIndexes.Extent() == 1 )
403 int anIndex = anIndexes( 1 );
405 aFaceName = QString( GEOMBase::GetName( anObj ) ) + QString( ":%1" ).arg( anIndex );
408 aFaceName = tr( "GEOM_MEN_POPUP_NAME" ).arg( anIndexes.Extent() );
410 myEditCurrentArgument->setText( aFaceName );
422 //=================================================================================
423 // function : LineEditReturnPressed()
425 //=================================================================================
426 void OperationGUI_ChamferDlg::LineEditReturnPressed()
428 QLineEdit* aSender = ( QLineEdit* )sender();
430 QMap< int, QLineEdit* >::iterator anIterLE;
431 for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
432 if ( anIterLE.data() == aSender )
433 myEditCurrentArgument = anIterLE.data();
435 GEOMBase_Skeleton::LineEditReturnPressed();
439 //=================================================================================
440 // function : SetEditCurrentArgument()
442 //=================================================================================
443 void OperationGUI_ChamferDlg::SetEditCurrentArgument()
445 QPushButton* aSender = ( QPushButton* )sender();
447 QMap< int, QPushButton* >::iterator anIter;
448 for ( anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter )
449 if ( anIter.data() == aSender )
451 mySelName[ anIter.key() ]->setFocus();
452 myEditCurrentArgument = mySelName[ anIter.key() ];
459 //=================================================================================
460 // function : DeactivateActiveDialog()
462 //=================================================================================
463 void OperationGUI_ChamferDlg::DeactivateActiveDialog()
465 // disconnect selection
466 GEOMBase_Skeleton::DeactivateActiveDialog();
470 //=================================================================================
471 // function : ActivateThisDialog()
473 //=================================================================================
474 void OperationGUI_ChamferDlg::ActivateThisDialog()
476 GEOMBase_Skeleton::ActivateThisDialog();
478 connect( mySelection, SIGNAL(currentSelectionChanged()),
479 this, SLOT( SelectionIntoArgument() ) );
486 //=================================================================================
487 // function : enterEvent()
489 //=================================================================================
490 void OperationGUI_ChamferDlg::enterEvent(QEvent* e)
492 if ( !GroupConstructors->isEnabled() )
493 this->ActivateThisDialog();
497 //=================================================================================
498 // function : ValueChangedInSpinBox()
500 //=================================================================================
501 void OperationGUI_ChamferDlg::ValueChangedInSpinBox( double newValue )
507 //=================================================================================
508 // function : createSelWg()
510 //=================================================================================
511 void OperationGUI_ChamferDlg::createSelWg( const QString& theLbl,
516 new QLabel( theLbl, theParent );
517 mySelBtn[ theId ] = new QPushButton( theParent );
518 mySelBtn[ theId ]->setPixmap( thePix );
519 mySelName[ theId ] = new QLineEdit( theParent );
520 mySelName[ theId ]->setReadOnly( true );
523 //=================================================================================
524 // function : reset()
526 //=================================================================================
527 void OperationGUI_ChamferDlg::reset()
529 // Set Initial values of spinboxes
530 QMap< int, DlgRef_SpinBox* >::iterator anIter;
531 for ( anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter )
532 anIter.data()->SetValue( 5 );
535 QMap< int, QLineEdit* >::iterator anIterLE;
536 for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
537 anIterLE.data()->setText( "" );
540 int aConstructorId = getConstructorId();
542 if ( aConstructorId == 0 ) myEditCurrentArgument = mySelName[ MainObj1 ];
543 else if ( aConstructorId == 1 ) myEditCurrentArgument = mySelName[ MainObj2 ];
544 else myEditCurrentArgument = mySelName[ MainObj3 ];
546 myShape = GEOM::GEOM_Object::_nil();
549 myFace[ Face1 ] = -1;
550 myFace[ Face2 ] = -1;
552 erasePreview( true );
559 //=================================================================================
560 // function : getConstructorId()
562 //=================================================================================
563 int OperationGUI_ChamferDlg::getConstructorId() const
565 return GroupConstructors->id( GroupConstructors->selected() );
568 //=================================================================================
569 // function : activateSelection
570 // purpose : Activate selection in accordance with myEditCurrentArgument
571 //=================================================================================
572 void OperationGUI_ChamferDlg::activateSelection()
574 if ( !myShape->_is_nil() &&
575 ( myEditCurrentArgument == mySelName[ Face1 ] ||
576 myEditCurrentArgument == mySelName[ Face2 ] ||
577 myEditCurrentArgument == mySelName[ Faces ] ) )
578 localSelection( myShape, TopAbs_FACE );
581 TColStd_MapOfInteger aMap;
582 aMap.Add( GEOM_SHELL );
583 aMap.Add( GEOM_SOLID );
584 aMap.Add( GEOM_COMPOUND );
585 globalSelection( aMap );
588 SelectionIntoArgument();
591 //=================================================================================
592 // function : enableWidgets
593 // purpose : Enable widgets of faces in accordance with value of main object
594 //=================================================================================
595 void OperationGUI_ChamferDlg::enableWidgets()
597 int anId = getConstructorId();
599 bool toEnable = !myShape->_is_nil();
603 mySelName[ Face1 ]->setEnabled( toEnable );
604 mySelName[ Face2 ]->setEnabled( toEnable );
605 mySelBtn[ Face1 ]->setEnabled( toEnable );
606 mySelBtn[ Face2 ]->setEnabled( toEnable );
610 mySelName[ Face1 ]->setText( "" );
611 mySelName[ Face2 ]->setText( "" );
612 myFace[ Face1 ] = -1;
613 myFace[ Face2 ] = -1;
616 else if ( anId == 2 )
618 mySelName[ Faces ]->setEnabled( toEnable );
625 //=================================================================================
626 // function : createOperation
628 //=================================================================================
629 GEOM::GEOM_IOperations_ptr OperationGUI_ChamferDlg::createOperation()
631 return getGeomEngine()->GetILocalOperations( getStudyId() );
634 //=================================================================================
635 // function : ClickOnApply()
636 // purpose : Verify validity of input data
637 //=================================================================================
638 bool OperationGUI_ChamferDlg::isValid( QString& )
640 switch ( getConstructorId() )
642 case 0: return !myShape->_is_nil();
643 case 1: return !myShape->_is_nil() && myFace[ Face1 ] > 0 && myFace[ Face2 ] > 0;
644 case 2: return !myShape->_is_nil() && myFaces.Extent() > 0;
645 default: return false;
649 //=================================================================================
650 // function : execute
652 //=================================================================================
653 bool OperationGUI_ChamferDlg::execute( ObjectList& objects )
655 GEOM::GEOM_Object_var anObj;
657 int anId = getConstructorId();
659 anObj = GEOM::GEOM_ILocalOperations::_narrow(
660 getOperation() )->MakeChamferAll( myShape,
661 mySpinBox[ SpinBox1 ]->GetValue() );
662 else if ( anId == 1 )
663 anObj = GEOM::GEOM_ILocalOperations::_narrow(
664 getOperation() )->MakeChamferEdge( myShape,
665 mySpinBox[ SpinBox21 ]->GetValue(),
666 mySpinBox[ SpinBox22 ]->GetValue(),
669 else if ( anId == 2 )
673 GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
674 anArray->length( myFaces.Extent() );
677 for ( int i = 1, n = myFaces.Extent(); i <= n; i++ )
678 anArray[ i - 1 ] = myFaces( i );
680 anObj = GEOM::GEOM_ILocalOperations::_narrow(
681 getOperation() )->MakeChamferFaces( myShape,
682 mySpinBox[ SpinBox31 ]->GetValue(),
683 mySpinBox[ SpinBox32 ]->GetValue(),
688 if ( !anObj->_is_nil() )
689 objects.push_back( anObj._retn() );