From 5763ac32b0dd8ac574b791f857eeec0d9d17a4f0 Mon Sep 17 00:00:00 2001 From: Vincenzo Calligaro Date: Sun, 18 Feb 2024 23:42:41 +0100 Subject: [PATCH] Part/Toponaming: tests for MapperHistory (#12402) * Part/Toponaming: MapperHistory * added test for MapperHistory::modified * added test for MapperHistory::generated * renamed edges in the test for MapperHistory::modified --------- Signed-off-by: CalligaroV --- tests/src/Mod/Part/App/TopoShapeExpansion.cpp | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/tests/src/Mod/Part/App/TopoShapeExpansion.cpp b/tests/src/Mod/Part/App/TopoShapeExpansion.cpp index aa3bb21940..994c4c0e8c 100644 --- a/tests/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/tests/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -18,6 +19,8 @@ #include #include #include +#include +#include #include #include @@ -254,6 +257,105 @@ TEST_F(TopoShapeExpansionTest, MapperMakerGenerated) EXPECT_EQ(fuse2MprMkr.generated(edge3).size(), 1); // fuse2 has a new vertex generated by edge3 } +TEST_F(TopoShapeExpansionTest, MapperHistoryModified) +{ + // Arrange + // Creating a all the shapes needed for the operations that have a history + auto vertex1 {BRepBuilderAPI_MakeVertex(gp_Pnt(-1.0, -1.0, 0.0)).Vertex()}; + auto vertex2 {BRepBuilderAPI_MakeVertex(gp_Pnt(1.0, 0.0, 0.0)).Vertex()}; + auto edge1 {BRepBuilderAPI_MakeEdge(vertex1, vertex2).Edge()}; + auto edge2 {BRepBuilderAPI_MakeEdge(gp_Pnt(-1.0, 0.0, 0.0), gp_Pnt(0.0, 1.0, 0.0)).Edge()}; + auto edge3 {BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 1.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge()}; + auto wire {BRepBuilderAPI_MakeWire(edge1, edge2, edge3).Wire()}; + + // Definition of a MapperHistory made with ShapeBuild_ReShape and of all the objects needed + // (https://dev.opencascade.org/doc/refman/html/class_shape_build___re_shape.html) + // (https://dev.opencascade.org/doc/overview/html/occt_user_guides__shape_healing.html#occt_shg_5_1) + Handle(ShapeBuild_ReShape) reshape {new ShapeBuild_ReShape()}; + // Recording all the shapes that will be modified + vertex1 = reshape->CopyVertex(vertex1); + vertex2 = reshape->CopyVertex(vertex2); + reshape->Apply(edge1); + auto reshapeMprHst {MapperHistory(reshape)}; + + // Definition a MapperHistory made with ShapeFix_Wireframe and of all the objects needed + // (https://dev.opencascade.org/doc/refman/html/class_shape_fix___wireframe.html) + // (https://dev.opencascade.org/doc/overview/html/occt_user_guides__shape_healing.html#occt_shg_2_1) + Handle(ShapeFix_Wireframe) fix {new ShapeFix_Wireframe()}; + fix->SetContext(reshape); + fix->SetPrecision(0.0); + auto fixMprHst {MapperHistory(*fix)}; + + // Definition of a MapperHistory made with the BRepTools_History of reshape + // (https://dev.opencascade.org/doc/refman/html/class_b_rep_tools___history.html) + auto historyMprHst {MapperHistory(reshape->History())}; + + // Act + // Closing the wire + fix->Load(wire); + fix->FixWireGaps(); + + // Replacing the edge with the new one made with the modified Vertexes + reshape->Replace(edge1, BRepBuilderAPI_MakeEdge(vertex1, vertex2).Edge()); + reshape->Apply(edge1); + + // Assert + // Check that all the shapes and operations have been performed + EXPECT_TRUE(reshape->Status(ShapeExtend_DONE1)); + EXPECT_TRUE(reshape->Status(ShapeExtend_DONE3)); + EXPECT_TRUE(fix->StatusWireGaps(ShapeExtend_DONE)); + + // Check the results of the operations after the ShapeFix_Wireframe. + // The history is in common so all the MapperHistory object defined previously will return the + // same values + EXPECT_EQ(historyMprHst.modified(edge1).size(), 1); + EXPECT_EQ(reshapeMprHst.modified(edge1).size(), 1); + EXPECT_EQ(fixMprHst.modified(edge1).size(), 1); +} + +TEST_F(TopoShapeExpansionTest, MapperHistoryGenerated) +{ + // Arrange + // Creating a all the shapes needed for the operations that have a history + auto edge1 {BRepBuilderAPI_MakeEdge(gp_Pnt(-1.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge()}; + auto edge2 {BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, -1.0, 0.0), gp_Pnt(0.0, 1.0, 0.0)).Edge()}; + auto edge3 {BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, -1.0), gp_Pnt(0.0, 0.0, 1.0)).Edge()}; + + // Definition of a MapperHistory made with a BRepTools_History containing the Generated() shapes + // of the Fuse operations, added manually to workaround a CI failure + // (https://github.com/FreeCAD/FreeCAD/pull/12402#issuecomment-1946234571) + auto fuse1Mkr {BRepAlgoAPI_Fuse(edge1, edge2)}; + Handle(BRepTools_History) fuse1Hst {new BRepTools_History()}; + auto fuse1MprHst {MapperHistory(fuse1Hst)}; + auto fuse2Mkr {BRepAlgoAPI_Fuse(edge1, edge3)}; + Handle(BRepTools_History) fuse2Hst {new BRepTools_History()}; + auto fuse2MprHst {MapperHistory(fuse2Hst)}; + + // Act + fuse1Mkr.Build(); + fuse1Hst->AddGenerated(edge1, fuse1Mkr); + fuse1Hst->AddGenerated(edge2, fuse1Mkr); + fuse2Mkr.Build(); + fuse2Hst->AddGenerated(edge1, fuse2Mkr); + fuse2Hst->AddGenerated(edge3, fuse2Mkr); + + // Assert + // Check that all the shapes and operations have been performed + EXPECT_TRUE(fuse1Mkr.IsDone()); + EXPECT_TRUE(fuse2Mkr.IsDone()); + + // Check the result of the operations + EXPECT_EQ(fuse1MprHst.generated(edge1).size(), 1); // fuse1 has a new vertex generated by edge1 + EXPECT_EQ(fuse1MprHst.generated(edge2).size(), 1); // fuse1 has a new vertex generated by edge2 + EXPECT_EQ(fuse1MprHst.generated(edge3).size(), + 0); // fuse1 doesn't have a new vertex generated by edge3 + + EXPECT_EQ(fuse2MprHst.generated(edge1).size(), 1); // fuse2 has a new vertex generated by edge1 + EXPECT_EQ(fuse2MprHst.generated(edge2).size(), + 0); // fuse2 doesn't have a new vertex generated by edge2 + EXPECT_EQ(fuse2MprHst.generated(edge3).size(), 1); // fuse2 has a new vertex generated by edge3 +} + TEST_F(TopoShapeExpansionTest, makeElementWiresCombinesAdjacent) { // Arrange