From 54a0a5b45488f7806dc8e6731db69a713c196050 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Mon, 24 Jun 2024 21:57:16 +0200 Subject: [PATCH] Some more python mapping wrapping experiments --- src/ifcwrap/IfcGeomWrapper.i | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/ifcwrap/IfcGeomWrapper.i b/src/ifcwrap/IfcGeomWrapper.i index 6fc23d2ca6..07df60c1df 100644 --- a/src/ifcwrap/IfcGeomWrapper.i +++ b/src/ifcwrap/IfcGeomWrapper.i @@ -100,6 +100,14 @@ std::pair vector_to_buffer(const T& t) { %ignore ifcopenshell::geometry::taxonomy::item::print; +%typemap(out) boost::variant< ifcopenshell::geometry::taxonomy::point3::ptr,double > { + if ($1.which() == 0) { + return SWIG_NewPointerObj(SWIG_as_voidptr(new std::shared_ptr(boost::get($1))), SWIGTYPE_p_std__shared_ptrT_ifcopenshell__geometry__taxonomy__point3_t, 0 | SWIG_POINTER_OWN); + } else { + return PyFloat_FromDouble(boost::get($1)); + } +} + %typemap(in) ifcopenshell::geometry::taxonomy::item::ptr { // @this is really annoying, but apparently inheritance @@ -197,6 +205,7 @@ std::string taxonomy_item_repr(ifcopenshell::geometry::taxonomy::item::ptr i) { %include "../serializers/GltfSerializer.h" %template(material_vector) std::vector; +%template(edge_vector) std::vector; %extend ifcopenshell::geometry::taxonomy::style { size_t instance_id() const { @@ -211,6 +220,47 @@ std::string taxonomy_item_repr(ifcopenshell::geometry::taxonomy::item::ptr i) { } } +%extend ifcopenshell::geometry::taxonomy::point3 { + PyObject* coords_() const { + auto result = PyTuple_New(3); + for (int i = 0; i < 3; ++i) { + PyTuple_SET_ITEM(result, i, PyFloat_FromDouble($self->ccomponents().data()[i])); + } + return result; + } + + %pythoncode %{ + coords = property(coords_) + %} +} + +%extend ifcopenshell::geometry::taxonomy::direction3 { + // @todo refactor in macro + PyObject* coords_() const { + auto result = PyTuple_New(3); + for (int i = 0; i < 3; ++i) { + PyTuple_SET_ITEM(result, i, PyFloat_FromDouble($self->ccomponents().data()[i])); + } + return result; + } + + %pythoncode %{ + coords = property(coords_) + %} +} + + +%extend ifcopenshell::geometry::taxonomy::loop { + std::vector children_() const { + return $self->children; + } + + %pythoncode %{ + children = property(children_) + %} +} + + %extend ifcopenshell::geometry::Settings { void set_(const std::string& name, bool val) { return $self->set(name, val);