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_2Sel1Spin.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_2Sel1Spin( 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->PushButton1->setPixmap( iconSelect );
88 Group2->PushButton2->setPixmap( iconSelect );
89 Group2->LineEdit1->setReadOnly( true );
90 Group2->LineEdit2->setReadOnly( true );
92 Group3 = new DlgRef_2Sel1Spin( this, "Group3" );
93 Group3->GroupBox1->setTitle(tr( "GEOM_FILLET_FACES" ) );
94 Group3->TextLabel1->setText(tr( "GEOM_MAIN_OBJECT" ) );
95 Group3->TextLabel2->setText(tr( "SELECTED_FACES" ) );
96 Group3->TextLabel3->setText(tr( "GEOM_RADIUS" ) );
97 Group3->PushButton1->setPixmap( iconSelect );
98 Group3->PushButton2->setPixmap( iconSelect );
99 Group3->LineEdit1->setReadOnly( true );
100 Group3->LineEdit2->setReadOnly( true );
102 Layout1->addWidget( Group1, 2, 0 );
103 Layout1->addWidget( Group2, 2, 0 );
104 Layout1->addWidget( Group3, 2, 0 );
105 /***************************************************************/
107 double SpecificStep = 10.0;
108 Group1->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
109 Group2->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
110 Group3->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
112 setHelpFileName("fillet.htm");
114 /* Initialisations */
119 //=================================================================================
120 // function : ~OperationGUI_FilletDlg()
121 // purpose : Destroys the object and frees any allocated resources
122 //=================================================================================
123 OperationGUI_FilletDlg::~OperationGUI_FilletDlg()
128 //=================================================================================
131 //=================================================================================
132 void OperationGUI_FilletDlg::Init()
134 myConstructorId = -1;
136 RadioButton1->setChecked( true );
137 myEditCurrentArgument = Group1->LineEdit1;
140 connect( buttonOk , SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
141 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
144 connect( GroupConstructors, SIGNAL( clicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
147 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
148 connect(Group2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
149 connect(Group3->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
150 connect(Group2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
151 connect(Group3->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
155 connect(Group2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
156 connect(Group3->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
159 connect(Group1->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
160 connect(Group2->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
161 connect(Group3->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
164 connect(myGeomGUI->getApp()->selectionMgr(),
165 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
167 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 myGeomGUI->getApp()->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 : ActivateThisDialog()
406 //=================================================================================
407 void OperationGUI_FilletDlg::ActivateThisDialog()
409 GEOMBase_Skeleton::ActivateThisDialog();
411 connect(myGeomGUI->getApp()->selectionMgr(),
412 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
419 //=================================================================================
420 // function : enterEvent()
422 //=================================================================================
423 void OperationGUI_FilletDlg::enterEvent( QEvent* e )
425 if ( !GroupConstructors->isEnabled() )
426 this->ActivateThisDialog();
429 //=================================================================================
430 // function : ValueChangedInSpinBox()
432 //=================================================================================
433 void OperationGUI_FilletDlg::ValueChangedInSpinBox( double newValue )
438 //=================================================================================
439 // function : reset()
441 //=================================================================================
442 void OperationGUI_FilletDlg::reset()
444 // Set Initial values of spinboxes
445 Group1->SpinBox_DX->SetValue( 5 );
446 Group2->SpinBox_DX->SetValue( 5 );
447 Group3->SpinBox_DX->SetValue( 5 );
449 Group1->LineEdit1->setText( "" );
450 Group2->LineEdit1->setText( "" );
451 Group2->LineEdit2->setText( "" );
452 Group3->LineEdit1->setText( "" );
453 Group3->LineEdit2->setText( "" );
456 int aConstructorId = getConstructorId();
458 if ( aConstructorId == 0 ) myEditCurrentArgument = Group1->LineEdit1;
459 else if ( aConstructorId == 1 ) myEditCurrentArgument = Group2->LineEdit1;
460 else myEditCurrentArgument = Group3->LineEdit1;
462 myShape = GEOM::GEOM_Object::_nil();
467 erasePreview( true );
474 //=================================================================================
475 // function : getConstructorId()
477 //=================================================================================
478 int OperationGUI_FilletDlg::getConstructorId() const
480 return GroupConstructors->id( GroupConstructors->selected() );
483 //=================================================================================
484 // function : activateSelection
485 // purpose : Activate selection in accordance with myEditCurrentArgument
486 //=================================================================================
487 void OperationGUI_FilletDlg::activateSelection()
490 if ( !myShape->_is_nil() && myEditCurrentArgument == Group2->LineEdit2 )
491 localSelection( myShape, TopAbs_EDGE );
492 else if ( !myShape->_is_nil() && myEditCurrentArgument == Group3->LineEdit2 )
493 localSelection( myShape, TopAbs_FACE );
496 TColStd_MapOfInteger aMap;
497 aMap.Add( GEOM_SHELL );
498 aMap.Add( GEOM_SOLID );
499 aMap.Add( GEOM_COMPOUND );
500 globalSelection( aMap );
503 SelectionIntoArgument();
506 //=================================================================================
507 // function : enableWidgets
508 // purpose : Enable widgets of faces in accordance with value of main object
509 //=================================================================================
510 void OperationGUI_FilletDlg::enableWidgets()
512 int anId = getConstructorId();
514 bool toEnable = !myShape->_is_nil();
518 Group2->LineEdit2->setEnabled( toEnable );
519 Group2->PushButton2->setEnabled( toEnable );
523 Group2->LineEdit2->setText( "" );
527 else if ( anId == 2 )
529 Group3->LineEdit2->setEnabled( toEnable );
530 Group3->PushButton2->setEnabled( toEnable );
534 Group3->LineEdit2->setText( "" );
540 //=================================================================================
541 // function : createOperation
543 //=================================================================================
544 GEOM::GEOM_IOperations_ptr OperationGUI_FilletDlg::createOperation()
546 return getGeomEngine()->GetILocalOperations( getStudyId() );
549 //=================================================================================
550 // function : ClickOnApply()
551 // purpose : Verify validity of input data
552 //=================================================================================
553 bool OperationGUI_FilletDlg::isValid( QString& )
555 switch ( getConstructorId() )
557 case 0: return !myShape->_is_nil();
558 case 1: return !myShape->_is_nil() && myEdges.Extent() > 0;
559 case 2: return !myShape->_is_nil() && myFaces.Extent() > 0;
560 default: return false;
564 //=================================================================================
565 // function : execute
567 //=================================================================================
568 bool OperationGUI_FilletDlg::execute( ObjectList& objects )
570 GEOM::GEOM_Object_var anObj;
572 int anId = getConstructorId();
574 anObj = GEOM::GEOM_ILocalOperations::_narrow(
575 getOperation() )->MakeFilletAll( myShape,
577 else if ( anId == 1 )
579 GEOM::ListOfLong_var aList = new GEOM::ListOfLong;
580 aList->length( myEdges.Extent() );
582 for ( int i = 1, n = myEdges.Extent(); i <= n; i++ )
583 aList[ i - 1 ] = myEdges( i );
585 anObj = GEOM::GEOM_ILocalOperations::_narrow(
586 getOperation() )->MakeFilletEdges( myShape, getRadius(), aList );
588 else if ( anId == 2 )
591 GEOM::ListOfLong_var aList = new GEOM::ListOfLong;
592 aList->length( myFaces.Extent() );
594 for ( int i = 1, n = myFaces.Extent(); i <= n; i++ )
595 aList[ i - 1 ] = myFaces( i );
597 anObj = GEOM::GEOM_ILocalOperations::_narrow(
598 getOperation() )->MakeFilletFaces( myShape, getRadius(), aList );
601 if ( !anObj->_is_nil() )
602 objects.push_back( anObj._retn() );
607 //=================================================================================
608 // function : getRadius
609 // purpose : Get radius
610 //=================================================================================
611 double OperationGUI_FilletDlg::getRadius() const
613 int anId = getConstructorId();
614 if ( anId == 0 ) return Group1->SpinBox_DX->GetValue();
615 else if ( anId == 1 ) return Group2->SpinBox_DX->GetValue();
616 else return Group3->SpinBox_DX->GetValue();