Salome HOME
a9ba9622f09bd4089f9db41300bf48a56c2cee8f
[modules/geom.git] / src / MeasureGUI / MeasureGUI_FastCheckIntersectionsDlg.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : MeasureGUI_FastCheckIntersectionsDlg.cxx
25
26 #include "MeasureGUI_FastCheckIntersectionsDlg.h"
27 #include "MeasureGUI.h"
28
29 #include <SUIT_OverrideCursor.h>
30 #include <SUIT_Session.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SUIT_MessageBox.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SalomeApp_Tools.h>
35 #include <SalomeApp_Application.h>
36
37 #include <TopTools_IndexedMapOfShape.hxx>
38 #include <TopExp.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TColStd_MapOfInteger.hxx>
41
42 #include <DlgRef.h>
43 #include <GeometryGUI.h>
44 #include <GEOMBase.h>
45 #include <GEOMImpl_Types.hxx>
46
47 #include <QListWidget>
48
49 #define TEXTEDIT_FONT_FAMILY "Courier"
50 #define TEXTEDIT_FONT_SIZE 11
51 //=================================================================================
52 // class    : MeasureGUI_FastCheckIntersectionsDlg()
53 // purpose  : Constructs a MeasureGUI_FastCheckIntersectionsDlg which is a child of 'parent', with the
54 //            name 'name' and widget flags set to 'f'.
55 //            The dialog will by default be modeless, unless you set 'modal' to
56 //            true to construct a modal dialog.
57 //=================================================================================
58 MeasureGUI_FastCheckIntersectionsDlg::MeasureGUI_FastCheckIntersectionsDlg (GeometryGUI* GUI, QWidget* parent)
59   : GEOMBase_Skeleton (GUI, parent, false),
60     mySelButton1       (0),
61     mySelButton2       (0),
62     myEditObjName1     (0),
63     myEditObjName2     (0),
64     myDetGaps          (0),
65     myTolerance        (0),
66     myDeflection       (0),
67     myComputeButton    (0),
68     myShapeList1       (0),
69     myShapeList2       (0)
70 {
71   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
72   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_FAST_CHECK_INTERSECTIONS")));
73   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
74
75   setWindowTitle(tr("GEOM_FAST_CHECK_INTERSECTIONS"));
76
77   /***************************************************************/
78   mainFrame()->GroupConstructors->setTitle(tr("GEOM_FAST_CHECK_INTERSECTIONS"));
79   mainFrame()->RadioButton1->setIcon(image0);
80   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
81   mainFrame()->RadioButton2->close();
82   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
83   mainFrame()->RadioButton3->close();
84
85   QGroupBox *aGrp      = new QGroupBox(tr("GEOM_FAST_CHECK_OBJ"));
86   QLabel    *anObjLbl1  = new QLabel(tr("GEOM_OBJECT_I").arg("1"));
87   QLabel    *anObjLbl2  = new QLabel(tr("GEOM_OBJECT_I").arg("2"));
88   QLabel    *aShapeLbl1 = new QLabel(tr("GEOM_FAST_CHECK_INT_SUBSHAPES").arg("1"));
89   QLabel    *aShapeLbl2 = new QLabel(tr("GEOM_FAST_CHECK_INT_SUBSHAPES").arg("2"));
90   QLabel    *aDeflectLbl = new QLabel(tr("GEOM_FAST_CHECK_INT_DEFLECT"));
91   QFont      aFont (TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE);
92
93   aFont.setStyleHint(QFont::TypeWriter, QFont::PreferAntialias);
94
95   mySelButton1 = new QPushButton;
96   mySelButton1->setIcon(image1);
97   mySelButton1->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
98   mySelButton2 = new QPushButton;
99   mySelButton2->setIcon(image1);
100   mySelButton2->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
101
102   myEditObjName1 = new QLineEdit;
103   myEditObjName1->setReadOnly(true);
104   myEditObjName2 = new QLineEdit;
105   myEditObjName2->setReadOnly(true);
106
107   myDetGaps = new QCheckBox( tr( "GEOM_FAST_CHECK_INT_DETECT_GAPS" ));
108   myTolerance = new SalomeApp_DoubleSpinBox;
109   myDeflection = new SalomeApp_DoubleSpinBox;
110   myShapeList1  = new QListWidget;
111   myShapeList2 = new QListWidget;
112   myShapeList1->setSelectionMode(QAbstractItemView::ExtendedSelection);
113   myShapeList2->setSelectionMode(QAbstractItemView::ExtendedSelection);
114
115   myComputeButton = new QPushButton(tr("GEOM_FAST_CHECK_INT_COMPUTE"));
116
117   QGridLayout *aGrpLayout = new QGridLayout(aGrp);
118   aGrpLayout->setMargin(9);
119   aGrpLayout->setSpacing(6);
120   aGrpLayout->addWidget(anObjLbl1,       0, 0);
121   aGrpLayout->addWidget(mySelButton1,    0, 1);
122   aGrpLayout->addWidget(myEditObjName1,  0, 2);
123   aGrpLayout->addWidget(anObjLbl2,       1, 0);
124   aGrpLayout->addWidget(mySelButton2,    1, 1);
125   aGrpLayout->addWidget(myEditObjName2,  1, 2);
126   aGrpLayout->addWidget(aDeflectLbl,     2, 0);
127   aGrpLayout->addWidget(myDeflection,    2, 1, 1, 2);
128   aGrpLayout->addWidget(myDetGaps,       3, 0);
129   aGrpLayout->addWidget(myTolerance,     3, 1, 1, 2);
130   aGrpLayout->addWidget(myComputeButton, 4, 0, 1, 3);
131   
132   QGridLayout *aGrpLayout2 = new QGridLayout();
133   aGrpLayout->addLayout(aGrpLayout2,     5, 0, 1, 3);
134   aGrpLayout2->addWidget(aShapeLbl1,     0, 0);
135   aGrpLayout2->addWidget(aShapeLbl2,     0, 1);
136   aGrpLayout2->addWidget(myShapeList1,   1, 0);
137   aGrpLayout2->addWidget(myShapeList2,   1, 1);
138
139   QVBoxLayout* layout = new QVBoxLayout (centralWidget());
140   layout->setMargin(0); layout->setSpacing(6);
141   layout->addWidget(aGrp);
142
143   /***************************************************************/
144
145   myHelpFileName = "fast_intersection_page.html";
146
147   // Initialisation 
148   Init();
149 }
150
151 //=================================================================================
152 // function : ~MeasureGUI_FastCheckIntersectionsDlg()
153 // purpose  : Destroys the object and frees any allocated resources
154 //=================================================================================
155 MeasureGUI_FastCheckIntersectionsDlg::~MeasureGUI_FastCheckIntersectionsDlg()
156 {
157 }
158
159 //=================================================================================
160 // function : Init()
161 // purpose  :
162 //=================================================================================
163 void MeasureGUI_FastCheckIntersectionsDlg::Init()
164 {
165   myObj1.nullify();
166   myObj2.nullify();
167   myEditObjName1->setText("");
168   myEditObjName2->setText("");
169   myEditObjName1->setEnabled(true);
170   myEditObjName2->setEnabled(false);
171
172   myDetGaps->setChecked(false);
173   double SpecificStep = 0.001;
174   double prec = Precision::Confusion();
175   initSpinBox(myTolerance, prec, MAX_NUMBER, SpecificStep);
176   myTolerance->setValue(SpecificStep);
177   myTolerance->setEnabled(false);
178
179   // Obtain deflection from preferences
180   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
181   const char* quantity = "deflection_coeff";
182   double aDeflection = resMgr->doubleValue("Geometry", quantity, 0.00001); 
183   initSpinBox(myDeflection, prec, 1.0, aDeflection);
184   myDeflection->setValue(aDeflection);
185
186   myEditCurrentArgument = myEditObjName1;
187
188   connect(myGeomGUI,          SIGNAL(SignalDeactivateActiveDialog()),
189           this,               SLOT(DeactivateActiveDialog()));
190   connect(myGeomGUI,          SIGNAL(SignalCloseAllDialogs()),
191           this,               SLOT(ClickOnCancel()));
192   connect(buttonOk(),         SIGNAL(clicked()), this, SLOT(ClickOnOk()));
193   connect(buttonApply(),      SIGNAL(clicked()), this, SLOT(ClickOnApply()));
194   connect(mySelButton1,       SIGNAL(clicked()),
195           this,               SLOT(SetEditCurrentArgument()));
196   connect(mySelButton2,       SIGNAL(clicked()),
197           this,               SLOT(SetEditCurrentArgument()));
198   connect(myDetGaps,          SIGNAL(toggled(bool)), this, SLOT(OnGaps(bool))); 
199   connect( myTolerance,       SIGNAL(valueChanged(double)), this, SLOT(clear()));
200   connect( myDeflection,      SIGNAL(valueChanged(double)), this, SLOT(clear()));
201   connect(myShapeList1,       SIGNAL(itemSelectionChanged()),
202           SLOT(onSubShapesListSelectionChanged()));
203   connect(myShapeList2,       SIGNAL(itemSelectionChanged()),
204           SLOT(onSubShapesListSelectionChanged()));
205   connect(myComputeButton,    SIGNAL(clicked()), this, SLOT(onCompute()));
206
207   LightApp_SelectionMgr* aSel = myGeomGUI->getApp()->selectionMgr();
208
209   connect(aSel,               SIGNAL(currentSelectionChanged()),
210           this,               SLOT(SelectionIntoArgument()));
211
212   initName(tr("GEOM_FAST_INTERSECTION_NAME"));
213   buttonOk()->setEnabled(false);
214   buttonApply()->setEnabled(false);
215   myComputeButton->setEnabled(false);
216   activateSelection();
217
218   mySelButton1->click();
219   SelectionIntoArgument();
220 }
221
222 //=================================================================================
223 // function : clear
224 // purpose  :
225 //=================================================================================
226 void MeasureGUI_FastCheckIntersectionsDlg::clear()
227 {
228   disconnect(myShapeList1, SIGNAL(itemSelectionChanged()), this, 0);
229   disconnect(myShapeList2, SIGNAL(itemSelectionChanged()), this, 0);
230   myShapeList1->clear();
231   myShapeList2->clear();
232   connect(myShapeList1,    SIGNAL(itemSelectionChanged()),
233           SLOT(onSubShapesListSelectionChanged()));
234   connect(myShapeList2,    SIGNAL(itemSelectionChanged()),
235           SLOT(onSubShapesListSelectionChanged()));
236   erasePreview();
237   buttonOk()->setEnabled(false);
238   buttonApply()->setEnabled(false);
239   myComputeButton->setEnabled(true);
240 }
241
242 //=================================================================================
243 // function : onCompute
244 // purpose  :
245 //=================================================================================
246 void MeasureGUI_FastCheckIntersectionsDlg::onCompute()
247 {
248   myShapeList1->clear();
249   myShapeList2->clear();
250
251   if (!findIntersections()) {
252     myShapeList1->addItem(tr("GEOM_FAST_INTERSECTION_FAILS"));
253     myShapeList1->setEnabled(false);
254     myShapeList2->addItem(tr("GEOM_FAST_INTERSECTION_FAILS"));
255     myShapeList2->setEnabled(false);
256     return;
257   }
258   
259   myShapeList1->setEnabled(true);
260   myShapeList2->setEnabled(true);
261   QStringList aSubShapeList1, aSubShapeList2;
262   TopoDS_Shape aSelShape1, aSelShape2;
263   if (myObj1 && GEOMBase::GetShape(myObj1.get(), aSelShape1) && myObj2
264                      && GEOMBase::GetShape(myObj2.get(), aSelShape2)) {
265     TopTools_IndexedMapOfShape anIndices1, anIndices2;
266     TopExp::MapShapes(aSelShape1, anIndices1);
267     TopExp::MapShapes(aSelShape2, anIndices2);
268
269     //Sub-shapes of 1st Object
270     for (int i = 0; i < myInters1->length(); i++) {
271       TopoDS_Shape aSubShape = anIndices1.FindKey(myInters1[i]);
272       QString aType = GEOMBase::GetShapeTypeString(aSubShape);
273       if (!aType.isEmpty())
274         aSubShapeList1.append(QString("%1_%2").arg(aType).arg(myInters1[i]));
275     }
276     myShapeList1->addItems(aSubShapeList1);
277     myShapeList1->selectAll();
278
279     //Sub-shapes of second Object
280     for (int i = 0; i < myInters2->length(); i++) {
281       TopoDS_Shape aSubShape = anIndices2.FindKey(myInters2[i]);
282       QString aType = GEOMBase::GetShapeTypeString(aSubShape);
283       if (!aType.isEmpty())
284         aSubShapeList2.append(QString("%1_%2").arg(aType).arg(myInters2[i]));
285     }
286     myShapeList2->addItems(aSubShapeList2);
287     myShapeList2->selectAll();
288   }
289
290   buttonOk()->setEnabled(true);
291   buttonApply()->setEnabled(true);
292   myComputeButton->setEnabled(false);
293 }
294
295 //=================================================================================
296 // function : ActivateThisDialog
297 // purpose  :
298 //=================================================================================
299 void MeasureGUI_FastCheckIntersectionsDlg::ActivateThisDialog()
300 {
301   GEOMBase_Skeleton::ActivateThisDialog();
302
303   LightApp_SelectionMgr* aSel = myGeomGUI->getApp()->selectionMgr();
304   if ( aSel )
305     connect( aSel, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
306
307   activateSelection();
308   DISPLAY_PREVIEW_MACRO
309 }
310
311 //=================================================================================
312 // function : DeactivateActiveDialog()
313 // purpose  : public slot to deactivate if active
314 //=================================================================================
315 void MeasureGUI_FastCheckIntersectionsDlg::DeactivateActiveDialog()
316 {
317   GEOMBase_Skeleton::DeactivateActiveDialog();
318 }
319
320 //=================================================================================
321 // function : activateSelection
322 // purpose  : 
323 //=================================================================================
324 void MeasureGUI_FastCheckIntersectionsDlg::activateSelection()
325 {
326   TColStd_MapOfInteger aTypes;
327   aTypes.Add(GEOM_COMPOUND );
328   aTypes.Add(GEOM_SOLID );
329   aTypes.Add(GEOM_SHELL);
330   aTypes.Add(GEOM_FACE);
331   globalSelection(aTypes);
332
333   std::list<int> needTypes;
334   needTypes.push_back( TopAbs_FACE ), needTypes.push_back( TopAbs_SHELL ), needTypes.push_back( TopAbs_SOLID ), needTypes.push_back( TopAbs_COMPOUND );
335   localSelection(GEOM::GEOM_Object::_nil(), needTypes );
336
337 }
338
339 //=================================================================================
340 // function : ClickOnOk()
341 // purpose  :
342 //=================================================================================
343 void MeasureGUI_FastCheckIntersectionsDlg::ClickOnOk()
344 {
345   if ( ClickOnApply() )
346     ClickOnCancel();
347 }
348
349 //=================================================================================
350 // function : ClickOnApply()
351 // purpose  :
352 //=================================================================================
353 bool MeasureGUI_FastCheckIntersectionsDlg::ClickOnApply()
354 {
355   if ( !onAccept() )
356     return false;
357
358   clear();
359   initName();
360   return true;
361 }
362
363 //=================================================================================
364 // function : extractPrefix
365 // purpose  :
366 //=================================================================================
367 bool MeasureGUI_FastCheckIntersectionsDlg::extractPrefix() const
368 {
369   return true;
370 }
371
372 //=================================================================================
373 // function : createOperation
374 // purpose  :
375 //=================================================================================
376 GEOM::GEOM_IOperations_ptr MeasureGUI_FastCheckIntersectionsDlg::createOperation()
377 {
378   return getGeomEngine()->GetIMeasureOperations( getStudyId() );
379 }
380
381 //=================================================================================
382 // function : isValid
383 // purpose  :
384 //=================================================================================
385 bool MeasureGUI_FastCheckIntersectionsDlg::isValid( QString& )
386 {
387   return myObj1 && myObj2;
388 }
389
390 //=================================================================================
391 // function : SetEditCurrentArgument
392 // purpose  :
393 //=================================================================================
394 void MeasureGUI_FastCheckIntersectionsDlg::SetEditCurrentArgument()
395 {
396     QPushButton* send = (QPushButton*)sender();
397
398   if (send == mySelButton1) {
399     myEditCurrentArgument = myEditObjName1;
400
401     mySelButton2->setDown(false);
402     myEditObjName2->setEnabled(false);
403     myObj1.nullify();
404   }
405   else {
406     myEditCurrentArgument = myEditObjName2;
407
408     mySelButton1->setDown(false);
409     myEditObjName1->setEnabled(false);
410     myObj2.nullify();
411   }
412
413   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
414   activateSelection();
415   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
416           this, SLOT(SelectionIntoArgument()));
417
418   // enable line edit
419   myEditCurrentArgument->setEnabled(true);
420   myEditCurrentArgument->setFocus();
421   // after setFocus(), because it will be setDown(false) when loses focus
422   send->setDown(true);
423
424   SelectionIntoArgument();
425 }
426
427 //=================================================================================
428 // function : OnGaps()
429 // purpose  :
430 //=================================================================================
431 void MeasureGUI_FastCheckIntersectionsDlg::OnGaps(bool cheked)
432 {
433   clear();
434   myTolerance->setEnabled(cheked);
435 }
436 //=================================================================================
437 // function : SelectionIntoArgument
438 // purpose  :
439 //=================================================================================
440 void MeasureGUI_FastCheckIntersectionsDlg::SelectionIntoArgument()
441 {
442   myEditCurrentArgument->setText("");
443   // Clear the dialog.
444   clear();
445
446   QList<TopAbs_ShapeEnum> typesLst;
447   typesLst << TopAbs_FACE << TopAbs_SHELL << TopAbs_SOLID << TopAbs_COMPOUND;
448   GEOM::GeomObjPtr aSelectedObject = getSelected( typesLst );
449
450   // clear selection
451   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
452   myGeomGUI->getApp()->selectionMgr()->clearSelected();
453   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
454           this, SLOT(SelectionIntoArgument()));
455
456   if (myEditCurrentArgument == myEditObjName1) {
457     myObj1 = aSelectedObject;
458     if (myObj1 && !myObj2)
459       mySelButton2->click();
460   }
461   else {
462     myObj2 = aSelectedObject;
463     if (myObj2 && !myObj1)
464       mySelButton1->click();
465   }
466   myEditObjName1->setText(myObj1 ? GEOMBase::GetName(myObj1.get()) : "");
467   myEditObjName2->setText(myObj2 ? GEOMBase::GetName(myObj2.get()) : "");
468 }
469
470 //=================================================================================
471 // function : enterEvent
472 // purpose  :
473 //=================================================================================
474 void MeasureGUI_FastCheckIntersectionsDlg::enterEvent(QEvent *)
475 {
476   if (!mainFrame()->GroupConstructors->isEnabled())
477     ActivateThisDialog();
478 }
479
480 //=================================================================================
481 // function : findIntersections
482 // purpose  :
483 //=================================================================================
484 bool MeasureGUI_FastCheckIntersectionsDlg::findIntersections()
485 {
486   if (!myObj1 || !myObj2)
487     return false;
488
489   GEOM::GEOM_IMeasureOperations_var anOper =
490     GEOM::GEOM_IMeasureOperations::_narrow(getOperation());
491   bool isOK = true;
492
493   bool HasInte;
494   try {
495     HasInte = anOper->FastIntersect(myObj1.get(), myObj2.get(), getTolerance(), getDeflection(), myInters1, myInters2);
496   }
497   catch (const SALOME::SALOME_Exception& e) {
498     SalomeApp_Tools::QtCatchCorbaException(e);
499     isOK = false;
500   }
501
502   bool isDone = anOper->IsDone();
503   if (!isDone) {
504     CORBA::String_var aMsg = anOper->GetErrorCode();
505     SUIT_MessageBox::warning(this,
506                              QObject::tr("WRN_WARNING"),
507                              QObject::tr(aMsg.in()));
508   }
509
510   if ( !HasInte || myInters1->length() == 0 || myInters2->length() == 0)
511     isOK = false;
512
513   return isOK;
514 }
515
516 //=================================================================================
517 // function : onSubShapesListSelectionChanged
518 // purpose  :
519 //=================================================================================
520 void MeasureGUI_FastCheckIntersectionsDlg::onSubShapesListSelectionChanged()
521 {
522   erasePreview();
523   previewSubShapesListSelection(myShapeList1);
524   previewSubShapesListSelection(myShapeList2);
525 }
526
527 //=================================================================================
528 // function : previewSubShapesListSelection
529 // purpose  :
530 //=================================================================================
531 void MeasureGUI_FastCheckIntersectionsDlg::previewSubShapesListSelection(QListWidget* theWidget)
532 {
533   GEOM::ListOfLong_var anInters;
534   GEOM::GeomObjPtr anObj;
535
536   if (theWidget == myShapeList1) { // Sub-Shapes of Object 1
537     anObj = myObj1;
538     anInters = myInters1;
539   }
540   else {
541     if (theWidget == myShapeList2) { // Sub-Shapes of Object 2
542       anObj = myObj2;
543       anInters = myInters2;
544     }
545     else return;
546   }
547   // Selected IDs
548   QList<int> aIds;
549   for (int i = 0, n = theWidget->count(); i < n; i++) {
550     if (theWidget->item(i)->isSelected())
551       aIds.append(i);
552   }
553   if (aIds.count() < 1)
554     return;
555
556   TopoDS_Shape aSelShape;
557   TopoDS_Shape aSubShape;
558   TopTools_IndexedMapOfShape anIndices;
559   if (anObj && GEOMBase::GetShape(anObj.get(), aSelShape)) {
560     SALOME_Prs* aPrs = 0;
561     TopExp::MapShapes(aSelShape, anIndices);
562     QList<int>::iterator it;
563     for (it = aIds.begin(); it != aIds.end(); ++it) {
564       aSubShape = anIndices.FindKey(anInters[(*it)]);
565       try {
566         getDisplayer()->SetColor(Quantity_NOC_RED);
567         getDisplayer()->SetWidth(3);
568         getDisplayer()->SetToActivate(false);
569         aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs(aSubShape) : 0;
570         if (aPrs)
571           displayPreview(aPrs, true);
572       }
573       catch (const SALOME::SALOME_Exception& e) {
574         SalomeApp_Tools::QtCatchCorbaException(e);
575       }
576     }
577   }
578 }
579
580 //=================================================================================
581 // function : getLstObjFromListSelection
582 // purpose  :
583 //=================================================================================
584 GEOM::ListOfGO_var MeasureGUI_FastCheckIntersectionsDlg::getLstObjFromListSelection(QListWidget* theWidget)
585 {
586   GEOM::ListOfLong_var anInters;
587   GEOM::GeomObjPtr anObj;
588   GEOM::ListOfGO_var anObjLst = new GEOM::ListOfGO();
589
590   if (theWidget == myShapeList1) { // Sub-Shapes of Object 1
591     anObj = myObj1;
592     anInters = myInters1;
593   }
594   else {
595     if (theWidget == myShapeList2) { // Sub-Shapes of Object 2
596       anObj = myObj2;
597       anInters = myInters2;
598     }
599     else
600       return anObjLst;
601   }
602   //Add in study myObj if local selection
603   GEOMBase::PublishSubObject( anObj.get() );
604   // Collect the map of indices and already publised objects
605   TColStd_IndexedMapOfInteger aMapIndex;
606   ObjectList aObjLstExist;
607   for (int i = 0, n = theWidget->count(); i < n; i++) {
608     if (theWidget->item(i)->isSelected()) {
609       GEOM::GEOM_Object_var aTmpObj = GEOMBase_Helper::findObjectInFather(anObj.get(), anInters[i]);
610       if (aTmpObj->_is_nil())
611         aMapIndex.Add(anInters[i]);
612       else
613         aObjLstExist.push_back( GEOM::GEOM_Object::_duplicate(aTmpObj));
614     }
615   }
616
617   if (aMapIndex.IsEmpty() && aObjLstExist.empty())
618     return anObjLst;
619  
620   // Create objects.
621   GEOM::ListOfLong_var anArray   = new GEOM::ListOfLong;
622   const int            aNbShapes = aMapIndex.Extent();
623   anArray->length(aNbShapes);
624   for (int i = 1; i <= aNbShapes; i++) {
625     anArray[i - 1] = aMapIndex.FindKey(i);
626   }
627
628   if (myShapesOper->_is_nil())
629     myShapesOper = getGeomEngine()->GetIShapesOperations(getStudyId());
630
631   GEOM::ListOfGO_var aObjLstCreate = myShapesOper->MakeSubShapes(anObj.get(), anArray);
632
633   //Collect all objects in list
634   anObjLst->length(aObjLstCreate->length() + aObjLstExist.size());
635   
636   ObjectList::iterator anIter;
637   int i;
638   for (i=0, anIter = aObjLstExist.begin(); anIter != aObjLstExist.end(); i++, ++anIter) {
639     anObjLst[i] = *anIter;
640   }
641   for (int j = 0; j < aObjLstCreate->length(); j++) {
642     anObjLst[aObjLstExist.size()+j]=aObjLstCreate[j];
643   }
644   return  anObjLst._retn();
645 }
646
647 //=================================================================================
648 // function : execute
649 // purpose  :
650 //=================================================================================
651 bool MeasureGUI_FastCheckIntersectionsDlg::execute(ObjectList& objects)
652 {
653   GEOM::ListOfGO_var aList1 = getLstObjFromListSelection(myShapeList1);
654   GEOM::ListOfGO_var aList2 = getLstObjFromListSelection(myShapeList2);
655   GEOM::ListOfGO_var aCompList = new GEOM::ListOfGO();
656   const int nbObj = aList1->length() + aList2->length();
657   if (nbObj <= 0)
658     return true;
659
660   //Collect general intersection list
661   aCompList->length(nbObj);
662   int i;
663   for (i = 0; i < aList1->length(); i++) {
664     GEOMBase::PublishSubObject( aList1[i] );
665     aCompList[i]=aList1[i];
666   }
667   for (int j = 0; j < aList2->length(); j++) {
668     GEOMBase::PublishSubObject( aList2[j] );
669     aCompList[i+j]=aList2[j];
670   }
671
672   // make compound
673   objects.push_back(myShapesOper->MakeCompound(aCompList));
674   return true; 
675 }
676
677 //=================================================================================
678 // function : getDeflection
679 // purpose  :
680 //=================================================================================
681 float MeasureGUI_FastCheckIntersectionsDlg::getDeflection()
682 {
683   return (float)myDeflection->value();
684 }
685
686 //=================================================================================
687 // function : getTolerance
688 // purpose  :
689 //=================================================================================
690 double MeasureGUI_FastCheckIntersectionsDlg::getTolerance()
691 {
692   double aVal = myTolerance->value();
693   if (!myDetGaps->isChecked() || aVal < 0.0)
694     return 0.0;
695   return aVal;
696 }