From cb7d7d27a23a89e50db7aeba5d5efdc1d0c1c9f1 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 29 Apr 2022 14:57:05 +0200 Subject: [PATCH] Part: adjust TopoShape::transformGShape() to reduce code duplication of TopoShape::makeGTransform Revert changes of a96d356afbdc4d as otherwise there is no way to handle a failure in client code --- src/Mod/Part/App/TopoShape.cpp | 33 +++++------------------------ src/Mod/Part/App/TopoShape.h | 2 +- src/Mod/Part/App/TopoShapePyImp.cpp | 8 +++---- 3 files changed, 10 insertions(+), 33 deletions(-) diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 12a848afc3..2bea062873 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -3179,7 +3179,7 @@ void TopoShape::transformGeometry(const Base::Matrix4D &rclMat) *this = makeGTransform(rclMat); } -TopoDS_Shape TopoShape::transformGShape(const Base::Matrix4D& rclTrf) const +TopoDS_Shape TopoShape::transformGShape(const Base::Matrix4D& rclTrf, bool copy) const { if (this->_Shape.IsNull()) Standard_Failure::Raise("Cannot transform null shape"); @@ -3199,7 +3199,7 @@ TopoDS_Shape TopoShape::transformGShape(const Base::Matrix4D& rclTrf) const mat.SetValue(3,4,rclTrf[2][3]); // geometric transformation - BRepBuilderAPI_GTransform mkTrf(this->_Shape, mat); + BRepBuilderAPI_GTransform mkTrf(this->_Shape, mat, copy); return mkTrf.Shape(); } @@ -4354,32 +4354,9 @@ TopoShape &TopoShape::makeTransform(const TopoShape &shape, const gp_Trsf &trsf, return *this; } -TopoShape &TopoShape::makeGTransform(const TopoShape &shape, - const Base::Matrix4D &rclTrf, const char *op, bool copy) +TopoShape &TopoShape::makeGTransform(const TopoShape &shape, const Base::Matrix4D &rclTrf, const char *op, bool copy) { - (void)op; - 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]); - - try { - // geometric transformation - BRepBuilderAPI_GTransform mkTrf(shape.getShape(), mat, copy); - _Shape = mkTrf.Shape(); - } - catch (const Standard_Failure& e) { - Base::Console().Error("TopoShape::makeGTransform failed: %s\n", e.GetMessageString()); - } + std::ignore = op; + _Shape = shape.transformGShape(rclTrf, copy); return *this; } - diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index fa155a71d2..1c90cca133 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -281,7 +281,7 @@ public: /** @name Manipulation*/ //@{ void transformGeometry(const Base::Matrix4D &rclMat); - TopoDS_Shape transformGShape(const Base::Matrix4D&) const; + TopoDS_Shape transformGShape(const Base::Matrix4D&, bool copy = false) const; bool transformShape(const Base::Matrix4D&, bool copy, bool checkScale=false); TopoDS_Shape mirror(const gp_Ax2&) const; TopoDS_Shape toNurbs() const; diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp index c551f1894a..82e172468f 100644 --- a/src/Mod/Part/App/TopoShapePyImp.cpp +++ b/src/Mod/Part/App/TopoShapePyImp.cpp @@ -1374,16 +1374,16 @@ PyObject* TopoShapePy::mirror(PyObject *args) PyObject* TopoShapePy::transformGeometry(PyObject *args) { PyObject *obj; - if (!PyArg_ParseTuple(args, "O!", &(Base::MatrixPy::Type),&obj)) + PyObject *cpy = Py_False; + if (!PyArg_ParseTuple(args, "O!|O!", &(Base::MatrixPy::Type), &obj, &PyBool_Type, &cpy)) return nullptr; - Base::Matrix4D mat = static_cast(obj)->value(); try { - TopoDS_Shape shape = this->getTopoShapePtr()->transformGShape(mat); + Base::Matrix4D mat = static_cast(obj)->value(); + TopoDS_Shape shape = this->getTopoShapePtr()->transformGShape(mat, PyObject_IsTrue(cpy) ? true : false); return new TopoShapePy(new TopoShape(shape)); } catch (Standard_Failure& e) { - PyErr_SetString(PartExceptionOCCError, e.GetMessageString()); return nullptr; }