From eb7c658a06c689120939717ed05916d52e8cf867 Mon Sep 17 00:00:00 2001 From: bgbsww Date: Fri, 26 Jan 2024 16:15:48 -0500 Subject: [PATCH] Add helper methods --- tests/src/Mod/Part/App/PartTestHelpers.cpp | 34 ++++++++++++++++++++++ tests/src/Mod/Part/App/PartTestHelpers.h | 17 +++++++++++ 2 files changed, 51 insertions(+) diff --git a/tests/src/Mod/Part/App/PartTestHelpers.cpp b/tests/src/Mod/Part/App/PartTestHelpers.cpp index 24d106f9f8..8b0390b7e5 100644 --- a/tests/src/Mod/Part/App/PartTestHelpers.cpp +++ b/tests/src/Mod/Part/App/PartTestHelpers.cpp @@ -89,6 +89,30 @@ void rectangle(double height, double width, char* name) ExecutePython(rectstring); } +std::tuple +CreateRectFace(float len, float wid) +{ + auto edge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(len, 0.0, 0.0)).Edge(); + auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(len, 0.0, 0.0), gp_Pnt(len, wid, 0.0)).Edge(); + auto edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(len, wid, 0.0), gp_Pnt(0.0, wid, 0.0)).Edge(); + auto edge4 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, wid, 0.0), gp_Pnt(0.0, 0.0, 0.0)).Edge(); + auto wire1 = BRepBuilderAPI_MakeWire({edge1, edge2, edge3, edge4}).Wire(); + auto face1 = BRepBuilderAPI_MakeFace(wire1).Face(); + return {face1, wire1, edge1, edge2, edge3, edge4}; +} + +std::tuple +CreateFaceWithRoundHole(float len, float wid, float radius) +{ + auto [face1, wire1, edge1, edge2, edge3, edge4] = CreateRectFace(len, wid); + auto circ1 = + GC_MakeCircle(gp_Pnt(len / 2.0, wid / 2.0, 0), gp_Dir(0.0, 0.0, 1.0), radius).Value(); + auto edge5 = BRepBuilderAPI_MakeEdge(circ1).Edge(); + auto wire2 = BRepBuilderAPI_MakeWire(edge5).Wire(); + auto face2 = BRepBuilderAPI_MakeFace(face1, wire2).Face(); + return {face2, wire1, wire2}; +} + testing::AssertionResult boxesMatch(const Base::BoundBox3d& b1, const Base::BoundBox3d& b2, double prec) { @@ -103,6 +127,16 @@ boxesMatch(const Base::BoundBox3d& b1, const Base::BoundBox3d& b2, double prec) << b2.MinY << "," << b2.MinZ << " ; " << b2.MaxX << "," << b2.MaxY << "," << b2.MaxZ << ")"; } +std::map elementMap(const TopoShape& shape) +{ + std::map result {}; + auto elements = shape.getElementMap(); + for (auto const& entry : elements) { + result[entry.index] = entry.name; + } + return result; +} + } // namespace PartTestHelpers // NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers) diff --git a/tests/src/Mod/Part/App/PartTestHelpers.h b/tests/src/Mod/Part/App/PartTestHelpers.h index 742eaf26bc..79147f6531 100644 --- a/tests/src/Mod/Part/App/PartTestHelpers.h +++ b/tests/src/Mod/Part/App/PartTestHelpers.h @@ -10,10 +10,18 @@ #include "Mod/Part/App/FeaturePartFuse.h" #include "Mod/Part/App/FeatureFillet.h" #include +#include +#include +#include +#include +#include namespace PartTestHelpers { +using namespace Data; +using namespace Part; + double getVolume(const TopoDS_Shape& shape); double getArea(const TopoDS_Shape& shape); @@ -38,6 +46,15 @@ void executePython(const std::vector& python); void rectangle(double height, double width, char* name); +std::tuple +CreateRectFace(float len = 2.0, float wid = 3.0); + +std::tuple +CreateFaceWithRoundHole(float len = 2.0, float wid = 3.0, float radius = 1.0); + testing::AssertionResult boxesMatch(const Base::BoundBox3d& b1, const Base::BoundBox3d& b2, double prec = 1e-05); // NOLINT + +std::map elementMap(const TopoShape& shape); + } // namespace PartTestHelpers