remove templates in wrapper

This commit is contained in:
Thomas Krijnen
2021-07-11 15:03:05 +02:00
parent 7c0459bc6e
commit c949211e1b
2 changed files with 50 additions and 93 deletions
+49 -92
View File
@@ -38,6 +38,24 @@
%ignore IfcGeom::impl::tree::selector;
// Using RTTI return a more specialized type of Element
// Note that these elements are not to be owned by SWIG/Python as they will be freed automatically upon the next iteration
// except for the IfcGeom::Element instances which are returned by Iterator::getObject() calls
%typemap(out) IfcGeom::Element* {
IfcGeom::SerializedElement* serialized_elem = dynamic_cast<IfcGeom::SerializedElement*>($1);
IfcGeom::TriangulationElement* triangulation_elem = dynamic_cast<IfcGeom::TriangulationElement*>($1);
IfcGeom::BRepElement* brep_elem = dynamic_cast<IfcGeom::BRepElement*>($1);
if (triangulation_elem) {
$result = SWIG_NewPointerObj(SWIG_as_voidptr(triangulation_elem), SWIGTYPE_p_IfcGeom__TriangulationElement, 0);
} else if (serialized_elem) {
$result = SWIG_NewPointerObj(SWIG_as_voidptr(serialized_elem), SWIGTYPE_p_IfcGeom__SerializedElement, 0);
} else if (brep_elem) {
$result = SWIG_NewPointerObj(SWIG_as_voidptr(brep_elem), SWIGTYPE_p_IfcGeom__BRepElement, 0);
} else {
$result = SWIG_NewPointerObj(SWIG_as_voidptr($1), SWIGTYPE_p_IfcGeom__Element, SWIG_POINTER_OWN);
}
}
%include "../ifcgeom/ifc_geom_api.h"
%include "../ifcgeom/IfcGeomIteratorSettings.h"
%include "../ifcgeom/IfcGeomElement.h"
@@ -102,57 +120,48 @@
}
// Using RTTI return a more specialized type of Element
// Note that these elements are not to be owned by SWIG/Python as they will be freed automatically upon the next iteration
// except for the IfcGeom::Element instances which are returned by Iterator::getObject() calls
%typemap(out) IfcGeom::Element<double>* {
IfcGeom::SerializedElement<double>* serialized_elem = dynamic_cast<IfcGeom::SerializedElement<double>*>($1);
IfcGeom::TriangulationElement<double>* triangulation_elem = dynamic_cast<IfcGeom::TriangulationElement<double>*>($1);
if (triangulation_elem) {
$result = SWIG_NewPointerObj(SWIG_as_voidptr(triangulation_elem), SWIGTYPE_p_IfcGeom__TriangulationElementT_double_double_t, 0);
} else if (serialized_elem) {
$result = SWIG_NewPointerObj(SWIG_as_voidptr(serialized_elem), SWIGTYPE_p_IfcGeom__SerializedElementT_double_double_t, 0);
} else {
$result = SWIG_NewPointerObj(SWIG_as_voidptr($1), SWIGTYPE_p_IfcGeom__ElementT_double_double_t, SWIG_POINTER_OWN);
}
}
// A visitor
%{
struct ShapeRTTI : public boost::static_visitor<PyObject*>
{
PyObject* operator()(IfcGeom::Element<double>* elem) const {
IfcGeom::SerializedElement<double>* serialized_elem = dynamic_cast<IfcGeom::SerializedElement<double>*>(elem);
IfcGeom::TriangulationElement<double>* triangulation_elem = dynamic_cast<IfcGeom::TriangulationElement<double>*>(elem);
PyObject* operator()(IfcGeom::Element* elem) const {
IfcGeom::SerializedElement* serialized_elem = dynamic_cast<IfcGeom::SerializedElement*>(elem);
IfcGeom::TriangulationElement* triangulation_elem = dynamic_cast<IfcGeom::TriangulationElement*>(elem);
IfcGeom::BRepElement* brep_elem = dynamic_cast<IfcGeom::BRepElement*>(elem);
if (triangulation_elem) {
return SWIG_NewPointerObj(SWIG_as_voidptr(triangulation_elem), SWIGTYPE_p_IfcGeom__TriangulationElementT_double_double_t, SWIG_POINTER_OWN);
return SWIG_NewPointerObj(SWIG_as_voidptr(triangulation_elem), SWIGTYPE_p_IfcGeom__TriangulationElement, SWIG_POINTER_OWN);
} else if (serialized_elem) {
return SWIG_NewPointerObj(SWIG_as_voidptr(serialized_elem), SWIGTYPE_p_IfcGeom__SerializedElementT_double_double_t, SWIG_POINTER_OWN);
return SWIG_NewPointerObj(SWIG_as_voidptr(serialized_elem), SWIGTYPE_p_IfcGeom__SerializedElement, SWIG_POINTER_OWN);
} else if (brep_elem) {
return SWIG_NewPointerObj(SWIG_as_voidptr(brep_elem), SWIGTYPE_p_IfcGeom__BRepElement, SWIG_POINTER_OWN);
} else {
throw std::runtime_error("Invalid element encountered");
return SWIG_Py_Void();
}
}
PyObject* operator()(IfcGeom::Representation::Representation* representation) const {
IfcGeom::Representation::Serialization* serialized_representation = dynamic_cast<IfcGeom::Representation::Serialization*>(representation);
IfcGeom::Representation::Triangulation<double>* triangulated_representation = dynamic_cast<IfcGeom::Representation::Triangulation<double>*>(representation);
IfcGeom::Representation::Triangulation* triangulated_representation = dynamic_cast<IfcGeom::Representation::Triangulation*>(representation);
IfcGeom::Representation::BRep* brep_representation = dynamic_cast<IfcGeom::Representation::BRep*>(representation);
if (serialized_representation) {
return SWIG_NewPointerObj(SWIG_as_voidptr(serialized_representation), SWIGTYPE_p_IfcGeom__Representation__Serialization, SWIG_POINTER_OWN);
} else if (triangulated_representation) {
return SWIG_NewPointerObj(SWIG_as_voidptr(triangulated_representation), SWIGTYPE_p_IfcGeom__Representation__TriangulationT_double_t, SWIG_POINTER_OWN);
return SWIG_NewPointerObj(SWIG_as_voidptr(triangulated_representation), SWIGTYPE_p_IfcGeom__Representation__Triangulation, SWIG_POINTER_OWN);
} else if (brep_representation) {
return SWIG_NewPointerObj(SWIG_as_voidptr(brep_representation), SWIGTYPE_p_IfcGeom__Representation__BRep, SWIG_POINTER_OWN);
} else {
throw std::runtime_error("Invalid element encountered");
return SWIG_Py_Void();
}
}
};
%}
// Note that these elements ARE to be owned by SWIG/Python
%typemap(out) boost::variant<IfcGeom::Element<double>*, IfcGeom::Representation::Representation*> {
%typemap(out) boost::variant<IfcGeom::Element*, IfcGeom::Representation::Representation*> {
// See which type is set and return appropriate
$result = boost::apply_visitor(ShapeRTTI(), $1);
}
%extend IfcGeom::IteratorSettings {
%extend SerializerSettings {
%pythoncode %{
old_init = __init__
@@ -183,57 +192,24 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
// I couldn't get the vector<string> typemap to be applied when %extending Iterator constructor.
// anyway it does not matter as SWIG generates C code without actual constructors
%inline %{
template <typename T>
IfcGeom::Iterator<T>* construct_iterator_with_include_exclude_(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector<std::string> elems, bool include, int num_threads) {
IfcGeom::Iterator* construct_iterator_with_include_exclude(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector<std::string> elems, bool include, int num_threads) {
std::set<std::string> elems_set(elems.begin(), elems.end());
IfcGeom::entity_filter ef{ include, false, elems_set };
return new IfcGeom::Iterator<T>(settings, file, {ef}, num_threads);
return new IfcGeom::Iterator(settings, file, {ef}, num_threads);
}
template <typename T>
IfcGeom::Iterator<T>* construct_iterator_with_include_exclude_globalid_(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector<std::string> elems, bool include, int num_threads) {
IfcGeom::Iterator* construct_iterator_with_include_exclude_globalid(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector<std::string> elems, bool include, int num_threads) {
std::set<std::string> elems_set(elems.begin(), elems.end());
IfcGeom::attribute_filter af;
af.attribute_name = "GlobalId";
af.populate(elems_set);
af.include = include;
return new IfcGeom::Iterator<T>(settings, file, {af}, num_threads);
}
IfcGeom::Iterator<float>* construct_iterator_single_precision_with_include_exclude(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector<std::string> elems, bool include, int num_threads) {
return construct_iterator_with_include_exclude_<float>(settings, file, elems, include, num_threads);
}
IfcGeom::Iterator<double>* construct_iterator_double_precision_with_include_exclude(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector<std::string> elems, bool include, int num_threads) {
return construct_iterator_with_include_exclude_<double>(settings, file, elems, include, num_threads);
}
IfcGeom::Iterator<float>* construct_iterator_single_precision_with_include_exclude_globalid(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector<std::string> elems, bool include, int num_threads) {
return construct_iterator_with_include_exclude_globalid_<float>(settings, file, elems, include, num_threads);
}
IfcGeom::Iterator<double>* construct_iterator_double_precision_with_include_exclude_globalid(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector<std::string> elems, bool include, int num_threads) {
return construct_iterator_with_include_exclude_globalid_<double>(settings, file, elems, include, num_threads);
return new IfcGeom::Iterator(settings, file, {af}, num_threads);
}
%}
%ignore construct_iterator_with_include_exclude_;
%newobject construct_iterator_single_precision_with_include_exclude;
%newobject construct_iterator_double_precision_with_include_exclude;
%newobject construct_iterator_single_precision_with_include_exclude_globalid;
%newobject construct_iterator_double_precision_with_include_exclude_globalid;
%extend IfcGeom::Iterator<float> {
static int mantissa_size() {
return std::numeric_limits<float>::digits;
}
};
%extend IfcGeom::Iterator<double> {
static int mantissa_size() {
return std::numeric_limits<double>::digits;
}
};
%newobject construct_iterator_with_include_exclude;
%newobject construct_iterator_with_include_exclude_globalid;
%extend IfcGeom::Representation::Triangulation {
%pythoncode %{
@@ -248,14 +224,7 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
// Specialized accessors follow later, for otherwise property definitions
// would appear before templated getter functions are defined.
%extend IfcGeom::Representation::Triangulation<float> {
%pythoncode %{
# Hide the getters with read-only property implementations
verts = property(verts)
normals = property(normals)
%}
};
%extend IfcGeom::Representation::Triangulation<double> {
%extend IfcGeom::Representation::Triangulation {
%pythoncode %{
# Hide the getters with read-only property implementations
verts = property(verts)
@@ -339,7 +308,7 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
%{
template <typename Schema>
static boost::variant<IfcGeom::Element<double>*, IfcGeom::Representation::Representation*> helper_fn_create_shape(IfcGeom::IteratorSettings& settings, IfcUtil::IfcBaseClass* instance, IfcUtil::IfcBaseClass* representation = 0) {
static boost::variant<IfcGeom::Element*, IfcGeom::Representation::Representation*> helper_fn_create_shape(IfcGeom::IteratorSettings& settings, IfcUtil::IfcBaseClass* instance, IfcUtil::IfcBaseClass* representation = 0) {
IfcParse::IfcFile* file = instance->data().file;
IfcGeom::Kernel kernel(file);
@@ -429,16 +398,16 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
}
}
IfcGeom::BRepElement<double>* brep = kernel.convert(settings, ifc_representation, product);
IfcGeom::BRepElement* brep = kernel.convert(settings, ifc_representation, product);
if (!brep) {
throw IfcParse::IfcException("Failed to process shape");
}
if (settings.get(IfcGeom::IteratorSettings::USE_BREP_DATA)) {
IfcGeom::SerializedElement<double>* serialization = new IfcGeom::SerializedElement<double>(*brep);
IfcGeom::SerializedElement* serialization = new IfcGeom::SerializedElement(*brep);
delete brep;
return serialization;
} else if (!settings.get(IfcGeom::IteratorSettings::DISABLE_TRIANGULATION)) {
IfcGeom::TriangulationElement<double>* triangulation = new IfcGeom::TriangulationElement<double>(*brep);
IfcGeom::TriangulationElement* triangulation = new IfcGeom::TriangulationElement(*brep);
delete brep;
return triangulation;
} else {
@@ -455,7 +424,7 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
if (settings.get(IfcGeom::IteratorSettings::USE_BREP_DATA)) {
return new IfcGeom::Representation::Serialization(brep);
} else if (!settings.get(IfcGeom::IteratorSettings::DISABLE_TRIANGULATION)) {
return new IfcGeom::Representation::Triangulation<double>(brep);
return new IfcGeom::Representation::Triangulation(brep);
}
} catch (...) {
throw IfcParse::IfcException("Error during shape serialization");
@@ -465,12 +434,12 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
throw IfcParse::IfcException("Invalid additional representation specified");
}
}
return boost::variant<IfcGeom::Element<double>*, IfcGeom::Representation::Representation*>();
return boost::variant<IfcGeom::Element*, IfcGeom::Representation::Representation*>();
}
%}
%inline %{
static boost::variant<IfcGeom::Element<double>*, IfcGeom::Representation::Representation*> create_shape(IfcGeom::IteratorSettings& settings, IfcUtil::IfcBaseClass* instance, IfcUtil::IfcBaseClass* representation = 0) {
static boost::variant<IfcGeom::Element*, IfcGeom::Representation::Representation*> create_shape(IfcGeom::IteratorSettings& settings, IfcUtil::IfcBaseClass* instance, IfcUtil::IfcBaseClass* representation = 0) {
const std::string& schema_name = instance->declaration().schema()->name();
#ifdef HAS_SCHEMA_2x3
@@ -527,15 +496,3 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
return IfcGeom::tesselate(schema_name, shp, d);
}
%}
namespace IfcGeom {
%template(iterator_double_precision) Iterator<double>;
%template(element_double_precision) Element<double>;
%template(triangulation_element_double_precision) TriangulationElement<double>;
%template(serialized_element_double_precision) SerializedElement<double>;
%template(transformation_double_precision) Transformation<double>;
%template(matrix_double_precision) Matrix<double>;
namespace Representation {
%template(triangulation_double_precision) Triangulation<double>;
};
};
+1 -1
View File
@@ -22,7 +22,7 @@
} else if ($1->as_aggregation_type()) {
$result = SWIG_NewPointerObj(SWIG_as_voidptr($1->as_aggregation_type()), SWIGTYPE_p_IfcParse__aggregation_type, 0);
} else {
throw std::runtime_error("unexpected parameter type");
$result = SWIG_Py_Void();
}
}