From ddcfdddcf2d7c6cd5827ccee545b329869edd6de Mon Sep 17 00:00:00 2001 From: bgbsww Date: Sat, 17 Feb 2024 12:32:29 -0500 Subject: [PATCH] Toponaming/Part: Add tests and clean --- tests/src/Mod/Part/App/TopoShapeExpansion.cpp | 60 +++++++++++++++---- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/tests/src/Mod/Part/App/TopoShapeExpansion.cpp b/tests/src/Mod/Part/App/TopoShapeExpansion.cpp index c8562e29ab..aa3bb21940 100644 --- a/tests/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/tests/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -1231,15 +1231,24 @@ TEST_F(TopoShapeExpansionTest, makeElementLinearizeFace) TEST_F(TopoShapeExpansionTest, makeElementRuledSurfaceEdges) { // Arrange - auto [cube1, cube2] = CreateTwoCubes(); - TopoShape cube1TS {cube1, 1L}; - std::vector subEdges = cube1TS.getSubTopoShapes(TopAbs_EDGE); - std::vector shapes2 = {subEdges[0], subEdges[1]}; + auto edge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(0.0, 0.0, 8.0)).Edge(); + auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(2.5, 0.0, 0.0), gp_Pnt(2.5, 0.0, 8.0)).Edge(); + TopoShape edge1ts {edge1, 2L}; + TopoShape edge2ts {edge2, 3L}; + TopoShape topoShape {1L}; // Act - TopoShape result2 = cube1TS.makeElementRuledSurface(shapes2, 0); // TODO: direction as enum? + topoShape.makeElementRuledSurface({edge1ts, edge2ts}, 0); // TODO: orientation as enum? + auto elements = elementMap(topoShape); // Assert - EXPECT_EQ(result2.countSubElements("Wire"), 1); - EXPECT_FLOAT_EQ(getArea(result2.getShape()), 0.32953611); + EXPECT_EQ(topoShape.countSubElements("Wire"), 1); + EXPECT_FLOAT_EQ(getArea(topoShape.getShape()), 20); + // Assert that we're creating a correct element map + EXPECT_TRUE(topoShape.getMappedChildElements().empty()); + // TODO: Revisit these when resetElementMap() is fully worked through. Suspect that last loop + // of makeElementRuledSurface is dependent on this to create elementMaps. + // EXPECT_EQ(elements.size(), 24); + // EXPECT_EQ(elements.count(IndexedName("Edge", 1)), 1); + // EXPECT_EQ(elements[IndexedName("Edge", 1)], MappedName("Vertex1;:G;PSH;:H2:7,E")); } TEST_F(TopoShapeExpansionTest, makeElementRuledSurfaceWires) @@ -1248,12 +1257,19 @@ TEST_F(TopoShapeExpansionTest, makeElementRuledSurfaceWires) auto [cube1, cube2] = CreateTwoCubes(); TopoShape cube1TS {cube1, 1L}; std::vector subWires = cube1TS.getSubTopoShapes(TopAbs_WIRE); - std::vector shapes = {subWires[0], subWires[1]}; // Act - TopoShape result = cube1TS.makeElementRuledSurface(shapes, 0); // TODO: direction as enum? + cube1TS.makeElementRuledSurface({subWires[0], subWires[1]}, 0); // TODO: orientation as enum? + auto elements = elementMap(cube1TS); // Assert - EXPECT_EQ(result.countSubElements("Wire"), 4); - EXPECT_FLOAT_EQ(getArea(result.getShape()), 2.023056); + EXPECT_EQ(cube1TS.countSubElements("Wire"), 4); + EXPECT_FLOAT_EQ(getArea(cube1TS.getShape()), 2.023056); + // Assert that we're creating a correct element map + EXPECT_TRUE(cube1TS.getMappedChildElements().empty()); + // TODO: Revisit these when resetElementMap() is fully worked through. Suspect that last loop + // of makeElementRuledSurface is dependent on this to create elementMaps. + // EXPECT_EQ(elements.size(), 24); + // EXPECT_EQ(elements.count(IndexedName("Edge", 1)), 1); + // EXPECT_EQ(elements[IndexedName("Edge", 1)], MappedName("Vertex1;:G;PSH;:H2:7,E")); } TEST_F(TopoShapeExpansionTest, makeElementLoft) @@ -1326,4 +1342,26 @@ TEST_F(TopoShapeExpansionTest, makeElementPipeShell) EXPECT_EQ(elements[IndexedName("Edge", 1)], MappedName("Vertex1;:G;PSH;:H2:7,E")); } +TEST_F(TopoShapeExpansionTest, makeElementThickSolid) +{ + // Arrange + auto [cube1, cube2] = CreateTwoCubes(); + TopoShape cube1TS {cube1, 1L}; + std::vector subFaces = cube1TS.getSubTopoShapes(TopAbs_FACE); + subFaces[0].Tag = 2L; + subFaces[1].Tag = 3L; + std::vector shapes = {subFaces[0], subFaces[1]}; + // Act + cube1TS.makeElementThickSolid(cube1TS, shapes, 0.1, 1e-07); + auto elements = elementMap(cube1TS); + // Assert + EXPECT_EQ(cube1TS.countSubElements("Wire"), 16); + EXPECT_FLOAT_EQ(getArea(cube1TS.getShape()), 9.4911509); + // Assert that we're creating a correct element map + EXPECT_TRUE(cube1TS.getMappedChildElements().empty()); + EXPECT_EQ(elements.size(), 74); + EXPECT_EQ(elements.count(IndexedName("Edge", 1)), 1); + EXPECT_EQ(elements[IndexedName("Edge", 1)], MappedName("Edge11;THK;:H1:4,E")); +} + // NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)