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