1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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 // GEOM GEOMGUI : GUI for Geometry component
23 // File : OperationGUI_FilletDlg.cxx
24 // Author : Damien COQUERET
28 #include "OperationGUI_FilletDlg.h"
29 #include "DlgRef_1Sel1Spin.h"
30 #include "DlgRef_2Sel3Spin2Rb.h"
32 #include "SUIT_Desktop.h"
33 #include "SUIT_Session.h"
34 #include "SalomeApp_Application.h"
35 #include "LightApp_SelectionMgr.h"
36 #include "OCCViewer_ViewModel.h"
40 #include <TColStd_MapOfInteger.hxx>
41 #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, "OperationGUI_FilletDlg", false,
55 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
59 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
60 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_FILLET_ALL")));
61 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_FILLET_EDGE")));
62 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_FILLET_FACE")));
64 QPixmap iconSelect(aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
66 setCaption(tr("GEOM_FILLET_TITLE"));
68 /***************************************************************/
69 GroupConstructors->setTitle( tr( "GEOM_FILLET" ) );
70 RadioButton1->setPixmap( image0 );
71 RadioButton2->setPixmap( image1 );
72 RadioButton3->setPixmap( image2 );
74 Group1 = new DlgRef_1Sel1Spin( this, "Group1" );
75 Group1->GroupBox1->setTitle( tr( "GEOM_FILLET_ALL" ) );
76 Group1->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
77 Group1->TextLabel2->setText( tr( "GEOM_RADIUS" ) );
78 Group1->PushButton1->setPixmap( iconSelect );
79 Group1->LineEdit1->setReadOnly( true );
81 Group2 = new DlgRef_2Sel3Spin2Rb( this, "Group2" );
82 Group2->GroupBox1->setTitle( tr( "GEOM_FILLET_EDGES" ) );
83 Group2->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
84 Group2->TextLabel2->setText( tr( "SELECTED_EDGES" ) );
85 Group2->TextLabel3->setText( tr( "GEOM_RADIUS" ) );
86 Group2->TextLabel4->setText( tr( "GEOM_R1" ) );
87 Group2->TextLabel5->setText( tr( "GEOM_R2" ) );
88 Group2->PushButton1->setPixmap( iconSelect );
89 Group2->PushButton2->setPixmap( iconSelect );
90 Group2->LineEdit1->setReadOnly( true );
91 Group2->LineEdit2->setReadOnly( true );
93 Group3 = new DlgRef_2Sel3Spin2Rb( this, "Group3" );
94 Group3->GroupBox1->setTitle(tr( "GEOM_FILLET_FACES" ) );
95 Group3->TextLabel1->setText(tr( "GEOM_MAIN_OBJECT" ) );
96 Group3->TextLabel2->setText(tr( "SELECTED_FACES" ) );
97 Group3->TextLabel3->setText(tr( "GEOM_RADIUS" ) );
98 Group3->TextLabel4->setText(tr( "GEOM_R1" ) );
99 Group3->TextLabel5->setText(tr( "GEOM_R2" ) );
100 Group3->PushButton1->setPixmap( iconSelect );
101 Group3->PushButton2->setPixmap( iconSelect );
102 Group3->LineEdit1->setReadOnly( true );
103 Group3->LineEdit2->setReadOnly( true );
105 Layout1->addWidget( Group1, 2, 0 );
106 Layout1->addWidget( Group2, 2, 0 );
107 Layout1->addWidget( Group3, 2, 0 );
108 /***************************************************************/
110 double SpecificStep = 10.0;
111 Group1->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
112 Group2->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
113 Group2->SpinBox_DY->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
114 Group2->SpinBox_DZ->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
115 Group3->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
116 Group3->SpinBox_DY->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
117 Group3->SpinBox_DZ->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
119 setHelpFileName("fillet_operation_page.html");
121 /* Initialisations */
126 //=================================================================================
127 // function : ~OperationGUI_FilletDlg()
128 // purpose : Destroys the object and frees any allocated resources
129 //=================================================================================
130 OperationGUI_FilletDlg::~OperationGUI_FilletDlg()
135 //=================================================================================
138 //=================================================================================
139 void OperationGUI_FilletDlg::Init()
141 myConstructorId = -1;
143 RadioButton1->setChecked( true );
144 myEditCurrentArgument = Group1->LineEdit1;
147 connect( buttonOk , SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
148 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
151 connect( GroupConstructors, SIGNAL( clicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
154 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
155 connect(Group2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
156 connect(Group3->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
157 connect(Group2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
158 connect(Group3->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
161 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
162 connect(Group2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
163 connect(Group3->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
166 connect(Group1->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
167 connect(Group2->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
168 connect(Group2->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
169 connect(Group2->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
170 connect(Group3->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
171 connect(Group3->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
172 connect(Group3->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
175 connect( Group2->RadioButton1, SIGNAL( clicked() ), this, SLOT( RadioButton_Clicked() ) );
176 connect( Group2->RadioButton2, SIGNAL( clicked() ), this, SLOT( RadioButton_Clicked() ) );
177 connect( Group3->RadioButton1, SIGNAL( clicked() ), this, SLOT( RadioButton_Clicked() ) );
178 connect( Group3->RadioButton2, SIGNAL( clicked() ), this, SLOT( RadioButton_Clicked() ) );
181 connect(myGeomGUI->getApp()->selectionMgr(),
182 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
184 initName( tr( "GEOM_FILLET" ) );
192 //=================================================================================
193 // function : ConstructorsClicked()
194 // purpose : Radio button management
195 //=================================================================================
196 void OperationGUI_FilletDlg::ConstructorsClicked( int constructorId )
198 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
199 != OCCViewer_Viewer::Type() )
201 RadioButton1->setChecked( true );
205 if ( myConstructorId == constructorId )
208 // Get radius from previous widget
209 double R = 5, R1 = 5, R2 = 5;
210 if ( myConstructorId == 0 ) R = Group1->SpinBox_DX->GetValue();
211 else if ( myConstructorId == 1 ) {
212 R = Group2->SpinBox_DX->GetValue();
213 R1 = Group2->SpinBox_DY->GetValue();
214 R2 = Group2->SpinBox_DZ->GetValue();
217 R = Group3->SpinBox_DX->GetValue();
218 R1 = Group3->SpinBox_DY->GetValue();
219 R2 = Group3->SpinBox_DZ->GetValue();
222 myConstructorId = constructorId;
224 switch ( constructorId )
230 Group1->SpinBox_DX->SetValue( R );
236 Group2->SpinBox_DX->SetValue( R );
237 Group2->SpinBox_DY->SetValue( R1 );
238 Group2->SpinBox_DZ->SetValue( R2 );
244 Group3->SpinBox_DX->SetValue( R );
245 Group3->SpinBox_DY->SetValue( R1 );
246 Group3->SpinBox_DZ->SetValue( R2 );
252 if ( constructorId == 0 ) myEditCurrentArgument = Group1->LineEdit1;
253 else if ( constructorId == 1 ) myEditCurrentArgument = Group2->LineEdit1;
254 else myEditCurrentArgument = Group3->LineEdit1;
259 if ( !myShape->_is_nil() )
261 myEditCurrentArgument->setText( GEOMBase::GetName( myShape ) );
262 GEOMBase_Skeleton::LineEditReturnPressed();
265 myEditCurrentArgument->setText( "" );
271 //=================================================================================
272 // function : ClickOnOk()
274 //=================================================================================
275 void OperationGUI_FilletDlg::ClickOnOk()
277 if ( ClickOnApply() )
282 //=================================================================================
283 // function : ClickOnApply()
285 //=================================================================================
286 bool OperationGUI_FilletDlg::ClickOnApply()
295 //=================================================================================
296 // function : SelectionIntoArgument()
297 // purpose : Called when selection has changed
298 //=================================================================================
299 void OperationGUI_FilletDlg::SelectionIntoArgument()
302 myEditCurrentArgument->setText( "" );
304 // If selection of main object is activated
305 if ( myEditCurrentArgument == Group1->LineEdit1 ||
306 myEditCurrentArgument == Group2->LineEdit1 ||
307 myEditCurrentArgument == Group3->LineEdit1 )
309 if ( IObjectCount() == 1 )
311 Standard_Boolean aResult = Standard_False;
312 GEOM::GEOM_Object_var anObj =
313 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
315 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 ( IObjectCount() == 1 )
334 Standard_Boolean aResult = Standard_False;
335 GEOM::GEOM_Object_var anObj =
336 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
338 if ( aResult && !anObj->_is_nil() )
340 TColStd_IndexedMapOfInteger anIndexes;
341 myGeomGUI->getApp()->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
343 if ( anIndexes.Extent() > 0 )
346 if ( anIndexes.Extent() == 1 )
348 int anIndex = anIndexes( 1 );
350 aName = QString( GEOMBase::GetName( anObj ) ) + QString( ":%1" ).arg( anIndex );
353 aName = tr( "GEOM_MEN_POPUP_NAME" ).arg( anIndexes.Extent() );
355 myEditCurrentArgument->setText( aName );
357 if ( myConstructorId == 1 )
372 //=================================================================================
373 // function : LineEditReturnPressed()
375 //=================================================================================
376 void OperationGUI_FilletDlg::LineEditReturnPressed()
378 QLineEdit* send = ( QLineEdit* )sender();
380 if ( send == Group1->LineEdit1 )
381 myEditCurrentArgument = Group1->LineEdit1;
382 else if ( send == Group2->LineEdit1 )
383 myEditCurrentArgument = Group2->LineEdit1;
384 else if ( send == Group3->LineEdit1 )
385 myEditCurrentArgument = Group3->LineEdit1;
389 GEOMBase_Skeleton::LineEditReturnPressed();
394 //=================================================================================
395 // function : SetEditCurrentArgument()
397 //=================================================================================
398 void OperationGUI_FilletDlg::SetEditCurrentArgument()
400 QPushButton* send = (QPushButton*)sender();
402 if ( send == Group1->PushButton1 )
404 Group1->LineEdit1->setFocus();
405 myEditCurrentArgument = Group1->LineEdit1;
407 else if( send == Group2->PushButton1 )
409 Group2->LineEdit1->setFocus();
410 myEditCurrentArgument = Group2->LineEdit1;
412 else if( send == Group2->PushButton2 )
414 Group2->LineEdit2->setFocus();
415 myEditCurrentArgument = Group2->LineEdit2;
417 else if ( send == Group3->PushButton1 )
419 Group3->LineEdit1->setFocus();
420 myEditCurrentArgument = Group3->LineEdit1;
422 else if( send == Group3->PushButton2 )
424 Group3->LineEdit1->setFocus();
425 myEditCurrentArgument = Group3->LineEdit2;
432 //=================================================================================
433 // function : ActivateThisDialog()
435 //=================================================================================
436 void OperationGUI_FilletDlg::ActivateThisDialog()
438 GEOMBase_Skeleton::ActivateThisDialog();
440 connect(myGeomGUI->getApp()->selectionMgr(),
441 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
448 //=================================================================================
449 // function : enterEvent()
451 //=================================================================================
452 void OperationGUI_FilletDlg::enterEvent( QEvent* e )
454 if ( !GroupConstructors->isEnabled() )
455 this->ActivateThisDialog();
458 //=================================================================================
459 // function : ValueChangedInSpinBox()
461 //=================================================================================
462 void OperationGUI_FilletDlg::ValueChangedInSpinBox( double newValue )
467 //=================================================================================
468 // function : reset()
470 //=================================================================================
471 void OperationGUI_FilletDlg::reset()
473 // Set Initial values of spinboxes
474 Group1->SpinBox_DX->SetValue( 5 );
475 Group2->SpinBox_DX->SetValue( 5 );
476 Group2->SpinBox_DY->SetValue( 5 );
477 Group2->SpinBox_DZ->SetValue( 5 );
478 Group3->SpinBox_DX->SetValue( 5 );
479 Group3->SpinBox_DY->SetValue( 5 );
480 Group3->SpinBox_DZ->SetValue( 5 );
482 Group1->LineEdit1->setText( "" );
483 Group2->LineEdit1->setText( "" );
484 Group2->LineEdit2->setText( "" );
485 Group3->LineEdit1->setText( "" );
486 Group3->LineEdit2->setText( "" );
489 int aConstructorId = getConstructorId();
491 if ( aConstructorId == 0 ) myEditCurrentArgument = Group1->LineEdit1;
492 else if ( aConstructorId == 1 ) myEditCurrentArgument = Group2->LineEdit1;
493 else myEditCurrentArgument = Group3->LineEdit1;
495 myShape = GEOM::GEOM_Object::_nil();
500 erasePreview( true );
507 //=================================================================================
508 // function : getConstructorId()
510 //=================================================================================
511 int OperationGUI_FilletDlg::getConstructorId() const
513 return GroupConstructors->id( GroupConstructors->selected() );
516 //=================================================================================
517 // function : activateSelection
518 // purpose : Activate selection in accordance with myEditCurrentArgument
519 //=================================================================================
520 void OperationGUI_FilletDlg::activateSelection()
523 if ( !myShape->_is_nil() && myEditCurrentArgument == Group2->LineEdit2 )
524 localSelection( myShape, TopAbs_EDGE );
525 else if ( !myShape->_is_nil() && myEditCurrentArgument == Group3->LineEdit2 )
526 localSelection( myShape, TopAbs_FACE );
529 TColStd_MapOfInteger aMap;
530 aMap.Add( GEOM_SHELL );
531 aMap.Add( GEOM_SOLID );
532 aMap.Add( GEOM_COMPOUND );
533 globalSelection( aMap );
536 SelectionIntoArgument();
539 //=================================================================================
540 // function : enableWidgets
541 // purpose : Enable widgets of faces in accordance with value of main object
542 //=================================================================================
543 void OperationGUI_FilletDlg::enableWidgets()
545 int anId = getConstructorId();
547 bool toEnable = !myShape->_is_nil();
551 Group2->LineEdit2->setEnabled( toEnable );
552 Group2->PushButton2->setEnabled( toEnable );
556 Group2->LineEdit2->setText( "" );
560 else if ( anId == 2 )
562 Group3->LineEdit2->setEnabled( toEnable );
563 Group3->PushButton2->setEnabled( toEnable );
567 Group3->LineEdit2->setText( "" );
573 //=================================================================================
574 // function : createOperation
576 //=================================================================================
577 GEOM::GEOM_IOperations_ptr OperationGUI_FilletDlg::createOperation()
579 return getGeomEngine()->GetILocalOperations( getStudyId() );
582 //=================================================================================
583 // function : ClickOnApply()
584 // purpose : Verify validity of input data
585 //=================================================================================
586 bool OperationGUI_FilletDlg::isValid( QString& )
588 switch ( getConstructorId() )
590 case 0: return !myShape->_is_nil();
591 case 1: return !myShape->_is_nil() && myEdges.Extent() > 0;
592 case 2: return !myShape->_is_nil() && myFaces.Extent() > 0;
593 default: return false;
597 //=================================================================================
598 // function : execute
600 //=================================================================================
601 bool OperationGUI_FilletDlg::execute( ObjectList& objects )
603 GEOM::GEOM_Object_var anObj;
605 int anId = getConstructorId();
607 anObj = GEOM::GEOM_ILocalOperations::_narrow(
608 getOperation() )->MakeFilletAll( myShape, getRadius() );
609 else if ( anId == 1 )
611 GEOM::ListOfLong_var aList = new GEOM::ListOfLong;
612 aList->length( myEdges.Extent() );
614 for ( int i = 1, n = myEdges.Extent(); i <= n; i++ )
615 aList[ i - 1 ] = myEdges( i );
616 if ( Group2->RadioButton1->isChecked() )
617 anObj = GEOM::GEOM_ILocalOperations::_narrow(
618 getOperation() )->MakeFilletEdges( myShape, getRadius(), aList );
620 anObj = GEOM::GEOM_ILocalOperations::_narrow( getOperation() )->MakeFilletEdgesR1R2( myShape,
621 (Group2->SpinBox_DY->GetValue()),
622 (Group2->SpinBox_DZ->GetValue()),
625 else if ( anId == 2 )
628 GEOM::ListOfLong_var aList = new GEOM::ListOfLong;
629 aList->length( myFaces.Extent() );
631 for ( int i = 1, n = myFaces.Extent(); i <= n; i++ )
632 aList[ i - 1 ] = myFaces( i );
633 if ( Group3->RadioButton1->isChecked() )
634 anObj = GEOM::GEOM_ILocalOperations::_narrow(
635 getOperation() )->MakeFilletFaces( myShape, getRadius(), aList );
637 anObj = GEOM::GEOM_ILocalOperations::_narrow(
638 getOperation() )->MakeFilletFacesR1R2( myShape, (Group3->SpinBox_DY->GetValue()),
639 (Group3->SpinBox_DZ->GetValue()), aList );
642 if ( !anObj->_is_nil() )
643 objects.push_back( anObj._retn() );
648 //=================================================================================
649 // function : getRadius
650 // purpose : Get radius
651 //=================================================================================
652 double OperationGUI_FilletDlg::getRadius() const
654 int anId = getConstructorId();
655 if ( anId == 0 ) return Group1->SpinBox_DX->GetValue();
656 else if ( anId == 1 ) return Group2->SpinBox_DX->GetValue();
657 else return Group3->SpinBox_DX->GetValue();
660 //=================================================================================
661 // function : RadiobuttonClicked
663 //=================================================================================
665 void OperationGUI_FilletDlg::RadioButton_Clicked()
667 bool flag = ( (Group2->RadioButton1->isChecked()) && (Group3->RadioButton1->isChecked()) );
670 Group2->SpinBox_DX->setEnabled(flag);
671 Group2->SpinBox_DY->setEnabled(!flag);
672 Group2->SpinBox_DZ->setEnabled(!flag);
673 Group2->RadioButton1->setChecked(flag);
674 Group2->RadioButton2->setChecked(!flag);
675 Group3->SpinBox_DX->setEnabled(flag);
676 Group3->SpinBox_DY->setEnabled(!flag);
677 Group3->SpinBox_DZ->setEnabled(!flag);
678 Group3->RadioButton1->setChecked(flag);
679 Group3->RadioButton2->setChecked(!flag);