From da72b47cfe8770de32f2b8cdc069b82df9136f43 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Mon, 6 Apr 2020 09:58:01 +0800 Subject: [PATCH] Path: handle open edges when sorting path --- src/Mod/Path/App/Area.cpp | 52 +++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/src/Mod/Path/App/Area.cpp b/src/Mod/Path/App/Area.cpp index fe552ecbd9..1badf749da 100644 --- a/src/Mod/Path/App/Area.cpp +++ b/src/Mod/Path/App/Area.cpp @@ -1138,37 +1138,63 @@ static void showShapes(const T &shapes, const char *name, const char *fmt=0, ... } template -static int foreachSubshape(const TopoDS_Shape &shape, Func func, int type=TopAbs_FACE) { - bool haveShape = false; +static int foreachSubshape(const TopoDS_Shape &shape, + Func func, int type=TopAbs_FACE, bool groupOpenEdges=false) +{ + int res = -1; + std::vector openShapes; switch(type) { case TopAbs_SOLID: for(TopExp_Explorer it(shape,TopAbs_SOLID); it.More(); it.Next()) { - haveShape = true; + res = TopAbs_SOLID; func(it.Current(),TopAbs_SOLID); } - if(haveShape) return TopAbs_SOLID; + if(res>=0) break; //fall through case TopAbs_FACE: for(TopExp_Explorer it(shape,TopAbs_FACE); it.More(); it.Next()) { - haveShape = true; + res = TopAbs_FACE; func(it.Current(),TopAbs_FACE); } - if(haveShape) return TopAbs_FACE; + if(res>=0) break; //fall through case TopAbs_WIRE: - for(TopExp_Explorer it(shape,TopAbs_WIRE); it.More(); it.Next()) { - haveShape = true; - func(it.Current(),TopAbs_WIRE); + for(TopExp_Explorer it(shape, TopAbs_WIRE); it.More(); it.Next()) { + res = TopAbs_WIRE; + if(groupOpenEdges && !BRep_Tool::IsClosed(TopoDS::Wire(it.Current()))) + openShapes.push_back(it.Current()); + else + func(it.Current(),TopAbs_WIRE); } - if(haveShape) return TopAbs_WIRE; + if(res>=0) break; //fall through default: for(TopExp_Explorer it(shape,TopAbs_EDGE); it.More(); it.Next()) { - haveShape = true; + res = TopAbs_EDGE; + if(groupOpenEdges) { + TopoDS_Edge e = TopoDS::Edge(it.Current()); + gp_Pnt p1,p2; + getEndPoints(e,p1,p2); + if(p1.SquareDistance(p2) > Precision::SquareConfusion()) { + openShapes.push_back(it.Current()); + continue; + } + } func(it.Current(),TopAbs_EDGE); } } - return haveShape?TopAbs_EDGE:-1; + if(openShapes.empty()) + return res; + + BRep_Builder builder; + TopoDS_Compound comp; + builder.MakeCompound(comp); + for(auto &s : openShapes) { + for(TopExp_Explorer it(s,TopAbs_EDGE); it.More(); it.Next()) + builder.Add(comp,s); + } + func(comp, TopAbs_COMPOUND); + return TopAbs_COMPOUND; } struct FindPlane { @@ -2950,7 +2976,7 @@ std::list Area::sortWires(const std::list &shapes, //explode the shape if(!shape.IsNull()){ foreachSubshape(shape,ShapeInfoBuilder( - arcPlaneFound,arc_plane,trsf,shape_list,rparams)); + arcPlaneFound,arc_plane,trsf,shape_list,rparams),TopAbs_FACE,true); } } FC_TIME_LOG(t1,"plane finding");