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 : GeometryGUI_FillingHoleDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_FillingHoleDlg.h"
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
37 #include <qbuttongroup.h>
38 #include <qcheckbox.h>
39 #include <qgroupbox.h>
41 #include <qlineedit.h>
42 #include <qpushbutton.h>
43 #include <qradiobutton.h>
47 #include <qwhatsthis.h>
51 //=================================================================================
52 // class : GeometryGUI_FillingHoleDlg()
53 // purpose : Constructs a GeometryGUI_FillingHoleDlg which is a child of 'parent', with the
54 // name 'name' and widget flags set to 'f'.
55 // The dialog will by default be modeless, unless you set 'modal' to
56 // TRUE to construct a modal dialog.
57 //=================================================================================
58 GeometryGUI_FillingHoleDlg::GeometryGUI_FillingHoleDlg( QWidget* parent,
60 SALOME_Selection* Sel,
61 Handle (AIS_InteractiveContext) ic,
64 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
67 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_SEWING")));
68 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
71 setName( "GeometryGUI_FillingHoleDlg" );
73 setCaption( tr( "Filling hole" ) );
74 setSizeGripEnabled( TRUE );
75 GeometryGUI_FillingHoleDlgLayout = new QGridLayout( this );
76 GeometryGUI_FillingHoleDlgLayout->setSpacing( 6 );
77 GeometryGUI_FillingHoleDlgLayout->setMargin( 11 );
79 /***************************************************************/
80 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
81 GroupConstructors->setTitle( tr( "" ) );
82 GroupConstructors->setExclusive( TRUE );
83 GroupConstructors->setColumnLayout(0, Qt::Vertical );
84 GroupConstructors->layout()->setSpacing( 0 );
85 GroupConstructors->layout()->setMargin( 0 );
86 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
87 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
88 GroupConstructorsLayout->setSpacing( 6 );
89 GroupConstructorsLayout->setMargin( 11 );
90 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
91 Constructor1->setText( tr( "" ) );
92 Constructor1->setPixmap( image0 );
93 Constructor1->setChecked( TRUE );
94 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
95 Constructor1->setMinimumSize( QSize( 50, 0 ) );
96 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
97 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
98 GroupConstructorsLayout->addItem( spacer, 0, 1 );
99 GeometryGUI_FillingHoleDlgLayout->addWidget( GroupConstructors, 0, 0 );
101 /***************************************************************/
102 GroupC1 = new QGroupBox( this, "GroupC1" );
103 GroupC1->setTitle( tr( "" ) );
104 GroupC1->setMinimumSize( QSize( 0, 0 ) );
105 GroupC1->setFrameShape( QGroupBox::Box );
106 GroupC1->setFrameShadow( QGroupBox::Sunken );
107 GroupC1->setColumnLayout(0, Qt::Vertical );
108 GroupC1->layout()->setSpacing( 0 );
109 GroupC1->layout()->setMargin( 0 );
110 GroupC1Layout = new QGridLayout( GroupC1->layout() );
111 GroupC1Layout->setAlignment( Qt::AlignTop );
112 GroupC1Layout->setSpacing( 6 );
113 GroupC1Layout->setMargin( 11 );
114 Layout2 = new QHBoxLayout;
115 Layout2->setSpacing( 6 );
116 Layout2->setMargin( 0 );
117 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
118 TextLabelC1A1->setText( tr( "Main object" ) );
119 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
120 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
121 TextLabelC1A1->setFrameShadow( QLabel::Plain );
122 Layout2->addWidget( TextLabelC1A1 );
123 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
124 SelectButtonC1A1->setText( tr( "" ) );
125 SelectButtonC1A1->setPixmap( image1 );
126 SelectButtonC1A1->setToggleButton( FALSE );
127 SelectButtonC1A1->setMaximumSize( QSize( 28, 32767 ) );
128 Layout2->addWidget( SelectButtonC1A1 );
129 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
130 LineEditC1A1->setAlignment( int( QLineEdit::AlignLeft ) );
131 Layout2->addWidget( LineEditC1A1 );
132 GroupC1Layout->addLayout( Layout2, 0, 0 );
133 CheckBox1 = new QCheckBox( GroupC1, "CheckBox1" );
134 CheckBox1->setText( tr( "Select edges of hole on main object" ) );
135 CheckBox1->setChecked( FALSE );
136 GroupC1Layout->addWidget( CheckBox1, 1, 0 );
137 GeometryGUI_FillingHoleDlgLayout->addWidget( GroupC1, 1, 0 );
139 /***************************************************************/
140 GroupButtons = new QGroupBox( this, "GroupButtons" );
141 GroupButtons->setTitle( tr( "" ) );
142 GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, GroupButtons->sizePolicy().hasHeightForWidth() ) );
143 GroupButtons->setColumnLayout(0, Qt::Vertical );
144 GroupButtons->layout()->setSpacing( 0 );
145 GroupButtons->layout()->setMargin( 0 );
146 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
147 GroupButtonsLayout->setAlignment( Qt::AlignTop );
148 GroupButtonsLayout->setSpacing( 6 );
149 GroupButtonsLayout->setMargin( 11 );
150 buttonClose = new QPushButton( GroupButtons, "buttonClose" );
151 buttonClose->setText( tr( "&Close" ) );
152 buttonClose->setAutoDefault( TRUE );
153 GroupButtonsLayout->addWidget( buttonClose, 0, 3 );
154 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
155 buttonOk->setText( tr( "&Ok" ) );
156 buttonOk->setAutoDefault( TRUE );
157 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
158 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
159 buttonApply->setText( tr( "&Apply" ) );
160 buttonApply->setAutoDefault( TRUE );
161 buttonApply->setDefault( TRUE );
162 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
163 QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
164 GroupButtonsLayout->addItem( spacer_2, 0, 2 );
165 GeometryGUI_FillingHoleDlgLayout->addWidget( GroupButtons, 2, 0 );
167 /* Initialisations */
173 //=================================================================================
174 // function : ~GeometryGUI_FillingHoleDlg()
175 // purpose : Destroys the object and frees any allocated resources
176 //=================================================================================
177 GeometryGUI_FillingHoleDlg::~GeometryGUI_FillingHoleDlg()
179 // no need to delete child widgets, Qt does it all for us
184 //=================================================================================
187 //=================================================================================
188 void GeometryGUI_FillingHoleDlg::Init( SALOME_Selection* Sel, Handle (AIS_InteractiveContext) ic )
192 myConstructorId = 0 ;
193 Constructor1->setChecked( TRUE );
194 myEditCurrentArgument = LineEditC1A1 ;
199 myUseLocalContext = false ;
201 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
203 /* Select sub shapes mode not checked */
204 CheckBox1->setChecked( FALSE );
205 myOkSelectSubMode = false ;
207 // TODO : previous selection into argument ?
209 /* Filter definitions */
210 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
211 myGeom = GEOM::GEOM_Gen::_narrow(comp);
213 /* signals and slots connections */
214 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
215 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
216 connect( buttonClose, SIGNAL( clicked() ), this, SLOT( ClickOnClose() ) );
217 connect( GroupConstructors, SIGNAL( clicked(int) ), this, SLOT( ConstructorsClicked(int) ));
219 connect( LineEditC1A1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
220 connect( SelectButtonC1A1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ));
221 connect( CheckBox1, SIGNAL( stateChanged(int) ), this, SLOT( ActivateUserSelection() ));
223 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ));
224 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
225 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnClose() ));
227 /* Move widget on the botton right corner of main widget */
229 myGeomGUI->DefineDlgPosition( this, x, y ) ;
231 this->show() ; /* display Dialog */
237 //=================================================================================
238 // function : ConstructorsClicked()
239 // purpose : Radio button management
240 //=================================================================================
241 void GeometryGUI_FillingHoleDlg::ConstructorsClicked(int constructorId)
247 //=================================================================================
248 // function : ClickOnOk()
249 // purpose : Same than click on apply but close this dialog.
250 //=================================================================================
251 void GeometryGUI_FillingHoleDlg::ClickOnOk()
253 this->ClickOnApply() ;
261 //=================================================================================
262 // function : ClickOnApply()
264 //=================================================================================
265 void GeometryGUI_FillingHoleDlg::ClickOnApply()
267 bool testResult = false ;
268 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
270 switch(myConstructorId)
274 if( myOkShape && myOkSelectSubMode ) {
275 testResult = myGeomGUI->OnFillingHole( myShape, myShapeIOR, myLocalContextId, myUseLocalContext ) ;
278 myGeomGUI->GetDesktop()->putInfo(tr("Operation aborted")) ;
281 myGeomGUI->GetDesktop()->putInfo(tr("Operation done"));
283 /* Reset arguments to allow a new selection */
284 this->ResetStateOfDialog() ;
293 //=================================================================================
294 // function : ClickOnClose()
296 //=================================================================================
297 void GeometryGUI_FillingHoleDlg::ClickOnClose()
299 disconnect( mySelection, 0, this, 0 );
300 myGeomGUI->ResetState() ;
302 if(myUseLocalContext) {
303 myIC->CloseLocalContext(myLocalContextId) ;
304 this->myUseLocalContext = false ;
305 myGeomGUI->OnDisplayAll(true) ;
312 //=================================================================================
313 // function : SelectionIntoArgument()
314 // purpose : Called when selection as changed or other case
315 // : used only by SelectButtonC1A1 (LineEditC1A1)
316 //=================================================================================
317 void GeometryGUI_FillingHoleDlg::SelectionIntoArgument()
320 /* Reset argument and local context when selection as changed */
321 this->ResetStateOfDialog() ;
323 QString aString = ""; /* name of selection */
325 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
331 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
333 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
336 // if( !IO->hasEntry() ) {
337 // myGeomGUI->GetDesktop()->putInfo(tr("Main shape must be in the study before")) ;
341 /* Test the exact type of topology to fill an hole */
342 if ( !S.IsNull() && ( S.ShapeType() == TopAbs_SOLID || S.ShapeType() == TopAbs_SHELL || S.ShapeType() == TopAbs_COMPOUND ) ) {
344 if ( IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
345 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IO );
346 myShapeIOR = GIObject->getIOR(); /* the Geom IOR string of selection */
347 LineEditC1A1->setText(aString) ;
353 if ( IO->hasEntry() ) {
354 SALOMEDS::Study_var aStudy = myGeomGUI->GetActiveStudy()->getStudyDocument();
355 SALOMEDS::SObject_var obj = aStudy->FindObjectID( IO->getEntry() );
356 SALOMEDS::GenericAttribute_var anAttr;
357 SALOMEDS::AttributeIOR_var anIOR;
358 if ( !obj->_is_nil() ) {
359 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
360 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
361 myShapeIOR = anIOR->Value();
364 LineEditC1A1->setText(aString) ;
375 //=================================================================================
376 // function : SetEditCurrentArgument()
378 //=================================================================================
379 void GeometryGUI_FillingHoleDlg::SetEditCurrentArgument()
381 QPushButton* send = (QPushButton*)sender();
382 switch (myConstructorId)
384 case 0: /* default constructor */
386 if(send == SelectButtonC1A1) {
387 LineEditC1A1->setFocus() ;
388 myEditCurrentArgument = LineEditC1A1;
389 SelectionIntoArgument() ;
398 //=================================================================================
399 // function : LineEditReturnPressed()
401 //=================================================================================
402 void GeometryGUI_FillingHoleDlg::LineEditReturnPressed()
404 QLineEdit* send = (QLineEdit*)sender();
405 if( send == LineEditC1A1 )
406 myEditCurrentArgument = LineEditC1A1 ;
410 /* User name of object input management */
411 /* If successfull the selection is changed and signal emitted... */
412 /* so SelectionIntoArgument() is automatically called. */
413 const QString objectUserName = myEditCurrentArgument->text() ;
414 QWidget* thisWidget = (QWidget*)this ;
415 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
416 myEditCurrentArgument->setText( objectUserName ) ;
422 //=================================================================================
423 // function : DeactivateActiveDialog()
425 //=================================================================================
426 void GeometryGUI_FillingHoleDlg::DeactivateActiveDialog()
428 if ( GroupConstructors->isEnabled() ) {
430 this->ResetStateOfDialog() ;
432 disconnect( mySelection, 0, this, 0 );
433 GroupConstructors->setEnabled(false) ;
434 GroupC1->setEnabled(false) ;
435 GroupButtons->setEnabled(false) ;
436 myGeomGUI->ResetState() ;
437 myGeomGUI->SetActiveDialogBox(0) ;
438 myGeomGUI->OnDisplayAll(true) ;
444 //=================================================================================
445 // function : ActivateThisDialog()
447 //=================================================================================
448 void GeometryGUI_FillingHoleDlg::ActivateThisDialog()
450 /* Emit a signal to deactivate other active dialog */
451 myGeomGUI->EmitSignalDeactivateDialog() ;
452 GroupConstructors->setEnabled(true) ;
453 GroupC1->setEnabled(true) ;
454 GroupButtons->setEnabled(true) ;
455 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
456 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
461 //=================================================================================
462 // function : enterEvent()
463 // purpose : Mouse enter onto the dialog to activate it
464 //=================================================================================
465 void GeometryGUI_FillingHoleDlg::enterEvent(QEvent* e)
467 if ( GroupConstructors->isEnabled() )
469 ActivateThisDialog() ;
474 //=================================================================================
475 // function : closeEvent()
477 //=================================================================================
478 void GeometryGUI_FillingHoleDlg::closeEvent( QCloseEvent* e )
480 /* same than click on cancel button */
481 this->ClickOnClose() ;
486 //=================================================================================
487 // function : ActivateUserSelection()
488 // purpose : Activate selection of faces when CheckBox1->isChecked()...
489 //=================================================================================
490 void GeometryGUI_FillingHoleDlg::ActivateUserSelection()
493 if( !this->myOkShape ) {
494 this->ResetStateOfDialog() ;
495 myGeomGUI->GetDesktop()->putInfo(tr("Select main shape first")) ;
499 this->myOkSelectSubMode = CheckBox1->isChecked() ;
501 if( this->myUseLocalContext ) {
502 myIC->CloseLocalContext(myLocalContextId) ;
503 this->myUseLocalContext = false ;
504 myGeomGUI->OnDisplayAll(true) ;
507 if( myOkShape && myOkSelectSubMode ) {
508 /* local context is defined into the method : GEOM::EDGE sub selection */
509 TopAbs_ShapeEnum aType = TopAbs_EDGE ;
510 myGeomGUI->PrepareSubShapeSelection( int(aType), this->myLocalContextId ) ;
511 myUseLocalContext = true ;
512 myGeomGUI->GetDesktop()->putInfo(tr("Select edges to fill an hole and click on Ok/Apply")) ;
519 //=================================================================================
520 // function : ResetStateOfDialog()
521 // purpose : Completely reset the state of method including local context
522 //=================================================================================
523 void GeometryGUI_FillingHoleDlg::ResetStateOfDialog()
525 this->myOkShape = false ;
526 this->myEditCurrentArgument->setText("") ;
528 /* Select sub shapes mode not checked */
529 this->myOkSelectSubMode = false ;
530 this->CheckBox1->setChecked( FALSE );
532 /* Close its local contact if opened */
533 if( this->myUseLocalContext ) {
534 myIC->CloseLocalContext(this->myLocalContextId) ;
535 this->myUseLocalContext = false ;
536 myGeomGUI->OnDisplayAll(true) ;