Toponaming/Part: tests addition and cleaning

This commit is contained in:
bgbsww
2024-02-17 18:07:23 -05:00
parent 99808e9ef2
commit 5db6ef559e

View File

@@ -15,7 +15,6 @@
#include <BRepFeat_SplitShape.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
#include <GC_MakeCircle.hxx>
#include <Geom_BezierCurve.hxx>
#include <Geom_BezierSurface.hxx>
#include <gp_Pln.hxx>
@@ -182,7 +181,7 @@ TEST_F(TopoShapeExpansionTest, MapperMakerModified)
// Creating a Face using the Wire created before
auto faceMkr {BRepBuilderAPI_MakeFace(wire)};
auto face = faceMkr.Face();
const auto& face = faceMkr.Face();
// Creating an Edge to split the Face and the Wire
auto edgeMkr {BRepBuilderAPI_MakeEdge(gp_Pnt(0.5, 1.0, 0.0), gp_Pnt(0.5, -1.0, 0.0))};
@@ -255,33 +254,55 @@ TEST_F(TopoShapeExpansionTest, MapperMakerGenerated)
EXPECT_EQ(fuse2MprMkr.generated(edge3).size(), 1); // fuse2 has a new vertex generated by edge3
}
// ================================================================================================
// The following test has been disabled to avoid the CI failing
// will be enabled again in following PRs
// ================================================================================================
TEST_F(TopoShapeExpansionTest, makeElementWiresCombinesAdjacent)
{
// Arrange
auto edge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge();
auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(2.0, 0.0, 0.0)).Edge();
TopoShape topoShape {3L};
std::vector<TopoShape> shapes {TopoShape(edge1, 1L), TopoShape(edge2, 2L)};
// std::vector<TopoShape> shapes {edge1, edge2};
// Act
topoShape.makeElementWires(shapes);
auto elementMap = topoShape.getElementMap();
// Assert
EXPECT_EQ(0, elementMap.size()); // TODO: What is the correct value?
}
// TEST_F(TopoShapeExpansionTest, makeElementWiresCombinesAdjacent)
// {
// // Arrange
// auto edge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge();
// auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(2.0, 0.0, 0.0)).Edge();
// TopoShape topoShape;
// std::vector<TopoShape> shapes {edge1, edge2};
// // Act
// topoShape.makeElementWires(shapes);
// // Assert
// auto elementMap = topoShape.getElementMap();
// EXPECT_EQ(6, elementMap.size());
// }
// ================================================================================================
TEST_F(TopoShapeExpansionTest, makeElementWiresCombinesWires)
{
// Arrange
auto edge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge();
auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(2.0, 0.0, 0.0)).Edge();
auto edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(3.0, 0.0, 0.0), gp_Pnt(2.0, 1.0, 0.0)).Edge();
auto edge4 = BRepBuilderAPI_MakeEdge(gp_Pnt(2.0, 1.0, 0.0), gp_Pnt(2.0, 2.0, 0.0)).Edge();
std::vector<TopoShape> shapes {TopoShape(edge1, 1L), TopoShape(edge2, 2L)};
std::vector<TopoShape> shapes2 {TopoShape(edge3, 4L), TopoShape(edge4, 4L)};
// std::vector<TopoShape> shapes {edge1, edge2};
// Act
auto& wire1 = (new TopoShape {})->makeElementWires(shapes);
auto& wire2 = (new TopoShape {})->makeElementWires(shapes2);
auto& topoShape = (new TopoShape {})->makeElementWires({wire1, wire2});
auto elements = elementMap((topoShape));
// Assert
EXPECT_EQ(elements.size(), 10);
EXPECT_EQ(elements.count(IndexedName("Edge", 1)), 1);
EXPECT_EQ(elements[IndexedName("Edge", 1)], MappedName("Edge1;:H,E"));
EXPECT_EQ(elements[IndexedName("Edge", 2)], MappedName("Edge2;:H,E"));
EXPECT_EQ(elements[IndexedName("Edge", 3)], MappedName("Edge1;:C1;:H:4,E"));
EXPECT_EQ(elements[IndexedName("Edge", 4)], MappedName("Edge2;:C1;:H:4,E"));
EXPECT_EQ(elements[IndexedName("Vertex", 1)], MappedName("Vertex1;:H,V"));
EXPECT_EQ(elements[IndexedName("Vertex", 2)], MappedName("Vertex2;:H,V"));
EXPECT_EQ(elements[IndexedName("Vertex", 3)], MappedName("Vertex3;:H,V"));
EXPECT_EQ(elements[IndexedName("Vertex", 4)], MappedName("Vertex1;:C1;:H:4,V"));
EXPECT_EQ(elements[IndexedName("Vertex", 5)], MappedName("Vertex2;:C1;:H:4,V"));
EXPECT_EQ(elements[IndexedName("Vertex", 6)], MappedName("Vertex3;:C1;:H:4,V"));
}
TEST_F(TopoShapeExpansionTest, makeElementFaceNull)
{
// Arrange
const double Len = 3, Wid = 2, Rad = 1;
const float Len = 3, Wid = 2, Rad = 1;
auto [face1, wire1, wire2] = CreateFaceWithRoundHole(Len, Wid, Rad);
TopoShape topoShape {face1};
double area = getArea(face1);
@@ -431,7 +452,7 @@ TEST_F(TopoShapeExpansionTest, makeElementFaceClosedWire)
TEST_F(TopoShapeExpansionTest, setElementComboNameNothing)
{
// Arrange
TopoShape topoShape(1L);
TopoShape topoShape {1L};
// Act
Data::MappedName result = topoShape.setElementComboName(Data::IndexedName(), {});
// ASSERT
@@ -443,7 +464,7 @@ TEST_F(TopoShapeExpansionTest, setElementComboNameSimple)
{
// Arrange
auto edge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge();
TopoShape topoShape(edge1, 1L);
TopoShape topoShape {edge1, 1L};
topoShape.setElementMap({}); // Initialize the map to avoid a segfault.
// Also, maybe the end of TopoShape::mapSubElementTypeForShape should enforce that elementMap()
// isn't nullptr to eliminate the segfault.
@@ -459,7 +480,7 @@ TEST_F(TopoShapeExpansionTest, setElementComboNameSimple)
TEST_F(TopoShapeExpansionTest, setElementComboName)
{
// Arrange
TopoShape topoShape(2L);
TopoShape topoShape {2L};
topoShape.setElementMap({});
Data::MappedName edgeName =
topoShape.getMappedName(Data::IndexedName::fromConst("Edge", 1), true);
@@ -484,7 +505,7 @@ TEST_F(TopoShapeExpansionTest, setElementComboNameCompound)
auto edge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge();
auto wire1 = BRepBuilderAPI_MakeWire({edge1}).Wire();
auto wire2 = BRepBuilderAPI_MakeWire({edge1}).Wire();
TopoShape topoShape(2L);
TopoShape topoShape {2L};
topoShape.makeElementCompound({wire1, wire2}); // Quality of shape doesn't matter
Data::MappedName edgeName =
topoShape.getMappedName(Data::IndexedName::fromConst("Edge", 1), true);
@@ -530,12 +551,63 @@ TEST_F(TopoShapeExpansionTest, splitWires)
// splitWires with all four reorientation values NoReorient, ReOrient, ReorientForward,
// ReorientReversed
TEST_F(TopoShapeExpansionTest, getSubShapes)
{
// Arrange
auto [cube1, cube2] = CreateTwoTopoShapeCubes();
// Act
auto subShapes = cube1.getSubShapes();
auto subShapes2 = cube1.getSubShapes(TopAbs_FACE);
auto subShapes3 = cube1.getSubShapes(TopAbs_SHAPE, TopAbs_EDGE);
// Assert
EXPECT_EQ(subShapes.size(), 6);
EXPECT_EQ(subShapes2.size(), 6);
EXPECT_EQ(subShapes3.size(), 0); // TODO: Why doesn't this match the next test?
}
TEST_F(TopoShapeExpansionTest, getSubTopoShapes)
{
// Arrange
auto [cube1, cube2] = CreateTwoTopoShapeCubes();
// Act
auto subShapes = cube1.getSubTopoShapes();
auto subShapes2 = cube1.getSubTopoShapes(TopAbs_FACE);
auto subShapes3 = cube1.getSubTopoShapes(TopAbs_SHAPE, TopAbs_EDGE);
// Assert
EXPECT_EQ(subShapes.size(), 6);
EXPECT_EQ(subShapes2.size(), 6);
EXPECT_EQ(subShapes3.size(), 6);
}
TEST_F(TopoShapeExpansionTest, getOrderedEdges)
{
// Arrange
auto [cube1, cube2] = CreateTwoTopoShapeCubes();
// Act
auto subShapes = cube1.getOrderedEdges(MapElement::noMap);
// Assert
EXPECT_EQ(subShapes.size(), 24);
// EXPECT_THROW(cube1.getOrderedEdges(), NullShapeException); // No Map
EXPECT_EQ(subShapes.front().getElementMap().size(), 0);
// EXPECT_EQ(subShapes2.front().getElementMap().size(),2);
}
TEST_F(TopoShapeExpansionTest, getOrderedVertexes)
{
// Arrange
auto [cube1, cube2] = CreateTwoTopoShapeCubes();
// Act
auto subShapes = cube1.getOrderedVertexes(MapElement::noMap);
// Assert
EXPECT_EQ(subShapes.size(), 24);
// EXPECT_THROW(cube1.getOrderedEdges(), NullShapeException); // No Map
}
TEST_F(TopoShapeExpansionTest, getSubTopoShapeByEnum)
{
// Arrange
auto [cube1, cube2] = CreateTwoCubes();
TopoShape cube1TS {cube1};
cube1TS.Tag = 1L;
TopoShape cube1TS {cube1, 1L};
// Act
auto subShape = cube1TS.getSubTopoShape(TopAbs_FACE, 1);
@@ -554,8 +626,7 @@ TEST_F(TopoShapeExpansionTest, getSubTopoShapeByStringDefaults)
{
// Arrange
auto [cube1, cube2] = CreateTwoCubes();
Part::TopoShape cube1TS {cube1};
cube1TS.Tag = 1L;
Part::TopoShape cube1TS {cube1, 1L};
const float Len = 3;
const float Wid = 2;
auto [face1, wire1, edge1, edge2, edge3, edge4] = CreateRectFace(Len, Wid);
@@ -581,8 +652,7 @@ TEST_F(TopoShapeExpansionTest, getSubTopoShapeByStringNames)
{
// Arrange
auto [cube1, cube2] = CreateTwoCubes();
TopoShape cube1TS {cube1};
cube1TS.Tag = 1;
TopoShape cube1TS {cube1, 1L};
// Act
auto subShape = cube1TS.getSubTopoShape("Face1");
@@ -602,16 +672,17 @@ TEST_F(TopoShapeExpansionTest, mapSubElementInvalidParm)
{
// Arrange
auto [cube1, cube2] = CreateTwoCubes();
TopoShape cube1TS {cube1};
cube1TS.Tag = 1;
TopoShape cube1TS {cube1, 1L};
TopoShape cube2TS {cube2, 2L};
// Act
std::vector<TopoShape> subShapes = cube1TS.getSubTopoShapes(TopAbs_FACE);
TopoShape face1 = subShapes.front();
face1.Tag = 2;
face1.Tag = 3;
cube1TS.mapSubElement(face1);
cube2TS.mapSubElement(face1);
// Assert
EXPECT_THROW(cube1TS.mapSubElement(face1), NullShapeException); // No subshapes
EXPECT_EQ(cube1TS.getElementMap().size(), 9); // Valid, the face is in Cube1
EXPECT_EQ(cube2TS.getElementMap().size(), 0); // Invalid, the face is not in Cube2
}
TEST_F(TopoShapeExpansionTest, mapSubElementFindShapeByNames)
@@ -1196,8 +1267,9 @@ TEST_F(TopoShapeExpansionTest, makeElementLoft)
transform.SetTranslation(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(0.0, 0.0, 10.0));
auto wire2 = wire1; // Shallow copy
wire2.Move(TopLoc_Location(transform));
TopoShape wire1ts {wire1,
1L}; // One of these shapes should have a tag or we won't get an Element Map
TopoShape wire1ts {
wire1,
1L}; // One of these shapes should have a tag or else we won't get an Element Map
TopoShape wire2ts {
wire2,
2L}; // If you change either tag or eliminate one it changes the resulting name.