Adding of testing cases from subgroups 937 940 and 941 of CHL group
[occt.git] / src / BOP / BOP_Builder.cxx
CommitLineData
b311480e 1// Created on: 2001-03-29
2// Created by: Peter KURNEV
3// Copyright (c) 2001-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21
22#include <BOP_Builder.ixx>
23
24#include <TopTools_ListIteratorOfListOfShape.hxx>
25#include <TopExp.hxx>
26
27#include <BooleanOperations_ShapesDataStructure.hxx>
28
29#include <BOPTools_SplitShapesPool.hxx>
30#include <BOPTools_CommonBlockPool.hxx>
31#include <BOPTools_ListOfPaveBlock.hxx>
32#include <BOPTools_ListOfCommonBlock.hxx>
33#include <TopTools_IndexedMapOfShape.hxx>
34#include <BOPTools_ListIteratorOfListOfCommonBlock.hxx>
35#include <BOPTools_CommonBlock.hxx>
36#include <BOPTools_PaveBlock.hxx>
37#include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
38
39//=======================================================================
40// function: BOP_Builder::BOP_Builder
41// purpose:
42//=======================================================================
b311480e 43BOP_Builder::BOP_Builder()
7fd59977 44: myOperation(BOP_UNKNOWN),
45 myManifoldFlag(Standard_False),
46 myIsDone(Standard_False),
47 myErrorStatus(1),
48 myDraw(0)
49{
50}
51//=======================================================================
52// function: Destroy
53// purpose:
54//=======================================================================
55 void BOP_Builder::Destroy()
56{
57}
58
59//=======================================================================
60// function: SetShapes
61// purpose:
62//=======================================================================
63 void BOP_Builder::SetShapes (const TopoDS_Shape& aS1,
64 const TopoDS_Shape& aS2)
65{
66 myShape1=aS1;
67 myShape2=aS2;
68}
69//=======================================================================
70// function: SetOperation
71// purpose:
72//=======================================================================
73 void BOP_Builder::SetOperation (const BOP_Operation anOp)
74{
75 myOperation=anOp;
76}
77
78
79//=======================================================================
80// function: SetManifoldFlag
81// purpose:
82//=======================================================================
83 void BOP_Builder::SetManifoldFlag (const Standard_Boolean aFlag)
84{
85 myManifoldFlag=aFlag;
86}
87//=======================================================================
88// function: Shape1
89// purpose:
90//=======================================================================
91 const TopoDS_Shape& BOP_Builder::Shape1()const
92{
93 return myShape1;
94}
95
96//=======================================================================
97// function: Shape2
98// purpose:
99//=======================================================================
100 const TopoDS_Shape& BOP_Builder::Shape2()const
101{
102 return myShape2;
103}
104//=======================================================================
105// function: Operation
106// purpose:
107//=======================================================================
108 BOP_Operation BOP_Builder::Operation () const
109{
110 return myOperation;
111}
112
113//=======================================================================
114// function: ManifoldFlag
115// purpose:
116//=======================================================================
117 Standard_Boolean BOP_Builder::ManifoldFlag () const
118{
119 return myManifoldFlag;
120}
121//=======================================================================
122// function: IsDone
123// purpose:
124//=======================================================================
125 Standard_Boolean BOP_Builder::IsDone() const
126{
127 return myIsDone;
128}
129//=======================================================================
130// function: ErrorStatus
131// purpose:
132//=======================================================================
133 Standard_Integer BOP_Builder::ErrorStatus() const
134{
135 return myErrorStatus;
136}
137//=======================================================================
138// function: Result
139// purpose:
140//=======================================================================
141 const TopoDS_Shape& BOP_Builder::Result()const
142{
143 return myResult;
144}
145
146//=======================================================================
147// function: Do
148// purpose:
149//=======================================================================
150 void BOP_Builder::Do()
151{
152}
153//=======================================================================
154// function: DoDoWithFiller
155// purpose:
156//=======================================================================
157 void BOP_Builder::DoWithFiller(const BOPTools_DSFiller& )
158{
159}
160
161//=======================================================================
162// function: BuildResult
163// purpose:
164//=======================================================================
165 void BOP_Builder::BuildResult()
166{
167}
168//
169//
170//=======================================================================
171// function: FillModified
172// purpose:
173//=======================================================================
174 void BOP_Builder::FillModified()
175{
176 //
177 // Prepare myResultMap
178 myResultMap.Clear();
179 TopExp::MapShapes(myResult, TopAbs_FACE, myResultMap);
180 TopExp::MapShapes(myResult, TopAbs_EDGE, myResultMap);
181 //
182 // Fill Modified for Edges
183 Standard_Integer i, aNbSources, aNbPaveBlocks, nSp, nFace;
184 //
185 const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
186 const BOPTools_SplitShapesPool& aSplitShapesPool= myDSFiller->SplitShapesPool();
187 const BOPTools_CommonBlockPool& aCommonBlockPool= myDSFiller->CommonBlockPool();
188 //
189 aNbSources=aDS.NumberOfSourceShapes();
190 for (i=1; i<=aNbSources; i++) {
191
192 if (aDS.GetShapeType(i) != TopAbs_EDGE){
193 continue;
194 }
195 //
196 const TopoDS_Shape& aE=aDS.Shape(i);
197 //
198 const BOPTools_ListOfPaveBlock& aSplitEdges=aSplitShapesPool(aDS.RefEdge(i));
199 const BOPTools_ListOfCommonBlock& aCBlocks =aCommonBlockPool(aDS.RefEdge(i));
200 //
201 aNbPaveBlocks=aSplitEdges.Extent();
202 if (!aNbPaveBlocks) {
203 continue;
204 }
205 //
206 TopTools_IndexedMapOfShape aM;
207
208 BOPTools_ListIteratorOfListOfCommonBlock aCBIt(aCBlocks);
209 for (; aCBIt.More(); aCBIt.Next()) {
210 BOPTools_CommonBlock& aCB=aCBIt.Value();
211 //
212 nFace=aCB.Face();
213 //
214 if (nFace) {
215 BOPTools_PaveBlock& aPB=aCB.PaveBlock1(i);
216 nSp=aPB.Edge();
217 const TopoDS_Shape& aSp=aDS.Shape(nSp);
218 //
219 if (aM.Contains(aSp)) {
220 continue;
221 }
222 aM.Add(aSp);
223 //
224 if (myResultMap.Contains(aSp)) {
225 FillModified(aE, aSp);
226 }
227 }
228 //
229 else {
230 const BOPTools_PaveBlock& aPB=aCB.PaveBlock1();
231 nSp=aPB.Edge();
232 const TopoDS_Shape& aSp=aDS.Shape(nSp);
233 //
234 if (aM.Contains(aSp)) {
235 continue;
236 }
237 aM.Add(aSp);
238 //
239 if (myResultMap.Contains(aSp)) {
240 FillModified(aE, aSp);
241 }
242 }
243 } // for (; aCBIt.More(); aCBIt.Next())
244
245
246 BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSplitEdges);
247 for (; aPBIt.More(); aPBIt.Next()) {
248 const BOPTools_PaveBlock& aPB=aPBIt.Value();
249 nSp=aPB.Edge();
250 const TopoDS_Shape& aSp=aDS.Shape(nSp);
251 //
252 if (aM.Contains(aSp)) {
253 continue;
254 }
255 aM.Add(aSp);
256 //
257 if (myResultMap.Contains(aSp)) {
258 FillModified(aE, aSp);
259 }
260 }// for (; aPBIt.More(); aPBIt.Next())
261 }
262}
263//=======================================================================
264// function: FillModified
265// purpose:
266//=======================================================================
267 void BOP_Builder::FillModified(const TopoDS_Shape& aE,
268 const TopoDS_Shape& aSp)
269{
270 if (myModifiedMap.Contains(aE)) {
271 TopTools_ListOfShape& aLM=myModifiedMap.ChangeFromKey(aE);
272 aLM.Append(aSp);
273 }
274 else {
275 TopTools_ListOfShape aLM;
276 aLM.Append(aSp);
277 myModifiedMap.Add(aE, aLM);
278 }
279}
280//=======================================================================
281// function: FillModified
282// purpose:
283//=======================================================================
284 void BOP_Builder::FillModified(const TopoDS_Shape& aS,
285 const TopTools_ListOfShape& aLFx)
286{
287 TopTools_ListIteratorOfListOfShape anIt(aLFx);
288 //
289 if (myModifiedMap.Contains(aS)) {
290 TopTools_ListOfShape& aLM=myModifiedMap.ChangeFromKey(aS);
291 anIt.Initialize(aLFx);
292 for (; anIt.More(); anIt.Next()) {
293 const TopoDS_Shape& aFx=anIt.Value();
294 aLM.Append(aFx);
295 }
296 }
297
298 else {
299 TopTools_ListOfShape aLM;
300 anIt.Initialize(aLFx);
301 for (; anIt.More(); anIt.Next()) {
302 const TopoDS_Shape& aFx=anIt.Value();
303 aLM.Append(aFx);
304 }
305 myModifiedMap.Add(aS, aLM);
306 }
307}
308//=======================================================================
309// function: Modified
310// purpose:
311//=======================================================================
312 const TopTools_ListOfShape& BOP_Builder::Modified(const TopoDS_Shape& aS)const
313{
314 if (myModifiedMap.Contains(aS)) {
315 const TopTools_ListOfShape& aLM=myModifiedMap.FindFromKey(aS);
316 return aLM;
317 }
318 else {
319 return myEmptyList;
320 }
321}
322//=======================================================================
323// function: IsDeleted
324// purpose:
325//=======================================================================
326 Standard_Boolean BOP_Builder::IsDeleted(const TopoDS_Shape& aS)const
327{
328 Standard_Boolean bFlag=Standard_False;
329 //
330 if (myResultMap.Contains(aS)) {
331 return bFlag;
332 }
333 //
334 const TopTools_ListOfShape& aLM=Modified(aS);
335 if (aLM.Extent()) {
336 return bFlag;
337 }
338 //
339 return !bFlag;
340}
341
342
343//=======================================================================
344//function : SortTypes
345//purpose :
346//=======================================================================
347 void BOP_Builder::SortTypes(TopAbs_ShapeEnum& aType1,
348 TopAbs_ShapeEnum& aType2)
349{
350 Standard_Integer iT1, iT2;
351
352 if (aType1==aType2)
353 return;
354
355 iT1=(Standard_Integer) aType1;
356 iT2=(Standard_Integer) aType2;
357
358 if (iT1 < iT2) {
359 aType1=(TopAbs_ShapeEnum) iT2;
360 aType2=(TopAbs_ShapeEnum) iT1;
361 }
362}
363
364//=======================================================================
365// function: SectionEdges
366// purpose:
367//=======================================================================
368 const TopTools_ListOfShape& BOP_Builder::SectionEdges()const
369{
370 return mySectionEdges;
371}
372
373
374//=======================================================================
375// function: SetHistoryCollector
376// purpose:
377//=======================================================================
378void BOP_Builder::SetHistoryCollector(const Handle(BOP_HistoryCollector)& theHistory)
379{
380 myHistory = theHistory;
381}
382
383//=======================================================================
384// function: GetHistoryCollector
385// purpose:
386//=======================================================================
387Handle(BOP_HistoryCollector) BOP_Builder::GetHistoryCollector() const
388{
389 return myHistory;
390}