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
22 // File : OperationGUI_ChamferDlg.cxx
23 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 #include "OperationGUI_ChamferDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_ViewWindow.h>
36 #include <SUIT_ViewManager.h>
37 #include <SalomeApp_Application.h>
38 #include <LightApp_SelectionMgr.h>
39 #include <OCCViewer_ViewModel.h>
41 #include <TColStd_MapOfInteger.hxx>
43 #include <GEOMImpl_Types.hxx>
45 //=================================================================================
46 // class : OperationGUI_ChamferDlg()
47 // purpose : Constructs a OperationGUI_ChamferDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 OperationGUI_ChamferDlg::OperationGUI_ChamferDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
53 : GEOMBase_Skeleton( theGeometryGUI, parent, false )
55 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CHAMFER_ALL" ) ) );
56 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CHAMFER_EDGE" ) ) );
57 QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CHAMFER_FACE" ) ) );
58 QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
60 setWindowTitle( tr( "GEOM_CHAMFER_TITLE" ) );
62 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CHAMFER" ) );
64 mainFrame()->RadioButton1->setIcon( image1 );
65 mainFrame()->RadioButton2->setIcon( image2 );
66 mainFrame()->RadioButton3->setIcon( image3 );
70 myGrp1 = new QGroupBox( tr( "GEOM_CHAMFER_ALL" ), centralWidget() );
72 QGridLayout* aLayout = new QGridLayout( myGrp1 );
73 aLayout->setMargin( 9 ); aLayout->setSpacing( 6 );
75 createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, myGrp1, aLayout, MainObj1 );
77 int row = aLayout->rowCount();
78 aLayout->addWidget( new QLabel( tr( "D" ), myGrp1 ), row, 0 );
79 aLayout->addWidget( ( mySpinBox[ SpinBox1 ] = new QDoubleSpinBox( myGrp1 ) ), row++, 2 );
80 aLayout->setRowStretch( row, 10 );
82 // Create second group
84 myGrp2 = new QGroupBox( tr( "GEOM_CHAMFER_EDGES" ), centralWidget() );
86 aLayout = new QGridLayout( myGrp2 );
87 aLayout->setMargin( 9 ); aLayout->setSpacing( 6 );
89 createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, myGrp2, aLayout, MainObj2 );
90 createSelWg( tr( "FACE_1" ), iconSelect, myGrp2, aLayout, Face1 );
91 createSelWg( tr( "FACE_2" ), iconSelect, myGrp2, aLayout, Face2 );
93 row = aLayout->rowCount();
95 aLayout->addWidget( new QLabel( tr( "GEOM_D1" ), myGrp2 ), row, 0 );
96 aLayout->addWidget( ( mySpinBox[ SpinBox21 ] = new QDoubleSpinBox( myGrp2 ) ), row++, 2 );
97 aLayout->addWidget( new QLabel( tr( "GEOM_D2" ), myGrp2 ), row, 0 );
98 aLayout->addWidget( ( mySpinBox[ SpinBox22 ] = new QDoubleSpinBox( myGrp2 ) ), row++, 2 );
99 aLayout->setRowStretch( row, 10 );
101 // Create third group
103 myGrp3 = new QGroupBox( tr( "GEOM_CHAMFER_FACES" ), centralWidget() );
105 aLayout = new QGridLayout( myGrp3 );
106 aLayout->setMargin( 9 ); aLayout->setSpacing( 6 );
108 createSelWg( tr( "GEOM_MAIN_OBJECT" ), iconSelect, myGrp3, aLayout, MainObj3 );
109 createSelWg( tr( "SELECTED_FACES" ), iconSelect, myGrp3, aLayout, Faces );
111 row = aLayout->rowCount();
113 aLayout->addWidget( new QLabel( tr( "GEOM_D1" ), myGrp3 ), row, 0 );
114 aLayout->addWidget( ( mySpinBox[ SpinBox31 ] = new QDoubleSpinBox( myGrp3 ) ), row++, 2 );
115 aLayout->addWidget( new QLabel( tr( "GEOM_D2" ), myGrp3 ), row, 0 );
116 aLayout->addWidget( ( mySpinBox[ SpinBox32 ] = new QDoubleSpinBox( myGrp3 ) ), row++, 2 );
117 aLayout->setRowStretch( row, 10 );
119 // Add groups to layout
121 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
122 layout->setMargin( 0 ); layout->setSpacing( 6 );
123 layout->addWidget( myGrp1 );
124 layout->addWidget( myGrp2 );
125 layout->addWidget( myGrp3 );
127 // Set range of spinboxes
129 double SpecificStep = 10.0;
130 QMap< int, QDoubleSpinBox* >::iterator anIter;
131 for ( anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter )
132 initSpinBox( anIter.value(), 0.001, COORD_MAX, SpecificStep, 3 );
134 setHelpFileName( "chamfer.htm" );
136 /* Initialisations */
141 //=================================================================================
142 // function : ~OperationGUI_ChamferDlg()
143 // purpose : Destroys the object and frees any allocated resources
144 //=================================================================================
145 OperationGUI_ChamferDlg::~OperationGUI_ChamferDlg()
150 //=================================================================================
153 //=================================================================================
154 void OperationGUI_ChamferDlg::Init()
156 myConstructorId = -1;
159 /* signals and slots connections */
162 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
163 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
166 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
169 QMap< int, QPushButton* >::iterator anIterBtn;
170 for ( anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn )
171 connect( anIterBtn.value(), SIGNAL( clicked() ),
172 this, SLOT( SetEditCurrentArgument() ) );
175 QMap< int, QLineEdit* >::iterator anIterLE2;
176 for ( anIterLE2 = mySelName.begin(); anIterLE2 != mySelName.end(); ++anIterLE2 )
177 connect( anIterLE2.value(), SIGNAL( returnPressed() ),
178 this, SLOT( LineEditReturnPressed() ) );
181 QMap< int, QDoubleSpinBox* >::iterator anIterSpin;
182 for ( anIterSpin = mySpinBox.begin(); anIterSpin != mySpinBox.end(); ++anIterSpin )
183 connect( anIterSpin.value(), SIGNAL( valueChanged( double ) ),
184 this, SLOT( ValueChangedInSpinBox( double ) ) );
187 connect( myGeomGUI->getApp()->selectionMgr(),
188 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
190 initName( tr( "GEOM_CHAMFER" ) );
192 ConstructorsClicked( 0 );
196 //=================================================================================
197 // function : ConstructorsClicked()
198 // purpose : Radio button management
199 //=================================================================================
200 void OperationGUI_ChamferDlg::ConstructorsClicked( int constructorId )
202 // Activate next widget
203 if ( myGeomGUI->getApp()->desktop()->activeWindow()->getViewManager()->getType()
204 != OCCViewer_Viewer::Type() ) {
205 mainFrame()->RadioButton1->setChecked( true );
209 if ( myConstructorId == constructorId )
212 // Get values from previous widget
213 double D1 = 5, D2 = 5;
214 if ( myConstructorId == 0 )
215 D1 = D2 = mySpinBox[ SpinBox1 ]->value();
216 else if ( myConstructorId == 1 ) {
217 D1 = mySpinBox[ SpinBox21 ]->value();
218 D2 = mySpinBox[ SpinBox22 ]->value();
220 else if ( myConstructorId == 2 ) {
221 D1 = mySpinBox[ SpinBox31 ]->value();
222 D2 = mySpinBox[ SpinBox32 ]->value();
225 myConstructorId = constructorId;
227 switch ( constructorId ) {
232 mySpinBox[ SpinBox1 ]->setValue( D1 );
238 mySpinBox[ SpinBox21 ]->setValue( D1 );
239 mySpinBox[ SpinBox22 ]->setValue( D2 );
245 mySpinBox[ SpinBox31 ]->setValue( D1 );
246 mySpinBox[ SpinBox32 ]->setValue( D2 );
252 if ( constructorId == 0 ) myEditCurrentArgument = mySelName[ MainObj1 ];
253 else if ( constructorId == 1 ) myEditCurrentArgument = mySelName[ MainObj2 ];
254 else myEditCurrentArgument = mySelName[ MainObj3 ];
259 if ( !myShape->_is_nil() )
261 myEditCurrentArgument->setText( GEOMBase::GetName( myShape ) );
262 GEOMBase_Skeleton::LineEditReturnPressed();
265 myEditCurrentArgument->setText( "" );
267 qApp->processEvents();
269 resize( minimumSize() );
275 //=================================================================================
276 // function : ClickOnOk()
278 //=================================================================================
279 void OperationGUI_ChamferDlg::ClickOnOk()
281 if ( ClickOnApply() )
285 //=================================================================================
286 // function : ClickOnApply()
288 //=================================================================================
289 bool OperationGUI_ChamferDlg::ClickOnApply()
299 //=================================================================================
300 // function : SelectionIntoArgument()
301 // purpose : Called when selection has changed
302 //=================================================================================
303 void OperationGUI_ChamferDlg::SelectionIntoArgument()
306 myEditCurrentArgument->setText( "" );
308 // Get index of current selection focus
310 QMap< int, QLineEdit* >::iterator anIter;
311 for ( anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter ) {
312 if ( myEditCurrentArgument == anIter.value() ) {
313 aCurrFocus = anIter.key();
318 // If selection of main object is activated
319 if ( aCurrFocus == MainObj1 || aCurrFocus == MainObj2 || aCurrFocus == MainObj3 ) {
320 if ( IObjectCount() == 1 ) {
321 Standard_Boolean aResult = Standard_False;
322 GEOM::GEOM_Object_var anObj =
323 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
325 if ( aResult && !anObj->_is_nil() ) {
327 mySelName[ aCurrFocus ]->setText( GEOMBase::GetName( anObj ) );
334 myShape = GEOM::GEOM_Object::_nil();
337 // If face selection of second tab is activated
338 else if ( aCurrFocus == Face1 || aCurrFocus == Face2 ) {
339 if ( IObjectCount() == 1 ) {
340 Standard_Boolean aResult = Standard_False;
341 GEOM::GEOM_Object_var anObj =
342 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
344 if ( aResult && !anObj->_is_nil() ) {
345 TColStd_IndexedMapOfInteger anIndexes;
346 ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
348 if ( anIndexes.Extent() == 1 ) {
349 int anIndex = anIndexes( 1 );
350 QString aFaceName = QString( GEOMBase::GetName( anObj ) ) + ":%1";
351 myEditCurrentArgument->setText( aFaceName.arg( anIndex ) );
352 myFace[ aCurrFocus ] = anIndex;
359 myFace[ aCurrFocus ] = -1;
361 // If face selection of third tab is activated
362 else if ( aCurrFocus == Faces ) {
363 if ( IObjectCount() == 1 ) {
364 Standard_Boolean aResult = Standard_False;
365 GEOM::GEOM_Object_var anObj =
366 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
368 if ( aResult && !anObj->_is_nil() ) {
369 TColStd_IndexedMapOfInteger anIndexes;
370 ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr()->GetIndexes( firstIObject(), anIndexes );
372 if ( anIndexes.Extent() > 0 ) {
374 if ( anIndexes.Extent() == 1 ) {
375 int anIndex = anIndexes( 1 );
377 aFaceName = QString( GEOMBase::GetName( anObj ) ) + QString( ":%1" ).arg( anIndex );
380 aFaceName = tr( "GEOM_MEN_POPUP_NAME" ).arg( anIndexes.Extent() );
383 myEditCurrentArgument->setText( aFaceName );
395 //=================================================================================
396 // function : LineEditReturnPressed()
398 //=================================================================================
399 void OperationGUI_ChamferDlg::LineEditReturnPressed()
401 QLineEdit* aSender = ( QLineEdit* )sender();
403 QMap< int, QLineEdit* >::iterator anIterLE;
404 for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
405 if ( anIterLE.value() == aSender )
406 myEditCurrentArgument = anIterLE.value();
408 GEOMBase_Skeleton::LineEditReturnPressed();
412 //=================================================================================
413 // function : SetEditCurrentArgument()
415 //=================================================================================
416 void OperationGUI_ChamferDlg::SetEditCurrentArgument()
418 QPushButton* aSender = ( QPushButton* )sender();
420 QMap< int, QPushButton* >::iterator anIter;
421 for ( anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter ) {
422 if ( anIter.value() == aSender ) {
423 mySelName[ anIter.key() ]->setFocus();
424 myEditCurrentArgument = mySelName[ anIter.key() ];
432 //=================================================================================
433 // function : ActivateThisDialog()
435 //=================================================================================
436 void OperationGUI_ChamferDlg::ActivateThisDialog()
438 GEOMBase_Skeleton::ActivateThisDialog();
440 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
441 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
448 //=================================================================================
449 // function : enterEvent()
451 //=================================================================================
452 void OperationGUI_ChamferDlg::enterEvent( QEvent* )
454 if ( !mainFrame()->GroupConstructors->isEnabled() )
455 this->ActivateThisDialog();
459 //=================================================================================
460 // function : ValueChangedInSpinBox()
462 //=================================================================================
463 void OperationGUI_ChamferDlg::ValueChangedInSpinBox( double )
469 //=================================================================================
470 // function : createSelWg()
472 //=================================================================================
473 void OperationGUI_ChamferDlg::createSelWg( const QString& theLbl,
476 QGridLayout* theLayout,
479 QLabel* lab = new QLabel( theLbl, theParent );
480 mySelBtn[ theId ] = new QPushButton( theParent );
481 mySelBtn[ theId ]->setIcon( thePix );
482 mySelName[ theId ] = new QLineEdit( theParent );
483 mySelName[ theId ]->setReadOnly( true );
484 int row = theLayout->rowCount();
485 theLayout->addWidget( lab, row, 0 );
486 theLayout->addWidget( mySelBtn[ theId ], row, 1 );
487 theLayout->addWidget( mySelName[ theId ], row, 2 );
490 //=================================================================================
491 // function : reset()
493 //=================================================================================
494 void OperationGUI_ChamferDlg::reset()
496 // Set Initial values of spinboxes
497 QMap< int, QDoubleSpinBox* >::iterator anIter;
498 for ( anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter )
499 anIter.value()->setValue( 5 );
502 QMap< int, QLineEdit* >::iterator anIterLE;
503 for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
504 anIterLE.value()->setText( "" );
507 int aConstructorId = getConstructorId();
509 if ( aConstructorId == 0 ) myEditCurrentArgument = mySelName[ MainObj1 ];
510 else if ( aConstructorId == 1 ) myEditCurrentArgument = mySelName[ MainObj2 ];
511 else myEditCurrentArgument = mySelName[ MainObj3 ];
513 myShape = GEOM::GEOM_Object::_nil();
516 myFace[ Face1 ] = -1;
517 myFace[ Face2 ] = -1;
519 erasePreview( true );
526 //=================================================================================
527 // function : activateSelection
528 // purpose : Activate selection in accordance with myEditCurrentArgument
529 //=================================================================================
530 void OperationGUI_ChamferDlg::activateSelection()
532 if ( !myShape->_is_nil() &&
533 ( myEditCurrentArgument == mySelName[ Face1 ] ||
534 myEditCurrentArgument == mySelName[ Face2 ] ||
535 myEditCurrentArgument == mySelName[ Faces ] ) )
536 localSelection( myShape, TopAbs_FACE );
539 TColStd_MapOfInteger aMap;
540 aMap.Add( GEOM_SHELL );
541 aMap.Add( GEOM_SOLID );
542 aMap.Add( GEOM_COMPOUND );
543 globalSelection( aMap );
546 SelectionIntoArgument();
549 //=================================================================================
550 // function : enableWidgets
551 // purpose : Enable widgets of faces in accordance with value of main object
552 //=================================================================================
553 void OperationGUI_ChamferDlg::enableWidgets()
555 int anId = getConstructorId();
557 bool toEnable = !myShape->_is_nil();
561 mySelName[ Face1 ]->setEnabled( toEnable );
562 mySelName[ Face2 ]->setEnabled( toEnable );
563 mySelBtn[ Face1 ]->setEnabled( toEnable );
564 mySelBtn[ Face2 ]->setEnabled( toEnable );
568 mySelName[ Face1 ]->setText( "" );
569 mySelName[ Face2 ]->setText( "" );
570 myFace[ Face1 ] = -1;
571 myFace[ Face2 ] = -1;
574 else if ( anId == 2 )
576 mySelName[ Faces ]->setEnabled( toEnable );
583 //=================================================================================
584 // function : createOperation
586 //=================================================================================
587 GEOM::GEOM_IOperations_ptr OperationGUI_ChamferDlg::createOperation()
589 return getGeomEngine()->GetILocalOperations( getStudyId() );
592 //=================================================================================
593 // function : ClickOnApply()
594 // purpose : Verify validity of input data
595 //=================================================================================
596 bool OperationGUI_ChamferDlg::isValid( QString& )
598 switch ( getConstructorId() )
600 case 0: return !myShape->_is_nil();
601 case 1: return !myShape->_is_nil() && myFace[ Face1 ] > 0 && myFace[ Face2 ] > 0;
602 case 2: return !myShape->_is_nil() && myFaces.Extent() > 0;
603 default: return false;
607 //=================================================================================
608 // function : execute
610 //=================================================================================
611 bool OperationGUI_ChamferDlg::execute( ObjectList& objects )
613 GEOM::GEOM_Object_var anObj;
615 int anId = getConstructorId();
617 anObj = GEOM::GEOM_ILocalOperations::_narrow(
618 getOperation() )->MakeChamferAll( myShape,
619 mySpinBox[ SpinBox1 ]->value() );
620 else if ( anId == 1 )
621 anObj = GEOM::GEOM_ILocalOperations::_narrow(
622 getOperation() )->MakeChamferEdge( myShape,
623 mySpinBox[ SpinBox21 ]->value(),
624 mySpinBox[ SpinBox22 ]->value(),
627 else if ( anId == 2 )
629 GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
630 anArray->length( myFaces.Extent() );
633 for ( int i = 1, n = myFaces.Extent(); i <= n; i++ )
634 anArray[ i - 1 ] = myFaces( i );
636 anObj = GEOM::GEOM_ILocalOperations::_narrow(
637 getOperation() )->MakeChamferFaces( myShape,
638 mySpinBox[ SpinBox31 ]->value(),
639 mySpinBox[ SpinBox32 ]->value(),
644 if ( !anObj->_is_nil() )
645 objects.push_back( anObj._retn() );