mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 14:02:27 +00:00
ifcwrap: use swig shadowing for keeping reference to Element
(cherry picked from commit 2f1b2f9638)
This commit is contained in:
@@ -267,6 +267,22 @@ namespace {
|
|||||||
%include "../ifcgeom/ifc_geom_api.h"
|
%include "../ifcgeom/ifc_geom_api.h"
|
||||||
%include "../ifcgeom/ConversionResult.h"
|
%include "../ifcgeom/ConversionResult.h"
|
||||||
%include "../ifcgeom/ConversionSettings.h"
|
%include "../ifcgeom/ConversionSettings.h"
|
||||||
|
|
||||||
|
// Keep the owning element alive while its geometry is referenced (#1124).
|
||||||
|
%define GEOMETRY_WITH_BACKREF(cls)
|
||||||
|
%feature("shadow") cls::geometry %{
|
||||||
|
@property
|
||||||
|
def geometry(self):
|
||||||
|
result = $action(self)
|
||||||
|
result._parent = self
|
||||||
|
return result
|
||||||
|
%}
|
||||||
|
%enddef
|
||||||
|
|
||||||
|
GEOMETRY_WITH_BACKREF(IfcGeom::TriangulationElement)
|
||||||
|
GEOMETRY_WITH_BACKREF(IfcGeom::SerializedElement)
|
||||||
|
GEOMETRY_WITH_BACKREF(IfcGeom::BRepElement)
|
||||||
|
|
||||||
%include "../ifcgeom/IfcGeomElement.h"
|
%include "../ifcgeom/IfcGeomElement.h"
|
||||||
%include "../ifcgeom/IfcGeomRepresentation.h"
|
%include "../ifcgeom/IfcGeomRepresentation.h"
|
||||||
%include "../ifcgeom/Iterator.h"
|
%include "../ifcgeom/Iterator.h"
|
||||||
@@ -886,27 +902,9 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
|
|||||||
};
|
};
|
||||||
|
|
||||||
%extend IfcGeom::TriangulationElement {
|
%extend IfcGeom::TriangulationElement {
|
||||||
%pythoncode %{
|
|
||||||
# Hide the getters with read-only property implementations
|
|
||||||
# Keep the owning element alive while its geometry is referenced (#1124).
|
|
||||||
def geometry_with_backref(self, _f=geometry):
|
|
||||||
result = _f(self)
|
|
||||||
result._parent = self
|
|
||||||
return result
|
|
||||||
geometry = property(geometry_with_backref)
|
|
||||||
%}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
%extend IfcGeom::SerializedElement {
|
%extend IfcGeom::SerializedElement {
|
||||||
%pythoncode %{
|
|
||||||
# Hide the getters with read-only property implementations
|
|
||||||
# Keep the owning element alive while its geometry is referenced (#1124).
|
|
||||||
def geometry_with_backref(self, _f=geometry):
|
|
||||||
result = _f(self)
|
|
||||||
result._parent = self
|
|
||||||
return result
|
|
||||||
geometry = property(geometry_with_backref)
|
|
||||||
%}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
%extend IfcGeom::BRepElement {
|
%extend IfcGeom::BRepElement {
|
||||||
@@ -929,13 +927,6 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
|
|||||||
}
|
}
|
||||||
|
|
||||||
%pythoncode %{
|
%pythoncode %{
|
||||||
# Hide the getters with read-only property implementations
|
|
||||||
# Keep the owning element alive while its geometry is referenced (#1124).
|
|
||||||
def geometry_with_backref(self, _f=geometry):
|
|
||||||
result = _f(self)
|
|
||||||
result._parent = self
|
|
||||||
return result
|
|
||||||
geometry = property(geometry_with_backref)
|
|
||||||
volume = property(calc_volume_)
|
volume = property(calc_volume_)
|
||||||
surface_area = property(calc_surface_area_)
|
surface_area = property(calc_surface_area_)
|
||||||
%}
|
%}
|
||||||
|
|||||||
Reference in New Issue
Block a user