From 6e9cd051f2cc7f17e634795ca46d682ed6672ed0 Mon Sep 17 00:00:00 2001 From: bgbsww Date: Wed, 14 Feb 2024 12:20:10 -0500 Subject: [PATCH] Toponaming/Part: Cleanup and test makeElementDraft --- src/Mod/Part/App/TopoShapeExpansion.cpp | 5 +- tests/src/Mod/Part/App/PartTestHelpers.cpp | 23 ++++++++ tests/src/Mod/Part/App/PartTestHelpers.h | 1 + tests/src/Mod/Part/App/TopoShapeExpansion.cpp | 55 ++++++++++++++++++- 4 files changed, 81 insertions(+), 3 deletions(-) diff --git a/src/Mod/Part/App/TopoShapeExpansion.cpp b/src/Mod/Part/App/TopoShapeExpansion.cpp index fca36f0c6c..adf55cf732 100644 --- a/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -41,6 +41,8 @@ #include #include #include +#include +#include #include #include #include @@ -68,7 +70,6 @@ #include "FaceMaker.h" #include -#include FC_LOG_LEVEL_INIT("TopoShape", true, true) // NOLINT @@ -1818,7 +1819,7 @@ TopoShape &TopoShape::makeElementDraft(const TopoShape &shape, const std::vector if(!op) op = Part::OpCodes::Draft; if(shape.isNull()) - HANDLE_NULL_SHAPE; + FC_THROWM(NullShapeException, "Null shape"); std::vector faces(_faces); bool done = true; diff --git a/tests/src/Mod/Part/App/PartTestHelpers.cpp b/tests/src/Mod/Part/App/PartTestHelpers.cpp index 36dc63f067..feb73e8d10 100644 --- a/tests/src/Mod/Part/App/PartTestHelpers.cpp +++ b/tests/src/Mod/Part/App/PartTestHelpers.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: LGPL-2.1-or-later #include +#include #include "PartTestHelpers.h" @@ -155,6 +156,28 @@ std::pair CreateTwoCubes() return {box1, box2}; } +std::pair CreateTwoTopoShapeCubes() +{ + auto [box1, box2] = CreateTwoCubes(); + std::vector vec; + long tag = 1L; + for (TopExp_Explorer exp(box1, TopAbs_FACE); exp.More(); exp.Next()) { + vec.emplace_back(TopoShape(exp.Current(), tag++)); + } + TopoShape box1ts; + box1ts.makeElementCompound(vec); + box1ts.Tag = tag++; + vec.clear(); + for (TopExp_Explorer exp(box2, TopAbs_FACE); exp.More(); exp.Next()) { + vec.emplace_back(TopoShape(exp.Current(), tag++)); + } + TopoShape box2ts; + box2ts.Tag = tag++; + box2ts.makeElementCompound(vec); + + return {box1ts, box2ts}; +} + } // 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 8b829e4ba6..a10e1f9e36 100644 --- a/tests/src/Mod/Part/App/PartTestHelpers.h +++ b/tests/src/Mod/Part/App/PartTestHelpers.h @@ -59,4 +59,5 @@ std::map elementMap(const TopoShape& shape); std::pair CreateTwoCubes(); +std::pair CreateTwoTopoShapeCubes(); } // namespace PartTestHelpers diff --git a/tests/src/Mod/Part/App/TopoShapeExpansion.cpp b/tests/src/Mod/Part/App/TopoShapeExpansion.cpp index b047f62eb0..7b6458e603 100644 --- a/tests/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/tests/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include @@ -867,4 +867,57 @@ TEST_F(TopoShapeExpansionTest, makeElementBooleanFuse) EXPECT_FLOAT_EQ(getVolume(result.getShape()), 1.75); } +TEST_F(TopoShapeExpansionTest, makeElementDraft) +{ // Draft as in Draft Angle or sloped sides for removing shapes from a mold. + // Arrange + auto [cube1, cube2] = CreateTwoCubes(); + TopoShape cube1TS {cube1, 1L}; + std::vector subShapes = cube1TS.getSubTopoShapes(TopAbs_FACE); + std::vector faces {subShapes[0], subShapes[1], subShapes[2], subShapes[3]}; + const gp_Dir pullDirection {0, 0, 1}; + double angle {M_PI * 10 + / 8}; // Angle should be between Pi and Pi * 1.5 ( 180 and 270 degrees ) + const gp_Pln plane {}; + // Act + TopoShape& result = cube1TS.makeElementDraft(cube1TS, faces, pullDirection, angle, plane); + auto elements = elementMap(result); + // Assert + EXPECT_EQ(elements.size(), 26); // Cubes have 6 Faces, 12 Edges, 8 Vertexes + EXPECT_NEAR(getVolume(result.getShape()), 4.3333333333, 1e-06); // Truncated pyramid +} + +TEST_F(TopoShapeExpansionTest, makeElementDraftTopoShapes) +{ + // Arrange + auto [cube1TS, cube2TS] = CreateTwoTopoShapeCubes(); + const gp_Dir pullDirection {0, 0, 1}; + double angle {M_PI * 10 + / 8}; // Angle should be between Pi and Pi * 1.5 ( 180 and 270 degrees ) + const gp_Pln plane {}; + // Act + TopoShape result3 = cube1TS.makeElementDraft(cube1TS.getSubTopoShapes(TopAbs_FACE), + pullDirection, + angle, + plane); // Non Reference call type + TopoShape result2 = cube1TS.makeElementDraft(cube1TS, + cube1TS.getSubTopoShapes(TopAbs_FACE), + pullDirection, + angle, + plane); // Bad use of Reference call + TopoShape& result = cube1TS.makeElementDraft(cube2TS, + cube2TS.getSubTopoShapes(TopAbs_FACE), + pullDirection, + angle, + plane); // Correct usage + auto elements = elementMap((result)); + // Assert + EXPECT_TRUE(result.getMappedChildElements().empty()); + EXPECT_EQ(elements.size(), 26); + EXPECT_EQ(elements.count(IndexedName("Face", 1)), 1); + EXPECT_EQ(elements[IndexedName("Face", 1)], MappedName("Face1;:G;DFT;:He:7,F")); + EXPECT_NEAR(getVolume(result.getShape()), 4.3333333333, 1e-06); // Truncated pyramid + EXPECT_EQ(result2.getElementMap().size(), 0); // No element map in non reference call. + EXPECT_EQ(result3.getElementMap().size(), 0); // No element map in non reference call. +} + // NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)