0026619: Tolerances of operands are modified using bop
[occt.git] / src / BOPAlgo / BOPAlgo_PaveFiller_1.cxx
index 418bdae..1780f1f 100644 (file)
@@ -20,6 +20,7 @@
 #include <BOPAlgo_PaveFiller.hxx>
 #include <BOPAlgo_SectionAttribute.hxx>
 #include <BOPAlgo_Tools.hxx>
+#include <BOPCol_DataMapOfIntegerInteger.hxx>
 #include <BOPCol_DataMapOfIntegerListOfInteger.hxx>
 #include <BOPCol_ListOfShape.hxx>
 #include <BOPCol_MapOfInteger.hxx>
 #include <BOPDS_VectorOfInterfVV.hxx>
 #include <BOPTools_AlgoTools.hxx>
 #include <BRepBndLib.hxx>
+#include <BRep_TVertex.hxx>
+#include <BRep_Tool.hxx>
 #include <gp_Pnt.hxx>
 #include <IntTools_Context.hxx>
 #include <NCollection_BaseAllocator.hxx>
+#include <Precision.hxx>
+#include <TopoDS.hxx>
 #include <TopoDS_Face.hxx>
 #include <TopoDS_Vertex.hxx>
 
 void BOPAlgo_PaveFiller::PerformVV() 
 {
   Standard_Boolean bWithSubShape;
-  Standard_Integer n1, n2, iFlag, nX, n, aSize, i, j, k, aNbBlocks;
+  Standard_Integer n1, n2, iFlag, aSize, k, aNbBlocks;
   Handle(NCollection_BaseAllocator) aAllocator;
-  BOPCol_ListIteratorOfListOfInteger aItLI, aItLI2;
-  TopoDS_Vertex aVn;
-  BOPDS_ShapeInfo aSIn;
   //
   myErrorStatus=0;
   //
@@ -58,8 +60,6 @@ void BOPAlgo_PaveFiller::PerformVV()
     return; 
   }
   //
-  aSIn.SetShapeType(TopAbs_VERTEX);
-  
   BOPDS_VectorOfInterfVV& aVVs=myDS->InterfVV();
   aVVs.SetIncrement(aSize);
   //
@@ -68,7 +68,6 @@ void BOPAlgo_PaveFiller::PerformVV()
     NCollection_BaseAllocator::CommonBaseAllocator();
   BOPCol_IndexedDataMapOfIntegerListOfInteger aMILI(100, aAllocator);
   BOPCol_DataMapOfIntegerListOfInteger aMBlocks(100, aAllocator);
-  BOPCol_ListOfShape aLV(aAllocator);
   //
   // 1. Map V/LV
   for (; myIterator->More(); myIterator->Next()) {
@@ -91,47 +90,80 @@ void BOPAlgo_PaveFiller::PerformVV()
   for (k=0; k<aNbBlocks; ++k) {
     const BOPCol_ListOfInteger& aLI=aMBlocks.Find(k);
     //
-    aLV.Clear();
-    aItLI.Initialize(aLI);
-    for (; aItLI.More(); aItLI.Next()) {
-      nX=aItLI.Value();
-      const TopoDS_Shape& aV=myDS->Shape(nX);
-      aLV.Append(aV);
-    }
-    //
-    BOPTools_AlgoTools::MakeVertex(aLV, aVn);
-    //
-    // Appennd new vertex to the DS
-    aSIn.SetShape(aVn);
-    n=myDS->Append(aSIn);
-    //
-    BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(n);
-    Bnd_Box& aBox=aSIDS.ChangeBox();
-    BRepBndLib::Add(aVn, aBox);
-    //
-    // Fill ShapesSD
-    aItLI.Initialize(aLI);
-    for (i=0; aItLI.More(); aItLI.Next(), ++i) {
-      n1=aItLI.Value();
-      myDS->AddShapeSD(n1, n);
-      //
-      aItLI2.Initialize(aLI);
-      for (j=0; aItLI2.More(); aItLI2.Next(), ++j) {
-        if (j>i) {
-          n2=aItLI2.Value();
-          //
-          myDS->AddInterf(n1, n2);
-          BOPDS_InterfVV& aVV=aVVs.Append1();
-          //
-          aVV.SetIndices(n1, n2);
-          aVV.SetIndexNew(n);
-        }
-      }
-    }
+    MakeSDVertices(aLI);
+  }
+  //
+  BOPCol_DataMapIteratorOfDataMapOfIntegerInteger aItDMII;
+  //
+  BOPCol_DataMapOfIntegerInteger& aDMII=myDS->ShapesSD();
+  aItDMII.Initialize(aDMII);
+  for (; aItDMII.More(); aItDMII.Next()) {
+    n1=aItDMII.Key();
+    myDS->InitPaveBlocksForVertex(n1);
   }
   //
   //-----------------------------------------------------scope t
-  aLV.Clear();
   aMBlocks.Clear();
   aMILI.Clear();
 }
+
+//=======================================================================
+// function: PerformVV
+// purpose: 
+//=======================================================================
+void BOPAlgo_PaveFiller::MakeSDVertices(const BOPCol_ListOfInteger& theVertIndices)
+{
+  TopoDS_Vertex aVSD, aVn;
+  BOPCol_ListIteratorOfListOfInteger aItLI(theVertIndices);
+  BOPCol_ListOfShape aLV;
+  for (; aItLI.More(); aItLI.Next()) {
+    Standard_Integer nX = aItLI.Value();
+    Standard_Integer nSD;
+    if (myDS->HasShapeSD(nX, nSD)) {
+      aVSD = TopoDS::Vertex(myDS->Shape(nSD));
+    }
+    const TopoDS_Shape& aV = myDS->Shape(nX);
+    aLV.Append(aV);
+  }
+  BOPTools_AlgoTools::MakeVertex(aLV, aVn);
+  if (!aVSD.IsNull()) {
+    // update old SD vertex with new value
+    Handle(BRep_TVertex)& aTVertex =
+      reinterpret_cast<Handle(BRep_TVertex)&>(const_cast<Handle(TopoDS_TShape)&>(aVSD.TShape()));
+    aTVertex->Pnt(BRep_Tool::Pnt(aVn));
+    aTVertex->Tolerance(BRep_Tool::Tolerance(aVn));
+  }
+  //
+  // Append new vertex to the DS
+  BOPDS_ShapeInfo aSIn;
+  aSIn.SetShapeType(TopAbs_VERTEX);
+  aSIn.SetShape(aVn);
+  Standard_Integer n = myDS->Append(aSIn);
+  //
+  BOPDS_ShapeInfo& aSIDS = myDS->ChangeShapeInfo(n);
+  Bnd_Box& aBox = aSIDS.ChangeBox();
+  BRepBndLib::Add(aVn, aBox);
+  aBox.SetGap(aBox.GetGap() + Precision::Confusion());
+  //
+  // Fill ShapesSD
+  BOPDS_VectorOfInterfVV& aVVs = myDS->InterfVV();
+  aVVs.SetIncrement(theVertIndices.Extent());
+  //
+  aItLI.Initialize(theVertIndices);
+  for (; aItLI.More(); aItLI.Next()) {
+    Standard_Integer n1 = aItLI.Value();
+    myDS->AddShapeSD(n1, n);
+    //
+    BOPCol_ListIteratorOfListOfInteger aItLI2 = aItLI;
+    aItLI2.Next();
+    for (; aItLI2.More(); aItLI2.Next()) {
+      Standard_Integer n2 = aItLI2.Value();
+      //
+      myDS->AddInterf(n1, n2);
+      BOPDS_InterfVV& aVV = aVVs.Append1();
+      //
+      aVV.SetIndices(n1, n2);
+      aVV.SetIndexNew(n);
+    }
+  }
+}