Salome HOME
Merge V8_4_BR branch.
[modules/geom.git] / src / BlockFix / BlockFix_UnionEdges.cxx
index 62a0307c5b269c602593f7ad0bcfa9ded82bf0cf..642953f67586b53a98a0e56eca31009b3f36134c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -150,7 +150,7 @@ static Standard_Boolean IsToMerge
     // Check if they belong to the same faces.
     Standard_Boolean isSame = Standard_False;
     Standard_Boolean has1   = theMapEdgeFaces.Contains(theEdge1);
-    Standard_Boolean has2   = theMapEdgeFaces.Contains(theEdge1);
+    Standard_Boolean has2   = theMapEdgeFaces.Contains(theEdge2);
 
     if (has1 && has2) {
       const TopTools_ListOfShape &aLst1 = theMapEdgeFaces.FindFromKey(theEdge1);
@@ -161,7 +161,7 @@ static Standard_Boolean IsToMerge
 
         isSame = Standard_True;
 
-        for (; anIter1.More(); anIter1.Next()) {
+        for (; anIter1.More() && isSame; anIter1.Next()) {
           TopoDS_Face aFace1 = TopoDS::Face(anIter1.Value());
           TopTools_ListIteratorOfListOfShape  anIter2(aLst2);
 
@@ -463,7 +463,7 @@ static TopoDS_Edge GlueEdgesWithPCurves(const TopTools_SequenceOfShape& aChain,
 
 //=======================================================================
 //function : MergeEdges
-//purpose  : auxilary
+//purpose  : auxiliary
 //=======================================================================
 static Standard_Boolean MergeEdges(const TopTools_SequenceOfShape& SeqEdges,
                                    const Standard_Real Tol,
@@ -581,16 +581,24 @@ static Standard_Boolean MergeEdges(const TopTools_SequenceOfShape& SeqEdges,
       if (C.IsNull()) {
         // jfa for Mantis issue 0020228
         if (PV1.Distance(PV2) > Precision::Confusion()) continue;
-        // closed chain
-        if (edge1.Orientation() == TopAbs_FORWARD) {
-          C = C1;
-        } else {
-          C = Handle(Geom_Circle)::DownCast(C1->Reversed());
+        // closed chain. Make a closed circular edge starting from V1.
+        gp_Ax1 anAxis = C1->Axis();
+
+        if (edge1.Orientation() == TopAbs_REVERSED) {
+          anAxis.Reverse();
         }
 
+        const gp_Pnt &aP0 = anAxis.Location();
+        gp_Dir        aDX(PV1.XYZ().Subtracted(aP0.XYZ()));
+        gp_Ax2        aNewAxis(aP0, anAxis.Direction(), aDX);
+
+        C = new Geom_Circle(aNewAxis, C1->Radius());
+
         B.MakeEdge (E,C,Precision::Confusion());
         B.Add(E,V1);
         B.Add(E,V2);
+        B.UpdateVertex(V1, 0., E, 0.);
+        B.UpdateVertex(V2, 2.*M_PI, E, 0.);
       }
       else {
         gp_Pnt P0 = C->Location();