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_SuppressHoleDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_SuppressHoleDlg.h"
31 #include "GeometryGUI.h"
33 #include "TopExp_Explorer.hxx"
35 #include "QAD_Application.h"
36 #include "QAD_Desktop.h"
37 #include "QAD_RightFrame.h"
38 #include "OCCViewer_Viewer3d.h"
39 #include "utilities.h"
41 #include <qapplication.h>
42 #include <qbuttongroup.h>
43 #include <qcheckbox.h>
44 #include <qgroupbox.h>
46 #include <qlineedit.h>
47 #include <qpushbutton.h>
48 #include <qradiobutton.h>
52 #include <qwhatsthis.h>
57 //=================================================================================
58 // class : GeometryGUI_SuppressHoleDlg()
59 // purpose : Constructs a GeometryGUI_SuppressHoleDlg which is a child of 'parent', with the
60 // name 'name' and widget flags set to 'f'.
61 // The dialog will by default be modeless, unless you set 'modal' to
62 // TRUE to construct a modal dialog.
63 //=================================================================================
64 GeometryGUI_SuppressHoleDlg::GeometryGUI_SuppressHoleDlg( QWidget* parent,
66 SALOME_Selection* Sel,
67 Handle (AIS_InteractiveContext) ic,
70 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
73 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_SUPRESS_HOLE")));
74 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
75 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_SUPRESS_HOLE_FACE_SHELL")));
78 setName( "GeometryGUI_SuppressHoleDlg" );
80 setCaption( tr( "GEOM_SUPPRESSHOLE_TITLE" ) );
81 setSizeGripEnabled( TRUE );
82 GeometryGUI_SuppressHoleLayout = new QGridLayout( this );
83 GeometryGUI_SuppressHoleLayout->setSpacing( 6 );
84 GeometryGUI_SuppressHoleLayout->setMargin( 11 );
87 /***************************************************************/
88 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
89 GroupConstructors->setTitle( tr( "" ) );
90 GroupConstructors->setExclusive( TRUE );
91 GroupConstructors->setColumnLayout(0, Qt::Vertical );
92 GroupConstructors->layout()->setSpacing( 0 );
93 GroupConstructors->layout()->setMargin( 0 );
94 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
95 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
96 GroupConstructorsLayout->setSpacing( 6 );
97 GroupConstructorsLayout->setMargin( 11 );
99 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
100 Constructor1->setText( tr( "" ) );
101 Constructor1->setPixmap( image0 );
102 Constructor1->setChecked( TRUE );
103 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
104 Constructor1->setMinimumSize( QSize( 50, 0 ) );
105 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
106 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
107 GroupConstructorsLayout->addItem( spacer, 0, 1 );
109 Constructor2 = new QRadioButton( GroupConstructors, "Constructor2" );
110 Constructor2->setText( tr( "" ) );
111 Constructor2->setPixmap( image2 );
112 Constructor2->setChecked( TRUE );
113 Constructor2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor2->sizePolicy().hasHeightForWidth() ) );
114 Constructor2->setMinimumSize( QSize( 50, 0 ) );
115 GroupConstructorsLayout->addWidget( Constructor2, 0, 2 );
116 QSpacerItem* spacer_4 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
117 GroupConstructorsLayout->addItem( spacer_4, 0, 3 );
118 GeometryGUI_SuppressHoleLayout->addWidget( GroupConstructors, 0, 0 );
121 /***************************************************************/
122 GroupButtons = new QGroupBox( this, "GroupButtons" );
123 GroupButtons->setTitle( tr( "" ) );
124 GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, GroupButtons->sizePolicy().hasHeightForWidth() ) );
125 GroupButtons->setColumnLayout(0, Qt::Vertical );
126 GroupButtons->layout()->setSpacing( 0 );
127 GroupButtons->layout()->setMargin( 0 );
128 GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
129 GroupButtonsLayout->setAlignment( Qt::AlignTop );
130 GroupButtonsLayout->setSpacing( 6 );
131 GroupButtonsLayout->setMargin( 11 );
133 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
134 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
135 buttonOk->setAutoDefault( TRUE );
136 buttonOk->setDefault( TRUE );
137 buttonOk->setAccel( 276824143 );
138 GroupButtonsLayout->addWidget( buttonOk );
139 QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
140 GroupButtonsLayout->addItem( spacer_2 );
141 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
142 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
143 buttonApply->setAutoDefault( TRUE );
144 buttonApply->setDefault( TRUE );
145 GroupButtonsLayout->addWidget( buttonApply );
146 buttonClose = new QPushButton( GroupButtons, "buttonClose" );
147 buttonClose->setText( tr( "GEOM_BUT_CLOSE" ) );
148 buttonClose->setAutoDefault( TRUE );
149 GroupButtonsLayout->addWidget( buttonClose );
150 GeometryGUI_SuppressHoleLayout->addWidget( GroupButtons, 2, 0 );
152 /* First constructor */
153 GroupC1 = new QGroupBox( this, "GroupC1" );
154 GroupC1->setTitle( tr( "" ) );
155 GroupC1->setMinimumSize( QSize( 0, 0 ) );
156 GroupC1->setFrameShape( QGroupBox::Box );
157 GroupC1->setFrameShadow( QGroupBox::Sunken );
158 GroupC1->setColumnLayout(0, Qt::Vertical );
159 GroupC1->layout()->setSpacing( 0 );
160 GroupC1->layout()->setMargin( 0 );
161 GroupC1Layout = new QGridLayout( GroupC1->layout() );
162 GroupC1Layout->setAlignment( Qt::AlignTop );
163 GroupC1Layout->setSpacing( 6 );
164 GroupC1Layout->setMargin( 11 );
166 Layout2 = new QHBoxLayout;
167 Layout2->setSpacing( 6 );
168 Layout2->setMargin( 0 );
170 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
171 TextLabelC1A1->setText( tr( "GEOM_MAIN_OBJECT" ) );
172 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
173 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
174 TextLabelC1A1->setFrameShadow( QLabel::Plain );
175 Layout2->addWidget( TextLabelC1A1 );
177 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
178 SelectButtonC1A1->setText( tr( "" ) );
179 SelectButtonC1A1->setPixmap( image1 );
180 SelectButtonC1A1->setToggleButton( FALSE );
181 SelectButtonC1A1->setMaximumSize( QSize( 28, 32767 ) );
182 Layout2->addWidget( SelectButtonC1A1 );
184 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
185 LineEditC1A1->setAlignment( int( QLineEdit::AlignLeft ) );
186 Layout2->addWidget( LineEditC1A1 );
188 GroupC1Layout->addLayout( Layout2, 0, 0 );
190 CheckBox1 = new QCheckBox( GroupC1, "CheckBox1" );
191 CheckBox1->setText( tr( "GEOM_SUPPRESSHOLE_SELECTFACE" ) );
192 CheckBox1->setChecked( FALSE );
193 GroupC1Layout->addWidget( CheckBox1, 1, 0 );
195 CheckBox2 = new QCheckBox( GroupC1, "CheckBox2" );
196 CheckBox2->setText( tr( "GEOM_SUPPRESSHOLE_SELECTWIRE" ) );
197 CheckBox2->setChecked( FALSE );
198 GroupC1Layout->addWidget( CheckBox2, 2, 0 );
200 CheckBox3 = new QCheckBox( GroupC1, "CheckBox3" );
201 CheckBox3->setText( tr( "GEOM_SUPPRESSHOLE_SELECTFACE_END" ) );
202 CheckBox3->setChecked( FALSE );
203 GroupC1Layout->addWidget( CheckBox3, 3, 0 );
204 GeometryGUI_SuppressHoleLayout->addWidget( GroupC1, 1, 0 );
206 /* Second constructor */
207 GroupC2 = new QGroupBox( this, "GroupC2" );
208 GroupC2->setTitle( tr( "" ) );
209 GroupC2->setMinimumSize( QSize( 0, 0 ) );
210 GroupC2->setFrameShape( QGroupBox::Box );
211 GroupC2->setFrameShadow( QGroupBox::Sunken );
212 GroupC2->setColumnLayout(0, Qt::Vertical );
213 GroupC2->layout()->setSpacing( 0 );
214 GroupC2->layout()->setMargin( 0 );
215 GroupC2Layout = new QGridLayout( GroupC2->layout() );
216 GroupC2Layout->setAlignment( Qt::AlignTop );
217 GroupC2Layout->setSpacing( 6 );
218 GroupC2Layout->setMargin( 11 );
220 Layout3 = new QHBoxLayout;
221 Layout3->setSpacing( 6 );
222 Layout3->setMargin( 0 );
224 TextLabelC2A1 = new QLabel( GroupC2, "TextLabelC2A1" );
225 TextLabelC2A1->setText( tr( "GEOM_SUPPRESSHOLE_FACE_SHELL" ) );
226 TextLabelC2A1->setMinimumSize( QSize( 50, 0 ) );
227 TextLabelC2A1->setFrameShape( QLabel::NoFrame );
228 TextLabelC2A1->setFrameShadow( QLabel::Plain );
229 Layout3->addWidget( TextLabelC2A1 );
231 SelectButtonC2A1 = new QPushButton( GroupC2, "SelectButtonC2A1" );
232 SelectButtonC2A1->setText( tr( "" ) );
233 SelectButtonC2A1->setPixmap( image1 );
234 SelectButtonC2A1->setToggleButton( FALSE );
235 SelectButtonC2A1->setMaximumSize( QSize( 28, 32767 ) );
236 Layout3->addWidget( SelectButtonC2A1 );
238 LineEditC2A1 = new QLineEdit( GroupC2, "LineEditC2A1" );
239 LineEditC2A1->setAlignment( int( QLineEdit::AlignLeft ) );
240 Layout3->addWidget( LineEditC2A1 );
242 GroupC2Layout->addLayout( Layout3, 0, 0 );
243 QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
244 GroupC2Layout->addItem( spacer_3, 2, 0 );
246 CheckBoxC2_1 = new QCheckBox( GroupC2, "CheckBoxC2_1" );
247 CheckBoxC2_1->setText( tr( "GEOM_SUPPRESSHOLE_SELECT_HOLES_ON_FACE" ) );
248 CheckBoxC2_1->setChecked( FALSE );
250 GroupC2Layout->addWidget( CheckBoxC2_1, 1, 0 );
251 GeometryGUI_SuppressHoleLayout->addWidget( GroupC2, 1, 0 );
254 /* Initialisations */
259 //=================================================================================
260 // function : ~GeometryGUI_SuppressHoleDlg()
261 // purpose : Destroys the object and frees any allocated resources
262 //=================================================================================
263 GeometryGUI_SuppressHoleDlg::~GeometryGUI_SuppressHoleDlg()
265 // no need to delete child widgets, Qt does it all for us
270 //=================================================================================
273 //=================================================================================
274 void GeometryGUI_SuppressHoleDlg::Init( SALOME_Selection* Sel, Handle (AIS_InteractiveContext) ic )
279 myConstructorId = 0 ;
280 Constructor1->setChecked( TRUE );
281 myEditCurrentArgument = LineEditC1A1 ;
286 myUseLocalContext = false ;
288 myOkSelectFace = false ;
290 myListOfIdFace = new GEOM::GEOM_Shape::ListOfSubShapeID;
291 myListOfIdWire = new GEOM::GEOM_Shape::ListOfSubShapeID;
292 myListOfIdEndFace = new GEOM::GEOM_Shape::ListOfSubShapeID;
294 myListOfIdFace->length(0) ;
295 myListOfIdWire->length(0) ;
296 myListOfIdEndFace->length(0) ;
298 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
300 /* Select sub modes not checked */
301 CheckBox1->setChecked( FALSE ); /* sub mode GEOM::FACE */
302 CheckBox2->setChecked( FALSE ); /* sub mode GEOM::WIRE */
303 CheckBox3->setChecked( FALSE ); /* sub mode END GEOM::FACE */
305 CheckBoxC2_1->setChecked( FALSE ); /* sub mode GEOM::WIRE(S) */
307 // TODO : previous selection into argument ?
309 /* Filter definitions */
310 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
311 myGeom = GEOM::GEOM_Gen::_narrow(comp);
313 /* signals and slots connections */
314 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
315 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
316 connect( buttonClose, SIGNAL( clicked() ), this, SLOT( ClickOnClose() ) );
317 connect( GroupConstructors, SIGNAL( clicked(int) ), this, SLOT( ConstructorsClicked(int) ));
319 connect( SelectButtonC1A1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ));
320 connect( SelectButtonC2A1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ));
322 connect( CheckBox1, SIGNAL( stateChanged(int) ), this, SLOT( ActivateUserFaceSelection() ));
323 connect( CheckBox2, SIGNAL( stateChanged(int) ), this, SLOT( ActivateUserWireSelection() ));
324 connect( CheckBox3, SIGNAL( stateChanged(int) ), this, SLOT( ActivateUserEndFaceSelection() ));
326 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
327 connect( LineEditC2A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
329 /* for the second constructor */
330 connect( CheckBoxC2_1, SIGNAL( stateChanged(int) ), this, SLOT( ActivateUserWiresOnFaceShellSelection() ));
332 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ));
333 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
334 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnClose() ));
336 /* Move widget on the botton right corner of main widget */
338 myGeomGUI->DefineDlgPosition( this, x, y ) ;
340 this->show() ; /* display Dialog */
345 //=================================================================================
346 // function : ConstructorsClicked()
347 // purpose : Radio button management
348 //=================================================================================
349 void GeometryGUI_SuppressHoleDlg::ConstructorsClicked(int constructorId)
351 switch (constructorId)
357 myConstructorId = constructorId ;
358 myEditCurrentArgument = LineEditC1A1 ;
359 LineEditC1A1->setText(tr("")) ;
361 myOkSelectFace = false ;
362 this->ResetPartial() ;
363 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
370 myConstructorId = constructorId ;
371 myEditCurrentArgument = LineEditC2A1 ;
372 LineEditC2A1->setText(tr("")) ;
374 this->ResetPartial() ;
375 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
376 this->ResetPartial() ;
384 //=================================================================================
385 // function : ClickOnOk()
386 // purpose : Same than click on apply but close this dialog.
387 //=================================================================================
388 void GeometryGUI_SuppressHoleDlg::ClickOnOk()
390 this->ClickOnApply() ;
398 //=================================================================================
399 // function : ClickOnApply()
401 //=================================================================================
402 void GeometryGUI_SuppressHoleDlg::ClickOnApply()
404 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
405 bool testResult = false ;
409 switch (myConstructorId)
411 case 0: /* default constructor */
413 if( !myOkSelectFace )
416 if( CheckBox2->isChecked() ) {
418 if( !CheckBox3->isChecked() ) {
420 /* Call method to get sub shape selection of GEOM::WIRE */
421 bool aTest = myGeomGUI->GetIndexSubShapeSelected(myFace, int(TopAbs_WIRE), myListOfIdWire, myLocalContextId, myUseLocalContext) ;
423 myGeomGUI->OnDisplayAll(true) ; /* Display all objects so that next method using ic can memorize them */
424 if( !aTest || myListOfIdWire->length() != 1 ) {
425 CheckBox2->setChecked(FALSE) ;
426 myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_ABORT") ) ;
429 myListOfIdEndFace->length(0) ; /* no end face */
430 QApplication::setOverrideCursor( Qt::waitCursor );
431 testResult = myGeomGUI->OnSuppressHole( myShapeIOR, myListOfIdFace, myListOfIdWire, myListOfIdEndFace ) ;
432 QApplication::restoreOverrideCursor();
435 else { /* CheckBox3->isChecked() */
437 /* Call method to get sub shape selection of END GEOM::FACE */
438 bool aTest = myGeomGUI->GetIndexSubShapeSelected(myShape, int(TopAbs_FACE), myListOfIdEndFace, myLocalContextId, myUseLocalContext) ;
440 myGeomGUI->OnDisplayAll(true) ; /* Display all objects so that next method using ic can memorize them */
441 if( !aTest || myListOfIdEndFace->length() != 1 ) {
442 CheckBox3->setChecked(FALSE) ;
443 myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_ABORT") ) ;
446 QApplication::setOverrideCursor( Qt::waitCursor );
447 testResult = myGeomGUI->OnSuppressHole( myShapeIOR, myListOfIdFace, myListOfIdWire, myListOfIdEndFace ) ;
448 QApplication::restoreOverrideCursor();
455 case 1: /* second constructor */
457 if( CheckBoxC2_1->isChecked() ) {
459 /* Call method to get sub shape selection of one or more GEOM::WIRE(s) on a face or a shell */
460 bool aTest = myGeomGUI->GetIndexSubShapeSelected(myShape, int(TopAbs_WIRE), myListOfIdWire, myLocalContextId, myUseLocalContext) ;
462 myGeomGUI->OnDisplayAll(true) ; /* Display all objects so that next method using ic can memorize them */
464 if( !aTest || myListOfIdWire->length() < 1 ) {
465 CheckBoxC2_1->setChecked(FALSE) ;
466 myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_ABORT") ) ;
469 QApplication::setOverrideCursor( Qt::waitCursor );
470 testResult = myGeomGUI->OnSuppressHolesInFaceOrShell( myShapeIOR, myListOfIdWire ) ;
471 QApplication::restoreOverrideCursor();
480 myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_ABORT") ) ;
482 myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_DONE") ) ;
484 /* Reset arguments to allow a new selection */
485 this->ResetStateOfDialog() ;
491 //=================================================================================
492 // function : ClickOnClose()
494 //=================================================================================
495 void GeometryGUI_SuppressHoleDlg::ClickOnClose()
497 disconnect( mySelection, 0, this, 0 );
498 myGeomGUI->ResetState() ;
500 if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
501 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
502 myIC = v3d->getAISContext(); // myIC = myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getViewerOCC()->getAISContext();
503 if(myUseLocalContext) {
504 myIC->CloseLocalContext(myLocalContextId) ;
505 this->myUseLocalContext = false ;
506 myGeomGUI->OnDisplayAll(true) ;
515 //=================================================================================
516 // function : SelectionIntoArgument()
517 // purpose : Called when selection as changed or other case
518 // : used only by SelectButtonC1A1 and SelectButtonC2A1
519 //=================================================================================
520 void GeometryGUI_SuppressHoleDlg::SelectionIntoArgument()
523 /* Reset argument and local context when selection as changed */
524 this->ResetStateOfDialog() ;
526 QString aString = ""; /* Name of selection */
528 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
534 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
536 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
539 if ( S.IsNull() || S.ShapeType() == TopAbs_VERTEX || S.ShapeType() == TopAbs_EDGE || S.ShapeType() == TopAbs_WIRE ) {
543 /* Test the exact type of topology to suppress faces into. */
544 /* For the second constructor a face or shell selection is needed */
545 if ( myConstructorId == 0 || ( myConstructorId == 1 && ( S.ShapeType() == TopAbs_FACE || S.ShapeType() == TopAbs_SHELL ) ) ) {
547 if ( IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
548 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IO );
550 /* The Geom IOR string of selection */
551 myShapeIOR = GIObject->getIOR();
552 myEditCurrentArgument->setText(aString) ;
558 if ( IO->hasEntry() ) {
559 SALOMEDS::Study_var aStudy = myGeomGUI->GetActiveStudy()->getStudyDocument();
560 SALOMEDS::SObject_var obj = aStudy->FindObjectID( IO->getEntry() );
561 SALOMEDS::GenericAttribute_var anAttr;
562 SALOMEDS::AttributeIOR_var anIOR;
563 if ( !obj->_is_nil() ) {
564 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
565 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
566 myShapeIOR = anIOR->Value();
569 myEditCurrentArgument->setText(aString) ;
580 //=================================================================================
581 // function : SetEditCurrentArgument()
583 //=================================================================================
584 void GeometryGUI_SuppressHoleDlg::SetEditCurrentArgument()
586 QPushButton* send = (QPushButton*)sender();
587 switch (myConstructorId)
589 case 0: /* default constructor */
591 if(send == SelectButtonC1A1) {
592 LineEditC1A1->setFocus() ;
593 myEditCurrentArgument = LineEditC1A1;
594 SelectionIntoArgument() ;
600 if(send == SelectButtonC2A1) {
601 LineEditC2A1->setFocus() ;
602 myEditCurrentArgument = LineEditC2A1;
603 SelectionIntoArgument() ;
612 //=================================================================================
613 // function : LineEditReturnPressed()
615 //=================================================================================
616 void GeometryGUI_SuppressHoleDlg::LineEditReturnPressed()
618 QLineEdit* send = (QLineEdit*)sender();
619 if( send == LineEditC1A1 )
620 myEditCurrentArgument = LineEditC1A1 ;
621 else if ( send == LineEditC2A1)
622 myEditCurrentArgument = LineEditC2A1;
626 /* User name of object input management */
627 /* If successfull the selection is changed and signal emitted... */
628 /* so SelectionIntoArgument() is automatically called. */
629 const QString objectUserName = myEditCurrentArgument->text() ;
630 QWidget* thisWidget = (QWidget*)this ;
631 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
632 myEditCurrentArgument->setText( objectUserName ) ;
639 //=================================================================================
640 // function : DeactivateActiveDialog()
642 //=================================================================================
643 void GeometryGUI_SuppressHoleDlg::DeactivateActiveDialog()
645 if ( GroupConstructors->isEnabled() ) {
647 this->ResetStateOfDialog() ;
649 disconnect( mySelection, 0, this, 0 );
650 GroupConstructors->setEnabled(false) ;
651 GroupC1->setEnabled(false) ;
652 GroupC2->setEnabled(false) ;
653 GroupButtons->setEnabled(false) ;
655 myGeomGUI->ResetState() ;
656 myGeomGUI->SetActiveDialogBox(0) ;
657 myGeomGUI->OnDisplayAll(true) ;
663 //=================================================================================
664 // function : ActivateThisDialog()
666 //=================================================================================
667 void GeometryGUI_SuppressHoleDlg::ActivateThisDialog()
669 /* Emit a signal to deactivate other active dialog */
670 myGeomGUI->EmitSignalDeactivateDialog() ;
672 GroupConstructors->setEnabled(true) ;
673 GroupC1->setEnabled(true) ;
674 GroupC2->setEnabled(true) ;
675 GroupButtons->setEnabled(true) ;
677 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
678 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
683 //=================================================================================
684 // function : enterEvent()
685 // purpose : Mouse enter onto the dialog to activate it
686 //=================================================================================
687 void GeometryGUI_SuppressHoleDlg::enterEvent(QEvent* e)
689 if ( GroupConstructors->isEnabled() )
691 ActivateThisDialog() ;
696 //=================================================================================
697 // function : closeEvent()
699 //=================================================================================
700 void GeometryGUI_SuppressHoleDlg::closeEvent( QCloseEvent* e )
702 /* same than click on cancel button */
703 this->ClickOnClose() ;
708 //=================================================================================
709 // function : ActivateUserFaceSelection()
710 // purpose : Called when CheckBox1 state has changed. (Face selection is ckecked)
711 // : Be careful user must first select a face then a wire !
712 //=================================================================================
713 void GeometryGUI_SuppressHoleDlg::ActivateUserFaceSelection()
715 if( !this->myOkShape ) {
716 this->ResetStateOfDialog() ;
717 myGeomGUI->GetDesktop()->putInfo( tr("GEOM_MAIN_OBJECT") ) ;
721 /* Test the viewer type VTK */
722 if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) {
723 myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_NOT_FOR_VTK_VIEWER") ) ;
724 this->ResetStateOfDialog() ;
728 if( CheckBox1->isChecked() ) {
730 /* local context is opened into the method : Prepare GEOM::FACE sub selection */
731 myGeomGUI->PrepareSubShapeSelection( int(TopAbs_FACE), this->myLocalContextId ) ;
732 myUseLocalContext = true ;
733 myGeomGUI->GetDesktop()->putInfo( tr("GEOM_SUPPRESSHOLE_SELECTFACE") ) ;
736 this->ResetPartial() ;
743 //=================================================================================
744 // function : ActivateUserWireSelection()
745 // purpose : Called when CheckBox2 state has changed. (Wire selection is ckecked)
746 // : Be careful user must first select a face then a wire !
747 //=================================================================================
748 void GeometryGUI_SuppressHoleDlg::ActivateUserWireSelection()
751 if( !this->myOkShape ) {
752 this->ResetStateOfDialog() ;
753 myGeomGUI->GetDesktop()->putInfo(tr("GEOM_MAIN_OBJECT") ) ;
757 /* Test the type of viewer VTK */
758 if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) {
759 myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_NOT_FOR_VTK_VIEWER") ) ;
760 this->ResetStateOfDialog() ;
764 if( CheckBox1->isChecked() ) {
766 /* Get sub shape selection GEOM::FACE : local context is closed */
767 bool aTest = myGeomGUI->GetIndexSubShapeSelected(myShape, int(TopAbs_FACE), myListOfIdFace, myLocalContextId, myUseLocalContext) ;
769 myGeomGUI->OnDisplayAll(true) ; /* Display all objects so that next method using ic can memorize them */
770 if( !aTest || myListOfIdFace->length() != 1 ) {
771 CheckBox1->setChecked(FALSE) ;
772 myOkSelectFace = false ;
773 myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_ABORT") ) ;
776 myOkSelectFace = true ;
780 this->ResetPartial() ;
785 if( CheckBox2->isChecked() ) {
787 /* Get the face selection */
788 this->myFace = FaceFromList(myShape, myListOfIdFace) ;
789 /* Local context is opened into the method : Prepare GEOM::WIRE sub selection into a face */
790 myGeomGUI->PrepareSubShapeSelectionArgumentShape( this->myFace, int(TopAbs_WIRE), this->myLocalContextId ) ;
791 myUseLocalContext = true ;
792 myGeomGUI->GetDesktop()->putInfo( tr("GEOM_SUPPRESSHOLE_SELECTWIRE") ) ;
795 this->ResetPartial() ;
803 //=================================================================================
804 // function : ActivateUserlEndFaceSelection()
805 // purpose : Called when CheckBox3 state has changed. ( Optional End Face selection )
806 // : Be careful user must first select a face then a wire then this optional end face !
807 //=================================================================================
808 void GeometryGUI_SuppressHoleDlg::ActivateUserEndFaceSelection()
811 if( !this->myOkShape ) {
812 this->ResetStateOfDialog() ;
813 myGeomGUI->GetDesktop()->putInfo(tr("GEOM_MAIN_OBJECT") ) ;
817 /* Test the type of viewer VTK */
818 if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) {
819 myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_NOT_FOR_VTK_VIEWER") ) ;
820 this->ResetStateOfDialog() ;
825 if( CheckBox2->isChecked() ) {
826 /* Call method to get sub shape selection for the GEOM::WIRE into myFace : local context is closed */
827 bool aTest = myGeomGUI->GetIndexSubShapeSelected(this->myFace, int(TopAbs_WIRE), myListOfIdWire, myLocalContextId, myUseLocalContext) ;
829 myGeomGUI->OnDisplayAll(true) ; /* Display all objects so that next method using ic can memorize them */
831 if( !aTest || myListOfIdWire->length() != 1 ) {
832 CheckBox2->setChecked(FALSE) ;
833 CheckBox3->setChecked(FALSE) ;
834 myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_ABORT") ) ;
839 this->ResetPartial() ;
844 if( CheckBox3->isChecked() ) {
845 /* Local context is opened into the method : prepare GEOM::FACE(end) into myShape sub selection */
846 myGeomGUI->PrepareSubShapeSelectionArgumentShape( this->myShape, int(TopAbs_FACE), this->myLocalContextId ) ;
847 myUseLocalContext = true ;
848 myGeomGUI->GetDesktop()->putInfo( tr("GEOM_SUPPRESSHOLE_SELECTFACE_END") ) ;
851 this->ResetPartial() ;
859 //=================================================================================
860 // function : ActivateUserWiresOnFaceShellSelection()
861 // purpose : Called when CheckBoxC2_1 state has changed.
862 // : Only for second constructor !
863 // : Prepare selection for wire(s) on main object that is a face or a shell
864 //=================================================================================
865 void GeometryGUI_SuppressHoleDlg::ActivateUserWiresOnFaceShellSelection()
868 if( !this->myOkShape ) {
869 this->ResetStateOfDialog() ;
870 myGeomGUI->GetDesktop()->putInfo(tr("GEOM_MAIN_OBJECT") ) ;
874 /* Test the type of viewer VTK */
875 if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) {
876 myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_NOT_FOR_VTK_VIEWER") ) ;
877 this->ResetStateOfDialog() ;
881 if( CheckBoxC2_1->isChecked() ) {
882 /* Local context is opened to prepare GEOM::WIRE(S) selection into 'myShape' that is a (main) face */
883 myGeomGUI->PrepareSubShapeSelectionArgumentShape( this->myShape, int(TopAbs_WIRE), this->myLocalContextId ) ;
884 myUseLocalContext = true ;
885 myGeomGUI->GetDesktop()->putInfo( tr("GEOM_SUPPRESSHOLE_SELECT_HOLES_ON_FACE") ) ;
888 this->ResetPartial() ;
895 //=================================================================================
896 // function : FaceFromList()
897 // purpose : Return the face (selected by user) that is a sub shape of 'aShape'
898 // : and which unique index is in 'ListOfSub'.
899 // : This allows opening a local context with this face loaded.
900 // : See : myGeomGUI->PrepareSubShapeSelectionArgumentShape(...)
901 //=================================================================================
902 TopoDS_Shape GeometryGUI_SuppressHoleDlg::FaceFromList( const TopoDS_Shape& aShape,
903 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfSub )
907 if( ListOfSub.length() != 1 || aShape.IsNull() )
910 int i = ListOfSub[0] ;
911 TopExp_Explorer exp ;
913 for( exp.Init(aShape, TopAbs_FACE); exp.More(); exp.Next() ) {
915 return exp.Current() ;
924 //=================================================================================
925 // function : ResetStateOfDialog()
926 // purpose : Completely reset the state of method including local context
927 //=================================================================================
928 void GeometryGUI_SuppressHoleDlg::ResetStateOfDialog()
930 this->myOkShape = false ;
931 this->myEditCurrentArgument->setText("") ;
933 /* Partial reset and more ...*/
934 this->ResetPartial() ;
940 //=================================================================================
941 // function : ResetPartial()
942 // purpose : Partially reset to keep only main selection
943 //=================================================================================
944 void GeometryGUI_SuppressHoleDlg::ResetPartial()
946 /* Select sub shape modes not checked */
947 this->myOkSelectFace = false ;
948 this->CheckBox1->setChecked( FALSE );
949 this->CheckBox2->setChecked( FALSE );
950 this->CheckBox3->setChecked( FALSE );
951 this->CheckBoxC2_1->setChecked( FALSE );
953 myListOfIdFace->length(0) ;
954 myListOfIdWire->length(0) ;
955 myListOfIdEndFace->length(0) ;
957 /* Close its local contact if opened */
958 if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
959 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
960 myIC = v3d->getAISContext(); // myIC = myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getViewerOCC()->getAISContext();
961 if( this->myUseLocalContext ) {
962 myIC->CloseLocalContext(this->myLocalContextId) ;
963 this->myUseLocalContext = false ;
964 myGeomGUI->OnDisplayAll(true) ;