Salome HOME
0023128: [CEA 1555] FuseCollinearEdgesWithinWire fails on the outline of a square...
authorskv <skv@opencascade.com>
Tue, 28 Jul 2015 12:38:27 +0000 (15:38 +0300)
committerskv <skv@opencascade.com>
Tue, 28 Jul 2015 12:38:27 +0000 (15:38 +0300)
src/GEOMImpl/GEOMImpl_HealingDriver.cxx
src/GEOMImpl/GEOMImpl_ShapeDriver.cxx

index 3c519465c76fad30fb043e9b86e5deaf8b9fe45c..fab57241a61731153ec96b7e589dea27593da6ec 100644 (file)
@@ -804,25 +804,73 @@ void GEOMImpl_HealingDriver::FuseCollinearEdges (const TopoDS_Shape& theOriginal
   theWire = TopoDS::Wire(Fixer->Shape());
   */
 
-  TopoDS_Edge prevEdge;
-  TopTools_ListOfShape finalList, currChain;
-
-  BRepTools_WireExplorer wexp (theWire);
-  if (wexp.More()) {
-    prevEdge = wexp.Current();
-    currChain.Append(prevEdge);
-    wexp.Next();
+  // Get the ordered list of edges.
+  TopTools_ListOfShape   anEdges;
+  TopTools_ListOfShape   aCurVertices;
+  BRepTools_WireExplorer aWExp (theWire);
+
+  for (; aWExp.More(); aWExp.Next()) {
+    anEdges.Append(aWExp.Current());
+    aCurVertices.Append(aWExp.CurrentVertex());
   }
-  else {
+
+  if (anEdges.IsEmpty()) {
     Standard_NullObject::Raise("Empty wire given");
   }
 
-  for (; wexp.More(); wexp.Next()) {
-    TopoDS_Edge anEdge = wexp.Current();
-    TopoDS_Vertex CurVertex = wexp.CurrentVertex();
+  // Treat the case if the wire is closed and first and last edges are C1.
+  Standard_Boolean isShift = Standard_False;
+
+  if (BRep_Tool::IsClosed(theWire)) {
+    // Wire is closed. Check if there are more than 2 edges in the wire.
+    if (!anEdges.First().IsSame(anEdges.Last())) {
+      isShift = Standard_True;
+    }
+  }
+
+  if (isShift) {
+    // Put first edge to the end of the list while the chain break is reached.
+    TopoDS_Shape aFirstEdge = anEdges.First();
+
+    while (isShift) {
+      isShift = Standard_False;
+
+      // Check if the first vertex should be kept
+      if (aMapToRemove.Contains(aCurVertices.First()) || removeAll) {
+        // Check if first and last edges are C1.
+        TopoDS_Edge anEdge1 = TopoDS::Edge(anEdges.Last());
+        TopoDS_Edge anEdge2 = TopoDS::Edge(anEdges.First());
+
+        if (AreEdgesC1(anEdge1, anEdge2)) {
+          // Make the first edge last.
+          anEdges.Append(anEdge2);
+          anEdges.RemoveFirst();
+          aCurVertices.Append(aCurVertices.First());
+          aCurVertices.RemoveFirst();
+
+          // Check if we reached the first edge again.
+          // Break the loop in this case.
+          isShift = !aFirstEdge.IsSame(anEdges.First());
+        }
+      }
+    }
+  }
+
+  TopTools_ListOfShape finalList, currChain;
+  TopTools_ListIteratorOfListOfShape anEIter(anEdges);
+  TopTools_ListIteratorOfListOfShape aVIter(aCurVertices);
+  TopoDS_Edge                        prevEdge = TopoDS::Edge(anEIter.Value());
+
+  currChain.Append(prevEdge);
+  anEIter.Next();
+  aVIter.Next();
+
+  for (; anEIter.More(); anEIter.Next(), aVIter.Next()) {
+    TopoDS_Edge         anEdge     = TopoDS::Edge(anEIter.Value());
+    const TopoDS_Shape &aCurVertex = aVIter.Value();
 
     bool continueChain = false;
-    if (aMapToRemove.Contains(CurVertex) || removeAll) {
+    if (aMapToRemove.Contains(aCurVertex) || removeAll) {
       // if C1 -> continue chain
       if (AreEdgesC1(prevEdge, anEdge)) {
         continueChain = true;
index 933ad9eea273c2c693c4ee3250f12c6d401d06be..5462bbdf40f78b8703ddd58e931e15fd1cdce47e 100644 (file)
@@ -861,11 +861,13 @@ TopoDS_Edge GEOMImpl_ShapeDriver::MakeEdgeFromWire(const TopoDS_Shape& aWire,
       {
         Standard_Boolean Done = Standard_False;
         Standard_Real NewFpar, NewLpar;
-        GeomAdaptor_Curve GAprevcurve(CurveSeq.Last());
+        Handle(Geom_Geometry) aTrsfGeom = CurveSeq.Last()->Transformed
+                      (LocSeq.Last().Location().Transformation());
+        GeomAdaptor_Curve GAprevcurve(Handle(Geom_Curve)::DownCast(aTrsfGeom));
         TopoDS_Vertex CurVertex = wexp.CurrentVertex();
         TopoDS_Vertex CurFirstVer = TopExp::FirstVertex(anEdge);
         TopAbs_Orientation ConnectByOrigin = (CurVertex.IsSame(CurFirstVer))? TopAbs_FORWARD : TopAbs_REVERSED;
-        if (aCurve == CurveSeq.Last())
+        if (aCurve == CurveSeq.Last() && aLoc.IsEqual(LocSeq.Last().Location()))
         {
           NewFpar = fpar;
           NewLpar = lpar;