]> SALOME platform Git repositories - modules/geom.git/blob - GEOMGUI/GeometryGUI_SuppressHoleDlg.cxx
Salome HOME
sources v1.2c
[modules/geom.git] / GEOMGUI / GeometryGUI_SuppressHoleDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : GeometryGUI_SuppressHoleDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "GeometryGUI_SuppressHoleDlg.h"
31 #include "GeometryGUI.h"
32
33 #include "TopExp_Explorer.hxx"
34
35 #include "QAD_Application.h"
36 #include "QAD_Desktop.h"
37 #include "QAD_RightFrame.h"
38 #include "OCCViewer_Viewer3d.h"
39 #include "utilities.h"
40
41 #include <qapplication.h>
42 #include <qbuttongroup.h>
43 #include <qcheckbox.h>
44 #include <qgroupbox.h>
45 #include <qlabel.h>
46 #include <qlineedit.h>
47 #include <qpushbutton.h>
48 #include <qradiobutton.h>
49 #include <qlayout.h>
50 #include <qvariant.h>
51 #include <qtooltip.h>
52 #include <qwhatsthis.h>
53 #include <qimage.h>
54 #include <qpixmap.h>
55
56
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, 
65                                                           const char* name,
66                                                           SALOME_Selection* Sel,
67                                                           Handle (AIS_InteractiveContext) ic,                                     
68                                                           bool modal,
69                                                           WFlags fl )
70   : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
71 {
72   
73   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_SUPRESS_HOLE")));
74   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
75   QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_SUPRESS_HOLE_FACE_SHELL")));
76
77   if ( !name )
78     setName( "GeometryGUI_SuppressHoleDlg" );
79   resize( 303, 204 ); 
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 );
85   
86
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 );
98   
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 );
108
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 );
119   
120
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 );
132   
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 );
151   
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 );
165   
166   Layout2 = new QHBoxLayout; 
167   Layout2->setSpacing( 6 );
168   Layout2->setMargin( 0 );
169
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 );
176   
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 );
183   
184   LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
185   LineEditC1A1->setAlignment( int( QLineEdit::AlignLeft ) );
186   Layout2->addWidget( LineEditC1A1 );
187   
188   GroupC1Layout->addLayout( Layout2, 0, 0 );
189   
190   CheckBox1 = new QCheckBox( GroupC1, "CheckBox1" );
191   CheckBox1->setText( tr( "GEOM_SUPPRESSHOLE_SELECTFACE" ) );
192   CheckBox1->setChecked( FALSE );
193   GroupC1Layout->addWidget( CheckBox1, 1, 0 );
194
195   CheckBox2 = new QCheckBox( GroupC1, "CheckBox2" );
196   CheckBox2->setText( tr( "GEOM_SUPPRESSHOLE_SELECTWIRE" ) );
197   CheckBox2->setChecked( FALSE );
198   GroupC1Layout->addWidget( CheckBox2, 2, 0 );
199   
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 );
205
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 );
219   
220   Layout3 = new QHBoxLayout; 
221   Layout3->setSpacing( 6 );
222   Layout3->setMargin( 0 );
223   
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 );
230   
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 );
237   
238   LineEditC2A1 = new QLineEdit( GroupC2, "LineEditC2A1" );
239   LineEditC2A1->setAlignment( int( QLineEdit::AlignLeft ) );
240   Layout3->addWidget( LineEditC2A1 );
241   
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 );
245   
246   CheckBoxC2_1 = new QCheckBox( GroupC2, "CheckBoxC2_1" );
247   CheckBoxC2_1->setText( tr( "GEOM_SUPPRESSHOLE_SELECT_HOLES_ON_FACE"  ) );
248   CheckBoxC2_1->setChecked( FALSE );
249   
250   GroupC2Layout->addWidget( CheckBoxC2_1, 1, 0 );
251   GeometryGUI_SuppressHoleLayout->addWidget( GroupC2, 1, 0 );
252
253
254   /* Initialisations */
255   Init(Sel, ic) ;
256 }
257
258
259 //=================================================================================
260 // function : ~GeometryGUI_SuppressHoleDlg()
261 // purpose  : Destroys the object and frees any allocated resources
262 //=================================================================================
263 GeometryGUI_SuppressHoleDlg::~GeometryGUI_SuppressHoleDlg()
264 {
265     // no need to delete child widgets, Qt does it all for us
266 }
267
268
269
270 //=================================================================================
271 // function : Init()
272 // purpose  :
273 //=================================================================================
274 void GeometryGUI_SuppressHoleDlg::Init( SALOME_Selection* Sel, Handle (AIS_InteractiveContext) ic )
275 {
276   GroupC1->show();
277   GroupC2->hide();
278   
279   myConstructorId = 0 ;
280   Constructor1->setChecked( TRUE );
281   myEditCurrentArgument = LineEditC1A1 ;
282   mySelection = Sel;
283   myShape.Nullify() ;
284   
285   myIC = ic ;
286   myUseLocalContext = false ;
287   myOkShape         = false ;
288   myOkSelectFace    = false ;
289
290   myListOfIdFace    = new GEOM::GEOM_Shape::ListOfSubShapeID;
291   myListOfIdWire    = new GEOM::GEOM_Shape::ListOfSubShapeID;
292   myListOfIdEndFace = new GEOM::GEOM_Shape::ListOfSubShapeID;
293   
294   myListOfIdFace->length(0) ;
295   myListOfIdWire->length(0) ;
296   myListOfIdEndFace->length(0) ; 
297   
298   myGeomGUI = GeometryGUI::GetGeometryGUI() ;
299   
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 */
304
305   CheckBoxC2_1->setChecked( FALSE ); /* sub mode GEOM::WIRE(S)  */
306
307   // TODO : previous selection into argument ?
308
309   /* Filter definitions */
310   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
311   myGeom = GEOM::GEOM_Gen::_narrow(comp);
312
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) ));
318
319   connect( SelectButtonC1A1,  SIGNAL( clicked() ),         this, SLOT( SetEditCurrentArgument() ));
320   connect( SelectButtonC2A1,  SIGNAL( clicked() ),         this, SLOT( SetEditCurrentArgument() ));
321   
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() ));
325
326   connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
327   connect( LineEditC2A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
328
329   /* for the second constructor */
330   connect( CheckBoxC2_1,      SIGNAL( stateChanged(int) ), this, SLOT( ActivateUserWiresOnFaceShellSelection() ));
331
332   connect( mySelection,       SIGNAL( currentSelectionChanged() ),      this, SLOT( SelectionIntoArgument() ));
333   connect( myGeomGUI,         SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;  
334   connect( myGeomGUI,         SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnClose() ));
335  
336   /* Move widget on the botton right corner of main widget */
337   int x, y ;
338   myGeomGUI->DefineDlgPosition( this, x, y ) ;
339   this->move( x, y ) ;
340   this->show() ; /* display Dialog */
341   return ;
342 }
343
344
345 //=================================================================================
346 // function : ConstructorsClicked()
347 // purpose  : Radio button management
348 //=================================================================================
349 void GeometryGUI_SuppressHoleDlg::ConstructorsClicked(int constructorId)
350 {
351   switch (constructorId)
352     {
353     case 0:
354       {
355         GroupC1->show();
356         GroupC2->hide();
357         myConstructorId = constructorId ;
358         myEditCurrentArgument = LineEditC1A1 ;  
359         LineEditC1A1->setText(tr("")) ;
360         myOkShape         = false ;
361         myOkSelectFace    = false ;
362         this->ResetPartial() ;
363         connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
364         break;
365       }
366     case 1:
367       {
368         GroupC1->hide();
369         GroupC2->show();
370         myConstructorId = constructorId ;
371         myEditCurrentArgument = LineEditC2A1 ;
372         LineEditC2A1->setText(tr("")) ;
373         myOkShape = false ;
374         this->ResetPartial() ;
375         connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
376         this->ResetPartial() ;
377         break;
378       }
379     }
380  return ;
381 }
382
383
384 //=================================================================================
385 // function : ClickOnOk()
386 // purpose  : Same than click on apply but close this dialog.
387 //=================================================================================
388 void GeometryGUI_SuppressHoleDlg::ClickOnOk()
389 {
390   this->ClickOnApply() ;
391   accept();
392
393   return ;
394 }
395
396
397
398 //=================================================================================
399 // function : ClickOnApply()
400 // purpose  :
401 //=================================================================================
402 void GeometryGUI_SuppressHoleDlg::ClickOnApply()
403 {
404   myGeomGUI->GetDesktop()->putInfo( tr("") ) ; 
405   bool testResult = false ;
406   
407   if( !myOkShape )
408     return ;
409   switch (myConstructorId)
410     {
411     case 0: /* default constructor */
412       {
413         if(  !myOkSelectFace )
414           return ;
415   
416         if( CheckBox2->isChecked() ) {
417           
418           if( !CheckBox3->isChecked() ) {
419             
420             /* Call method to get sub shape selection of GEOM::WIRE */
421             bool aTest = myGeomGUI->GetIndexSubShapeSelected(myFace, int(TopAbs_WIRE), myListOfIdWire, myLocalContextId, myUseLocalContext) ;
422             
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") ) ; 
427             }
428             else {
429               myListOfIdEndFace->length(0) ; /* no end face */  
430               QApplication::setOverrideCursor( Qt::waitCursor );
431               testResult = myGeomGUI->OnSuppressHole( myShapeIOR, myListOfIdFace, myListOfIdWire, myListOfIdEndFace ) ;
432               QApplication::restoreOverrideCursor();
433             }
434           }
435           else { /* CheckBox3->isChecked() */
436             
437             /* Call method to get sub shape selection of END GEOM::FACE */
438             bool aTest = myGeomGUI->GetIndexSubShapeSelected(myShape, int(TopAbs_FACE), myListOfIdEndFace, myLocalContextId, myUseLocalContext) ;
439             
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") ) ; 
444             }
445             else {      
446               QApplication::setOverrideCursor( Qt::waitCursor );
447               testResult = myGeomGUI->OnSuppressHole( myShapeIOR, myListOfIdFace, myListOfIdWire, myListOfIdEndFace ) ; 
448               QApplication::restoreOverrideCursor();
449             }     
450           }
451         }
452         break ;
453       }
454
455     case 1:  /* second constructor */
456       {
457         if( CheckBoxC2_1->isChecked() ) {
458           
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) ;
461           
462           myGeomGUI->OnDisplayAll(true) ; /* Display all objects so that next method using ic can memorize them */
463           
464           if( !aTest || myListOfIdWire->length() < 1 ) {
465             CheckBoxC2_1->setChecked(FALSE) ;
466             myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_ABORT") ) ;
467           }
468           else {
469             QApplication::setOverrideCursor( Qt::waitCursor );
470             testResult = myGeomGUI->OnSuppressHolesInFaceOrShell( myShapeIOR, myListOfIdWire ) ;
471             QApplication::restoreOverrideCursor();
472           }
473         }
474         break ;
475       }
476     }
477   
478
479   if( !testResult )
480     myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_ABORT") ) ;
481   else
482     myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_DONE") ) ;
483   
484   /* Reset arguments to allow a new selection */
485   this->ResetStateOfDialog() ;
486   return ;
487 }
488
489
490
491 //=================================================================================
492 // function : ClickOnClose()
493 // purpose  :
494 //=================================================================================
495 void GeometryGUI_SuppressHoleDlg::ClickOnClose()
496 {
497   disconnect( mySelection, 0, this, 0 );
498   myGeomGUI->ResetState() ;
499
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) ;
507     }
508   }
509
510   reject() ;
511   return ;
512 }
513
514
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()
521 {
522   
523   /* Reset argument and local context when selection as changed */
524   this->ResetStateOfDialog() ;
525   
526   QString aString = ""; /* Name of selection */
527   
528   int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
529   if ( nbSel != 1 )
530     return ;
531   
532   /* nbSel == 1 */
533   TopoDS_Shape S ;
534   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
535
536   if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
537     return ;
538   
539   if ( S.IsNull() || S.ShapeType() == TopAbs_VERTEX || S.ShapeType() == TopAbs_EDGE || S.ShapeType() == TopAbs_WIRE ) {
540     return ;
541   }
542   
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 ) ) ) {
546     
547     if ( IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
548       Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IO );
549
550       /* The Geom IOR string of selection */
551       myShapeIOR = GIObject->getIOR();
552       myEditCurrentArgument->setText(aString) ;
553       myShape = S ;
554       myOkShape = true ;
555       return;
556     } 
557     
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();
567           myOkShape = true ;
568           myShape = S ;
569           myEditCurrentArgument->setText(aString) ;
570           return;
571         }
572       }
573     }
574     
575   }
576   return ;
577 }
578
579
580 //=================================================================================
581 // function : SetEditCurrentArgument()
582 // purpose  :
583 //=================================================================================
584 void GeometryGUI_SuppressHoleDlg::SetEditCurrentArgument()
585 {
586   QPushButton* send = (QPushButton*)sender();
587   switch (myConstructorId)
588     {
589     case 0: /* default constructor */
590       {
591         if(send == SelectButtonC1A1) {
592           LineEditC1A1->setFocus() ;
593           myEditCurrentArgument = LineEditC1A1;   
594           SelectionIntoArgument() ;
595         }
596         break;
597       }
598    case 1:
599       {
600         if(send == SelectButtonC2A1) {
601           LineEditC2A1->setFocus() ;
602           myEditCurrentArgument = LineEditC2A1;   
603           SelectionIntoArgument() ;
604         }
605         break;
606       }
607     }
608   return ;
609 }
610
611
612 //=================================================================================
613 // function : LineEditReturnPressed()
614 // purpose  :
615 //=================================================================================
616 void GeometryGUI_SuppressHoleDlg::LineEditReturnPressed()
617 {
618   QLineEdit* send = (QLineEdit*)sender();
619   if( send == LineEditC1A1 )
620     myEditCurrentArgument = LineEditC1A1 ;
621   else if ( send == LineEditC2A1)
622     myEditCurrentArgument = LineEditC2A1; 
623   else
624     return ;
625   
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 ) ;
633   }
634   
635   return ;
636 }
637
638
639 //=================================================================================
640 // function : DeactivateActiveDialog()
641 // purpose  :
642 //=================================================================================
643 void GeometryGUI_SuppressHoleDlg::DeactivateActiveDialog()
644 {
645   if ( GroupConstructors->isEnabled() ) {
646     
647     this->ResetStateOfDialog() ;
648     
649     disconnect( mySelection, 0, this, 0 );
650     GroupConstructors->setEnabled(false) ;    
651     GroupC1->setEnabled(false) ;
652     GroupC2->setEnabled(false) ;
653     GroupButtons->setEnabled(false) ;
654
655     myGeomGUI->ResetState() ;    
656     myGeomGUI->SetActiveDialogBox(0) ;
657     myGeomGUI->OnDisplayAll(true) ;
658   }
659   return ;
660 }
661
662
663 //=================================================================================
664 // function : ActivateThisDialog()
665 // purpose  :
666 //=================================================================================
667 void GeometryGUI_SuppressHoleDlg::ActivateThisDialog()
668 {
669   /* Emit a signal to deactivate other active dialog */
670   myGeomGUI->EmitSignalDeactivateDialog() ;
671
672   GroupConstructors->setEnabled(true) ;
673   GroupC1->setEnabled(true) ;
674   GroupC2->setEnabled(true) ;
675   GroupButtons->setEnabled(true) ;
676
677   connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
678   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
679   return ;
680 }
681
682
683 //=================================================================================
684 // function : enterEvent()
685 // purpose  : Mouse enter onto the dialog to activate it
686 //=================================================================================
687 void GeometryGUI_SuppressHoleDlg::enterEvent(QEvent* e)
688 {
689   if ( GroupConstructors->isEnabled() )
690     return ;  
691   ActivateThisDialog() ;
692   return ;
693 }
694
695
696 //=================================================================================
697 // function : closeEvent()
698 // purpose  :
699 //=================================================================================
700 void GeometryGUI_SuppressHoleDlg::closeEvent( QCloseEvent* e )
701 {
702   /* same than click on cancel button */
703   this->ClickOnClose() ;
704   return ;
705 }
706
707
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()
714 {
715   if( !this->myOkShape ) {
716     this->ResetStateOfDialog() ;
717     myGeomGUI->GetDesktop()->putInfo( tr("GEOM_MAIN_OBJECT") ) ;
718     return ;
719   }
720   
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() ;  
725     return;
726   }
727   
728   if( CheckBox1->isChecked() ) {
729     
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") ) ;
734   } 
735   else {
736     this->ResetPartial() ;
737   }
738
739   return ;
740 }
741
742
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()
749 {
750   
751   if( !this->myOkShape ) {
752     this->ResetStateOfDialog() ;
753     myGeomGUI->GetDesktop()->putInfo(tr("GEOM_MAIN_OBJECT") ) ;
754     return ;
755   } 
756   
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() ;
761     return;
762   }
763
764   if( CheckBox1->isChecked() ) {
765     
766     /* Get sub shape selection GEOM::FACE : local context is closed */    
767     bool aTest = myGeomGUI->GetIndexSubShapeSelected(myShape, int(TopAbs_FACE), myListOfIdFace, myLocalContextId, myUseLocalContext) ;
768     
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") ) ; 
774     }
775     else {
776       myOkSelectFace = true ;
777     }
778   }
779   else {
780     this->ResetPartial() ;
781     return ;
782   }
783   
784
785   if( CheckBox2->isChecked() ) {
786     
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") ) ;
793   }
794   else {
795     this->ResetPartial() ;
796   }
797   
798   return ;
799 }
800
801
802
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()
809 {
810   
811   if( !this->myOkShape ) {
812     this->ResetStateOfDialog() ;
813     myGeomGUI->GetDesktop()->putInfo(tr("GEOM_MAIN_OBJECT") ) ;
814     return ;
815   }
816   
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() ;
821     return;
822   }
823  
824    
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) ;
828     
829     myGeomGUI->OnDisplayAll(true) ; /* Display all objects so that next method using ic can memorize them */
830     
831     if( !aTest || myListOfIdWire->length() != 1 ) {
832       CheckBox2->setChecked(FALSE) ;
833       CheckBox3->setChecked(FALSE) ;
834       myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_ABORT") ) ;     
835       return ;
836     }
837   }
838   else {
839     this->ResetPartial() ;
840     return ;
841   }
842   
843   
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") ) ;
849   }
850   else {
851     this->ResetPartial() ;
852   }
853
854   return ;
855 }
856
857
858
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()
866 {
867   
868   if( !this->myOkShape ) {
869     this->ResetStateOfDialog() ;
870     myGeomGUI->GetDesktop()->putInfo(tr("GEOM_MAIN_OBJECT") ) ;
871     return ;
872   }
873   
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() ;
878     return;
879   }
880   
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") ) ;
886   }
887   else {
888     this->ResetPartial() ;
889   }
890   return ;
891 }
892
893
894
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 )
904 {
905   TopoDS_Shape tds ;
906   tds.Nullify() ;
907   if( ListOfSub.length() != 1 || aShape.IsNull() )
908     return tds ;
909   
910   int i = ListOfSub[0] ;
911   TopExp_Explorer exp ;
912   int j = 1 ; 
913   for( exp.Init(aShape, TopAbs_FACE); exp.More(); exp.Next() ) {
914     if(j == i)
915       return exp.Current() ;    
916     j++ ;
917   }
918   return tds ;
919 }
920
921
922
923
924 //=================================================================================
925 // function : ResetStateOfDialog()
926 // purpose  : Completely reset the state of method including local context
927 //=================================================================================
928 void GeometryGUI_SuppressHoleDlg::ResetStateOfDialog()
929 {
930   this->myOkShape = false ;
931   this->myEditCurrentArgument->setText("") ;
932   
933   /* Partial reset and more ...*/
934   this->ResetPartial() ;
935
936   return ;
937 }
938
939
940 //=================================================================================
941 // function : ResetPartial()
942 // purpose  : Partially reset to keep only main selection
943 //=================================================================================
944 void GeometryGUI_SuppressHoleDlg::ResetPartial()
945 {
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 );
952   
953   myListOfIdFace->length(0) ;
954   myListOfIdWire->length(0) ;
955   myListOfIdEndFace->length(0) ;
956   
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) ;
965     }
966   }
967
968   return ;
969 }