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"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_Session.h"
35 #include "SalomeApp_Application.h"
36 #include "SalomeApp_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( QWidget* parent )
55 :GEOMBase_Skeleton( parent, "OperationGUI_FilletDlg", false,
56 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
60 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_FILLET_ALL" ) ) );
61 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_FILLET_EDGE" ) ) );
62 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_FILLET_FACE" ) ) );
64 QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->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_2Sel1Spin( 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->PushButton1->setPixmap( iconSelect );
87 Group2->PushButton2->setPixmap( iconSelect );
88 Group2->LineEdit1->setReadOnly( true );
89 Group2->LineEdit2->setReadOnly( true );
91 Group3 = new DlgRef_2Sel1Spin( this, "Group3" );
92 Group3->GroupBox1->setTitle(tr( "GEOM_FILLET_FACES" ) );
93 Group3->TextLabel1->setText(tr( "GEOM_MAIN_OBJECT" ) );
94 Group3->TextLabel2->setText(tr( "SELECTED_FACES" ) );
95 Group3->TextLabel3->setText(tr( "GEOM_RADIUS" ) );
96 Group3->PushButton1->setPixmap( iconSelect );
97 Group3->PushButton2->setPixmap( iconSelect );
98 Group3->LineEdit1->setReadOnly( true );
99 Group3->LineEdit2->setReadOnly( true );
101 Layout1->addWidget( Group1, 2, 0 );
102 Layout1->addWidget( Group2, 2, 0 );
103 Layout1->addWidget( Group3, 2, 0 );
104 /***************************************************************/
106 double SpecificStep = 10.0;
107 Group1->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
108 Group2->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
109 Group3->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, SpecificStep, 3);
111 /* Initialisations */
116 //=================================================================================
117 // function : ~OperationGUI_FilletDlg()
118 // purpose : Destroys the object and frees any allocated resources
119 //=================================================================================
120 OperationGUI_FilletDlg::~OperationGUI_FilletDlg()
125 //=================================================================================
128 //=================================================================================
129 void OperationGUI_FilletDlg::Init()
131 myConstructorId = -1;
133 RadioButton1->setChecked( true );
134 myEditCurrentArgument = Group1->LineEdit1;
137 connect( buttonOk , SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
138 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
141 connect( GroupConstructors, SIGNAL( clicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
144 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
145 connect(Group2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146 connect(Group3->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
147 connect(Group2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
148 connect(Group3->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
151 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
152 connect(Group2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
153 connect(Group3->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
156 connect(Group1->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
157 connect(Group2->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
158 connect(Group3->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
161 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
162 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
165 initName( tr( "GEOM_FILLET" ) );
175 //=================================================================================
176 // function : ConstructorsClicked()
177 // purpose : Radio button management
178 //=================================================================================
179 void OperationGUI_FilletDlg::ConstructorsClicked( int constructorId )
181 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
182 != OCCViewer_Viewer::Type() )
184 RadioButton1->setChecked( true );
188 if ( myConstructorId == constructorId )
191 // Get radius from previous widget
193 if ( myConstructorId == 0 ) R = Group1->SpinBox_DX->GetValue();
194 else if ( myConstructorId == 1 ) R = Group2->SpinBox_DX->GetValue();
195 else R = Group3->SpinBox_DX->GetValue();
197 myConstructorId = constructorId;
199 switch ( constructorId )
205 Group1->SpinBox_DX->SetValue( R );
211 Group2->SpinBox_DX->SetValue( R );
217 Group3->SpinBox_DX->SetValue( R );
223 if ( constructorId == 0 ) myEditCurrentArgument = Group1->LineEdit1;
224 else if ( constructorId == 1 ) myEditCurrentArgument = Group2->LineEdit1;
225 else myEditCurrentArgument = Group3->LineEdit1;
230 if ( !myShape->_is_nil() )
232 myEditCurrentArgument->setText( GEOMBase::GetName( myShape ) );
233 GEOMBase_Skeleton::LineEditReturnPressed();
236 myEditCurrentArgument->setText( "" );
242 //=================================================================================
243 // function : ClickOnOk()
245 //=================================================================================
246 void OperationGUI_FilletDlg::ClickOnOk()
248 if ( ClickOnApply() )
253 //=================================================================================
254 // function : ClickOnApply()
256 //=================================================================================
257 bool OperationGUI_FilletDlg::ClickOnApply()
266 //=================================================================================
267 // function : SelectionIntoArgument()
268 // purpose : Called when selection has changed
269 //=================================================================================
270 void OperationGUI_FilletDlg::SelectionIntoArgument()
273 myEditCurrentArgument->setText( "" );
275 // If selection of main object is activated
276 if ( myEditCurrentArgument == Group1->LineEdit1 ||
277 myEditCurrentArgument == Group2->LineEdit1 ||
278 myEditCurrentArgument == Group3->LineEdit1 )
280 if ( IObjectCount() == 1 )
282 Standard_Boolean aResult = Standard_False;
283 GEOM::GEOM_Object_var anObj =
284 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
286 if ( aResult && !anObj->_is_nil() )
289 myEditCurrentArgument->setText( GEOMBase::GetName( anObj ) );
296 myShape = GEOM::GEOM_Object::_nil();
299 // If face or edge selection is activated
300 else if ( myEditCurrentArgument == Group2->LineEdit2 ||
301 myEditCurrentArgument == Group3->LineEdit2 )
303 if ( IObjectCount() == 1 )
305 Standard_Boolean aResult = Standard_False;
306 GEOM::GEOM_Object_var anObj =
307 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
309 if ( aResult && !anObj->_is_nil() )
311 TColStd_IndexedMapOfInteger anIndexes;
312 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
314 if ( anIndexes.Extent() > 0 )
317 if ( anIndexes.Extent() == 1 )
319 int anIndex = anIndexes( 1 );
321 aName = QString( GEOMBase::GetName( anObj ) ) + QString( ":%1" ).arg( anIndex );
324 aName = tr( "GEOM_MEN_POPUP_NAME" ).arg( anIndexes.Extent() );
326 myEditCurrentArgument->setText( aName );
328 if ( myConstructorId == 1 )
343 //=================================================================================
344 // function : LineEditReturnPressed()
346 //=================================================================================
347 void OperationGUI_FilletDlg::LineEditReturnPressed()
349 QLineEdit* send = ( QLineEdit* )sender();
351 if ( send == Group1->LineEdit1 )
352 myEditCurrentArgument = Group1->LineEdit1;
353 else if ( send == Group2->LineEdit1 )
354 myEditCurrentArgument = Group2->LineEdit1;
355 else if ( send == Group3->LineEdit1 )
356 myEditCurrentArgument = Group3->LineEdit1;
360 GEOMBase_Skeleton::LineEditReturnPressed();
365 //=================================================================================
366 // function : SetEditCurrentArgument()
368 //=================================================================================
369 void OperationGUI_FilletDlg::SetEditCurrentArgument()
371 QPushButton* send = (QPushButton*)sender();
373 if ( send == Group1->PushButton1 )
375 Group1->LineEdit1->setFocus();
376 myEditCurrentArgument = Group1->LineEdit1;
378 else if( send == Group2->PushButton1 )
380 Group2->LineEdit1->setFocus();
381 myEditCurrentArgument = Group2->LineEdit1;
383 else if( send == Group2->PushButton2 )
385 Group2->LineEdit2->setFocus();
386 myEditCurrentArgument = Group2->LineEdit2;
388 else if ( send == Group3->PushButton1 )
390 Group3->LineEdit1->setFocus();
391 myEditCurrentArgument = Group3->LineEdit1;
393 else if( send == Group3->PushButton2 )
395 Group3->LineEdit1->setFocus();
396 myEditCurrentArgument = Group3->LineEdit2;
403 //=================================================================================
404 // function : DeactivateActiveDialog()
406 //=================================================================================
407 void OperationGUI_FilletDlg::DeactivateActiveDialog()
409 GEOMBase_Skeleton::DeactivateActiveDialog();
414 //=================================================================================
415 // function : ActivateThisDialog()
417 //=================================================================================
418 void OperationGUI_FilletDlg::ActivateThisDialog()
420 GEOMBase_Skeleton::ActivateThisDialog();
422 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
423 SIGNAL(currentSelectionChanged()), this, SLOT( SelectionIntoArgument() ) );
430 //=================================================================================
431 // function : enterEvent()
433 //=================================================================================
434 void OperationGUI_FilletDlg::enterEvent( QEvent* e )
436 if ( !GroupConstructors->isEnabled() )
437 this->ActivateThisDialog();
440 //=================================================================================
441 // function : ValueChangedInSpinBox()
443 //=================================================================================
444 void OperationGUI_FilletDlg::ValueChangedInSpinBox( double newValue )
449 //=================================================================================
450 // function : reset()
452 //=================================================================================
453 void OperationGUI_FilletDlg::reset()
455 // Set Initial values of spinboxes
456 Group1->SpinBox_DX->SetValue( 5 );
457 Group2->SpinBox_DX->SetValue( 5 );
458 Group3->SpinBox_DX->SetValue( 5 );
460 Group1->LineEdit1->setText( "" );
461 Group2->LineEdit1->setText( "" );
462 Group2->LineEdit2->setText( "" );
463 Group3->LineEdit1->setText( "" );
464 Group3->LineEdit2->setText( "" );
467 int aConstructorId = getConstructorId();
469 if ( aConstructorId == 0 ) myEditCurrentArgument = Group1->LineEdit1;
470 else if ( aConstructorId == 1 ) myEditCurrentArgument = Group2->LineEdit1;
471 else myEditCurrentArgument = Group3->LineEdit1;
473 myShape = GEOM::GEOM_Object::_nil();
478 erasePreview( true );
485 //=================================================================================
486 // function : getConstructorId()
488 //=================================================================================
489 int OperationGUI_FilletDlg::getConstructorId() const
491 return GroupConstructors->id( GroupConstructors->selected() );
494 //=================================================================================
495 // function : activateSelection
496 // purpose : Activate selection in accordance with myEditCurrentArgument
497 //=================================================================================
498 void OperationGUI_FilletDlg::activateSelection()
501 if ( !myShape->_is_nil() && myEditCurrentArgument == Group2->LineEdit2 )
502 localSelection( myShape, TopAbs_EDGE );
503 else if ( !myShape->_is_nil() && myEditCurrentArgument == Group3->LineEdit2 )
504 localSelection( myShape, TopAbs_FACE );
507 TColStd_MapOfInteger aMap;
508 aMap.Add( GEOM_SHELL );
509 aMap.Add( GEOM_SOLID );
510 aMap.Add( GEOM_COMPOUND );
511 globalSelection( aMap );
514 SelectionIntoArgument();
517 //=================================================================================
518 // function : enableWidgets
519 // purpose : Enable widgets of faces in accordance with value of main object
520 //=================================================================================
521 void OperationGUI_FilletDlg::enableWidgets()
523 int anId = getConstructorId();
525 bool toEnable = !myShape->_is_nil();
529 Group2->LineEdit2->setEnabled( toEnable );
530 Group2->PushButton2->setEnabled( toEnable );
534 Group2->LineEdit2->setText( "" );
538 else if ( anId == 2 )
540 Group3->LineEdit2->setEnabled( toEnable );
541 Group3->PushButton2->setEnabled( toEnable );
545 Group3->LineEdit2->setText( "" );
551 //=================================================================================
552 // function : createOperation
554 //=================================================================================
555 GEOM::GEOM_IOperations_ptr OperationGUI_FilletDlg::createOperation()
557 return getGeomEngine()->GetILocalOperations( getStudyId() );
560 //=================================================================================
561 // function : ClickOnApply()
562 // purpose : Verify validity of input data
563 //=================================================================================
564 bool OperationGUI_FilletDlg::isValid( QString& )
566 switch ( getConstructorId() )
568 case 0: return !myShape->_is_nil();
569 case 1: return !myShape->_is_nil() && myEdges.Extent() > 0;
570 case 2: return !myShape->_is_nil() && myFaces.Extent() > 0;
571 default: return false;
575 //=================================================================================
576 // function : execute
578 //=================================================================================
579 bool OperationGUI_FilletDlg::execute( ObjectList& objects )
581 GEOM::GEOM_Object_var anObj;
583 int anId = getConstructorId();
585 anObj = GEOM::GEOM_ILocalOperations::_narrow(
586 getOperation() )->MakeFilletAll( myShape,
588 else if ( anId == 1 )
590 GEOM::ListOfLong_var aList = new GEOM::ListOfLong;
591 aList->length( myEdges.Extent() );
593 for ( int i = 1, n = myEdges.Extent(); i <= n; i++ )
594 aList[ i - 1 ] = myEdges( i );
596 anObj = GEOM::GEOM_ILocalOperations::_narrow(
597 getOperation() )->MakeFilletEdges( myShape, getRadius(), aList );
599 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 anObj = GEOM::GEOM_ILocalOperations::_narrow(
609 getOperation() )->MakeFilletFaces( myShape, getRadius(), aList );
612 if ( !anObj->_is_nil() )
613 objects.push_back( anObj._retn() );
618 //=================================================================================
619 // function : getRadius
620 // purpose : Get radius
621 //=================================================================================
622 double OperationGUI_FilletDlg::getRadius() const
624 int anId = getConstructorId();
625 if ( anId == 0 ) return Group1->SpinBox_DX->GetValue();
626 else if ( anId == 1 ) return Group2->SpinBox_DX->GetValue();
627 else return Group3->SpinBox_DX->GetValue();