0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[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
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23#include <BRepAlgo_Tool.ixx>
24
25#include <TopTools_ListOfShape.hxx>
26#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
27#include <TopExp.hxx>
28#include <BRep_Builder.hxx>
29#include <BRep_Tool.hxx>
30#include <TopoDS.hxx>
31#include <TopoDS_Iterator.hxx>
32#include <TopoDS_Edge.hxx>
33
34
b311480e 35
7fd59977 36
37//=======================================================================
38//function : Deboucle3D
39//purpose :
40//=======================================================================
41
42TopoDS_Shape BRepAlgo_Tool::Deboucle3D(const TopoDS_Shape& S,
43 const TopTools_MapOfShape& Boundary)
44{
45 TopoDS_Shape SS;
46
47 switch ( S.ShapeType()) {
48 case TopAbs_FACE:
49 {
50 }
51 break;
52 case TopAbs_SHELL:
53 {
0d969553
Y
54 // if the shell contains free borders that do not belong to the
55 // free borders of caps ( Boundary) it is removed.
7fd59977 56 TopTools_IndexedDataMapOfShapeListOfShape Map;
57 TopExp::MapShapesAndAncestors(S,TopAbs_EDGE,TopAbs_FACE,Map);
58
59 Standard_Boolean JeGarde = Standard_True;
60 for ( Standard_Integer i = 1; i <= Map.Extent() && JeGarde; i++) {
61 if (Map(i).Extent() < 2) {
62 const TopoDS_Edge& anEdge = TopoDS::Edge(Map.FindKey(i));
63 if (!Boundary.Contains(anEdge) &&
64 !BRep_Tool::Degenerated(anEdge) )
65 JeGarde = Standard_False;
66 }
67 }
68 if ( JeGarde) SS = S;
69 }
70 break;
71 case TopAbs_COMPOUND:
72 case TopAbs_SOLID:
73 {
0d969553 74 // iterate on sub-shapes and add non-empty.
7fd59977 75 TopoDS_Iterator it(S);
76 TopoDS_Shape SubShape;
77 Standard_Boolean NbSub = 0;
78 BRep_Builder B;
79 if (S.ShapeType() == TopAbs_COMPOUND) {
80 B.MakeCompound(TopoDS::Compound(SS));
81 }
82 else {
83 B.MakeSolid(TopoDS::Solid(SS));
84 }
85 for ( ; it.More(); it.Next()) {
86 const TopoDS_Shape& CurS = it.Value();
87 SubShape = Deboucle3D(CurS,Boundary);
88 if ( !SubShape.IsNull()) {
89 B.Add(SS, SubShape);
90 NbSub++;
91 }
92 }
ab87e6fc 93 if (NbSub == 0)
94 {
95#ifdef DEB
96 cout << "No subhape in shape!" << endl;
97#endif
98 SS = TopoDS_Shape();
99 }
7fd59977 100 }
101 break;
102 default:
103 break;
104 }
105 return SS;
106}