1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <BOPDS_DS.ixx>
17 #include <NCollection_IncAllocator.hxx>
18 #include <NCollection_BaseAllocator.hxx>
21 #include <Bnd_Box.hxx>
23 #include <TopoDS_Shape.hxx>
24 #include <TopoDS_Iterator.hxx>
25 #include <TopoDS_Vertex.hxx>
26 #include <TopoDS_Edge.hxx>
27 #include <TopoDS_Face.hxx>
28 #include <BRep_Tool.hxx>
30 #include <BRepBndLib.hxx>
32 #include <BOPCol_MapOfInteger.hxx>
33 #include <BOPCol_ListOfInteger.hxx>
34 #include <BOPCol_DataMapOfShapeInteger.hxx>
36 #include <BOPDS_IndexRange.hxx>
37 #include <BOPDS_ShapeInfo.hxx>
38 #include <BOPDS_PassKey.hxx>
39 #include <BOPDS_DataMapOfPassKeyListOfPaveBlock.hxx>
40 #include <BOPDS_PassKey.hxx>
41 #include <BOPDS_MapOfPave.hxx>
42 #include <BOPDS_MapOfPaveBlock.hxx>
44 #include <Geom_Curve.hxx>
45 #include <BRep_Builder.hxx>
46 #include <Precision.hxx>
47 #include <IntTools_Tools.hxx>
48 #include <BOPTools_AlgoTools.hxx>
49 #include <GeomAPI_ProjectPointOnCurve.hxx>
53 inline void ResetShape(const TopoDS_Shape& aS);
56 inline void ResetShapes(const TopoDS_Shape& aS);
59 void TotalShapes(const TopoDS_Shape& aS,
60 Standard_Integer& aNbS);
63 Standard_Real ComputeParameter(const TopoDS_Vertex& aV,
64 const TopoDS_Edge& aE);
66 void SortShell(const int n, BOPDS_Pave *a);
68 //=======================================================================
71 //=======================================================================
74 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
75 myArguments(myAllocator),
76 myRanges(myAllocator),
78 myMapShapeIndex(100, myAllocator),
79 myPaveBlocksPool(myAllocator),
80 myMapPBCB(100, myAllocator),
81 myFaceInfoPool(myAllocator),
82 myShapesSD(100, myAllocator),
83 myInterfTB(100, myAllocator),
84 myInterfVV(myAllocator),
85 myInterfVE(myAllocator),
86 myInterfVF(myAllocator),
87 myInterfEE(myAllocator),
88 myInterfEF(myAllocator),
89 myInterfFF(myAllocator),
90 myInterfVZ(myAllocator),
91 myInterfEZ(myAllocator),
92 myInterfFZ(myAllocator),
93 myInterfZZ(myAllocator)
98 //=======================================================================
101 //=======================================================================
102 BOPDS_DS::BOPDS_DS(const Handle(NCollection_BaseAllocator)& theAllocator)
104 myAllocator(theAllocator),
105 myArguments(myAllocator),
106 myRanges(myAllocator),
107 myLines(myAllocator),
108 myMapShapeIndex(100, myAllocator),
109 myPaveBlocksPool(myAllocator),
110 myMapPBCB(100, myAllocator),
111 myFaceInfoPool(myAllocator),
112 myShapesSD(100, myAllocator),
113 myInterfTB(100, myAllocator),
114 myInterfVV(myAllocator),
115 myInterfVE(myAllocator),
116 myInterfVF(myAllocator),
117 myInterfEE(myAllocator),
118 myInterfEF(myAllocator),
119 myInterfFF(myAllocator),
120 myInterfVZ(myAllocator),
121 myInterfEZ(myAllocator),
122 myInterfFZ(myAllocator),
123 myInterfZZ(myAllocator)
128 //=======================================================================
131 //=======================================================================
132 BOPDS_DS::~BOPDS_DS()
136 //=======================================================================
139 //=======================================================================
140 void BOPDS_DS::Clear()
148 myMapShapeIndex.Clear();
149 myPaveBlocksPool.Clear();
150 myFaceInfoPool.Clear();
165 //=======================================================================
166 //function : SetArguments
168 //=======================================================================
169 void BOPDS_DS::SetArguments(const BOPCol_ListOfShape& theLS)
173 //=======================================================================
174 //function : Arguments
176 //=======================================================================
177 const BOPCol_ListOfShape& BOPDS_DS::Arguments()const
181 //=======================================================================
182 //function : Allocator
184 //=======================================================================
185 const Handle(NCollection_BaseAllocator)& BOPDS_DS::Allocator()const
190 //=======================================================================
191 //function : NbShapes
193 //=======================================================================
194 Standard_Integer BOPDS_DS::NbShapes()const
196 return myLines.Size();
198 //=======================================================================
199 //function : NbSourceShapes
201 //=======================================================================
202 Standard_Integer BOPDS_DS::NbSourceShapes()const
204 return myNbSourceShapes;
206 //=======================================================================
207 //function : NbRanges
209 //=======================================================================
210 Standard_Integer BOPDS_DS::NbRanges()const
212 return myRanges.Size();
214 //=======================================================================
217 //=======================================================================
218 const BOPDS_IndexRange& BOPDS_DS::Range(const Standard_Integer theI)const
220 return myRanges(theI);
222 //=======================================================================
225 //=======================================================================
226 Standard_Integer BOPDS_DS::Rank(const Standard_Integer theI)const
228 Standard_Integer i, aNb, iErr;
232 for(i=0; i<aNb; ++i) {
233 const BOPDS_IndexRange& aR=Range(i);
234 if (aR.Contains(theI)) {
240 //=======================================================================
241 //function : IsNewShape
243 //=======================================================================
244 Standard_Boolean BOPDS_DS::IsNewShape(const Standard_Integer theI)const
246 return theI>=NbSourceShapes();
248 //=======================================================================
251 //=======================================================================
252 Standard_Integer BOPDS_DS::Append(const BOPDS_ShapeInfo& theSI)
256 iX=myLines.Append()-1;
260 //=======================================================================
263 //=======================================================================
264 Standard_Integer BOPDS_DS::Append(const TopoDS_Shape& theS)
268 iX=myLines.Append()-1;
269 myLines(iX).SetShape(theS);
272 //=======================================================================
273 //function : ShapeInfo
275 //=======================================================================
276 const BOPDS_ShapeInfo& BOPDS_DS::ShapeInfo
277 (const Standard_Integer theI)const
279 return myLines(theI);
281 //=======================================================================
282 //function : ChangeShapeInfo
284 //=======================================================================
285 BOPDS_ShapeInfo& BOPDS_DS::ChangeShapeInfo(const Standard_Integer theI)
287 BOPDS_ShapeInfo *pSI;
289 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI);
290 pSI=(BOPDS_ShapeInfo *)&aSI;
293 //=======================================================================
296 //=======================================================================
297 const TopoDS_Shape& BOPDS_DS::Shape(const Standard_Integer theI)const
299 const TopoDS_Shape& aS=ShapeInfo(theI).Shape();
302 //=======================================================================
305 //=======================================================================
306 Standard_Integer BOPDS_DS::Index(const TopoDS_Shape& theS)const
308 Standard_Integer iRet;
311 if (myMapShapeIndex.IsBound(theS)) {
312 iRet=myMapShapeIndex.Find(theS);
317 //=======================================================================
320 //=======================================================================
321 void BOPDS_DS::Init()
323 Standard_Integer i1, i2, j, aI, aNb, aNbS, aNbE, aNbSx;
324 Standard_Integer n1, n2, n3, nV, nW, nE, aNbF;
326 TopAbs_ShapeEnum aTS;
327 TopoDS_Iterator aItS;
328 BOPCol_ListIteratorOfListOfInteger aIt1, aIt2, aIt3;
329 BOPCol_ListIteratorOfListOfShape aIt;
331 Handle(NCollection_IncAllocator) aAllocator;
333 // 1 Append Source Shapes
334 aNb=myArguments.Extent();
339 myRanges.SetStartSize(aNb);
342 aIt.Initialize(myArguments);
343 for (; aIt.More(); aIt.Next()) {
344 const TopoDS_Shape& aSx=aIt.Value();
349 aIt.Initialize(myArguments);
350 for (; aIt.More(); aIt.Next()) {
351 const TopoDS_Shape& aSx=aIt.Value();
354 TotalShapes(aSx, aNbSx);
358 myLines.SetStartSize(2*aNbS);
359 myLines.SetIncrement(aNbS);
362 //-----------------------------------------------------scope_1 f
363 aAllocator=new NCollection_IncAllocator();
365 BOPCol_DataMapOfShapeInteger& aMSI=myMapShapeIndex;
369 aIt.Initialize(myArguments);
370 for (; aIt.More(); aIt.Next()) {
371 const TopoDS_Shape& aS=aIt.Value();
372 if (aMSI.IsBound(aS)) {
378 InitShape(aI, aS, aAllocator, aMSI);
381 aR.SetIndices(i1, i2);
386 myNbSourceShapes=NbShapes();
391 for (j=0; j<myNbSourceShapes; ++j) {
392 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
394 const TopoDS_Shape& aS=aSI.Shape();
399 if (aTS==TopAbs_VERTEX) {
400 Bnd_Box& aBox=aSI.ChangeBox();
401 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aS);
402 const gp_Pnt& aP=BRep_Tool::Pnt(aV);
403 aTol=BRep_Tool::Tolerance(aV);
410 for (j=0; j<myNbSourceShapes; ++j) {
411 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
414 if (aTS==TopAbs_EDGE) {
415 const TopoDS_Shape& aS=aSI.Shape();
416 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aS);
417 aTol=BRep_Tool::Tolerance(aE);
419 if (!BRep_Tool::Degenerated(aE)) {
420 Standard_Boolean bInf1, bInf2;
421 Standard_Integer aIx;
422 Standard_Real aT1, aT2;
424 Handle(Geom_Curve) aC3D;
428 BOPDS_ShapeInfo aSIx;
430 BOPCol_ListOfInteger& aLI=aSI.ChangeSubShapes();
433 aEx.Orientation(TopAbs_FORWARD);
435 aC3D=BRep_Tool::Curve (aEx, aT1, aT2);
436 bInf1=Precision::IsNegativeInfinite(aT1);
437 bInf2=Precision::IsPositiveInfinite(aT2);
441 aBB.MakeVertex(aVx, aPx, aTol);
442 aVx.Orientation(TopAbs_FORWARD);
445 aSIx.SetShapeType(TopAbs_VERTEX);
446 aSIx.SetFlag(1); //infinite flag
453 aBB.MakeVertex(aVx, aPx, aTol);
454 aVx.Orientation(TopAbs_REVERSED);
457 aSIx.SetShapeType(TopAbs_VERTEX);
458 aSIx.SetFlag(1);//infinite flag
468 Bnd_Box& aBox=aSI.ChangeBox();
469 BRepBndLib::Add(aE, aBox);
471 const BOPCol_ListOfInteger& aLV=aSI.SubShapes();
472 aIt1.Initialize(aLV);
473 for (; aIt1.More(); aIt1.Next()) {
475 BOPDS_ShapeInfo& aSIV=ChangeShapeInfo(nV);
476 Bnd_Box& aBx=aSIV.ChangeBox();
483 BOPCol_MapOfInteger aMI(100, aAllocator);
484 BOPCol_MapIteratorOfMapOfInteger aItMI;
487 for (j=0; j<myNbSourceShapes; ++j) {
488 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
491 if (aTS==TopAbs_FACE) {
492 const TopoDS_Shape& aS=aSI.Shape();
493 const TopoDS_Face& aF=*((TopoDS_Face*)&aS);
494 aTol=BRep_Tool::Tolerance(aF);
496 Bnd_Box& aBox=aSI.ChangeBox();
497 BRepBndLib::Add(aS, aBox);
499 BOPCol_ListOfInteger& aLW=aSI.ChangeSubShapes();
500 aIt1.Initialize(aLW);
501 for (; aIt1.More(); aIt1.Next()) {
503 BOPDS_ShapeInfo& aSIW=ChangeShapeInfo(nW);
505 const BOPCol_ListOfInteger& aLE=aSIW.SubShapes();
506 aIt2.Initialize(aLE);
507 for (; aIt2.More(); aIt2.Next()) {
509 BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
510 Bnd_Box& aBx=aSIE.ChangeBox();
514 const TopoDS_Edge& aE=*(TopoDS_Edge*)(&aSIE.Shape());
515 if (BRep_Tool::Degenerated(aE)) {
519 const BOPCol_ListOfInteger& aLV=aSIE.SubShapes();
520 aIt3.Initialize(aLV);
521 for (; aIt3.More(); aIt3.Next()) {
526 }//for (; aIt1.More(); aIt1.Next()) {
528 // pure internal vertices on the face
530 for (; aItS.More(); aItS.Next()) {
531 const TopoDS_Shape& aSx=aItS.Value();
532 if (aSx.ShapeType()==TopAbs_VERTEX){
539 // For a Face: change wires for BRep sub-shapes
541 aItMI.Initialize(aMI);
542 for (; aItMI.More(); aItMI.Next()) {
548 }//if (aTS==TopAbs_FACE) {
549 }//for (j=0; j<myNbSourceShapes; ++j) {
552 for (j=0; j<myNbSourceShapes; ++j) {
553 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(j);
556 if (aTS!=TopAbs_SOLID) {
559 Bnd_Box& aBox=aSI.ChangeBox();
560 BuildBndBoxSolid(j, aBox);
563 // update sub-shapes by BRep comprising ones
565 BOPCol_ListOfInteger& aLI1=aSI.ChangeSubShapes();
567 aIt1.Initialize(aLI1);
568 for (; aIt1.More(); aIt1.Next()) {
570 BOPDS_ShapeInfo& aSI1=ChangeShapeInfo(n1);
571 if (aSI1.ShapeType()!=TopAbs_SHELL) {
575 const BOPCol_ListOfInteger& aLI2=aSI1.SubShapes();
576 aIt2.Initialize(aLI2);
577 for (; aIt2.More(); aIt2.Next()) {
579 BOPDS_ShapeInfo& aSI2=ChangeShapeInfo(n2);
580 if (aSI2.ShapeType()!=TopAbs_FACE) {
586 const BOPCol_ListOfInteger& aLI3=aSI2.SubShapes();
587 aIt3.Initialize(aLI3);
588 for (; aIt3.More(); aIt3.Next()) {
596 aItMI.Initialize(aMI);
597 for (; aItMI.More(); aItMI.Next()) {
602 }//for (j=0; j<myNbSourceShapes; ++j) {
605 aAllocator.Nullify();
606 //-----------------------------------------------------scope_1 t
608 // 3 myPaveBlocksPool
609 myPaveBlocksPool.SetStartSize(aNbE);
610 myPaveBlocksPool.SetIncrement(aNbE);
611 myPaveBlocksPool.Init();
614 myFaceInfoPool.SetStartSize(aNbF);
615 myFaceInfoPool.SetIncrement(aNbF);
616 myFaceInfoPool.Init();
619 //=======================================================================
620 //function : InitShape
622 //=======================================================================
623 void BOPDS_DS::InitShape
624 (const Standard_Integer aI,
625 const TopoDS_Shape& aS,
626 Handle(NCollection_BaseAllocator)& theAllocator,
627 BOPCol_DataMapOfShapeInteger& aMSI)
629 Standard_Integer aIx;
631 BOPCol_ListIteratorOfListOfInteger aIt1;
633 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(aI);
634 aSI.SetShapeType(aS.ShapeType());
635 BOPCol_ListOfInteger& aLI=aSI.ChangeSubShapes();
637 BOPCol_MapOfInteger aM(100, theAllocator);
639 aIt1.Initialize(aLI);
640 for (; aIt1.More(); aIt1.Next()) {
641 aM.Add(aIt1.Value());
645 for (; aIt.More(); aIt.Next()) {
646 const TopoDS_Shape& aSx=aIt.Value();
647 if (aMSI.IsBound(aSx)) {
655 InitShape(aIx, aSx, theAllocator, aMSI);
663 //=======================================================================
664 //function : HasInterf
666 //=======================================================================
667 Standard_Boolean BOPDS_DS::HasInterf(const Standard_Integer theI) const
669 Standard_Integer n1, n2;
670 Standard_Boolean bRet;
671 BOPDS_MapIteratorMapOfPassKey aIt;
673 bRet = Standard_False;
675 aIt.Initialize(myInterfTB);
676 for (; aIt.More(); aIt.Next()) {
677 const BOPDS_PassKey& aPK = aIt.Value();
679 if (n1 == theI || n2 == theI) {
680 bRet = Standard_True;
687 //=======================================================================
688 //function : HasInterfShapeSubShapes
690 //=======================================================================
691 Standard_Boolean BOPDS_DS::HasInterfShapeSubShapes
692 (const Standard_Integer theI1,
693 const Standard_Integer theI2,
694 const Standard_Boolean theFlag)const
696 Standard_Boolean bRet;
698 BOPCol_ListIteratorOfListOfInteger aIt;
699 bRet = Standard_False;
701 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI2);
702 const BOPCol_ListOfInteger& aLI=aSI.SubShapes();
704 for (; aIt.More(); aIt.Next()) {
706 bRet=HasInterf(theI1, n2);
720 //=======================================================================
721 //function : HasInterfSubShapes
723 //=======================================================================
724 Standard_Boolean BOPDS_DS::HasInterfSubShapes
725 (const Standard_Integer theI1,
726 const Standard_Integer theI2)const
728 Standard_Boolean bRet;
730 BOPCol_ListIteratorOfListOfInteger aIt;
731 bRet = Standard_False;
733 const BOPDS_ShapeInfo& aSI=ShapeInfo(theI1);
734 const BOPCol_ListOfInteger& aLI=aSI.SubShapes();
736 for (; aIt.More(); aIt.Next()) {
738 bRet=HasInterfShapeSubShapes(n1, theI2);
747 //=======================================================================
748 //function : PaveBlocksPool
750 //=======================================================================
751 const BOPDS_VectorOfListOfPaveBlock& BOPDS_DS::PaveBlocksPool()const
753 return myPaveBlocksPool;
755 //=======================================================================
756 //function : ChangePaveBlocksPool
758 //=======================================================================
759 BOPDS_VectorOfListOfPaveBlock& BOPDS_DS::ChangePaveBlocksPool()
761 return myPaveBlocksPool;
763 //=======================================================================
764 //function : HasPaveBlocks
766 //=======================================================================
767 Standard_Boolean BOPDS_DS::HasPaveBlocks(const Standard_Integer theI)const
769 return ShapeInfo(theI).HasReference();
771 //=======================================================================
772 //function : PaveBlocks
774 //=======================================================================
775 const BOPDS_ListOfPaveBlock& BOPDS_DS::PaveBlocks
776 (const Standard_Integer theI)const
778 static BOPDS_ListOfPaveBlock sLPB;
779 Standard_Integer aRef;
781 if (HasPaveBlocks(theI)) {
782 aRef=ShapeInfo(theI).Reference();
783 const BOPDS_ListOfPaveBlock& aLPB=myPaveBlocksPool(aRef);
788 //=======================================================================
789 //function : ChangePaveBlocks
791 //=======================================================================
792 BOPDS_ListOfPaveBlock& BOPDS_DS::ChangePaveBlocks
793 (const Standard_Integer theI)
795 Standard_Boolean bHasReference;
796 Standard_Integer aRef;
798 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
799 bHasReference=aSI.HasReference();
800 if (!bHasReference) {
801 InitPaveBlocks(theI);
804 aRef=aSI.Reference();
805 return myPaveBlocksPool(aRef);
807 //=======================================================================
808 //function : InitPaveBlocks
810 //=======================================================================
811 void BOPDS_DS::InitPaveBlocks(const Standard_Integer theI)
813 Standard_Integer nV = 0, iRef, aNbV, nVSD, i;
816 BOPCol_ListIteratorOfListOfInteger aIt;
818 Handle(BOPDS_PaveBlock) aPB;
820 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
821 const TopoDS_Edge& aE=*(TopoDS_Edge*)(&aSI.Shape());
823 const BOPCol_ListOfInteger& aLV=aSI.SubShapes();
829 aPB=new BOPDS_PaveBlock;
830 aPB->SetOriginalEdge(theI);
833 for (i=0; aIt.More(); aIt.Next(), ++i) {
836 const BOPDS_ShapeInfo& aSIV=ShapeInfo(nV);
837 aV=*(TopoDS_Vertex*)(&aSIV.Shape());
838 if (aSIV.HasFlag()) {
839 aT=ComputeParameter(aV, aE);
842 aT=BRep_Tool::Parameter(aV, aE);
845 if (HasShapeSD(nV, nVSD)) {
849 aPave.SetParameter(aT);
850 aPB->AppendExtPave(aPave);
855 aT=BRep_Tool::Parameter(aV, aE);
857 aPave.SetParameter(aT);
858 aPB->AppendExtPave1(aPave);
861 iRef = myPaveBlocksPool.Append() - 1;
862 BOPDS_ListOfPaveBlock &aLPB=myPaveBlocksPool(iRef);
864 aPB->Update(aLPB, Standard_False);
865 aSI.SetReference(iRef);
867 //=======================================================================
868 //function : UpdatePaveBlocks
870 //=======================================================================
871 void BOPDS_DS::UpdatePaveBlocks()
873 Standard_Boolean bIsToUpdate;
874 Standard_Integer i, aNbPBP;
875 BOPDS_ListOfPaveBlock aLPBN(myAllocator);
876 BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBN;
878 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
881 for (i=0; i<aNbPBP; ++i) {
882 BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
884 aItPB.Initialize(aLPB);
885 for (; aItPB.More(); aItPB.Next()) {
886 Handle(BOPDS_PaveBlock)& aPB=aItPB.ChangeValue();
888 bIsToUpdate=aPB->IsToUpdate();
893 aItPBN.Initialize(aLPBN);
894 for (; aItPBN.More(); aItPBN.Next()) {
895 Handle(BOPDS_PaveBlock)& aPBN=aItPBN.ChangeValue();
900 }// for (; aItPB.More(); aItPB.Next()) {
901 }// for (i=0; i<aNbPBP; ++i) {
903 //=======================================================================
904 //function : UpdatePaveBlock
906 //=======================================================================
907 void BOPDS_DS::UpdatePaveBlock(const Handle(BOPDS_PaveBlock)& thePB)
909 if (!thePB->IsToUpdate()){
913 Standard_Integer nE, iRef;
914 BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBN;
915 BOPDS_ListOfPaveBlock aLPBN(myAllocator);
916 Handle(BOPDS_PaveBlock) aPB;
918 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
920 nE=thePB->OriginalEdge();
921 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(nE);
922 iRef=aSI.Reference();
923 BOPDS_ListOfPaveBlock& aLPB=aPBP(iRef);
925 aItPB.Initialize(aLPB);
926 for (; aItPB.More(); aItPB.Next()) {
927 aPB=aItPB.ChangeValue();
931 aItPBN.Initialize(aLPBN);
932 for (; aItPBN.More(); aItPBN.Next()) {
933 Handle(BOPDS_PaveBlock)& aPBN=aItPBN.ChangeValue();
941 //=======================================================================
942 //function : UpdateCommonBlock
944 //=======================================================================
945 void BOPDS_DS::UpdateCommonBlock(const Handle(BOPDS_CommonBlock)& theCB)
947 Standard_Integer nE, iRef, n1, n2;
948 BOPDS_ListIteratorOfListOfPaveBlock aItPB, aItPBCB, aItPBN;
949 BOPDS_DataMapIteratorOfDataMapOfPassKeyListOfPaveBlock aItMPKLPB;
950 BOPDS_ListOfPaveBlock aLPBN;
951 BOPDS_DataMapOfPassKeyListOfPaveBlock aMPKLPB;
952 Handle(BOPDS_PaveBlock) aPB;
953 Handle(BOPDS_CommonBlock) aCBx;
956 const BOPDS_ListOfPaveBlock& aLPBCB=theCB->PaveBlocks();
957 if (!aLPBCB.First()->IsToUpdate()){
961 const BOPCol_ListOfInteger& aLF=theCB->Faces();
963 BOPDS_VectorOfListOfPaveBlock& aPBP=myPaveBlocksPool;
965 aItPBCB.Initialize(aLPBCB);
966 for (; aItPBCB.More(); aItPBCB.Next()) {
967 const Handle(BOPDS_PaveBlock)& aPBCB=aItPBCB.ChangeValue();
969 nE=aPBCB->OriginalEdge();
970 iRef=ChangeShapeInfo(nE).Reference();
971 BOPDS_ListOfPaveBlock& aLPB=aPBP(iRef);
973 aItPB.Initialize(aLPB);
974 for (; aItPB.More(); aItPB.Next()) {
975 aPB=aItPB.ChangeValue();
981 aItPBN.Initialize(aLPBN);
982 for (; aItPBN.More(); aItPBN.Next()) {
983 Handle(BOPDS_PaveBlock)& aPBN=aItPBN.ChangeValue();
986 aPBN->Indices(n1, n2);
988 if (aMPKLPB.IsBound(aPK)) {
989 BOPDS_ListOfPaveBlock& aLPBx=aMPKLPB.ChangeFind(aPK);
993 BOPDS_ListOfPaveBlock aLPBx;
995 aMPKLPB.Bind(aPK, aLPBx);
1004 aItMPKLPB.Initialize(aMPKLPB);
1005 for (; aItMPKLPB.More(); aItMPKLPB.Next()) {
1006 BOPDS_ListOfPaveBlock& aLPBx=aItMPKLPB.ChangeValue();
1008 while (aLPBx.Extent()) {
1009 Standard_Boolean bCoinside;
1010 Standard_Real aTol, aTolMax(0.);
1011 BOPDS_ListOfPaveBlock aLPBxN;
1013 aItPB.Initialize(aLPBx);
1014 for(; aItPB.More(); ) {
1015 const Handle(BOPDS_PaveBlock)& aPBx=aItPB.Value();
1016 if (aLPBxN.Extent()) {
1017 const Handle(BOPDS_PaveBlock)& aPBCx = aLPBxN.First();
1018 bCoinside = CheckCoincidence(aPBx, aPBCx);
1020 nE = aPBx->OriginalEdge();
1021 const TopoDS_Edge& aE = *(TopoDS_Edge*)&Shape(nE);
1022 aTol = BRep_Tool::Tolerance(aE);
1024 //pave block with the max tolerance of the original edge
1025 //must be the first in the common block
1026 if (aTolMax < aTol) {
1028 aLPBxN.Prepend(aPBx);
1030 aLPBxN.Append(aPBx);
1032 aLPBx.Remove(aItPB);
1035 }//if (aLPBxN.Extent()) {
1037 nE = aPBx->OriginalEdge();
1038 const TopoDS_Edge& aE = *(TopoDS_Edge*)&Shape(nE);
1039 aTolMax = BRep_Tool::Tolerance(aE);
1041 aLPBxN.Append(aPBx);
1042 aLPBx.Remove(aItPB);
1046 }//for(; aItPB.More(); ) {
1048 aCBx=new BOPDS_CommonBlock;
1049 aCBx->AddPaveBlocks(aLPBxN);
1050 aCBx->AddFaces(aLF);
1052 aItPB.Initialize(aLPBxN);
1053 for (; aItPB.More(); aItPB.Next()) {
1054 aPB=aItPB.ChangeValue();
1055 SetCommonBlock(aPB, aCBx);
1061 //=======================================================================
1062 // function: RealPaveBlock
1064 //=======================================================================
1065 Handle(BOPDS_PaveBlock) BOPDS_DS::RealPaveBlock
1066 (const Handle(BOPDS_PaveBlock)& thePB) const
1068 if (IsCommonBlock(thePB)) {
1069 const Handle(BOPDS_CommonBlock)& aCB = CommonBlock(thePB);
1070 const Handle(BOPDS_PaveBlock)& aPB = aCB->PaveBlock1();
1076 //=======================================================================
1077 // function: IsCommonBlockOnEdge
1079 //=======================================================================
1080 Standard_Boolean BOPDS_DS::IsCommonBlockOnEdge
1081 (const Handle(BOPDS_PaveBlock)& thePB) const
1083 if (IsCommonBlock(thePB)) {
1084 const Handle(BOPDS_CommonBlock)& aCB = CommonBlock(thePB);
1085 return aCB->PaveBlocks().Extent()>1;
1087 return Standard_False;
1090 //=======================================================================
1091 //function : IsCommonBlock
1093 //=======================================================================
1094 Standard_Boolean BOPDS_DS::IsCommonBlock
1095 (const Handle(BOPDS_PaveBlock)& thePB) const
1097 return myMapPBCB.IsBound(thePB);
1100 //=======================================================================
1101 //function : CommonBlock
1103 //=======================================================================
1104 Handle(BOPDS_CommonBlock) BOPDS_DS::CommonBlock
1105 (const Handle(BOPDS_PaveBlock)& thePB) const
1107 return (IsCommonBlock(thePB) ? myMapPBCB.Find(thePB) : NULL);
1110 //=======================================================================
1111 //function : SetCommonBlock
1113 //=======================================================================
1114 void BOPDS_DS::SetCommonBlock(const Handle(BOPDS_PaveBlock)& thePB,
1115 const Handle(BOPDS_CommonBlock)& theCB)
1117 if (IsCommonBlock(thePB)) {
1118 Handle(BOPDS_CommonBlock)& aCB = myMapPBCB.ChangeFind(thePB);
1122 myMapPBCB.Bind(thePB, theCB);
1130 //=======================================================================
1131 //function : FaceInfoPool
1133 //=======================================================================
1134 const BOPDS_VectorOfFaceInfo& BOPDS_DS::FaceInfoPool()const
1136 return myFaceInfoPool;
1138 //=======================================================================
1139 //function : HasFaceInfo
1141 //=======================================================================
1142 Standard_Boolean BOPDS_DS::HasFaceInfo(const Standard_Integer theI)const
1144 return ShapeInfo(theI).HasReference();
1146 //=======================================================================
1147 //function : FaceInfo
1149 //=======================================================================
1150 const BOPDS_FaceInfo& BOPDS_DS::FaceInfo(const Standard_Integer theI)const
1152 static BOPDS_FaceInfo sFI;
1153 Standard_Integer aRef;
1155 if (HasFaceInfo(theI)) {
1156 aRef=ShapeInfo(theI).Reference();
1157 const BOPDS_FaceInfo& aFI=myFaceInfoPool(aRef);
1162 //=======================================================================
1163 //function : ChangeFaceInfo
1165 //=======================================================================
1166 BOPDS_FaceInfo& BOPDS_DS::ChangeFaceInfo(const Standard_Integer theI)
1168 Standard_Boolean bHasReference;
1169 Standard_Integer aRef;
1170 BOPDS_FaceInfo* pFI;
1172 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1173 bHasReference=aSI.HasReference();
1174 if (!bHasReference) {
1178 aRef=aSI.Reference();
1179 const BOPDS_FaceInfo& aFI=myFaceInfoPool(aRef);
1180 pFI=(BOPDS_FaceInfo*)&aFI;
1183 //=======================================================================
1184 //function : InitFaceInfo
1186 //=======================================================================
1187 void BOPDS_DS::InitFaceInfo(const Standard_Integer theI)
1189 Standard_Integer iRef;
1191 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1192 iRef=myFaceInfoPool.Append()-1;
1193 BOPDS_FaceInfo &aFI=myFaceInfoPool(iRef);
1194 aSI.SetReference(iRef);
1197 UpdateFaceInfoIn(theI);
1198 UpdateFaceInfoOn(theI);
1200 //=======================================================================
1201 //function : UpdateFaceInfoIn
1203 //=======================================================================
1204 void BOPDS_DS::UpdateFaceInfoIn(const Standard_Integer theI)
1206 Standard_Integer iRef;
1208 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1209 if (aSI.HasReference()) {
1210 iRef=aSI.Reference();
1211 BOPDS_FaceInfo &aFI=myFaceInfoPool(iRef);
1213 BOPDS_IndexedMapOfPaveBlock& aMPBIn=aFI.ChangePaveBlocksIn();
1214 BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
1217 FaceInfoIn(theI, aMPBIn, aMVIn);
1220 //=======================================================================
1221 //function : UpdateFaceInfoOn
1223 //=======================================================================
1224 void BOPDS_DS::UpdateFaceInfoOn(const Standard_Integer theI)
1226 Standard_Integer iRef;
1228 BOPDS_ShapeInfo& aSI=ChangeShapeInfo(theI);
1229 if (aSI.HasReference()) {
1230 iRef=aSI.Reference();
1231 BOPDS_FaceInfo &aFI=myFaceInfoPool(iRef);
1233 BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.ChangePaveBlocksOn();
1234 BOPCol_MapOfInteger& aMVOn=aFI.ChangeVerticesOn();
1237 FaceInfoOn(theI, aMPBOn, aMVOn);
1240 //=======================================================================
1241 //function : FaceInfoOn
1243 //=======================================================================
1244 void BOPDS_DS::FaceInfoOn(const Standard_Integer theF,
1245 BOPDS_IndexedMapOfPaveBlock& theMPB,
1246 BOPCol_MapOfInteger& theMI)
1248 Standard_Integer nS, nSD, nV1, nV2;
1249 BOPCol_ListIteratorOfListOfInteger aIt;
1250 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
1252 const BOPDS_ShapeInfo& aSI=ShapeInfo(theF);
1253 const BOPCol_ListOfInteger& aLI=aSI.SubShapes();
1254 aIt.Initialize(aLI);
1255 for (; aIt.More(); aIt.Next()) {
1257 const BOPDS_ShapeInfo& aSIE=ShapeInfo(nS);
1258 if (aSIE.ShapeType()==TopAbs_EDGE) {
1259 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nS);
1260 aItPB.Initialize(aLPB);
1261 for (; aItPB.More(); aItPB.Next()) {
1262 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
1263 aPB->Indices(nV1, nV2);
1266 Handle(BOPDS_PaveBlock) aPBR=RealPaveBlock(aPB);
1269 }//if (aSIE.ShapeType()==TopAbs_EDGE)
1271 // nE is TopAbs_VERTEX
1272 if (HasShapeSD(nS, nSD)) {
1279 //=======================================================================
1280 //function : FaceInfoIn
1282 //=======================================================================
1283 void BOPDS_DS::FaceInfoIn(const Standard_Integer theF,
1284 BOPDS_IndexedMapOfPaveBlock& theMPB,
1285 BOPCol_MapOfInteger& theMI)
1287 Standard_Integer i, aNbVF, aNbEF, nV, nE, nVSD;
1288 TopoDS_Iterator aItS;
1289 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
1291 // 1. Pure internal vertices on the face
1292 const TopoDS_Shape& aF=Shape(theF);
1293 aItS.Initialize(aF);
1294 for (; aItS.More(); aItS.Next()) {
1295 const TopoDS_Shape& aSx=aItS.Value();
1296 if (aSx.ShapeType()==TopAbs_VERTEX){
1298 if (HasShapeSD(nV, nVSD)) {
1306 BOPDS_VectorOfInterfVF& aVFs=InterfVF();
1307 aNbVF=aVFs.Extent();
1308 for (i=0; i<aNbVF; ++i) {
1309 BOPDS_InterfVF& aVF=aVFs(i);
1310 if(aVF.Contains(theF)) {
1311 nV=aVF.OppositeIndex(theF);
1317 BOPDS_VectorOfInterfEF& aEFs=InterfEF();
1318 aNbEF=aEFs.Extent();
1319 for (i=0; i<aNbEF; ++i) {
1320 BOPDS_InterfEF& aEF=aEFs(i);
1321 if(aEF.Contains(theF)) {
1322 if(aEF.HasIndexNew(nV)) {
1326 nE=aEF.OppositeIndex(theF);
1327 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1328 aItPB.Initialize(aLPB);
1329 for (; aItPB.More(); aItPB.Next()) {
1330 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
1331 if (IsCommonBlock(aPB)) {
1332 const Handle(BOPDS_CommonBlock)& aCB=CommonBlock(aPB);
1333 if (aCB->Contains(theF)) {
1334 const Handle(BOPDS_PaveBlock)& aPB1=aCB->PaveBlock1();
1338 }// for (; aItPB.More(); aItPB.Next()) {
1340 }// if(aEF.Contains(theF)) {
1341 }// for (i=0; i<aNbEF; ++i) {
1344 //=======================================================================
1345 //function : RefineFaceInfoOn
1347 //=======================================================================
1348 void BOPDS_DS::RefineFaceInfoOn()
1350 Standard_Integer i, aNb, nF, aNbPB, j;
1351 BOPDS_IndexedMapOfPaveBlock aMPB;
1353 aNb=myFaceInfoPool.Extent();
1354 for (i=0; i<aNb; ++i) {
1355 BOPDS_FaceInfo &aFI=myFaceInfoPool(i);
1357 UpdateFaceInfoOn(nF);
1358 BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.ChangePaveBlocksOn();
1361 aMPB.Assign(aMPBOn);
1364 aNbPB=aMPB.Extent();
1365 for (j=1; j<=aNbPB; ++j) {
1366 const Handle(BOPDS_PaveBlock)& aPB=aMPB(j);
1367 if (aPB->HasEdge()) {
1373 //=======================================================================
1374 //function : AloneVertices
1376 //=======================================================================
1377 void BOPDS_DS::AloneVertices(const Standard_Integer theI,
1378 BOPCol_ListOfInteger& theLI)const
1380 if (HasFaceInfo(theI)) {
1382 Standard_Integer i, nV1, nV2, nV;
1383 BOPDS_MapIteratorOfMapOfPaveBlock aItMPB;
1384 BOPCol_MapIteratorOfMapOfInteger aItMI;
1386 BOPCol_MapOfInteger aMI(100, myAllocator);
1388 const BOPDS_FaceInfo& aFI=FaceInfo(theI);
1390 for (i=0; i<2; ++i) {
1391 const BOPDS_IndexedMapOfPaveBlock& aMPB=
1392 (!i) ? aFI.PaveBlocksIn() : aFI.PaveBlocksSc();
1393 aItMPB.Initialize(aMPB);
1394 for (; aItMPB.More(); aItMPB.Next()) {
1395 const Handle(BOPDS_PaveBlock)& aPB=aItMPB.Value();
1396 aPB->Indices(nV1, nV2);
1402 for (i=0; i<2; ++i) {
1403 const BOPCol_MapOfInteger& aMIV=
1404 (!i) ? aFI.VerticesIn() : aFI.VerticesSc();
1405 aItMI.Initialize(aMIV);
1406 for (; aItMI.More(); aItMI.Next()) {
1417 //=======================================================================
1418 //function : VerticesOnIn
1420 //=======================================================================
1421 void BOPDS_DS::VerticesOnIn
1422 (const Standard_Integer nF1,
1423 const Standard_Integer nF2,
1424 BOPCol_MapOfInteger& aMI,
1425 BOPDS_IndexedMapOfPaveBlock& aMPB)const
1427 Standard_Integer i, j, nV, nV1, nV2, aNbPB;
1428 BOPCol_MapIteratorOfMapOfInteger aIt;
1429 BOPDS_IndexedMapOfPaveBlock pMPB[4];
1431 const BOPDS_FaceInfo& aFI1=FaceInfo(nF1);
1432 const BOPDS_FaceInfo& aFI2=FaceInfo(nF2);
1434 pMPB[0]=aFI1.PaveBlocksOn();
1435 pMPB[1]=aFI1.PaveBlocksIn();
1436 pMPB[2]=aFI2.PaveBlocksOn();
1437 pMPB[3]=aFI2.PaveBlocksIn();
1439 for (i=0; i<4; ++i) {
1440 aNbPB = pMPB[i].Extent();
1441 for (j = 1; j <= aNbPB; ++j) {
1442 const Handle(BOPDS_PaveBlock)& aPB = pMPB[i](j);
1444 aPB->Indices(nV1, nV2);
1450 const BOPCol_MapOfInteger& aMVOn1=aFI1.VerticesOn();
1451 const BOPCol_MapOfInteger& aMVIn1=aFI1.VerticesIn();
1452 const BOPCol_MapOfInteger& aMVOn2=aFI2.VerticesOn();
1453 const BOPCol_MapOfInteger& aMVIn2=aFI2.VerticesIn();
1455 for (i=0; i<2; ++i) {
1456 const BOPCol_MapOfInteger& aMV1=(!i) ? aMVOn1 : aMVIn1;
1457 aIt.Initialize(aMV1);
1458 for (; aIt.More(); aIt.Next()) {
1460 if (aMVOn2.Contains(nV) || aMVIn2.Contains(nV)) {
1466 //=======================================================================
1467 //function : SharedEdges
1469 //=======================================================================
1470 void BOPDS_DS::SharedEdges(const Standard_Integer nF1,
1471 const Standard_Integer nF2,
1472 BOPCol_ListOfInteger& theLI,
1473 const Handle(NCollection_BaseAllocator)& aAllocator)
1475 Standard_Integer nE, nSp;
1476 BOPCol_ListIteratorOfListOfInteger aItLI;
1477 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
1478 BOPCol_MapOfInteger aMI(100, aAllocator);
1480 const BOPDS_ShapeInfo& aSI1=ShapeInfo(nF1);
1481 const BOPCol_ListOfInteger& aLI1=aSI1.SubShapes();
1482 aItLI.Initialize(aLI1);
1483 for (; aItLI.More(); aItLI.Next()) {
1485 const BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1486 if(aSIE.ShapeType()==TopAbs_EDGE) {
1487 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1488 if (aLPB.IsEmpty()) {
1492 aItLPB.Initialize(aLPB);
1493 for (; aItLPB.More(); aItLPB.Next()) {
1494 const Handle(BOPDS_PaveBlock) aPB=RealPaveBlock(aItLPB.Value());
1502 const BOPDS_ShapeInfo& aSI2=ShapeInfo(nF2);
1503 const BOPCol_ListOfInteger& aLI2=aSI2.SubShapes();
1504 aItLI.Initialize(aLI2);
1505 for (; aItLI.More(); aItLI.Next()) {
1507 const BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1508 if(aSIE.ShapeType()==TopAbs_EDGE) {
1509 const BOPDS_ListOfPaveBlock& aLPB=PaveBlocks(nE);
1510 if (aLPB.IsEmpty()) {
1511 if (aMI.Contains(nE)) {
1516 aItLPB.Initialize(aLPB);
1517 for (; aItLPB.More(); aItLPB.Next()) {
1518 const Handle(BOPDS_PaveBlock) aPB=RealPaveBlock(aItLPB.Value());
1520 if (aMI.Contains(nSp)) {
1529 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1531 // same domain shapes
1533 //=======================================================================
1534 //function : ShapesSD
1536 //=======================================================================
1537 BOPCol_DataMapOfIntegerInteger& BOPDS_DS::ShapesSD()
1541 //=======================================================================
1542 //function : AddShapeSD
1544 //=======================================================================
1545 void BOPDS_DS::AddShapeSD(const Standard_Integer theIndex,
1546 const Standard_Integer theIndexSD)
1548 myShapesSD.Bind(theIndex, theIndexSD);
1550 //=======================================================================
1551 //function : HasShapeSD
1553 //=======================================================================
1554 Standard_Boolean BOPDS_DS::HasShapeSD
1555 (const Standard_Integer theIndex,
1556 Standard_Integer& theIndexSD)const
1558 Standard_Boolean bRet;
1560 bRet=myShapesSD.IsBound(theIndex);
1562 theIndexSD=myShapesSD.Find(theIndex);
1566 //=======================================================================
1569 //=======================================================================
1570 void BOPDS_DS::Dump()const
1572 Standard_Integer i, aNb, aNbSS;
1574 printf(" *** DS ***\n");
1576 printf(" Ranges:%d\n", aNb);
1577 for (i=0; i<aNb; ++i) {
1578 const BOPDS_IndexRange& aR=Range(i);
1583 aNbSS=NbSourceShapes();
1584 printf(" Shapes:%d\n", aNbSS);
1586 for (i=0; i<aNb; ++i) {
1587 const BOPDS_ShapeInfo& aSI=ShapeInfo(i);
1592 printf(" ****** adds\n");
1595 printf(" ******\n");
1598 //=======================================================================
1599 // function: CheckCoincidence
1601 //=======================================================================
1602 Standard_Boolean BOPDS_DS::CheckCoincidence
1603 (const Handle(BOPDS_PaveBlock)& aPB1,
1604 const Handle(BOPDS_PaveBlock)& aPB2)
1606 Standard_Boolean bRet;
1607 Standard_Integer nE1, nE2, aNbPoints;
1608 Standard_Real aT11, aT12, aT21, aT22, aT1m, aD, aTol, aT2x;
1611 bRet=Standard_False;
1613 aPB1->Range(aT11, aT12);
1614 aT1m=IntTools_Tools::IntermediatePoint (aT11, aT12);
1615 nE1=aPB1->OriginalEdge();
1616 const TopoDS_Edge& aE1=(*(TopoDS_Edge*)(&Shape(nE1)));
1617 BOPTools_AlgoTools::PointOnEdge(aE1, aT1m, aP1m);
1619 aPB2->Range(aT21, aT22);
1620 nE2=aPB2->OriginalEdge();
1621 const TopoDS_Edge& aE2=(*(TopoDS_Edge*)(&Shape(nE2)));
1624 Handle(Geom_Curve)aC2 = BRep_Tool::Curve (aE2, f, l);
1625 GeomAPI_ProjectPointOnCurve aPPC;
1626 aPPC.Init(aC2, f, l);
1628 aNbPoints=aPPC.NbPoints();
1630 aD=aPPC.LowerDistance();
1632 aTol=BRep_Tool::Tolerance(aE1);
1633 aTol=aTol+BRep_Tool::Tolerance(aE2);
1635 aT2x=aPPC.LowerDistanceParameter();
1636 if (aT2x>aT21 && aT2x<aT22) {
1643 //=======================================================================
1644 // function: SortPaveBlocks
1646 //=======================================================================
1647 void BOPDS_DS::SortPaveBlocks(const Handle(BOPDS_CommonBlock)& aCB)
1649 Standard_Integer theI;
1650 Standard_Boolean bToSort;
1651 bToSort = IsToSort(aCB, theI);
1656 Standard_Integer i(0);
1657 const BOPDS_ListOfPaveBlock& aLPB = aCB->PaveBlocks();
1658 BOPDS_ListOfPaveBlock aLPBN = aLPB;
1660 Handle(BOPDS_PaveBlock) aPB;
1661 BOPDS_ListIteratorOfListOfPaveBlock aIt;
1663 aIt.Initialize(aLPBN);
1664 for (aIt.Next(); aIt.More(); ) {
1675 aCB->AddPaveBlocks(aLPBN);
1677 //=======================================================================
1678 // function: IsToSort
1680 //=======================================================================
1681 Standard_Boolean BOPDS_DS::IsToSort
1682 (const Handle(BOPDS_CommonBlock)& aCB,
1683 Standard_Integer& theI)
1685 Standard_Boolean bRet;
1686 bRet = Standard_False;
1687 const BOPDS_ListOfPaveBlock& aLPB = aCB->PaveBlocks();
1688 if (aLPB.Extent()==1) {
1692 Standard_Integer nE;
1693 Standard_Real aTolMax, aTol;
1694 Handle(BOPDS_PaveBlock) aPB;
1696 BOPDS_ListIteratorOfListOfPaveBlock aIt;
1699 nE = aPB->OriginalEdge();
1700 aE = (*(TopoDS_Edge *)(&Shape(nE)));
1701 aTolMax = BRep_Tool::Tolerance(aE);
1704 aIt.Initialize(aLPB);
1705 for (aIt.Next(); aIt.More(); aIt.Next()) {
1708 nE = aPB->OriginalEdge();
1709 aE = (*(TopoDS_Edge *)(&Shape(nE)));
1710 aTol = BRep_Tool::Tolerance(aE);
1711 if (aTolMax < aTol) {
1713 bRet = Standard_True;
1719 //=======================================================================
1720 // function: IsSubShape
1722 //=======================================================================
1723 Standard_Boolean BOPDS_DS::IsSubShape
1724 (const Standard_Integer theI1,
1725 const Standard_Integer theI2)
1727 Standard_Boolean bRet;
1728 Standard_Integer nS;
1729 bRet = Standard_False;
1731 BOPCol_ListIteratorOfListOfInteger aItLI;
1733 const BOPDS_ShapeInfo& aSI = ShapeInfo(theI2);
1734 const BOPCol_ListOfInteger& aLI = aSI.SubShapes();
1735 aItLI.Initialize(aLI);
1736 for(;aItLI.More(); aItLI.Next()) {
1739 bRet = Standard_True;
1747 //=======================================================================
1750 //=======================================================================
1751 void BOPDS_DS::Paves(const Standard_Integer theEdge,
1752 BOPDS_ListOfPave& theLP)
1754 Standard_Integer aNb, i;
1756 BOPDS_ListIteratorOfListOfPaveBlock aIt;
1757 BOPDS_MapOfPave aMP;
1759 const BOPDS_ListOfPaveBlock& aLPB = PaveBlocks(theEdge);
1760 aNb = aLPB.Extent();
1761 aNb = (aNb==0) ? 0 : (aNb+1);
1763 pPaves=(BOPDS_Pave *)myAllocator->Allocate(aNb*sizeof(BOPDS_Pave));
1764 for (i=0; i<aNb; ++i) {
1765 new (pPaves+i) BOPDS_Pave();
1769 for (aIt.Initialize(aLPB); aIt.More(); aIt.Next()) {
1770 const Handle(BOPDS_PaveBlock)& aPB = aIt.Value();
1771 if (aMP.Add(aPB->Pave1())){
1772 pPaves[i] = aPB->Pave1();
1775 if (aMP.Add(aPB->Pave2())){
1776 pPaves[i] = aPB->Pave2();
1781 SortShell(aNb, pPaves);
1783 for (i = 0; i < aNb; ++i) {
1784 theLP.Append(pPaves[i]);
1788 //=======================================================================
1789 // function: UpdateTolerance
1791 //=======================================================================
1792 void BOPDS_DS::UpdateEdgeTolerance(const Standard_Integer nE,
1793 const Standard_Real aTol)
1795 Standard_Integer nV;
1796 Standard_Real aTolV;
1798 BOPCol_ListIteratorOfListOfInteger aIt;
1800 const TopoDS_Edge& aE = *(TopoDS_Edge*)&Shape(nE);
1801 aBB.UpdateEdge(aE, aTol);
1802 BOPDS_ShapeInfo& aSIE=ChangeShapeInfo(nE);
1803 Bnd_Box& aBoxE=aSIE.ChangeBox();
1804 BRepBndLib::Add(aE, aBoxE);
1806 const BOPCol_ListOfInteger& aLI = aSIE.SubShapes();
1807 aIt.Initialize(aLI);
1808 for (; aIt.More(); aIt.Next()) {
1810 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&Shape(nV);
1811 aTolV = BRep_Tool::Tolerance(aV);
1813 aBB.UpdateVertex(aV, aTol);
1814 BOPDS_ShapeInfo& aSIV = ChangeShapeInfo(nV);
1815 Bnd_Box& aBoxV = aSIV.ChangeBox();
1816 BRepBndLib::Add(aV, aBoxV);
1821 //=======================================================================
1822 //function : TotalShapes
1824 //=======================================================================
1825 void TotalShapes(const TopoDS_Shape& aS,
1826 Standard_Integer& aNbS)
1830 pS=(TopoDS_Shape *)&aS;
1831 if (!pS->Checked()) {
1832 TopoDS_Iterator aIt;
1837 for (; aIt.More(); aIt.Next()) {
1838 const TopoDS_Shape& aSx=aIt.Value();
1839 TotalShapes(aSx, aNbS);
1843 //=======================================================================
1844 //function : ResetShape
1846 //=======================================================================
1847 void ResetShape(const TopoDS_Shape& aS)
1851 pS=(TopoDS_Shape *)&aS;
1854 //=======================================================================
1855 //function : ResetShape
1857 //=======================================================================
1858 void ResetShapes(const TopoDS_Shape& aS)
1860 TopoDS_Iterator aIt;
1864 for (; aIt.More(); aIt.Next()) {
1865 const TopoDS_Shape& aSx=aIt.Value();
1869 //=======================================================================
1870 //function : ComputeParameter
1872 //=======================================================================
1873 Standard_Real ComputeParameter(const TopoDS_Vertex& aV,
1874 const TopoDS_Edge& aE)
1876 Standard_Real aT1, aT2, aTRet, aTolE2, aD2;
1878 Handle(Geom_Curve) aC3D;
1882 aEE.Orientation(TopAbs_FORWARD);
1886 aTolE2=BRep_Tool::Tolerance(aE);
1887 aTolE2=aTolE2*aTolE2;
1889 aPV=BRep_Tool::Pnt(aV);
1891 aC3D=BRep_Tool::Curve (aEE, aT1, aT2);
1894 aD2=aPC.SquareDistance(aPV);
1900 aD2=aPC.SquareDistance(aPV);
1907 //=======================================================================
1908 // function: SortShell
1910 //=======================================================================
1911 void SortShell(const int n, BOPDS_Pave *a)
1913 int nd, i, j, l, d=1;
1924 for (i=0; i<nd; ++i) {
1933 if (j > -1) goto m30;
1934 }//if (a[l] < a[j]){
1935 }//for (i=0; i<nd; ++i)
1938 //=======================================================================
1939 //function : BuildBndBoxSolid
1941 //=======================================================================
1942 void BOPDS_DS::BuildBndBoxSolid(const Standard_Integer theIndex,
1945 Standard_Boolean bIsOpenBox, bIsInverted;
1946 Standard_Integer nSh, nFc;
1947 Standard_Real aTolS, aTolFc;
1948 BOPCol_ListIteratorOfListOfInteger aItLI, aItLI1;
1950 const BOPDS_ShapeInfo& aSI=ShapeInfo(theIndex);
1951 const TopoDS_Shape& aS=aSI.Shape();
1952 const TopoDS_Solid& aSolid=(*(TopoDS_Solid*)(&aS));
1954 bIsOpenBox=Standard_False;
1957 const BOPCol_ListOfInteger& aLISh=aSI.SubShapes();
1958 aItLI.Initialize(aLISh);
1959 for (; aItLI.More(); aItLI.Next()) {
1961 const BOPDS_ShapeInfo& aSISh=ShapeInfo(nSh);
1962 if (aSISh.ShapeType()!=TopAbs_SHELL) {
1966 const BOPCol_ListOfInteger& aLIFc=aSISh.SubShapes();
1967 aItLI1.Initialize(aLIFc);
1968 for (; aItLI1.More(); aItLI1.Next()) {
1970 const BOPDS_ShapeInfo& aSIFc=ShapeInfo(nFc);
1971 if (aSIFc.ShapeType()!=TopAbs_FACE) {
1975 const Bnd_Box& aBFc=aSIFc.Box();
1979 bIsOpenBox=(aBFc.IsOpenXmin() || aBFc.IsOpenXmax() ||
1980 aBFc.IsOpenYmin() || aBFc.IsOpenYmax() ||
1981 aBFc.IsOpenZmin() || aBFc.IsOpenZmax());
1987 const TopoDS_Face& aFc=*((TopoDS_Face*)&aSIFc.Shape());
1988 aTolFc=BRep_Tool::Tolerance(aFc);
1992 }//for (; aItLI1.More(); aItLI1.Next()) {
1997 const TopoDS_Shell& aSh=*((TopoDS_Shell*)&aSISh.Shape());
1998 bIsOpenBox=BOPTools_AlgoTools::IsOpenShell(aSh);
2002 }//for (; aItLI.More(); aItLI.Next()) {
2008 bIsInverted=BOPTools_AlgoTools::IsInvertedSolid(aSolid);