Toponaming/Part: Cleanup and test makeElementDraft
This commit is contained in:
@@ -41,6 +41,8 @@
|
||||
#include <BRepAlgoAPI_Section.hxx>
|
||||
#include <BRepBuilderAPI_Copy.hxx>
|
||||
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
#include <BRepLib.hxx>
|
||||
#include <BRepOffsetAPI_DraftAngle.hxx>
|
||||
#include <BRepOffsetAPI_MakePipe.hxx>
|
||||
#include <ShapeUpgrade_ShellSewing.hxx>
|
||||
#include <TopTools_HSequenceOfShape.hxx>
|
||||
@@ -68,7 +70,6 @@
|
||||
#include "FaceMaker.h"
|
||||
|
||||
#include <App/ElementNamingUtils.h>
|
||||
#include <BRepLib.hxx>
|
||||
|
||||
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<TopoShape> faces(_faces);
|
||||
bool done = true;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <BRepPrimAPI_MakeBox.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
|
||||
#include "PartTestHelpers.h"
|
||||
|
||||
@@ -155,6 +156,28 @@ std::pair<TopoDS_Shape, TopoDS_Shape> CreateTwoCubes()
|
||||
return {box1, box2};
|
||||
}
|
||||
|
||||
std::pair<TopoShape, TopoShape> CreateTwoTopoShapeCubes()
|
||||
{
|
||||
auto [box1, box2] = CreateTwoCubes();
|
||||
std::vector<TopoShape> 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)
|
||||
|
||||
@@ -59,4 +59,5 @@ std::map<IndexedName, MappedName> elementMap(const TopoShape& shape);
|
||||
|
||||
std::pair<TopoDS_Shape, TopoDS_Shape> CreateTwoCubes();
|
||||
|
||||
std::pair<TopoShape, TopoShape> CreateTwoTopoShapeCubes();
|
||||
} // namespace PartTestHelpers
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <BRepFeat_SplitShape.hxx>
|
||||
#include <BRepPrimAPI_MakeBox.hxx>
|
||||
#include <BRepAlgoAPI_Fuse.hxx>
|
||||
#include <GC_MakeCircle.hxx>
|
||||
#include <gp_Pln.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <TopoDS_Edge.hxx>
|
||||
|
||||
@@ -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<TopoShape> subShapes = cube1TS.getSubTopoShapes(TopAbs_FACE);
|
||||
std::vector<TopoShape> 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)
|
||||
|
||||
Reference in New Issue
Block a user