2 // File : GeometryGUI_FillingHoleDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_FillingHoleDlg.h"
12 #include "GeometryGUI.h"
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "utilities.h"
17 #include <qbuttongroup.h>
18 #include <qcheckbox.h>
19 #include <qgroupbox.h>
21 #include <qlineedit.h>
22 #include <qpushbutton.h>
23 #include <qradiobutton.h>
27 #include <qwhatsthis.h>
31 //=================================================================================
32 // class : GeometryGUI_FillingHoleDlg()
33 // purpose : Constructs a GeometryGUI_FillingHoleDlg which is a child of 'parent', with the
34 // name 'name' and widget flags set to 'f'.
35 // The dialog will by default be modeless, unless you set 'modal' to
36 // TRUE to construct a modal dialog.
37 //=================================================================================
38 GeometryGUI_FillingHoleDlg::GeometryGUI_FillingHoleDlg( QWidget* parent,
40 SALOME_Selection* Sel,
41 Handle (AIS_InteractiveContext) ic,
44 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
47 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_SEWING")));
48 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
51 setName( "GeometryGUI_FillingHoleDlg" );
53 setCaption( tr( "Filling hole" ) );
54 setSizeGripEnabled( TRUE );
55 GeometryGUI_FillingHoleDlgLayout = new QGridLayout( this );
56 GeometryGUI_FillingHoleDlgLayout->setSpacing( 6 );
57 GeometryGUI_FillingHoleDlgLayout->setMargin( 11 );
59 /***************************************************************/
60 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
61 GroupConstructors->setTitle( tr( "" ) );
62 GroupConstructors->setExclusive( TRUE );
63 GroupConstructors->setColumnLayout(0, Qt::Vertical );
64 GroupConstructors->layout()->setSpacing( 0 );
65 GroupConstructors->layout()->setMargin( 0 );
66 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
67 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
68 GroupConstructorsLayout->setSpacing( 6 );
69 GroupConstructorsLayout->setMargin( 11 );
70 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
71 Constructor1->setText( tr( "" ) );
72 Constructor1->setPixmap( image0 );
73 Constructor1->setChecked( TRUE );
74 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
75 Constructor1->setMinimumSize( QSize( 50, 0 ) );
76 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
77 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
78 GroupConstructorsLayout->addItem( spacer, 0, 1 );
79 GeometryGUI_FillingHoleDlgLayout->addWidget( GroupConstructors, 0, 0 );
81 /***************************************************************/
82 GroupC1 = new QGroupBox( this, "GroupC1" );
83 GroupC1->setTitle( tr( "" ) );
84 GroupC1->setMinimumSize( QSize( 0, 0 ) );
85 GroupC1->setFrameShape( QGroupBox::Box );
86 GroupC1->setFrameShadow( QGroupBox::Sunken );
87 GroupC1->setColumnLayout(0, Qt::Vertical );
88 GroupC1->layout()->setSpacing( 0 );
89 GroupC1->layout()->setMargin( 0 );
90 GroupC1Layout = new QGridLayout( GroupC1->layout() );
91 GroupC1Layout->setAlignment( Qt::AlignTop );
92 GroupC1Layout->setSpacing( 6 );
93 GroupC1Layout->setMargin( 11 );
94 Layout2 = new QHBoxLayout;
95 Layout2->setSpacing( 6 );
96 Layout2->setMargin( 0 );
97 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
98 TextLabelC1A1->setText( tr( "Main object" ) );
99 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
100 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
101 TextLabelC1A1->setFrameShadow( QLabel::Plain );
102 Layout2->addWidget( TextLabelC1A1 );
103 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
104 SelectButtonC1A1->setText( tr( "" ) );
105 SelectButtonC1A1->setPixmap( image1 );
106 SelectButtonC1A1->setToggleButton( FALSE );
107 SelectButtonC1A1->setMaximumSize( QSize( 28, 32767 ) );
108 Layout2->addWidget( SelectButtonC1A1 );
109 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
110 LineEditC1A1->setAlignment( int( QLineEdit::AlignLeft ) );
111 Layout2->addWidget( LineEditC1A1 );
112 GroupC1Layout->addLayout( Layout2, 0, 0 );
113 CheckBox1 = new QCheckBox( GroupC1, "CheckBox1" );
114 CheckBox1->setText( tr( "Select edges of hole on main object" ) );
115 CheckBox1->setChecked( FALSE );
116 GroupC1Layout->addWidget( CheckBox1, 1, 0 );
117 GeometryGUI_FillingHoleDlgLayout->addWidget( GroupC1, 1, 0 );
119 /***************************************************************/
120 GroupButtons = new QGroupBox( this, "GroupButtons" );
121 GroupButtons->setTitle( tr( "" ) );
122 GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, GroupButtons->sizePolicy().hasHeightForWidth() ) );
123 GroupButtons->setColumnLayout(0, Qt::Vertical );
124 GroupButtons->layout()->setSpacing( 0 );
125 GroupButtons->layout()->setMargin( 0 );
126 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
127 GroupButtonsLayout->setAlignment( Qt::AlignTop );
128 GroupButtonsLayout->setSpacing( 6 );
129 GroupButtonsLayout->setMargin( 11 );
130 buttonClose = new QPushButton( GroupButtons, "buttonClose" );
131 buttonClose->setText( tr( "&Close" ) );
132 buttonClose->setAutoDefault( TRUE );
133 GroupButtonsLayout->addWidget( buttonClose, 0, 3 );
134 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
135 buttonOk->setText( tr( "&Ok" ) );
136 buttonOk->setAutoDefault( TRUE );
137 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
138 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
139 buttonApply->setText( tr( "&Apply" ) );
140 buttonApply->setAutoDefault( TRUE );
141 buttonApply->setDefault( TRUE );
142 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
143 QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
144 GroupButtonsLayout->addItem( spacer_2, 0, 2 );
145 GeometryGUI_FillingHoleDlgLayout->addWidget( GroupButtons, 2, 0 );
147 /* Initialisations */
153 //=================================================================================
154 // function : ~GeometryGUI_FillingHoleDlg()
155 // purpose : Destroys the object and frees any allocated resources
156 //=================================================================================
157 GeometryGUI_FillingHoleDlg::~GeometryGUI_FillingHoleDlg()
159 // no need to delete child widgets, Qt does it all for us
164 //=================================================================================
167 //=================================================================================
168 void GeometryGUI_FillingHoleDlg::Init( SALOME_Selection* Sel, Handle (AIS_InteractiveContext) ic )
172 myConstructorId = 0 ;
173 Constructor1->setChecked( TRUE );
174 myEditCurrentArgument = LineEditC1A1 ;
179 myUseLocalContext = false ;
181 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
183 /* Select sub shapes mode not checked */
184 CheckBox1->setChecked( FALSE );
185 myOkSelectSubMode = false ;
187 // TODO : previous selection into argument ?
189 /* Filter definitions */
190 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
191 myGeom = GEOM::GEOM_Gen::_narrow(comp);
193 /* signals and slots connections */
194 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
195 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
196 connect( buttonClose, SIGNAL( clicked() ), this, SLOT( ClickOnClose() ) );
197 connect( GroupConstructors, SIGNAL( clicked(int) ), this, SLOT( ConstructorsClicked(int) ));
199 connect( LineEditC1A1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
200 connect( SelectButtonC1A1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ));
201 connect( CheckBox1, SIGNAL( stateChanged(int) ), this, SLOT( ActivateUserSelection() ));
203 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ));
204 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
205 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnClose() ));
207 /* Move widget on the botton right corner of main widget */
209 myGeomGUI->DefineDlgPosition( this, x, y ) ;
211 this->show() ; /* display Dialog */
217 //=================================================================================
218 // function : ConstructorsClicked()
219 // purpose : Radio button management
220 //=================================================================================
221 void GeometryGUI_FillingHoleDlg::ConstructorsClicked(int constructorId)
227 //=================================================================================
228 // function : ClickOnOk()
229 // purpose : Same than click on apply but close this dialog.
230 //=================================================================================
231 void GeometryGUI_FillingHoleDlg::ClickOnOk()
233 this->ClickOnApply() ;
241 //=================================================================================
242 // function : ClickOnApply()
244 //=================================================================================
245 void GeometryGUI_FillingHoleDlg::ClickOnApply()
247 bool testResult = false ;
248 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
250 switch(myConstructorId)
254 if( myOkShape && myOkSelectSubMode ) {
255 testResult = myGeomGUI->OnFillingHole( myShape, myShapeIOR, myLocalContextId, myUseLocalContext ) ;
258 myGeomGUI->GetDesktop()->putInfo(tr("Operation aborted")) ;
261 myGeomGUI->GetDesktop()->putInfo(tr("Operation done"));
263 /* Reset arguments to allow a new selection */
264 this->ResetStateOfDialog() ;
273 //=================================================================================
274 // function : ClickOnClose()
276 //=================================================================================
277 void GeometryGUI_FillingHoleDlg::ClickOnClose()
279 disconnect( mySelection, 0, this, 0 );
280 myGeomGUI->ResetState() ;
282 if(myUseLocalContext) {
283 myIC->CloseLocalContext(myLocalContextId) ;
284 this->myUseLocalContext = false ;
285 myGeomGUI->OnDisplayAll(true) ;
292 //=================================================================================
293 // function : SelectionIntoArgument()
294 // purpose : Called when selection as changed or other case
295 // : used only by SelectButtonC1A1 (LineEditC1A1)
296 //=================================================================================
297 void GeometryGUI_FillingHoleDlg::SelectionIntoArgument()
300 /* Reset argument and local context when selection as changed */
301 this->ResetStateOfDialog() ;
303 QString aString = ""; /* name of selection */
305 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
311 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
313 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
316 // if( !IO->hasEntry() ) {
317 // myGeomGUI->GetDesktop()->putInfo(tr("Main shape must be in the study before")) ;
321 /* Test the exact type of topology to fill an hole */
322 if ( !S.IsNull() && ( S.ShapeType() == TopAbs_SOLID || S.ShapeType() == TopAbs_SHELL || S.ShapeType() == TopAbs_COMPOUND ) ) {
324 if ( IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
325 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IO );
326 myShapeIOR = GIObject->getIOR(); /* the Geom IOR string of selection */
327 LineEditC1A1->setText(aString) ;
333 if ( IO->hasEntry() ) {
334 SALOMEDS::Study_var aStudy = myGeomGUI->GetActiveStudy()->getStudyDocument();
335 SALOMEDS::SObject_var obj = aStudy->FindObjectID( IO->getEntry() );
336 SALOMEDS::GenericAttribute_var anAttr;
337 SALOMEDS::AttributeIOR_var anIOR;
338 if ( !obj->_is_nil() ) {
339 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
340 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
341 myShapeIOR = anIOR->Value();
344 LineEditC1A1->setText(aString) ;
355 //=================================================================================
356 // function : SetEditCurrentArgument()
358 //=================================================================================
359 void GeometryGUI_FillingHoleDlg::SetEditCurrentArgument()
361 QPushButton* send = (QPushButton*)sender();
362 switch (myConstructorId)
364 case 0: /* default constructor */
366 if(send == SelectButtonC1A1) {
367 LineEditC1A1->setFocus() ;
368 myEditCurrentArgument = LineEditC1A1;
369 SelectionIntoArgument() ;
378 //=================================================================================
379 // function : LineEditReturnPressed()
381 //=================================================================================
382 void GeometryGUI_FillingHoleDlg::LineEditReturnPressed()
384 QLineEdit* send = (QLineEdit*)sender();
385 if( send == LineEditC1A1 )
386 myEditCurrentArgument = LineEditC1A1 ;
390 /* User name of object input management */
391 /* If successfull the selection is changed and signal emitted... */
392 /* so SelectionIntoArgument() is automatically called. */
393 const QString objectUserName = myEditCurrentArgument->text() ;
394 QWidget* thisWidget = (QWidget*)this ;
395 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
396 myEditCurrentArgument->setText( objectUserName ) ;
402 //=================================================================================
403 // function : DeactivateActiveDialog()
405 //=================================================================================
406 void GeometryGUI_FillingHoleDlg::DeactivateActiveDialog()
408 if ( GroupConstructors->isEnabled() ) {
410 this->ResetStateOfDialog() ;
412 disconnect( mySelection, 0, this, 0 );
413 GroupConstructors->setEnabled(false) ;
414 GroupC1->setEnabled(false) ;
415 GroupButtons->setEnabled(false) ;
416 myGeomGUI->ResetState() ;
417 myGeomGUI->SetActiveDialogBox(0) ;
418 myGeomGUI->OnDisplayAll(true) ;
424 //=================================================================================
425 // function : ActivateThisDialog()
427 //=================================================================================
428 void GeometryGUI_FillingHoleDlg::ActivateThisDialog()
430 /* Emit a signal to deactivate other active dialog */
431 myGeomGUI->EmitSignalDeactivateDialog() ;
432 GroupConstructors->setEnabled(true) ;
433 GroupC1->setEnabled(true) ;
434 GroupButtons->setEnabled(true) ;
435 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
436 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
441 //=================================================================================
442 // function : enterEvent()
443 // purpose : Mouse enter onto the dialog to activate it
444 //=================================================================================
445 void GeometryGUI_FillingHoleDlg::enterEvent(QEvent* e)
447 if ( GroupConstructors->isEnabled() )
449 ActivateThisDialog() ;
454 //=================================================================================
455 // function : closeEvent()
457 //=================================================================================
458 void GeometryGUI_FillingHoleDlg::closeEvent( QCloseEvent* e )
460 /* same than click on cancel button */
461 this->ClickOnClose() ;
466 //=================================================================================
467 // function : ActivateUserSelection()
468 // purpose : Activate selection of faces when CheckBox1->isChecked()...
469 //=================================================================================
470 void GeometryGUI_FillingHoleDlg::ActivateUserSelection()
473 if( !this->myOkShape ) {
474 this->ResetStateOfDialog() ;
475 myGeomGUI->GetDesktop()->putInfo(tr("Select main shape first")) ;
479 this->myOkSelectSubMode = CheckBox1->isChecked() ;
481 if( this->myUseLocalContext ) {
482 myIC->CloseLocalContext(myLocalContextId) ;
483 this->myUseLocalContext = false ;
484 myGeomGUI->OnDisplayAll(true) ;
487 if( myOkShape && myOkSelectSubMode ) {
488 /* local context is defined into the method : GEOM::EDGE sub selection */
489 TopAbs_ShapeEnum aType = TopAbs_EDGE ;
490 myGeomGUI->PrepareSubShapeSelection( int(aType), this->myLocalContextId ) ;
491 myUseLocalContext = true ;
492 myGeomGUI->GetDesktop()->putInfo(tr("Select edges to fill an hole and click on Ok/Apply")) ;
499 //=================================================================================
500 // function : ResetStateOfDialog()
501 // purpose : Completely reset the state of method including local context
502 //=================================================================================
503 void GeometryGUI_FillingHoleDlg::ResetStateOfDialog()
505 this->myOkShape = false ;
506 this->myEditCurrentArgument->setText("") ;
508 /* Select sub shapes mode not checked */
509 this->myOkSelectSubMode = false ;
510 this->CheckBox1->setChecked( FALSE );
512 /* Close its local contact if opened */
513 if( this->myUseLocalContext ) {
514 myIC->CloseLocalContext(this->myLocalContextId) ;
515 this->myUseLocalContext = false ;
516 myGeomGUI->OnDisplayAll(true) ;