From: skv Date: Tue, 28 Jul 2015 12:38:27 +0000 (+0300) Subject: 0023128: [CEA 1555] FuseCollinearEdgesWithinWire fails on the outline of a square... X-Git-Tag: V7_7_0a1~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d7f33d79e41ce83f5126af2d8a44c7c3078b81bd;p=modules%2Fgeom.git 0023128: [CEA 1555] FuseCollinearEdgesWithinWire fails on the outline of a square face partitioned --- diff --git a/src/GEOMImpl/GEOMImpl_HealingDriver.cxx b/src/GEOMImpl/GEOMImpl_HealingDriver.cxx index 3c519465c..fab57241a 100644 --- a/src/GEOMImpl/GEOMImpl_HealingDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_HealingDriver.cxx @@ -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; diff --git a/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx b/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx index 933ad9eea..5462bbdf4 100644 --- a/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx @@ -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;