0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / BRepAlgo / BRepAlgo_Tool.cxx
CommitLineData
b311480e 1// Created on: 1995-10-23
2// Created by: Yves FRICAUD
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
7fd59977 18#include <BRep_Builder.hxx>
19#include <BRep_Tool.hxx>
42cf5bc1 20#include <BRepAlgo_Tool.hxx>
21#include <TopExp.hxx>
7fd59977 22#include <TopoDS.hxx>
7fd59977 23#include <TopoDS_Edge.hxx>
42cf5bc1 24#include <TopoDS_Iterator.hxx>
25#include <TopoDS_Shape.hxx>
26#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
27#include <TopTools_ListOfShape.hxx>
7fd59977 28
29//=======================================================================
30//function : Deboucle3D
31//purpose :
32//=======================================================================
7fd59977 33TopoDS_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 {
0d969553
Y
45 // if the shell contains free borders that do not belong to the
46 // free borders of caps ( Boundary) it is removed.
7fd59977 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 if (Map(i).Extent() < 2) {
53 const TopoDS_Edge& anEdge = TopoDS::Edge(Map.FindKey(i));
54 if (!Boundary.Contains(anEdge) &&
55 !BRep_Tool::Degenerated(anEdge) )
56 JeGarde = Standard_False;
57 }
58 }
59 if ( JeGarde) SS = S;
60 }
61 break;
62 case TopAbs_COMPOUND:
63 case TopAbs_SOLID:
64 {
0d969553 65 // iterate on sub-shapes and add non-empty.
7fd59977 66 TopoDS_Iterator it(S);
67 TopoDS_Shape SubShape;
68 Standard_Boolean NbSub = 0;
69 BRep_Builder B;
70 if (S.ShapeType() == TopAbs_COMPOUND) {
71 B.MakeCompound(TopoDS::Compound(SS));
72 }
73 else {
74 B.MakeSolid(TopoDS::Solid(SS));
75 }
76 for ( ; it.More(); it.Next()) {
77 const TopoDS_Shape& CurS = it.Value();
78 SubShape = Deboucle3D(CurS,Boundary);
79 if ( !SubShape.IsNull()) {
80 B.Add(SS, SubShape);
81 NbSub++;
82 }
83 }
ab87e6fc 84 if (NbSub == 0)
85 {
0797d9d3 86#ifdef OCCT_DEBUG
ab87e6fc 87 cout << "No subhape in shape!" << endl;
88#endif
89 SS = TopoDS_Shape();
90 }
7fd59977 91 }
92 break;
93 default:
94 break;
95 }
96 return SS;
97}