diff --git a/src/Mod/Part/App/CrossSection.cpp b/src/Mod/Part/App/CrossSection.cpp index ba9f30220..04ec25e28 100644 --- a/src/Mod/Part/App/CrossSection.cpp +++ b/src/Mod/Part/App/CrossSection.cpp @@ -23,12 +23,19 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include +# include # include +# include # include +# include +# include # include # include # include +# include # include +# include # include # include # include @@ -47,15 +54,50 @@ CrossSection::CrossSection(double a, double b, double c, const TopoDS_Shape& s) std::list CrossSection::section(double d) const { std::list wires; - BRepAlgoAPI_Section cs(s, gp_Pln(a,b,c,-d)); - if (cs.IsDone()) { - std::list edges; - TopExp_Explorer xp; - for (xp.Init(cs.Shape(), TopAbs_EDGE); xp.More(); xp.Next()) - edges.push_back(TopoDS::Edge(xp.Current())); - connectEdges(edges, wires); - } +#if 0 + // Fixes: 0001228: Cross section of Torus in Part Workbench fails or give wrong results + if (s.ShapeType() == TopAbs_SOLID) { + gp_Pln slicePlane(a,b,c,-d); + BRepBuilderAPI_MakeFace mkFace(slicePlane); + TopoDS_Face face = mkFace.Face(); + BRepPrimAPI_MakeHalfSpace mkSolid(face, gp_Pnt(0,0,d-1)); + TopoDS_Solid solid = mkSolid.Solid(); + BRepAlgoAPI_Cut mkCut(s,solid); + if (mkCut.IsDone()) { + TopTools_IndexedMapOfShape mapOfFaces; + TopExp::MapShapes(mkCut.Shape(), TopAbs_FACE, mapOfFaces); + for (int i=1; i<=mapOfFaces.Extent(); i++) { + const TopoDS_Face& face = TopoDS::Face(mapOfFaces.FindKey(i)); + BRepAdaptor_Surface adapt(face); + if (adapt.GetType() == GeomAbs_Plane) { + gp_Pln plane = adapt.Plane(); + if (plane.Axis().IsParallel(slicePlane.Axis(), Precision::Confusion()) && + plane.Distance(slicePlane.Location()) < Precision::Confusion()) { + TopTools_IndexedMapOfShape mapOfWires; + TopExp::MapShapes(face, TopAbs_WIRE, mapOfWires); + for (int j=1; j<=mapOfWires.Extent(); j++) { + const TopoDS_Wire& wire = TopoDS::Wire(mapOfWires.FindKey(j)); + wires.push_back(wire); + } + } + } + } + } + } + else +#else + { + BRepAlgoAPI_Section cs(s, gp_Pln(a,b,c,-d)); + if (cs.IsDone()) { + std::list edges; + TopExp_Explorer xp; + for (xp.Init(cs.Shape(), TopAbs_EDGE); xp.More(); xp.Next()) + edges.push_back(TopoDS::Edge(xp.Current())); + connectEdges(edges, wires); + } + } +#endif return wires; }