0021762: Integration of new Boolean Operation algorithm to OCCT.
[occt.git] / src / BOP / BOP_SolidBuilder.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
7 //
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10 //
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
17
18 #include <BOP_SolidBuilder.ixx>
19
20 #include <TopoDS.hxx>
21
22 #include <BOP_ShellFaceClassifier.hxx>
23 #include <BOP_Loop.hxx>
24 #include <BOP_SFSCorrector.hxx>
25
26
27
28 // ==============================================================
29 // function: BOP_SolidBuilder
30 // purpose: 
31 // ==============================================================
32 BOP_SolidBuilder::BOP_SolidBuilder()
33 {
34 }
35
36 // ==============================================================
37 // function: BOP_SolidBuilder
38 // purpose: 
39 // ==============================================================
40   BOP_SolidBuilder::BOP_SolidBuilder(BOP_ShellFaceSet&      theSFS,
41                                      const Standard_Boolean theForceClassFlag)
42 {
43   InitSolidBuilder(theSFS, theForceClassFlag);
44 }
45
46 // ==============================================================
47 // function: InitSolidBuilder
48 // purpose: 
49 // ==============================================================
50   void BOP_SolidBuilder::InitSolidBuilder(BOP_ShellFaceSet&      theSFS,
51                                           const Standard_Boolean theForceClassFlag) 
52 {
53   //
54   BOP_SFSCorrector aSFSCor;
55   aSFSCor.SetSFS(theSFS);
56   aSFSCor.Do();
57   BOP_ShellFaceSet& aNewSFS=aSFSCor.NewSFS();
58   //
59   //MakeLoops(theSFS);
60   
61   MakeLoops(aNewSFS);
62   BOP_ShellFaceClassifier SFC(myBlockBuilder);
63   //
64   mySolidAreaBuilder.InitSolidAreaBuilder(myLoopSet, SFC, theForceClassFlag);
65 }
66
67 // ==============================================================
68 // function: InitSolid
69 // purpose: 
70 // ==============================================================
71   Standard_Integer BOP_SolidBuilder::InitSolid() 
72 {
73   return mySolidAreaBuilder.InitArea();
74 }
75
76 // ==============================================================
77 // function: MoreSolid
78 // purpose: 
79 // ==============================================================
80   Standard_Boolean BOP_SolidBuilder::MoreSolid() const
81 {
82   return mySolidAreaBuilder.MoreArea();
83 }
84
85 // ==============================================================
86 // function: NextSolid
87 // purpose: 
88 // ==============================================================
89   void BOP_SolidBuilder::NextSolid() 
90 {
91   mySolidAreaBuilder.NextArea();
92 }
93
94 // ==============================================================
95 // function: InitShell
96 // purpose: 
97 // ==============================================================
98   Standard_Integer BOP_SolidBuilder::InitShell() 
99 {
100   return mySolidAreaBuilder.InitLoop();
101 }
102
103 // ==============================================================
104 // function: MoreShell
105 // purpose: 
106 // ==============================================================
107   Standard_Boolean BOP_SolidBuilder::MoreShell() const
108 {
109   return mySolidAreaBuilder.MoreLoop();
110 }
111
112 // ==============================================================
113 // function: NextShell
114 // purpose: 
115 // ==============================================================
116   void BOP_SolidBuilder::NextShell() 
117 {
118   mySolidAreaBuilder.NextLoop();
119 }
120
121 // ==============================================================
122 // function: IsOldShell
123 // purpose: 
124 // ==============================================================
125   Standard_Boolean BOP_SolidBuilder::IsOldShell() const
126 {
127   return mySolidAreaBuilder.Loop()->IsShape();  
128 }
129
130 // ==============================================================
131 // function: OldShell
132 // purpose: 
133 // ==============================================================
134   TopoDS_Shell BOP_SolidBuilder::OldShell() const
135 {
136   if(!IsOldShell()) {
137     Standard_DomainError::Raise("BOP_SolidBuilder::OldShell");
138   }
139   
140   return TopoDS::Shell(mySolidAreaBuilder.Loop()->Shape());
141 }
142
143 // ==============================================================
144 // function: InitFace
145 // purpose: 
146 // ==============================================================
147   Standard_Integer BOP_SolidBuilder::InitFace() 
148 {
149   const Handle(BOP_Loop)& aLoop = mySolidAreaBuilder.Loop();
150   
151   if(aLoop->IsShape())
152     Standard_DomainError::Raise("BOP_SolidBuilder::InitFace");
153   else {
154     myBlockIterator = aLoop->BlockIterator();
155     myBlockIterator.Initialize();
156   }
157   return myBlockIterator.Extent();
158 }
159
160 // ==============================================================
161 // function: MoreFace
162 // purpose: 
163 // ==============================================================
164   Standard_Boolean BOP_SolidBuilder::MoreFace() const
165 {
166   return myBlockIterator.More();
167 }
168
169 // ==============================================================
170 // function: NextFace
171 // purpose: 
172 // ==============================================================
173   void BOP_SolidBuilder::NextFace() 
174 {
175   myBlockIterator.Next();
176 }
177
178 // ==============================================================
179 // function: Face
180 // purpose: 
181 // ==============================================================
182   const TopoDS_Face& BOP_SolidBuilder::Face() const
183 {
184   const TopoDS_Shape& aShape = myBlockBuilder.Element(myBlockIterator);
185   return TopoDS::Face(aShape);
186 }
187
188 // ==============================================================
189 // function: MakeLoops
190 // purpose: 
191 // ==============================================================
192   void BOP_SolidBuilder::MakeLoops(BOP_ShapeSet& theSFS) 
193 {
194   myBlockBuilder.MakeBlock(theSFS);
195
196   BOP_ListOfLoop& aList = myLoopSet.ChangeListOfLoop();
197   aList.Clear();
198
199   // Add shapes of theSFS as shape loops
200   for(theSFS.InitShapes(); theSFS.MoreShapes(); theSFS.NextShape()) {
201     Handle(BOP_Loop) aShapeLoop = new BOP_Loop(theSFS.Shape());
202     aList.Append(aShapeLoop);
203   }
204
205   // Add blocks of myBlockBuilder as block loops
206   for(myBlockBuilder.InitBlock(); myBlockBuilder.MoreBlock(); myBlockBuilder.NextBlock()) {
207     BOP_BlockIterator aBlockIterator = myBlockBuilder.BlockIterator();
208     Handle(BOP_Loop) aShapeLoop = new BOP_Loop(aBlockIterator);
209     aList.Append(aShapeLoop);
210   }
211 }
212