mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 10:57:49 +00:00
Python wrapper improvements
This commit is contained in:
@@ -138,7 +138,9 @@
|
||||
PyObject* pythonize(const IfcParse::inverse_attribute* t) { return SWIG_NewPointerObj(SWIG_as_voidptr(t), SWIGTYPE_p_IfcParse__inverse_attribute, 0); }
|
||||
PyObject* pythonize(const IfcParse::entity* t) { return SWIG_NewPointerObj(SWIG_as_voidptr(t), SWIGTYPE_p_IfcParse__entity, 0); }
|
||||
PyObject* pythonize(const IfcParse::declaration* t) { return SWIG_NewPointerObj(SWIG_as_voidptr(t), declaration_type_to_swig(t), 0); }
|
||||
PyObject* pythonize(const IfcGeom::ConversionResultShape* t) { return SWIG_NewPointerObj(SWIG_as_voidptr(t), SWIGTYPE_p_IfcGeom__ConversionResultShape, 0); }
|
||||
// @nb ownership
|
||||
PyObject* pythonize(const IfcGeom::ConversionResultShape* t) { return SWIG_NewPointerObj(SWIG_as_voidptr(t), SWIGTYPE_p_IfcGeom__ConversionResultShape, SWIG_POINTER_OWN); }
|
||||
// PyObject* pythonize(const IfcGeom::ConversionResultShape* t) { return SWIG_NewPointerObj(SWIG_as_voidptr(t), SWIGTYPE_p_IfcGeom__ConversionResultShape, 0); }
|
||||
// NB: This cannot be temporary as a Python object is constructed from a pointer to the address of this object
|
||||
// PyObject* pythonize(const IfcGeom::Material& t) { return SWIG_NewPointerObj(SWIG_as_voidptr(&t), SWIGTYPE_p_IfcGeom__Material, 0); }
|
||||
|
||||
|
||||
@@ -317,4 +317,58 @@ CREATE_VECTOR_TYPEMAP_IN(std::string, STRING, str)
|
||||
|
||||
CREATE_OPTIONAL_TYPEMAP_IN(int, integer, int)
|
||||
CREATE_OPTIONAL_TYPEMAP_IN(double, real, float)
|
||||
CREATE_OPTIONAL_TYPEMAP_IN(std::string, string, str)
|
||||
CREATE_OPTIONAL_TYPEMAP_IN(std::string, string, str)
|
||||
|
||||
%{
|
||||
bool check_aggregate_of_swig_type(PyObject* aggregate, swig_type_info* type_obj) {
|
||||
if (!PySequence_Check(aggregate)) return false;
|
||||
for(Py_ssize_t i = 0; i < PySequence_Size(aggregate); ++i) {
|
||||
PyObject* element = PySequence_GetItem(aggregate, i);
|
||||
|
||||
bool b = true;
|
||||
void* argp1 = nullptr;
|
||||
auto res1 = SWIG_ConvertPtr(element, &argp1, type_obj, 0);
|
||||
if (!SWIG_IsOK(res1)) {
|
||||
b = false;
|
||||
}
|
||||
|
||||
Py_DECREF(element);
|
||||
if (!b) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::vector<T> python_sequence_as_swig_object_vector(PyObject* aggregate, swig_type_info* type_obj) {
|
||||
std::vector<T> result_vector;
|
||||
result_vector.reserve(PySequence_Size(aggregate));
|
||||
for(Py_ssize_t i = 0; i < PySequence_Size(aggregate); ++i) {
|
||||
PyObject* element = PySequence_GetItem(aggregate, i);
|
||||
void* argp1 = nullptr;
|
||||
auto res1 = SWIG_ConvertPtr(element, &argp1, type_obj, 0);
|
||||
if (SWIG_IsOK(res1)) {
|
||||
auto arg1 = reinterpret_cast<IfcGeom::OpaqueCoordinate<4>*>(argp1);
|
||||
result_vector.push_back(*arg1);
|
||||
}
|
||||
}
|
||||
return result_vector;
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap(typecheck,precedence=SWIG_TYPECHECK_INTEGER) const std::vector<IfcGeom::OpaqueCoordinate<4>>& {
|
||||
$1 = check_aggregate_of_swig_type($input, SWIGTYPE_p_IfcGeom__OpaqueCoordinateT_4_t) ? 1 : 0;
|
||||
}
|
||||
%typemap(arginit) const std::vector<IfcGeom::OpaqueCoordinate<4>>& {
|
||||
$1 = new std::vector<IfcGeom::OpaqueCoordinate<4>>();
|
||||
}
|
||||
%typemap(in) const std::vector<IfcGeom::OpaqueCoordinate<4>>& {
|
||||
if (!check_aggregate_of_swig_type($input, SWIGTYPE_p_IfcGeom__OpaqueCoordinateT_4_t)) {
|
||||
SWIG_exception(SWIG_TypeError, "");
|
||||
}
|
||||
*$1 = python_sequence_as_swig_object_vector<IfcGeom::OpaqueCoordinate<4>>($input, SWIGTYPE_p_IfcGeom__OpaqueCoordinateT_4_t);
|
||||
}
|
||||
%typemap(freearg) const std::vector<IfcGeom::OpaqueCoordinate<4>>& {
|
||||
delete $1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user