From 7fc99b42e7711d5dc11b5c150e71cc1da01e08f7 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Tue, 20 Feb 2024 10:10:57 -0500 Subject: [PATCH 1/2] Toposhape/Part: Transfer in _makETransform, makETransform, makEGTransform --- src/Mod/Part/App/TopoShape.h | 135 ++++++++++++++++++++++++ src/Mod/Part/App/TopoShapeExpansion.cpp | 84 +++++++++++++++ 2 files changed, 219 insertions(+) diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 9b1e1a73bd..1a8f21144b 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -1241,6 +1241,39 @@ public: } + /** Make a new shape with transformation that may contain non-uniform scaling + * + * @param source: input shape + * @param mat: transformation matrix + * @param op: optional string to be encoded into topo naming for indicating + * the operation + * @param copy: whether to perform deep copy of the shape. If false, the + * shape will still be copied if there is scaling. + * + * @return The original content of this TopoShape is discarded and replaced + * with the new transformed shape. The function returns the + * TopoShape itself as a self reference so that multiple operations + * can be carried out for the same shape in the same line of code. + */ + TopoShape &makeElementGTransform(const TopoShape &source, const Base::Matrix4D &mat, + const char *op=nullptr, bool copy=false); + + /** Make a new shape with transformation that may contain non-uniform scaling + * + * @param source: input shape + * @param mat: transformation matrix + * @param op: optional string to be encoded into topo naming for indicating + * the operation + * @param copy: whether to perform deep copy of the shape. If false, the + * shape will still be copied if there is scaling. + * + * @return Return a new shape with transformation. The shape itself is not + * modified + */ + TopoShape makeElementGTransform(const Base::Matrix4D &mat, const char *op=nullptr, bool copy=false) const { + return TopoShape(Tag,Hasher).makeElementGTransform(*this,mat,op,copy); + } + /** Make a deep copy of the shape * * @param source: input shape @@ -1411,6 +1444,108 @@ public: .makeElementChamfer(*this, edges, radius1, radius2, op, flipDirection, asAngle); } + /** Make a new shape with transformation + * + * @param source: input shape + * @param mat: transformation matrix + * @param op: optional string to be encoded into topo naming for indicating + * the operation + * @param checkScale: whether to check if the transformation matrix + * contains scaling factor. + * @param copy: whether to perform deep copy of the shape. If false, and + * checkScale is true, then the shape will be copied if there + * is scaling. + * + * @return Returns true if scaling is performed. + * + * The original content of this TopoShape is discarded and replaced with + * the new transformed shape. + */ + bool _makeElementTransform(const TopoShape &source, const Base::Matrix4D &mat, + const char *op=nullptr, bool checkScale=false, bool copy=false); + + /** Make a new shape with transformation + * + * @param source: input shape + * @param mat: transformation matrix + * @param op: optional string to be encoded into topo naming for indicating + * the operation + * @param checkScale: whether to check if the transformation matrix + * contains scaling factor. + * @param copy: whether to perform deep copy of the shape. If false, and + * checkScale is true, then the shape will be copied if there + * is scaling. + * + * @return The original content of this TopoShape is discarded and replaced + * with the new transformed shape. The function returns the + * TopoShape itself as a self reference so that multiple operations + * can be carried out for the same shape in the same line of code. + */ + TopoShape &makeElementTransform(const TopoShape &source, const Base::Matrix4D &mat, + const char *op=nullptr, bool checkScale=false, bool copy=false) { + _makeElementTransform(source,mat,op,checkScale,copy); + return *this; + } + + /** Make a new shape with transformation + * + * @param source: input shape + * @param mat: transformation matrix + * @param op: optional string to be encoded into topo naming for indicating + * the operation + * @param checkScale: whether to check if the transformation matrix + * contains scaling factor. + * @param copy: whether to perform deep copy of the shape. If false, and + * checkScale is true, then the shape will be copied if there + * is scaling. + * + * @return Return a new shape with transformation. The shape itself is not + * modified + */ + TopoShape makeElementTransform(const Base::Matrix4D &mat, const char *op=nullptr, + bool checkScale=false, bool copy=false) const { + return TopoShape(Tag,Hasher).makeElementTransform(*this,mat,op,checkScale,copy); + } + + /** Make a new shape with transformation + * + * @param source: input shape + * @param trsf: OCCT transformation matrix + * @param op: optional string to be encoded into topo naming for indicating + * the operation + * @param checkScale: whether to check if the transformation matrix + * contains scaling factor. + * @param copy: whether to perform deep copy of the shape. If false, and + * checkScale is true, then the shape will be copied if there + * is scaling. + * + * @return The original content of this TopoShape is discarded and replaced + * with the new transformed shape. The function returns the + * TopoShape itself as a self reference so that multiple operations + * can be carried out for the same shape in the same line of code. + */ + TopoShape &makeElementTransform(const TopoShape &shape, const gp_Trsf &trsf, + const char *op=nullptr, bool copy=false); + + /** Make a new shape with transformation + * + * @param source: input shape + * @param trsf: OCCT transformation matrix + * @param op: optional string to be encoded into topo naming for indicating + * the operation + * @param checkScale: whether to check if the transformation matrix + * contains scaling factor. + * @param copy: whether to perform deep copy of the shape. If false, and + * checkScale is true, then the shape will be copied if there + * is scaling. + * + * @return Return a new shape with transformation. The shape itself is not + * modified + */ + TopoShape makeElementTransform(const gp_Trsf &trsf, const char *op=nullptr, bool copy=false) const { + return TopoShape(Tag,Hasher).makeElementTransform(*this,trsf,op,copy); + } + /* Make draft shape * * @param source: the source shape diff --git a/src/Mod/Part/App/TopoShapeExpansion.cpp b/src/Mod/Part/App/TopoShapeExpansion.cpp index 1fc8a6639c..7839d4fb0d 100644 --- a/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -84,6 +84,8 @@ #include #include +#include +#include #include "Geometry.h" FC_LOG_LEVEL_INIT("TopoShape", true, true) // NOLINT @@ -2506,6 +2508,88 @@ TopoShape& TopoShape::makeElementOrderedWires(const std::vector& shap return makeElementCompound(wires, nullptr, SingleShapeCompoundCreationPolicy::returnShape); } +bool TopoShape::_makeElementTransform(const TopoShape &shape, + const Base::Matrix4D &rclTrf, const char *op, bool checkScale, bool copy) +{ + if(checkScale) { + auto scaleType = rclTrf.hasScale(); + if (scaleType != Base::ScaleType::NoScaling && scaleType != Base::ScaleType::Uniform) { + makeElementGTransform(shape,rclTrf,op,copy); + return true; + } + } + makeElementTransform(shape,convert(rclTrf),op,copy); + return false; +} + +TopoShape &TopoShape::makeElementTransform(const TopoShape &shape, const gp_Trsf &trsf, const char *op, bool copy) { + if(!copy) { + // OCCT checks the ScaleFactor against gp::Resolution() which is DBL_MIN!!! + copy = trsf.ScaleFactor()*trsf.HVectorialPart().Determinant() < 0. || + Abs(Abs(trsf.ScaleFactor()) - 1) > Precision::Confusion(); + } + TopoShape tmp(shape); + if(copy) { + if(shape.isNull()) + FC_THROWM(NullShapeException, "Null input shape"); + + BRepBuilderAPI_Transform mkTrf(shape.getShape(), trsf, Standard_True); + // TODO: calling Moved() is to make sure the shape has some Location, + // which is necessary for STEP export to work. However, if we reach + // here, it porabably means BRepBuilderAPI_Transform has modified + // underlying shapes (because of scaling), it will break compound child + // parent relationship anyway. In short, STEP import/export will most + // likely break badly if there is any scaling involved + tmp.setShape(mkTrf.Shape().Moved(gp_Trsf()), false); + } else + tmp.move(trsf); + + if(op || (shape.Tag && shape.Tag!=Tag)) { + setShape(tmp._Shape); + initCache(); + if (!Hasher) + Hasher = tmp.Hasher; + copyElementMap(tmp, op); + } else + *this = tmp; + return *this; +} + +TopoShape &TopoShape::makeElementGTransform(const TopoShape &shape, + const Base::Matrix4D &rclTrf, const char *op, bool copy) +{ + if(shape.isNull()) + FC_THROWM(NullShapeException, "Null input shape"); + + // if(!op) op = Part::OpCodes::Gtransform; + gp_GTrsf mat; + mat.SetValue(1,1,rclTrf[0][0]); + mat.SetValue(2,1,rclTrf[1][0]); + mat.SetValue(3,1,rclTrf[2][0]); + mat.SetValue(1,2,rclTrf[0][1]); + mat.SetValue(2,2,rclTrf[1][1]); + mat.SetValue(3,2,rclTrf[2][1]); + mat.SetValue(1,3,rclTrf[0][2]); + mat.SetValue(2,3,rclTrf[1][2]); + mat.SetValue(3,3,rclTrf[2][2]); + mat.SetValue(1,4,rclTrf[0][3]); + mat.SetValue(2,4,rclTrf[1][3]); + mat.SetValue(3,4,rclTrf[2][3]); + + // geometric transformation + TopoShape tmp(shape); + BRepBuilderAPI_GTransform mkTrf(shape.getShape(), mat, copy); + tmp.setShape(mkTrf.Shape(), false); + if(op || (shape.Tag && shape.Tag!=Tag)) { + setShape(tmp._Shape); + initCache(); + if (!Hasher) + Hasher = tmp.Hasher; + copyElementMap(tmp, op); + } else + *this = tmp; + return *this; +} TopoShape& TopoShape::makeElementCopy(const TopoShape& shape, const char* op, bool copyGeom, bool copyMesh) From e33e0a3f5e9d5f276ee5ef0c668f013b22657758 Mon Sep 17 00:00:00 2001 From: bgbsww Date: Tue, 20 Feb 2024 11:40:24 -0500 Subject: [PATCH 2/2] Toponaming/Part: Clean and add tests for elementTransform methods --- src/Mod/Part/App/TopoShape.h | 95 +++++++++------- src/Mod/Part/App/TopoShapeExpansion.cpp | 102 +++++++++++------- tests/src/Mod/Part/App/TopoShapeExpansion.cpp | 96 ++++++++++++++++- .../Part/App/TopoShapeMakeElementRefine.cpp | 2 +- 4 files changed, 215 insertions(+), 80 deletions(-) diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 1a8f21144b..4cc128c696 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -214,6 +214,18 @@ enum class AsAngle yes }; +enum class CheckScale +{ + noScaleCheck, + checkScale +}; + +enum class Copy +{ + noCopy, + copy +}; + /** The representation for a CAD Shape */ // NOLINTNEXTLINE cppcoreguidelines-special-member-functions @@ -802,7 +814,7 @@ public: /** Make a hollowed solid by removing some faces from a given solid * - * @param source: input shape + * @param shape: input shape * @param faces: list of faces to remove, must be sub shape of the input shape * @param offset: thickness of the walls * @param tol: tolerance criterion for coincidence in generated shapes @@ -818,13 +830,12 @@ public: * a self reference so that multiple operations can be carried out * for the same shape in the same line of code. */ - TopoShape &makeElementThickSolid(const TopoShape &source, const std::vector &faces, + TopoShape &makeElementThickSolid(const TopoShape &shape, const std::vector &faces, double offset, double tol, bool intersection = false, bool selfInter = false, short offsetMode = 0, JoinType join = JoinType::arc, const char *op=nullptr); /** Make a hollowed solid by removing some faces from a given solid * - * @param source: input shape * @param faces: list of faces to remove, must be sub shape of the input shape * @param offset: thickness of the walls * @param tol: tolerance criterion for coincidence in generated shapes @@ -1240,7 +1251,6 @@ public: return TopoShape(0, Hasher).makeElementWires(*this, op, tol, policy, output); } - /** Make a new shape with transformation that may contain non-uniform scaling * * @param source: input shape @@ -1255,8 +1265,10 @@ public: * TopoShape itself as a self reference so that multiple operations * can be carried out for the same shape in the same line of code. */ - TopoShape &makeElementGTransform(const TopoShape &source, const Base::Matrix4D &mat, - const char *op=nullptr, bool copy=false); + TopoShape& makeElementGTransform(const TopoShape& source, + const Base::Matrix4D& mat, + const char* op = nullptr, + Copy copy = Copy::noCopy); /** Make a new shape with transformation that may contain non-uniform scaling * @@ -1270,8 +1282,11 @@ public: * @return Return a new shape with transformation. The shape itself is not * modified */ - TopoShape makeElementGTransform(const Base::Matrix4D &mat, const char *op=nullptr, bool copy=false) const { - return TopoShape(Tag,Hasher).makeElementGTransform(*this,mat,op,copy); + TopoShape makeElementGTransform(const Base::Matrix4D& mat, + const char* op = nullptr, + Copy copy = Copy::noCopy) const + { + return TopoShape(Tag, Hasher).makeElementGTransform(*this, mat, op, copy); } /** Make a deep copy of the shape @@ -1452,8 +1467,8 @@ public: * the operation * @param checkScale: whether to check if the transformation matrix * contains scaling factor. - * @param copy: whether to perform deep copy of the shape. If false, and - * checkScale is true, then the shape will be copied if there + * @param copy: whether to perform deep copy of the shape. If noCopy, and + * checkScale, then the shape will be copied if there * is scaling. * * @return Returns true if scaling is performed. @@ -1461,8 +1476,11 @@ public: * The original content of this TopoShape is discarded and replaced with * the new transformed shape. */ - bool _makeElementTransform(const TopoShape &source, const Base::Matrix4D &mat, - const char *op=nullptr, bool checkScale=false, bool copy=false); + bool _makeElementTransform(const TopoShape& source, + const Base::Matrix4D& mat, + const char* op = nullptr, + CheckScale checkScale = CheckScale::noScaleCheck, + Copy copy = Copy::noCopy); /** Make a new shape with transformation * @@ -1472,8 +1490,8 @@ public: * the operation * @param checkScale: whether to check if the transformation matrix * contains scaling factor. - * @param copy: whether to perform deep copy of the shape. If false, and - * checkScale is true, then the shape will be copied if there + * @param copy: whether to perform deep copy of the shape. If noCopy, and + * checkScale, then the shape will be copied if there * is scaling. * * @return The original content of this TopoShape is discarded and replaced @@ -1481,9 +1499,13 @@ public: * TopoShape itself as a self reference so that multiple operations * can be carried out for the same shape in the same line of code. */ - TopoShape &makeElementTransform(const TopoShape &source, const Base::Matrix4D &mat, - const char *op=nullptr, bool checkScale=false, bool copy=false) { - _makeElementTransform(source,mat,op,checkScale,copy); + TopoShape& makeElementTransform(const TopoShape& source, + const Base::Matrix4D& mat, + const char* op = nullptr, + CheckScale checkScale = CheckScale::noScaleCheck, + Copy copy = Copy::noCopy) + { + _makeElementTransform(source, mat, op, checkScale, copy); return *this; } @@ -1495,16 +1517,19 @@ public: * the operation * @param checkScale: whether to check if the transformation matrix * contains scaling factor. - * @param copy: whether to perform deep copy of the shape. If false, and - * checkScale is true, then the shape will be copied if there + * @param copy: whether to perform deep copy of the shape. If noCopy, and + * checkScale, then the shape will be copied if there * is scaling. * * @return Return a new shape with transformation. The shape itself is not * modified */ - TopoShape makeElementTransform(const Base::Matrix4D &mat, const char *op=nullptr, - bool checkScale=false, bool copy=false) const { - return TopoShape(Tag,Hasher).makeElementTransform(*this,mat,op,checkScale,copy); + TopoShape makeElementTransform(const Base::Matrix4D& mat, + const char* op = nullptr, + CheckScale checkScale = CheckScale::noScaleCheck, + Copy copy = Copy::noCopy) const + { + return TopoShape(Tag, Hasher).makeElementTransform(*this, mat, op, checkScale, copy); } /** Make a new shape with transformation @@ -1513,19 +1538,17 @@ public: * @param trsf: OCCT transformation matrix * @param op: optional string to be encoded into topo naming for indicating * the operation - * @param checkScale: whether to check if the transformation matrix - * contains scaling factor. - * @param copy: whether to perform deep copy of the shape. If false, and - * checkScale is true, then the shape will be copied if there - * is scaling. + * @param copy: whether to perform deep copy of the shape. * * @return The original content of this TopoShape is discarded and replaced * with the new transformed shape. The function returns the * TopoShape itself as a self reference so that multiple operations * can be carried out for the same shape in the same line of code. */ - TopoShape &makeElementTransform(const TopoShape &shape, const gp_Trsf &trsf, - const char *op=nullptr, bool copy=false); + TopoShape& makeElementTransform(const TopoShape& shape, + const gp_Trsf& trsf, + const char* op = nullptr, + Copy copy = Copy::noCopy); /** Make a new shape with transformation * @@ -1533,17 +1556,15 @@ public: * @param trsf: OCCT transformation matrix * @param op: optional string to be encoded into topo naming for indicating * the operation - * @param checkScale: whether to check if the transformation matrix - * contains scaling factor. - * @param copy: whether to perform deep copy of the shape. If false, and - * checkScale is true, then the shape will be copied if there - * is scaling. + * @param copy: whether to perform deep copy of the shape. * * @return Return a new shape with transformation. The shape itself is not * modified */ - TopoShape makeElementTransform(const gp_Trsf &trsf, const char *op=nullptr, bool copy=false) const { - return TopoShape(Tag,Hasher).makeElementTransform(*this,trsf,op,copy); + TopoShape + makeElementTransform(const gp_Trsf& trsf, const char* op = nullptr, Copy copy = Copy::noCopy) + { + return TopoShape(Tag, Hasher).makeElementTransform(*this, trsf, op, copy); } /* Make draft shape @@ -1784,7 +1805,7 @@ public: * makeShapeWithElementMap directly. For example: * makeElementShape(sewer, sources) * makeShapeWithElementMap(sewer.SewedShape(), MapperSewing(sewer), sources, OpCodes::Sewing); - * Note that if op exists in the method, it should be checked for null and overriden with + * Note that if op exists in the method, it should be checked for null and overridden with * the appropriate operation if so. */ diff --git a/src/Mod/Part/App/TopoShapeExpansion.cpp b/src/Mod/Part/App/TopoShapeExpansion.cpp index 7839d4fb0d..08daf6132a 100644 --- a/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -48,9 +48,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -83,10 +85,6 @@ #include "Geometry.h" #include -#include -#include -#include -#include "Geometry.h" FC_LOG_LEVEL_INIT("TopoShape", true, true) // NOLINT @@ -2508,86 +2506,108 @@ TopoShape& TopoShape::makeElementOrderedWires(const std::vector& shap return makeElementCompound(wires, nullptr, SingleShapeCompoundCreationPolicy::returnShape); } -bool TopoShape::_makeElementTransform(const TopoShape &shape, - const Base::Matrix4D &rclTrf, const char *op, bool checkScale, bool copy) +bool TopoShape::_makeElementTransform(const TopoShape& shape, + const Base::Matrix4D& mat, + const char* op, + CheckScale checkScale, + Copy copy) { - if(checkScale) { - auto scaleType = rclTrf.hasScale(); + if (checkScale == CheckScale::checkScale) { + auto scaleType = mat.hasScale(); if (scaleType != Base::ScaleType::NoScaling && scaleType != Base::ScaleType::Uniform) { - makeElementGTransform(shape,rclTrf,op,copy); + makeElementGTransform(shape, mat, op, copy); return true; } } - makeElementTransform(shape,convert(rclTrf),op,copy); + makeElementTransform(shape, convert(mat), op, copy); return false; } -TopoShape &TopoShape::makeElementTransform(const TopoShape &shape, const gp_Trsf &trsf, const char *op, bool copy) { - if(!copy) { +TopoShape& TopoShape::makeElementTransform(const TopoShape& shape, + const gp_Trsf& trsf, + const char* op, + Copy copy) +{ + if (copy == Copy::noCopy) { // OCCT checks the ScaleFactor against gp::Resolution() which is DBL_MIN!!! - copy = trsf.ScaleFactor()*trsf.HVectorialPart().Determinant() < 0. || - Abs(Abs(trsf.ScaleFactor()) - 1) > Precision::Confusion(); + // No scaling is 1 as in 1:1 + const bool scaling = Abs(Abs(trsf.ScaleFactor()) - 1) > Precision::Confusion(); + const bool negative_scaling = + trsf.ScaleFactor() * trsf.HVectorialPart().Determinant() < 0.0; + copy = negative_scaling || scaling ? Copy::copy : Copy::noCopy; } TopoShape tmp(shape); - if(copy) { - if(shape.isNull()) + if (copy == Copy::copy) { + if (shape.isNull()) { FC_THROWM(NullShapeException, "Null input shape"); + } BRepBuilderAPI_Transform mkTrf(shape.getShape(), trsf, Standard_True); // TODO: calling Moved() is to make sure the shape has some Location, // which is necessary for STEP export to work. However, if we reach - // here, it porabably means BRepBuilderAPI_Transform has modified + // here, it probably means BRepBuilderAPI_Transform has modified // underlying shapes (because of scaling), it will break compound child // parent relationship anyway. In short, STEP import/export will most // likely break badly if there is any scaling involved tmp.setShape(mkTrf.Shape().Moved(gp_Trsf()), false); - } else + } + else { tmp.move(trsf); + } - if(op || (shape.Tag && shape.Tag!=Tag)) { + if (op || (shape.Tag && shape.Tag != Tag)) { setShape(tmp._Shape); initCache(); - if (!Hasher) + if (!Hasher) { Hasher = tmp.Hasher; + } copyElementMap(tmp, op); - } else + } + else { *this = tmp; + } return *this; } -TopoShape &TopoShape::makeElementGTransform(const TopoShape &shape, - const Base::Matrix4D &rclTrf, const char *op, bool copy) +TopoShape& TopoShape::makeElementGTransform(const TopoShape& shape, + const Base::Matrix4D& mat, + const char* op, + Copy copy) { - if(shape.isNull()) + if (shape.isNull()) { FC_THROWM(NullShapeException, "Null input shape"); + } // if(!op) op = Part::OpCodes::Gtransform; - gp_GTrsf mat; - mat.SetValue(1,1,rclTrf[0][0]); - mat.SetValue(2,1,rclTrf[1][0]); - mat.SetValue(3,1,rclTrf[2][0]); - mat.SetValue(1,2,rclTrf[0][1]); - mat.SetValue(2,2,rclTrf[1][1]); - mat.SetValue(3,2,rclTrf[2][1]); - mat.SetValue(1,3,rclTrf[0][2]); - mat.SetValue(2,3,rclTrf[1][2]); - mat.SetValue(3,3,rclTrf[2][2]); - mat.SetValue(1,4,rclTrf[0][3]); - mat.SetValue(2,4,rclTrf[1][3]); - mat.SetValue(3,4,rclTrf[2][3]); + gp_GTrsf matrix; + matrix.SetValue(1, 1, mat[0][0]); + matrix.SetValue(2, 1, mat[1][0]); + matrix.SetValue(3, 1, mat[2][0]); + matrix.SetValue(1, 2, mat[0][1]); + matrix.SetValue(2, 2, mat[1][1]); + matrix.SetValue(3, 2, mat[2][1]); + matrix.SetValue(1, 3, mat[0][2]); + matrix.SetValue(2, 3, mat[1][2]); + matrix.SetValue(3, 3, mat[2][2]); + matrix.SetValue(1, 4, mat[0][3]); + matrix.SetValue(2, 4, mat[1][3]); + matrix.SetValue(3, 4, mat[2][3]); // geometric transformation TopoShape tmp(shape); - BRepBuilderAPI_GTransform mkTrf(shape.getShape(), mat, copy); + BRepBuilderAPI_GTransform mkTrf(shape.getShape(), matrix, copy == Copy::copy); tmp.setShape(mkTrf.Shape(), false); - if(op || (shape.Tag && shape.Tag!=Tag)) { + if (op || (shape.Tag && shape.Tag != Tag)) { setShape(tmp._Shape); initCache(); - if (!Hasher) + if (!Hasher) { Hasher = tmp.Hasher; + } copyElementMap(tmp, op); - } else + } + else { *this = tmp; + } return *this; } diff --git a/tests/src/Mod/Part/App/TopoShapeExpansion.cpp b/tests/src/Mod/Part/App/TopoShapeExpansion.cpp index 16f9578827..c122481cdd 100644 --- a/tests/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/tests/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -1523,7 +1523,6 @@ TEST_F(TopoShapeExpansionTest, makeElementThickSolid) EXPECT_EQ(elements[IndexedName("Edge", 1)], MappedName("Edge11;THK;:H1:4,E")); } - TEST_F(TopoShapeExpansionTest, makeElementGeneralFuse) { // Arrange @@ -1845,4 +1844,99 @@ TEST_F(TopoShapeExpansionTest, makeElementFillet) })); } +TEST_F(TopoShapeExpansionTest, makeElementTransformWithoutMap) +{ + // Arrange + auto [cube1, cube2] = CreateTwoCubes(); + auto tr {gp_Trsf()}; + tr.SetTranslation(gp_Vec(gp_XYZ(-0.5, -0.5, 0))); + TopoShape topoShape1 {cube1, 1L}; + // Act + TopoShape& result = topoShape1.makeElementTransform(topoShape1, tr); + auto elements = elementMap(result); + Base::BoundBox3d bb = result.getBoundBox(); + // Assert shape is correct + EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(-0.5, -0.5, 0.0, 0.5, 0.5, 1.0))); + EXPECT_FLOAT_EQ(getVolume(result.getShape()), 1); + // Assert elementMap is correct + EXPECT_EQ(elements.size(), 0); +} + +TEST_F(TopoShapeExpansionTest, makeElementTransformWithMap) +{ + // Arrange + auto [cube1, cube2] = CreateTwoCubes(); + auto tr {gp_Trsf()}; + tr.SetTranslation(gp_Vec(gp_XYZ(-0.5, -0.5, 0))); + cube2.Move(TopLoc_Location(tr)); + TopoShape topoShape1 {cube1, 1L}; + TopoShape topoShape2 {cube2, 2L}; + // Act + TopoShape& result = topoShape1.makeElementFuse({topoShape1, topoShape2}); // op, tolerance + topoShape1.makeElementTransform(result, tr); + auto elements = elementMap(result); + Base::BoundBox3d bb = result.getBoundBox(); + // Assert shape is correct + EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(-0.5, -1.0, 0.0, 1.0, 0.5, 1.0))); + EXPECT_FLOAT_EQ(getVolume(result.getShape()), 1.75); + // Assert elementMap is correct + EXPECT_EQ(elements.size(), 66); + EXPECT_EQ(elements.count(IndexedName("Face", 1)), 1); + EXPECT_EQ( + elements[IndexedName("Face", 1)], + MappedName( + "Face3;:M;FUS;:H1:7,F;:U;FUS;:H1:7,E;:L(Face5;:M;FUS;:H1:7,F;:U2;FUS;:H1:8,E|Face5;:M;" + "FUS;:H1:7,F;:U2;FUS;:H1:8,E;:U;FUS;:H1:7,V;:L(Face6;:M;FUS;:H1:7,F;:U2;FUS;:H1:8,E;:U;" + "FUS;:H1:7,V);FUS;:H1:3c,E|Face6;:M;FUS;:H1:7,F;:U2;FUS;:H1:8,E);FUS;:H1:cb,F")); +} + +TEST_F(TopoShapeExpansionTest, makeElementGTransformWithoutMap) +{ + // Arrange + auto [cube1, cube2] = CreateTwoCubes(); + auto tr {gp_Trsf()}; + tr.SetTranslation(gp_Vec(gp_XYZ(-0.5, -0.5, 0))); + TopoShape topoShape1 {cube1, 1L}; + // Act + TopoShape& result = topoShape1.makeElementGTransform(topoShape1, TopoShape::convert(tr)); + auto elements = elementMap(result); + Base::BoundBox3d bb = result.getBoundBox(); + // Assert shape is correct + EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(-0.5, -0.5, 0.0, 0.5, 0.5, 1.0))); + EXPECT_FLOAT_EQ(getVolume(result.getShape()), 1); + // Assert elementMap is correct + EXPECT_EQ(elements.size(), 0); +} + +TEST_F(TopoShapeExpansionTest, makeElementGTransformWithMap) +{ + // Arrange + auto [cube1, cube2] = CreateTwoCubes(); + auto tr {gp_Trsf()}; + tr.SetTranslation(gp_Vec(gp_XYZ(-0.5, -0.5, 0))); + cube2.Move(TopLoc_Location(tr)); + TopoShape topoShape1 {cube1, 1L}; + TopoShape topoShape2 {cube2, 2L}; + // Act + TopoShape& result = topoShape1.makeElementFuse({topoShape1, topoShape2}); // op, tolerance + topoShape1.makeElementGTransform(result, TopoShape::convert(tr)); + auto elements = elementMap(result); + Base::BoundBox3d bb = result.getBoundBox(); + // Assert shape is correct + EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(-0.5, -1.0, 0.0, 1.0, 0.5, 1.0))); + EXPECT_FLOAT_EQ(getVolume(result.getShape()), 1.75); + // Assert elementMap is correct + EXPECT_EQ(elements.size(), 66); + EXPECT_EQ(elements.count(IndexedName("Face", 1)), 1); + EXPECT_EQ( + elements[IndexedName("Face", 1)], + MappedName( + "Face3;:M;FUS;:H1:7,F;:U;FUS;:H1:7,E;:L(Face5;:M;FUS;:H1:7,F;:U2;FUS;:H1:8,E|Face5;:M;" + "FUS;:H1:7,F;:U2;FUS;:H1:8,E;:U;FUS;:H1:7,V;:L(Face6;:M;FUS;:H1:7,F;:U2;FUS;:H1:8,E;:U;" + "FUS;:H1:7,V);FUS;:H1:3c,E|Face6;:M;FUS;:H1:7,F;:U2;FUS;:H1:8,E);FUS;:H1:cb,F")); +} + +// Not testing _makeElementTransform as it is a thin wrapper that calls the same places as the four +// preceding tests. + // NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers) diff --git a/tests/src/Mod/Part/App/TopoShapeMakeElementRefine.cpp b/tests/src/Mod/Part/App/TopoShapeMakeElementRefine.cpp index e823ace748..84afef491b 100644 --- a/tests/src/Mod/Part/App/TopoShapeMakeElementRefine.cpp +++ b/tests/src/Mod/Part/App/TopoShapeMakeElementRefine.cpp @@ -48,6 +48,6 @@ TEST_F(FeaturePartMakeElementRefineTest, makeElementRefineBoxes) EXPECT_EQ(refined.countSubElements("Face"), 6); // After refining it is one box EXPECT_EQ(refined.countSubElements("Edge"), 12); // 12 edges in a box // TODO: Make sure we have an elementMap for the refine. - // Refine doesn't work on compounds, so we're going to need a binary operation or the + // TODO: Refine doesn't work on compounds, so we're going to need a binary operation or the // like, and those don't exist yet. Once they do, this test can be expanded }