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