0028599: Replacement of old Boolean operations with new ones in BRepProj_Projection...
[occt.git] / src / BOPAlgo / BOPAlgo_PaveFiller_5.cxx
index 8c40a99..7aa22d1 100644 (file)
 // commercial license or contractual agreement.
 
 
-#include <Precision.hxx>
-
 #include <Bnd_Box.hxx>
 #include <BOPAlgo_PaveFiller.hxx>
-#include <BOPAlgo_SectionAttribute.hxx>
+#include <BOPAlgo_Alerts.hxx>
 #include <BOPAlgo_Tools.hxx>
-#include <BOPCol_MapOfInteger.hxx>
-#include <BOPCol_NCVector.hxx>
-#include <BOPCol_Parallel.hxx>
-#include <BOPCol_DataMapOfShapeReal.hxx>
 #include <BOPDS_CommonBlock.hxx>
 #include <BOPDS_CoupleOfPaveBlocks.hxx>
 #include <BOPDS_Curve.hxx>
-#include <BOPDS_DataMapOfPaveBlockListOfInteger.hxx>
 #include <BOPDS_DS.hxx>
 #include <BOPDS_Interf.hxx>
 #include <BOPDS_Iterator.hxx>
 #include <BOPDS_Pave.hxx>
 #include <BOPDS_PaveBlock.hxx>
 #include <BOPTools_AlgoTools.hxx>
+#include <BOPTools_Parallel.hxx>
 #include <BRep_Builder.hxx>
 #include <BRep_Tool.hxx>
 #include <BRepAdaptor_Curve.hxx>
-#include <BRepBndLib.hxx>
-#include <GeomAPI_ProjectPointOnSurf.hxx>
 #include <gp_Pnt.hxx>
 #include <IntTools_CommonPrt.hxx>
 #include <IntTools_Context.hxx>
@@ -49,6 +41,9 @@
 #include <IntTools_Range.hxx>
 #include <IntTools_SequenceOfCommonPrts.hxx>
 #include <IntTools_Tools.hxx>
+#include <NCollection_Vector.hxx>
+#include <Precision.hxx>
+#include <TColStd_MapOfInteger.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS_Face.hxx>
@@ -102,9 +97,22 @@ class BOPAlgo_EdgeFace :
     return myPB;
   }
   //
+  void SetFuzzyValue(const Standard_Real theFuzz) {
+    IntTools_EdgeFace::SetFuzzyValue(theFuzz);
+  }
+  //
   virtual void Perform() {
     BOPAlgo_Algo::UserBreak();
-    IntTools_EdgeFace::Perform();
+    try
+    {
+      OCC_CATCH_SIGNALS
+
+      IntTools_EdgeFace::Perform();
+    }
+    catch (Standard_Failure)
+    {
+      AddError(new BOPAlgo_AlertIntersectionFailed);
+    }
   }
   //
  protected:
@@ -115,15 +123,15 @@ class BOPAlgo_EdgeFace :
 };
 //
 //=======================================================================
-typedef BOPCol_NCVector<BOPAlgo_EdgeFace> BOPAlgo_VectorOfEdgeFace; 
+typedef NCollection_Vector<BOPAlgo_EdgeFace> BOPAlgo_VectorOfEdgeFace; 
 //
-typedef BOPCol_ContextFunctor 
+typedef BOPTools_ContextFunctor 
   <BOPAlgo_EdgeFace,
   BOPAlgo_VectorOfEdgeFace,
   Handle(IntTools_Context), 
   IntTools_Context> BOPAlgo_EdgeFaceFunctor;
 //
-typedef BOPCol_ContextCnt 
+typedef BOPTools_ContextCnt 
   <BOPAlgo_EdgeFaceFunctor,
   BOPAlgo_VectorOfEdgeFace,
   Handle(IntTools_Context)> BOPAlgo_EdgeFaceCnt;
@@ -134,22 +142,34 @@ typedef BOPCol_ContextCnt
 //=======================================================================
 void BOPAlgo_PaveFiller::PerformEF()
 {
-  Standard_Integer iSize;
-  //
-  myErrorStatus=0;
-  //
   FillShrunkData(TopAbs_EDGE, TopAbs_FACE);
   //
   myIterator->Initialize(TopAbs_EDGE, TopAbs_FACE);
-  iSize=myIterator->ExpectedLength();
+  Standard_Integer iSize = myIterator->ExpectedLength();
   if (!iSize) {
     return; 
   }
   //
-  Standard_Boolean bJustAdd, bV[2];
-  Standard_Integer nE, nF, aDiscretize, i, aNbCPrts, iX, nV[2];
+  Standard_Integer nE, nF;
+  //
+  if (myGlue == BOPAlgo_GlueFull) {
+    // there is no need to intersect edges with faces in this mode
+    // just initialize FaceInfo for faces
+    for (; myIterator->More(); myIterator->Next()) {
+      myIterator->Value(nE, nF);
+      if (!myDS->ShapeInfo(nE).HasFlag()) {
+        myDS->ChangeFaceInfo(nF);
+      }
+    }
+    return;
+  }
+  //
+  Standard_Boolean bV[2], bIsPBSplittable;
+  Standard_Boolean bV1, bV2, bExpressCompute;
+  Standard_Integer nV1, nV2;
+  Standard_Integer i, aNbCPrts, iX, nV[2];
   Standard_Integer aNbEdgeFace, k;
-  Standard_Real aTolE, aTolF, aTS1, aTS2, aT1, aT2, aDeflection;
+  Standard_Real aTolE, aTolF, aTS1, aTS2, aT1, aT2;
   Handle(NCollection_BaseAllocator) aAllocator;
   TopAbs_ShapeEnum aType;
   BOPDS_ListIteratorOfListOfPaveBlock aIt;
@@ -158,21 +178,16 @@ void BOPAlgo_PaveFiller::PerformEF()
   //
   aAllocator=NCollection_BaseAllocator::CommonBaseAllocator();
   //
-  BOPCol_MapOfInteger aMIEFC(100, aAllocator);
+  TColStd_MapOfInteger aMIEFC(100, aAllocator);
   BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMVCPB(100, aAllocator);
   BOPDS_IndexedDataMapOfPaveBlockListOfInteger aMPBLI(100, aAllocator);
-  //
-  aDiscretize=35;
-  aDeflection=0.01;
+  BOPAlgo_DataMapOfPaveBlockBndBox aDMPBBox(100, aAllocator);
   //
   BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
   aEFs.SetIncrement(iSize);
   //
   for (; myIterator->More(); myIterator->Next()) {
-    myIterator->Value(nE, nF, bJustAdd);
-    if(bJustAdd) {
-      continue;
-    }
+    myIterator->Value(nE, nF);
     //
     const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
     if (aSIE.HasFlag()){//degenerated 
@@ -186,6 +201,9 @@ void BOPAlgo_PaveFiller::PerformEF()
     BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
     const BOPDS_IndexedMapOfPaveBlock& aMPBF=aFI.PaveBlocksOn();
     //
+    const TColStd_MapOfInteger& aMVIn=aFI.VerticesIn();
+    const TColStd_MapOfInteger& aMVOn=aFI.VerticesOn();
+    //
     aTolE=BRep_Tool::Tolerance(aE);
     aTolF=BRep_Tool::Tolerance(aF);
     //
@@ -199,35 +217,35 @@ void BOPAlgo_PaveFiller::PerformEF()
         continue;
       }
       //
-      if (!aPB->HasShrunkData()) {
+      Bnd_Box aBBE;
+      if (!GetPBBox(aE, aPB, aDMPBBox, aT1, aT2, aTS1, aTS2, aBBE)) {
         continue;
       }
       //
-      Bnd_Box aBBE;
-      aPB->ShrunkData(aTS1, aTS2, aBBE);
-      //
       if (aBBF.IsOut (aBBE)) {
         continue;
       }
       //
-      BOPAlgo_EdgeFace& aEdgeFace=aVEdgeFace.Append1();
+      aPBR->Indices(nV1, nV2);
+      bV1=aMVIn.Contains(nV1) || aMVOn.Contains(nV1);
+      bV2=aMVIn.Contains(nV2) || aMVOn.Contains(nV2);
+      bExpressCompute=bV1 && bV2;
+      //
+      BOPAlgo_EdgeFace& aEdgeFace=aVEdgeFace.Appended();
       //
       aEdgeFace.SetIndices(nE, nF);
       aEdgeFace.SetPaveBlock(aPB);
       //
       aEdgeFace.SetEdge (aE);
       aEdgeFace.SetFace (aF);
-      aEdgeFace.SetTolE (aTolE);
-      aEdgeFace.SetTolF (aTolF);
-      aEdgeFace.SetDiscretize (aDiscretize);
-      aEdgeFace.SetDeflection (aDeflection);
+      aEdgeFace.SetFuzzyValue(myFuzzyValue);
+      aEdgeFace.UseQuickCoincidenceCheck(bExpressCompute);
       //
       IntTools_Range aSR(aTS1, aTS2);
       IntTools_Range anewSR=aSR;
       BOPTools_AlgoTools::CorrectRange(aE, aF, aSR, anewSR);
       aEdgeFace.SetNewSR(anewSR);
       //
-      aPB->Range(aT1, aT2);
       IntTools_Range aPBRange(aT1, aT2);
       aSR = aPBRange;
       BOPTools_AlgoTools::CorrectRange(aE, aF, aSR, aPBRange);
@@ -237,51 +255,67 @@ void BOPAlgo_PaveFiller::PerformEF()
     }//for (; aIt.More(); aIt.Next()) {
   }//for (; myIterator->More(); myIterator->Next()) {
   //
-  aNbEdgeFace=aVEdgeFace.Extent();
+  aNbEdgeFace=aVEdgeFace.Length();
   //=================================================================
   BOPAlgo_EdgeFaceCnt::Perform(myRunParallel, aVEdgeFace, myContext);
   //=================================================================
   //
   for (k=0; k < aNbEdgeFace; ++k) {
     BOPAlgo_EdgeFace& aEdgeFace=aVEdgeFace(k);
-    if (!aEdgeFace.IsDone()) {
+    if (!aEdgeFace.IsDone() || aEdgeFace.HasErrors()) {
+      // Warn about failed intersection of sub-shapes
+      AddIntersectionFailedWarning(aEdgeFace.Edge(), aEdgeFace.Face());
       continue;
     }
-    //~~~
+    //
+    const IntTools_SequenceOfCommonPrts& aCPrts=aEdgeFace.CommonParts();
+    aNbCPrts = aCPrts.Length();
+    if (!aNbCPrts) {
+      continue;
+    }
+    //
     aEdgeFace.Indices(nE, nF);
     //
     const TopoDS_Edge& aE=aEdgeFace.Edge();
     const TopoDS_Face& aF=aEdgeFace.Face();
     //
-    aTolE=aEdgeFace.TolE();
-    aTolF=aEdgeFace.TolF();
+    aTolE=BRep_Tool::Tolerance(aE);
+    aTolF=BRep_Tool::Tolerance(aF);
     const IntTools_Range& anewSR=aEdgeFace.NewSR();
     Handle(BOPDS_PaveBlock)& aPB=aEdgeFace.PaveBlock();
     //
     aPB->Range(aT1, aT2);
     aPB->Indices(nV[0], nV[1]);
+    bIsPBSplittable = aPB->IsSplittable();
+    //
+    anewSR.Range(aTS1, aTS2);
+    //
+    if (aCPrts(1).Type() == TopAbs_VERTEX) {
+      // for the intersection type VERTEX
+      // extend vertices ranges using Edge/Edge intersections
+      // between the edge aE and the edges of the face aF.
+      // thereby the edge's intersection range is reduced
+      ReduceIntersectionRange(nV[0], nV[1], nE, nF, aTS1, aTS2);
+    }
+    //
+    IntTools_Range aR1(aT1, aTS1), aR2(aTS2, aT2);
     //
     BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
-    const BOPCol_MapOfInteger& aMIFOn=aFI.VerticesOn();
-    const BOPCol_MapOfInteger& aMIFIn=aFI.VerticesIn();
-    //~~~
-    const IntTools_SequenceOfCommonPrts& aCPrts=aEdgeFace.CommonParts();
-    aNbCPrts = aCPrts.Length();
+    const TColStd_MapOfInteger& aMIFOn=aFI.VerticesOn();
+    const TColStd_MapOfInteger& aMIFIn=aFI.VerticesIn();
     //
     Standard_Boolean bLinePlane = Standard_False;
     if (aNbCPrts) {
       BRepAdaptor_Curve aBAC(aE);
-      BRepAdaptor_Surface aBAS(aF, Standard_False);
-      //
       bLinePlane = (aBAC.GetType() == GeomAbs_Line &&
-                    aBAS.GetType() == GeomAbs_Plane);
+                    myContext->SurfaceAdaptor(aF).GetType() == GeomAbs_Plane);
     }
-
+    //
     for (i=1; i<=aNbCPrts; ++i) {
       const IntTools_CommonPrt& aCPart=aCPrts(i);
       aType=aCPart.Type();
       switch (aType) {
-        case TopAbs_VERTEX:  {
+        case TopAbs_VERTEX: {
           Standard_Boolean bIsOnPave[2];
           Standard_Integer j;
           Standard_Real aT, aTolToDecide; 
@@ -293,8 +327,6 @@ void BOPAlgo_PaveFiller::PerformEF()
           const IntTools_Range& aR=aCPart.Range1();
           aTolToDecide=5.e-8;
           //
-          IntTools_Range aR1(aT1,anewSR.First()),aR2(anewSR.Last(), aT2);
-          //
           bIsOnPave[0]=IntTools_Tools::IsInRange(aR1, aR, aTolToDecide); 
           bIsOnPave[1]=IntTools_Tools::IsInRange(aR2, aR, aTolToDecide); 
           //
@@ -305,8 +337,8 @@ void BOPAlgo_PaveFiller::PerformEF()
             if (bV[0] && bV[1]) {
               IntTools_CommonPrt aCP = aCPart;
               aCP.SetType(TopAbs_EDGE);
-              BOPDS_InterfEF& aEF=aEFs.Append1();
-              iX=aEFs.Extent()-1;
+              BOPDS_InterfEF& aEF=aEFs.Appended();
+              iX=aEFs.Length()-1;
               aEF.SetIndices(nE, nF);
               aEF.SetCommonPart(aCP);
               myDS->AddInterf(nE, nF);
@@ -317,6 +349,11 @@ void BOPAlgo_PaveFiller::PerformEF()
               break;
             }
           }
+          //
+          if (!bIsPBSplittable) {
+            continue;
+          }
+          //
           for (j=0; j<2; ++j) {
             if (bIsOnPave[j]) {
               bV[j]=CheckFacePaves(nV[j], aMIFOn, aMIFIn);
@@ -331,15 +368,14 @@ void BOPAlgo_PaveFiller::PerformEF()
                 gp_Pnt aP1 = BRep_Tool::Pnt(aV);
                 gp_Pnt aP2 = aCur->Value(aT);
                 //
-                
                 aDistPP=aP1.Distance(aP2);
-                
+                //
                 aTolPC=Precision::PConfusion();
                 aTolV=BRep_Tool::Tolerance(aV);
                 if (aDistPP > (aTolV+aTolPC)) {
                   aTolVnew=Max(aTolE, aDistPP);
                   UpdateVertex(nV[j], aTolVnew);
-              }
+                }
               }
               else {
                 bIsOnPave[j] = ForceInterfVF(nV[j], nF);
@@ -370,8 +406,8 @@ void BOPAlgo_PaveFiller::PerformEF()
             //
             aMIEFC.Add(nF);
             // 1
-            BOPDS_InterfEF& aEF=aEFs.Append1();
-            iX=aEFs.Extent()-1;
+            BOPDS_InterfEF& aEF=aEFs.Appended();
+            iX=aEFs.Length()-1;
             aEF.SetIndices(nE, nF);
             aEF.SetCommonPart(aCPart);
             // 2
@@ -390,8 +426,8 @@ void BOPAlgo_PaveFiller::PerformEF()
           aMIEFC.Add(nF);
           //
           // 1
-          BOPDS_InterfEF& aEF=aEFs.Append1();
-          iX=aEFs.Extent()-1;
+          BOPDS_InterfEF& aEF=aEFs.Appended();
+          iX=aEFs.Length()-1;
           aEF.SetIndices(nE, nF);
           //
           bV[0]=CheckFacePaves(nV[0], aMIFOn, aMIFIn);
@@ -418,18 +454,15 @@ void BOPAlgo_PaveFiller::PerformEF()
   // post treatment
   //=========================================
   BOPAlgo_Tools::PerformCommonBlocks(aMPBLI, aAllocator, myDS);
-  PerformVerticesEF(aMVCPB, aAllocator);
+  PerformNewVertices(aMVCPB, aAllocator, Standard_False);
   //
   // Update FaceInfoIn for all faces having EF common parts
-  BOPCol_MapIteratorOfMapOfInteger aItMI;
+  TColStd_MapIteratorOfMapOfInteger aItMI;
   aItMI.Initialize(aMIEFC);
   for (; aItMI.More(); aItMI.Next()) {
     nF=aItMI.Value();
     myDS->UpdateFaceInfoIn(nF);
   }
-  // Refine FaceInfoOn to remove all formal pave blocks 
-  // made during EF processing 
-  //myDS->RefineFaceInfoOn();
   //-----------------------------------------------------scope t
   aMIEFC.Clear();
   aMVCPB.Clear();
@@ -437,201 +470,17 @@ void BOPAlgo_PaveFiller::PerformEF()
   ////aAllocator.Nullify();
 }
 //=======================================================================
-//function : PerformVerticesEF
-//purpose  : 
-//=======================================================================
-Standard_Integer BOPAlgo_PaveFiller::PerformVerticesEF
-  (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMVCPB,
-   const Handle(NCollection_BaseAllocator)& theAllocator)
-{
-  Standard_Integer aNbV, iRet;
-  //
-  iRet=0;
-  aNbV=theMVCPB.Extent();
-  if (!aNbV) {
-    return iRet;
-  }
-  //
-  Standard_Integer nVx, nVSD, iV, iErr, nE, iFlag, iX, i, aNbPBLI;
-  Standard_Real aT, dummy;
-  TopoDS_Shape aV;
-  BOPCol_ListIteratorOfListOfShape aItLS;
-  BOPCol_ListIteratorOfListOfInteger aItLI;
-  BOPDS_PDS aPDS;
-  BOPDS_ShapeInfo aSI;
-  BOPDS_Pave aPave;
-  //
-  BOPCol_ListOfShape aLS(theAllocator);
-  BOPCol_DataMapOfShapeInteger aMVI(100, theAllocator);
-  BOPDS_IndexedDataMapOfPaveBlockListOfInteger aMPBLI(100, theAllocator);
-  BOPAlgo_PaveFiller aPF(theAllocator); 
-  BOPCol_DataMapOfShapeReal aMVIniTol;
-  //
-  aSI.SetShapeType(TopAbs_VERTEX);
-  BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
-  //
-  // 1 prepare arguments
-  for (i=1; i<=aNbV; ++i) {
-    const TopoDS_Vertex& aV = TopoDS::Vertex(theMVCPB.FindKey(i));
-    aLS.Append(aV);
-    // if an enlarged tolerance is associated with the vertex then update it 
-    // remembering its initial tolerance
-    Standard_Real aTolEnlarged = theMVCPB.FindFromIndex(i).Tolerance();
-    Standard_Real aIniTol = BRep_Tool::Tolerance(aV);
-    if (aTolEnlarged > aIniTol) {
-      aMVIniTol.Bind(aV, aIniTol);
-      BRep_Builder().UpdateVertex(aV, aTolEnlarged);
-    }
-  }
-  //
-  // 2 Fuse vertices
-  aPF.SetIsPrimary(Standard_False);
-  aPF.SetNonDestructive(myNonDestructive);
-  aPF.SetArguments(aLS);
-  aPF.Perform();
-  iErr=aPF.ErrorStatus();
-  if (iErr) {
-    iRet=1;
-    return iRet;
-  }
-  aPDS=aPF.PDS();
-  //
-  // Recompute common vertex for each SD group containing enlarged vertex;
-  // for that first fill in the map of SD vertex -> its counterparts
-  BOPCol_IndexedDataMapOfShapeListOfShape aImages;
-  aItLS.Initialize(aLS);
-  for (; aItLS.More(); aItLS.Next()) {
-    const TopoDS_Shape& aVx = aItLS.Value();
-    nVx = aPDS->Index(aVx);
-    //
-    if (aPDS->HasShapeSD(nVx, nVSD)) {
-      aV = aPDS->Shape(nVSD);
-    }
-    else {
-      aV = aVx;
-    }
-    BOPCol_ListOfShape* pLst = aImages.ChangeSeek(aV);
-    if (!pLst) {
-      pLst = &aImages.ChangeFromIndex(aImages.Add(aV, BOPCol_ListOfShape()));
-    }
-    pLst->Append(aVx);
-  }
-  // 3 Add new vertices to theDS; 
-  for (i = 1; i <= aImages.Extent(); i++) {
-    TopoDS_Vertex aV = TopoDS::Vertex(aImages.FindKey(i));
-    const BOPCol_ListOfShape& aLVSD = aImages.FindFromIndex(i);
-    Standard_Boolean isReset = Standard_False;
-    BOPCol_ListIteratorOfListOfShape it(aLVSD);
-    for (; it.More(); it.Next()) {
-      const TopoDS_Vertex& aVx = TopoDS::Vertex(it.Value());
-      const Standard_Real* pTolIni = aMVIniTol.Seek(aVx);
-      if (pTolIni) {
-        // reset enlarged vertex tolerance to the initial value
-        reinterpret_cast<BRep_TVertex*>(aVx.TShape().operator->())->Tolerance(*pTolIni);
-        isReset = Standard_True;
-      }
-    }
-    TopoDS_Vertex aVnew = aV;
-    if (isReset && aLVSD.Extent() > 1) {
-      // make new vertex again
-      BOPTools_AlgoTools::MakeVertex(aLVSD, aVnew);
-    }
-    // index of new vertex in theDS -> iV
-    aSI.SetShape(aVnew);
-    iV = myDS->Append(aSI);
-    //
-    BOPDS_ShapeInfo& aSIDS = myDS->ChangeShapeInfo(iV);
-    Bnd_Box& aBox = aSIDS.ChangeBox();
-    BRepBndLib::Add(aVnew, aBox);
-    aBox.SetGap(aBox.GetGap() + Precision::Confusion());
-    //
-    aMVI.Bind(aV, iV);
-  }
-  //
-  // 4 Map PaveBlock/ListOfVertices to add to this PaveBlock ->aMPBLI
-  aItLS.Initialize(aLS);
-  for (; aItLS.More(); aItLS.Next()) {
-    const TopoDS_Shape& aVx=aItLS.Value();
-    nVx=aPDS->Index(aVx);
-    //
-    if (aPDS->HasShapeSD(nVx, nVSD)) {
-      aV=aPDS->Shape(nVSD);
-    }
-    else {
-      aV=aVx;
-    }
-    iV = aMVI.Find(aV);
-    //
-    BOPDS_CoupleOfPaveBlocks &aCPB=theMVCPB.ChangeFromKey(aVx);
-    aCPB.SetIndex(iV);
-    // update EF interference
-    iX=aCPB.IndexInterf();
-    BOPDS_InterfEF& aEF=aEFs(iX);
-    aEF.SetIndexNew(iV);
-    // map aMPBLI
-    const Handle(BOPDS_PaveBlock)& aPB=aCPB.PaveBlock1();
-    if (aMPBLI.Contains(aPB)) {
-      BOPCol_ListOfInteger& aLI=aMPBLI.ChangeFromKey(aPB);
-      aLI.Append(iV);
-    }
-    else {
-      BOPCol_ListOfInteger aLI(theAllocator);
-      aLI.Append(iV);
-      aMPBLI.Add(aPB, aLI);
-    }
-  }
-  //
-  // 5 
-  // 5.1  Compute Extra Paves and 
-  // 5.2. Add Extra Paves to the PaveBlocks
-  aNbPBLI=aMPBLI.Extent();
-  for (i=1; i<=aNbPBLI; ++i) {
-    Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i);
-    const BOPCol_ListOfInteger& aLI=aMPBLI.FindFromIndex(i);
-    nE=aPB->OriginalEdge();
-    const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
-    // 
-    aItLI.Initialize(aLI);
-    for (; aItLI.More(); aItLI.Next()) {
-      nVx=aItLI.Value();
-      const TopoDS_Vertex& aVx=(*(TopoDS_Vertex *)(&myDS->Shape(nVx)));
-      //
-      iFlag=myContext->ComputeVE (aVx, aE, aT, dummy);
-      if (!iFlag) {
-        aPave.SetIndex(nVx);
-        aPave.SetParameter(aT);
-        aPB->AppendExtPave(aPave);
-      }
-    }
-  }
-  // 6  Split PaveBlocks
-  for (i=1; i<=aNbPBLI; ++i) {
-    Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i);
-    nE=aPB->OriginalEdge();
-    // 3
-    if (!myDS->IsCommonBlock(aPB)) {
-      myDS->UpdatePaveBlock(aPB);
-    }
-    else {
-      const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
-      myDS->UpdateCommonBlock(aCB);
-    }    
-  }//for (; aItMPBLI.More(); aItMPBLI.Next()) {
-  // 
-  return iRet;
-}
-//=======================================================================
 // function: CheckFacePaves
 // purpose: 
 //=======================================================================
 Standard_Boolean BOPAlgo_PaveFiller::CheckFacePaves 
   (const Standard_Integer nVx,
-   const BOPCol_MapOfInteger& aMIFOn,
-   const BOPCol_MapOfInteger& aMIFIn)
+   const TColStd_MapOfInteger& aMIFOn,
+   const TColStd_MapOfInteger& aMIFIn)
 {
   Standard_Boolean bRet;
   Standard_Integer nV;
-  BOPCol_MapIteratorOfMapOfInteger aIt;
+  TColStd_MapIteratorOfMapOfInteger aIt;
   //
   bRet=Standard_False;
   //
@@ -660,11 +509,11 @@ Standard_Boolean BOPAlgo_PaveFiller::CheckFacePaves
 //=======================================================================
 Standard_Boolean BOPAlgo_PaveFiller::CheckFacePaves 
   (const TopoDS_Vertex& aVnew,
-   const BOPCol_MapOfInteger& aMIF)
+   const TColStd_MapOfInteger& aMIF)
 {
   Standard_Boolean bRet;
   Standard_Integer nV, iFlag;
-  BOPCol_MapIteratorOfMapOfInteger aIt;
+  TColStd_MapIteratorOfMapOfInteger aIt;
   //
   bRet=Standard_True;
   //
@@ -696,14 +545,14 @@ Standard_Boolean BOPAlgo_PaveFiller::ForceInterfVF
   const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV);
   const TopoDS_Face&   aF = *(TopoDS_Face*)  &myDS->Shape(nF);
   //
-  iFlag = myContext->ComputeVF(aV, aF, U, V, aTolVNew);
+  iFlag = myContext->ComputeVF(aV, aF, U, V, aTolVNew, myFuzzyValue);
   if (iFlag == 0 || iFlag == -2) {
     bRet=!bRet;
   //
     BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
     aVFs.SetIncrement(10);
     // 1
-    BOPDS_InterfVF& aVF=aVFs.Append1();
+    BOPDS_InterfVF& aVF=aVFs.Appended();
     //
     aVF.SetIndices(nV, nF);
     aVF.SetUV(U, V);
@@ -718,8 +567,98 @@ Standard_Boolean BOPAlgo_PaveFiller::ForceInterfVF
     }
     //
     BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
-    BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
+    TColStd_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();
     aMVIn.Add(nVx);
+    //
+    // check for self-interference
+    Standard_Integer iRV = myDS->Rank(nV);
+    if (iRV >= 0 && iRV == myDS->Rank(nF)) {
+      // add warning status
+      TopoDS_Compound aWC;
+      BRep_Builder().MakeCompound(aWC);
+      BRep_Builder().Add(aWC, aV);
+      BRep_Builder().Add(aWC, aF);
+      AddWarning (new BOPAlgo_AlertSelfInterferingShape (aWC));
+    }
+
   }
   return bRet;
 }
+//=======================================================================
+//function : ReduceIntersectionRange
+//purpose  : 
+//=======================================================================
+void BOPAlgo_PaveFiller::ReduceIntersectionRange(const Standard_Integer theV1,
+                                                 const Standard_Integer theV2,
+                                                 const Standard_Integer theE,
+                                                 const Standard_Integer theF,
+                                                 Standard_Real& theTS1,
+                                                 Standard_Real& theTS2)
+{
+  if (!myDS->IsNewShape(theV1) &&
+      !myDS->IsNewShape(theV2)) {
+    return;
+  }
+  //
+  if (!myDS->HasInterfShapeSubShapes(theE, theF)) {
+    return;
+  }
+  //
+  BOPDS_VectorOfInterfEE& aEEs = myDS->InterfEE();
+  Standard_Integer aNbEEs = aEEs.Length();
+  if (!aNbEEs) {
+    return;
+  }
+  //
+  Standard_Integer i, nV, nE1, nE2;
+  Standard_Real aTR1, aTR2;
+  //
+  // get face's edges to check that E/E contains the edge from the face
+  TColStd_MapOfInteger aMFE;
+  const TColStd_ListOfInteger& aLI = myDS->ShapeInfo(theF).SubShapes();
+  TColStd_ListIteratorOfListOfInteger aItLI(aLI);
+  for (; aItLI.More(); aItLI.Next()) {
+    nE1 = aItLI.Value();
+    if (myDS->ShapeInfo(nE1).ShapeType() == TopAbs_EDGE) {
+      aMFE.Add(nE1);
+    }
+  }
+  //
+  for (i = 0; i < aNbEEs; ++i) {
+    BOPDS_InterfEE& aEE = aEEs(i);
+    if (!aEE.HasIndexNew()) {
+      continue;
+    }
+    //
+    // check the vertex
+    nV = aEE.IndexNew();
+    if (nV != theV1 && nV != theV2) {
+      continue;
+    }
+    //
+    // check that the intersection is between the edge
+    // and one of the face's edge
+    aEE.Indices(nE1, nE2);
+    if (((theE != nE1) && (theE != nE2)) ||
+        (!aMFE.Contains(nE1) && !aMFE.Contains(nE2))) {
+      continue;
+    }
+    //
+    // update the intersection range
+    const IntTools_CommonPrt& aCPart = aEE.CommonPart();
+    const IntTools_Range& aCRange = 
+      (theE == nE1) ? aCPart.Range1() : aCPart.Ranges2().First();
+    aCRange.Range(aTR1, aTR2);
+    //
+    if (nV == theV1) {
+      if (theTS1 < aTR2) {
+        theTS1 = aTR2;
+      }
+    }
+    else {
+      if (theTS2 > aTR1) {
+        theTS2 = aTR1;
+      }
+    }
+  }
+}