Integration of OCCT 6.5.0 from SVN
[occt.git] / src / BRepAlgo / BRepAlgo_Tool.cxx
CommitLineData
7fd59977 1// File: BRepAlgo_Tool.cxx
2// Created: Mon Oct 23 14:25:07 1995
3// Author: Yves FRICAUD
4// <yfr@stylox>
5
6
7#include <BRepAlgo_Tool.ixx>
8
9#include <TopTools_ListOfShape.hxx>
10#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
11#include <TopExp.hxx>
12#include <BRep_Builder.hxx>
13#include <BRep_Tool.hxx>
14#include <TopoDS.hxx>
15#include <TopoDS_Iterator.hxx>
16#include <TopoDS_Edge.hxx>
17
18
19
20
21//=======================================================================
22//function : Deboucle3D
23//purpose :
24//=======================================================================
25
26TopoDS_Shape BRepAlgo_Tool::Deboucle3D(const TopoDS_Shape& S,
27 const TopTools_MapOfShape& Boundary)
28{
29 TopoDS_Shape SS;
30
31 switch ( S.ShapeType()) {
32 case TopAbs_FACE:
33 {
34 }
35 break;
36 case TopAbs_SHELL:
37 {
38 // si le shell contient des bords libres qui n'appartiennent pas aux
39 // bord libres des bouchons ( Boundary) on l'enleve.
40 TopTools_IndexedDataMapOfShapeListOfShape Map;
41 TopExp::MapShapesAndAncestors(S,TopAbs_EDGE,TopAbs_FACE,Map);
42
43 Standard_Boolean JeGarde = Standard_True;
44 for ( Standard_Integer i = 1; i <= Map.Extent() && JeGarde; i++) {
45 if (Map(i).Extent() < 2) {
46 const TopoDS_Edge& anEdge = TopoDS::Edge(Map.FindKey(i));
47 if (!Boundary.Contains(anEdge) &&
48 !BRep_Tool::Degenerated(anEdge) )
49 JeGarde = Standard_False;
50 }
51 }
52 if ( JeGarde) SS = S;
53 }
54 break;
55 case TopAbs_COMPOUND:
56 case TopAbs_SOLID:
57 {
58 // on itere sur les sous-shape et on ajoute les non vides.
59 TopoDS_Iterator it(S);
60 TopoDS_Shape SubShape;
61 Standard_Boolean NbSub = 0;
62 BRep_Builder B;
63 if (S.ShapeType() == TopAbs_COMPOUND) {
64 B.MakeCompound(TopoDS::Compound(SS));
65 }
66 else {
67 B.MakeSolid(TopoDS::Solid(SS));
68 }
69 for ( ; it.More(); it.Next()) {
70 const TopoDS_Shape& CurS = it.Value();
71 SubShape = Deboucle3D(CurS,Boundary);
72 if ( !SubShape.IsNull()) {
73 B.Add(SS, SubShape);
74 NbSub++;
75 }
76 }
77 if (NbSub == 0) SS = TopoDS_Shape();
78 }
79 break;
80 default:
81 break;
82 }
83 return SS;
84}