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
22 // File : OperationGUI_FilletDlg.cxx
23 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 #include "OperationGUI_FilletDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_ViewWindow.h>
36 #include <SUIT_ViewManager.h>
37 #include <SalomeApp_Application.h>
38 #include <LightApp_SelectionMgr.h>
39 #include <OCCViewer_ViewModel.h>
41 #include <TColStd_MapOfInteger.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
44 #include <GEOMImpl_Types.hxx>
46 //=================================================================================
47 // class : OperationGUI_FilletDlg()
48 // purpose : Constructs a OperationGUI_FilletDlg 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_FilletDlg::OperationGUI_FilletDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
54 : GEOMBase_Skeleton( theGeometryGUI, parent, false )
56 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
57 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_FILLET_ALL" ) ) );
58 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_FILLET_EDGE" ) ) );
59 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_FILLET_FACE" ) ) );
61 QPixmap iconSelect( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
63 setWindowTitle( tr( "GEOM_FILLET_TITLE" ) );
65 /***************************************************************/
66 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_FILLET" ) );
67 mainFrame()->RadioButton1->setIcon( image0 );
68 mainFrame()->RadioButton2->setIcon( image1 );
69 mainFrame()->RadioButton3->setIcon( image2 );
71 Group1 = new DlgRef_1Sel1Spin( centralWidget() );
72 Group1->GroupBox1->setTitle( tr( "GEOM_FILLET_ALL" ) );
73 Group1->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
74 Group1->TextLabel2->setText( tr( "GEOM_RADIUS" ) );
75 Group1->PushButton1->setIcon( iconSelect );
76 Group1->LineEdit1->setReadOnly( true );
78 Group2 = new DlgRef_2Sel3Spin2Rb( centralWidget() );
79 Group2->GroupBox1->setTitle( tr( "GEOM_FILLET_EDGES" ) );
80 Group2->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
81 Group2->TextLabel2->setText( tr( "SELECTED_EDGES" ) );
82 Group2->TextLabel3->setText( tr( "GEOM_RADIUS" ) );
83 Group2->TextLabel4->setText( tr( "GEOM_R1" ) );
84 Group2->TextLabel5->setText( tr( "GEOM_R2" ) );
85 Group2->PushButton1->setIcon( iconSelect );
86 Group2->PushButton2->setIcon( iconSelect );
87 Group2->LineEdit1->setReadOnly( true );
88 Group2->LineEdit2->setReadOnly( true );
90 Group3 = new DlgRef_2Sel3Spin2Rb( centralWidget() );
91 Group3->GroupBox1->setTitle( tr( "GEOM_FILLET_FACES" ) );
92 Group3->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
93 Group3->TextLabel2->setText( tr( "SELECTED_FACES" ) );
94 Group3->TextLabel3->setText( tr( "GEOM_RADIUS" ) );
95 Group3->TextLabel4->setText( tr( "GEOM_R1" ) );
96 Group3->TextLabel5->setText( tr( "GEOM_R2" ) );
97 Group3->PushButton1->setIcon( iconSelect );
98 Group3->PushButton2->setIcon( iconSelect );
99 Group3->LineEdit1->setReadOnly( true );
100 Group3->LineEdit2->setReadOnly( true );
102 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
103 layout->setMargin( 0 ); layout->setSpacing( 6 );
104 layout->addWidget( Group1 );
105 layout->addWidget( Group2 );
106 layout->addWidget( Group3 );
107 /***************************************************************/
109 double SpecificStep = 10.0;
110 initSpinBox( Group1->SpinBox_DX, 0.001, COORD_MAX, SpecificStep, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
111 initSpinBox( Group2->SpinBox_DX, 0.001, COORD_MAX, SpecificStep, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
112 initSpinBox( Group2->SpinBox_DY, 0.001, COORD_MAX, SpecificStep, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
113 initSpinBox( Group2->SpinBox_DZ, 0.001, COORD_MAX, SpecificStep, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
114 initSpinBox( Group3->SpinBox_DX, 0.001, COORD_MAX, SpecificStep, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
115 initSpinBox( Group3->SpinBox_DY, 0.001, COORD_MAX, SpecificStep, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
116 initSpinBox( Group3->SpinBox_DZ, 0.001, COORD_MAX, SpecificStep, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
118 setHelpFileName( "fillet_operation_page.html" );
120 /* Initialisations */
125 //=================================================================================
126 // function : ~OperationGUI_FilletDlg()
127 // purpose : Destroys the object and frees any allocated resources
128 //=================================================================================
129 OperationGUI_FilletDlg::~OperationGUI_FilletDlg()
134 //=================================================================================
137 //=================================================================================
138 void OperationGUI_FilletDlg::Init()
140 myConstructorId = -1;
144 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
145 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
148 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
151 connect( Group1->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
152 connect( Group2->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
153 connect( Group3->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
154 connect( Group2->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
155 connect( Group3->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
158 connect( Group1->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
159 connect( Group2->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
160 connect( Group3->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
163 connect( Group1->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
164 connect( Group2->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
165 connect( Group2->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
166 connect( Group2->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
167 connect( Group3->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
168 connect( Group3->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
169 connect( Group3->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
172 connect( Group2->RadioButton1, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
173 connect( Group2->RadioButton2, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
174 connect( Group3->RadioButton1, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
175 connect( Group3->RadioButton2, SIGNAL( clicked() ), this, SLOT( RadioButtonClicked() ) );
178 connect( myGeomGUI->getApp()->selectionMgr(),
179 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
181 initName( tr( "GEOM_FILLET" ) );
183 ConstructorsClicked( 0 );
187 //=================================================================================
188 // function : ConstructorsClicked()
189 // purpose : Radio button management
190 //=================================================================================
191 void OperationGUI_FilletDlg::ConstructorsClicked( int constructorId )
193 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
194 != OCCViewer_Viewer::Type() ) {
195 mainFrame()->RadioButton1->setChecked( true );
199 if ( myConstructorId == constructorId )
202 // Get radius from previous widget
203 double R = 5, R1 = 5, R2 = 5;
204 if ( myConstructorId == 0 ) {
205 R = Group1->SpinBox_DX->value();
207 else if ( myConstructorId == 1 ) {
208 R = Group2->SpinBox_DX->value();
209 R1 = Group2->SpinBox_DY->value();
210 R2 = Group2->SpinBox_DZ->value();
213 R = Group3->SpinBox_DX->value();
214 R1 = Group3->SpinBox_DY->value();
215 R2 = Group3->SpinBox_DZ->value();
218 myConstructorId = constructorId;
220 switch ( constructorId ) {
225 Group1->SpinBox_DX->setValue( R );
231 Group2->SpinBox_DX->setValue( R );
232 Group2->SpinBox_DY->setValue( R1 );
233 Group2->SpinBox_DZ->setValue( R2 );
239 Group3->SpinBox_DX->setValue( R );
240 Group3->SpinBox_DY->setValue( R1 );
241 Group3->SpinBox_DZ->setValue( R2 );
247 if ( constructorId == 0 ) myEditCurrentArgument = Group1->LineEdit1;
248 else if ( constructorId == 1 ) myEditCurrentArgument = Group2->LineEdit1;
249 else myEditCurrentArgument = Group3->LineEdit1;
254 if ( !myShape->_is_nil() ) {
255 myEditCurrentArgument->setText( GEOMBase::GetName( myShape ) );
256 GEOMBase_Skeleton::LineEditReturnPressed();
259 myEditCurrentArgument->setText( "" );
261 qApp->processEvents();
263 resize( minimumSize() );
269 //=================================================================================
270 // function : ClickOnOk()
272 //=================================================================================
273 void OperationGUI_FilletDlg::ClickOnOk()
275 if ( ClickOnApply() )
280 //=================================================================================
281 // function : ClickOnApply()
283 //=================================================================================
284 bool OperationGUI_FilletDlg::ClickOnApply()
293 //=================================================================================
294 // function : SelectionIntoArgument()
295 // purpose : Called when selection has changed
296 //=================================================================================
297 void OperationGUI_FilletDlg::SelectionIntoArgument()
300 myEditCurrentArgument->setText( "" );
302 // If selection of main object is activated
303 if ( myEditCurrentArgument == Group1->LineEdit1 ||
304 myEditCurrentArgument == Group2->LineEdit1 ||
305 myEditCurrentArgument == Group3->LineEdit1 ) {
306 if ( IObjectCount() == 1 ) {
307 Standard_Boolean aResult = Standard_False;
308 GEOM::GEOM_Object_var anObj =
309 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
311 if ( aResult && !anObj->_is_nil() ) {
313 myEditCurrentArgument->setText( GEOMBase::GetName( anObj ) );
320 myShape = GEOM::GEOM_Object::_nil();
323 // If face or edge selection is activated
324 else if ( myEditCurrentArgument == Group2->LineEdit2 ||
325 myEditCurrentArgument == Group3->LineEdit2 ) {
326 if ( IObjectCount() == 1 ) {
327 Standard_Boolean aResult = Standard_False;
328 GEOM::GEOM_Object_var anObj =
329 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
331 if ( aResult && !anObj->_is_nil() ) {
332 TColStd_IndexedMapOfInteger anIndexes;
333 myGeomGUI->getApp()->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
335 if ( anIndexes.Extent() > 0 ) {
337 if ( anIndexes.Extent() == 1 ) {
338 int anIndex = anIndexes( 1 );
340 aName = QString( GEOMBase::GetName( anObj ) ) + QString( ":%1" ).arg( anIndex );
343 aName = tr( "GEOM_MEN_POPUP_NAME" ).arg( anIndexes.Extent() );
345 myEditCurrentArgument->setText( aName );
347 if ( myConstructorId == 1 )
362 //=================================================================================
363 // function : LineEditReturnPressed()
365 //=================================================================================
366 void OperationGUI_FilletDlg::LineEditReturnPressed()
368 QLineEdit* send = ( QLineEdit* )sender();
370 if ( send == Group1->LineEdit1 )
371 myEditCurrentArgument = Group1->LineEdit1;
372 else if ( send == Group2->LineEdit1 )
373 myEditCurrentArgument = Group2->LineEdit1;
374 else if ( send == Group3->LineEdit1 )
375 myEditCurrentArgument = Group3->LineEdit1;
379 GEOMBase_Skeleton::LineEditReturnPressed();
383 //=================================================================================
384 // function : SetEditCurrentArgument()
386 //=================================================================================
387 void OperationGUI_FilletDlg::SetEditCurrentArgument()
389 QPushButton* send = (QPushButton*)sender();
391 if ( send == Group1->PushButton1 ) {
392 Group1->LineEdit1->setFocus();
393 myEditCurrentArgument = Group1->LineEdit1;
395 else if ( send == Group2->PushButton1 ) {
396 Group2->LineEdit1->setFocus();
397 myEditCurrentArgument = Group2->LineEdit1;
399 else if ( send == Group2->PushButton2 ) {
400 Group2->LineEdit2->setFocus();
401 myEditCurrentArgument = Group2->LineEdit2;
403 else if ( send == Group3->PushButton1 ) {
404 Group3->LineEdit1->setFocus();
405 myEditCurrentArgument = Group3->LineEdit1;
407 else if ( send == Group3->PushButton2 ) {
408 Group3->LineEdit1->setFocus();
409 myEditCurrentArgument = Group3->LineEdit2;
416 //=================================================================================
417 // function : ActivateThisDialog()
419 //=================================================================================
420 void OperationGUI_FilletDlg::ActivateThisDialog()
422 GEOMBase_Skeleton::ActivateThisDialog();
424 connect( myGeomGUI->getApp()->selectionMgr(),
425 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
432 //=================================================================================
433 // function : enterEvent()
435 //=================================================================================
436 void OperationGUI_FilletDlg::enterEvent( QEvent* )
438 if ( !mainFrame()->GroupConstructors->isEnabled() )
439 this->ActivateThisDialog();
442 //=================================================================================
443 // function : ValueChangedInSpinBox()
445 //=================================================================================
446 void OperationGUI_FilletDlg::ValueChangedInSpinBox( double )
451 //=================================================================================
452 // function : reset()
454 //=================================================================================
455 void OperationGUI_FilletDlg::reset()
457 // Set Initial values of spinboxes
458 Group1->SpinBox_DX->setValue( 5 );
459 Group2->SpinBox_DX->setValue( 5 );
460 Group2->SpinBox_DY->setValue( 5 );
461 Group2->SpinBox_DZ->setValue( 5 );
462 Group3->SpinBox_DX->setValue( 5 );
463 Group3->SpinBox_DY->setValue( 5 );
464 Group3->SpinBox_DZ->setValue( 5 );
466 Group1->LineEdit1->setText( "" );
467 Group2->LineEdit1->setText( "" );
468 Group2->LineEdit2->setText( "" );
469 Group3->LineEdit1->setText( "" );
470 Group3->LineEdit2->setText( "" );
473 int aConstructorId = getConstructorId();
475 if ( aConstructorId == 0 ) myEditCurrentArgument = Group1->LineEdit1;
476 else if ( aConstructorId == 1 ) myEditCurrentArgument = Group2->LineEdit1;
477 else myEditCurrentArgument = Group3->LineEdit1;
479 myShape = GEOM::GEOM_Object::_nil();
484 erasePreview( true );
491 //=================================================================================
492 // function : activateSelection
493 // purpose : Activate selection in accordance with myEditCurrentArgument
494 //=================================================================================
495 void OperationGUI_FilletDlg::activateSelection()
498 if ( !myShape->_is_nil() && myEditCurrentArgument == Group2->LineEdit2 )
499 localSelection( myShape, TopAbs_EDGE );
500 else if ( !myShape->_is_nil() && myEditCurrentArgument == Group3->LineEdit2 )
501 localSelection( myShape, TopAbs_FACE );
503 TColStd_MapOfInteger aMap;
504 aMap.Add( GEOM_SHELL );
505 aMap.Add( GEOM_SOLID );
506 aMap.Add( GEOM_COMPOUND );
507 globalSelection( aMap );
510 SelectionIntoArgument();
513 //=================================================================================
514 // function : enableWidgets
515 // purpose : Enable widgets of faces in accordance with value of main object
516 //=================================================================================
517 void OperationGUI_FilletDlg::enableWidgets()
519 int anId = getConstructorId();
521 bool toEnable = !myShape->_is_nil();
524 Group2->LineEdit2->setEnabled( toEnable );
525 Group2->PushButton2->setEnabled( toEnable );
528 Group2->LineEdit2->setText( "" );
532 else if ( anId == 2 ) {
533 Group3->LineEdit2->setEnabled( toEnable );
534 Group3->PushButton2->setEnabled( toEnable );
537 Group3->LineEdit2->setText( "" );
543 //=================================================================================
544 // function : createOperation
546 //=================================================================================
547 GEOM::GEOM_IOperations_ptr OperationGUI_FilletDlg::createOperation()
549 return getGeomEngine()->GetILocalOperations( getStudyId() );
552 //=================================================================================
553 // function : ClickOnApply()
554 // purpose : Verify validity of input data
555 //=================================================================================
556 bool OperationGUI_FilletDlg::isValid( QString& )
558 switch ( getConstructorId() )
560 case 0: return !myShape->_is_nil();
561 case 1: return !myShape->_is_nil() && myEdges.Extent() > 0;
562 case 2: return !myShape->_is_nil() && myFaces.Extent() > 0;
563 default: return false;
567 //=================================================================================
568 // function : execute
570 //=================================================================================
571 bool OperationGUI_FilletDlg::execute( ObjectList& objects )
573 GEOM::GEOM_Object_var anObj;
575 int anId = getConstructorId();
577 anObj = GEOM::GEOM_ILocalOperations::_narrow(
578 getOperation() )->MakeFilletAll( myShape, getRadius() );
579 else if ( anId == 1 ) {
580 GEOM::ListOfLong_var aList = new GEOM::ListOfLong;
581 aList->length( myEdges.Extent() );
583 for ( int i = 1, n = myEdges.Extent(); i <= n; i++ )
584 aList[ i - 1 ] = myEdges( i );
586 if ( Group2->RadioButton1->isChecked() )
587 anObj = GEOM::GEOM_ILocalOperations::_narrow( getOperation() )->
588 MakeFilletEdges( myShape, getRadius(), aList );
590 anObj = GEOM::GEOM_ILocalOperations::_narrow( getOperation() )->
591 MakeFilletEdgesR1R2( myShape,
592 Group2->SpinBox_DY->value(),
593 Group2->SpinBox_DZ->value(),
596 else if ( anId == 2 ) {
597 GEOM::ListOfLong_var aList = new GEOM::ListOfLong;
598 aList->length( myFaces.Extent() );
600 for ( int i = 1, n = myFaces.Extent(); i <= n; i++ )
601 aList[ i - 1 ] = myFaces( i );
603 if ( Group3->RadioButton1->isChecked() ) {
604 anObj = GEOM::GEOM_ILocalOperations::_narrow( getOperation() )->
605 MakeFilletFaces( myShape, getRadius(), aList );
608 anObj = GEOM::GEOM_ILocalOperations::_narrow( getOperation() )->
609 MakeFilletFacesR1R2( myShape,
610 Group3->SpinBox_DY->value(),
611 Group3->SpinBox_DZ->value(), aList );
615 if ( !anObj->_is_nil() )
616 objects.push_back( anObj._retn() );
621 //=================================================================================
622 // function : getRadius
623 // purpose : Get radius
624 //=================================================================================
625 double OperationGUI_FilletDlg::getRadius() const
627 int anId = getConstructorId();
628 if ( anId == 0 ) return Group1->SpinBox_DX->value();
629 else if ( anId == 1 ) return Group2->SpinBox_DX->value();
630 else return Group3->SpinBox_DX->value();
633 //=================================================================================
634 // function : RadiobuttonClicked
636 //=================================================================================
638 void OperationGUI_FilletDlg::RadioButtonClicked()
640 const QObject* s = sender();
642 bool flag = s == Group2->RadioButton1 || s == Group3->RadioButton1;
644 Group2->RadioButton1->blockSignals( true );
645 Group2->RadioButton2->blockSignals( true );
646 Group3->RadioButton1->blockSignals( true );
647 Group3->RadioButton2->blockSignals( true );
649 Group2->SpinBox_DX->setEnabled( flag );
650 Group2->SpinBox_DY->setEnabled( !flag );
651 Group2->SpinBox_DZ->setEnabled( !flag );
652 Group2->RadioButton1->setChecked( flag );
653 Group2->RadioButton2->setChecked( !flag );
654 Group3->SpinBox_DX->setEnabled( flag );
655 Group3->SpinBox_DY->setEnabled( !flag );
656 Group3->SpinBox_DZ->setEnabled( !flag );
657 Group3->RadioButton1->setChecked( flag );
658 Group3->RadioButton2->setChecked( !flag );
660 Group2->RadioButton1->blockSignals( false );
661 Group2->RadioButton2->blockSignals( false );
662 Group3->RadioButton1->blockSignals( false );
663 Group3->RadioButton2->blockSignals( false );