0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / BOPAlgo / BOPAlgo_PaveFiller_6.cxx
index 2ed55c8..521d51c 100644 (file)
@@ -6,8 +6,8 @@
 //
 // This file is part of Open CASCADE Technology software library.
 //
-// This library is free software; you can redistribute it and / or modify it
-// under the terms of the GNU Lesser General Public version 2.1 as published
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
 // by the Free Software Foundation, with special exception defined in the file
 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
 // distribution for complete text of the license and disclaimer of any warranty.
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#include <BOPAlgo_PaveFiller.ixx>
 
-#include <Precision.hxx>
-#include <NCollection_IncAllocator.hxx>
 #include <Bnd_Box.hxx>
-
-#include <Geom_Curve.hxx>
-#include <Geom2d_Curve.hxx>
-
-#include <GeomAPI_ProjectPointOnCurve.hxx>
-#include <GeomAPI_ProjectPointOnSurf.hxx>
-
-#include <TopoDS_Edge.hxx>
-#include <TopoDS_Face.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopoDS_Compound.hxx>
-
-#include <TopExp_Explorer.hxx>
-
-#include <BRep_Builder.hxx>
-#include <BRep_Tool.hxx>
-
-#include <BRepBndLib.hxx>
-#include <BRepTools.hxx>
-
-#include <BRepAdaptor_Curve.hxx>
-#include <BRepAdaptor_Surface.hxx>
-
-#include <IntTools_FaceFace.hxx>
-#include <IntTools_SequenceOfCurves.hxx>
-#include <IntTools_SequenceOfPntOn2Faces.hxx>
-#include <IntTools_Curve.hxx>
-#include <IntTools_PntOn2Faces.hxx>
-#include <IntTools_Tools.hxx>
-
-#include <IntSurf_ListOfPntOn2S.hxx>
-#include <IntSurf_PntOn2S.hxx>
-
-#include <BOPTools_AlgoTools.hxx>
-#include <BOPTools_AlgoTools3D.hxx>
-
-#include <BOPCol_MapOfInteger.hxx>
-#include <BOPCol_ListOfShape.hxx>
+#include <BOPAlgo_PaveFiller.hxx>
+#include <BOPAlgo_SectionAttribute.hxx>
+#include <BOPAlgo_Tools.hxx>
+#include <BOPCol_DataMapOfIntegerReal.hxx>
 #include <BOPCol_DataMapOfShapeInteger.hxx>
-#include <BOPCol_ListOfInteger.hxx>
 #include <BOPCol_IndexedMapOfInteger.hxx>
-#include <BOPCol_DataMapOfIntegerReal.hxx>
-
-#include <BOPInt_Context.hxx>
-#include <BOPInt_Tools.hxx>
-
-#include <BOPDS_Interf.hxx>
-#include <BOPDS_Iterator.hxx>
+#include <BOPCol_ListOfInteger.hxx>
+#include <BOPCol_ListOfShape.hxx>
+#include <BOPCol_MapOfInteger.hxx>
+#include <BOPCol_NCVector.hxx>
+#include <BOPCol_Parallel.hxx>
+#include <BOPDS_CommonBlock.hxx>
+#include <BOPDS_CoupleOfPaveBlocks.hxx>
 #include <BOPDS_Curve.hxx>
-#include <BOPDS_Point.hxx>
+#include <BOPDS_DataMapOfPaveBlockListOfPaveBlock.hxx>
+#include <BOPDS_DS.hxx>
 #include <BOPDS_FaceInfo.hxx>
-#include <BOPDS_Curve.hxx>
+#include <BOPDS_Interf.hxx>
+#include <BOPDS_Iterator.hxx>
+#include <BOPDS_ListOfPave.hxx>
+#include <BOPDS_ListOfPaveBlock.hxx>
 #include <BOPDS_MapOfPaveBlock.hxx>
 #include <BOPDS_PaveBlock.hxx>
+#include <BOPDS_Point.hxx>
+#include <BOPDS_ShapeInfo.hxx>
 #include <BOPDS_VectorOfCurve.hxx>
 #include <BOPDS_VectorOfPoint.hxx>
-#include <BOPDS_ShapeInfo.hxx>
-#include <BOPDS_PaveBlock.hxx>
-#include <BOPDS_ListOfPave.hxx>
-#include <BOPDS_ListOfPaveBlock.hxx>
-#include <BOPDS_CoupleOfPaveBlocks.hxx>
-#include <BOPDS_FaceInfo.hxx>
-#include <BOPDS_CommonBlock.hxx>
-
-#include <BOPAlgo_Tools.hxx>
+#include <BOPTools_AlgoTools.hxx>
+#include <BOPTools_AlgoTools3D.hxx>
+#include <BRep_Builder.hxx>
+#include <BRep_Tool.hxx>
+#include <BRepAdaptor_Curve.hxx>
+#include <BRepAdaptor_Surface.hxx>
+#include <BRepBndLib.hxx>
 #include <BRepBuilderAPI_MakeVertex.hxx>
+#include <BRepTools.hxx>
+#include <Geom2d_Curve.hxx>
+#include <Geom_Curve.hxx>
+#include <GeomAPI_ProjectPointOnCurve.hxx>
+#include <GeomAPI_ProjectPointOnSurf.hxx>
+#include <gp_Pnt.hxx>
+#include <IntSurf_ListOfPntOn2S.hxx>
+#include <IntSurf_PntOn2S.hxx>
+#include <IntTools_Context.hxx>
+#include <IntTools_Curve.hxx>
+#include <IntTools_EdgeFace.hxx>
+#include <IntTools_FaceFace.hxx>
+#include <IntTools_PntOn2Faces.hxx>
+#include <IntTools_SequenceOfCurves.hxx>
+#include <IntTools_SequenceOfPntOn2Faces.hxx>
+#include <IntTools_ShrunkRange.hxx>
+#include <IntTools_Tools.hxx>
+#include <NCollection_IncAllocator.hxx>
+#include <Precision.hxx>
 #include <TopExp.hxx>
-#include <BOPInt_ShrunkRange.hxx>
-#include <BOPDS_DataMapOfPaveBlockListOfPaveBlock.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS_Compound.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Vertex.hxx>
 
+//
 static void ToleranceFF(const BRepAdaptor_Surface& aBAS1,
                         const BRepAdaptor_Surface& aBAS2,
                         Standard_Real& aTolFF);
 
+/////////////////////////////////////////////////////////////////////////
+//=======================================================================
+//class    : BOPAlgo_FaceFace
+//purpose  : 
+//=======================================================================
+class BOPAlgo_FaceFace : 
+  public IntTools_FaceFace,
+  public BOPAlgo_Algo {
+
+ public:
+  DEFINE_STANDARD_ALLOC
+
+  BOPAlgo_FaceFace() : 
+    IntTools_FaceFace(),  
+    BOPAlgo_Algo(),
+    myIF1(-1), myIF2(-1), myTolFF(1.e-7) {
+  }
+  //
+  virtual ~BOPAlgo_FaceFace() {
+  }
+  //
+  void SetIndices(const Standard_Integer nF1,
+                  const Standard_Integer nF2) {
+    myIF1=nF1;
+    myIF2=nF2;
+  }
+  //
+  void Indices(Standard_Integer& nF1,
+               Standard_Integer& nF2) const {
+    nF1=myIF1;
+    nF2=myIF2;
+  }
+  //
+  void SetFaces(const TopoDS_Face& aF1,
+                const TopoDS_Face& aF2) {
+    myF1=aF1;
+    myF2=aF2;
+  }
+  //
+  const TopoDS_Face& Face1()const {
+    return myF1;
+  }
+  //
+  const TopoDS_Face& Face2()const {
+    return myF2;
+  }
+  //
+  void SetTolFF(const Standard_Real aTolFF) {
+    myTolFF=aTolFF;
+  }
+  //
+  Standard_Real TolFF() const{
+    return myTolFF;
+  }
+  //
+  virtual void Perform() {
+    BOPAlgo_Algo::UserBreak();
+    IntTools_FaceFace::Perform(myF1, myF2);
+  }
+  //
+ protected:
+  Standard_Integer myIF1;
+  Standard_Integer myIF2;
+  Standard_Real myTolFF;
+  TopoDS_Face myF1;
+  TopoDS_Face myF2;
+};
+//
+//=======================================================================
+typedef BOPCol_NCVector
+  <BOPAlgo_FaceFace> BOPAlgo_VectorOfFaceFace; 
+//
+typedef BOPCol_Functor 
+  <BOPAlgo_FaceFace,
+  BOPAlgo_VectorOfFaceFace> BOPAlgo_FaceFaceFunctor;
+//
+typedef BOPCol_Cnt 
+  <BOPAlgo_FaceFaceFunctor,
+  BOPAlgo_VectorOfFaceFace> BOPAlgo_FaceFaceCnt;
+/////////////////////////////////////////////////////////////////////////
 //=======================================================================
 //function : PerformFF
 //purpose  : 
@@ -113,15 +182,15 @@ void BOPAlgo_PaveFiller::PerformFF()
   //
   Standard_Boolean bJustAdd, bApp, bCompC2D1, bCompC2D2, bIsDone;
   Standard_Boolean bToSplit, bTangentFaces;
-  Standard_Integer nF1, nF2, aNbCurves, aNbPoints, iX, i, iP, iC, aNbLP;
+  Standard_Integer nF1, nF2, aNbCurves, aNbPoints, i, aNbLP;
+  Standard_Integer aNbFaceFace, k;
   Standard_Real aApproxTol, aTolR3D, aTolR2D, aTolFF;
   BRepAdaptor_Surface aBAS1, aBAS2;
   BOPCol_MapOfInteger aMI;
+  BOPAlgo_VectorOfFaceFace aVFaceFace;
   //
   BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
-  aFFs.SetStartSize(iSize);
   aFFs.SetIncrement(iSize);
-  aFFs.Init();
   //
   bApp=mySectionAttribute.Approximation();
   bCompC2D1=mySectionAttribute.PCurveOnS1();
@@ -157,15 +226,20 @@ void BOPAlgo_PaveFiller::PerformFF()
       bToIntersect = CheckPlanes(nF1, nF2);
       if (!bToIntersect) {
         myDS->AddInterf(nF1, nF2);
-        iX=aFFs.Append()-1;
-        BOPDS_InterfFF& aFF=aFFs(iX);
+        BOPDS_InterfFF& aFF=aFFs.Append1();
         aFF.SetIndices(nF1, nF2);
         aFF.Init(0, 0);
         continue;
       }
     }
     //
-    IntTools_FaceFace aFaceFace;
+    ToleranceFF(aBAS1, aBAS2, aTolFF); 
+    //
+    BOPAlgo_FaceFace& aFaceFace=aVFaceFace.Append1();
+    //
+    aFaceFace.SetIndices(nF1, nF2);
+    aFaceFace.SetFaces(aF1, aF2);
+    aFaceFace.SetTolFF(aTolFF);
     //
     IntSurf_ListOfPntOn2S aListOfPnts;
     GetEFPnts(nF1, nF2, aListOfPnts);
@@ -173,10 +247,21 @@ void BOPAlgo_PaveFiller::PerformFF()
     if (aNbLP) {
       aFaceFace.SetList(aListOfPnts);
     }
-
+    //
     aFaceFace.SetParameters(bApp, bCompC2D1, bCompC2D2, aApproxTol);
+    aFaceFace.SetProgressIndicator(myProgressIndicator);
+  }//for (; myIterator->More(); myIterator->Next()) {
+  //
+  aNbFaceFace=aVFaceFace.Extent();
+  //======================================================
+  BOPAlgo_FaceFaceCnt::Perform(myRunParallel, aVFaceFace);
+  //======================================================
+  //
+  for (k=0; k < aNbFaceFace; ++k) {
+    BOPAlgo_FaceFace& aFaceFace=aVFaceFace(k);
     //
-    aFaceFace.Perform(aF1, aF2);
+    aFaceFace.Indices(nF1, nF2);
+    aTolFF=aFaceFace.TolFF();
     //
     bIsDone=aFaceFace.IsDone();
     if (bIsDone) {
@@ -184,8 +269,6 @@ void BOPAlgo_PaveFiller::PerformFF()
       aTolR2D=aFaceFace.TolReached2d();
       bTangentFaces=aFaceFace.TangentFaces();
       //
-      ToleranceFF(aBAS1, aBAS2, aTolFF);
-      //
       if (aTolR3D < aTolFF){
         aTolR3D=aTolFF;
       }
@@ -201,10 +284,11 @@ void BOPAlgo_PaveFiller::PerformFF()
       aNbCurves=aCvsX.Length();
       aNbPoints=aPntsX.Length();
       //
-      myDS->AddInterf(nF1, nF2);
+      if (aNbCurves || aNbPoints) {
+        myDS->AddInterf(nF1, nF2);
+      } 
       //
-      iX=aFFs.Append()-1;
-      BOPDS_InterfFF& aFF=aFFs(iX);
+      BOPDS_InterfFF& aFF=aFFs.Append1();
       aFF.SetIndices(nF1, nF2);
       //
       aFF.SetTolR3D(aTolR3D);
@@ -221,10 +305,9 @@ void BOPAlgo_PaveFiller::PerformFF()
         //
         const IntTools_Curve& aIC=aCvsX(i);
         const Handle(Geom_Curve)& aC3D= aIC.Curve();
-        bValid=BOPInt_Tools::CheckCurve(aC3D, aTolR3D, aBox);
+        bValid=IntTools_Tools::CheckCurve(aC3D, aTolR3D, aBox);
         if (bValid) {
-          iC=aVNC.Append()-1;
-          BOPDS_Curve& aNC=aVNC(iC);
+          BOPDS_Curve& aNC=aVNC.Append1();
           aNC.SetCurve(aIC);
           aNC.SetBox(aBox);
         }
@@ -236,21 +319,19 @@ void BOPAlgo_PaveFiller::PerformFF()
         const IntTools_PntOn2Faces& aPi=aPntsX(i);
         const gp_Pnt& aP=aPi.P1().Pnt();
         //
-        iP=aVNP.Append()-1;
-        BOPDS_Point& aNP=aVNP(iP);
+        BOPDS_Point& aNP=aVNP.Append1();
         aNP.SetPnt(aP);
       }
     //}// if (aNbCs || aNbPs)
     }// if (bIsDone) {
     else {// 904/L1
-      iX=aFFs.Append()-1;
-      BOPDS_InterfFF& aFF=aFFs(iX);
+      BOPDS_InterfFF& aFF=aFFs.Append1();
       aFF.SetIndices(nF1, nF2);
       aNbCurves=0;
       aNbPoints=0;
       aFF.Init(aNbCurves, aNbPoints);
     }
-  }// for (; myIterator->More(); myIterator->Next()) {
+  }// for (k=0; k < aNbFaceFace; ++k) {
 }
 //=======================================================================
 //function : MakeBlocks
@@ -271,7 +352,7 @@ void BOPAlgo_PaveFiller::MakeBlocks()
   Standard_Boolean bExist, bValid2D;
   Standard_Integer i, nF1, nF2, aNbC, aNbP, j;
   Standard_Integer nV1, nV2;
-  Standard_Real aTolR3D, aTolR2D, aT1, aT2, aTol;
+  Standard_Real aTolR3D, aT1, aT2, aTol;
   Handle(NCollection_IncAllocator) aAllocator;
   BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
   TopoDS_Edge aES;
@@ -280,21 +361,25 @@ void BOPAlgo_PaveFiller::MakeBlocks()
   //-----------------------------------------------------scope f
   aAllocator=new NCollection_IncAllocator();
   //
-  BOPCol_ListOfInteger aLSE(aAllocator);
+  BOPCol_ListOfInteger aLSE(aAllocator), aLBV(aAllocator);
   BOPCol_MapOfInteger aMVOnIn(100, aAllocator), aMF(100, aAllocator),
                       aMVStick(100,aAllocator), aMVEF(100, aAllocator),
-                      aMVB(100, aAllocator), aMI(100, aAllocator);
-  BOPDS_MapOfPaveBlock aMPBOnIn(100, aAllocator),
-                       aMPBAdd(100, aAllocator);
+                      aMI(100, aAllocator);
+  BOPDS_IndexedMapOfPaveBlock aMPBOnIn(100, aAllocator);
+  BOPDS_MapOfPaveBlock aMPBAdd(100, aAllocator);
   BOPDS_ListOfPaveBlock aLPB(aAllocator);
   BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMSCPB(100, aAllocator); 
   BOPCol_DataMapOfShapeInteger aMVI(100, aAllocator);
   BOPDS_DataMapOfPaveBlockListOfPaveBlock aDMExEdges(100, aAllocator);
   BOPCol_DataMapOfIntegerReal aMVTol(100, aAllocator);
-  BOPCol_DataMapIteratorOfDataMapOfIntegerReal aItMV;
   BOPCol_DataMapOfIntegerInteger aDMI(100, aAllocator);
+  BOPCol_DataMapOfIntegerListOfInteger aDMBV(100, aAllocator);
+  BOPCol_DataMapIteratorOfDataMapOfIntegerReal aItMV;
   //
   for (i=0; i<aNbFF; ++i) {
+    //
+    UserBreak();
+    //
     BOPDS_InterfFF& aFF=aFFs(i);
     aFF.Indices(nF1, nF2);
     //
@@ -310,22 +395,23 @@ void BOPAlgo_PaveFiller::MakeBlocks()
     const TopoDS_Face& aF2=(*(TopoDS_Face *)(&myDS->Shape(nF2)));
     //
     aTolR3D=aFF.TolR3D();
-    aTolR2D=aFF.TolR2D();
     //
     // Update face info
     if (aMF.Add(nF1)) {
       myDS->UpdateFaceInfoOn(nF1);
+      myDS->UpdateFaceInfoIn(nF1);
     }
     if (aMF.Add(nF2)) {
       myDS->UpdateFaceInfoOn(nF2);
+      myDS->UpdateFaceInfoIn(nF2);
     }
-   
+    //
     BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
     BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
     //
     aMVOnIn.Clear();
     aMPBOnIn.Clear();
-    aMVB.Clear();
+    aDMBV.Clear();
     aMVTol.Clear();
     //
     myDS->VerticesOnIn(nF1, nF2, aMVOnIn, aMPBOnIn);
@@ -369,7 +455,13 @@ void BOPAlgo_PaveFiller::MakeBlocks()
       }
       //
       if (aIC.HasBounds()) {
-        PutBoundPaveOnCurve(aF1, aF2, aTolR3D, aNC, aMVOnIn, aMVB);
+        aLBV.Clear();
+        //
+        PutBoundPaveOnCurve(aF1, aF2, aTolR3D, aNC, aLBV);
+        //
+        if (!aLBV.IsEmpty()) {
+          aDMBV.Bind(j, aLBV);
+        }
       }
     }//for (j=0; j<aNbC; ++j) {
     //
@@ -400,7 +492,8 @@ void BOPAlgo_PaveFiller::MakeBlocks()
           continue;
         }
         //
-        bValid2D=myContext->IsValidBlockForFaces(aT1, aT2, aIC, aF1, aF2, aTolR3D);
+        bValid2D=myContext->IsValidBlockForFaces(aT1, aT2, aIC, 
+                                                 aF1, aF2, aTolR3D);
         if (!bValid2D) {
           continue;
         }
@@ -432,7 +525,7 @@ void BOPAlgo_PaveFiller::MakeBlocks()
                               aFI2.PaveBlocksIn().Contains(aPBOut));
             }
             if (!bInBothFaces) {
-              PreparePostTreatFF(i, aPBOut, aMSCPB, aMVI, aVC);
+              PreparePostTreatFF(i, j, aPBOut, aMSCPB, aMVI, aLPBC);
             }
           }
           continue;
@@ -442,7 +535,8 @@ void BOPAlgo_PaveFiller::MakeBlocks()
         const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
         const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
         //
-        BOPTools_AlgoTools::MakeEdge (aIC, aV1, aT1, aV2, aT2, aTolR3D, aES);
+        BOPTools_AlgoTools::MakeEdge (aIC, aV1, aT1, 
+                                      aV2, aT2, aTolR3D, aES);
         BOPTools_AlgoTools::MakePCurve(aES, aF1, aF2, aIC, 
                                        mySectionAttribute.PCurveOnS1(),
                                        mySectionAttribute.PCurveOnS2());
@@ -477,11 +571,12 @@ void BOPAlgo_PaveFiller::MakeBlocks()
       aTol = aItMV.Value();
       //
       const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV1);
-      const Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*)&aV.TShape());
+      const Handle(BRep_TVertex)& TV = 
+        *((Handle(BRep_TVertex)*)&aV.TShape());
       TV->Tolerance(aTol);
     }
     //
-    ProcessExistingPaveBlocks(i, aMPBOnIn, aMSCPB, aMVI, aMVB, aMPBAdd);
+    ProcessExistingPaveBlocks(i, aMPBOnIn, aDMBV, aMSCPB, aMVI, aMPBAdd);
   }//for (i=0; i<aNbFF; ++i) {
   // 
   // post treatment
@@ -491,7 +586,7 @@ void BOPAlgo_PaveFiller::MakeBlocks()
   }
   //
   // update face info
-  UpdateFaceInfo(aDMExEdges);
+  UpdateFaceInfo(aDMExEdges, aDMI);
   //Update all pave blocks
   UpdatePaveBlocks(aDMI);
   //-----------------------------------------------------scope t
@@ -509,7 +604,7 @@ void BOPAlgo_PaveFiller::MakeBlocks()
 //function : PostTreatFF
 //purpose  : 
 //=======================================================================
-  Standard_Integer BOPAlgo_PaveFiller::PostTreatFF
+Standard_Integer BOPAlgo_PaveFiller::PostTreatFF
     (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMSCPB,
      BOPCol_DataMapOfShapeInteger& aMVI,
      BOPDS_DataMapOfPaveBlockListOfPaveBlock& aDMExEdges,
@@ -542,8 +637,6 @@ void BOPAlgo_PaveFiller::MakeBlocks()
   //
   BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
   //
-  // <-DEB f
-  //
   // 0
   if (aNbS==1) {
     const TopoDS_Shape& aS=theMSCPB.FindKey(1);
@@ -588,11 +681,12 @@ void BOPAlgo_PaveFiller::MakeBlocks()
   }
   //
   // 2 Fuse shapes
+  aPF.SetProgressIndicator(myProgressIndicator);
+  aPF.SetRunParallel(myRunParallel);
   aPF.SetArguments(aLS);
   aPF.Perform();
   iErr=aPF.ErrorStatus();
   if (iErr) {
-    iRet=1;
     return iRet;
   }
   aPDS=aPF.PDS();
@@ -649,7 +743,8 @@ void BOPAlgo_PaveFiller::MakeBlocks()
       if (!bHasPaveBlocks) {
         if (bOld) {
           aDMExEdges.ChangeFind(aPB1).Append(aPB1);
-        } else {
+        }
+        else {
           aSI.SetShapeType(aType);
           aSI.SetShape(aSx);
           iE=myDS->Append(aSI);
@@ -730,7 +825,8 @@ void BOPAlgo_PaveFiller::MakeBlocks()
                 nV=aPave[j].Index();
                 aV=aPDS->Shape(nV);
                 //
-                if (!aMVI.IsBound(aV)) {// index of new vertex in theDS -> iV
+                if (!aMVI.IsBound(aV)) {
+                  // index of new vertex in theDS -> iV
                   aSI.SetShapeType(TopAbs_VERTEX);
                   aSI.SetShape(aV);
                   iV=myDS->Append(aSI);
@@ -741,8 +837,10 @@ void BOPAlgo_PaveFiller::MakeBlocks()
                 }
               }
               const BOPDS_Pave& aP1 = !j ? aPB1->Pave1() : aPB1->Pave2();
-              if (aP1.Parameter() == aPave[j].Parameter() && aP1.Index() != iV) {
+              if (aP1.Parameter() == aPave[j].Parameter() && 
+                  aP1.Index() != iV) {
                 aDMI.Bind(aP1.Index(), iV);
+                myDS->AddShapeSD(aP1.Index(), iV);
               }
               //
               aPave[j].SetIndex(iV);
@@ -785,12 +883,14 @@ void BOPAlgo_PaveFiller::MakeBlocks()
 //function : UpdateFaceInfo
 //purpose  : 
 //=======================================================================
-void BOPAlgo_PaveFiller::UpdateFaceInfo(BOPDS_DataMapOfPaveBlockListOfPaveBlock& theDME)
+void BOPAlgo_PaveFiller::UpdateFaceInfo
+  (BOPDS_DataMapOfPaveBlockListOfPaveBlock& theDME,
+   const BOPCol_DataMapOfIntegerInteger& theDMV)
 {
   Standard_Integer i, j, nV1, nF1, nF2, 
-                   aNbFF, aNbC, aNbP, aNbS, aNbPBIn;
-  BOPDS_IndexedMapOfPaveBlock aMPBCopy;
+                   aNbFF, aNbC, aNbP;
   BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
+  BOPCol_MapOfInteger aMF;
   //
   BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
   aNbFF=aFFs.Extent();
@@ -803,73 +903,124 @@ void BOPAlgo_PaveFiller::UpdateFaceInfo(BOPDS_DataMapOfPaveBlockListOfPaveBlock&
     BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
     BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
     //
+    // 1.1. Section edges
     BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves();
     aNbC=aVNC.Extent();
     for (j=0; j<aNbC; ++j) {
       BOPDS_Curve& aNC=aVNC(j);
       BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
-      aItLPB.Initialize(aLPBC);
       //
-      if (aItLPB.More() && theDME.IsBound(aLPBC.First())) {
-        const Handle(BOPDS_PaveBlock)& aPB=aLPBC.First();
-        BOPDS_ListOfPaveBlock& aLPB = theDME.ChangeFind(aPB);
-        UpdateExistingPaveBlocks(aPB, aLPB, nF1, nF2);
-        aLPBC.Clear();
-        continue;
-      }
-      //
-      for(; aItLPB.More(); aItLPB.Next()) {
+      // Add section edges to face info
+      aItLPB.Initialize(aLPBC);
+      for (; aItLPB.More(); ) {
         const Handle(BOPDS_PaveBlock)& aPB=aItLPB.Value();
+        //
+        // Treat existing pave blocks
+        if (theDME.IsBound(aPB)) {
+          BOPDS_ListOfPaveBlock& aLPB=theDME.ChangeFind(aPB);
+          UpdateExistingPaveBlocks(aPB, aLPB, nF1, nF2);
+          aLPBC.Remove(aItLPB);
+          continue;
+        }
+        //
         aFI1.ChangePaveBlocksSc().Add(aPB);
         aFI2.ChangePaveBlocksSc().Add(aPB);
+        aItLPB.Next();
       }
     }
-    // VerticesSc
+    //
+    // 1.2. Section vertices
     const BOPDS_VectorOfPoint& aVNP=aFF.Points();
     aNbP=aVNP.Extent();
     for (j=0; j<aNbP; ++j) {
       const BOPDS_Point& aNP=aVNP(j);
       nV1=aNP.Index();
+      if (nV1<0) {
+        continue;
+      }
       aFI1.ChangeVerticesSc().Add(nV1);
       aFI2.ChangeVerticesSc().Add(nV1);
     }
+    //
+    aMF.Add(nF1);
+    aMF.Add(nF2);
   }
   //
-  //2. PaveBlocksIn
-  if (theDME.IsEmpty()) {
+  Standard_Boolean bVerts, bEdges;
+  //
+  bVerts = theDMV.Extent() > 0;
+  bEdges = theDME.Extent() > 0;
+  //
+  if (!bVerts && !bEdges) {
     return;
   }
   //
-  aNbS=myDS->NbSourceShapes();
-  for (i=0; i<aNbS; ++i) {
-    const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
-    if (aSI.ShapeType()!=TopAbs_FACE) {
-      continue;
-    }
-    if(!myDS->HasFaceInfo(i)) {
-      continue;
-    }
-    BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(i);
+  // 2. Update Face Info information with new vertices and new
+  //    pave blocks created in PostTreatFF from existing ones
+  Standard_Integer nV2, aNbPB;
+  BOPCol_MapIteratorOfMapOfInteger aItMF;
+  BOPCol_DataMapIteratorOfDataMapOfIntegerInteger aItMV;
+  //
+  aItMF.Initialize(aMF);
+  for (; aItMF.More(); aItMF.Next()) {
+    nF1 = aItMF.Value();
     //
-    BOPDS_IndexedMapOfPaveBlock& aMPBIn=aFI.ChangePaveBlocksIn();
-    aMPBCopy.Assign(aMPBIn);
-    aMPBIn.Clear();
+    BOPDS_FaceInfo& aFI = myDS->ChangeFaceInfo(nF1);
     //
-    aNbPBIn=aMPBCopy.Extent();
-    for (j=1; j<=aNbPBIn; ++j) {
-      const Handle(BOPDS_PaveBlock)& aPB = aMPBCopy(j);
-      if (theDME.IsBound(aPB)) {
-        const BOPDS_ListOfPaveBlock& aLPB = theDME.Find(aPB);
-        aItLPB.Initialize(aLPB);
-        for (; aItLPB.More(); aItLPB.Next()) {
-          const Handle(BOPDS_PaveBlock)& aPB1 = aItLPB.Value();
-          aMPBIn.Add(aPB1);
+    // 2.1. Update information about vertices
+    if (bVerts) {
+      BOPCol_MapOfInteger& aMVOn = aFI.ChangeVerticesOn();
+      BOPCol_MapOfInteger& aMVIn = aFI.ChangeVerticesIn();
+      //
+      aItMV.Initialize(theDMV);
+      for (; aItMV.More(); aItMV.Next()) {
+        nV1 = aItMV.Key();
+        nV2 = aItMV.Value();
+        //
+        if (aMVOn.Remove(nV1)) {
+          aMVOn.Add(nV2);
         }
-      } else {
-        aMPBIn.Add(aPB);
-      }
-    }//for (j=1; j<=aNbPBIn; ++j) {
-  }//for (i=0; i<aNbS; ++i) {
+        //
+        if (aMVIn.Remove(nV1)) {
+          aMVIn.Add(nV2);
+        }
+      } // for (; aItMV.More(); aItMV.Next()) {
+    } // if (bVerts) {
+    //
+    // 2.2. Update information about pave blocks
+    if (bEdges) {
+      BOPDS_IndexedMapOfPaveBlock& aMPBOn = aFI.ChangePaveBlocksOn();
+      BOPDS_IndexedMapOfPaveBlock& aMPBIn = aFI.ChangePaveBlocksIn();
+      //
+      BOPDS_IndexedMapOfPaveBlock aMPBCopy;
+      for (i = 0; i < 2; ++i) {
+        BOPDS_IndexedMapOfPaveBlock& aMPBOnIn = !i ? aMPBOn : aMPBIn;
+        aMPBCopy = aMPBOnIn;
+        aMPBOnIn.Clear();
+        //
+        aNbPB = aMPBCopy.Extent();
+        for (j = 1; j <= aNbPB; ++j) {
+          const Handle(BOPDS_PaveBlock)& aPB = aMPBCopy(j);
+          if (theDME.IsBound(aPB)) {
+            const BOPDS_ListOfPaveBlock& aLPB = theDME.Find(aPB);
+            if (aLPB.IsEmpty()) {
+              aMPBOnIn.Add(aPB);
+              continue;
+            }
+            //
+            aItLPB.Initialize(aLPB);
+            for (; aItLPB.More(); aItLPB.Next()) {
+              const Handle(BOPDS_PaveBlock)& aPB1 = aItLPB.Value();
+              aMPBOnIn.Add(aPB1);
+            }
+          }
+          else {
+            aMPBOnIn.Add(aPB);
+          }
+        } // for (j = 1; j <= aNbPB; ++j) {
+      } // for (i = 0; i < 2; ++i) {
+    } // if (bEdges) {
+  }
 }
 //=======================================================================
 //function : IsExistingVertex
@@ -966,15 +1117,14 @@ void BOPAlgo_PaveFiller::UpdateFaceInfo(BOPDS_DataMapOfPaveBlockListOfPaveBlock&
     (const Handle(BOPDS_PaveBlock)& thePB,
      const BOPDS_Curve& theNC,
      const Standard_Real theTolR3D,
-     const BOPDS_MapOfPaveBlock& theMPBOnIn,
-     Handle(BOPDS_PaveBlock&) aPBOut)
+     const BOPDS_IndexedMapOfPaveBlock& theMPBOnIn,
+     Handle(BOPDS_PaveBlock)& aPBOut)
 {
   Standard_Boolean bRet;
   Standard_Real aT1, aT2, aTm, aTx;
-  Standard_Integer nSp, iFlag1, iFlag2, nV11, nV12, nV21, nV22;
+  Standard_Integer nSp, iFlag1, iFlag2, nV11, nV12, nV21, nV22, i, aNbPB;
   gp_Pnt aP1, aPm, aP2;
   Bnd_Box aBoxP1, aBoxPm, aBoxP2;
-  BOPDS_MapIteratorOfMapOfPaveBlock aIt;
   //
   bRet=Standard_False;
   const IntTools_Curve& aIC=theNC.Curve();
@@ -995,19 +1145,24 @@ void BOPAlgo_PaveFiller::UpdateFaceInfo(BOPDS_DataMapOfPaveBlockListOfPaveBlock&
   aBoxP2.Add(aP2);
   aBoxP2.Enlarge(theTolR3D);
   //
-  aIt.Initialize(theMPBOnIn);
-  for (; aIt.More(); aIt.Next()) {
-    const Handle(BOPDS_PaveBlock)& aPB=aIt.Value();
+  aNbPB = theMPBOnIn.Extent();
+  for (i = 1; i <= aNbPB; ++i) {
+    const Handle(BOPDS_PaveBlock)& aPB = theMPBOnIn(i);
     aPB->Indices(nV21, nV22);
     nSp=aPB->Edge();
     const BOPDS_ShapeInfo& aSISp=myDS->ChangeShapeInfo(nSp);
     const TopoDS_Edge& aSp=(*(TopoDS_Edge *)(&aSISp.Shape()));
     const Bnd_Box& aBoxSp=aSISp.Box();
     //
-    iFlag1 = (nV11 == nV21 || nV11 == nV22) ? 2 : (!aBoxSp.IsOut(aBoxP1) ? 1 : 0);
-    iFlag2 = (nV12 == nV21 || nV12 == nV22) ? 2 : (!aBoxSp.IsOut(aBoxP2) ? 1 : 0);
+    iFlag1 = (nV11 == nV21 || nV11 == nV22) ? 2 : 
+      (!aBoxSp.IsOut(aBoxP1) ? 1 : 0);
+    iFlag2 = (nV12 == nV21 || nV12 == nV22) ? 2 : 
+      (!aBoxSp.IsOut(aBoxP2) ? 1 : 0);
     if (iFlag1 && iFlag2) {
-      if (aBoxSp.IsOut(aBoxPm) || myContext->ComputePE(aPm, theTolR3D, aSp, aTx)) {
+      if (aBoxSp.IsOut(aBoxPm) || myContext->ComputePE(aPm, 
+                                                       theTolR3D, 
+                                                       aSp, 
+                                                       aTx)) {
         continue;
       }
       //
@@ -1028,7 +1183,6 @@ void BOPAlgo_PaveFiller::UpdateFaceInfo(BOPDS_DataMapOfPaveBlockListOfPaveBlock&
   }
   return bRet;
 }
-
 //=======================================================================
 //function : PutBoundPaveOnCurve
 //purpose  : 
@@ -1037,8 +1191,7 @@ void BOPAlgo_PaveFiller::UpdateFaceInfo(BOPDS_DataMapOfPaveBlockListOfPaveBlock&
                                                const TopoDS_Face& aF2,
                                                const Standard_Real aTolR3D,
                                                BOPDS_Curve& aNC,
-                                               BOPCol_MapOfInteger& aMVOnIn,
-                                               BOPCol_MapOfInteger& aMVB)
+                                               BOPCol_ListOfInteger& aLVB)
 {
   Standard_Boolean bVF;
   Standard_Integer nV, iFlag, nVn, j, aNbEP;
@@ -1126,8 +1279,8 @@ void BOPAlgo_PaveFiller::UpdateFaceInfo(BOPDS_DataMapOfPaveBlockListOfPaveBlock&
       BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nVn);
       Bnd_Box& aBoxDS=aSIDS.ChangeBox();
       BRepBndLib::Add(aVn, aBoxDS);
-      aMVOnIn.Add(nVn);
-      aMVB.Add(nVn);
+      //
+      aLVB.Append(nVn);
     }
   }
 }
@@ -1136,14 +1289,15 @@ void BOPAlgo_PaveFiller::UpdateFaceInfo(BOPDS_DataMapOfPaveBlockListOfPaveBlock&
 //function : PutPavesOnCurve
 //purpose  : 
 //=======================================================================
-  void BOPAlgo_PaveFiller::PutPavesOnCurve(const BOPCol_MapOfInteger& aMVOnIn,
-                                           const Standard_Real aTolR3D,
-                                           BOPDS_Curve& aNC,
-                                           const Standard_Integer nF1,
-                                           const Standard_Integer nF2,
-                                           const BOPCol_MapOfInteger& aMI,
-                                           const BOPCol_MapOfInteger& aMVEF,
-                                           BOPCol_DataMapOfIntegerReal& aMVTol)
+  void BOPAlgo_PaveFiller::PutPavesOnCurve
+  (const BOPCol_MapOfInteger& aMVOnIn,
+   const Standard_Real aTolR3D,
+   BOPDS_Curve& aNC,
+   const Standard_Integer nF1,
+   const Standard_Integer nF2,
+   const BOPCol_MapOfInteger& aMI,
+   const BOPCol_MapOfInteger& aMVEF,
+   BOPCol_DataMapOfIntegerReal& aMVTol)
 {
   Standard_Boolean bInBothFaces;
   Standard_Integer nV;
@@ -1192,10 +1346,11 @@ void BOPAlgo_PaveFiller::UpdateFaceInfo(BOPDS_DataMapOfPaveBlockListOfPaveBlock&
 //function : ExtendedTolerance
 //purpose  : 
 //=======================================================================
-Standard_Boolean BOPAlgo_PaveFiller::ExtendedTolerance(const Standard_Integer nV,
-                                                       const BOPCol_MapOfInteger& aMI,
-                                                       Standard_Real& aTolVExt,
-                                                       const Standard_Integer aType)
+Standard_Boolean BOPAlgo_PaveFiller::ExtendedTolerance
+  (const Standard_Integer nV,
+   const BOPCol_MapOfInteger& aMI,
+   Standard_Real& aTolVExt,
+   const Standard_Integer aType)
 {
   Standard_Boolean bFound = Standard_False;
   if (!(myDS->IsNewShape(nV))) {
@@ -1227,7 +1382,8 @@ Standard_Boolean BOPAlgo_PaveFiller::ExtendedTolerance(const Standard_Integer nV
       BOPDS_Interf *aInt = !k ? (BOPDS_Interf*) (&aEEs(i)) :
         (BOPDS_Interf*) (&aEFs(i));
       if (aInt->IndexNew() == nV) {
-        if (aMI.Contains(aInt->Index1()) && aMI.Contains(aInt->Index2())) {
+        if (aMI.Contains(aInt->Index1()) && 
+            aMI.Contains(aInt->Index2())) {
           const IntTools_CommonPrt& aComPrt = !k ? aEEs(i).CommonPart() :
             aEFs(i).CommonPart();
           //
@@ -1276,15 +1432,17 @@ Standard_Boolean BOPAlgo_PaveFiller::ExtendedTolerance(const Standard_Integer nV
         const IntTools_CommonPrt& aCP = aEF.CommonPart();
         Standard_Real aPar = aCP.VertexParameter1();
         const TopoDS_Edge& aE = (*(TopoDS_Edge*)(&myDS->Shape(nE)));
-        const TopoDS_Face& aFOpposite = (*(TopoDS_Face*)(&myDS->Shape(nFOpposite)));
+        const TopoDS_Face& aFOpposite = 
+          (*(TopoDS_Face*)(&myDS->Shape(nFOpposite)));
         //
         const Handle(Geom_Curve)& aCurve = BRep_Tool::Curve(aE, f, l);
         //
         nF = (nFOpposite == nF1) ? nF2 : nF1;
         const TopoDS_Face& aF = (*(TopoDS_Face*)(&myDS->Shape(nF)));
-        Handle(Geom2d_Curve) aPCurve = BRep_Tool::CurveOnSurface(aE, aF, f, l);
+        Handle(Geom2d_Curve) aPCurve = 
+          BRep_Tool::CurveOnSurface(aE, aF, f, l);
         //
-        GeomAPI_ProjectPointOnSurf& aProj = myContext->ProjPS(aFOpposite);
+        GeomAPI_ProjectPointOnSurf& aProj=myContext->ProjPS(aFOpposite);
         //
         gp_Pnt aPoint;
         aCurve->D0(aPar, aPoint);
@@ -1326,10 +1484,11 @@ Standard_Boolean BOPAlgo_PaveFiller::ExtendedTolerance(const Standard_Integer nV
 //function : ProcessUnUsedVertices
 //purpose  : 
 //=======================================================================
-  void BOPAlgo_PaveFiller::PutEFPavesOnCurve(BOPDS_Curve& aNC,
-                                             const BOPCol_MapOfInteger& aMI,
-                                             const BOPCol_MapOfInteger& aMVEF,
-                                             BOPCol_DataMapOfIntegerReal& aMVTol)
+  void BOPAlgo_PaveFiller::PutEFPavesOnCurve
+  (BOPDS_Curve& aNC,
+   const BOPCol_MapOfInteger& aMI,
+   const BOPCol_MapOfInteger& aMVEF,
+   BOPCol_DataMapOfIntegerReal& aMVTol)
 {
   if (!aMVEF.Extent()) {
     return;
@@ -1376,12 +1535,13 @@ Standard_Boolean BOPAlgo_PaveFiller::ExtendedTolerance(const Standard_Integer nV
 //function : ProcessUnUsedVertices
 //purpose  : 
 //=======================================================================
-  void BOPAlgo_PaveFiller::PutStickPavesOnCurve(const TopoDS_Face& aF1,
-                                                const TopoDS_Face& aF2,
-                                                const BOPCol_MapOfInteger& aMI,
-                                                BOPDS_Curve& aNC,
-                                                const BOPCol_MapOfInteger& aMVStick,
-                                                BOPCol_DataMapOfIntegerReal& aMVTol)
+  void BOPAlgo_PaveFiller::PutStickPavesOnCurve
+  (const TopoDS_Face& aF1,
+   const TopoDS_Face& aF2,
+   const BOPCol_MapOfInteger& aMI,
+   BOPDS_Curve& aNC,
+   const BOPCol_MapOfInteger& aMVStick,
+   BOPCol_DataMapOfIntegerReal& aMVTol)
 {
   BOPCol_MapOfInteger aMV;
   aMV.Assign(aMVStick);
@@ -1391,75 +1551,65 @@ Standard_Boolean BOPAlgo_PaveFiller::ExtendedTolerance(const Standard_Integer nV
     return;
   }
   //
-  GeomAbs_SurfaceType aType1, aType2;
   Handle(Geom_Surface) aS1=BRep_Tool::Surface(aF1);
   Handle(Geom_Surface) aS2=BRep_Tool::Surface(aF2);
-  GeomAdaptor_Surface aGAS1(aS1);
-  GeomAdaptor_Surface aGAS2(aS2);
   //
-  aType1=aGAS1.GetType();
-  aType2=aGAS2.GetType();
-  //
-  if (aType1==GeomAbs_Torus  || aType2==GeomAbs_Torus) {
-    GeomAbs_CurveType aTypeC;
+  const IntTools_Curve& aIC=aNC.Curve();
+  //if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) {
+  Handle(Geom2d_Curve) aC2D[2];
+  //
+  aC2D[0]=aIC.FirstCurve2d();
+  aC2D[1]=aIC.SecondCurve2d();
+  if (!aC2D[0].IsNull() && !aC2D[1].IsNull()) {
+    Standard_Integer nV, m, n;
+    Standard_Real aTC[2], aD, aD2, u, v, aDT2, aScPr, aDScPr;
+    gp_Pnt aPC[2], aPV;
+    gp_Dir aDN[2];
+    gp_Pnt2d aP2D;
+    BOPCol_MapIteratorOfMapOfInteger aItMI, aItMI1;
     //
-    const IntTools_Curve& aIC=aNC.Curve();
-    aTypeC=aIC.Type();
-    if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) {
-      Handle(Geom2d_Curve) aC2D[2];
+    aDT2=2e-7;     // the rich criteria
+    aDScPr=5.e-9;  // the creasing criteria
+    aIC.Bounds(aTC[0], aTC[1], aPC[0], aPC[1]);
+    //
+    aItMI.Initialize(aMV);
+    for (; aItMI.More(); aItMI.Next()) {
+      nV = aItMI.Value();
+      const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&myDS->Shape(nV));
+      aPV=BRep_Tool::Pnt(aV);
       //
-      aC2D[0]=aIC.FirstCurve2d();
-      aC2D[1]=aIC.SecondCurve2d();
-      if (!aC2D[0].IsNull() && !aC2D[1].IsNull()) {
-        Standard_Integer nV, m, n;
-        Standard_Real aTC[2], aD, aD2, u, v, aDT2, aScPr, aDScPr;
-        gp_Pnt aPC[2], aPV;
-        gp_Dir aDN[2];
-        gp_Pnt2d aP2D;
-        BOPCol_MapIteratorOfMapOfInteger aItMI, aItMI1;
+      for (m=0; m<2; ++m) {
+        aD2=aPC[m].SquareDistance(aPV);
+        if (aD2>aDT2) {// no rich
+          continue; 
+        }
         //
-        aDT2=2e-7;     // the rich criteria
-        aDScPr=5.e-9;  // the creasing criteria
-        aIC.Bounds(aTC[0], aTC[1], aPC[0], aPC[1]);
+        for (n=0; n<2; ++n) {
+          Handle(Geom_Surface)& aS=(!n)? aS1 : aS2;
+          aC2D[n]->D0(aTC[m], aP2D);
+          aP2D.Coord(u, v);
+          BOPTools_AlgoTools3D::GetNormalToSurface(aS, u, v, aDN[n]);
+        }
+        // 
+        aScPr=aDN[0]*aDN[1];
+        if (aScPr<0.) {
+          aScPr=-aScPr;
+        }
+        aScPr=1.-aScPr;
         //
-        aItMI.Initialize(aMV);
-        for (; aItMI.More(); aItMI.Next()) {
-          nV = aItMI.Value();
-          const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&myDS->Shape(nV));
-          aPV=BRep_Tool::Pnt(aV);
-          //
-          for (m=0; m<2; ++m) {
-            aD2=aPC[m].SquareDistance(aPV);
-            if (aD2>aDT2) {// no rich
-              continue; 
-            }
-            //
-            for (n=0; n<2; ++n) {
-              Handle(Geom_Surface)& aS=(!n)? aS1 : aS2;
-              aC2D[n]->D0(aTC[m], aP2D);
-              aP2D.Coord(u, v);
-              BOPTools_AlgoTools3D::GetNormalToSurface(aS, u, v, aDN[n]);
-            }
-            // 
-            aScPr=aDN[0]*aDN[1];
-            if (aScPr<0.) {
-              aScPr=-aScPr;
-            }
-            aScPr=1.-aScPr;
-            //
-            if (aScPr>aDScPr) {
-              continue;
-            }
-            //
-            // The intersection curve aIC is vanishing curve (the crease)
-            aD=sqrt(aD2);
-            //
-            PutPaveOnCurve(nV, aD, aNC, aMI, aMVTol);
-          }
-        }//for (jVU=1; jVU=aNbVU; ++jVU) {
+        if (aScPr>aDScPr) {
+          continue;
+        }
+        //
+        // The intersection curve aIC is vanishing curve (the crease)
+        aD=sqrt(aD2);
+        //
+        PutPaveOnCurve(nV, aD, aNC, aMI, aMVTol);
       }
-    }//if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) {
-  }//if(aType1==GeomAbs_Torus  || aType2==GeomAbs_Torus) {
+    }//for (jVU=1; jVU=aNbVU; ++jVU) {
+  }
+  //}//if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) {
+  //}//if(aType1==GeomAbs_Torus  || aType2==GeomAbs_Torus) {
 }
 
 //=======================================================================
@@ -1480,8 +1630,10 @@ Standard_Boolean BOPAlgo_PaveFiller::ExtendedTolerance(const Standard_Integer nV
   BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
   BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
   //
-  Standard_Integer aNbLines[5] = {aVVs.Extent(), aVEs.Extent(), aEEs.Extent(),
-                                  aVFs.Extent(), aEFs.Extent()};
+  Standard_Integer aNbLines[5] = {
+    aVVs.Extent(), aVEs.Extent(), aEEs.Extent(),
+    aVFs.Extent(), aEFs.Extent()
+    };
   //collect indices of all shapes from nF1 and nF2.
   aMI.Clear();
   GetFullShapeMap(nF1, aMI);
@@ -1492,7 +1644,8 @@ Standard_Boolean BOPAlgo_PaveFiller::ExtendedTolerance(const Standard_Integer nV
     for (i = 0; i < aNbLines[aTypeInt]; ++i) {
       BOPDS_Interf* aInt = (aTypeInt==0) ? (BOPDS_Interf*)(&aVVs(i)) : 
         ((aTypeInt==1) ? (BOPDS_Interf*)(&aVEs(i)) :
-         ((aTypeInt==2) ? (BOPDS_Interf*)(&aEEs(i)) : (BOPDS_Interf*)(&aVFs(i))));
+         ((aTypeInt==2) ? (BOPDS_Interf*)(&aEEs(i)) : 
+          (BOPDS_Interf*)(&aVFs(i))));
       if (aInt->HasIndexNew()) {
         aInt->Indices(nS1, nS2);
         if(aMI.Contains(nS1) && aMI.Contains(nS2)) {
@@ -1565,12 +1718,13 @@ void BOPAlgo_PaveFiller::RemoveUsedVertices(BOPDS_Curve& aNC,
 //function : PutPaveOnCurve
 //purpose  : 
 //=======================================================================
-  void BOPAlgo_PaveFiller::PutPaveOnCurve(const Standard_Integer nV,
-                                          const Standard_Real aTolR3D,
-                                          BOPDS_Curve& aNC,
-                                          const BOPCol_MapOfInteger& aMI,
-                                          BOPCol_DataMapOfIntegerReal& aMVTol,
-                                          const Standard_Integer iCheckExtend)
+  void BOPAlgo_PaveFiller::PutPaveOnCurve
+  (const Standard_Integer nV,
+   const Standard_Real aTolR3D,
+   BOPDS_Curve& aNC,
+   const BOPCol_MapOfInteger& aMI,
+   BOPCol_DataMapOfIntegerReal& aMVTol,
+   const Standard_Integer iCheckExtend)
 {
   Standard_Boolean bIsVertexOnLine;
   Standard_Real aT, aTol, aTolNew;
@@ -1617,59 +1771,74 @@ void BOPAlgo_PaveFiller::RemoveUsedVertices(BOPDS_Curve& aNC,
 //=======================================================================
   void BOPAlgo_PaveFiller::ProcessExistingPaveBlocks
     (const Standard_Integer theInt,
-     const BOPDS_MapOfPaveBlock& aMPBOnIn,
+     const BOPDS_IndexedMapOfPaveBlock& aMPBOnIn,
+     const BOPCol_DataMapOfIntegerListOfInteger& aDMBV,
      BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& aMSCPB,
      BOPCol_DataMapOfShapeInteger& aMVI,
-     const BOPCol_MapOfInteger& aMVB,
      BOPDS_MapOfPaveBlock& aMPB)
 {
-  Standard_Integer nV, nE, iFlag;
+  if (aDMBV.IsEmpty()) {
+    return;
+  }
+  //
   Standard_Real aT;
-  BOPCol_MapIteratorOfMapOfInteger aItB;
-  BOPDS_MapIteratorOfMapOfPaveBlock aItPB;
+  Standard_Integer i, nV, nE, iC, aNbPB, iFlag;
+  BOPCol_ListIteratorOfListOfInteger aItLI;
+  BOPCol_DataMapIteratorOfDataMapOfIntegerListOfInteger aItBV;
   //
-  BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
+  BOPDS_VectorOfInterfFF& aFFs = myDS->InterfFF();
   BOPDS_InterfFF& aFF = aFFs(theInt);
-  BOPDS_VectorOfCurve& aVC=aFF.ChangeCurves();
-  //  
-  aItB.Initialize(aMVB);
-  for (; aItB.More(); aItB.Next()) {
-    nV = aItB.Value();
-    const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
-    const Bnd_Box& aBoxV=aSIV.Box();
-    const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&aSIV.Shape();
-    if (!aMVI.IsBound(aV)) {
-      continue;
-    }
+  BOPDS_VectorOfCurve& aVC = aFF.ChangeCurves();
+  //
+  aNbPB = aMPBOnIn.Extent();
+  //
+  aItBV.Initialize(aDMBV);
+  for (; aItBV.More(); aItBV.Next()) {
+    iC = aItBV.Key();
+    const BOPCol_ListOfInteger& aLBV = aItBV.Value();
     //
-    aItPB.Initialize(aMPBOnIn);
-    for (; aItPB.More(); aItPB.Next()) {
-      const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
-      if (aPB->Pave1().Index() == nV || aPB->Pave2().Index() == nV) {
-        continue;
-      }
-      //
-      if (aMPB.Contains(aPB)) {
+    BOPDS_Curve& aNC = aVC.ChangeValue(iC);
+    BOPDS_ListOfPaveBlock& aLPBC = aNC.ChangePaveBlocks();
+    //
+    aItLI.Initialize(aLBV);
+    for (; aItLI.More(); aItLI.Next()) {
+      nV = aItLI.Value();
+      const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
+      const Bnd_Box& aBoxV=aSIV.Box();
+      const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&aSIV.Shape();
+      if (!aMVI.IsBound(aV)) {
         continue;
       }
-      nE=aPB->Edge();
-      const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
-      const Bnd_Box& aBoxE=aSIE.Box();
       //
-      if (!aBoxV.IsOut(aBoxE)) {
+      for (i = 1; i <= aNbPB; ++i) {
+        const Handle(BOPDS_PaveBlock)& aPB = aMPBOnIn(i);
+        if (aPB->Pave1().Index() == nV || aPB->Pave2().Index() == nV) {
+          continue;
+        }
+        //
+        if (aMPB.Contains(aPB)) {
+          continue;
+        }
+        //
+        nE = aPB->Edge();
+        const BOPDS_ShapeInfo& aSIE = myDS->ShapeInfo(nE);
+        const Bnd_Box& aBoxE = aSIE.Box();
+        //
+        if (aBoxV.IsOut(aBoxE)) {
+          continue;
+        }
+        //
         const TopoDS_Edge& aE = *(TopoDS_Edge*)&aSIE.Shape();
         //
-        iFlag=myContext->ComputeVE (aV, aE, aT);
+        iFlag = myContext->ComputeVE(aV, aE, aT);
         if (!iFlag) {
           aMPB.Add(aPB);
-          //
-          PreparePostTreatFF(theInt, aPB, aMSCPB, aMVI, aVC);
+          PreparePostTreatFF(theInt, iC, aPB, aMSCPB, aMVI, aLPBC);
         }
       }
     }
   }
 }
-
 //=======================================================================
 //function : UpdateExistingPaveBlocks
 //purpose  : 
@@ -1685,9 +1854,8 @@ void BOPAlgo_PaveFiller::RemoveUsedVertices(BOPDS_Curve& aNC,
   Handle(BOPDS_PaveBlock) aPB, aPB1, aPB2, aPB2n;
   Handle(BOPDS_CommonBlock) aCB;
   BOPDS_ListIteratorOfListOfPaveBlock aIt, aIt1, aIt2;
-  BOPDS_IndexedMapOfPaveBlock aMPB;
   //
-  //remove micro edges from aLPB
+  // 1. Remove micro edges from aLPB
   aIt.Initialize(aLPB);
   for (; aIt.More();) {
     aPB = aIt.Value();
@@ -1702,10 +1870,6 @@ void BOPAlgo_PaveFiller::RemoveUsedVertices(BOPDS_Curve& aNC,
   if (!aLPB.Extent()) {
     return;
   }
-  //update face info
-  myDS->UpdateFaceInfoOn(nF1);
-  //
-  myDS->UpdateFaceInfoOn(nF2);
   //
   BOPDS_FaceInfo& aFI1 = myDS->ChangeFaceInfo(nF1);
   BOPDS_FaceInfo& aFI2 = myDS->ChangeFaceInfo(nF2);
@@ -1715,7 +1879,7 @@ void BOPAlgo_PaveFiller::RemoveUsedVertices(BOPDS_Curve& aNC,
   BOPDS_IndexedMapOfPaveBlock& aMPBOn2 = aFI2.ChangePaveBlocksOn();
   BOPDS_IndexedMapOfPaveBlock& aMPBIn2 = aFI2.ChangePaveBlocksIn();
   //
-  // remove old pave blocks
+  // 2. Remove old pave blocks
   const Handle(BOPDS_CommonBlock)& aCB1 = myDS->CommonBlock(aPBf);
   bCB = !aCB1.IsNull();
   BOPDS_ListOfPaveBlock aLPB1;
@@ -1741,12 +1905,14 @@ void BOPAlgo_PaveFiller::RemoveUsedVertices(BOPDS_Curve& aNC,
     }
   }
   //
+  // 3. Update pave blocks
   if (bCB) {
-    //create new pave blocks
+    //create new common blocks
+    BOPDS_ListOfPaveBlock aLPBNew;
     const BOPCol_ListOfInteger& aFaces = aCB1->Faces();
     aIt.Initialize(aLPB);
     for (; aIt.More(); aIt.Next()) {
-      Handle(BOPDS_PaveBlock)& aPB = aIt.ChangeValue();
+      const Handle(BOPDS_PaveBlock)& aPB = aIt.Value();
       //
       aCB = new BOPDS_CommonBlock;
       aIt1.Initialize(aLPB1);
@@ -1766,60 +1932,75 @@ void BOPAlgo_PaveFiller::RemoveUsedVertices(BOPDS_Curve& aNC,
       aCB->AddFaces(aFaces);
       myDS->SortPaveBlocks(aCB);
       //
-      aPB=aCB->PaveBlocks().First();
+      const Handle(BOPDS_PaveBlock)& aPBNew = aCB->PaveBlocks().First();
+      aLPBNew.Append(aPBNew);
     }
-  } 
-  //
-  aIt.Initialize(aLPB);
-  for (; aIt.More(); aIt.Next()) {
-    Handle(BOPDS_PaveBlock)& aPB = aIt.ChangeValue();
-    nE = aPB->OriginalEdge();
     //
-    Standard_Integer nF = (aMPBOn1.Contains(aPBf) || 
-                           aMPBIn1.Contains(aPBf)) ? nF2 : nF1;
-    const TopoDS_Face& aF = *(TopoDS_Face*)&myDS->Shape(nF);
-    IntTools_Range aShrR(aPB->Pave1().Parameter(), aPB->Pave2().Parameter());
-    const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge());
-    //
-    Standard_Boolean bCom = BOPTools_AlgoTools::IsBlockInOnFace(aShrR, aF, aE, myContext);
-    if (bCom) {
-      if (bCB) {
-        aCB = myDS->CommonBlock(aPB);
-        aCB->AddFace(nF);
-      } else {
-        aCB = new BOPDS_CommonBlock;
-        aCB->AddPaveBlock(aPB);
-        aCB->AddFace(nF1);
-        aCB->AddFace(nF2);
-        //
-        myDS->SetCommonBlock(aPB, aCB);
-      }
-      aMPB.Add(aPB);
-    }
-    if (!bCB) {
-      myDS->ChangePaveBlocks(nE).Append(aPB);
+    aLPB = aLPBNew;
+  } 
+  else {
+    nE = aPBf->OriginalEdge();
+    BOPDS_ListOfPaveBlock& aLPBE = myDS->ChangePaveBlocks(nE);
+    aIt.Initialize(aLPB);
+    for (; aIt.More(); aIt.Next()) {
+      aPB = aIt.Value();
+      aLPBE.Append(aPB);
     }
   }
   //
-  Standard_Integer i, aNbPB;
   Standard_Boolean bIn1, bIn2;
   //
   bIn1 = aMPBOn1.Contains(aPBf) || aMPBIn1.Contains(aPBf);
   bIn2 = aMPBOn2.Contains(aPBf) || aMPBIn2.Contains(aPBf);
   //
-  aNbPB=aMPB.Extent();
-  for (i=1; i<=aNbPB; ++i) {
-    aPB = aMPB(i);
-    if (!bIn1) {
-      aMPBIn1.Add(aPB);
-    }
+  if (bIn1 && bIn2) {
+    return;
+  }
+  //
+  // 4. Check new pave blocks for coincidence 
+  //    with the opposite face.
+  //    In case of coincidence create common blocks
+  Standard_Integer nF;
+  Standard_Real aTolE, aTolF;
+  //
+  nF = bIn1 ? nF2 : nF1;
+  const TopoDS_Face& aF = *(TopoDS_Face*)&myDS->Shape(nF);
+  BOPDS_IndexedMapOfPaveBlock& aMPBIn = bIn1 ? aMPBIn2 : aMPBIn1;
+  aTolF = BRep_Tool::Tolerance(aF);
+  //
+  aIt.Initialize(aLPB);
+  for (; aIt.More(); aIt.Next()) {
+    Handle(BOPDS_PaveBlock)& aPB = aIt.ChangeValue();
+    const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge());
+    aTolE = BRep_Tool::Tolerance(aE);
+    //
+    IntTools_EdgeFace anEF;
+    anEF.SetEdge(aE);
+    anEF.SetFace(aF);
+    anEF.SetTolE(aTolE);
+    anEF.SetTolF(aTolF);
+    anEF.SetRange(aPB->Pave1().Parameter(), aPB->Pave2().Parameter());
+    anEF.SetContext(myContext);
+    anEF.Perform();
     //
-    if (!bIn2) {
-      aMPBIn2.Add(aPB);
+    const IntTools_SequenceOfCommonPrts& aCPrts=anEF.CommonParts();
+    if (aCPrts.Length() == 1) {
+      Standard_Boolean bCoinc = (aCPrts(1).Type() == TopAbs_EDGE);
+      if (bCoinc) {
+        if (bCB) {
+          aCB = myDS->CommonBlock(aPB);
+        } else {
+          aCB = new BOPDS_CommonBlock;
+          aCB->AddPaveBlock(aPB);
+          myDS->SetCommonBlock(aPB, aCB);
+        }
+        aCB->AddFace(nF);
+        //
+        aMPBIn.Add(aPB);
+      }
     }
   }
 }
-
 //=======================================================================
 // function: PutClosingPaveOnCurve
 // purpose:
@@ -1875,22 +2056,20 @@ void BOPAlgo_PaveFiller::RemoveUsedVertices(BOPDS_Curve& aNC,
     }
   }
 }
-
 //=======================================================================
 //function : PreparePostTreatFF
 //purpose  : 
 //=======================================================================
   void BOPAlgo_PaveFiller::PreparePostTreatFF
     (const Standard_Integer aInt,
+     const Standard_Integer aCur,
      const Handle(BOPDS_PaveBlock)& aPB,
      BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& aMSCPB,
      BOPCol_DataMapOfShapeInteger& aMVI,
-     BOPDS_VectorOfCurve& aVC) 
+     BOPDS_ListOfPaveBlock& aLPBC)
 {
   Standard_Integer nV1, nV2;
   //
-  Standard_Integer iC=aVC.Append()-1;
-  BOPDS_ListOfPaveBlock& aLPBC = aVC(iC).ChangePaveBlocks();
   aLPBC.Append(aPB);
   //
   aPB->Indices(nV1, nV2);
@@ -1900,7 +2079,7 @@ void BOPAlgo_PaveFiller::RemoveUsedVertices(BOPDS_Curve& aNC,
   // Keep info for post treatment 
   BOPDS_CoupleOfPaveBlocks aCPB;
   aCPB.SetIndexInterf(aInt);
-  aCPB.SetIndex(iC);
+  aCPB.SetIndex(aCur);
   aCPB.SetPaveBlock1(aPB);
   //
   aMSCPB.Add(aE, aCPB);
@@ -1912,9 +2091,9 @@ void BOPAlgo_PaveFiller::RemoveUsedVertices(BOPDS_Curve& aNC,
 //function : CheckPlanes
 //purpose  : 
 //=======================================================================
-Standard_Boolean 
-  BOPAlgo_PaveFiller::CheckPlanes(const Standard_Integer nF1,
-                                  const Standard_Integer nF2)const
+Standard_Boolean BOPAlgo_PaveFiller::CheckPlanes
+  (const Standard_Integer nF1,
+   const Standard_Integer nF2)const
 {
   Standard_Boolean bToIntersect;
   Standard_Integer i, nV2, iCnt;
@@ -1952,7 +2131,8 @@ Standard_Boolean
 //function : UpdatePaveBlocks
 //purpose  : 
 //=======================================================================
-void BOPAlgo_PaveFiller::UpdatePaveBlocks(const BOPCol_DataMapOfIntegerInteger& aDMI)
+void BOPAlgo_PaveFiller::UpdatePaveBlocks
+  (const BOPCol_DataMapOfIntegerInteger& aDMI)
 {
   if (aDMI.IsEmpty()) {
     return;