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_FilletDlg.cxx
25 // Author : Damien COQUERET
29 #include "OperationGUI_FilletDlg.h"
30 #include "DlgRef_1Sel1Spin.h"
31 #include "DlgRef_2Sel1Spin.h"
32 #include "QAD_Desktop.h"
34 #include <TColStd_IndexedMapOfInteger.hxx>
37 #include "GEOMImpl_Types.hxx"
39 //=================================================================================
40 // class : OperationGUI_FilletDlg()
41 // purpose : Constructs a OperationGUI_FilletDlg which is a child of 'parent', with the
42 // name 'name' and widget flags set to 'f'.
43 // The dialog will by default be modeless, unless you set 'modal' to
44 // TRUE to construct a modal dialog.
45 //=================================================================================
46 OperationGUI_FilletDlg::OperationGUI_FilletDlg( QWidget* parent, SALOME_Selection* Sel )
47 :GEOMBase_Skeleton( parent, "OperationGUI_FilletDlg", Sel, false,
48 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
53 QPixmap image0( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM", tr( "ICON_DLG_FILLET_ALL" ) ) );
54 QPixmap image1( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM", tr( "ICON_DLG_FILLET_EDGE" ) ) );
55 QPixmap image2( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM", tr( "ICON_DLG_FILLET_FACE" ) ) );
57 QPixmap iconSelect( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
59 setCaption( tr( "GEOM_FILLET_TITLE" ) );
61 /***************************************************************/
62 GroupConstructors->setTitle( tr( "GEOM_FILLET" ) );
63 RadioButton1->setPixmap( image0 );
64 RadioButton2->setPixmap( image1 );
65 RadioButton3->setPixmap( image2 );
67 Group1 = new DlgRef_1Sel1Spin( this, "Group1" );
68 Group1->GroupBox1->setTitle( tr( "GEOM_FILLET_ALL" ) );
69 Group1->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
70 Group1->TextLabel2->setText( tr( "GEOM_RADIUS" ) );
71 Group1->PushButton1->setPixmap( iconSelect );
72 Group1->LineEdit1->setReadOnly( true );
74 Group2 = new DlgRef_2Sel1Spin( this, "Group2" );
75 Group2->GroupBox1->setTitle( tr( "GEOM_FILLET_EDGES" ) );
76 Group2->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
77 Group2->TextLabel2->setText( tr( "SELECTED_EDGES" ) );
78 Group2->TextLabel3->setText( tr( "GEOM_RADIUS" ) );
79 Group2->PushButton1->setPixmap( iconSelect );
80 Group2->PushButton2->setPixmap( iconSelect );
81 Group2->LineEdit1->setReadOnly( true );
82 Group2->LineEdit2->setReadOnly( true );
84 Group3 = new DlgRef_2Sel1Spin( this, "Group3" );
85 Group3->GroupBox1->setTitle(tr( "GEOM_FILLET_FACES" ) );
86 Group3->TextLabel1->setText(tr( "GEOM_MAIN_OBJECT" ) );
87 Group3->TextLabel2->setText(tr( "SELECTED_FACES" ) );
88 Group3->TextLabel3->setText(tr( "GEOM_RADIUS" ) );
89 Group3->PushButton1->setPixmap( iconSelect );
90 Group3->PushButton2->setPixmap( iconSelect );
91 Group3->LineEdit1->setReadOnly( true );
92 Group3->LineEdit2->setReadOnly( true );
94 Layout1->addWidget( Group1, 2, 0 );
95 Layout1->addWidget( Group2, 2, 0 );
96 Layout1->addWidget( Group3, 2, 0 );
97 /***************************************************************/
99 double SpecificStep = 10.0;
100 Group1->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
101 Group2->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
102 Group3->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
104 /* Initialisations */
109 //=================================================================================
110 // function : ~OperationGUI_FilletDlg()
111 // purpose : Destroys the object and frees any allocated resources
112 //=================================================================================
113 OperationGUI_FilletDlg::~OperationGUI_FilletDlg()
118 //=================================================================================
121 //=================================================================================
122 void OperationGUI_FilletDlg::Init( SALOME_Selection* Sel )
125 myConstructorId = -1;
127 RadioButton1->setChecked( true );
128 myEditCurrentArgument = Group1->LineEdit1;
131 connect( buttonOk , SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
132 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
135 connect( GroupConstructors, SIGNAL( clicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
138 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139 connect(Group2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140 connect(Group3->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141 connect(Group2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
142 connect(Group3->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
145 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
146 connect(Group2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147 connect(Group3->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
150 connect(Group1->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
151 connect(Group2->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
152 connect(Group3->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
155 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
158 initName( tr( "GEOM_FILLET" ) );
168 //=================================================================================
169 // function : ConstructorsClicked()
170 // purpose : Radio button management
171 //=================================================================================
172 void OperationGUI_FilletDlg::ConstructorsClicked( int constructorId )
174 if ( QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC )
176 RadioButton1->setChecked( true );
180 if ( myConstructorId == constructorId )
183 // Get radius from previous widget
185 if ( myConstructorId == 0 ) R = Group1->SpinBox_DX->GetValue();
186 else if ( myConstructorId == 1 ) R = Group2->SpinBox_DX->GetValue();
187 else R = Group3->SpinBox_DX->GetValue();
189 myConstructorId = constructorId;
191 switch ( constructorId )
197 Group1->SpinBox_DX->SetValue( R );
203 Group2->SpinBox_DX->SetValue( R );
209 Group3->SpinBox_DX->SetValue( R );
215 if ( constructorId == 0 ) myEditCurrentArgument = Group1->LineEdit1;
216 else if ( constructorId == 1 ) myEditCurrentArgument = Group2->LineEdit1;
217 else myEditCurrentArgument = Group3->LineEdit1;
222 if ( !myShape->_is_nil() )
224 myEditCurrentArgument->setText( GEOMBase::GetName( myShape ) );
225 GEOMBase_Skeleton::LineEditReturnPressed();
228 myEditCurrentArgument->setText( "" );
234 //=================================================================================
235 // function : ClickOnOk()
237 //=================================================================================
238 void OperationGUI_FilletDlg::ClickOnOk()
240 if ( ClickOnApply() )
245 //=================================================================================
246 // function : ClickOnApply()
248 //=================================================================================
249 bool OperationGUI_FilletDlg::ClickOnApply()
258 //=================================================================================
259 // function : SelectionIntoArgument()
260 // purpose : Called when selection has changed
261 //=================================================================================
262 void OperationGUI_FilletDlg::SelectionIntoArgument()
265 myEditCurrentArgument->setText( "" );
267 // If selection of main object is activated
268 if ( myEditCurrentArgument == Group1->LineEdit1 ||
269 myEditCurrentArgument == Group2->LineEdit1 ||
270 myEditCurrentArgument == Group3->LineEdit1 )
272 if ( mySelection->IObjectCount() == 1 )
274 Standard_Boolean aResult = Standard_False;
275 GEOM::GEOM_Object_var anObj =
276 GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aResult );
278 if ( aResult && !anObj->_is_nil() )
281 myEditCurrentArgument->setText( GEOMBase::GetName( anObj ) );
288 myShape = GEOM::GEOM_Object::_nil();
291 // If face or edge selection is activated
292 else if ( myEditCurrentArgument == Group2->LineEdit2 ||
293 myEditCurrentArgument == Group3->LineEdit2 )
295 if ( mySelection->IObjectCount() == 1 )
297 Standard_Boolean aResult = Standard_False;
298 GEOM::GEOM_Object_var anObj =
299 GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aResult );
301 if ( aResult && !anObj->_is_nil() )
303 TColStd_IndexedMapOfInteger anIndexes;
304 mySelection->GetIndex( mySelection->firstIObject(), anIndexes );
306 if ( anIndexes.Extent() > 0 )
309 if ( anIndexes.Extent() == 1 )
311 int anIndex = anIndexes( 1 );
313 aName = QString( GEOMBase::GetName( anObj ) ) + QString( ":%1" ).arg( anIndex );
316 aName = tr( "GEOM_MEN_POPUP_NAME" ).arg( anIndexes.Extent() );
318 myEditCurrentArgument->setText( aName );
320 if ( myConstructorId == 1 )
335 //=================================================================================
336 // function : LineEditReturnPressed()
338 //=================================================================================
339 void OperationGUI_FilletDlg::LineEditReturnPressed()
341 QLineEdit* send = ( QLineEdit* )sender();
343 if ( send == Group1->LineEdit1 )
344 myEditCurrentArgument = Group1->LineEdit1;
345 else if ( send == Group2->LineEdit1 )
346 myEditCurrentArgument = Group2->LineEdit1;
347 else if ( send == Group3->LineEdit1 )
348 myEditCurrentArgument = Group3->LineEdit1;
352 GEOMBase_Skeleton::LineEditReturnPressed();
357 //=================================================================================
358 // function : SetEditCurrentArgument()
360 //=================================================================================
361 void OperationGUI_FilletDlg::SetEditCurrentArgument()
363 QPushButton* send = (QPushButton*)sender();
365 if ( send == Group1->PushButton1 )
367 Group1->LineEdit1->setFocus();
368 myEditCurrentArgument = Group1->LineEdit1;
370 else if( send == Group2->PushButton1 )
372 Group2->LineEdit1->setFocus();
373 myEditCurrentArgument = Group2->LineEdit1;
375 else if( send == Group2->PushButton2 )
377 Group2->LineEdit2->setFocus();
378 myEditCurrentArgument = Group2->LineEdit2;
380 else if ( send == Group3->PushButton1 )
382 Group3->LineEdit1->setFocus();
383 myEditCurrentArgument = Group3->LineEdit1;
385 else if( send == Group3->PushButton2 )
387 Group3->LineEdit1->setFocus();
388 myEditCurrentArgument = Group3->LineEdit2;
395 //=================================================================================
396 // function : DeactivateActiveDialog()
398 //=================================================================================
399 void OperationGUI_FilletDlg::DeactivateActiveDialog()
401 GEOMBase_Skeleton::DeactivateActiveDialog();
406 //=================================================================================
407 // function : ActivateThisDialog()
409 //=================================================================================
410 void OperationGUI_FilletDlg::ActivateThisDialog()
412 GEOMBase_Skeleton::ActivateThisDialog();
414 connect( mySelection, SIGNAL(currentSelectionChanged()),
415 this, SLOT( SelectionIntoArgument() ) );
422 //=================================================================================
423 // function : enterEvent()
425 //=================================================================================
426 void OperationGUI_FilletDlg::enterEvent( QEvent* e )
428 if ( !GroupConstructors->isEnabled() )
429 this->ActivateThisDialog();
432 //=================================================================================
433 // function : ValueChangedInSpinBox()
435 //=================================================================================
436 void OperationGUI_FilletDlg::ValueChangedInSpinBox( double newValue )
441 //=================================================================================
442 // function : reset()
444 //=================================================================================
445 void OperationGUI_FilletDlg::reset()
447 // Set Initial values of spinboxes
448 Group1->SpinBox_DX->SetValue( 5 );
449 Group2->SpinBox_DX->SetValue( 5 );
450 Group3->SpinBox_DX->SetValue( 5 );
452 Group1->LineEdit1->setText( "" );
453 Group2->LineEdit1->setText( "" );
454 Group2->LineEdit2->setText( "" );
455 Group3->LineEdit1->setText( "" );
456 Group3->LineEdit2->setText( "" );
459 int aConstructorId = getConstructorId();
461 if ( aConstructorId == 0 ) myEditCurrentArgument = Group1->LineEdit1;
462 else if ( aConstructorId == 1 ) myEditCurrentArgument = Group2->LineEdit1;
463 else myEditCurrentArgument = Group3->LineEdit1;
465 myShape = GEOM::GEOM_Object::_nil();
470 erasePreview( true );
477 //=================================================================================
478 // function : getConstructorId()
480 //=================================================================================
481 int OperationGUI_FilletDlg::getConstructorId() const
483 return GroupConstructors->id( GroupConstructors->selected() );
486 //=================================================================================
487 // function : activateSelection
488 // purpose : Activate selection in accordance with myEditCurrentArgument
489 //=================================================================================
490 void OperationGUI_FilletDlg::activateSelection()
493 if ( !myShape->_is_nil() && myEditCurrentArgument == Group2->LineEdit2 )
494 localSelection( myShape, TopAbs_EDGE );
495 else if ( !myShape->_is_nil() && myEditCurrentArgument == Group3->LineEdit2 )
496 localSelection( myShape, TopAbs_FACE );
499 TColStd_MapOfInteger aMap;
500 aMap.Add( GEOM_SHELL );
501 aMap.Add( GEOM_SOLID );
502 aMap.Add( GEOM_COMPOUND );
503 globalSelection( aMap );
506 SelectionIntoArgument();
509 //=================================================================================
510 // function : enableWidgets
511 // purpose : Enable widgets of faces in accordance with value of main object
512 //=================================================================================
513 void OperationGUI_FilletDlg::enableWidgets()
515 int anId = getConstructorId();
517 bool toEnable = !myShape->_is_nil();
521 Group2->LineEdit2->setEnabled( toEnable );
522 Group2->PushButton2->setEnabled( toEnable );
526 Group2->LineEdit2->setText( "" );
530 else if ( anId == 2 )
532 Group3->LineEdit2->setEnabled( toEnable );
533 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,
580 else if ( anId == 1 )
582 GEOM::ListOfLong_var aList = new GEOM::ListOfLong;
583 aList->length( myEdges.Extent() );
585 for ( int i = 1, n = myEdges.Extent(); i <= n; i++ )
586 aList[ i - 1 ] = myEdges( i );
588 anObj = GEOM::GEOM_ILocalOperations::_narrow(
589 getOperation() )->MakeFilletEdges( myShape, getRadius(), aList );
591 else if ( anId == 2 )
594 GEOM::ListOfLong_var aList = new GEOM::ListOfLong;
595 aList->length( myFaces.Extent() );
597 for ( int i = 1, n = myFaces.Extent(); i <= n; i++ )
598 aList[ i - 1 ] = myFaces( i );
600 anObj = GEOM::GEOM_ILocalOperations::_narrow(
601 getOperation() )->MakeFilletFaces( myShape, getRadius(), aList );
604 if ( !anObj->_is_nil() )
605 objects.push_back( anObj._retn() );
610 //=================================================================================
611 // function : getRadius
612 // purpose : Get radius
613 //=================================================================================
614 double OperationGUI_FilletDlg::getRadius() const
616 int anId = getConstructorId();
617 if ( anId == 0 ) return Group1->SpinBox_DX->GetValue();
618 else if ( anId == 1 ) return Group2->SpinBox_DX->GetValue();
619 else return Group3->SpinBox_DX->GetValue();