From d1978a075ae5d31db7f8589ad861ede5fa86f467 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Thu, 9 Mar 2017 12:23:27 +0800 Subject: [PATCH] Path.Area: fixed handling of shape with placement --- src/Mod/Path/App/Area.cpp | 38 +++++++++++--------------------- src/Mod/Path/App/FeatureArea.cpp | 4 ++-- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/Mod/Path/App/Area.cpp b/src/Mod/Path/App/Area.cpp index 23099be31f..976520d368 100644 --- a/src/Mod/Path/App/Area.cpp +++ b/src/Mod/Path/App/Area.cpp @@ -481,19 +481,23 @@ static int foreachSubshape(const TopoDS_Shape &shape, Func func, int type=TopAbs } struct FindPlane { - TopoDS_Shape &myShape; + TopoDS_Shape &myPlaneShape; gp_Trsf &myTrsf; double &myZ; FindPlane(TopoDS_Shape &s, gp_Trsf &t, double &z) - :myShape(s),myTrsf(t),myZ(z) + :myPlaneShape(s),myTrsf(t),myZ(z) {} void operator()(const TopoDS_Shape &shape, int) { gp_Trsf trsf; + BRepLib_FindSurface finder(shape,-1,Standard_True); if (!finder.Found()) return; - gp_Ax3 pos = GeomAdaptor_Surface(finder.Surface()).Plane().Position(); + // NOTE: It seemed that FindSurface disregardge shape's transformation, + // so we have to transformed the found plane manually + gp_Ax3 pos = GeomAdaptor_Surface(finder.Surface()).Plane().Position().Transformed( + shape.Location().Transformation()); //force plane to be right handed if(!pos.Direct()) @@ -501,34 +505,18 @@ struct FindPlane { gp_Dir dir(pos.Direction()); trsf.SetTransformation(pos); + if(fabs(dir.X())Precision::Confusion()) { - AREA_WARN("XY plane has wrong Z height "< Precision::Confusion() || - fabs(pt.Y()) > Precision::Confusion() || - fabs(pt.Z()) > Precision::Confusion()) { - AREA_WARN("wrong transformation "< z) + const auto &pt = BRep_Tool::Pnt(TopoDS::Vertex(it.Current())); + if(!myPlaneShape.IsNull() && myZ > pt.Z()) return; - myZ = z; - }else if(!myShape.IsNull()) + myZ = pt.Z(); + }else if(!myPlaneShape.IsNull()) return; - myShape = shape; + myPlaneShape = shape; myTrsf = trsf; } }; diff --git a/src/Mod/Path/App/FeatureArea.cpp b/src/Mod/Path/App/FeatureArea.cpp index 759eca3b55..ed8fd1a230 100644 --- a/src/Mod/Path/App/FeatureArea.cpp +++ b/src/Mod/Path/App/FeatureArea.cpp @@ -114,9 +114,9 @@ App::DocumentObjectExecReturn *FeatureArea::execute(void) if(myShapes.empty()) Shape.setValue(TopoDS_Shape()); - else if(myShapes.size()==1) - Shape.setValue(myShapes.front()); else{ + // compound is built even if there is only one shape to save the + // trouble of messing around with placement BRep_Builder builder; TopoDS_Compound compound; builder.MakeCompound(compound);