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