From: azv Date: Tue, 24 Jan 2017 10:05:07 +0000 (+0300) Subject: Improve searching of start vertex in SketchBuilder (issue #2013) X-Git-Tag: V_2.7.0~313 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6e91aadd81f8371e76fb277c2732993d12a5ed23;p=modules%2Fshaper.git Improve searching of start vertex in SketchBuilder (issue #2013) --- diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp index 3b3b4d548..62a879f57 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,45 @@ static TopoDS_Vertex findStartVertex(const TopoDS_Shape& theShape) return aStart; } +static TopoDS_Vertex findStartVertex(const TopoDS_Shape& theShape, + const std::list >& theInitialShapes) +{ + // Try to find edge lying on the one of original edges. + // First found edge will be taken as a start edge for the result wire + std::list >::const_iterator aFeatIt = theInitialShapes.begin(); + for (; aFeatIt != theInitialShapes.end(); aFeatIt++) { + std::shared_ptr aShape(*aFeatIt); + const TopoDS_Edge& anEdge = aShape->impl(); + if (anEdge.ShapeType() != TopAbs_EDGE) + continue; + + double aFirst, aLast; + Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast); + if (aCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) + aCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve)->BasisCurve(); + + TopExp_Explorer anExp(theShape, TopAbs_EDGE); + for (; anExp.More(); anExp.Next()) { + const TopoDS_Edge& aShapeEdge = TopoDS::Edge(anExp.Current()); + double aF, aL; + Handle(Geom_Curve) aShapeCurve = BRep_Tool::Curve(aShapeEdge, aF, aL); + if (aShapeCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) + aShapeCurve = Handle(Geom_TrimmedCurve)::DownCast(aShapeCurve)->BasisCurve(); + + if (aCurve != aShapeCurve) + continue; + + // the edge is found, search vertex + TopoDS_Vertex aV1, aV2; + TopExp::Vertices(aShapeEdge, aV1, aV2); + return fabs(aF - aFirst) <= fabs(aL - aFirst) ? aV1 : aV2; + } + } + + // start vertex is not found, use algorithm to search vertex with the greatest coordinates + return findStartVertex(theShape); +} + void GeomAlgoAPI_SketchBuilder::createFaces( const std::shared_ptr& theOrigin, const std::shared_ptr& theDirX, @@ -99,8 +139,8 @@ void GeomAlgoAPI_SketchBuilder::createFaces( TopoDS_Wire aWire = TopoDS::Wire(aWireExp.Current()); // to make faces equal on different platforms, we will find - // a vertex with greater coordinates and start wire from it - TopoDS_Vertex aStartVertex = findStartVertex(aWire); + // a vertex lying on an edge with the lowest index in the list of initial edges + TopoDS_Vertex aStartVertex = findStartVertex(aWire, theFeatures); TopoDS_Wire aNewWire; aBuilder.MakeWire(aNewWire);