From cc96c416c12f9b88b2614cc90a8716842c412086 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 27 Oct 2011 12:55:50 +0000 Subject: [PATCH] + implement an improved method to check if one wire is inside another wire git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5074 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d --- src/Mod/PartDesign/App/FeatureSketchBased.cpp | 53 ++++++++++++++++--- src/Mod/PartDesign/App/FeatureSketchBased.h | 1 + 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.cpp b/src/Mod/PartDesign/App/FeatureSketchBased.cpp index aa0892570..c04f1c444 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.cpp +++ b/src/Mod/PartDesign/App/FeatureSketchBased.cpp @@ -29,16 +29,21 @@ # include # include # include +# include +# include # include # include # include # include +# include # include # include # include # include # include # include +# include +# include #endif @@ -71,6 +76,45 @@ SketchBased::SketchBased() ADD_PROPERTY(Sketch,(0)); } +bool SketchBased::isInside(const TopoDS_Wire& wire1, const TopoDS_Wire& wire2) const +{ + Bnd_Box box1; + BRepBndLib::Add(wire1, box1); + box1.SetGap(0.0); + + Bnd_Box box2; + BRepBndLib::Add(wire2, box2); + box2.SetGap(0.0); + + if (box1.IsOut(box2)) + return false; + + double prec = Precision::Confusion(); + + BRepBuilderAPI_MakeFace mkFace(wire1); + TopoDS_Face face = validateFace(mkFace.Face()); + BRepAdaptor_Surface adapt(face); + IntTools_FClass2d class2d(face, prec); + Handle_Geom_Surface surf = new Geom_Plane(adapt.Plane()); + ShapeAnalysis_Surface as(surf); + + TopExp_Explorer xp(wire2,TopAbs_VERTEX); + while (xp.More()) { + TopoDS_Vertex v = TopoDS::Vertex(xp.Current()); + gp_Pnt p = BRep_Tool::Pnt(v); + gp_Pnt2d uv = as.ValueOfUV(p, prec); + if (class2d.Perform(uv) == TopAbs_IN) + return true; + // TODO: We can make a check to see if all points are inside or all outside + // because otherwise we have some intersections which is not allowed + else + return false; + xp.Next(); + } + + return false; +} + TopoDS_Face SketchBased::validateFace(const TopoDS_Face& face) const { BRepCheck_Analyzer aChecker(face); @@ -150,16 +194,9 @@ TopoDS_Shape SketchBased::makeFace(const std::vector& w) const wire_list.pop_front(); sep_list.push_back(wire); - Bnd_Box box; - BRepBndLib::Add(wire, box); - box.SetGap(0.0); - std::list::iterator it = wire_list.begin(); while (it != wire_list.end()) { - Bnd_Box box2; - BRepBndLib::Add(*it, box2); - box2.SetGap(0.0); - if (!box.IsOut(box2)) { + if (isInside(wire, *it)) { sep_list.push_back(*it); it = wire_list.erase(it); } diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.h b/src/Mod/PartDesign/App/FeatureSketchBased.h index 943b53af0..c65033dda 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.h +++ b/src/Mod/PartDesign/App/FeatureSketchBased.h @@ -46,6 +46,7 @@ protected: TopoDS_Face validateFace(const TopoDS_Face&) const; TopoDS_Shape makeFace(const std::vector&) const; TopoDS_Shape makeFace(std::list&) const; // for internal use only + bool isInside(const TopoDS_Wire&, const TopoDS_Wire&) const; }; } //namespace PartDesign