1cedf308fc3b5479b582467d22ac0c85bffc3b54
[occt.git] / src / BRepAlgo / BRepAlgo_Tool.cxx
1 // Created on: 1995-10-23
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <BRep_Builder.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepAlgo_Tool.hxx>
21 #include <TopExp.hxx>
22 #include <TopoDS.hxx>
23 #include <TopoDS_Edge.hxx>
24 #include <TopoDS_Iterator.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
27 #include <TopTools_ListOfShape.hxx>
28
29 //=======================================================================
30 //function : Deboucle3D
31 //purpose  : 
32 //=======================================================================
33 TopoDS_Shape BRepAlgo_Tool::Deboucle3D(const TopoDS_Shape& S,
34                                        const TopTools_MapOfShape& Boundary)
35 {
36   TopoDS_Shape SS;
37
38   switch ( S.ShapeType()) {
39   case TopAbs_FACE:
40     {
41     }
42     break;
43   case TopAbs_SHELL: 
44     {
45       // if the shell contains free borders that do not belong to the 
46       // free borders of caps ( Boundary) it is removed.
47       TopTools_IndexedDataMapOfShapeListOfShape Map;
48       TopExp::MapShapesAndAncestors(S,TopAbs_EDGE,TopAbs_FACE,Map);
49       
50       Standard_Boolean JeGarde = Standard_True;
51       for ( Standard_Integer i = 1; i <= Map.Extent() && JeGarde; i++) {
52         const TopTools_ListOfShape& aLF = Map(i);
53         if (aLF.Extent() < 2) {
54           const TopoDS_Edge& anEdge = TopoDS::Edge(Map.FindKey(i));
55           if (anEdge.Orientation() == TopAbs_INTERNAL) {
56             const TopoDS_Face& aFace = TopoDS::Face(aLF.First());
57             if (aFace.Orientation() != TopAbs_INTERNAL) {
58               continue;
59             }
60           }
61           if (!Boundary.Contains(anEdge)  && 
62               !BRep_Tool::Degenerated(anEdge) )
63             JeGarde = Standard_False;
64         }
65       }
66       if ( JeGarde) SS = S;
67     }
68     break;
69   case TopAbs_COMPOUND:  
70   case TopAbs_SOLID:
71     {
72       // iterate on sub-shapes and add non-empty.
73       TopoDS_Iterator it(S);
74       TopoDS_Shape SubShape;
75       Standard_Boolean NbSub = 0;
76       BRep_Builder B;
77       if (S.ShapeType() == TopAbs_COMPOUND) {
78         B.MakeCompound(TopoDS::Compound(SS));
79       }
80       else {
81         B.MakeSolid(TopoDS::Solid(SS));
82       }
83       for ( ; it.More(); it.Next()) {
84         const TopoDS_Shape& CurS = it.Value();
85         SubShape = Deboucle3D(CurS,Boundary);
86         if ( !SubShape.IsNull()) {
87           B.Add(SS, SubShape);
88           NbSub++;
89         }
90       }
91       if (NbSub == 0)
92         {
93 #ifdef OCCT_DEBUG
94         cout << "No subhape in shape!" << endl;
95 #endif
96         SS = TopoDS_Shape();
97         }
98     }
99     break;
100   default:
101     break;
102   }
103   return SS;
104 }