From e3562c29efe612dc79f804645aa82e3cbe586125 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Mon, 2 Aug 2021 13:04:26 +0200 Subject: [PATCH] implicitly convert 2-tuples to occ-pnt,vec,dir --- libsrc/occ/python_occ.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libsrc/occ/python_occ.cpp b/libsrc/occ/python_occ.cpp index 097e6182..c660f03a 100644 --- a/libsrc/occ/python_occ.cpp +++ b/libsrc/occ/python_occ.cpp @@ -286,6 +286,9 @@ DLL_HEADER void ExportNgOCC(py::module &m) py::class_(m, "gp_Pnt") .def(py::init([] (py::tuple pnt) { + if (py::len(pnt) != 3) + throw Exception("need 3-tuple to create gp_Pnt"); + return gp_Pnt(py::cast(pnt[0]), py::cast(pnt[1]), py::cast(pnt[2])); @@ -334,6 +337,8 @@ DLL_HEADER void ExportNgOCC(py::module &m) py::class_(m, "gp_Pnt2d") .def(py::init([] (py::tuple pnt) { + if (py::len(pnt) != 2) + throw Exception("need 2-tuple to create gp_Pnt2d"); return gp_Pnt2d(py::cast(pnt[0]), py::cast(pnt[1])); })) @@ -344,6 +349,8 @@ DLL_HEADER void ExportNgOCC(py::module &m) py::class_(m, "gp_Vec2d") .def(py::init([] (py::tuple vec) { + if (py::len(vec) != 2) + throw Exception("need 2-tuple to create gp_Vec2d"); return gp_Vec2d(py::cast(vec[0]), py::cast(vec[1])); })) @@ -355,6 +362,8 @@ DLL_HEADER void ExportNgOCC(py::module &m) py::class_(m, "gp_Dir2d") .def(py::init([] (py::tuple dir) { + if (py::len(dir) != 2) + throw Exception("need 2-tuple to create gp_Dir2d"); return gp_Dir2d(py::cast(dir[0]), py::cast(dir[1])); })) @@ -381,11 +390,12 @@ DLL_HEADER void ExportNgOCC(py::module &m) }) ; - py::implicitly_convertible(); py::implicitly_convertible(); py::implicitly_convertible(); - + py::implicitly_convertible(); + py::implicitly_convertible(); + py::implicitly_convertible(); py::class_ (m, "TopoDS_Shape") .def("__str__", [] (const TopoDS_Shape & shape)