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