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"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_Session.h"
35 #include "SalomeApp_Application.h"
36 #include "SalomeApp_SelectionMgr.h"
37 #include "OCCViewer_ViewModel.h"
39 #include <TColStd_MapOfInteger.hxx>
45 #include "GEOMImpl_Types.hxx"
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)
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")));
65 setCaption( tr( "GEOM_CHAMFER_TITLE" ) );
67 GroupConstructors->setTitle( tr( "GEOM_CHAMFER" ) );
69 RadioButton1->setPixmap( image1 );
70 RadioButton2->setPixmap( image2 );
71 RadioButton3->setPixmap( image3 );
75 myGrp1 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_ALL" ), this );
77 QGroupBox* aSelGrp1 = new QGroupBox( 3, Qt::Horizontal, myGrp1 );
78 aSelGrp1->setFrameStyle( QFrame::NoFrame );
79 aSelGrp1->setInsideMargin( 0 );
81 createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp1, MainObj1 );
83 QGroupBox* aSpinGrp = new QGroupBox( 1, Qt::Vertical, myGrp1 );
84 aSpinGrp->setFrameStyle( QFrame::NoFrame );
85 aSpinGrp->setInsideMargin( 0 );
87 new QLabel( tr( "D" ), aSpinGrp );
88 mySpinBox[ SpinBox1 ] = new DlgRef_SpinBox( aSpinGrp );
90 ( new QFrame( myGrp1 ) )->setSizePolicy(
91 QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
93 // Create second group
95 myGrp2 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_EDGES" ), this );
97 QGroupBox* aSelGrp2 = new QGroupBox( 3, Qt::Horizontal, myGrp2 );
98 aSelGrp2->setFrameStyle( QFrame::NoFrame );
99 aSelGrp2->setInsideMargin( 0 );
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 );
105 aSpinGrp = new QGroupBox( 1, Qt::Vertical, myGrp2 );
106 aSpinGrp->setFrameStyle( QFrame::NoFrame );
107 aSpinGrp->setInsideMargin( 0 );
109 new QLabel( tr( "GEOM_D1" ), aSpinGrp );
110 mySpinBox[ SpinBox21 ] = new DlgRef_SpinBox( aSpinGrp );
112 new QLabel( tr( "GEOM_D2" ), aSpinGrp );
113 mySpinBox[ SpinBox22 ] = new DlgRef_SpinBox( aSpinGrp );
115 // Create third group
117 myGrp3 = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_CHAMFER_FACES" ), this );
119 QGroupBox* aSelGrp3 = new QGroupBox( 3, Qt::Horizontal, myGrp3 );
120 aSelGrp3->setFrameStyle( QFrame::NoFrame );
121 aSelGrp3->setInsideMargin( 0 );
123 createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, aSelGrp3, MainObj3 );
124 createSelWg( tr( "SELECTED_FACES" ), iconSelect, aSelGrp3, Faces );
126 aSpinGrp = new QGroupBox( 1, Qt::Vertical, myGrp3 );
127 aSpinGrp->setFrameStyle( QFrame::NoFrame );
128 aSpinGrp->setInsideMargin( 0 );
130 new QLabel( tr( "GEOM_D1" ), aSpinGrp );
131 mySpinBox[ SpinBox31 ] = new DlgRef_SpinBox( aSpinGrp );
133 new QLabel( tr( "GEOM_D2" ), aSpinGrp );
134 mySpinBox[ SpinBox32 ] = new DlgRef_SpinBox( aSpinGrp );
136 ( new QLabel( myGrp3 ) )->setSizePolicy(
137 QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
139 // Add groups to layout
141 Layout1->addWidget( myGrp1, 2, 0 );
142 Layout1->addWidget( myGrp2, 2, 0 );
143 Layout1->addWidget( myGrp3, 2, 0 );
145 // Set range of spinboxes
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 );
152 /* Initialisations */
157 //=================================================================================
158 // function : ~OperationGUI_ChamferDlg()
159 // purpose : Destroys the object and frees any allocated resources
160 //=================================================================================
161 OperationGUI_ChamferDlg::~OperationGUI_ChamferDlg()
166 //=================================================================================
169 //=================================================================================
170 void OperationGUI_ChamferDlg::Init()
172 myConstructorId = -1;
174 RadioButton1->setChecked( true );
175 myEditCurrentArgument = mySelName[ MainObj1 ];
177 /* signals and slots connections */
180 connect( buttonOk , SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
181 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
184 connect( GroupConstructors, SIGNAL( clicked( int ) ),
185 this, SLOT( ConstructorsClicked( int ) ) );
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() ) );
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() ) );
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 ) ) );
206 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
207 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
209 initName( tr( "GEOM_CHAMFER" ) );
219 //=================================================================================
220 // function : ConstructorsClicked()
221 // purpose : Radio button management
222 //=================================================================================
223 void OperationGUI_ChamferDlg::ConstructorsClicked( int constructorId )
225 // Activate next widget
226 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
227 != OCCViewer_Viewer::Type() )
229 RadioButton1->setChecked( true );
233 if ( myConstructorId == constructorId )
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 )
242 D1 = mySpinBox[ SpinBox21 ]->GetValue();
243 D2 = mySpinBox[ SpinBox22 ]->GetValue();
245 else if ( myConstructorId == 2 )
247 D1 = mySpinBox[ SpinBox31 ]->GetValue();
248 D2 = mySpinBox[ SpinBox32 ]->GetValue();
251 myConstructorId = constructorId;
253 switch ( constructorId )
259 mySpinBox[ SpinBox1 ]->SetValue( D1 );
265 mySpinBox[ SpinBox21 ]->SetValue( D1 );
266 mySpinBox[ SpinBox22 ]->SetValue( D2 );
272 mySpinBox[ SpinBox31 ]->SetValue( D1 );
273 mySpinBox[ SpinBox32 ]->SetValue( D2 );
279 if ( constructorId == 0 ) myEditCurrentArgument = mySelName[ MainObj1 ];
280 else if ( constructorId == 1 ) myEditCurrentArgument = mySelName[ MainObj2 ];
281 else myEditCurrentArgument = mySelName[ MainObj3 ];
286 if ( !myShape->_is_nil() )
288 myEditCurrentArgument->setText( GEOMBase::GetName( myShape ) );
289 GEOMBase_Skeleton::LineEditReturnPressed();
292 myEditCurrentArgument->setText( "" );
298 //=================================================================================
299 // function : ClickOnOk()
301 //=================================================================================
302 void OperationGUI_ChamferDlg::ClickOnOk()
304 if ( ClickOnApply() )
308 //=================================================================================
309 // function : ClickOnApply()
311 //=================================================================================
312 bool OperationGUI_ChamferDlg::ClickOnApply()
322 //=================================================================================
323 // function : SelectionIntoArgument()
324 // purpose : Called when selection has changed
325 //=================================================================================
326 void OperationGUI_ChamferDlg::SelectionIntoArgument()
329 myEditCurrentArgument->setText( "" );
331 // Get index of current selection focus
333 QMap< int, QLineEdit* >::iterator anIter;
334 for ( anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter )
335 if ( myEditCurrentArgument == anIter.data() )
337 aCurrFocus = anIter.key();
341 // If selection of main object is activated
342 if ( aCurrFocus == MainObj1 || aCurrFocus == MainObj2 || aCurrFocus == MainObj3 )
344 if ( IObjectCount() == 1 )
346 Standard_Boolean aResult = Standard_False;
347 GEOM::GEOM_Object_var anObj =
348 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
350 if ( aResult && !anObj->_is_nil() )
353 mySelName[ aCurrFocus ]->setText( GEOMBase::GetName( anObj ) );
360 myShape = GEOM::GEOM_Object::_nil();
363 // If face selection of second tab is activated
364 else if ( aCurrFocus == Face1 || aCurrFocus == Face2 )
366 if ( IObjectCount() == 1 )
368 Standard_Boolean aResult = Standard_False;
369 GEOM::GEOM_Object_var anObj =
370 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
372 if ( aResult && !anObj->_is_nil() )
374 TColStd_IndexedMapOfInteger anIndexes;
375 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
377 if ( anIndexes.Extent() == 1 )
379 int anIndex = anIndexes( 1 );
380 QString aFaceName = QString( GEOMBase::GetName( anObj ) ) + ":%1";
381 myEditCurrentArgument->setText( aFaceName.arg( anIndex ) );
382 myFace[ aCurrFocus ] = anIndex;
389 myFace[ aCurrFocus ] = -1;
391 // If face selection of third tab is activated
392 else if ( aCurrFocus == Faces )
394 if ( IObjectCount() == 1 )
396 Standard_Boolean aResult = Standard_False;
397 GEOM::GEOM_Object_var anObj =
398 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
400 if ( aResult && !anObj->_is_nil() )
402 TColStd_IndexedMapOfInteger anIndexes;
403 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
405 if ( anIndexes.Extent() > 0 )
408 if ( anIndexes.Extent() == 1 )
410 int anIndex = anIndexes( 1 );
412 aFaceName = QString( GEOMBase::GetName( anObj ) ) + QString( ":%1" ).arg( anIndex );
415 aFaceName = tr( "GEOM_MEN_POPUP_NAME" ).arg( anIndexes.Extent() );
417 myEditCurrentArgument->setText( aFaceName );
429 //=================================================================================
430 // function : LineEditReturnPressed()
432 //=================================================================================
433 void OperationGUI_ChamferDlg::LineEditReturnPressed()
435 QLineEdit* aSender = ( QLineEdit* )sender();
437 QMap< int, QLineEdit* >::iterator anIterLE;
438 for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
439 if ( anIterLE.data() == aSender )
440 myEditCurrentArgument = anIterLE.data();
442 GEOMBase_Skeleton::LineEditReturnPressed();
446 //=================================================================================
447 // function : SetEditCurrentArgument()
449 //=================================================================================
450 void OperationGUI_ChamferDlg::SetEditCurrentArgument()
452 QPushButton* aSender = ( QPushButton* )sender();
454 QMap< int, QPushButton* >::iterator anIter;
455 for ( anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter )
456 if ( anIter.data() == aSender )
458 mySelName[ anIter.key() ]->setFocus();
459 myEditCurrentArgument = mySelName[ anIter.key() ];
466 //=================================================================================
467 // function : DeactivateActiveDialog()
469 //=================================================================================
470 void OperationGUI_ChamferDlg::DeactivateActiveDialog()
472 // disconnect selection
473 GEOMBase_Skeleton::DeactivateActiveDialog();
477 //=================================================================================
478 // function : ActivateThisDialog()
480 //=================================================================================
481 void OperationGUI_ChamferDlg::ActivateThisDialog()
483 GEOMBase_Skeleton::ActivateThisDialog();
485 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
486 SIGNAL(currentSelectionChanged()), this, SLOT( SelectionIntoArgument() ) );
493 //=================================================================================
494 // function : enterEvent()
496 //=================================================================================
497 void OperationGUI_ChamferDlg::enterEvent(QEvent* e)
499 if ( !GroupConstructors->isEnabled() )
500 this->ActivateThisDialog();
504 //=================================================================================
505 // function : ValueChangedInSpinBox()
507 //=================================================================================
508 void OperationGUI_ChamferDlg::ValueChangedInSpinBox( double newValue )
514 //=================================================================================
515 // function : createSelWg()
517 //=================================================================================
518 void OperationGUI_ChamferDlg::createSelWg( const QString& theLbl,
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 );
530 //=================================================================================
531 // function : reset()
533 //=================================================================================
534 void OperationGUI_ChamferDlg::reset()
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 );
542 QMap< int, QLineEdit* >::iterator anIterLE;
543 for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
544 anIterLE.data()->setText( "" );
547 int aConstructorId = getConstructorId();
549 if ( aConstructorId == 0 ) myEditCurrentArgument = mySelName[ MainObj1 ];
550 else if ( aConstructorId == 1 ) myEditCurrentArgument = mySelName[ MainObj2 ];
551 else myEditCurrentArgument = mySelName[ MainObj3 ];
553 myShape = GEOM::GEOM_Object::_nil();
556 myFace[ Face1 ] = -1;
557 myFace[ Face2 ] = -1;
559 erasePreview( true );
566 //=================================================================================
567 // function : getConstructorId()
569 //=================================================================================
570 int OperationGUI_ChamferDlg::getConstructorId() const
572 return GroupConstructors->id( GroupConstructors->selected() );
575 //=================================================================================
576 // function : activateSelection
577 // purpose : Activate selection in accordance with myEditCurrentArgument
578 //=================================================================================
579 void OperationGUI_ChamferDlg::activateSelection()
581 if ( !myShape->_is_nil() &&
582 ( myEditCurrentArgument == mySelName[ Face1 ] ||
583 myEditCurrentArgument == mySelName[ Face2 ] ||
584 myEditCurrentArgument == mySelName[ Faces ] ) )
585 localSelection( myShape, TopAbs_FACE );
588 TColStd_MapOfInteger aMap;
589 aMap.Add( GEOM_SHELL );
590 aMap.Add( GEOM_SOLID );
591 aMap.Add( GEOM_COMPOUND );
592 globalSelection( aMap );
595 SelectionIntoArgument();
598 //=================================================================================
599 // function : enableWidgets
600 // purpose : Enable widgets of faces in accordance with value of main object
601 //=================================================================================
602 void OperationGUI_ChamferDlg::enableWidgets()
604 int anId = getConstructorId();
606 bool toEnable = !myShape->_is_nil();
610 mySelName[ Face1 ]->setEnabled( toEnable );
611 mySelName[ Face2 ]->setEnabled( toEnable );
612 mySelBtn[ Face1 ]->setEnabled( toEnable );
613 mySelBtn[ Face2 ]->setEnabled( toEnable );
617 mySelName[ Face1 ]->setText( "" );
618 mySelName[ Face2 ]->setText( "" );
619 myFace[ Face1 ] = -1;
620 myFace[ Face2 ] = -1;
623 else if ( anId == 2 )
625 mySelName[ Faces ]->setEnabled( toEnable );
632 //=================================================================================
633 // function : createOperation
635 //=================================================================================
636 GEOM::GEOM_IOperations_ptr OperationGUI_ChamferDlg::createOperation()
638 return getGeomEngine()->GetILocalOperations( getStudyId() );
641 //=================================================================================
642 // function : ClickOnApply()
643 // purpose : Verify validity of input data
644 //=================================================================================
645 bool OperationGUI_ChamferDlg::isValid( QString& )
647 switch ( getConstructorId() )
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;
656 //=================================================================================
657 // function : execute
659 //=================================================================================
660 bool OperationGUI_ChamferDlg::execute( ObjectList& objects )
662 GEOM::GEOM_Object_var anObj;
664 int anId = getConstructorId();
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(),
676 else if ( anId == 2 )
680 GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
681 anArray->length( myFaces.Extent() );
684 for ( int i = 1, n = myFaces.Extent(); i <= n; i++ )
685 anArray[ i - 1 ] = myFaces( i );
687 anObj = GEOM::GEOM_ILocalOperations::_narrow(
688 getOperation() )->MakeChamferFaces( myShape,
689 mySpinBox[ SpinBox31 ]->GetValue(),
690 mySpinBox[ SpinBox32 ]->GetValue(),
695 if ( !anObj->_is_nil() )
696 objects.push_back( anObj._retn() );