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_FilletDlg.cxx
25 // Author : Damien COQUERET
29 #include "OperationGUI_FilletDlg.h"
30 #include "DlgRef_1Sel1Spin.h"
31 #include "DlgRef_2Sel3Spin2Rb.h"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_Session.h"
35 #include "SalomeApp_Application.h"
36 #include "LightApp_SelectionMgr.h"
37 #include "OCCViewer_ViewModel.h"
41 #include <TColStd_MapOfInteger.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
45 #include "GEOMImpl_Types.hxx"
47 //=================================================================================
48 // class : OperationGUI_FilletDlg()
49 // purpose : Constructs a OperationGUI_FilletDlg 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_FilletDlg::OperationGUI_FilletDlg(GeometryGUI* theGeometryGUI, QWidget* parent)
55 :GEOMBase_Skeleton(theGeometryGUI, parent, "OperationGUI_FilletDlg", false,
56 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
60 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
61 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_FILLET_ALL")));
62 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_FILLET_EDGE")));
63 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_FILLET_FACE")));
65 QPixmap iconSelect(aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
67 setCaption(tr("GEOM_FILLET_TITLE"));
69 /***************************************************************/
70 GroupConstructors->setTitle( tr( "GEOM_FILLET" ) );
71 RadioButton1->setPixmap( image0 );
72 RadioButton2->setPixmap( image1 );
73 RadioButton3->setPixmap( image2 );
75 Group1 = new DlgRef_1Sel1Spin( this, "Group1" );
76 Group1->GroupBox1->setTitle( tr( "GEOM_FILLET_ALL" ) );
77 Group1->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
78 Group1->TextLabel2->setText( tr( "GEOM_RADIUS" ) );
79 Group1->PushButton1->setPixmap( iconSelect );
80 Group1->LineEdit1->setReadOnly( true );
82 Group2 = new DlgRef_2Sel3Spin2Rb( this, "Group2" );
83 Group2->GroupBox1->setTitle( tr( "GEOM_FILLET_EDGES" ) );
84 Group2->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
85 Group2->TextLabel2->setText( tr( "SELECTED_EDGES" ) );
86 Group2->TextLabel3->setText( tr( "GEOM_RADIUS" ) );
87 Group2->TextLabel4->setText( tr( "GEOM_R1" ) );
88 Group2->TextLabel5->setText( tr( "GEOM_R2" ) );
89 Group2->PushButton1->setPixmap( iconSelect );
90 Group2->PushButton2->setPixmap( iconSelect );
91 Group2->LineEdit1->setReadOnly( true );
92 Group2->LineEdit2->setReadOnly( true );
94 Group3 = new DlgRef_2Sel3Spin2Rb( this, "Group3" );
95 Group3->GroupBox1->setTitle(tr( "GEOM_FILLET_FACES" ) );
96 Group3->TextLabel1->setText(tr( "GEOM_MAIN_OBJECT" ) );
97 Group3->TextLabel2->setText(tr( "SELECTED_FACES" ) );
98 Group3->TextLabel3->setText(tr( "GEOM_RADIUS" ) );
99 Group3->TextLabel4->setText(tr( "GEOM_R1" ) );
100 Group3->TextLabel5->setText(tr( "GEOM_R2" ) );
101 Group3->PushButton1->setPixmap( iconSelect );
102 Group3->PushButton2->setPixmap( iconSelect );
103 Group3->LineEdit1->setReadOnly( true );
104 Group3->LineEdit2->setReadOnly( true );
106 Layout1->addWidget( Group1, 2, 0 );
107 Layout1->addWidget( Group2, 2, 0 );
108 Layout1->addWidget( Group3, 2, 0 );
109 /***************************************************************/
111 double SpecificStep = 10.0;
112 Group1->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
113 Group2->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
114 Group2->SpinBox_DY->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
115 Group2->SpinBox_DZ->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
116 Group3->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
117 Group3->SpinBox_DY->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
118 Group3->SpinBox_DZ->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
120 setHelpFileName("fillet.htm");
122 /* Initialisations */
127 //=================================================================================
128 // function : ~OperationGUI_FilletDlg()
129 // purpose : Destroys the object and frees any allocated resources
130 //=================================================================================
131 OperationGUI_FilletDlg::~OperationGUI_FilletDlg()
136 //=================================================================================
139 //=================================================================================
140 void OperationGUI_FilletDlg::Init()
142 myConstructorId = -1;
144 RadioButton1->setChecked( true );
145 myEditCurrentArgument = Group1->LineEdit1;
148 connect( buttonOk , SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
149 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
152 connect( GroupConstructors, SIGNAL( clicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
155 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
156 connect(Group2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
157 connect(Group3->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
158 connect(Group2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
159 connect(Group3->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
162 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
163 connect(Group2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
164 connect(Group3->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
167 connect(Group1->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
168 connect(Group2->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
169 connect(Group2->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
170 connect(Group2->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
171 connect(Group3->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
172 connect(Group3->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
173 connect(Group3->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
176 connect( Group2->RadioButton1, SIGNAL( clicked() ), this, SLOT( RadioButton_Clicked() ) );
177 connect( Group2->RadioButton2, SIGNAL( clicked() ), this, SLOT( RadioButton_Clicked() ) );
178 connect( Group3->RadioButton1, SIGNAL( clicked() ), this, SLOT( RadioButton_Clicked() ) );
179 connect( Group3->RadioButton2, SIGNAL( clicked() ), this, SLOT( RadioButton_Clicked() ) );
182 connect(myGeomGUI->getApp()->selectionMgr(),
183 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
185 initName( tr( "GEOM_FILLET" ) );
193 //=================================================================================
194 // function : ConstructorsClicked()
195 // purpose : Radio button management
196 //=================================================================================
197 void OperationGUI_FilletDlg::ConstructorsClicked( int constructorId )
199 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
200 != OCCViewer_Viewer::Type() )
202 RadioButton1->setChecked( true );
206 if ( myConstructorId == constructorId )
209 // Get radius from previous widget
210 double R = 5, R1 = 5, R2 = 5;
211 if ( myConstructorId == 0 ) R = Group1->SpinBox_DX->GetValue();
212 else if ( myConstructorId == 1 ) {
213 R = Group2->SpinBox_DX->GetValue();
214 R1 = Group2->SpinBox_DY->GetValue();
215 R2 = Group2->SpinBox_DZ->GetValue();
218 R = Group3->SpinBox_DX->GetValue();
219 R1 = Group3->SpinBox_DY->GetValue();
220 R2 = Group3->SpinBox_DZ->GetValue();
223 myConstructorId = constructorId;
225 switch ( constructorId )
231 Group1->SpinBox_DX->SetValue( R );
237 Group2->SpinBox_DX->SetValue( R );
238 Group2->SpinBox_DY->SetValue( R1 );
239 Group2->SpinBox_DZ->SetValue( R2 );
245 Group3->SpinBox_DX->SetValue( R );
246 Group3->SpinBox_DY->SetValue( R1 );
247 Group3->SpinBox_DZ->SetValue( R2 );
253 if ( constructorId == 0 ) myEditCurrentArgument = Group1->LineEdit1;
254 else if ( constructorId == 1 ) myEditCurrentArgument = Group2->LineEdit1;
255 else myEditCurrentArgument = Group3->LineEdit1;
260 if ( !myShape->_is_nil() )
262 myEditCurrentArgument->setText( GEOMBase::GetName( myShape ) );
263 GEOMBase_Skeleton::LineEditReturnPressed();
266 myEditCurrentArgument->setText( "" );
272 //=================================================================================
273 // function : ClickOnOk()
275 //=================================================================================
276 void OperationGUI_FilletDlg::ClickOnOk()
278 if ( ClickOnApply() )
283 //=================================================================================
284 // function : ClickOnApply()
286 //=================================================================================
287 bool OperationGUI_FilletDlg::ClickOnApply()
296 //=================================================================================
297 // function : SelectionIntoArgument()
298 // purpose : Called when selection has changed
299 //=================================================================================
300 void OperationGUI_FilletDlg::SelectionIntoArgument()
303 myEditCurrentArgument->setText( "" );
305 // If selection of main object is activated
306 if ( myEditCurrentArgument == Group1->LineEdit1 ||
307 myEditCurrentArgument == Group2->LineEdit1 ||
308 myEditCurrentArgument == Group3->LineEdit1 )
310 if ( IObjectCount() == 1 )
312 Standard_Boolean aResult = Standard_False;
313 GEOM::GEOM_Object_var anObj =
314 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
316 if ( aResult && !anObj->_is_nil() )
319 myEditCurrentArgument->setText( GEOMBase::GetName( anObj ) );
326 myShape = GEOM::GEOM_Object::_nil();
329 // If face or edge selection is activated
330 else if ( myEditCurrentArgument == Group2->LineEdit2 ||
331 myEditCurrentArgument == Group3->LineEdit2 )
333 if ( IObjectCount() == 1 )
335 Standard_Boolean aResult = Standard_False;
336 GEOM::GEOM_Object_var anObj =
337 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
339 if ( aResult && !anObj->_is_nil() )
341 TColStd_IndexedMapOfInteger anIndexes;
342 myGeomGUI->getApp()->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
344 if ( anIndexes.Extent() > 0 )
347 if ( anIndexes.Extent() == 1 )
349 int anIndex = anIndexes( 1 );
351 aName = QString( GEOMBase::GetName( anObj ) ) + QString( ":%1" ).arg( anIndex );
354 aName = tr( "GEOM_MEN_POPUP_NAME" ).arg( anIndexes.Extent() );
356 myEditCurrentArgument->setText( aName );
358 if ( myConstructorId == 1 )
373 //=================================================================================
374 // function : LineEditReturnPressed()
376 //=================================================================================
377 void OperationGUI_FilletDlg::LineEditReturnPressed()
379 QLineEdit* send = ( QLineEdit* )sender();
381 if ( send == Group1->LineEdit1 )
382 myEditCurrentArgument = Group1->LineEdit1;
383 else if ( send == Group2->LineEdit1 )
384 myEditCurrentArgument = Group2->LineEdit1;
385 else if ( send == Group3->LineEdit1 )
386 myEditCurrentArgument = Group3->LineEdit1;
390 GEOMBase_Skeleton::LineEditReturnPressed();
395 //=================================================================================
396 // function : SetEditCurrentArgument()
398 //=================================================================================
399 void OperationGUI_FilletDlg::SetEditCurrentArgument()
401 QPushButton* send = (QPushButton*)sender();
403 if ( send == Group1->PushButton1 )
405 Group1->LineEdit1->setFocus();
406 myEditCurrentArgument = Group1->LineEdit1;
408 else if( send == Group2->PushButton1 )
410 Group2->LineEdit1->setFocus();
411 myEditCurrentArgument = Group2->LineEdit1;
413 else if( send == Group2->PushButton2 )
415 Group2->LineEdit2->setFocus();
416 myEditCurrentArgument = Group2->LineEdit2;
418 else if ( send == Group3->PushButton1 )
420 Group3->LineEdit1->setFocus();
421 myEditCurrentArgument = Group3->LineEdit1;
423 else if( send == Group3->PushButton2 )
425 Group3->LineEdit1->setFocus();
426 myEditCurrentArgument = Group3->LineEdit2;
433 //=================================================================================
434 // function : ActivateThisDialog()
436 //=================================================================================
437 void OperationGUI_FilletDlg::ActivateThisDialog()
439 GEOMBase_Skeleton::ActivateThisDialog();
441 connect(myGeomGUI->getApp()->selectionMgr(),
442 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
449 //=================================================================================
450 // function : enterEvent()
452 //=================================================================================
453 void OperationGUI_FilletDlg::enterEvent( QEvent* e )
455 if ( !GroupConstructors->isEnabled() )
456 this->ActivateThisDialog();
459 //=================================================================================
460 // function : ValueChangedInSpinBox()
462 //=================================================================================
463 void OperationGUI_FilletDlg::ValueChangedInSpinBox( double newValue )
468 //=================================================================================
469 // function : reset()
471 //=================================================================================
472 void OperationGUI_FilletDlg::reset()
474 // Set Initial values of spinboxes
475 Group1->SpinBox_DX->SetValue( 5 );
476 Group2->SpinBox_DX->SetValue( 5 );
477 Group2->SpinBox_DY->SetValue( 5 );
478 Group2->SpinBox_DZ->SetValue( 5 );
479 Group3->SpinBox_DX->SetValue( 5 );
480 Group3->SpinBox_DY->SetValue( 5 );
481 Group3->SpinBox_DZ->SetValue( 5 );
483 Group1->LineEdit1->setText( "" );
484 Group2->LineEdit1->setText( "" );
485 Group2->LineEdit2->setText( "" );
486 Group3->LineEdit1->setText( "" );
487 Group3->LineEdit2->setText( "" );
490 int aConstructorId = getConstructorId();
492 if ( aConstructorId == 0 ) myEditCurrentArgument = Group1->LineEdit1;
493 else if ( aConstructorId == 1 ) myEditCurrentArgument = Group2->LineEdit1;
494 else myEditCurrentArgument = Group3->LineEdit1;
496 myShape = GEOM::GEOM_Object::_nil();
501 erasePreview( true );
508 //=================================================================================
509 // function : getConstructorId()
511 //=================================================================================
512 int OperationGUI_FilletDlg::getConstructorId() const
514 return GroupConstructors->id( GroupConstructors->selected() );
517 //=================================================================================
518 // function : activateSelection
519 // purpose : Activate selection in accordance with myEditCurrentArgument
520 //=================================================================================
521 void OperationGUI_FilletDlg::activateSelection()
524 if ( !myShape->_is_nil() && myEditCurrentArgument == Group2->LineEdit2 )
525 localSelection( myShape, TopAbs_EDGE );
526 else if ( !myShape->_is_nil() && myEditCurrentArgument == Group3->LineEdit2 )
527 localSelection( myShape, TopAbs_FACE );
530 TColStd_MapOfInteger aMap;
531 aMap.Add( GEOM_SHELL );
532 aMap.Add( GEOM_SOLID );
533 aMap.Add( GEOM_COMPOUND );
534 globalSelection( aMap );
537 SelectionIntoArgument();
540 //=================================================================================
541 // function : enableWidgets
542 // purpose : Enable widgets of faces in accordance with value of main object
543 //=================================================================================
544 void OperationGUI_FilletDlg::enableWidgets()
546 int anId = getConstructorId();
548 bool toEnable = !myShape->_is_nil();
552 Group2->LineEdit2->setEnabled( toEnable );
553 Group2->PushButton2->setEnabled( toEnable );
557 Group2->LineEdit2->setText( "" );
561 else if ( anId == 2 )
563 Group3->LineEdit2->setEnabled( toEnable );
564 Group3->PushButton2->setEnabled( toEnable );
568 Group3->LineEdit2->setText( "" );
574 //=================================================================================
575 // function : createOperation
577 //=================================================================================
578 GEOM::GEOM_IOperations_ptr OperationGUI_FilletDlg::createOperation()
580 return getGeomEngine()->GetILocalOperations( getStudyId() );
583 //=================================================================================
584 // function : ClickOnApply()
585 // purpose : Verify validity of input data
586 //=================================================================================
587 bool OperationGUI_FilletDlg::isValid( QString& )
589 switch ( getConstructorId() )
591 case 0: return !myShape->_is_nil();
592 case 1: return !myShape->_is_nil() && myEdges.Extent() > 0;
593 case 2: return !myShape->_is_nil() && myFaces.Extent() > 0;
594 default: return false;
598 //=================================================================================
599 // function : execute
601 //=================================================================================
602 bool OperationGUI_FilletDlg::execute( ObjectList& objects )
604 GEOM::GEOM_Object_var anObj;
606 int anId = getConstructorId();
608 anObj = GEOM::GEOM_ILocalOperations::_narrow(
609 getOperation() )->MakeFilletAll( myShape, getRadius() );
610 else if ( anId == 1 )
612 GEOM::ListOfLong_var aList = new GEOM::ListOfLong;
613 aList->length( myEdges.Extent() );
615 for ( int i = 1, n = myEdges.Extent(); i <= n; i++ )
616 aList[ i - 1 ] = myEdges( i );
617 if ( Group2->RadioButton1->isChecked() )
618 anObj = GEOM::GEOM_ILocalOperations::_narrow(
619 getOperation() )->MakeFilletEdges( myShape, getRadius(), aList );
621 anObj = GEOM::GEOM_ILocalOperations::_narrow( getOperation() )->MakeFilletEdgesR1R2( myShape,
622 (Group2->SpinBox_DY->GetValue()),
623 (Group2->SpinBox_DZ->GetValue()),
626 else if ( anId == 2 )
629 GEOM::ListOfLong_var aList = new GEOM::ListOfLong;
630 aList->length( myFaces.Extent() );
632 for ( int i = 1, n = myFaces.Extent(); i <= n; i++ )
633 aList[ i - 1 ] = myFaces( i );
634 if ( Group3->RadioButton1->isChecked() )
635 anObj = GEOM::GEOM_ILocalOperations::_narrow(
636 getOperation() )->MakeFilletFaces( myShape, getRadius(), aList );
638 anObj = GEOM::GEOM_ILocalOperations::_narrow(
639 getOperation() )->MakeFilletFacesR1R2( myShape, (Group3->SpinBox_DY->GetValue()),
640 (Group3->SpinBox_DZ->GetValue()), aList );
643 if ( !anObj->_is_nil() )
644 objects.push_back( anObj._retn() );
649 //=================================================================================
650 // function : getRadius
651 // purpose : Get radius
652 //=================================================================================
653 double OperationGUI_FilletDlg::getRadius() const
655 int anId = getConstructorId();
656 if ( anId == 0 ) return Group1->SpinBox_DX->GetValue();
657 else if ( anId == 1 ) return Group2->SpinBox_DX->GetValue();
658 else return Group3->SpinBox_DX->GetValue();
661 //=================================================================================
662 // function : RadiobuttonClicked
664 //=================================================================================
666 void OperationGUI_FilletDlg::RadioButton_Clicked()
668 bool flag = ( (Group2->RadioButton1->isChecked()) && (Group3->RadioButton1->isChecked()) );
671 Group2->SpinBox_DX->setEnabled(flag);
672 Group2->SpinBox_DY->setEnabled(!flag);
673 Group2->SpinBox_DZ->setEnabled(!flag);
674 Group2->RadioButton1->setChecked(flag);
675 Group2->RadioButton2->setChecked(!flag);
676 Group3->SpinBox_DX->setEnabled(flag);
677 Group3->SpinBox_DY->setEnabled(!flag);
678 Group3->SpinBox_DZ->setEnabled(!flag);
679 Group3->RadioButton1->setChecked(flag);
680 Group3->RadioButton2->setChecked(!flag);