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"
39 #include <qbuttongroup.h>
40 #include <qcheckbox.h>
41 #include <qgroupbox.h>
43 #include <qlineedit.h>
44 #include <qpushbutton.h>
45 #include <qradiobutton.h>
49 #include <qwhatsthis.h>
53 //=================================================================================
54 // class : GeometryGUI_FillingHoleDlg()
55 // purpose : Constructs a GeometryGUI_FillingHoleDlg which is a child of 'parent', with the
56 // name 'name' and widget flags set to 'f'.
57 // The dialog will by default be modeless, unless you set 'modal' to
58 // TRUE to construct a modal dialog.
59 //=================================================================================
60 GeometryGUI_FillingHoleDlg::GeometryGUI_FillingHoleDlg( QWidget* parent,
62 SALOME_Selection* Sel,
63 Handle (AIS_InteractiveContext) ic,
66 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
69 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_SEWING")));
70 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
73 setName( "GeometryGUI_FillingHoleDlg" );
75 setCaption( tr( "Filling hole" ) );
76 setSizeGripEnabled( TRUE );
77 GeometryGUI_FillingHoleDlgLayout = new QGridLayout( this );
78 GeometryGUI_FillingHoleDlgLayout->setSpacing( 6 );
79 GeometryGUI_FillingHoleDlgLayout->setMargin( 11 );
81 /***************************************************************/
82 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
83 GroupConstructors->setTitle( tr( "" ) );
84 GroupConstructors->setExclusive( TRUE );
85 GroupConstructors->setColumnLayout(0, Qt::Vertical );
86 GroupConstructors->layout()->setSpacing( 0 );
87 GroupConstructors->layout()->setMargin( 0 );
88 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
89 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
90 GroupConstructorsLayout->setSpacing( 6 );
91 GroupConstructorsLayout->setMargin( 11 );
92 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
93 Constructor1->setText( tr( "" ) );
94 Constructor1->setPixmap( image0 );
95 Constructor1->setChecked( TRUE );
96 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
97 Constructor1->setMinimumSize( QSize( 50, 0 ) );
98 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
99 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
100 GroupConstructorsLayout->addItem( spacer, 0, 1 );
101 GeometryGUI_FillingHoleDlgLayout->addWidget( GroupConstructors, 0, 0 );
103 /***************************************************************/
104 GroupC1 = new QGroupBox( this, "GroupC1" );
105 GroupC1->setTitle( tr( "" ) );
106 GroupC1->setMinimumSize( QSize( 0, 0 ) );
107 GroupC1->setFrameShape( QGroupBox::Box );
108 GroupC1->setFrameShadow( QGroupBox::Sunken );
109 GroupC1->setColumnLayout(0, Qt::Vertical );
110 GroupC1->layout()->setSpacing( 0 );
111 GroupC1->layout()->setMargin( 0 );
112 GroupC1Layout = new QGridLayout( GroupC1->layout() );
113 GroupC1Layout->setAlignment( Qt::AlignTop );
114 GroupC1Layout->setSpacing( 6 );
115 GroupC1Layout->setMargin( 11 );
116 Layout2 = new QHBoxLayout;
117 Layout2->setSpacing( 6 );
118 Layout2->setMargin( 0 );
119 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
120 TextLabelC1A1->setText( tr( "Main object" ) );
121 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
122 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
123 TextLabelC1A1->setFrameShadow( QLabel::Plain );
124 Layout2->addWidget( TextLabelC1A1 );
125 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
126 SelectButtonC1A1->setText( tr( "" ) );
127 SelectButtonC1A1->setPixmap( image1 );
128 SelectButtonC1A1->setToggleButton( FALSE );
129 SelectButtonC1A1->setMaximumSize( QSize( 28, 32767 ) );
130 Layout2->addWidget( SelectButtonC1A1 );
131 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
132 LineEditC1A1->setAlignment( int( QLineEdit::AlignLeft ) );
133 Layout2->addWidget( LineEditC1A1 );
134 GroupC1Layout->addLayout( Layout2, 0, 0 );
135 CheckBox1 = new QCheckBox( GroupC1, "CheckBox1" );
136 CheckBox1->setText( tr( "Select edges of hole on main object" ) );
137 CheckBox1->setChecked( FALSE );
138 GroupC1Layout->addWidget( CheckBox1, 1, 0 );
139 GeometryGUI_FillingHoleDlgLayout->addWidget( GroupC1, 1, 0 );
141 /***************************************************************/
142 GroupButtons = new QGroupBox( this, "GroupButtons" );
143 GroupButtons->setTitle( tr( "" ) );
144 GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, GroupButtons->sizePolicy().hasHeightForWidth() ) );
145 GroupButtons->setColumnLayout(0, Qt::Vertical );
146 GroupButtons->layout()->setSpacing( 0 );
147 GroupButtons->layout()->setMargin( 0 );
148 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
149 GroupButtonsLayout->setAlignment( Qt::AlignTop );
150 GroupButtonsLayout->setSpacing( 6 );
151 GroupButtonsLayout->setMargin( 11 );
152 buttonClose = new QPushButton( GroupButtons, "buttonClose" );
153 buttonClose->setText( tr( "&Close" ) );
154 buttonClose->setAutoDefault( TRUE );
155 GroupButtonsLayout->addWidget( buttonClose, 0, 3 );
156 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
157 buttonOk->setText( tr( "&Ok" ) );
158 buttonOk->setAutoDefault( TRUE );
159 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
160 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
161 buttonApply->setText( tr( "&Apply" ) );
162 buttonApply->setAutoDefault( TRUE );
163 buttonApply->setDefault( TRUE );
164 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
165 QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
166 GroupButtonsLayout->addItem( spacer_2, 0, 2 );
167 GeometryGUI_FillingHoleDlgLayout->addWidget( GroupButtons, 2, 0 );
169 /* Initialisations */
175 //=================================================================================
176 // function : ~GeometryGUI_FillingHoleDlg()
177 // purpose : Destroys the object and frees any allocated resources
178 //=================================================================================
179 GeometryGUI_FillingHoleDlg::~GeometryGUI_FillingHoleDlg()
181 // no need to delete child widgets, Qt does it all for us
186 //=================================================================================
189 //=================================================================================
190 void GeometryGUI_FillingHoleDlg::Init( SALOME_Selection* Sel, Handle (AIS_InteractiveContext) ic )
194 myConstructorId = 0 ;
195 Constructor1->setChecked( TRUE );
196 myEditCurrentArgument = LineEditC1A1 ;
201 myUseLocalContext = false ;
203 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
205 /* Select sub shapes mode not checked */
206 CheckBox1->setChecked( FALSE );
207 myOkSelectSubMode = false ;
209 // TODO : previous selection into argument ?
211 /* Filter definitions */
212 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
213 myGeom = GEOM::GEOM_Gen::_narrow(comp);
215 /* signals and slots connections */
216 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
217 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
218 connect( buttonClose, SIGNAL( clicked() ), this, SLOT( ClickOnClose() ) );
219 connect( GroupConstructors, SIGNAL( clicked(int) ), this, SLOT( ConstructorsClicked(int) ));
221 connect( LineEditC1A1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
222 connect( SelectButtonC1A1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ));
223 connect( CheckBox1, SIGNAL( stateChanged(int) ), this, SLOT( ActivateUserSelection() ));
225 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ));
226 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
227 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnClose() ));
229 /* Move widget on the botton right corner of main widget */
231 myGeomGUI->DefineDlgPosition( this, x, y ) ;
233 this->show() ; /* display Dialog */
239 //=================================================================================
240 // function : ConstructorsClicked()
241 // purpose : Radio button management
242 //=================================================================================
243 void GeometryGUI_FillingHoleDlg::ConstructorsClicked(int constructorId)
249 //=================================================================================
250 // function : ClickOnOk()
251 // purpose : Same than click on apply but close this dialog.
252 //=================================================================================
253 void GeometryGUI_FillingHoleDlg::ClickOnOk()
255 this->ClickOnApply() ;
263 //=================================================================================
264 // function : ClickOnApply()
266 //=================================================================================
267 void GeometryGUI_FillingHoleDlg::ClickOnApply()
269 bool testResult = false ;
270 QAD_Application::getDesktop()->putInfo( tr("") ) ;
272 switch(myConstructorId)
276 if( myOkShape && myOkSelectSubMode ) {
277 testResult = myGeomGUI->OnFillingHole( myShape, myShapeIOR, myLocalContextId, myUseLocalContext ) ;
280 QAD_Application::getDesktop()->putInfo(tr("Operation aborted")) ;
283 QAD_Application::getDesktop()->putInfo(tr("Operation done"));
285 /* Reset arguments to allow a new selection */
286 this->ResetStateOfDialog() ;
295 //=================================================================================
296 // function : ClickOnClose()
298 //=================================================================================
299 void GeometryGUI_FillingHoleDlg::ClickOnClose()
301 disconnect( mySelection, 0, this, 0 );
302 myGeomGUI->ResetState() ;
304 if(myUseLocalContext) {
305 myIC->CloseLocalContext(myLocalContextId) ;
306 this->myUseLocalContext = false ;
307 myGeomGUI->OnDisplayAll(true) ;
314 //=================================================================================
315 // function : SelectionIntoArgument()
316 // purpose : Called when selection as changed or other case
317 // : used only by SelectButtonC1A1 (LineEditC1A1)
318 //=================================================================================
319 void GeometryGUI_FillingHoleDlg::SelectionIntoArgument()
322 /* Reset argument and local context when selection as changed */
323 this->ResetStateOfDialog() ;
325 QString aString = ""; /* name of selection */
327 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
333 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
335 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
338 // if( !IO->hasEntry() ) {
339 // QAD_Application::getDesktop()->putInfo(tr("Main shape must be in the study before")) ;
343 /* Test the exact type of topology to fill an hole */
344 if ( !S.IsNull() && ( S.ShapeType() == TopAbs_SOLID || S.ShapeType() == TopAbs_SHELL || S.ShapeType() == TopAbs_COMPOUND ) ) {
346 if ( IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
347 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IO );
348 myShapeIOR = GIObject->getIOR(); /* the Geom IOR string of selection */
349 LineEditC1A1->setText(aString) ;
355 if ( IO->hasEntry() ) {
356 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
357 SALOMEDS::SObject_var obj = aStudy->FindObjectID( IO->getEntry() );
358 SALOMEDS::GenericAttribute_var anAttr;
359 SALOMEDS::AttributeIOR_var anIOR;
360 if ( !obj->_is_nil() ) {
361 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
362 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
363 myShapeIOR = anIOR->Value();
366 LineEditC1A1->setText(aString) ;
377 //=================================================================================
378 // function : SetEditCurrentArgument()
380 //=================================================================================
381 void GeometryGUI_FillingHoleDlg::SetEditCurrentArgument()
383 QPushButton* send = (QPushButton*)sender();
384 switch (myConstructorId)
386 case 0: /* default constructor */
388 if(send == SelectButtonC1A1) {
389 LineEditC1A1->setFocus() ;
390 myEditCurrentArgument = LineEditC1A1;
391 SelectionIntoArgument() ;
400 //=================================================================================
401 // function : LineEditReturnPressed()
403 //=================================================================================
404 void GeometryGUI_FillingHoleDlg::LineEditReturnPressed()
406 QLineEdit* send = (QLineEdit*)sender();
407 if( send == LineEditC1A1 )
408 myEditCurrentArgument = LineEditC1A1 ;
412 /* User name of object input management */
413 /* If successfull the selection is changed and signal emitted... */
414 /* so SelectionIntoArgument() is automatically called. */
415 const QString objectUserName = myEditCurrentArgument->text() ;
416 QWidget* thisWidget = (QWidget*)this ;
417 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
418 myEditCurrentArgument->setText( objectUserName ) ;
424 //=================================================================================
425 // function : DeactivateActiveDialog()
427 //=================================================================================
428 void GeometryGUI_FillingHoleDlg::DeactivateActiveDialog()
430 if ( GroupConstructors->isEnabled() ) {
432 this->ResetStateOfDialog() ;
434 disconnect( mySelection, 0, this, 0 );
435 GroupConstructors->setEnabled(false) ;
436 GroupC1->setEnabled(false) ;
437 GroupButtons->setEnabled(false) ;
438 myGeomGUI->ResetState() ;
439 myGeomGUI->SetActiveDialogBox(0) ;
440 myGeomGUI->OnDisplayAll(true) ;
446 //=================================================================================
447 // function : ActivateThisDialog()
449 //=================================================================================
450 void GeometryGUI_FillingHoleDlg::ActivateThisDialog()
452 /* Emit a signal to deactivate other active dialog */
453 myGeomGUI->EmitSignalDeactivateDialog() ;
454 GroupConstructors->setEnabled(true) ;
455 GroupC1->setEnabled(true) ;
456 GroupButtons->setEnabled(true) ;
457 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
458 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
463 //=================================================================================
464 // function : enterEvent()
465 // purpose : Mouse enter onto the dialog to activate it
466 //=================================================================================
467 void GeometryGUI_FillingHoleDlg::enterEvent(QEvent* e)
469 if ( GroupConstructors->isEnabled() )
471 ActivateThisDialog() ;
476 //=================================================================================
477 // function : closeEvent()
479 //=================================================================================
480 void GeometryGUI_FillingHoleDlg::closeEvent( QCloseEvent* e )
482 /* same than click on cancel button */
483 this->ClickOnClose() ;
488 //=================================================================================
489 // function : ActivateUserSelection()
490 // purpose : Activate selection of faces when CheckBox1->isChecked()...
491 //=================================================================================
492 void GeometryGUI_FillingHoleDlg::ActivateUserSelection()
495 if( !this->myOkShape ) {
496 this->ResetStateOfDialog() ;
497 QAD_Application::getDesktop()->putInfo(tr("Select main shape first")) ;
501 this->myOkSelectSubMode = CheckBox1->isChecked() ;
503 if( this->myUseLocalContext ) {
504 myIC->CloseLocalContext(myLocalContextId) ;
505 this->myUseLocalContext = false ;
506 myGeomGUI->OnDisplayAll(true) ;
509 if( myOkShape && myOkSelectSubMode ) {
510 /* local context is defined into the method : GEOM::EDGE sub selection */
511 TopAbs_ShapeEnum aType = TopAbs_EDGE ;
512 myGeomGUI->PrepareSubShapeSelection( int(aType), this->myLocalContextId ) ;
513 myUseLocalContext = true ;
514 QAD_Application::getDesktop()->putInfo(tr("Select edges to fill an hole and click on Ok/Apply")) ;
521 //=================================================================================
522 // function : ResetStateOfDialog()
523 // purpose : Completely reset the state of method including local context
524 //=================================================================================
525 void GeometryGUI_FillingHoleDlg::ResetStateOfDialog()
527 this->myOkShape = false ;
528 this->myEditCurrentArgument->setText("") ;
530 /* Select sub shapes mode not checked */
531 this->myOkSelectSubMode = false ;
532 this->CheckBox1->setChecked( FALSE );
534 /* Close its local contact if opened */
535 if( this->myUseLocalContext ) {
536 myIC->CloseLocalContext(this->myLocalContextId) ;
537 this->myUseLocalContext = false ;
538 myGeomGUI->OnDisplayAll(true) ;