Salome HOME
Porting to OCCT dev version: update version 0x07010000 -> 0x07010001
[modules/geom.git] / src / GEOMImpl / GEOMImpl_BooleanDriver.cxx
1 // Copyright (C) 2007-2016  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 #include <GEOMImpl_BooleanDriver.hxx>
24 #include <GEOMImpl_IBoolean.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOMImpl_GlueDriver.hxx>
27 #include <GEOM_Function.hxx>
28 #include <GEOMUtils.hxx>
29 #include <BlockFix_BlockFixAPI.hxx>
30 #include <ShHealOper_ShapeProcess.hxx>
31
32 #include <TNaming_CopyShape.hxx>
33
34 #include <BRep_Builder.hxx>
35 #include <BRepAlgoAPI_Common.hxx>
36 #include <BRepAlgoAPI_Cut.hxx>
37 #include <BRepAlgoAPI_Fuse.hxx>
38 #include <BRepAlgoAPI_Section.hxx>
39 #include <BOPAlgo_CheckerSI.hxx>
40 #include <BOPDS_DS.hxx>
41 #include <BOPTools_AlgoTools.hxx>
42
43 #include <TopExp_Explorer.hxx>
44 #include <TopoDS_Compound.hxx>
45 #include <TopoDS_Iterator.hxx>
46 #include <TopTools_MapOfShape.hxx>
47 #include <TopTools_ListOfShape.hxx>
48 #include <TopTools_ListIteratorOfListOfShape.hxx>
49
50 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
51
52 #include <Precision.hxx>
53
54 #include <Standard_ConstructionError.hxx>
55 #include <StdFail_NotDone.hxx>
56
57 // Depth of self-intersection check (see BOPAlgo_CheckerSI::SetLevelOfCheck() for more details)
58 // Default value for BOPAlgo_CheckerSI gives very long computation when checking face-to-face intersections;
59 // here check level is decreased to more appropriate value to avoid problems with performance).
60 #define BOP_SELF_INTERSECTIONS_LEVEL 4
61
62 /**
63  * This function performs extra edges removal.
64  *
65  * \param theShape the shape to be processed.
66  * \return the modified shape or null shape in case of failure.
67  */
68 static TopoDS_Shape RemoveExtraEdges(const TopoDS_Shape &theShape)
69 {
70   TopoDS_Shape aResult;
71
72   if (!theShape.IsNull()) {
73     BlockFix_BlockFixAPI aTool;
74
75     aTool.OptimumNbFaces() = 0;
76     aTool.SetShape(theShape);
77     aTool.Perform();
78     TopoDS_Shape aShape = aTool.Shape();
79
80     if (GEOMUtils::CheckShape(aShape)) {
81       aResult = aShape;
82     }
83     else {
84       TopoDS_Shape aFixed;
85       ShHealOper_ShapeProcess aHealer;
86       aHealer.Perform(aShape, aFixed);
87       if (aHealer.isDone() && GEOMUtils::CheckShape(aFixed))
88         aResult = aFixed;
89     }
90   }
91
92   return aResult;
93 }
94
95 //=======================================================================
96 //function : GetID
97 //purpose  :
98 //=======================================================================
99 const Standard_GUID& GEOMImpl_BooleanDriver::GetID()
100 {
101   static Standard_GUID aBooleanDriver("FF1BBB21-5D14-4df2-980B-3A668264EA16");
102   return aBooleanDriver;
103 }
104
105 //=======================================================================
106 //function : GEOMImpl_BooleanDriver
107 //purpose  :
108 //=======================================================================
109 GEOMImpl_BooleanDriver::GEOMImpl_BooleanDriver()
110 {
111 }
112
113 //=======================================================================
114 //function : Execute
115 //purpose  :
116 //=======================================================================
117 Standard_Integer GEOMImpl_BooleanDriver::Execute(LOGBOOK& log) const
118 {
119   if (Label().IsNull()) return 0;
120   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
121
122   GEOMImpl_IBoolean aCI (aFunction);
123   Standard_Integer aType = aFunction->GetType();
124   const Standard_Boolean isCheckSelfInte = aCI.GetCheckSelfIntersection();
125   const Standard_Boolean isRmExtraEdges  = aCI.GetRmExtraEdges();
126
127   TopoDS_Shape aShape;
128
129   switch (aType) {
130   case BOOLEAN_COMMON:
131   case BOOLEAN_CUT:
132   case BOOLEAN_FUSE:
133   case BOOLEAN_SECTION:
134     {
135       Handle(GEOM_Function) aRefShape1 = aCI.GetShape1();
136       Handle(GEOM_Function) aRefShape2 = aCI.GetShape2();
137       TopoDS_Shape aShape1 = aRefShape1->GetValue();
138       TopoDS_Shape aShape2 = aRefShape2->GetValue();
139
140       if (!aShape1.IsNull() && !aShape2.IsNull()) {
141         // check arguments for Mantis issue 0021019
142         if (!GEOMUtils::CheckShape(aShape1, true) || !GEOMUtils::CheckShape(aShape2, true))
143           StdFail_NotDone::Raise("Boolean operation will not be performed, because argument shape is not valid");
144
145         if (isCheckSelfInte) {
146           BOPAlgo_CheckerSI aCSI;  // checker of self-interferences
147           aCSI.SetLevelOfCheck(BOP_SELF_INTERSECTIONS_LEVEL);
148           BOPCol_ListOfShape aList1, aList2;
149           aList1.Append(aShape1);
150           aList2.Append(aShape2);
151           aCSI.SetArguments(aList1);
152           aCSI.Perform();
153 #if OCC_VERSION_LARGE > 0x07010001
154           if (aCSI.HasErrors() || aCSI.DS().Interferences().Extent() > 0)
155 #else
156           if (aCSI.ErrorStatus() || aCSI.DS().Interferences().Extent() > 0)
157 #endif
158             StdFail_NotDone::Raise("Boolean operation will not be performed, because argument shape is self-intersected");
159           aCSI.SetArguments(aList2);
160           aCSI.Perform();
161 #if OCC_VERSION_LARGE > 0x07010001
162           if (aCSI.HasErrors() || aCSI.DS().Interferences().Extent() > 0)
163 #else
164           if (aCSI.ErrorStatus() || aCSI.DS().Interferences().Extent() > 0)
165 #endif
166             StdFail_NotDone::Raise("Boolean operation will not be performed, because argument shape is self-intersected");
167         }
168
169         // Make a copy to prevent the original shape changes.
170         TopoDS_Shape aShapeCopy1;
171         TopoDS_Shape aShapeCopy2;
172         TColStd_IndexedDataMapOfTransientTransient aMapTShapes;
173         TNaming_CopyShape::CopyTool(aShape1, aMapTShapes, aShapeCopy1);
174         TNaming_CopyShape::CopyTool(aShape2, aMapTShapes, aShapeCopy2);
175
176         aShape = performOperation (aShapeCopy1, aShapeCopy2, aType);
177
178         if (isRmExtraEdges) {
179           aShape = RemoveExtraEdges(aShape);
180         }
181
182         if (aShape.IsNull()) {
183           return 0;
184         }
185       }
186     }
187     break;
188   case BOOLEAN_COMMON_LIST:
189   case BOOLEAN_FUSE_LIST:
190     {
191       Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
192       const Standard_Integer nbShapes = aShapes->Length();
193       Standard_Integer i;
194       Handle(GEOM_Function) aRefShape;
195       TopoDS_Shape aShape2;
196       Standard_Integer aSimpleType =
197         (aType == BOOLEAN_FUSE_LIST ? BOOLEAN_FUSE : BOOLEAN_COMMON);
198
199       if (nbShapes > 0) {
200         aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(1));
201         aShape = aRefShape->GetValue();
202
203         if (!aShape.IsNull()) {
204           // check arguments for Mantis issue 0021019
205           if (!GEOMUtils::CheckShape(aShape, true))
206             StdFail_NotDone::Raise("Boolean operation will not be performed, because argument shape is not valid");
207
208           BOPAlgo_CheckerSI aCSI;  // checker of self-interferences
209
210           if (isCheckSelfInte) {
211             aCSI.SetLevelOfCheck(BOP_SELF_INTERSECTIONS_LEVEL);
212             BOPCol_ListOfShape aList1;
213             aList1.Append(aShape);
214             aCSI.SetArguments(aList1);
215             aCSI.Perform();
216 #if OCC_VERSION_LARGE > 0x07010001
217             if (aCSI.HasErrors() || aCSI.DS().Interferences().Extent() > 0) {
218 #else
219             if (aCSI.ErrorStatus() || aCSI.DS().Interferences().Extent() > 0) {
220 #endif
221               StdFail_NotDone::Raise("Boolean operation will not be performed, because argument shape is self-intersected");
222             }
223           }
224
225           // Copy shape
226           TopoDS_Shape aShapeCopy;
227           TColStd_IndexedDataMapOfTransientTransient aMapTShapes;
228
229           TNaming_CopyShape::CopyTool(aShape, aMapTShapes, aShapeCopy);
230           aShape = aShapeCopy;
231
232           for (i = 2; i <= nbShapes; i++) {
233             aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(i));
234             aShape2 = aRefShape->GetValue();
235
236             if (!GEOMUtils::CheckShape(aShape2, true))
237               StdFail_NotDone::Raise("Boolean operation will not be performed, because argument shape is not valid");
238
239             if (isCheckSelfInte) {
240               BOPCol_ListOfShape aList2;
241               aList2.Append(aShape2);
242               aCSI.SetArguments(aList2);
243               aCSI.Perform();
244 #if OCC_VERSION_LARGE > 0x07010001
245               if (aCSI.HasErrors() || aCSI.DS().Interferences().Extent() > 0) {
246 #else
247               if (aCSI.ErrorStatus() || aCSI.DS().Interferences().Extent() > 0) {
248 #endif
249                 StdFail_NotDone::Raise("Boolean operation will not be performed, because argument shape is self-intersected");
250               }
251             }
252
253             // Copy shape
254             aShapeCopy.Nullify();
255             TNaming_CopyShape::CopyTool(aShape2, aMapTShapes, aShapeCopy);
256             aShape = performOperation (aShape, aShapeCopy, aSimpleType);
257
258             if (isRmExtraEdges) {
259               aShape = RemoveExtraEdges(aShape);
260             }
261
262             if (aShape.IsNull()) {
263               return 0;
264             }
265           }
266         }
267       }
268     }
269     break;
270   case BOOLEAN_CUT_LIST:
271     {
272       Handle(GEOM_Function) aRefObject = aCI.GetShape1();
273
274       aShape = aRefObject->GetValue();
275
276       if (!aShape.IsNull()) {
277         // check arguments for Mantis issue 0021019
278         if (!GEOMUtils::CheckShape(aShape, true))
279           StdFail_NotDone::Raise("Boolean operation will not be performed, because argument shape is not valid");
280
281         BOPAlgo_CheckerSI aCSI;  // checker of self-interferences
282
283         if (isCheckSelfInte) {
284           aCSI.SetLevelOfCheck(BOP_SELF_INTERSECTIONS_LEVEL);
285           BOPCol_ListOfShape aList1;
286           aList1.Append(aShape);
287           aCSI.SetArguments(aList1);
288           aCSI.Perform();
289 #if OCC_VERSION_LARGE > 0x07010001
290           if (aCSI.HasErrors() || aCSI.DS().Interferences().Extent() > 0) {
291 #else
292           if (aCSI.ErrorStatus() || aCSI.DS().Interferences().Extent() > 0) {
293 #endif
294             StdFail_NotDone::Raise("Boolean operation will not be performed, because argument shape is self-intersected");
295           }
296         }
297
298         // Copy shape
299         TopoDS_Shape aShapeCopy;
300         TColStd_IndexedDataMapOfTransientTransient aMapTShapes;
301
302         TNaming_CopyShape::CopyTool(aShape, aMapTShapes, aShapeCopy);
303         aShape = aShapeCopy;
304
305         Handle(TColStd_HSequenceOfTransient) aTools = aCI.GetShapes();
306         const Standard_Integer nbShapes = aTools->Length();
307         Standard_Integer i;
308         Handle(GEOM_Function) aRefTool;
309         TopoDS_Shape aTool;
310
311         for (i = 1; i <= nbShapes; i++) {
312           aRefTool = Handle(GEOM_Function)::DownCast(aTools->Value(i));
313           aTool = aRefTool->GetValue();
314
315           if (!GEOMUtils::CheckShape(aTool, true))
316             StdFail_NotDone::Raise("Boolean operation will not be performed, because argument shape is not valid");
317
318           if (isCheckSelfInte) {
319             BOPCol_ListOfShape aList2;
320             aList2.Append(aTool);
321             aCSI.SetArguments(aList2);
322             aCSI.Perform();
323 #if OCC_VERSION_LARGE > 0x07010001
324             if (aCSI.HasErrors() || aCSI.DS().Interferences().Extent() > 0) {
325 #else
326             if (aCSI.ErrorStatus() || aCSI.DS().Interferences().Extent() > 0) {
327 #endif
328               StdFail_NotDone::Raise("Boolean operation will not be performed, because argument shape is self-intersected");
329             }
330           }
331
332           // Copy shape
333           aShapeCopy.Nullify();
334           TNaming_CopyShape::CopyTool(aTool, aMapTShapes, aShapeCopy);
335           aShape = performOperation (aShape, aShapeCopy, BOOLEAN_CUT);
336
337           if (aShape.IsNull()) {
338             return 0;
339           }
340         }
341       }
342     }
343     break;
344   default:
345     break;
346   }
347
348   aFunction->SetValue(aShape);
349
350 #if OCC_VERSION_MAJOR < 7
351   log.SetTouched(Label());
352 #else
353   log->SetTouched(Label());
354 #endif
355
356   return 1;
357 }
358
359 //=======================================================================
360 //function : makeCompoundShellFromFaces
361 //purpose  :
362 //=======================================================================
363 TopoDS_Shape GEOMImpl_BooleanDriver::makeCompoundShellFromFaces
364                                (const TopoDS_Shape theShape)const
365 {
366   if (theShape.ShapeType() != TopAbs_COMPOUND)
367     return theShape;
368
369   BRep_Builder B;
370   TopoDS_Compound aFaces;
371   B.MakeCompound(aFaces);
372
373   // simplify compound structure for
374   // Mantis issue 0023419 (note 0021712)
375   TopExp_Explorer aExp;
376   TopTools_MapOfShape aMapFaces;
377   aExp.Init(theShape, TopAbs_FACE);
378   for (; aExp.More(); aExp.Next()) {
379     const TopoDS_Shape& aFace = aExp.Current();
380     if (aMapFaces.Add(aFace)) {
381       B.Add(aFaces, aFace);
382     }
383   }
384
385   BOPCol_ListOfShape aListShapes;
386   BOPTools_AlgoTools::MakeConnexityBlocks(aFaces, TopAbs_EDGE, TopAbs_FACE, aListShapes);
387
388   if (aListShapes.IsEmpty())
389     return theShape;
390
391   TopoDS_Compound aResult;
392   B.MakeCompound(aResult);
393   BOPCol_ListIteratorOfListOfShape anIter(aListShapes);
394
395   for (; anIter.More(); anIter.Next()) {
396     TopoDS_Shell aShell;
397     B.MakeShell(aShell);
398     TopoDS_Shape aShapeFromFaces = anIter.Value();
399     aExp.Init(aShapeFromFaces, TopAbs_FACE);
400     for (; aExp.More(); aExp.Next()) {
401       const TopoDS_Shape& aFace = aExp.Current();
402       B.Add(aShell, aFace);
403     }
404     if (!aShell.IsNull()) {
405       BOPTools_AlgoTools::OrientFacesOnShell(aShell);
406       B.Add(aResult, aShell);
407     }
408     else
409       B.Add(aResult, aShapeFromFaces);
410   }
411
412   return aResult;
413 }
414
415 //=======================================================================
416 //function : performOperation
417 //purpose  :
418 //=======================================================================
419 TopoDS_Shape GEOMImpl_BooleanDriver::performOperation
420                                (const TopoDS_Shape theShape1,
421                                 const TopoDS_Shape theShape2,
422                                 const Standard_Integer theType)const
423 {
424   TopoDS_Shape aShape;
425
426   // perform COMMON operation
427   if (theType == BOOLEAN_COMMON) {
428     BRep_Builder B;
429     TopoDS_Compound C;
430     B.MakeCompound(C);
431
432     TopTools_ListOfShape listShape1, listShape2;
433     GEOMUtils::AddSimpleShapes(theShape1, listShape1);
434     GEOMUtils::AddSimpleShapes(theShape2, listShape2);
435
436     Standard_Boolean isCompound =
437       (listShape1.Extent() > 1 || listShape2.Extent() > 1);
438
439     TopTools_ListIteratorOfListOfShape itSub1 (listShape1);
440     for (; itSub1.More(); itSub1.Next()) {
441       TopoDS_Shape aValue1 = itSub1.Value();
442       TopTools_ListIteratorOfListOfShape itSub2 (listShape2);
443       for (; itSub2.More(); itSub2.Next()) {
444         TopoDS_Shape aValue2 = itSub2.Value();
445         BRepAlgoAPI_Common BO (aValue1, aValue2);
446         if (!BO.IsDone()) {
447           StdFail_NotDone::Raise("Common operation can not be performed on the given shapes");
448         }
449         if (isCompound) {
450           TopoDS_Shape aStepResult = BO.Shape();
451
452           // check result of this step: if it is a compound (boolean operations
453           // allways return a compound), we add all sub-shapes of it.
454           // This allows to avoid adding empty compounds,
455           // resulting from COMMON on two non-intersecting shapes.
456           if (aStepResult.ShapeType() == TopAbs_COMPOUND) {
457 #if OCC_VERSION_MAJOR >= 7
458             if ((aValue1.ShapeType() == TopAbs_FACE || aValue1.ShapeType() == TopAbs_SHELL) &&
459                 (aValue2.ShapeType() == TopAbs_FACE || aValue2.ShapeType() == TopAbs_SHELL)) {
460               aStepResult = makeCompoundShellFromFaces(aStepResult);
461             }
462 #endif
463             TopoDS_Iterator aCompIter (aStepResult);
464             for (; aCompIter.More(); aCompIter.Next()) {
465               // add shape in a result
466               B.Add(C, aCompIter.Value());
467             }
468           }
469           else {
470             // add shape in a result
471             B.Add(C, aStepResult);
472           }
473         }
474         else
475           aShape = BO.Shape();
476       }
477     }
478
479     if (isCompound) {
480       // As GlueFaces has been improved to keep all kind of shapes
481       TopExp_Explorer anExp (C, TopAbs_VERTEX);
482       if (anExp.More())
483         aShape = GEOMImpl_GlueDriver::GlueFaces(C, Precision::Confusion(), Standard_True);
484       else
485         aShape = C;
486     }
487   }
488
489   // perform CUT operation
490   else if (theType == BOOLEAN_CUT) {
491     BRep_Builder B;
492     TopoDS_Compound C;
493     B.MakeCompound(C);
494
495     TopTools_ListOfShape listShapes, listTools;
496     GEOMUtils::AddSimpleShapes(theShape1, listShapes);
497     GEOMUtils::AddSimpleShapes(theShape2, listTools);
498
499     Standard_Boolean isCompound = (listShapes.Extent() > 1);
500
501     TopTools_ListIteratorOfListOfShape itSub1 (listShapes);
502     for (; itSub1.More(); itSub1.Next()) {
503       TopoDS_Shape aCut = itSub1.Value();
504       // tools
505       TopTools_ListIteratorOfListOfShape itSub2 (listTools);
506       for (; itSub2.More(); itSub2.Next()) {
507         TopoDS_Shape aTool = itSub2.Value();
508         BRepAlgoAPI_Cut BO (aCut, aTool);
509         if (!BO.IsDone()) {
510           StdFail_NotDone::Raise("Cut operation can not be performed on the given shapes");
511         }
512         aCut = BO.Shape();
513       }
514       if (isCompound) {
515         // check result of this step: if it is a compound (boolean operations
516         // allways return a compound), we add all sub-shapes of it.
517         // This allows to avoid adding empty compounds,
518         // resulting from CUT of parts
519         if (aCut.ShapeType() == TopAbs_COMPOUND) {
520 #if OCC_VERSION_MAJOR >= 7
521           if (itSub1.Value().ShapeType() == TopAbs_FACE ||
522               itSub1.Value().ShapeType() == TopAbs_SHELL) {
523             aCut = makeCompoundShellFromFaces(aCut);
524           }
525 #endif
526           TopoDS_Iterator aCompIter (aCut);
527           for (; aCompIter.More(); aCompIter.Next()) {
528             // add shape in a result
529             B.Add(C, aCompIter.Value());
530           }
531         }
532         else {
533           // add shape in a result
534           B.Add(C, aCut);
535         }
536       }
537       else
538         aShape = aCut;
539     }
540
541     if (isCompound) {
542       // As GlueFaces has been improved to keep all kind of shapes
543       TopExp_Explorer anExp (C, TopAbs_VERTEX);
544       if (anExp.More())
545         aShape = GEOMImpl_GlueDriver::GlueFaces(C, Precision::Confusion(), Standard_True);
546       else
547         aShape = C;
548     }
549   }
550
551   // perform FUSE operation
552   else if (theType == BOOLEAN_FUSE) {
553 #if OCC_VERSION_MAJOR >= 7
554     Standard_Boolean isFaces = Standard_False;
555     TopTools_ListOfShape listShape1, listShape2;
556     GEOMUtils::AddSimpleShapes(theShape1, listShape1);
557     GEOMUtils::AddSimpleShapes(theShape2, listShape2);
558
559     TopTools_ListIteratorOfListOfShape itSub1 (listShape1);
560     for (; itSub1.More(); itSub1.Next()) {
561       TopoDS_Shape aValue1 = itSub1.Value();
562       TopTools_ListIteratorOfListOfShape itSub2 (listShape2);
563       for (; itSub2.More(); itSub2.Next()) {
564         TopoDS_Shape aValue2 = itSub2.Value();
565         if ((aValue1.ShapeType() == TopAbs_FACE || aValue1.ShapeType() == TopAbs_SHELL) &&
566             (aValue2.ShapeType() == TopAbs_FACE || aValue2.ShapeType() == TopAbs_SHELL)) {
567           isFaces = Standard_True;
568         }
569       }
570     }
571 #endif
572
573     // Perform
574     BRepAlgoAPI_Fuse BO (theShape1, theShape2);
575     if (!BO.IsDone()) {
576       StdFail_NotDone::Raise("Fuse operation can not be performed on the given shapes");
577     }
578     aShape = BO.Shape();
579 #if OCC_VERSION_MAJOR >= 7
580     if (isFaces)
581       aShape = makeCompoundShellFromFaces(aShape);
582 #endif
583   }
584
585   // perform SECTION operation
586   else if (theType == BOOLEAN_SECTION) {
587     BRep_Builder B;
588     TopoDS_Compound C;
589     B.MakeCompound(C);
590
591     TopTools_ListOfShape listShape1, listShape2;
592     GEOMUtils::AddSimpleShapes(theShape1, listShape1);
593     GEOMUtils::AddSimpleShapes(theShape2, listShape2);
594
595     Standard_Boolean isCompound =
596       (listShape1.Extent() > 1 || listShape2.Extent() > 1);
597
598     TopTools_ListIteratorOfListOfShape itSub1 (listShape1);
599     for (; itSub1.More(); itSub1.Next()) {
600       TopoDS_Shape aValue1 = itSub1.Value();
601       TopTools_ListIteratorOfListOfShape itSub2 (listShape2);
602       for (; itSub2.More(); itSub2.Next()) {
603         TopoDS_Shape aValue2 = itSub2.Value();
604         BRepAlgoAPI_Section BO (aValue1, aValue2, Standard_False);
605         // Set approximation to have an attached 3D BSpline geometry to each edge,
606         // where analytic curve is not possible. Without this flag in some cases
607         // we obtain BSpline curve of degree 1 (C0), which is slowly
608         // processed by some algorithms (Partition for example).
609         BO.Approximation(Standard_True);
610         //modified by NIZNHY-PKV Tue Oct 18 14:34:16 2011f
611         BO.ComputePCurveOn1(Standard_True);
612         BO.ComputePCurveOn2(Standard_True);
613         //modified by NIZNHY-PKV Tue Oct 18 14:34:18 2011t
614
615         BO.Build();
616         if (!BO.IsDone()) {
617           StdFail_NotDone::Raise("Section operation can not be performed on the given shapes");
618         }
619         if (isCompound) {
620           TopoDS_Shape aStepResult = BO.Shape();
621
622           // check result of this step: if it is a compound (boolean operations
623           // allways return a compound), we add all sub-shapes of it.
624           // This allows to avoid adding empty compounds,
625           // resulting from SECTION on two non-intersecting shapes.
626           if (aStepResult.ShapeType() == TopAbs_COMPOUND) {
627             TopoDS_Iterator aCompIter (aStepResult);
628             for (; aCompIter.More(); aCompIter.Next()) {
629               // add shape in a result
630               B.Add(C, aCompIter.Value());
631             }
632           }
633           else {
634             // add shape in a result
635             B.Add(C, aStepResult);
636           }
637         }
638         else
639           aShape = BO.Shape();
640       }
641     }
642
643     if (isCompound) {
644       // As GlueFaces has been improved to keep all kind of shapes
645       TopExp_Explorer anExp (C, TopAbs_VERTEX);
646       if (anExp.More())
647         aShape = GEOMImpl_GlueDriver::GlueFaces(C, Precision::Confusion(), Standard_True);
648       else
649         aShape = C;
650     }
651   }
652
653   // UNKNOWN operation
654   else {
655   }
656
657   if (aShape.IsNull()) return aShape;
658
659   // as boolean operations always produce compound, lets simplify it
660   // for the case, if it contains only one sub-shape
661   TopTools_ListOfShape listShapeRes;
662   GEOMUtils::AddSimpleShapes(aShape, listShapeRes);
663   if (listShapeRes.Extent() == 1) {
664     aShape = listShapeRes.First();
665     if (aShape.IsNull()) return aShape;
666   }
667
668   // 08.07.2008 skl for bug 19761 from Mantis
669   if ( !GEOMUtils::CheckShape(aShape, true) && !GEOMUtils::FixShapeTolerance(aShape) )
670     Standard_ConstructionError::Raise("Boolean operation aborted : non valid shape result");
671
672   return aShape;
673 }
674
675 //================================================================================
676 /*!
677  * \brief Returns a name of creation operation and names and values of creation parameters
678  */
679 //================================================================================
680
681 bool GEOMImpl_BooleanDriver::
682 GetCreationInformation(std::string&             theOperationName,
683                        std::vector<GEOM_Param>& theParams)
684 {
685   if (Label().IsNull()) return 0;
686   Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
687
688   GEOMImpl_IBoolean aCI (function);
689   Standard_Integer aType = function->GetType();
690   Standard_Boolean isCheckSelfInte = aCI.GetCheckSelfIntersection();
691
692   switch ( aType ) {
693   case BOOLEAN_COMMON:
694     theOperationName = "COMMON";
695     AddParam( theParams, "Object 1", aCI.GetShape1() );
696     AddParam( theParams, "Object 2", aCI.GetShape2() );
697     AddParam( theParams, "Check self-intersections", isCheckSelfInte );
698     break;
699   case BOOLEAN_CUT:
700     theOperationName = "CUT";
701     AddParam( theParams, "Main Object", aCI.GetShape1() );
702     AddParam( theParams, "Tool Object", aCI.GetShape2() );
703     AddParam( theParams, "Check self-intersections", isCheckSelfInte );
704     break;
705   case BOOLEAN_FUSE:
706     theOperationName = "FUSE";
707     AddParam( theParams, "Object 1", aCI.GetShape1() );
708     AddParam( theParams, "Object 2", aCI.GetShape2() );
709     AddParam( theParams, "Check self-intersections", isCheckSelfInte );
710     AddParam( theParams, "Remove extra edges", aCI.GetRmExtraEdges() );
711     break;
712   case BOOLEAN_SECTION:
713     theOperationName = "SECTION";
714     AddParam( theParams, "Object 1", aCI.GetShape1() );
715     AddParam( theParams, "Object 2", aCI.GetShape2() );
716     AddParam( theParams, "Check self-intersections", isCheckSelfInte );
717     break;
718   case BOOLEAN_COMMON_LIST:
719     theOperationName = "COMMON";
720     AddParam( theParams, "Selected objects", aCI.GetShapes() );
721     AddParam( theParams, "Check self-intersections", isCheckSelfInte );
722     break;
723   case BOOLEAN_FUSE_LIST:
724     theOperationName = "FUSE";
725     AddParam( theParams, "Selected objects", aCI.GetShapes() );
726     AddParam( theParams, "Check self-intersections", isCheckSelfInte );
727     AddParam( theParams, "Remove extra edges", aCI.GetRmExtraEdges() );
728     break;
729   case BOOLEAN_CUT_LIST:
730     theOperationName = "CUT";
731     AddParam( theParams, "Main Object", aCI.GetShape1() );
732     AddParam( theParams, "Tool Objects", aCI.GetShapes() );
733     AddParam( theParams, "Check self-intersections", isCheckSelfInte );
734     break;
735   default:
736     return false;
737   }
738
739   return true;
740 }
741
742 OCCT_IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_BooleanDriver,GEOM_BaseDriver);