From 43b707bcfbd902aef43ebf8acce867e4236dfbd9 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Thu, 7 Mar 2024 12:39:56 +0100 Subject: [PATCH] wrap inertia of occ-shape to Python --- libsrc/occ/occ_utils.hpp | 2 +- libsrc/occ/python_occ_basic.cpp | 6 ++++++ libsrc/occ/python_occ_shapes.cpp | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libsrc/occ/occ_utils.hpp b/libsrc/occ/occ_utils.hpp index 42d92e6b..36a2f3d9 100644 --- a/libsrc/occ/occ_utils.hpp +++ b/libsrc/occ/occ_utils.hpp @@ -317,6 +317,6 @@ namespace netgen { return Properties(shape).Mass(); } - + } #endif // FILE_OCC_UTILS_INCLUDED diff --git a/libsrc/occ/python_occ_basic.cpp b/libsrc/occ/python_occ_basic.cpp index d84e78d1..5f2482bc 100644 --- a/libsrc/occ/python_occ_basic.cpp +++ b/libsrc/occ/python_occ_basic.cpp @@ -132,6 +132,12 @@ DLL_HEADER void ExportNgOCCBasic(py::module &m) return str.str(); }) ; + + + py::class_(m, "gp_Mat", "3d OCC matrix") + .def("__getitem__", [](const gp_Mat& mat, tuple index) + { return mat.Row(get<0>(index)+1).Coord(get<1>(index)+1); }) + ; py::class_(m, "Axis", "an OCC axis in 3d") .def(py::init([](gp_Pnt p, gp_Dir d) { diff --git a/libsrc/occ/python_occ_shapes.cpp b/libsrc/occ/python_occ_shapes.cpp index 0fb7c51e..2be43ca3 100644 --- a/libsrc/occ/python_occ_shapes.cpp +++ b/libsrc/occ/python_occ_shapes.cpp @@ -740,6 +740,10 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m) return Mass(shape); }, "returns mass of shape, what is length, face, or volume") + .def_property_readonly("inertia", [](const TopoDS_Shape & shape) { + return Properties(shape).MatrixOfInertia(); + }, "returns matrix of inertia of shape") + .def("Move", [](const TopoDS_Shape & shape, const gp_Vec v) { // which one to choose ?