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 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
303 SALOME_ListIO aSelList;
304 aSelMgr->selectedObjects(aSelList);
306 // If selection of main object is activated
307 if (myEditCurrentArgument == Group1->LineEdit1 ||
308 myEditCurrentArgument == Group2->LineEdit1 ||
309 myEditCurrentArgument == Group3->LineEdit1)
311 if (aSelList.Extent() == 1) {
312 Standard_Boolean aResult = Standard_False;
313 GEOM::GEOM_Object_var anObj =
314 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
316 if (aResult && !anObj->_is_nil()) {
318 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
325 myShape = GEOM::GEOM_Object::_nil();
328 // If face or edge selection is activated
329 else if (myEditCurrentArgument == Group2->LineEdit2 ||
330 myEditCurrentArgument == Group3->LineEdit2)
332 if (aSelList.Extent() == 1) {
333 Standard_Boolean aResult = Standard_False;
334 GEOM::GEOM_Object_var anObj =
335 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
337 if (aResult && !anObj->_is_nil()) {
338 TColStd_IndexedMapOfInteger anIndexes;
339 aSelMgr->GetIndexes(aSelList.First(), anIndexes);
341 if (anIndexes.Extent() > 0) {
343 if (anIndexes.Extent() == 1) {
344 int anIndex = anIndexes(1);
346 aName = QString( GEOMBase::GetName( anObj ) ) + QString( ":%1" ).arg( anIndex );
349 aName = tr( "GEOM_MEN_POPUP_NAME" ).arg( anIndexes.Extent() );
351 myEditCurrentArgument->setText( aName );
353 if ( myConstructorId == 1 )
367 //=================================================================================
368 // function : LineEditReturnPressed()
370 //=================================================================================
371 void OperationGUI_FilletDlg::LineEditReturnPressed()
373 QLineEdit* send = ( QLineEdit* )sender();
375 if ( send == Group1->LineEdit1 )
376 myEditCurrentArgument = Group1->LineEdit1;
377 else if ( send == Group2->LineEdit1 )
378 myEditCurrentArgument = Group2->LineEdit1;
379 else if ( send == Group3->LineEdit1 )
380 myEditCurrentArgument = Group3->LineEdit1;
384 GEOMBase_Skeleton::LineEditReturnPressed();
388 //=================================================================================
389 // function : SetEditCurrentArgument()
391 //=================================================================================
392 void OperationGUI_FilletDlg::SetEditCurrentArgument()
394 QPushButton* send = (QPushButton*)sender();
396 if ( send == Group1->PushButton1 ) {
397 Group1->LineEdit1->setFocus();
398 myEditCurrentArgument = Group1->LineEdit1;
400 else if ( send == Group2->PushButton1 ) {
401 Group2->LineEdit1->setFocus();
402 myEditCurrentArgument = Group2->LineEdit1;
404 else if ( send == Group2->PushButton2 ) {
405 Group2->LineEdit2->setFocus();
406 myEditCurrentArgument = Group2->LineEdit2;
408 else if ( send == Group3->PushButton1 ) {
409 Group3->LineEdit1->setFocus();
410 myEditCurrentArgument = Group3->LineEdit1;
412 else if ( send == Group3->PushButton2 ) {
413 Group3->LineEdit1->setFocus();
414 myEditCurrentArgument = Group3->LineEdit2;
421 //=================================================================================
422 // function : ActivateThisDialog()
424 //=================================================================================
425 void OperationGUI_FilletDlg::ActivateThisDialog()
427 GEOMBase_Skeleton::ActivateThisDialog();
429 connect( myGeomGUI->getApp()->selectionMgr(),
430 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
437 //=================================================================================
438 // function : enterEvent()
440 //=================================================================================
441 void OperationGUI_FilletDlg::enterEvent( QEvent* )
443 if ( !mainFrame()->GroupConstructors->isEnabled() )
444 this->ActivateThisDialog();
447 //=================================================================================
448 // function : ValueChangedInSpinBox()
450 //=================================================================================
451 void OperationGUI_FilletDlg::ValueChangedInSpinBox( double )
456 //=================================================================================
457 // function : reset()
459 //=================================================================================
460 void OperationGUI_FilletDlg::reset()
462 // Set Initial values of spinboxes
463 Group1->SpinBox_DX->setValue( 5 );
464 Group2->SpinBox_DX->setValue( 5 );
465 Group2->SpinBox_DY->setValue( 5 );
466 Group2->SpinBox_DZ->setValue( 5 );
467 Group3->SpinBox_DX->setValue( 5 );
468 Group3->SpinBox_DY->setValue( 5 );
469 Group3->SpinBox_DZ->setValue( 5 );
471 Group1->LineEdit1->setText( "" );
472 Group2->LineEdit1->setText( "" );
473 Group2->LineEdit2->setText( "" );
474 Group3->LineEdit1->setText( "" );
475 Group3->LineEdit2->setText( "" );
478 int aConstructorId = getConstructorId();
480 if ( aConstructorId == 0 ) myEditCurrentArgument = Group1->LineEdit1;
481 else if ( aConstructorId == 1 ) myEditCurrentArgument = Group2->LineEdit1;
482 else myEditCurrentArgument = Group3->LineEdit1;
484 myShape = GEOM::GEOM_Object::_nil();
489 erasePreview( true );
496 //=================================================================================
497 // function : activateSelection
498 // purpose : Activate selection in accordance with myEditCurrentArgument
499 //=================================================================================
500 void OperationGUI_FilletDlg::activateSelection()
503 if ( !myShape->_is_nil() && myEditCurrentArgument == Group2->LineEdit2 )
504 localSelection( myShape, TopAbs_EDGE );
505 else if ( !myShape->_is_nil() && myEditCurrentArgument == Group3->LineEdit2 )
506 localSelection( myShape, TopAbs_FACE );
508 TColStd_MapOfInteger aMap;
509 aMap.Add( GEOM_SHELL );
510 aMap.Add( GEOM_SOLID );
511 aMap.Add( GEOM_COMPOUND );
512 globalSelection( aMap );
515 SelectionIntoArgument();
518 //=================================================================================
519 // function : enableWidgets
520 // purpose : Enable widgets of faces in accordance with value of main object
521 //=================================================================================
522 void OperationGUI_FilletDlg::enableWidgets()
524 int anId = getConstructorId();
526 bool toEnable = !myShape->_is_nil();
529 Group2->LineEdit2->setEnabled( toEnable );
530 Group2->PushButton2->setEnabled( toEnable );
533 Group2->LineEdit2->setText( "" );
537 else if ( anId == 2 ) {
538 Group3->LineEdit2->setEnabled( toEnable );
539 Group3->PushButton2->setEnabled( toEnable );
542 Group3->LineEdit2->setText( "" );
548 //=================================================================================
549 // function : createOperation
551 //=================================================================================
552 GEOM::GEOM_IOperations_ptr OperationGUI_FilletDlg::createOperation()
554 return getGeomEngine()->GetILocalOperations( getStudyId() );
557 //=================================================================================
558 // function : ClickOnApply()
559 // purpose : Verify validity of input data
560 //=================================================================================
561 bool OperationGUI_FilletDlg::isValid( QString& )
563 switch ( getConstructorId() )
565 case 0: return !myShape->_is_nil();
566 case 1: return !myShape->_is_nil() && myEdges.Extent() > 0;
567 case 2: return !myShape->_is_nil() && myFaces.Extent() > 0;
568 default: return false;
572 //=================================================================================
573 // function : execute
575 //=================================================================================
576 bool OperationGUI_FilletDlg::execute( ObjectList& objects )
578 GEOM::GEOM_Object_var anObj;
580 int anId = getConstructorId();
582 anObj = GEOM::GEOM_ILocalOperations::_narrow(
583 getOperation() )->MakeFilletAll( myShape, getRadius() );
584 else if ( anId == 1 ) {
585 GEOM::ListOfLong_var aList = new GEOM::ListOfLong;
586 aList->length( myEdges.Extent() );
588 for ( int i = 1, n = myEdges.Extent(); i <= n; i++ )
589 aList[ i - 1 ] = myEdges( i );
591 if ( Group2->RadioButton1->isChecked() )
592 anObj = GEOM::GEOM_ILocalOperations::_narrow( getOperation() )->
593 MakeFilletEdges( myShape, getRadius(), aList );
595 anObj = GEOM::GEOM_ILocalOperations::_narrow( getOperation() )->
596 MakeFilletEdgesR1R2( myShape,
597 Group2->SpinBox_DY->value(),
598 Group2->SpinBox_DZ->value(),
601 else if ( anId == 2 ) {
602 GEOM::ListOfLong_var aList = new GEOM::ListOfLong;
603 aList->length( myFaces.Extent() );
605 for ( int i = 1, n = myFaces.Extent(); i <= n; i++ )
606 aList[ i - 1 ] = myFaces( i );
608 if ( Group3->RadioButton1->isChecked() ) {
609 anObj = GEOM::GEOM_ILocalOperations::_narrow( getOperation() )->
610 MakeFilletFaces( myShape, getRadius(), aList );
613 anObj = GEOM::GEOM_ILocalOperations::_narrow( getOperation() )->
614 MakeFilletFacesR1R2( myShape,
615 Group3->SpinBox_DY->value(),
616 Group3->SpinBox_DZ->value(), aList );
620 if ( !anObj->_is_nil() )
621 objects.push_back( anObj._retn() );
626 //=================================================================================
627 // function : getRadius
628 // purpose : Get radius
629 //=================================================================================
630 double OperationGUI_FilletDlg::getRadius() const
632 int anId = getConstructorId();
633 if ( anId == 0 ) return Group1->SpinBox_DX->value();
634 else if ( anId == 1 ) return Group2->SpinBox_DX->value();
635 else return Group3->SpinBox_DX->value();
638 //=================================================================================
639 // function : RadiobuttonClicked
641 //=================================================================================
643 void OperationGUI_FilletDlg::RadioButtonClicked()
645 const QObject* s = sender();
647 bool flag = s == Group2->RadioButton1 || s == Group3->RadioButton1;
649 Group2->RadioButton1->blockSignals( true );
650 Group2->RadioButton2->blockSignals( true );
651 Group3->RadioButton1->blockSignals( true );
652 Group3->RadioButton2->blockSignals( true );
654 Group2->SpinBox_DX->setEnabled( flag );
655 Group2->SpinBox_DY->setEnabled( !flag );
656 Group2->SpinBox_DZ->setEnabled( !flag );
657 Group2->RadioButton1->setChecked( flag );
658 Group2->RadioButton2->setChecked( !flag );
659 Group3->SpinBox_DX->setEnabled( flag );
660 Group3->SpinBox_DY->setEnabled( !flag );
661 Group3->SpinBox_DZ->setEnabled( !flag );
662 Group3->RadioButton1->setChecked( flag );
663 Group3->RadioButton2->setChecked( !flag );
665 Group2->RadioButton1->blockSignals( false );
666 Group2->RadioButton2->blockSignals( false );
667 Group3->RadioButton1->blockSignals( false );
668 Group3->RadioButton2->blockSignals( false );