]> SALOME platform Git repositories - modules/geom.git/blob - src/RepairGUI/RepairGUI_SuppressHoleDlg.cxx
Salome HOME
DCQ: prepare V2.0.0
[modules/geom.git] / src / RepairGUI / RepairGUI_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   : RepairGUI_SuppressHoleDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "RepairGUI_SuppressHoleDlg.h"
31
32 #include "DisplayGUI.h"
33
34 #include "QAD_RightFrame.h"
35 #include "OCCViewer_Viewer3d.h"
36
37 #include <TopExp_Explorer.hxx>
38
39 //=================================================================================
40 // class    : RepairGUI_SuppressHoleDlg()
41 // purpose  : Constructs a RepairGUI_SuppressHoleDlg which is a child of 'parent', with the
42 //            name 'name' and widget flags set to 'f'.
43 //            The dialog will by default be modeless, unless you set 'modal' to
44 //            TRUE to construct a modal dialog.
45 //=================================================================================
46 RepairGUI_SuppressHoleDlg::RepairGUI_SuppressHoleDlg(QWidget* parent, const char* name, RepairGUI* theRepairGUI, SALOME_Selection* Sel, Handle(AIS_InteractiveContext) ic, bool modal, WFlags fl)
47   :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
48 {
49   
50   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SUPRESS_HOLE")));
51   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SUPRESS_HOLE_FACE_SHELL")));
52   QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
53
54   setCaption(tr("GEOM_SUPPRESSHOLE_TITLE"));
55
56   /***************************************************************/
57   GroupConstructors->setTitle(tr(""));
58   RadioButton1->setPixmap(image0);
59   RadioButton2->setPixmap(image1);
60   RadioButton3->close(TRUE);
61
62   Group1 = new DlgRef_1Sel3Check_QTD(this, "Group1");
63   Group1->GroupBox1->setTitle(tr(""));
64   Group1->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
65   Group1->CheckButton1->setText(tr("GEOM_SUPPRESSHOLE_SELECTFACE"));
66   Group1->CheckButton2->setText(tr("GEOM_SUPPRESSHOLE_SELECTWIRE"));
67   Group1->CheckButton3->setText(tr("GEOM_SUPPRESSHOLE_SELECTFACE_END"));
68   Group1->PushButton1->setPixmap(image2);
69
70   Group2 = new DlgRef_1Sel1Check_QTD(this, "Group2");
71   Group2->GroupBox1->setTitle(tr(""));
72   Group2->TextLabel1->setText(tr("GEOM_SUPPRESSHOLE_FACE_SHELL"));
73   Group2->CheckButton1->setText(tr("GEOM_SUPPRESSHOLE_SELECT_HOLES_ON_FACE"));
74   Group2->PushButton1->setPixmap(image2);
75
76   Layout1->addWidget(Group1, 1, 0);
77   Layout1->addWidget(Group2, 1, 0);
78   /***************************************************************/
79
80   /* Initialisations */
81   myRepairGUI = theRepairGUI;
82   Init(ic);
83 }
84
85
86 //=================================================================================
87 // function : ~RepairGUI_SuppressHoleDlg()
88 // purpose  : Destroys the object and frees any allocated resources
89 //=================================================================================
90 RepairGUI_SuppressHoleDlg::~RepairGUI_SuppressHoleDlg()
91 {
92   // no need to delete child widgets, Qt does it all for us
93 }
94
95
96 //=================================================================================
97 // function : Init()
98 // purpose  :
99 //=================================================================================
100 void RepairGUI_SuppressHoleDlg::Init(Handle (AIS_InteractiveContext) ic)
101 {
102   /* init variables */
103   myConstructorId = 0;
104   myEditCurrentArgument = Group1->LineEdit1;
105
106   myIC = ic;
107   myUseLocalContext = myOkShape = myOkSelectFace = false;
108   myLocalContextId = -1;
109
110   myListOfIdFace = new GEOM::GEOM_Shape::ListOfSubShapeID;
111   myListOfIdWire = new GEOM::GEOM_Shape::ListOfSubShapeID;
112   myListOfIdEndFace = new GEOM::GEOM_Shape::ListOfSubShapeID;
113   
114   myListOfIdFace->length(0);
115   myListOfIdWire->length(0);
116   myListOfIdEndFace->length(0); 
117
118   /* signals and slots connections */
119   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
120   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
121   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
122
123   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
124   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
125   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
126
127   connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128   connect(Group2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129   connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
130   connect(Group2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
131
132   connect(Group1->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ActivateUserFaceSelection()));
133   connect(Group1->CheckButton2, SIGNAL(stateChanged(int)), this, SLOT(ActivateUserWireSelection()));
134   connect(Group1->CheckButton3, SIGNAL(stateChanged(int)), this, SLOT(ActivateUserEndFaceSelection()));
135   connect(Group2->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ActivateUserWiresOnFaceShellSelection()));
136   
137   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
138
139   /* displays Dialog */
140   Group2->hide();
141   Group1->show();
142   this->show();
143
144   return;
145 }
146
147
148 //=================================================================================
149 // function : ConstructorsClicked()
150 // purpose  : Radio button management
151 //=================================================================================
152 void RepairGUI_SuppressHoleDlg::ConstructorsClicked(int constructorId)
153 {
154   myConstructorId = constructorId;
155   disconnect(mySelection, 0, this, 0);
156   myOkShape = false;
157
158   if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC && myUseLocalContext) {
159     myIC->CloseLocalContext(myLocalContextId);
160     DisplayGUI* myDisplayGUI = new DisplayGUI();
161     myDisplayGUI->OnDisplayAll(true);
162     myUseLocalContext = false;
163   }
164
165   switch (constructorId)
166     {
167     case 0:
168       {
169         Group2->hide();
170         resize(0, 0);
171         Group1->show();
172
173         myEditCurrentArgument = Group1->LineEdit1;
174         Group1->LineEdit1->setText("");
175         connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
176
177         myOkSelectFace = false;
178         this->ResetPartial();
179         break;
180       }
181     case 1:
182       {
183         Group1->hide();
184         resize(0, 0);
185         Group2->show();
186
187         myEditCurrentArgument = Group2->LineEdit1;
188         Group2->LineEdit1->setText("");
189
190         this->ResetPartial();
191         connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
192         this->ResetPartial();
193         break;
194       }
195     }
196  return;
197 }
198
199
200 //=================================================================================
201 // function : ClickOnOk()
202 // purpose  : Same than click on apply but close this dialog.
203 //=================================================================================
204 void RepairGUI_SuppressHoleDlg::ClickOnOk()
205 {
206   this->ClickOnApply();
207   this->ClickOnCancel();
208   return;
209 }
210
211
212 //=================================================================================
213 // function : ClickOnApply()
214 // purpose  :
215 //=================================================================================
216 void RepairGUI_SuppressHoleDlg::ClickOnApply()
217 {
218   QAD_Application::getDesktop()->putInfo(tr(""));
219   bool testResult = false;
220   
221   if(!myOkShape)
222     return;
223
224   switch (myConstructorId)
225     {
226     case 0: /* default constructor */
227       {
228         if(!myOkSelectFace)
229           return;
230   
231         if(Group1->CheckButton2->isChecked()) {
232           if(!Group1->CheckButton3->isChecked()) {
233             /* Call method to get sub shape selection of GEOM::WIRE */
234             bool aTest = this->GetIndexSubShapeSelected(myFace, int(TopAbs_WIRE), myListOfIdWire, myLocalContextId, myUseLocalContext);
235             
236             /* Display all objects so that next method using ic can memorize them */
237             DisplayGUI* myDisplayGUI = new DisplayGUI();
238             myDisplayGUI->OnDisplayAll(true);
239
240             if(!aTest || myListOfIdWire->length() != 1) {
241               Group1->CheckButton2->setChecked(FALSE);
242               QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT")); 
243             }
244             else {
245               myListOfIdEndFace->length(0); /* no end face */   
246               QApplication::setOverrideCursor(Qt::waitCursor);
247               testResult = myRepairGUI->OnSuppressHole(myShapeIOR, myListOfIdFace, myListOfIdWire, myListOfIdEndFace);
248               QApplication::restoreOverrideCursor();
249             }
250           }
251           else { /* Group1->CheckButton3->isChecked() */
252             
253             /* Call method to get sub shape selection of END GEOM::FACE */
254             bool aTest = this->GetIndexSubShapeSelected(myShape, int(TopAbs_FACE), myListOfIdEndFace, myLocalContextId, myUseLocalContext);
255
256             /* Display all objects so that next method using ic can memorize them */
257             DisplayGUI* myDisplayGUI = new DisplayGUI();
258             myDisplayGUI->OnDisplayAll(true);
259
260             if(!aTest || myListOfIdEndFace->length() != 1) {
261               Group1->CheckButton3->setChecked(FALSE);
262               QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT")); 
263             }
264             else {      
265               QApplication::setOverrideCursor(Qt::waitCursor);
266               testResult = myRepairGUI->OnSuppressHole(myShapeIOR, myListOfIdFace, myListOfIdWire, myListOfIdEndFace); 
267               QApplication::restoreOverrideCursor();
268             }     
269           }
270         }
271         break;
272       }
273     case 1:  /* second constructor */
274       {
275         if(Group2->CheckButton1->isChecked()) {
276           /* Call method to get sub shape selection of one or more GEOM::WIRE(s) on a face or a shell */
277           bool aTest = this->GetIndexSubShapeSelected(myShape, int(TopAbs_WIRE), myListOfIdWire, myLocalContextId, myUseLocalContext);
278           
279           /* Display all objects so that next method using ic can memorize them */
280           DisplayGUI* myDisplayGUI = new DisplayGUI();
281           myDisplayGUI->OnDisplayAll(true);
282           
283           if(!aTest || myListOfIdWire->length() < 1) {
284             Group2->CheckButton1->setChecked(FALSE);
285             QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
286           }
287           else {
288             QApplication::setOverrideCursor(Qt::waitCursor);
289             testResult = myRepairGUI->OnSuppressHolesInFaceOrShell(myShapeIOR, myListOfIdWire);
290             QApplication::restoreOverrideCursor();
291           }
292         }
293         break;
294       }
295     }
296   
297
298   if(!testResult)
299     QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
300   else
301     QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
302   
303   /* Reset arguments to allow a new selection */
304   this->ResetStateOfDialog();
305   return;
306 }
307
308
309 //=================================================================================
310 // function : ClickOnCancel()
311 // purpose  :
312 //=================================================================================
313 void RepairGUI_SuppressHoleDlg::ClickOnCancel()
314 {
315   this->ResetStateOfDialog();
316   GEOMBase_Skeleton::ClickOnCancel();
317   return;
318 }
319
320
321 //=================================================================================
322 // function : SelectionIntoArgument()
323 // purpose  : Called when selection as changed or other case
324 //          : used only by SelectButtonC1A1 and SelectButtonC2A1
325 //=================================================================================
326 void RepairGUI_SuppressHoleDlg::SelectionIntoArgument()
327 {
328   myEditCurrentArgument->setText("");
329   this->ResetStateOfDialog();
330   QString aString = ""; /* name of selection */
331
332   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
333   if(nbSel != 1)
334     return;
335   
336   /* nbSel == 1 */
337   TopoDS_Shape S;
338   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
339
340   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
341     return;
342   
343   if(S.IsNull() || S.ShapeType() == TopAbs_VERTEX || S.ShapeType() == TopAbs_EDGE || S.ShapeType() == TopAbs_WIRE)
344     return;
345   
346   /* Test the exact type of topology to suppress faces into.         */
347   /* For the second constructor a face or shell selection is needed  */
348   if(myConstructorId == 0 || (myConstructorId == 1 && (S.ShapeType() == TopAbs_FACE || S.ShapeType() == TopAbs_SHELL))) {
349     if(IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) {
350       Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IO);
351
352       /* The Geom IOR string of selection */
353       myShapeIOR = GIObject->getIOR();
354       myEditCurrentArgument->setText(aString);
355       myShape = S;
356       myOkShape = true;
357       return;
358     } 
359     
360     if(IO->hasEntry()) {
361       SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
362       SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry());
363       SALOMEDS::GenericAttribute_var anAttr;
364       SALOMEDS::AttributeIOR_var anIOR;
365       if(!obj->_is_nil()) {
366         if(obj->FindAttribute(anAttr, "AttributeIOR")) {
367           anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
368           myShapeIOR = anIOR->Value();
369           myOkShape = true;
370           myShape = S;
371           myEditCurrentArgument->setText(aString);
372           return;
373         }
374       }
375     }
376     
377   }
378   return;
379 }
380
381
382 //=================================================================================
383 // function : SetEditCurrentArgument()
384 // purpose  :
385 //=================================================================================
386 void RepairGUI_SuppressHoleDlg::SetEditCurrentArgument()
387 {
388   QPushButton* send = (QPushButton*)sender();  
389
390   if(send == Group1->PushButton1) {
391     Group1->LineEdit1->setFocus();
392     myEditCurrentArgument = Group1->LineEdit1;
393   }
394   else if(send == Group2->PushButton1) {
395     Group2->LineEdit1->setFocus();
396     myEditCurrentArgument = Group2->LineEdit1;
397   }
398   this->SelectionIntoArgument();
399   return;
400 }
401
402
403 //=================================================================================
404 // function : LineEditReturnPressed()
405 // purpose  :
406 //=================================================================================
407 void RepairGUI_SuppressHoleDlg::LineEditReturnPressed()
408 {
409   QLineEdit* send = (QLineEdit*)sender();
410   if(send == Group1->LineEdit1)
411     myEditCurrentArgument = Group1->LineEdit1;
412   else if (send == Group2->LineEdit1)
413     myEditCurrentArgument = Group2->LineEdit1;
414   else
415     return;
416
417   GEOMBase_Skeleton::LineEditReturnPressed();
418   return;
419 }
420
421
422 //=================================================================================
423 // function : DeactivateActiveDialog()
424 // purpose  :
425 //=================================================================================
426 void RepairGUI_SuppressHoleDlg::DeactivateActiveDialog()
427 {
428   this->ResetStateOfDialog();
429   GEOMBase_Skeleton::DeactivateActiveDialog();
430   return;
431 }
432
433
434 //=================================================================================
435 // function : ActivateThisDialog()
436 // purpose  :
437 //=================================================================================
438 void RepairGUI_SuppressHoleDlg::ActivateThisDialog()
439 {
440   GEOMBase_Skeleton::ActivateThisDialog();
441   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
442   return;
443 }
444
445
446 //=================================================================================
447 // function : enterEvent()
448 // purpose  : Mouse enter onto the dialog to activate it
449 //=================================================================================
450 void RepairGUI_SuppressHoleDlg::enterEvent(QEvent* e)
451 {
452   if(GroupConstructors->isEnabled())
453     return;
454   this->ActivateThisDialog();
455   return;
456 }
457
458
459 //=================================================================================
460 // function : closeEvent()
461 // purpose  :
462 //=================================================================================
463 void RepairGUI_SuppressHoleDlg::closeEvent(QCloseEvent* e)
464 {
465   /* same than click on cancel button */
466   this->ClickOnCancel();
467   return;
468 }
469
470
471 //=================================================================================
472 // function : ActivateUserFaceSelection()
473 // purpose  : Called when CheckBox1 state has changed. (Face selection is ckecked)
474 //          : Be careful user must first select a face then a wire !
475 //=================================================================================
476 void RepairGUI_SuppressHoleDlg::ActivateUserFaceSelection()
477 {
478   if(!this->myOkShape) {
479     this->ResetStateOfDialog();
480     QAD_Application::getDesktop()->putInfo(tr("GEOM_MAIN_OBJECT"));
481     return;
482   }
483   
484   if(Group1->CheckButton1->isChecked()) {
485     /* local context is opened into the method : Prepare GEOM::FACE sub selection */
486     DisplayGUI* myDisplayGUI = new DisplayGUI();
487     myDisplayGUI->PrepareSubShapeSelection(int(TopAbs_FACE), myLocalContextId);    
488     myUseLocalContext = true;
489     QAD_Application::getDesktop()->putInfo(tr("GEOM_SUPPRESSHOLE_SELECTFACE"));
490   } 
491   else
492     this->ResetPartial();
493
494   return;
495 }
496
497
498 //=================================================================================
499 // function : ActivateUserWireSelection()
500 // purpose  : Called when CheckBox2 state has changed. (Wire selection is ckecked)
501 //          : Be careful user must first select a face then a wire !
502 //=================================================================================
503 void RepairGUI_SuppressHoleDlg::ActivateUserWireSelection()
504 {
505   
506   if(!myOkShape) {
507     this->ResetStateOfDialog();
508     QAD_Application::getDesktop()->putInfo(tr("GEOM_MAIN_OBJECT"));
509     return;
510   } 
511
512   if(Group1->CheckButton1->isChecked()) {
513     /* Get sub shape selection GEOM::FACE : local context is closed */    
514     bool aTest = this->GetIndexSubShapeSelected(myShape, int(TopAbs_FACE), myListOfIdFace, myLocalContextId, myUseLocalContext);
515     
516     /* Display all objects so that next method using ic can memorize them */
517     DisplayGUI* myDisplayGUI = new DisplayGUI();
518     myDisplayGUI->OnDisplayAll(true);
519     if(!aTest || myListOfIdFace->length() != 1) {
520       Group1->CheckButton1->setChecked(FALSE);
521       myOkSelectFace = false;
522       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT")); 
523     }
524     else
525       myOkSelectFace = true;
526   }
527   else {
528     this->ResetPartial();
529     return;
530   }
531   
532
533   if(Group1->CheckButton2->isChecked()) {
534     /* Get the face selection */
535     myFace = FaceFromList(myShape, myListOfIdFace);    
536     /* Local context is opened into the method : Prepare GEOM::WIRE sub selection into a face */
537     DisplayGUI* myDisplayGUI = new DisplayGUI();
538     myDisplayGUI->PrepareSubShapeSelectionArgumentShape(myFace, int(TopAbs_WIRE), myLocalContextId);    
539     myUseLocalContext = true;
540     QAD_Application::getDesktop()->putInfo(tr("GEOM_SUPPRESSHOLE_SELECTWIRE"));
541   }
542   else {
543     this->ResetPartial();
544   }
545   return;
546 }
547
548
549 //=================================================================================
550 // function : ActivateUserlEndFaceSelection()
551 // purpose  : Called when CheckBox3 state has changed. ( Optional End Face selection )
552 //          : Be careful user must first select a face then a wire then this optional end face !
553 //=================================================================================
554 void RepairGUI_SuppressHoleDlg::ActivateUserEndFaceSelection()
555 {
556   
557   if(!myOkShape) {
558     this->ResetStateOfDialog();
559     QAD_Application::getDesktop()->putInfo(tr("GEOM_MAIN_OBJECT"));
560     return;
561   }
562   
563   if(Group1->CheckButton2->isChecked()) {
564     /* Call method to get sub shape selection for the GEOM::WIRE into myFace : local context is closed */
565     bool aTest = this->GetIndexSubShapeSelected(myFace, int(TopAbs_WIRE), myListOfIdWire, myLocalContextId, myUseLocalContext);
566     
567     /* Display all objects so that next method using ic can memorize them */
568     DisplayGUI* myDisplayGUI = new DisplayGUI();
569     myDisplayGUI->OnDisplayAll(true);
570     
571     if(!aTest || myListOfIdWire->length() != 1) {
572       Group1->CheckButton2->setChecked(FALSE);
573       Group1->CheckButton3->setChecked(FALSE);
574       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));     
575       return;
576     }
577   }
578   else {
579     this->ResetPartial();
580     return;
581   }
582   
583   
584   if(Group1->CheckButton3->isChecked()) {    
585     /* Local context is opened into the method : prepare GEOM::FACE(end) into myShape sub selection */
586     DisplayGUI* myDisplayGUI = new DisplayGUI();
587     myDisplayGUI->PrepareSubShapeSelectionArgumentShape(myShape, int(TopAbs_FACE), myLocalContextId);    
588     myUseLocalContext = true;
589     QAD_Application::getDesktop()->putInfo(tr("GEOM_SUPPRESSHOLE_SELECTFACE_END"));
590   }
591   else
592     this->ResetPartial();
593   return;
594 }
595
596
597 //=================================================================================
598 // function : ActivateUserWiresOnFaceShellSelection()
599 // purpose  : Called when CheckBoxC2_1 state has changed.
600 //          : Only for second constructor !
601 //          : Prepare selection for wire(s) on main object that is a face or a shell
602 //=================================================================================
603 void RepairGUI_SuppressHoleDlg::ActivateUserWiresOnFaceShellSelection()
604 {
605   
606   if(!myOkShape) {
607     this->ResetStateOfDialog();
608     QAD_Application::getDesktop()->putInfo(tr("GEOM_MAIN_OBJECT"));
609     return;
610   }
611   
612   if(Group2->CheckButton1->isChecked()) {    
613     /* Local context is opened to prepare GEOM::WIRE(S) selection into 'myShape' that is a (main) face */
614     DisplayGUI* myDisplayGUI = new DisplayGUI();
615     myDisplayGUI->PrepareSubShapeSelectionArgumentShape(myShape, int(TopAbs_WIRE), myLocalContextId);    
616     myUseLocalContext = true;
617     QAD_Application::getDesktop()->putInfo(tr("GEOM_SUPPRESSHOLE_SELECT_HOLES_ON_FACE"));
618   }
619   else
620     this->ResetPartial();
621   return;
622 }
623
624
625 //=================================================================================
626 // function : FaceFromList()
627 // purpose  : Return the face (selected by user) that is a sub shape of 'aShape'
628 //          : and which unique index is in 'ListOfSub'.
629 //          : This allows opening a local context with this face loaded.
630 //          : See : myGeomBase->PrepareSubShapeSelectionArgumentShape(...)
631 //=================================================================================
632 TopoDS_Shape RepairGUI_SuppressHoleDlg::FaceFromList(const TopoDS_Shape& aShape,
633                                                      const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfSub)
634 {
635   TopoDS_Shape tds;
636   tds.Nullify();
637   if(ListOfSub.length() != 1 || aShape.IsNull())
638     return tds;
639   
640   int i = ListOfSub[0];
641   TopExp_Explorer exp;
642   int j = 1; 
643   for(exp.Init(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
644     if(j == i)
645       return exp.Current();    
646     j++;
647   }
648   return tds;
649 }
650
651
652 //=================================================================================
653 // function : ResetStateOfDialog()
654 // purpose  : Completely reset the state of method including local context
655 //=================================================================================
656 void RepairGUI_SuppressHoleDlg::ResetStateOfDialog()
657 {
658   myOkShape = false;
659   myEditCurrentArgument->setText("");
660   QApplication::restoreOverrideCursor();
661   
662   /* Partial reset and more ...*/
663   this->ResetPartial();
664
665   return;
666 }
667
668
669 //=================================================================================
670 // function : ResetPartial()
671 // purpose  : Partially reset to keep only main selection
672 //=================================================================================
673 void RepairGUI_SuppressHoleDlg::ResetPartial()
674 {
675   /* Select sub shape modes not checked */
676   myOkSelectFace = false ;
677   Group1->CheckButton1->setChecked(FALSE);
678   Group1->CheckButton2->setChecked(FALSE);
679   Group1->CheckButton3->setChecked(FALSE);
680   Group2->CheckButton1->setChecked(FALSE);
681   
682   myListOfIdFace->length(0);
683   myListOfIdWire->length(0);
684   myListOfIdEndFace->length(0);
685
686   /* Close its local contact if opened */
687   if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC && myUseLocalContext) {
688     myIC->CloseLocalContext(myLocalContextId);
689     myUseLocalContext = false;
690     DisplayGUI* myDisplayGUI = new DisplayGUI();
691     myDisplayGUI->OnDisplayAll(true);
692   }
693   return;
694 }
695
696
697 //=====================================================================================
698 // function : GetIndexSubShapeSelected()
699 // purpose  : Define a ListOfID of sub shapes selected in ShapeTopo with SubShapeType
700 //          : Method used by Dialogs
701 //=====================================================================================
702 bool RepairGUI_SuppressHoleDlg::GetIndexSubShapeSelected(const TopoDS_Shape& ShapeTopo, const int SubShapeType, GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID, Standard_Integer& aLocalContextId, bool& myUseLocalContext)
703 {
704   //* Test the type of viewer */
705   if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
706     return false;
707   
708   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
709   Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
710
711   ic->InitSelected();
712   int nbSelected = ic->NbSelected();
713   ListOfID.length(nbSelected);
714   
715   //***************** DEFINE INDEX OF EACH SELECTION *********************//
716   int i = 0;
717   ic->InitSelected(); /* to restart */
718   while(ic->MoreSelected()) {
719     /* Find index of sub shape into main shape */
720     TopExp_Explorer Exp (ShapeTopo, TopAbs_ShapeEnum(SubShapeType));
721     int index = 1;
722     bool found = false;
723     while( Exp.More()) {
724       if((Exp.Current()).IsSame(ic->SelectedShape())) {
725         found = true;
726         break;
727       }
728       index++;
729       Exp.Next();
730     }
731     if(!found) {
732       /* Manage local context from DialogBox */
733       ic->CloseLocalContext(aLocalContextId);
734       myUseLocalContext = false;
735       return false;
736     }
737     ListOfID[i] = index;
738     i++;
739     ic->NextSelected();
740   }
741     //***************** END  *********************//
742
743   /* Manage local context from DialogBox */
744   ic->CloseLocalContext(aLocalContextId);
745   myUseLocalContext = false;
746   
747   return true;
748 }