0021762: Integration of new Boolean Operation algorithm to OCCT.
[occt.git] / src / BRepFeat / BRepFeat_Builder.cxx
CommitLineData
4e57c75e 1// Created on: 2012-06-01
2// Created by: Eugeny MALTCHIKOV
b311480e 3// Copyright (c) 1999-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
7fd59977 21#include <BRepFeat_Builder.ixx>
22
4e57c75e 23#include <Precision.hxx>
24
25#include <TopoDS_Shape.hxx>
26#include <TopoDS_Face.hxx>
27#include <TopoDS_Edge.hxx>
28
29#include <TopExp_Explorer.hxx>
7fd59977 30#include <TopTools_ListIteratorOfListOfShape.hxx>
7fd59977 31
4e57c75e 32#include <Geom_Curve.hxx>
33
34#include <BRep_Tool.hxx>
35#include <BRep_Builder.hxx>
36
37#include <BRepBndLib.hxx>
38
39#include <IntTools_Tools.hxx>
40
41#include <BOPDS_DS.hxx>
42#include <BOPDS_ShapeInfo.hxx>
43#include <BOPDS_FaceInfo.hxx>
44#include <BOPDS_Pave.hxx>
45#include <BOPDS_ListOfPave.hxx>
46#include <BOPDS_ListOfPaveBlock.hxx>
47#include <BOPDS_MapOfPaveBlock.hxx>
48
49#include <BOPAlgo_BuilderFace.hxx>
50
51#include <BOPTools.hxx>
52#include <BOPTools_AlgoTools.hxx>
53#include <BOPTools_AlgoTools2D.hxx>
54#include <BOPTools_AlgoTools3D.hxx>
55#include <BOPTools_AlgoTools3D.hxx>
56#include <BOPTools_MapOfSet.hxx>
57
58#include <BOPCol_DataMapOfShapeListOfShape.hxx>
59
60//=======================================================================
61//function :
62//purpose :
63//=======================================================================
64 BRepFeat_Builder::BRepFeat_Builder()
65:
66 BOPAlgo_BOP()
67{
68 Clear();
69}
70
71//=======================================================================
72//function : ~
73//purpose :
74//=======================================================================
75 BRepFeat_Builder::~BRepFeat_Builder()
76{
77}
78
79//=======================================================================
80//function : Clear
81//purpose :
82//=======================================================================
83 void BRepFeat_Builder::Clear()
84{
85 myShapes.Clear();
86 myRemoved.Clear();
87 BOPAlgo_BOP::Clear();
88}
89
90//=======================================================================
91//function : Init
92//purpose :
93//=======================================================================
94 void BRepFeat_Builder::Init(const TopoDS_Shape& theShape)
95{
96 Clear();
97 //
98 AddArgument(theShape);
99}
100
101//=======================================================================
102//function : Init
103//purpose :
104//=======================================================================
105 void BRepFeat_Builder::Init(const TopoDS_Shape& theShape,
106 const TopoDS_Shape& theTool)
107{
108 Clear();
109 //
110 AddArgument(theShape);
111 AddTool(theTool);
112}
113
114//=======================================================================
115//function : SetOperation
116//purpose :
117//=======================================================================
118 void BRepFeat_Builder::SetOperation(const Standard_Integer theFuse)
119{
120 myFuse = theFuse;
121 myOperation = myFuse ? BOPAlgo_FUSE : BOPAlgo_CUT;
122}
123
124//=======================================================================
125//function : SetOperation
126//purpose :
127//=======================================================================
128 void BRepFeat_Builder::SetOperation(const Standard_Integer theFuse,
129 const Standard_Boolean theFlag)
130{
131 myFuse = theFuse;
132 if (!theFlag) {
133 myOperation = myFuse ? BOPAlgo_FUSE : BOPAlgo_CUT;
134 } else {
135 myOperation = myFuse ? BOPAlgo_CUT21 : BOPAlgo_COMMON;
136 }
137}
138
139//=======================================================================
140//function : PartsOfTool
141//purpose :
142//=======================================================================
143 void BRepFeat_Builder::PartsOfTool(TopTools_ListOfShape& aLT)
144{
145 TopExp_Explorer aExp;
146 //
147 aLT.Clear();
148 aExp.Init(myShape, TopAbs_SOLID);
149 for (;aExp.More(); aExp.Next()) {
150 const TopoDS_Shape& aS = aExp.Current();
151 aLT.Append(aS);
152 }
153}
154
155//=======================================================================
156//function : KeepPartsOfTool
157//purpose :
158//=======================================================================
159 void BRepFeat_Builder::KeepParts(const TopTools_ListOfShape& theIm)
160{
161 TopTools_ListIteratorOfListOfShape aItT;
162 aItT.Initialize(theIm);
163 for (; aItT.More(); aItT.Next()) {
164 const TopoDS_Shape& aTIm=aItT.Value();
165 KeepPart(aTIm);
166 }
167}
168
169//=======================================================================
170//function : KeepPart
171//purpose :
172//=======================================================================
173 void BRepFeat_Builder::KeepPart(const TopoDS_Shape& thePart)
174{
175 TopoDS_Shape aF, aFOr;
176 TopExp_Explorer aExp;
177 //
178 BOPTools::MapShapes(thePart, myShapes);
179}
180
181//=======================================================================
182//function : Prepare
183//purpose :
184//=======================================================================
185 void BRepFeat_Builder::Prepare()
186{
187 myErrorStatus=0;
188 //
189 BRep_Builder aBB;
190 TopoDS_Compound aC;
191 aBB.MakeCompound(aC);
192 myShape=aC;
193 //
194 myFlagHistory=Standard_True;
195 //
196 FillRemoved();
197}
198
199//=======================================================================
200//function : FillRemoved
201//purpose :
202//=======================================================================
203 void BRepFeat_Builder::FillRemoved()
204{
205 TopExp_Explorer aExp;
206 aExp.Init(myArgs[0], TopAbs_SOLID);
207 for (; aExp.More(); aExp.Next()) {
208 const TopoDS_Shape& aS = aExp.Current();
209 myImages.UnBind(aS);
210 }
211 //
212 if (!myImages.IsBound(myArgs[1])) {
213 return;
214 }
215 //
216 BOPCol_ListIteratorOfListOfShape aItIm;
217 //
218 BOPCol_ListOfShape& aLS = myImages.ChangeFind(myArgs[1]);
219 aItIm.Initialize(aLS);
220 for (; aItIm.More(); aItIm.Next()) {
221 const TopoDS_Shape& aS = aItIm.Value();
222 FillRemoved(aS, myRemoved);
223 }
224}
7fd59977 225
226//=======================================================================
4e57c75e 227//function : PerformResult
7fd59977 228//purpose :
229//=======================================================================
4e57c75e 230 void BRepFeat_Builder::PerformResult()
231{
232 myOperation = myFuse ? BOPAlgo_FUSE : BOPAlgo_CUT;
233 //
234 Prepare();
235 //
236 RebuildFaces();
237 //
238 FillImagesContainers(TopAbs_SHELL);
239 if (myErrorStatus) {
240 return;
241 }
242 //
243 FillImagesSolids();
244 if (myErrorStatus) {
245 return;
246 }
247 //
248 CheckSolidImages();
249 //
250 BuildResult(TopAbs_SOLID);
251 if (myErrorStatus) {
252 return;
253 }
254 //
255 FillImagesCompounds();
256 if (myErrorStatus) {
257 return;
258 }
259 //
260 BuildResult(TopAbs_COMPOUND);
261 if (myErrorStatus) {
262 return;
263 }
264 //
265 BuildShape();
266}
7fd59977 267
4e57c75e 268//=======================================================================
269//function : RebuildFaces
270//purpose :
271//=======================================================================
272 void BRepFeat_Builder::RebuildFaces()
7fd59977 273{
4e57c75e 274 Standard_Integer aNbS, i, iRank, nSp, j;
275 Standard_Boolean bIsClosed, bIsDegenerated, bToReverse,
276 bRem, bIm, bFlagSD, bVInShapes;
277 TopAbs_Orientation anOriF, anOriE;
278 TopoDS_Face aFF, aFSD;
279 TopoDS_Edge aSp;
280 TopoDS_Shape aSx;
281 TopExp_Explorer aExp, aExpE;
282 BOPCol_MapOfShape aME, aMESplit;
283 BOPCol_ListIteratorOfListOfShape aItIm;
284 BOPDS_MapIteratorOfMapOfPaveBlock aItMPB;
285 BOPCol_MapIteratorOfMapOfShape aItM;
286 BOPTools_MapOfSet aMST;
287 BOPCol_ListOfShape aLE;
288 //
289 aItM.Initialize(myShapes);
290 for (; aItM.More(); aItM.Next()) {
291 const TopoDS_Shape& aS = aItM.Value();
292 if (aS.ShapeType() == TopAbs_FACE) {
293 BOPTools_Set aST;
294 aST.Add(aS, TopAbs_EDGE);
295 aMST.Add(aST);
296 }
297 }
298 //
299 aNbS=myDS->NbSourceShapes();
300 for (i=0; i<aNbS; ++i) {
301 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
302 //
303 iRank = myDS->Rank(i);
304 if (iRank == 1) {
305 const TopoDS_Shape& aS = aSI.Shape();
306 //
307 if (myImages.IsBound(aS)) {
308 BOPCol_ListOfShape& aLIm = myImages.ChangeFind(aS);
309 aItIm.Initialize(aLIm);
310 for (; aItIm.More(); ) {
311 const TopoDS_Shape& aSIm = aItIm.Value();
312 if (!myShapes.Contains(aSIm)) {
313 aLIm.Remove(aItIm);
314 continue;
315 }
316 aItIm.Next();
317 }
318 }
319 continue;
320 }
321 //
322 if (aSI.ShapeType()!=TopAbs_FACE) {
323 continue;
324 }
325 //
326 const BOPDS_FaceInfo& aFI=myDS->FaceInfo(i);
327 const TopoDS_Face& aF=(*(TopoDS_Face*)(&aSI.Shape()));
328 //
329 if (!myImages.IsBound(aF)) {
330 continue;
331 }
332 //
333 anOriF=aF.Orientation();
334 aFF=aF;
335 aFF.Orientation(TopAbs_FORWARD);
336
337 const BOPDS_IndexedMapOfPaveBlock& aMPBIn=aFI.PaveBlocksIn();
338 const BOPDS_IndexedMapOfPaveBlock& aMPBSc=aFI.PaveBlocksSc();
339
340 aLE.Clear();
341
342 //bounding edges
343 aExp.Init(aFF, TopAbs_EDGE);
344 for (; aExp.More(); aExp.Next()) {
345 const TopoDS_Edge& aE=(*(TopoDS_Edge*)(&aExp.Current()));
346 anOriE=aE.Orientation();
347 bIsDegenerated=BRep_Tool::Degenerated(aE);
348 bIsClosed=BRep_Tool::IsClosed(aE, aF);
349 if (myImages.IsBound(aE)) {
350 BOPCol_ListOfShape& aLEIm = myImages.ChangeFind(aE);
351 //
352 bRem = Standard_False;
353 bIm = Standard_False;
354 aME.Clear();
355 BOPCol_ListOfShape aLEImNew;
356 //
357 aItIm.Initialize(aLEIm);
358 for (; aItIm.More(); aItIm.Next()) {
359 const TopoDS_Shape& aS = aItIm.Value();
360
361 bVInShapes = Standard_False;
362 if (myShapes.Contains(aS)) {
363 bVInShapes = Standard_True;
364 } else {
365 aExpE.Init(aS, TopAbs_VERTEX);
366 for(;aExpE.More(); aExpE.Next()) {
367 const TopoDS_Shape& aV = aExpE.Current();
368 if (myShapes.Contains(aV)) {
369 bVInShapes = Standard_True;
370 break;
371 }
372 }
373 }
374 //
375 if (bVInShapes) {
376 bIm = Standard_True;
377 aLEImNew.Append(aS);
378 } else {
379 bRem = Standard_True;
380 aME.Add(aS);
381 }
382 }
383 //
384 if (!bIm) {
385 aLE.Append(aE);
386 continue;
387 }
388 //
389 if (bRem && bIm) {
390 if (aLEIm.Extent() == 2) {
391 aLE.Append(aE);
392 continue;
393 }
394 if (aMESplit.Add(aE)) {
395 RebuildEdge(aE, aFF, aME, aLEImNew);
396 aLEIm.Assign(aLEImNew);
397 if (aLEIm.Extent() == 1) {
398 aLE.Append(aE);
399 continue;
400 }
401 }
402 }
403 //
404 aItIm.Initialize(aLEIm);
405 for (; aItIm.More(); aItIm.Next()) {
406 aSp = *(TopoDS_Edge*)&aItIm.Value();
407
408 if (bIsDegenerated) {
409 aSp.Orientation(anOriE);
410 aLE.Append(aSp);
411 continue;
412 }
413 //
414 if (anOriE==TopAbs_INTERNAL) {
415 aSp.Orientation(TopAbs_FORWARD);
416 aLE.Append(aSp);
417 aSp.Orientation(TopAbs_REVERSED);
418 aLE.Append(aSp);
419 continue;
420 }
421 //
422 if (bIsClosed) {
423 if (!BRep_Tool::IsClosed(aSp, aFF)){
424 BOPTools_AlgoTools3D::DoSplitSEAMOnFace(aSp, aFF);
425 }
426 //
427 aSp.Orientation(TopAbs_FORWARD);
428 aLE.Append(aSp);
429 aSp.Orientation(TopAbs_REVERSED);
430 aLE.Append(aSp);
431 continue;
432 }// if (bIsClosed){
433 //
434 aSp.Orientation(anOriE);
435 bToReverse=BOPTools_AlgoTools::IsSplitToReverse(aSp, aE, myContext);
436 if (bToReverse) {
437 aSp.Reverse();
438 }
439 aLE.Append(aSp);
440 }
441 }
442 else {
443 aLE.Append(aE);
444 }
445 }
446
447 Standard_Integer aNbPBIn, aNbPBSc;
448 aNbPBIn = aMPBIn.Extent();
449 aNbPBSc = aMPBSc.Extent();
450 //
451 //in edges
452 for (j=1; j<=aNbPBIn; ++j) {
453 const Handle(BOPDS_PaveBlock)& aPB=aMPBIn(j);
454 nSp=aPB->Edge();
455 aSp=(*(TopoDS_Edge*)(&myDS->Shape(nSp)));
456 if (myRemoved.Contains(aSp)) {
457 continue;
458 }
459 //
460 aSp.Orientation(TopAbs_FORWARD);
461 aLE.Append(aSp);
462 aSp.Orientation(TopAbs_REVERSED);
463 aLE.Append(aSp);
464 }
465 //section edges
466 for (j=1; j<=aNbPBSc; ++j) {
467 const Handle(BOPDS_PaveBlock)& aPB=aMPBSc(j);
468 nSp=aPB->Edge();
469 aSp=(*(TopoDS_Edge*)(&myDS->Shape(nSp)));
470 if (myRemoved.Contains(aSp)) {
471 continue;
472 }
473 //
474 aSp.Orientation(TopAbs_FORWARD);
475 aLE.Append(aSp);
476 aSp.Orientation(TopAbs_REVERSED);
477 aLE.Append(aSp);
478 }
479
480 //build new faces
481 BOPAlgo_BuilderFace aBF;
482 aBF.SetFace(aFF);
483 aBF.SetShapes(aLE);
484
485 aBF.Perform();
486
487 BOPCol_ListOfShape& aLFIm = myImages.ChangeFind(aF);
488 aLFIm.Clear();
489
490 const BOPCol_ListOfShape& aLFR=aBF.Areas();
491 aItIm.Initialize(aLFR);
492 for (; aItIm.More(); aItIm.Next()) {
493 TopoDS_Shape& aFR=aItIm.ChangeValue();
494 //
495 BOPTools_Set aST;
496 aST.Add(aFR, TopAbs_EDGE);
497 bFlagSD=aMST.Contains(aST);
498 //
499 const BOPTools_Set& aSTx=aMST.Added(aST);
500 aSx=aSTx.Shape();
501 aSx.Orientation(anOriF);
502 aLFIm.Append(aSx);
503 myOrigins.Bind(aSx, aF);
504 //
505 if (bFlagSD) {
506 myShapesSD.Bind(aFR, aSx);
507 }
508 }
509 //
510 mySplits.Bind(aF, aLFIm);
511 if (aLFIm.Extent() == 0) {
512 mySplits.UnBind(aF);
513 myImages.UnBind(aF);
514 }
7fd59977 515 }
7fd59977 516}
517
4e57c75e 518//=======================================================================
519//function : RebuildEdge
520//purpose :
521//=======================================================================
522 void BRepFeat_Builder::RebuildEdge(const TopoDS_Shape& theE,
523 const TopoDS_Face& theF,
524 const BOPCol_MapOfShape& aME,
525 BOPCol_ListOfShape& aLIm)
526{
527 Standard_Integer nE, nSp, nV1, nV2, nE1, nV, nVx, nVSD;
528 Standard_Integer nV11, nV21;
529 Standard_Boolean bOld;
530 Standard_Real aT11, aT21;
531 Standard_Real aT1, aT2;
532 TopoDS_Edge aSp, aE;
533 BOPDS_ShapeInfo aSI;
534 TopoDS_Vertex aV1, aV2;
535 Handle(BOPDS_PaveBlock) aPBNew;
536 BOPCol_MapOfInteger aMI, aMAdd, aMV, aMVOr;
537 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
538 BOPCol_ListIteratorOfListOfShape aIt;
539 BOPCol_ListIteratorOfListOfInteger aItLI;
540 BOPCol_MapIteratorOfMapOfShape aItM;
541 BOPDS_MapOfPaveBlock aMPB;
542 BOPDS_MapIteratorOfMapOfPaveBlock aItMPB;
543 //
544 aSI.SetShapeType(TopAbs_EDGE);
545
546 //1. collect origin vertices to aMV map.
547 nE = myDS->Index(theE);
548 const BOPDS_ShapeInfo& aSIE = myDS->ShapeInfo(nE);
549 const BOPCol_ListOfInteger& aLS = aSIE.SubShapes();
550 aItLI.Initialize(aLS);
551 for(; aItLI.More(); aItLI.Next()) {
552 nV = aItLI.Value();
553 nVx=nV;
554 if (myDS->HasShapeSD(nV, nVSD)) {
555 nVx=nVSD;
556 }
557 aMV.Add(nVx);
558 aMVOr.Add(nVx);
559 }
560 //
561 //2. collect vertices that should be removed to aMI map.
562 aPBNew = new BOPDS_PaveBlock;
563 BOPDS_ListOfPave& aLPExt = aPBNew->ChangeExtPaves();
564 BOPDS_ListOfPaveBlock& aLPB = myDS->ChangePaveBlocks(nE);
565 //
566 for (aItPB.Initialize(aLPB); aItPB.More(); aItPB.Next()) {
567 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
568 nE1 = aPB->Edge();
569 const TopoDS_Shape& aE1 = myDS->Shape(nE1);
570 //
571 if (aME.Contains(aE1)) {
572 aPB->Indices(nV1, nV2);
573 aMI.Add(nV1);
574 aMI.Add(nV2);
575 }
576 else {
577 aMPB.Add(aPB);
578 }
579 }
580 //3. collect vertices that split the source shape.
581 for (aItPB.Initialize(aLPB); aItPB.More(); aItPB.Next()) {
582 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
583 aPB->Indices(nV1, nV2);
584 //
585 if (!aMI.Contains(nV1)) {
586 aMV.Add(nV1);
587 }
588 if (!aMI.Contains(nV2)) {
589 aMV.Add(nV2);
590 }
591 }
592 //4. collect ext paves.
593 for (aItPB.Initialize(aLPB); aItPB.More(); aItPB.Next()) {
594 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
595 aPB->Indices(nV1, nV2);
596 //
597 if (aMV.Contains(nV1)) {
598 if (aMAdd.Add(nV1) || aMVOr.Contains(nV1)) {
599 aLPExt.Append(aPB->Pave1());
600 }
601 }
602 //
603 if (aMV.Contains(nV2)) {
604 if (aMAdd.Add(nV2) || aMVOr.Contains(nV2)) {
605 aLPExt.Append(aPB->Pave2());
606 }
607 }
608 }
609
610 aE = (*(TopoDS_Edge *)(&theE));
611 aE.Orientation(TopAbs_FORWARD);
612 //
613 aLIm.Clear();
614 //
615 //5. split edge by new set of vertices.
616 aLPB.Clear();
617 aPBNew->SetOriginalEdge(nE);
618 aPBNew->Update(aLPB, Standard_False);
619 //
620 for (aItPB.Initialize(aLPB); aItPB.More(); aItPB.Next()) {
621 Handle(BOPDS_PaveBlock)& aPB = aItPB.ChangeValue();
622 const BOPDS_Pave& aPave1=aPB->Pave1();
623 aPave1.Contents(nV1, aT1);
624 //
625 const BOPDS_Pave& aPave2=aPB->Pave2();
626 aPave2.Contents(nV2, aT2);
627 //
628 aItMPB.Initialize(aMPB);
629 //check if it is the old pave block.
630 bOld = Standard_False;
631 for (; aItMPB.More(); aItMPB.Next()) {
632 const Handle(BOPDS_PaveBlock)& aPB1 = aItMPB.Value();
633 aPB1->Indices(nV11, nV21);
634 aPB1->Range(aT11, aT21);
635 if (nV1 == nV11 && nV2 == nV21 &&
636 aT1 == aT11 && aT2 == aT21) {
637 const TopoDS_Shape& aEIm = myDS->Shape(aPB1->Edge());
638 aLIm.Append(aEIm);
639 bOld = Standard_True;
640 break;
641 }
642 }
643 if (bOld) {
644 continue;
645 }
646 //
647 aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
648 aV1.Orientation(TopAbs_FORWARD);
649 //
650 aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
651 aV2.Orientation(TopAbs_REVERSED);
652 //
653 BOPTools_AlgoTools::MakeSplitEdge(aE, aV1, aT1, aV2, aT2, aSp);
654 BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace(aSp, theF);
655 //
656 aSI.SetShape(aSp);
657 //
658 Bnd_Box& aBox=aSI.ChangeBox();
659 BRepBndLib::Add(aSp, aBox);
660 //
661 nSp=myDS->Append(aSI);
662 //
663 aPB->SetEdge(nSp);
664 aLIm.Append(aSp);
665 }
666}
667
668//=======================================================================
669//function : CheckSolidImages
670//purpose :
671//=======================================================================
672 void BRepFeat_Builder::CheckSolidImages()
673{
674 BOPTools_MapOfSet aMST;
675 BOPCol_ListOfShape aLSImNew;
676 BOPCol_MapOfShape aMS;
677 BOPCol_ListIteratorOfListOfShape aIt;
678 TopExp_Explorer aExp, aExpF;
679 Standard_Boolean bFlagSD;
680 //
681 const BOPCol_ListOfShape& aLSIm = myImages.Find(myArgs[1]);
682 aIt.Initialize(aLSIm);
683 for(;aIt.More();aIt.Next()) {
684 const TopoDS_Shape& aSolIm = aIt.Value();
685 //
686 BOPTools_Set aST;
687 aST.Add(aSolIm, TopAbs_FACE);
688 aMST.Add(aST);
689 }
690 //
691 aExp.Init(myArgs[0], TopAbs_SOLID);
692 for(; aExp.More(); aExp.Next()) {
693 const TopoDS_Shape& aSolid = aExp.Current();
694 if (myImages.IsBound(aSolid)) {
695 BOPCol_ListOfShape& aLSImSol = myImages.ChangeFind(aSolid);
696 aIt.Initialize(aLSImSol);
697 for(;aIt.More();aIt.Next()) {
698 const TopoDS_Shape& aSolIm = aIt.Value();
699 //
700 BOPTools_Set aST;
701 aST.Add(aSolIm, TopAbs_FACE);
702 bFlagSD=aMST.Contains(aST);
703 //
704 const BOPTools_Set& aSTx=aMST.Added(aST);
705 const TopoDS_Shape& aSx=aSTx.Shape();
706 aLSImNew.Append(aSx);
707 //
708 if (bFlagSD) {
709 myShapesSD.Bind(aSolIm, aSx);
710 }
711 }
712 aLSImSol.Assign(aLSImNew);
713 }
714 }
715}
716
717//=======================================================================
718//function : MapShapes
719//purpose :
720//=======================================================================
721 void BRepFeat_Builder::FillRemoved(const TopoDS_Shape& S,
722 BOPCol_MapOfShape& M)
723{
724 if (myShapes.Contains(S)) {
725 return;
726 }
727 //
728 M.Add(S);
729 TopoDS_Iterator It(S);
730 while (It.More()) {
731 FillRemoved(It.Value(),M);
732 It.Next();
733 }
734}
735
736//=======================================================================
737//function : FillIn3DParts
738//purpose :
739//=======================================================================
740 void BRepFeat_Builder::FillIn3DParts(BOPCol_DataMapOfShapeListOfShape& theInParts,
741 BOPCol_DataMapOfShapeShape& theDraftSolids,
742 const Handle(NCollection_BaseAllocator)& theAllocator)
743{
744 myErrorStatus=0;
745 //
746 Standard_Boolean bIsIN, bHasImage;
747 Standard_Integer aNbS, aNbSolids, i, j, aNbFaces, aNbFP, aNbFPx, aNbFIN, aNbLIF, aNbEFP;
748 Standard_Integer aNbRem;
749 TopAbs_ShapeEnum aType;
750 TopAbs_State aState;
751 TopoDS_Iterator aIt, aItF;
752 BRep_Builder aBB;
753 TopoDS_Solid aSolidSp;
754 TopoDS_Face aFP;
755 BOPCol_ListIteratorOfListOfShape aItS, aItFP, aItEx;
756 BOPCol_MapIteratorOfMapOfShape aItMS, aItMS1;
757 //
758 BOPCol_ListOfShape aLIF(theAllocator);
759 BOPCol_MapOfShape aMFDone(100, theAllocator);
760 BOPCol_MapOfShape aMSolids(100, theAllocator);
761 BOPCol_MapOfShape aMFaces(100, theAllocator);
762 BOPCol_MapOfShape aMFIN(100, theAllocator);
763 BOPCol_IndexedMapOfShape aMS(100, theAllocator);
764 BOPCol_IndexedDataMapOfShapeListOfShape aMEF(100, theAllocator);
765 //
766 theDraftSolids.Clear();
767 //
768 aNbRem = myRemoved.Extent();
769 //
770 aNbS=myDS->NbSourceShapes();
771 for (i=0; i<aNbS; ++i) {
772 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
773 const TopoDS_Shape& aS=aSI.Shape();
774 //
775 aType=aSI.ShapeType();
776 switch(aType) {
777 case TopAbs_SOLID: {
778 aMSolids.Add(aS);
779 break;
780 }
781 //
782 case TopAbs_FACE: {
783 // all faces (originals or images)
784 if (myImages.IsBound(aS)) {
785 const BOPCol_ListOfShape& aLS=myImages.Find(aS);
786 aItS.Initialize(aLS);
787 for (; aItS.More(); aItS.Next()) {
788 const TopoDS_Shape& aFx=aItS.Value();
789 if (!myRemoved.Contains(aFx)) {
790 aMFaces.Add(aFx);
791 }
792 }
793 }
794 else {
795 if (!myRemoved.Contains(aS)) {
796 aMFaces.Add(aS);
797 }
798 }
799 break;
800 }
801 //
802 default:
803 break;
804 }
805 }
806 //
807 aNbFaces=aMFaces.Extent();
808 aNbSolids=aMSolids.Extent();
809 //
810 aItMS.Initialize(aMSolids);
811 for (; aItMS.More(); aItMS.Next()) {
812 const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aItMS.Value()));
813 //
814 aMFDone.Clear();
815 aMFIN.Clear();
816 aMEF.Clear();
817 //
818 aBB.MakeSolid(aSolidSp);
819 //
820 // Draft solid and its pure internal faces => aSolidSp, aLIF
821 aLIF.Clear();
822 BuildDraftSolid(aSolid, aSolidSp, aLIF);
823 aNbLIF=aLIF.Extent();
824 //
825 // 1 all faces/edges from aSolid [ aMS ]
826 bHasImage=Standard_False;
827 aMS.Clear();
828 aIt.Initialize(aSolid);
829 for (; aIt.More(); aIt.Next()) {
830 const TopoDS_Shape& aShell=aIt.Value();
831 //
832 if (myImages.IsBound(aShell)) {
833 bHasImage=Standard_True;
834 //
835 const BOPCol_ListOfShape& aLS=myImages.Find(aShell);
836 aItS.Initialize(aLS);
837 for (; aItS.More(); aItS.Next()) {
838 const TopoDS_Shape& aSx=aItS.Value();
839 aMS.Add(aSx);
840 BOPTools::MapShapes(aSx, TopAbs_FACE, aMS);
841 BOPTools::MapShapes(aSx, TopAbs_EDGE, aMS);
842 BOPTools::MapShapesAndAncestors(aSx, TopAbs_EDGE, TopAbs_FACE, aMEF);
843 }
844 }
845 else {
846 //aMS.Add(aShell);
847 BOPTools::MapShapes(aShell, TopAbs_FACE, aMS);
848 BOPTools::MapShapesAndAncestors(aShell, TopAbs_EDGE, TopAbs_FACE, aMEF);
849 }
850 }
851 //
852 // 2 all faces that are not from aSolid [ aLFP1 ]
853 BOPCol_IndexedDataMapOfShapeListOfShape aMEFP(100, theAllocator);
854 BOPCol_ListOfShape aLFP1(theAllocator);
855 BOPCol_ListOfShape aLFP(theAllocator);
856 BOPCol_ListOfShape aLCBF(theAllocator);
857 BOPCol_ListOfShape aLFIN(theAllocator);
858 BOPCol_ListOfShape aLEx(theAllocator);
859 //
860 // for all non-solid faces build EF map [ aMEFP ]
861 aItMS1.Initialize(aMFaces);
862 for (; aItMS1.More(); aItMS1.Next()) {
863 const TopoDS_Shape& aFace=aItMS1.Value();
864 if (!aMS.Contains(aFace)) {
865 BOPTools::MapShapesAndAncestors(aFace, TopAbs_EDGE, TopAbs_FACE, aMEFP);
866 }
867 }
868 //
869 // among all faces from aMEFP select these that have same edges
870 // with the solid (i.e aMEF). These faces will be treated first
871 // to prevent the usage of 3D classifier.
872 // The full list of faces to process is aLFP1.
873 aNbEFP=aMEFP.Extent();
874 for (j=1; j<=aNbEFP; ++j) {
875 const TopoDS_Shape& aE=aMEFP.FindKey(j);
876 //
877 if (aMEF.Contains(aE)) { // !!
878 const BOPCol_ListOfShape& aLF=aMEFP(j);
879 aItFP.Initialize(aLF);
880 for (; aItFP.More(); aItFP.Next()) {
881 const TopoDS_Shape& aF=aItFP.Value();
882 if (aMFDone.Add(aF)) {
883 aLFP1.Append(aF);
884 }
885 }
886 }
887 else {
888 aLEx.Append(aE);
889 }
890 }
891 //
892 aItEx.Initialize(aLEx);
893 for (; aItEx.More(); aItEx.Next()) {
894 const TopoDS_Shape& aE=aItEx.Value();
895 const BOPCol_ListOfShape& aLF=aMEFP.FindFromKey(aE);
896 aItFP.Initialize(aLF);
897 for (; aItFP.More(); aItFP.Next()) {
898 const TopoDS_Shape& aF=aItFP.Value();
899 if (aMFDone.Add(aF)) {
900 //aLFP2.Append(aF);
901 aLFP1.Append(aF);
902 }
903 }
904 }
905 //
906 //==========
907 //
908 // 3 Process faces aLFP1
909 aMFDone.Clear();
910 aNbFP=aLFP1.Extent();
911 aItFP.Initialize(aLFP1);
912 for (; aItFP.More(); aItFP.Next()) {
913 const TopoDS_Shape& aSP=aItFP.Value();
914 if (!aMFDone.Add(aSP)) {
915 continue;
916 }
917
918 //
919 // first face to process
920 aFP=(*(TopoDS_Face*)(&aSP));
921 bIsIN=BOPTools_AlgoTools::IsInternalFace(aFP, aSolidSp, aMEF, 1.e-14, myContext);
922 aState=(bIsIN) ? TopAbs_IN : TopAbs_OUT;
923 //
924 // collect faces to process [ aFP is the first ]
925 aLFP.Clear();
926 aLFP.Append(aFP);
927 aItS.Initialize(aLFP1);
928 for (; aItS.More(); aItS.Next()) {
929 const TopoDS_Shape& aSk=aItS.Value();
930 if (!aMFDone.Contains(aSk)) {
931 aLFP.Append(aSk);
932 }
933 }
934 //
935 // Connexity Block that spreads from aFP the Bound
936 // or till the end of the block itself
937 aLCBF.Clear();
938 BOPTools_AlgoTools::MakeConnexityBlock(aLFP, aMS, aLCBF, theAllocator);
939 //
940 // fill states for the Connexity Block
941 aItS.Initialize(aLCBF);
942 for (; aItS.More(); aItS.Next()) {
943 const TopoDS_Shape& aSx=aItS.Value();
944 aMFDone.Add(aSx);
945 if (aState==TopAbs_IN) {
946 aMFIN.Add(aSx);
947 }
948 }
949 //
950 aNbFPx=aMFDone.Extent();
951 if (aNbFPx==aNbFP) {
952 break;
953 }
954 }//for (; aItFP.More(); aItFP.Next())
955 //
956 // faces Inside aSolid
957 aLFIN.Clear();
958 aNbFIN=aMFIN.Extent();
959 if (aNbFIN || aNbLIF) {
960 aItMS1.Initialize(aMFIN);
961 for (; aItMS1.More(); aItMS1.Next()) {
962 const TopoDS_Shape& aFIn=aItMS1.Value();
963 aLFIN.Append(aFIn);
964 }
965 //
966 aItS.Initialize(aLIF);
967 for (; aItS.More(); aItS.Next()) {
968 const TopoDS_Shape& aFIN=aItS.Value();
969 aLFIN.Append(aFIN);
970 }
971 //
972 theInParts.Bind(aSolid, aLFIN);
973 }
974 if (aNbFIN || bHasImage) {
975 theDraftSolids.Bind(aSolid, aSolidSp);
976 }
977 }// for (; aItMS.More(); aItMS.Next()) {
978}