Salome HOME
NRI : Replace Geometry by GEOM.
[modules/geom.git] / src / GEOMGUI / GeometryGUI_SuppressHoleDlg.cxx
1 using namespace std;
2 //  File      : GeometryGUI_SuppressHoleDlg.cxx
3 //  Created   :
4 //  Author    : Lucien PIGNOLONI
5 //  Project   : SALOME
6 //  Module    : GeometryGUI
7 //  Copyright : OPEN CASCADE
8 //  $Header$
9
10 #include "GeometryGUI_SuppressHoleDlg.h"
11 #include "GeometryGUI.h"
12
13 #include "TopExp_Explorer.hxx"
14
15 #include "QAD_Application.h"
16 #include "QAD_Desktop.h"
17 #include "QAD_RightFrame.h"
18 #include "OCCViewer_Viewer3d.h"
19 #include "utilities.h"
20
21 #include <qapplication.h>
22 #include <qbuttongroup.h>
23 #include <qcheckbox.h>
24 #include <qgroupbox.h>
25 #include <qlabel.h>
26 #include <qlineedit.h>
27 #include <qpushbutton.h>
28 #include <qradiobutton.h>
29 #include <qlayout.h>
30 #include <qvariant.h>
31 #include <qtooltip.h>
32 #include <qwhatsthis.h>
33 #include <qimage.h>
34 #include <qpixmap.h>
35
36
37 //=================================================================================
38 // class    : GeometryGUI_SuppressHoleDlg()
39 // purpose  : Constructs a GeometryGUI_SuppressHoleDlg which is a child of 'parent', with the
40 //            name 'name' and widget flags set to 'f'.
41 //            The dialog will by default be modeless, unless you set 'modal' to
42 //            TRUE to construct a modal dialog.
43 //=================================================================================
44 GeometryGUI_SuppressHoleDlg::GeometryGUI_SuppressHoleDlg( QWidget* parent, 
45                                                           const char* name,
46                                                           SALOME_Selection* Sel,
47                                                           Handle (AIS_InteractiveContext) ic,                                     
48                                                           bool modal,
49                                                           WFlags fl )
50   : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
51 {
52   
53   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_SUPRESS_HOLE")));
54   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
55   QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_SUPRESS_HOLE_FACE_SHELL")));
56
57   if ( !name )
58     setName( "GeometryGUI_SuppressHoleDlg" );
59   resize( 303, 204 ); 
60   setCaption( tr( "GEOM_SUPPRESSHOLE_TITLE"  ) );
61   setSizeGripEnabled( TRUE );
62   GeometryGUI_SuppressHoleLayout = new QGridLayout( this ); 
63   GeometryGUI_SuppressHoleLayout->setSpacing( 6 );
64   GeometryGUI_SuppressHoleLayout->setMargin( 11 );
65   
66
67   /***************************************************************/
68   GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
69   GroupConstructors->setTitle( tr( ""  ) );
70   GroupConstructors->setExclusive( TRUE );
71   GroupConstructors->setColumnLayout(0, Qt::Vertical );
72   GroupConstructors->layout()->setSpacing( 0 );
73   GroupConstructors->layout()->setMargin( 0 );
74   GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
75   GroupConstructorsLayout->setAlignment( Qt::AlignTop );
76   GroupConstructorsLayout->setSpacing( 6 );
77   GroupConstructorsLayout->setMargin( 11 );
78   
79   Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
80   Constructor1->setText( tr( ""  ) );
81   Constructor1->setPixmap( image0 );
82   Constructor1->setChecked( TRUE );
83   Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
84   Constructor1->setMinimumSize( QSize( 50, 0 ) );
85   GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
86   QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
87   GroupConstructorsLayout->addItem( spacer, 0, 1 );
88
89   Constructor2 = new QRadioButton( GroupConstructors, "Constructor2" );
90   Constructor2->setText( tr( ""  ) );
91   Constructor2->setPixmap( image2 );
92   Constructor2->setChecked( TRUE );
93   Constructor2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor2->sizePolicy().hasHeightForWidth() ) );
94   Constructor2->setMinimumSize( QSize( 50, 0 ) );
95   GroupConstructorsLayout->addWidget( Constructor2, 0, 2 );  
96   QSpacerItem* spacer_4 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
97   GroupConstructorsLayout->addItem( spacer_4, 0, 3 );  
98   GeometryGUI_SuppressHoleLayout->addWidget( GroupConstructors, 0, 0 );
99   
100
101   /***************************************************************/
102   GroupButtons = new QGroupBox( this, "GroupButtons" );
103   GroupButtons->setTitle( tr( ""  ) );
104   GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, GroupButtons->sizePolicy().hasHeightForWidth() ) );
105   GroupButtons->setColumnLayout(0, Qt::Vertical );
106   GroupButtons->layout()->setSpacing( 0 );
107   GroupButtons->layout()->setMargin( 0 );
108   GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
109   GroupButtonsLayout->setAlignment( Qt::AlignTop );
110   GroupButtonsLayout->setSpacing( 6 );
111   GroupButtonsLayout->setMargin( 11 );
112   
113   buttonOk = new QPushButton( GroupButtons, "buttonOk" );
114   buttonOk->setText( tr( "GEOM_BUT_OK"  ) );
115   buttonOk->setAutoDefault( TRUE );
116   buttonOk->setDefault( TRUE );
117   buttonOk->setAccel( 276824143 );
118   GroupButtonsLayout->addWidget( buttonOk );
119   QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
120   GroupButtonsLayout->addItem( spacer_2 );  
121   buttonApply = new QPushButton( GroupButtons, "buttonApply" );
122   buttonApply->setText( tr( "GEOM_BUT_APPLY"  ) );
123   buttonApply->setAutoDefault( TRUE );
124   buttonApply->setDefault( TRUE );
125   GroupButtonsLayout->addWidget( buttonApply );  
126   buttonClose = new QPushButton( GroupButtons, "buttonClose" );
127   buttonClose->setText( tr( "GEOM_BUT_CLOSE"  ) );
128   buttonClose->setAutoDefault( TRUE );
129   GroupButtonsLayout->addWidget( buttonClose );  
130   GeometryGUI_SuppressHoleLayout->addWidget( GroupButtons, 2, 0 );
131   
132   /* First constructor */
133   GroupC1 = new QGroupBox( this, "GroupC1" );
134   GroupC1->setTitle( tr( ""  ) );
135   GroupC1->setMinimumSize( QSize( 0, 0 ) );
136   GroupC1->setFrameShape( QGroupBox::Box );
137   GroupC1->setFrameShadow( QGroupBox::Sunken );
138   GroupC1->setColumnLayout(0, Qt::Vertical );
139   GroupC1->layout()->setSpacing( 0 );
140   GroupC1->layout()->setMargin( 0 );
141   GroupC1Layout = new QGridLayout( GroupC1->layout() );
142   GroupC1Layout->setAlignment( Qt::AlignTop );
143   GroupC1Layout->setSpacing( 6 );
144   GroupC1Layout->setMargin( 11 );
145   
146   Layout2 = new QHBoxLayout; 
147   Layout2->setSpacing( 6 );
148   Layout2->setMargin( 0 );
149
150   TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
151   TextLabelC1A1->setText( tr( "GEOM_MAIN_OBJECT"  ) );
152   TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
153   TextLabelC1A1->setFrameShape( QLabel::NoFrame );
154   TextLabelC1A1->setFrameShadow( QLabel::Plain );
155   Layout2->addWidget( TextLabelC1A1 );
156   
157   SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
158   SelectButtonC1A1->setText( tr( ""  ) );
159   SelectButtonC1A1->setPixmap( image1 );
160   SelectButtonC1A1->setToggleButton( FALSE );
161   SelectButtonC1A1->setMaximumSize( QSize( 28, 32767 ) );
162   Layout2->addWidget( SelectButtonC1A1 );
163   
164   LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
165   LineEditC1A1->setAlignment( int( QLineEdit::AlignLeft ) );
166   Layout2->addWidget( LineEditC1A1 );
167   
168   GroupC1Layout->addLayout( Layout2, 0, 0 );
169   
170   CheckBox1 = new QCheckBox( GroupC1, "CheckBox1" );
171   CheckBox1->setText( tr( "GEOM_SUPPRESSHOLE_SELECTFACE" ) );
172   CheckBox1->setChecked( FALSE );
173   GroupC1Layout->addWidget( CheckBox1, 1, 0 );
174
175   CheckBox2 = new QCheckBox( GroupC1, "CheckBox2" );
176   CheckBox2->setText( tr( "GEOM_SUPPRESSHOLE_SELECTWIRE" ) );
177   CheckBox2->setChecked( FALSE );
178   GroupC1Layout->addWidget( CheckBox2, 2, 0 );
179   
180   CheckBox3 = new QCheckBox( GroupC1, "CheckBox3" );
181   CheckBox3->setText( tr( "GEOM_SUPPRESSHOLE_SELECTFACE_END" ) );
182   CheckBox3->setChecked( FALSE );
183   GroupC1Layout->addWidget( CheckBox3, 3, 0 );
184   GeometryGUI_SuppressHoleLayout->addWidget( GroupC1, 1, 0 );
185
186   /* Second constructor */
187   GroupC2 = new QGroupBox( this, "GroupC2" );
188   GroupC2->setTitle( tr( ""  ) );
189   GroupC2->setMinimumSize( QSize( 0, 0 ) );
190   GroupC2->setFrameShape( QGroupBox::Box );
191   GroupC2->setFrameShadow( QGroupBox::Sunken );
192   GroupC2->setColumnLayout(0, Qt::Vertical );
193   GroupC2->layout()->setSpacing( 0 );
194   GroupC2->layout()->setMargin( 0 );
195   GroupC2Layout = new QGridLayout( GroupC2->layout() );
196   GroupC2Layout->setAlignment( Qt::AlignTop );
197   GroupC2Layout->setSpacing( 6 );
198   GroupC2Layout->setMargin( 11 );
199   
200   Layout3 = new QHBoxLayout; 
201   Layout3->setSpacing( 6 );
202   Layout3->setMargin( 0 );
203   
204   TextLabelC2A1 = new QLabel( GroupC2, "TextLabelC2A1" );
205   TextLabelC2A1->setText( tr( "GEOM_SUPPRESSHOLE_FACE_SHELL"  ) );
206   TextLabelC2A1->setMinimumSize( QSize( 50, 0 ) );
207   TextLabelC2A1->setFrameShape( QLabel::NoFrame );
208   TextLabelC2A1->setFrameShadow( QLabel::Plain );
209   Layout3->addWidget( TextLabelC2A1 );
210   
211   SelectButtonC2A1 = new QPushButton( GroupC2, "SelectButtonC2A1" );
212   SelectButtonC2A1->setText( tr( ""  ) );
213   SelectButtonC2A1->setPixmap( image1 );
214   SelectButtonC2A1->setToggleButton( FALSE );
215   SelectButtonC2A1->setMaximumSize( QSize( 28, 32767 ) );
216   Layout3->addWidget( SelectButtonC2A1 );
217   
218   LineEditC2A1 = new QLineEdit( GroupC2, "LineEditC2A1" );
219   LineEditC2A1->setAlignment( int( QLineEdit::AlignLeft ) );
220   Layout3->addWidget( LineEditC2A1 );
221   
222   GroupC2Layout->addLayout( Layout3, 0, 0 );
223   QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
224   GroupC2Layout->addItem( spacer_3, 2, 0 );
225   
226   CheckBoxC2_1 = new QCheckBox( GroupC2, "CheckBoxC2_1" );
227   CheckBoxC2_1->setText( tr( "GEOM_SUPPRESSHOLE_SELECT_HOLES_ON_FACE"  ) );
228   CheckBoxC2_1->setChecked( FALSE );
229   
230   GroupC2Layout->addWidget( CheckBoxC2_1, 1, 0 );
231   GeometryGUI_SuppressHoleLayout->addWidget( GroupC2, 1, 0 );
232
233
234   /* Initialisations */
235   Init(Sel, ic) ;
236 }
237
238
239 //=================================================================================
240 // function : ~GeometryGUI_SuppressHoleDlg()
241 // purpose  : Destroys the object and frees any allocated resources
242 //=================================================================================
243 GeometryGUI_SuppressHoleDlg::~GeometryGUI_SuppressHoleDlg()
244 {
245     // no need to delete child widgets, Qt does it all for us
246 }
247
248
249
250 //=================================================================================
251 // function : Init()
252 // purpose  :
253 //=================================================================================
254 void GeometryGUI_SuppressHoleDlg::Init( SALOME_Selection* Sel, Handle (AIS_InteractiveContext) ic )
255 {
256   GroupC1->show();
257   GroupC2->hide();
258   
259   myConstructorId = 0 ;
260   Constructor1->setChecked( TRUE );
261   myEditCurrentArgument = LineEditC1A1 ;
262   mySelection = Sel;
263   myShape.Nullify() ;
264   
265   myIC = ic ;
266   myUseLocalContext = false ;
267   myOkShape         = false ;
268   myOkSelectFace    = false ;
269
270   myListOfIdFace    = new GEOM::GEOM_Shape::ListOfSubShapeID;
271   myListOfIdWire    = new GEOM::GEOM_Shape::ListOfSubShapeID;
272   myListOfIdEndFace = new GEOM::GEOM_Shape::ListOfSubShapeID;
273   
274   myListOfIdFace->length(0) ;
275   myListOfIdWire->length(0) ;
276   myListOfIdEndFace->length(0) ; 
277   
278   myGeomGUI = GeometryGUI::GetGeometryGUI() ;
279   
280   /* Select sub modes not checked */
281   CheckBox1->setChecked( FALSE );    /* sub mode GEOM::FACE     */
282   CheckBox2->setChecked( FALSE );    /* sub mode GEOM::WIRE     */
283   CheckBox3->setChecked( FALSE );    /* sub mode END GEOM::FACE */
284
285   CheckBoxC2_1->setChecked( FALSE ); /* sub mode GEOM::WIRE(S)  */
286
287   // TODO : previous selection into argument ?
288
289   /* Filter definitions */
290   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
291   myGeom = GEOM::GEOM_Gen::_narrow(comp);
292
293   /* signals and slots connections */
294   connect( buttonOk,          SIGNAL( clicked() ),    this, SLOT( ClickOnOk() ) );
295   connect( buttonApply,       SIGNAL( clicked() ),    this, SLOT( ClickOnApply() ) );
296   connect( buttonClose,       SIGNAL( clicked() ),    this, SLOT( ClickOnClose() ) );
297   connect( GroupConstructors, SIGNAL( clicked(int) ), this, SLOT( ConstructorsClicked(int) ));
298
299   connect( SelectButtonC1A1,  SIGNAL( clicked() ),         this, SLOT( SetEditCurrentArgument() ));
300   connect( SelectButtonC2A1,  SIGNAL( clicked() ),         this, SLOT( SetEditCurrentArgument() ));
301   
302   connect( CheckBox1,         SIGNAL( stateChanged(int) ), this, SLOT( ActivateUserFaceSelection() ));
303   connect( CheckBox2,         SIGNAL( stateChanged(int) ), this, SLOT( ActivateUserWireSelection() ));
304   connect( CheckBox3,         SIGNAL( stateChanged(int) ), this, SLOT( ActivateUserEndFaceSelection() ));
305
306   connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
307   connect( LineEditC2A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
308
309   /* for the second constructor */
310   connect( CheckBoxC2_1,      SIGNAL( stateChanged(int) ), this, SLOT( ActivateUserWiresOnFaceShellSelection() ));
311
312   connect( mySelection,       SIGNAL( currentSelectionChanged() ),      this, SLOT( SelectionIntoArgument() ));
313   connect( myGeomGUI,         SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;  
314   connect( myGeomGUI,         SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnClose() ));
315  
316   /* Move widget on the botton right corner of main widget */
317   int x, y ;
318   myGeomGUI->DefineDlgPosition( this, x, y ) ;
319   this->move( x, y ) ;
320   this->show() ; /* display Dialog */
321   return ;
322 }
323
324
325 //=================================================================================
326 // function : ConstructorsClicked()
327 // purpose  : Radio button management
328 //=================================================================================
329 void GeometryGUI_SuppressHoleDlg::ConstructorsClicked(int constructorId)
330 {
331   switch (constructorId)
332     {
333     case 0:
334       {
335         GroupC1->show();
336         GroupC2->hide();
337         myConstructorId = constructorId ;
338         myEditCurrentArgument = LineEditC1A1 ;  
339         LineEditC1A1->setText(tr("")) ;
340         myOkShape         = false ;
341         myOkSelectFace    = false ;
342         this->ResetPartial() ;
343         connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
344         break;
345       }
346     case 1:
347       {
348         GroupC1->hide();
349         GroupC2->show();
350         myConstructorId = constructorId ;
351         myEditCurrentArgument = LineEditC2A1 ;
352         LineEditC2A1->setText(tr("")) ;
353         myOkShape = false ;
354         this->ResetPartial() ;
355         connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
356         this->ResetPartial() ;
357         break;
358       }
359     }
360  return ;
361 }
362
363
364 //=================================================================================
365 // function : ClickOnOk()
366 // purpose  : Same than click on apply but close this dialog.
367 //=================================================================================
368 void GeometryGUI_SuppressHoleDlg::ClickOnOk()
369 {
370   this->ClickOnApply() ;
371   accept();
372
373   return ;
374 }
375
376
377
378 //=================================================================================
379 // function : ClickOnApply()
380 // purpose  :
381 //=================================================================================
382 void GeometryGUI_SuppressHoleDlg::ClickOnApply()
383 {
384   myGeomGUI->GetDesktop()->putInfo( tr("") ) ; 
385   bool testResult = false ;
386   
387   if( !myOkShape )
388     return ;
389   switch (myConstructorId)
390     {
391     case 0: /* default constructor */
392       {
393         if(  !myOkSelectFace )
394           return ;
395   
396         if( CheckBox2->isChecked() ) {
397           
398           if( !CheckBox3->isChecked() ) {
399             
400             /* Call method to get sub shape selection of GEOM::WIRE */
401             bool aTest = myGeomGUI->GetIndexSubShapeSelected(myFace, int(TopAbs_WIRE), myListOfIdWire, myLocalContextId, myUseLocalContext) ;
402             
403             myGeomGUI->OnDisplayAll(true) ; /* Display all objects so that next method using ic can memorize them */
404             if( !aTest || myListOfIdWire->length() != 1 ) {
405               CheckBox2->setChecked(FALSE) ;
406               myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_ABORT") ) ; 
407             }
408             else {
409               myListOfIdEndFace->length(0) ; /* no end face */  
410               QApplication::setOverrideCursor( Qt::waitCursor );
411               testResult = myGeomGUI->OnSuppressHole( myShapeIOR, myListOfIdFace, myListOfIdWire, myListOfIdEndFace ) ;
412               QApplication::restoreOverrideCursor();
413             }
414           }
415           else { /* CheckBox3->isChecked() */
416             
417             /* Call method to get sub shape selection of END GEOM::FACE */
418             bool aTest = myGeomGUI->GetIndexSubShapeSelected(myShape, int(TopAbs_FACE), myListOfIdEndFace, myLocalContextId, myUseLocalContext) ;
419             
420             myGeomGUI->OnDisplayAll(true) ; /* Display all objects so that next method using ic can memorize them */
421             if( !aTest || myListOfIdEndFace->length() != 1 ) {
422               CheckBox3->setChecked(FALSE) ;
423               myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_ABORT") ) ; 
424             }
425             else {      
426               QApplication::setOverrideCursor( Qt::waitCursor );
427               testResult = myGeomGUI->OnSuppressHole( myShapeIOR, myListOfIdFace, myListOfIdWire, myListOfIdEndFace ) ; 
428               QApplication::restoreOverrideCursor();
429             }     
430           }
431         }
432         break ;
433       }
434
435     case 1:  /* second constructor */
436       {
437         if( CheckBoxC2_1->isChecked() ) {
438           
439           /* Call method to get sub shape selection of one or more GEOM::WIRE(s) on a face or a shell */
440           bool aTest = myGeomGUI->GetIndexSubShapeSelected(myShape, int(TopAbs_WIRE), myListOfIdWire, myLocalContextId, myUseLocalContext) ;
441           
442           myGeomGUI->OnDisplayAll(true) ; /* Display all objects so that next method using ic can memorize them */
443           
444           if( !aTest || myListOfIdWire->length() < 1 ) {
445             CheckBoxC2_1->setChecked(FALSE) ;
446             myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_ABORT") ) ;
447           }
448           else {
449             QApplication::setOverrideCursor( Qt::waitCursor );
450             testResult = myGeomGUI->OnSuppressHolesInFaceOrShell( myShapeIOR, myListOfIdWire ) ;
451             QApplication::restoreOverrideCursor();
452           }
453         }
454         break ;
455       }
456     }
457   
458
459   if( !testResult )
460     myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_ABORT") ) ;
461   else
462     myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_DONE") ) ;
463   
464   /* Reset arguments to allow a new selection */
465   this->ResetStateOfDialog() ;
466   return ;
467 }
468
469
470
471 //=================================================================================
472 // function : ClickOnClose()
473 // purpose  :
474 //=================================================================================
475 void GeometryGUI_SuppressHoleDlg::ClickOnClose()
476 {
477   disconnect( mySelection, 0, this, 0 );
478   myGeomGUI->ResetState() ;
479
480   if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
481     OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
482     myIC = v3d->getAISContext(); //    myIC = myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getViewerOCC()->getAISContext();
483     if(myUseLocalContext) {
484       myIC->CloseLocalContext(myLocalContextId) ;
485       this->myUseLocalContext = false ;
486       myGeomGUI->OnDisplayAll(true) ;
487     }
488   }
489
490   reject() ;
491   return ;
492 }
493
494
495 //=================================================================================
496 // function : SelectionIntoArgument()
497 // purpose  : Called when selection as changed or other case
498 //          : used only by SelectButtonC1A1 and SelectButtonC2A1
499 //=================================================================================
500 void GeometryGUI_SuppressHoleDlg::SelectionIntoArgument()
501 {
502   
503   /* Reset argument and local context when selection as changed */
504   this->ResetStateOfDialog() ;
505   
506   QString aString = ""; /* Name of selection */
507   
508   int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
509   if ( nbSel != 1 )
510     return ;
511   
512   /* nbSel == 1 */
513   TopoDS_Shape S ;
514   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
515
516   if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
517     return ;
518   
519   if ( S.IsNull() || S.ShapeType() == TopAbs_VERTEX || S.ShapeType() == TopAbs_EDGE || S.ShapeType() == TopAbs_WIRE ) {
520     return ;
521   }
522   
523   /* Test the exact type of topology to suppress faces into.         */
524   /* For the second constructor a face or shell selection is needed  */
525   if (  myConstructorId == 0 || ( myConstructorId == 1 && ( S.ShapeType() == TopAbs_FACE || S.ShapeType() == TopAbs_SHELL ) ) ) {
526     
527     if ( IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
528       Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IO );
529
530       /* The Geom IOR string of selection */
531       myShapeIOR = GIObject->getIOR();
532       myEditCurrentArgument->setText(aString) ;
533       myShape = S ;
534       myOkShape = true ;
535       return;
536     } 
537     
538     if ( IO->hasEntry() ) {
539       SALOMEDS::Study_var aStudy = myGeomGUI->GetActiveStudy()->getStudyDocument();
540       SALOMEDS::SObject_var obj = aStudy->FindObjectID( IO->getEntry() );
541       SALOMEDS::GenericAttribute_var anAttr;
542       SALOMEDS::AttributeIOR_var     anIOR;
543       if ( !obj->_is_nil() ) {
544         if (obj->FindAttribute(anAttr, "AttributeIOR")) {
545           anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
546           myShapeIOR = anIOR->Value();
547           myOkShape = true ;
548           myShape = S ;
549           myEditCurrentArgument->setText(aString) ;
550           return;
551         }
552       }
553     }
554     
555   }
556   return ;
557 }
558
559
560 //=================================================================================
561 // function : SetEditCurrentArgument()
562 // purpose  :
563 //=================================================================================
564 void GeometryGUI_SuppressHoleDlg::SetEditCurrentArgument()
565 {
566   QPushButton* send = (QPushButton*)sender();
567   switch (myConstructorId)
568     {
569     case 0: /* default constructor */
570       {
571         if(send == SelectButtonC1A1) {
572           LineEditC1A1->setFocus() ;
573           myEditCurrentArgument = LineEditC1A1;   
574           SelectionIntoArgument() ;
575         }
576         break;
577       }
578    case 1:
579       {
580         if(send == SelectButtonC2A1) {
581           LineEditC2A1->setFocus() ;
582           myEditCurrentArgument = LineEditC2A1;   
583           SelectionIntoArgument() ;
584         }
585         break;
586       }
587     }
588   return ;
589 }
590
591
592 //=================================================================================
593 // function : LineEditReturnPressed()
594 // purpose  :
595 //=================================================================================
596 void GeometryGUI_SuppressHoleDlg::LineEditReturnPressed()
597 {
598   QLineEdit* send = (QLineEdit*)sender();
599   if( send == LineEditC1A1 )
600     myEditCurrentArgument = LineEditC1A1 ;
601   else if ( send == LineEditC2A1)
602     myEditCurrentArgument = LineEditC2A1; 
603   else
604     return ;
605   
606   /* User name of object input management                          */
607   /* If successfull the selection is changed and signal emitted... */
608   /* so SelectionIntoArgument() is automatically called.           */
609   const QString objectUserName = myEditCurrentArgument->text() ;
610   QWidget* thisWidget = (QWidget*)this ;
611   if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
612     myEditCurrentArgument->setText( objectUserName ) ;
613   }
614   
615   return ;
616 }
617
618
619 //=================================================================================
620 // function : DeactivateActiveDialog()
621 // purpose  :
622 //=================================================================================
623 void GeometryGUI_SuppressHoleDlg::DeactivateActiveDialog()
624 {
625   if ( GroupConstructors->isEnabled() ) {
626     
627     this->ResetStateOfDialog() ;
628     
629     disconnect( mySelection, 0, this, 0 );
630     GroupConstructors->setEnabled(false) ;    
631     GroupC1->setEnabled(false) ;
632     GroupC2->setEnabled(false) ;
633     GroupButtons->setEnabled(false) ;
634
635     myGeomGUI->ResetState() ;    
636     myGeomGUI->SetActiveDialogBox(0) ;
637     myGeomGUI->OnDisplayAll(true) ;
638   }
639   return ;
640 }
641
642
643 //=================================================================================
644 // function : ActivateThisDialog()
645 // purpose  :
646 //=================================================================================
647 void GeometryGUI_SuppressHoleDlg::ActivateThisDialog()
648 {
649   /* Emit a signal to deactivate other active dialog */
650   myGeomGUI->EmitSignalDeactivateDialog() ;
651
652   GroupConstructors->setEnabled(true) ;
653   GroupC1->setEnabled(true) ;
654   GroupC2->setEnabled(true) ;
655   GroupButtons->setEnabled(true) ;
656
657   connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
658   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
659   return ;
660 }
661
662
663 //=================================================================================
664 // function : enterEvent()
665 // purpose  : Mouse enter onto the dialog to activate it
666 //=================================================================================
667 void GeometryGUI_SuppressHoleDlg::enterEvent(QEvent* e)
668 {
669   if ( GroupConstructors->isEnabled() )
670     return ;  
671   ActivateThisDialog() ;
672   return ;
673 }
674
675
676 //=================================================================================
677 // function : closeEvent()
678 // purpose  :
679 //=================================================================================
680 void GeometryGUI_SuppressHoleDlg::closeEvent( QCloseEvent* e )
681 {
682   /* same than click on cancel button */
683   this->ClickOnClose() ;
684   return ;
685 }
686
687
688 //=================================================================================
689 // function : ActivateUserFaceSelection()
690 // purpose  : Called when CheckBox1 state has changed. (Face selection is ckecked)
691 //          : Be careful user must first select a face then a wire !
692 //=================================================================================
693 void GeometryGUI_SuppressHoleDlg::ActivateUserFaceSelection()
694 {
695   if( !this->myOkShape ) {
696     this->ResetStateOfDialog() ;
697     myGeomGUI->GetDesktop()->putInfo( tr("GEOM_MAIN_OBJECT") ) ;
698     return ;
699   }
700   
701   /* Test the viewer type VTK */
702   if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) {
703     myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_NOT_FOR_VTK_VIEWER") ) ;
704     this->ResetStateOfDialog() ;  
705     return;
706   }
707   
708   if( CheckBox1->isChecked() ) {
709     
710     /* local context is opened into the method : Prepare GEOM::FACE sub selection */
711     myGeomGUI->PrepareSubShapeSelection( int(TopAbs_FACE), this->myLocalContextId ) ;    
712     myUseLocalContext = true ;
713     myGeomGUI->GetDesktop()->putInfo( tr("GEOM_SUPPRESSHOLE_SELECTFACE") ) ;
714   } 
715   else {
716     this->ResetPartial() ;
717   }
718
719   return ;
720 }
721
722
723 //=================================================================================
724 // function : ActivateUserWireSelection()
725 // purpose  : Called when CheckBox2 state has changed. (Wire selection is ckecked)
726 //          : Be careful user must first select a face then a wire !
727 //=================================================================================
728 void GeometryGUI_SuppressHoleDlg::ActivateUserWireSelection()
729 {
730   
731   if( !this->myOkShape ) {
732     this->ResetStateOfDialog() ;
733     myGeomGUI->GetDesktop()->putInfo(tr("GEOM_MAIN_OBJECT") ) ;
734     return ;
735   } 
736   
737   /* Test the type of viewer VTK */
738   if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) {
739     myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_NOT_FOR_VTK_VIEWER") ) ;
740     this->ResetStateOfDialog() ;
741     return;
742   }
743
744   if( CheckBox1->isChecked() ) {
745     
746     /* Get sub shape selection GEOM::FACE : local context is closed */    
747     bool aTest = myGeomGUI->GetIndexSubShapeSelected(myShape, int(TopAbs_FACE), myListOfIdFace, myLocalContextId, myUseLocalContext) ;
748     
749     myGeomGUI->OnDisplayAll(true) ; /* Display all objects so that next method using ic can memorize them */
750     if( !aTest || myListOfIdFace->length() != 1 ) {
751       CheckBox1->setChecked(FALSE) ;
752       myOkSelectFace = false ;
753       myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_ABORT") ) ; 
754     }
755     else {
756       myOkSelectFace = true ;
757     }
758   }
759   else {
760     this->ResetPartial() ;
761     return ;
762   }
763   
764
765   if( CheckBox2->isChecked() ) {
766     
767     /* Get the face selection */
768     this->myFace = FaceFromList(myShape, myListOfIdFace) ;    
769     /* Local context is opened into the method : Prepare GEOM::WIRE sub selection into a face */
770     myGeomGUI->PrepareSubShapeSelectionArgumentShape( this->myFace, int(TopAbs_WIRE), this->myLocalContextId ) ;    
771     myUseLocalContext = true ;
772     myGeomGUI->GetDesktop()->putInfo( tr("GEOM_SUPPRESSHOLE_SELECTWIRE") ) ;
773   }
774   else {
775     this->ResetPartial() ;
776   }
777   
778   return ;
779 }
780
781
782
783 //=================================================================================
784 // function : ActivateUserlEndFaceSelection()
785 // purpose  : Called when CheckBox3 state has changed. ( Optional End Face selection )
786 //          : Be careful user must first select a face then a wire then this optional end face !
787 //=================================================================================
788 void GeometryGUI_SuppressHoleDlg::ActivateUserEndFaceSelection()
789 {
790   
791   if( !this->myOkShape ) {
792     this->ResetStateOfDialog() ;
793     myGeomGUI->GetDesktop()->putInfo(tr("GEOM_MAIN_OBJECT") ) ;
794     return ;
795   }
796   
797   /* Test the type of viewer VTK */
798   if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) {
799     myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_NOT_FOR_VTK_VIEWER") ) ;
800     this->ResetStateOfDialog() ;
801     return;
802   }
803  
804    
805   if( CheckBox2->isChecked() ) {
806     /* Call method to get sub shape selection for the GEOM::WIRE into myFace : local context is closed */
807     bool aTest = myGeomGUI->GetIndexSubShapeSelected(this->myFace, int(TopAbs_WIRE), myListOfIdWire, myLocalContextId, myUseLocalContext) ;
808     
809     myGeomGUI->OnDisplayAll(true) ; /* Display all objects so that next method using ic can memorize them */
810     
811     if( !aTest || myListOfIdWire->length() != 1 ) {
812       CheckBox2->setChecked(FALSE) ;
813       CheckBox3->setChecked(FALSE) ;
814       myGeomGUI->GetDesktop()->putInfo( tr("GEOM_PRP_ABORT") ) ;     
815       return ;
816     }
817   }
818   else {
819     this->ResetPartial() ;
820     return ;
821   }
822   
823   
824   if( CheckBox3->isChecked() ) {    
825     /* Local context is opened into the method : prepare GEOM::FACE(end) into myShape sub selection */
826     myGeomGUI->PrepareSubShapeSelectionArgumentShape( this->myShape, int(TopAbs_FACE), this->myLocalContextId ) ;    
827     myUseLocalContext = true ;
828     myGeomGUI->GetDesktop()->putInfo( tr("GEOM_SUPPRESSHOLE_SELECTFACE_END") ) ;
829   }
830   else {
831     this->ResetPartial() ;
832   }
833
834   return ;
835 }
836
837
838
839 //=================================================================================
840 // function : ActivateUserWiresOnFaceShellSelection()
841 // purpose  : Called when CheckBoxC2_1 state has changed.
842 //          : Only for second constructor !
843 //          : Prepare selection for wire(s) on main object that is a face or a shell
844 //=================================================================================
845 void GeometryGUI_SuppressHoleDlg::ActivateUserWiresOnFaceShellSelection()
846 {
847   
848   if( !this->myOkShape ) {
849     this->ResetStateOfDialog() ;
850     myGeomGUI->GetDesktop()->putInfo(tr("GEOM_MAIN_OBJECT") ) ;
851     return ;
852   }
853   
854   /* Test the type of viewer VTK */
855   if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) {
856     myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_NOT_FOR_VTK_VIEWER") ) ;
857     this->ResetStateOfDialog() ;
858     return;
859   }
860   
861   if( CheckBoxC2_1->isChecked() ) {    
862     /* Local context is opened to prepare GEOM::WIRE(S) selection into 'myShape' that is a (main) face */
863     myGeomGUI->PrepareSubShapeSelectionArgumentShape( this->myShape, int(TopAbs_WIRE), this->myLocalContextId ) ;    
864     myUseLocalContext = true ;
865     myGeomGUI->GetDesktop()->putInfo( tr("GEOM_SUPPRESSHOLE_SELECT_HOLES_ON_FACE") ) ;
866   }
867   else {
868     this->ResetPartial() ;
869   }
870   return ;
871 }
872
873
874
875 //=================================================================================
876 // function : FaceFromList()
877 // purpose  : Return the face (selected by user) that is a sub shape of 'aShape'
878 //          : and which unique index is in 'ListOfSub'.
879 //          : This allows opening a local context with this face loaded.
880 //          : See : myGeomGUI->PrepareSubShapeSelectionArgumentShape(...)
881 //=================================================================================
882 TopoDS_Shape GeometryGUI_SuppressHoleDlg::FaceFromList( const TopoDS_Shape& aShape,
883                                                         const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfSub )
884 {
885   TopoDS_Shape tds ;
886   tds.Nullify() ;
887   if( ListOfSub.length() != 1 || aShape.IsNull() )
888     return tds ;
889   
890   int i = ListOfSub[0] ;
891   TopExp_Explorer exp ;
892   int j = 1 ; 
893   for( exp.Init(aShape, TopAbs_FACE); exp.More(); exp.Next() ) {
894     if(j == i)
895       return exp.Current() ;    
896     j++ ;
897   }
898   return tds ;
899 }
900
901
902
903
904 //=================================================================================
905 // function : ResetStateOfDialog()
906 // purpose  : Completely reset the state of method including local context
907 //=================================================================================
908 void GeometryGUI_SuppressHoleDlg::ResetStateOfDialog()
909 {
910   this->myOkShape = false ;
911   this->myEditCurrentArgument->setText("") ;
912   
913   /* Partial reset and more ...*/
914   this->ResetPartial() ;
915
916   return ;
917 }
918
919
920 //=================================================================================
921 // function : ResetPartial()
922 // purpose  : Partially reset to keep only main selection
923 //=================================================================================
924 void GeometryGUI_SuppressHoleDlg::ResetPartial()
925 {
926   /* Select sub shape modes not checked */
927   this->myOkSelectFace = false ;
928   this->CheckBox1->setChecked( FALSE );
929   this->CheckBox2->setChecked( FALSE );
930   this->CheckBox3->setChecked( FALSE );
931   this->CheckBoxC2_1->setChecked( FALSE );
932   
933   myListOfIdFace->length(0) ;
934   myListOfIdWire->length(0) ;
935   myListOfIdEndFace->length(0) ;
936   
937   /* Close its local contact if opened */
938   if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
939     OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
940     myIC = v3d->getAISContext(); //    myIC = myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getViewerOCC()->getAISContext();
941     if( this->myUseLocalContext ) {
942       myIC->CloseLocalContext(this->myLocalContextId) ;
943       this->myUseLocalContext = false ;
944       myGeomGUI->OnDisplayAll(true) ;
945     }
946   }
947
948   return ;
949 }