0025202: Incorrect value of IsClosed flag in shapes produced by some algorithms
[occt.git] / src / BRepLib / BRepLib_MakeSolid.cxx
1 // Created on: 1995-01-04
2 // Created by: Bruno DUMORTIER
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 #include <BRepLib_MakeSolid.ixx>
18
19 #include <TopoDS.hxx>
20 #include <BRep_Builder.hxx>
21 #include <TopExp_Explorer.hxx>
22 #include <TopTools_MapOfShape.hxx>
23 #include <TopTools_MapIteratorOfMapOfShape.hxx>
24 #include <TopTools_ListIteratorOfListOfShape.hxx>
25
26 //=======================================================================
27 //function : BRepLib_MakeSolid
28 //purpose  : 
29 //=======================================================================
30
31 BRepLib_MakeSolid::BRepLib_MakeSolid()
32 {
33   BRep_Builder B;
34   B.MakeSolid(TopoDS::Solid(myShape));
35   Done();
36 }
37
38 //=======================================================================
39 //function : BRepLib_MakeSolid
40 //purpose  : 
41 //=======================================================================
42
43 BRepLib_MakeSolid::BRepLib_MakeSolid(const TopoDS_CompSolid& S)
44 {
45   BRep_Builder B;
46   B.MakeSolid(TopoDS::Solid(myShape));
47
48   TopExp_Explorer ex1, ex2;
49   TopTools_MapOfShape aMapOfFaces;
50   for (ex1.Init(S,TopAbs_SHELL); ex1.More(); ex1.Next()) {
51     for (ex2.Init(ex1.Current(),TopAbs_FACE); ex2.More(); ex2.Next()) {
52       if(!aMapOfFaces.Add(ex2.Current())) {
53         myDeletedFaces.Append(ex2.Current());
54         aMapOfFaces.Remove(ex2.Current());
55       }
56     }    
57   }
58
59   TopoDS_Shape aShell;
60   B.MakeShell(TopoDS::Shell(aShell));
61
62   TopTools_MapIteratorOfMapOfShape aFaceIter(aMapOfFaces);
63   for(; aFaceIter.More(); aFaceIter.Next()) {
64     B.Add(aShell, aFaceIter.Key());
65   }
66   aShell.Closed (BRep_Tool::IsClosed (aShell));
67
68   B.Add(myShape,aShell);
69
70   Done();
71 }
72
73
74 //=======================================================================
75 //function : BRepLib_MakeSolid
76 //purpose  : 
77 //=======================================================================
78
79 BRepLib_MakeSolid::BRepLib_MakeSolid(const TopoDS_Shell& S)
80 {
81   BRep_Builder B;
82   B.MakeSolid(TopoDS::Solid(myShape));
83   B.Add(myShape,S);
84   Done();
85 }
86
87
88 //=======================================================================
89 //function : BRepLib_MakeSolid
90 //purpose  : 
91 //=======================================================================
92
93 BRepLib_MakeSolid::BRepLib_MakeSolid(const TopoDS_Shell& S1, const TopoDS_Shell& S2)
94 {
95   BRep_Builder B;
96   B.MakeSolid(TopoDS::Solid(myShape));
97   B.Add(myShape,S1);
98   B.Add(myShape,S2);
99   Done();
100 }
101
102
103 //=======================================================================
104 //function : BRepLib_MakeSolid
105 //purpose  : 
106 //=======================================================================
107
108 BRepLib_MakeSolid::BRepLib_MakeSolid(const TopoDS_Shell& S1, const TopoDS_Shell& S2, const TopoDS_Shell& S3)
109 {
110   BRep_Builder B;
111   B.MakeSolid(TopoDS::Solid(myShape));
112   B.Add(myShape,S1);
113   B.Add(myShape,S2);
114   B.Add(myShape,S3);
115   Done();
116 }
117
118
119 //=======================================================================
120 //function : BRepLib_MakeSolid
121 //purpose  : 
122 //=======================================================================
123
124 BRepLib_MakeSolid::BRepLib_MakeSolid(const TopoDS_Solid& So)
125 {
126   BRep_Builder B;
127   B.MakeSolid(TopoDS::Solid(myShape));
128   TopExp_Explorer ex;
129   for (ex.Init(So,TopAbs_SHELL); ex.More(); ex.Next())
130     B.Add(myShape,ex.Current());
131   Done();
132 }
133
134
135 //=======================================================================
136 //function : BRepLib_MakeSolid
137 //purpose  : 
138 //=======================================================================
139
140 BRepLib_MakeSolid::BRepLib_MakeSolid(const TopoDS_Solid& So, const TopoDS_Shell& S)
141 {
142   BRep_Builder B;
143   B.MakeSolid(TopoDS::Solid(myShape));
144   TopExp_Explorer ex;
145   for (ex.Init(So,TopAbs_SHELL); ex.More(); ex.Next())
146     B.Add(myShape,ex.Current());
147   B.Add(myShape,S);
148   Done();
149 }
150
151
152 //=======================================================================
153 //function : Add
154 //purpose  : 
155 //=======================================================================
156
157 void  BRepLib_MakeSolid::Add(const TopoDS_Shell& S)
158 {
159   BRep_Builder B;
160   B.Add(myShape,S);
161 }
162
163
164 //=======================================================================
165 //function : Solid
166 //purpose  : 
167 //=======================================================================
168
169 const TopoDS_Solid&  BRepLib_MakeSolid::Solid()const 
170 {
171   return TopoDS::Solid(Shape());
172 }
173
174
175
176 //=======================================================================
177 //function : operator
178 //purpose  : 
179 //=======================================================================
180
181 BRepLib_MakeSolid::operator TopoDS_Solid() const
182 {
183   return TopoDS::Solid(Shape());
184 }
185
186 //=======================================================================
187 //function : FaceStatus
188 //purpose  : 
189 //=======================================================================
190
191 BRepLib_ShapeModification BRepLib_MakeSolid::FaceStatus
192   (const TopoDS_Face& F) const
193 {
194   BRepLib_ShapeModification myStatus = BRepLib_Preserved;
195   TopTools_ListIteratorOfListOfShape anIter(myDeletedFaces);
196
197   for(; anIter.More(); anIter.Next()) {
198     if(F.IsSame(anIter.Value())) {
199       myStatus = BRepLib_Deleted;
200       break;
201     }
202   }
203   
204   return myStatus;
205 }
206