0024624: Lost word in license statement in source files
[occt.git] / src / BOPAlgo / BOPAlgo_Builder_3.cxx
... / ...
CommitLineData
1// Created by: Peter KURNEV
2// Copyright (c) 2010-2014 OPEN CASCADE SAS
3// Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4// Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5// EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6//
7// This file is part of Open CASCADE Technology software library.
8//
9// This library is free software; you can redistribute it and/or modify it under
10// the terms of the GNU Lesser General Public License version 2.1 as published
11// by the Free Software Foundation, with special exception defined in the file
12// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13// distribution for complete text of the license and disclaimer of any warranty.
14//
15// Alternatively, this file may be used under the terms of Open CASCADE
16// commercial license or contractual agreement.
17
18#include <BOPAlgo_Builder.hxx>
19
20#include <NCollection_IncAllocator.hxx>
21#include <NCollection_UBTreeFiller.hxx>
22
23#include <Bnd_Box.hxx>
24#include <TopAbs_State.hxx>
25
26#include <TopoDS.hxx>
27#include <TopoDS_Iterator.hxx>
28#include <TopoDS_Solid.hxx>
29#include <TopoDS_Shape.hxx>
30#include <TopoDS_Face.hxx>
31#include <TopoDS_Edge.hxx>
32#include <TopoDS_Solid.hxx>
33#include <TopoDS_Iterator.hxx>
34#include <TopoDS_Shell.hxx>
35#include <TopoDS_Compound.hxx>
36
37#include <TopExp.hxx>
38#include <TopExp_Explorer.hxx>
39
40#include <BRep_Builder.hxx>
41#include <BRepTools.hxx>
42#include <BRepClass3d_SolidClassifier.hxx>
43#include <BRepBndLib.hxx>
44//
45#include <BOPCol_IndexedMapOfShape.hxx>
46#include <BOPCol_MapOfShape.hxx>
47#include <BOPCol_IndexedDataMapOfShapeListOfShape.hxx>
48#include <BOPCol_ListOfShape.hxx>
49#include <BOPCol_BoxBndTree.hxx>
50#include <BOPCol_ListOfInteger.hxx>
51#include <BOPCol_DataMapOfIntegerShape.hxx>
52//
53#include <BOPInt_Context.hxx>
54//
55#include <BOPDS_DS.hxx>
56#include <BOPDS_ShapeInfo.hxx>
57//
58#include <BOPTools.hxx>
59#include <BOPTools_AlgoTools.hxx>
60#include <BOPTools_MapOfSet.hxx>
61#include <BOPTools_Set.hxx>
62//
63#include <BOPAlgo_BuilderSolid.hxx>
64#include <BOPAlgo_Builder_2Cnt.hxx>
65
66
67static
68 void OwnInternalShapes(const TopoDS_Shape& ,
69 BOPCol_IndexedMapOfShape& );
70
71static
72 void TreatCompound(const TopoDS_Shape& theS,
73 BOPCol_MapOfShape& aMFence,
74 BOPCol_ListOfShape& theLS);
75
76//=======================================================================
77//class : BOPAlgo_ShapeBox
78//purpose : Auxiliary class
79//=======================================================================
80class BOPAlgo_ShapeBox {
81 public:
82 BOPAlgo_ShapeBox() {
83 };
84 //
85 ~BOPAlgo_ShapeBox() {
86 };
87 //
88 void SetShape(const TopoDS_Shape& aS) {
89 myShape=aS;
90 };
91 //
92 const TopoDS_Shape& Shape()const {
93 return myShape;
94 };
95 //
96 void SetBox(const Bnd_Box& aBox) {
97 myBox=aBox;
98 };
99 //
100 const Bnd_Box& Box()const {
101 return myBox;
102 };
103 //
104 protected:
105 TopoDS_Shape myShape;
106 Bnd_Box myBox;
107};
108//
109typedef NCollection_DataMap\
110 <Standard_Integer, BOPAlgo_ShapeBox, TColStd_MapIntegerHasher> \
111 BOPAlgo_DataMapOfIntegerShapeBox;
112//
113typedef BOPAlgo_DataMapOfIntegerShapeBox::Iterator \
114 BOPAlgo_DataMapIteratorOfDataMapOfIntegerShapeBox;
115//
116
117//=======================================================================
118//function : FillImagesSolids
119//purpose :
120//=======================================================================
121void BOPAlgo_Builder::FillImagesSolids()
122{
123 Standard_Boolean bHasSolids;
124 Standard_Integer i, aNbS;
125 //
126 myErrorStatus=0;
127 //
128 bHasSolids=Standard_False;
129 aNbS=myDS->NbSourceShapes();
130 for (i=0; i<aNbS; ++i) {
131 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
132 if (aSI.ShapeType()==TopAbs_SOLID) {
133 bHasSolids=!bHasSolids;
134 break;
135 }
136 }
137 //
138 if (!bHasSolids) {
139 return;
140 }
141 //
142 Handle(NCollection_IncAllocator) aAlr;
143 //
144 aAlr=new NCollection_IncAllocator();
145 BOPCol_DataMapOfShapeListOfShape theInParts(100, aAlr);
146 BOPCol_DataMapOfShapeShape theDraftSolids(100, aAlr);
147 //
148 FillIn3DParts(theInParts, theDraftSolids, aAlr);
149 BuildSplitSolids(theInParts, theDraftSolids, aAlr);
150 FillInternalShapes();
151 //
152 theInParts.Clear();
153 theDraftSolids.Clear();
154}
155//=======================================================================
156//function : FillIn3DParts
157//purpose :
158//=======================================================================
159void BOPAlgo_Builder::FillIn3DParts(BOPCol_DataMapOfShapeListOfShape& theInParts,
160 BOPCol_DataMapOfShapeShape& theDraftSolids,
161 const BOPCol_BaseAllocator& )
162{
163 Standard_Boolean bHasImage;
164 Standard_Integer i, k, aNbS, aNbLIF, nFP, aNbFP, aNbFIN, iIsIN;
165 TopoDS_Solid aSD;
166 TopoDS_Iterator aIt;
167 BRep_Builder aBB;
168 BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1;
169 BOPCol_ListIteratorOfListOfShape aItLS;
170 BOPAlgo_ShapeBox aSB;
171 Handle(NCollection_IncAllocator) aAlr0;
172 //
173 aAlr0=new NCollection_IncAllocator();
174 BOPAlgo_DataMapOfIntegerShapeBox aDMISB(100, aAlr0);
175 BOPAlgo_DataMapIteratorOfDataMapOfIntegerShapeBox aItDMISB;
176 //
177 myErrorStatus=0;
178 theDraftSolids.Clear();
179 //
180 // 1. aDMISB map Index/FaceBox
181 k=0;
182 aNbS=myDS->NbSourceShapes();
183 for (i=0; i<aNbS; ++i) {
184 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
185 if (aSI.ShapeType()!=TopAbs_FACE) {
186 continue;
187 }
188 //
189 const TopoDS_Shape& aS=aSI.Shape();
190 //
191 if (myImages.IsBound(aS)) {
192 const BOPCol_ListOfShape& aLS=myImages.Find(aS);
193 aItLS.Initialize(aLS);
194 for (; aItLS.More(); aItLS.Next()) {
195 const TopoDS_Shape& aSx=aItLS.Value();
196 //
197 Bnd_Box aBox;
198 BRepBndLib::Add(aSx, aBox);
199 //
200 aSB.SetShape(aSx);
201 aSB.SetBox(aBox);
202 //
203 aDMISB.Bind(k, aSB);
204 ++k;
205 }
206 }
207 else {
208 const Bnd_Box& aBox=aSI.Box();
209 //
210 aSB.SetShape(aS);
211 aSB.SetBox(aBox);
212 //
213 aDMISB.Bind(k, aSB);
214 ++k;
215 }
216 }//for (i=0; i<aNbS; ++i) {
217 //
218 // 1.2. Prepare TreeFiller
219 BOPCol_BoxBndTree aBBTree;
220 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
221 //
222 aItDMISB.Initialize(aDMISB);
223 for (; aItDMISB.More(); aItDMISB.Next()) {
224 k=aItDMISB.Key();
225 const BOPAlgo_ShapeBox& aSBk=aItDMISB.Value();
226 const Bnd_Box& aBk=aSBk.Box();
227 //
228 aTreeFiller.Add(k, aBk);
229 }
230 //
231 // 1.3. Shake TreeFiller
232 aTreeFiller.Fill();
233 //
234 //---------------------------------------------
235 // 2. Solids
236 for (i=0; i<aNbS; ++i) {
237 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
238 if (aSI.ShapeType()!=TopAbs_SOLID) {
239 continue;
240 }
241 //
242 //---------------------------------------------
243 Handle(NCollection_IncAllocator) aAlr1;
244 //
245 aAlr1=new NCollection_IncAllocator();
246 //
247 BOPCol_ListOfShape aLFIN(aAlr1);
248 BOPCol_ListOfShape aLIF(aAlr1);
249 BOPCol_IndexedMapOfShape aMF(100, aAlr1);
250 BOPCol_IndexedDataMapOfShapeListOfShape aMEF(100, aAlr1);
251 BOPCol_BoxBndTreeSelector aSelector;
252 Bnd_Box aBoxS;
253 //
254 const TopoDS_Shape& aS=aSI.Shape();
255 const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS));
256 //
257 // 2.0 Flag bHasImage
258 bHasImage=Standard_False;
259 aIt.Initialize(aS);
260 for (; aIt.More(); aIt.Next()) {
261 const TopoDS_Shape& aShell=aIt.Value();
262 bHasImage=myImages.IsBound(aShell);
263 if (bHasImage){
264 break;
265 }
266 }
267 //
268 // 2.1 Bounding box for the solid aS [ aBoxS ]
269 aBoxS=aSI.Box();
270 //-----
271 //
272 // 2.2 Build Draft Solid [aSD]
273 aBB.MakeSolid(aSD);
274 //
275 BuildDraftSolid(aSolid, aSD, aLIF);
276 aNbLIF=aLIF.Extent();
277 //
278 BOPTools::MapShapesAndAncestors(aSD, TopAbs_EDGE, TopAbs_FACE, aMEF);
279 //
280 // 2.3 Faces from aSD and own internal faces => aMF
281 BOPTools::MapShapes(aSD, TopAbs_FACE, aMF);
282 //
283 aItLS.Initialize(aLIF);
284 for (; aItLS.More(); aItLS.Next()) {
285 const TopoDS_Shape& aFI=aItLS.Value();
286 aMF.Add(aFI);
287 }
288 //
289 // 2.4. Select boxes of faces that are not out of aBoxS
290 aSelector.Clear();
291 aSelector.SetBox(aBoxS);
292 //
293 aNbFP=aBBTree.Select(aSelector);
294 //
295 const BOPCol_ListOfInteger& aLIFP=aSelector.Indices();
296 //
297 // 2.5. Collect faces that are IN aSolid [ aLFIN ]
298 BOPCol_ListOfShape aLFP(aAlr1);
299 BOPCol_ListOfShape aLCBF(aAlr1);
300 BOPCol_MapOfShape aMFDone(100, aAlr1);
301 BOPCol_IndexedMapOfShape aME(100, aAlr1);
302 //
303 BOPTools::MapShapes(aSD, TopAbs_EDGE, aME);
304 //
305 aItLI.Initialize(aLIFP);
306 for (; aItLI.More(); aItLI.Next()) {
307 nFP=aItLI.Value();
308 const BOPAlgo_ShapeBox& aSBF=aDMISB.Find(nFP);
309 const TopoDS_Face& aFP=(*(TopoDS_Face*)&aSBF.Shape());
310 if (aMF.Contains(aFP)) {
311 continue;
312 }
313 if (aMFDone.Contains(aFP)) {
314 continue;
315 }
316 //
317 aMFDone.Add(aFP);
318 //
319 iIsIN=BOPTools_AlgoTools::IsInternalFace(aFP, aSD, aMEF, 1.e-14, myContext);
320 //
321 aLFP.Clear();
322 aLFP.Append(aFP);
323 //
324 aItLI1.Initialize(aLIFP);
325 for (; aItLI1.More(); aItLI1.Next()) {
326 const TopoDS_Shape& aFx=aDMISB.Find(aItLI1.Value()).Shape();
327 if (!aMFDone.Contains(aFx)) {
328 aLFP.Append(aFx);
329 }
330 }
331 //
332 aLCBF.Clear();
333 //----------------------------------------
334 {
335 Handle(NCollection_IncAllocator) aAlr2;
336 aAlr2=new NCollection_IncAllocator();
337 //
338 BOPTools_AlgoTools::MakeConnexityBlock(aLFP, aME, aLCBF, aAlr2);
339 }
340 //----------------------------------------
341 aItLS.Initialize(aLCBF);
342 for (; aItLS.More(); aItLS.Next()) {
343 const TopoDS_Shape& aFx=aItLS.Value();
344 aMFDone.Add(aFx);
345 if (iIsIN) {
346 aLFIN.Append(aFx);
347 }
348 }
349 }// for (; aItLI.More(); aItLI.Next()) {
350 //
351 // 2.6. Store the results in theInParts, theDraftSolids
352 aNbFIN=aLFIN.Extent();
353 if (aNbFIN || aNbLIF) {
354 aItLS.Initialize(aLIF);
355 for (; aItLS.More(); aItLS.Next()) {
356 const TopoDS_Shape& aFI=aItLS.Value();
357 aLFIN.Append(aFI);
358 }
359 theInParts.Bind(aSolid, aLFIN);
360 }
361 //
362 if (aNbFIN || bHasImage) {
363 theDraftSolids.Bind(aSolid, aSD);
364 }
365 //---------------------------------------------
366 }// for (i=0; i<aNbS; ++i) {
367}
368
369//=======================================================================
370//function : BuildDraftSolid
371//purpose :
372//=======================================================================
373void BOPAlgo_Builder::BuildDraftSolid(const TopoDS_Shape& theSolid,
374 TopoDS_Shape& theDraftSolid,
375 BOPCol_ListOfShape& theLIF)
376{
377 myErrorStatus=0;
378 //
379 Standard_Boolean bToReverse;
380 Standard_Integer iFlag;
381 TopAbs_Orientation aOrF, aOrSh, aOrSd;
382 TopoDS_Iterator aIt1, aIt2;
383 TopoDS_Shell aShD;
384 TopoDS_Shape aFSDx, aFx;
385 BRep_Builder aBB;
386 BOPCol_ListIteratorOfListOfShape aItS;
387 //
388 aOrSd=theSolid.Orientation();
389 theDraftSolid.Orientation(aOrSd);
390 //
391 aIt1.Initialize(theSolid);
392 for (; aIt1.More(); aIt1.Next()) {
393 const TopoDS_Shape& aSh=aIt1.Value();
394 if(aSh.ShapeType()!=TopAbs_SHELL) {
395 continue; // mb internal edges,vertices
396 }
397 //
398 aOrSh=aSh.Orientation();
399 aBB.MakeShell(aShD);
400 aShD.Orientation(aOrSh);
401 iFlag=0;
402 //
403 aIt2.Initialize(aSh);
404 for (; aIt2.More(); aIt2.Next()) {
405 const TopoDS_Shape& aF=aIt2.Value();
406 aOrF=aF.Orientation();
407 //
408 if (myImages.IsBound(aF)) {
409 const BOPCol_ListOfShape& aLSp=myImages.Find(aF);
410 aItS.Initialize(aLSp);
411 for (; aItS.More(); aItS.Next()) {
412 aFx=aItS.Value();
413 //
414 if (myShapesSD.IsBound(aFx)) {
415 aFSDx=myShapesSD.Find(aFx);
416 //
417 if (aOrF==TopAbs_INTERNAL) {
418 aFSDx.Orientation(aOrF);
419 theLIF.Append(aFSDx);
420 }
421 else {
422 bToReverse=BOPTools_AlgoTools::IsSplitToReverse(aFSDx, aF, myContext);
423 if (bToReverse) {
424 aFSDx.Reverse();
425 }
426 //
427 iFlag=1;
428 aBB.Add(aShD, aFSDx);
429 }
430 }//if (myShapesSD.IsBound(aFx)) {
431 else {
432 aFx.Orientation(aOrF);
433 if (aOrF==TopAbs_INTERNAL) {
434 theLIF.Append(aFx);
435 }
436 else{
437 iFlag=1;
438 aBB.Add(aShD, aFx);
439 }
440 }
441 }
442 } // if (myImages.IsBound(aF)) {
443 //
444 else {
445 if (aOrF==TopAbs_INTERNAL) {
446 theLIF.Append(aF);
447 }
448 else{
449 iFlag=1;
450 aBB.Add(aShD, aF);
451 }
452 }
453 } //for (; aIt2.More(); aIt2.Next()) {
454 //
455 if (iFlag) {
456 aBB.Add(theDraftSolid, aShD);
457 }
458 } //for (; aIt1.More(); aIt1.Next()) {
459}
460//=======================================================================
461//function : BuildSplitSolids
462//purpose :
463//=======================================================================
464void BOPAlgo_Builder::BuildSplitSolids(BOPCol_DataMapOfShapeListOfShape& theInParts,
465 BOPCol_DataMapOfShapeShape& theDraftSolids,
466 const BOPCol_BaseAllocator& )
467{
468 myErrorStatus=0;
469 //
470 Standard_Boolean bFlagSD;
471 Standard_Integer i, aNbS;
472 TopExp_Explorer aExp;
473 BOPCol_ListIteratorOfListOfShape aIt;
474 BOPCol_DataMapIteratorOfDataMapOfShapeShape aIt1;
475 //
476 Handle(NCollection_IncAllocator) aAlr0;
477 aAlr0=new NCollection_IncAllocator();
478 //
479 BOPCol_ListOfShape aSFS(aAlr0), aLSEmpty(aAlr0);
480 BOPCol_MapOfShape aMFence(100, aAlr0);
481 BOPTools_MapOfSet aMST(100, aAlr0);
482 BOPAlgo_VectorOfBuilderSolid aVBS;
483 //
484 // 0. Find same domain solids for non-interferred solids
485 aNbS=myDS->NbSourceShapes();
486 for (i=0; i<aNbS; ++i) {
487 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
488 //
489 if (aSI.ShapeType()!=TopAbs_SOLID) {
490 continue;
491 }
492 //
493 const TopoDS_Shape& aS=aSI.Shape();
494 if (!aMFence.Add(aS)) {
495 continue;
496 }
497 if(theDraftSolids.IsBound(aS)) {
498 continue;
499 }
500 //
501 BOPTools_Set aST;
502 //
503 aST.Add(aS, TopAbs_FACE);
504 aMST.Add(aST);
505 //
506 } //for (i=1; i<=aNbS; ++i)
507 //
508 // 1. Build solids for interferred source solids
509 for (i=0; i<aNbS; ++i) {
510 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
511 //
512 if (aSI.ShapeType()!=TopAbs_SOLID) {
513 continue;
514 }
515 //
516 const TopoDS_Shape& aS=aSI.Shape();
517 const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS));
518 if(!theDraftSolids.IsBound(aS)) {
519 continue;
520 }
521 const TopoDS_Shape& aSD=theDraftSolids.Find(aS);
522 const BOPCol_ListOfShape& aLFIN=
523 (theInParts.IsBound(aS)) ? theInParts.Find(aS) : aLSEmpty;
524 //
525 // 1.1 Fill Shell Faces Set
526 aSFS.Clear();
527 aExp.Init(aSD, TopAbs_FACE);
528 for (; aExp.More(); aExp.Next()) {
529 const TopoDS_Shape& aF=aExp.Current();
530 aSFS.Append(aF);
531 }
532 //
533 aIt.Initialize(aLFIN);
534 for (; aIt.More(); aIt.Next()) {
535 TopoDS_Shape aF=aIt.Value();
536 //
537 aF.Orientation(TopAbs_FORWARD);
538 aSFS.Append(aF);
539 aF.Orientation(TopAbs_REVERSED);
540 aSFS.Append(aF);
541 }
542 //
543 // 1.3 Build new solids
544 Handle(NCollection_IncAllocator) aAlr1;
545 aAlr1=new NCollection_IncAllocator();
546 //
547 BOPAlgo_BuilderSolid& aBS=aVBS.Append1();
548 aBS.SetSolid(aSolid);
549 aBS.SetShapes(aSFS);
550 }//for (i=0; i<aNbS; ++i) {
551 //
552 Standard_Integer k, aNbBS;
553 //
554 aNbBS=aVBS.Extent();
555 //
556 //===================================================
557 BOPAlgo_BuilderSolidCnt::Perform(myRunParallel, aVBS);
558 //===================================================
559 //
560 for (k=0; k<aNbBS; ++k) {
561 BOPAlgo_BuilderSolid& aBS=aVBS(k);
562 const TopoDS_Solid& aS=aBS.Solid();
563 const BOPCol_ListOfShape& aLSR=aBS.Areas();
564 //
565 if (!myImages.IsBound(aS)) {
566 BOPCol_ListOfShape aLSx;
567 //
568 myImages.Bind(aS, aLSx);
569 BOPCol_ListOfShape& aLSIm=myImages.ChangeFind(aS);
570 //
571 aIt.Initialize(aLSR);
572 for (; aIt.More(); aIt.Next()) {
573 BOPTools_Set aST;
574 //
575 const TopoDS_Shape& aSR=aIt.Value();
576 aST.Add(aSR, TopAbs_FACE);
577 //
578 bFlagSD=aMST.Contains(aST);
579 //
580 const BOPTools_Set& aSTx=aMST.Added(aST);
581 const TopoDS_Shape& aSx=aSTx.Shape();
582 aLSIm.Append(aSx);
583 //
584 if (bFlagSD) {
585 myShapesSD.Bind(aSR, aSx);
586 }
587 }
588 }
589 }
590}
591//=======================================================================
592//function :FillInternalShapes
593//purpose :
594//=======================================================================
595void BOPAlgo_Builder::FillInternalShapes()
596{
597 myErrorStatus=0;
598 //
599 Standard_Integer i, j, aNbS, aNbSI, aNbSx;
600 TopAbs_ShapeEnum aType;
601 TopAbs_State aState;
602 TopoDS_Iterator aItS;
603 BRep_Builder aBB;
604 BOPCol_MapIteratorOfMapOfShape aItM;
605 BOPCol_ListIteratorOfListOfShape aIt, aIt1;
606 //
607 Handle(NCollection_IncAllocator) aAllocator;
608 //-----------------------------------------------------scope f
609 aAllocator=new NCollection_IncAllocator();
610 //
611 BOPCol_IndexedDataMapOfShapeListOfShape aMSx(100, aAllocator);
612 BOPCol_IndexedMapOfShape aMx(100, aAllocator);
613 BOPCol_MapOfShape aMSI(100, aAllocator);
614 BOPCol_MapOfShape aMFence(100, aAllocator);
615 BOPCol_MapOfShape aMSOr(100, aAllocator);
616 BOPCol_ListOfShape aLSd(aAllocator);
617 BOPCol_ListOfShape aLArgs(aAllocator);
618 BOPCol_ListOfShape aLSC(aAllocator);
619 //
620 // 1. Shapes to process
621 //
622 // 1.1 Shapes from pure arguments aMSI
623 // 1.1.1 vertex, edge, wire
624 //
625 aIt.Initialize(myArguments);
626 for (; aIt.More(); aIt.Next()) {
627 const TopoDS_Shape& aS=aIt.Value();
628 TreatCompound(aS, aMFence, aLSC);
629 }
630 aIt.Initialize(aLSC);
631 for (; aIt.More(); aIt.Next()) {
632 const TopoDS_Shape& aS=aIt.Value();
633 aType=aS.ShapeType();
634 if (aType==TopAbs_WIRE) {
635 aItS.Initialize(aS);
636 for(; aItS.More(); aItS.Next()) {
637 const TopoDS_Shape& aE=aItS.Value();
638 if (aMFence.Add(aE)) {
639 aLArgs.Append(aE);
640 }
641 }
642 }
643 else if (aType==TopAbs_VERTEX || aType==TopAbs_EDGE){
644 aLArgs.Append(aS);
645 }
646 }
647 aMFence.Clear();
648 //
649 aIt.Initialize(aLArgs);
650 for (; aIt.More(); aIt.Next()) {
651 const TopoDS_Shape& aS=aIt.Value();
652 aType=aS.ShapeType();
653 if (aType==TopAbs_VERTEX || aType==TopAbs_EDGE ||aType==TopAbs_WIRE) {
654 if (aMFence.Add(aS)) {
655 if (myImages.IsBound(aS)) {
656 const BOPCol_ListOfShape &aLSp=myImages.Find(aS);
657 aIt1.Initialize(aLSp);
658 for (; aIt1.More(); aIt1.Next()) {
659 const TopoDS_Shape& aSp=aIt1.Value();
660 aMSI.Add(aSp);
661 }
662 }
663 else {
664 aMSI.Add(aS);
665 }
666 }
667 }
668 }
669
670 aNbSI=aMSI.Extent();
671 //
672 // 2. Internal vertices, edges from source solids
673 aMFence.Clear();
674 aLSd.Clear();
675 //
676 aNbS=myDS->NbSourceShapes();
677 for (i=0; i<aNbS; ++i) {
678 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
679 //
680 if (aSI.ShapeType()!=TopAbs_SOLID) {
681 continue;
682 }
683 //
684 const TopoDS_Shape& aS=aSI.Shape();
685 //
686 aMx.Clear();
687 OwnInternalShapes(aS, aMx);
688 //
689 aNbSx=aMx.Extent();
690 for (j=1; j<=aNbSx; ++j) {
691 const TopoDS_Shape& aSi=aMx(j);
692 if (myImages.IsBound(aSi)) {
693 const BOPCol_ListOfShape &aLSp=myImages.Find(aSi);
694 aIt1.Initialize(aLSp);
695 for (; aIt1.More(); aIt1.Next()) {
696 const TopoDS_Shape& aSp=aIt1.Value();
697 aMSI.Add(aSp);
698 }
699 }
700 else {
701 aMSI.Add(aSi);
702 }
703 }
704 //
705 // build aux map from splits of solids
706 if (myImages.IsBound(aS)) {
707 const BOPCol_ListOfShape &aLSp=myImages.Find(aS);
708 aIt.Initialize(aLSp);
709 for (; aIt.More(); aIt.Next()) {
710 const TopoDS_Shape& aSp=aIt.Value();
711 if (aMFence.Add(aSp)) {
712 BOPTools::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_EDGE, aMSx);
713 BOPTools::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_FACE, aMSx);
714 BOPTools::MapShapesAndAncestors(aSp, TopAbs_EDGE , TopAbs_FACE, aMSx);
715 aLSd.Append(aSp);
716 }
717 }
718 }
719 else {
720 if (aMFence.Add(aS)) {
721 BOPTools::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_EDGE, aMSx);
722 BOPTools::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_FACE, aMSx);
723 BOPTools::MapShapesAndAncestors(aS, TopAbs_EDGE , TopAbs_FACE, aMSx);
724 aLSd.Append(aS);
725 aMSOr.Add(aS);
726 }
727 }
728 }// for (i=0; i<aNbS; ++i) {
729 //
730 // 3. Some shapes of aMSI can be already tied with faces of
731 // split solids
732 aItM.Initialize(aMSI);
733 for (; aItM.More(); aItM.Next()) {
734 const TopoDS_Shape& aSI=aItM.Key();
735 if (aMSx.Contains(aSI)) {
736 const BOPCol_ListOfShape &aLSx=aMSx.FindFromKey(aSI);
737 aNbSx=aLSx.Extent();
738 if (aNbSx) {
739 aMSI.Remove(aSI);
740 }
741 }
742 }
743 //
744 // 4. Just check it
745 aNbSI=aMSI.Extent();
746 if (!aNbSI) {
747 return;
748 }
749 //
750 // 5 Settle internal vertices and edges into solids
751 aMx.Clear();
752 aIt.Initialize(aLSd);
753 for (; aIt.More(); aIt.Next()) {
754 TopoDS_Solid aSd=TopoDS::Solid(aIt.Value());
755 //
756 aItM.Initialize(aMSI);
757 for (; aItM.More(); aItM.Next()) {
758 TopoDS_Shape aSI=aItM.Key();
759 aSI.Orientation(TopAbs_INTERNAL);
760 //
761 aState=BOPTools_AlgoTools::ComputeStateByOnePoint(aSI, aSd, 1.e-11, myContext);
762 if (aState==TopAbs_IN) {
763 //
764 if(aMSOr.Contains(aSd)) {
765 //
766 TopoDS_Solid aSdx;
767 //
768 aBB.MakeSolid(aSdx);
769 aItS.Initialize(aSd);
770 for (; aItS.More(); aItS.Next()) {
771 const TopoDS_Shape& aSh=aItS.Value();
772 aBB.Add(aSdx, aSh);
773 }
774 //
775 aBB.Add(aSdx, aSI);
776 //
777 if (myImages.IsBound(aSdx)) {
778 BOPCol_ListOfShape& aLS=myImages.ChangeFind(aSdx);
779 aLS.Append(aSdx);
780 }
781 else {
782 BOPCol_ListOfShape aLS;
783 aLS.Append(aSdx);
784 myImages.Bind(aSd, aLS);
785 }
786 //
787 aMSOr.Remove(aSd);
788 aSd=aSdx;
789 }
790 else {
791 aBB.Add(aSd, aSI);
792 }
793 //
794 aMSI.Remove(aSI);
795 } //if (aState==TopAbs_IN) {
796 }// for (; aItM.More(); aItM.Next()) {
797 }//for (; aIt1.More(); aIt1.Next()) {
798 //
799 //-----------------------------------------------------scope t
800 aLArgs.Clear();
801 aLSd.Clear();
802 aMSOr.Clear();
803 aMFence.Clear();
804 aMSI.Clear();
805 aMx.Clear();
806 aMSx.Clear();
807}
808//=======================================================================
809//function : OwnInternalShapes
810//purpose :
811//=======================================================================
812 void OwnInternalShapes(const TopoDS_Shape& theS,
813 BOPCol_IndexedMapOfShape& theMx)
814{
815 TopoDS_Iterator aIt;
816 //
817 aIt.Initialize(theS);
818 for (; aIt.More(); aIt.Next()) {
819 const TopoDS_Shape& aSx=aIt.Value();
820 if (aSx.ShapeType()!=TopAbs_SHELL) {
821 theMx.Add(aSx);
822 }
823 }
824}
825//=======================================================================
826//function : TreatCompound
827//purpose :
828//=======================================================================
829void TreatCompound(const TopoDS_Shape& theS,
830 BOPCol_MapOfShape& aMFence,
831 BOPCol_ListOfShape& theLS)
832{
833 TopAbs_ShapeEnum aType;
834 //
835 aType = theS.ShapeType();
836 if (aType != TopAbs_COMPOUND) {
837 if (aMFence.Add(theS)) {
838 theLS.Append(theS);
839 }
840 return;
841 }
842 //
843 TopoDS_Iterator aIt;
844 //
845 aIt.Initialize(theS);
846 for (; aIt.More(); aIt.Next()) {
847 const TopoDS_Shape& aS = aIt.Value();
848 TreatCompound(aS, aMFence, theLS);
849 }
850}
851
852//
853// ErrorStatus
854// 30 - SolidBuilder failed
855// A