diff --git a/src/ifcwrap/IfcGeomWrapper.i b/src/ifcwrap/IfcGeomWrapper.i index 69b737fff4..007e9d6223 100644 --- a/src/ifcwrap/IfcGeomWrapper.i +++ b/src/ifcwrap/IfcGeomWrapper.i @@ -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($1); + IfcGeom::TriangulationElement* triangulation_elem = dynamic_cast($1); + IfcGeom::BRepElement* brep_elem = dynamic_cast($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* { - IfcGeom::SerializedElement* serialized_elem = dynamic_cast*>($1); - IfcGeom::TriangulationElement* triangulation_elem = dynamic_cast*>($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* operator()(IfcGeom::Element* elem) const { - IfcGeom::SerializedElement* serialized_elem = dynamic_cast*>(elem); - IfcGeom::TriangulationElement* triangulation_elem = dynamic_cast*>(elem); + PyObject* operator()(IfcGeom::Element* elem) const { + IfcGeom::SerializedElement* serialized_elem = dynamic_cast(elem); + IfcGeom::TriangulationElement* triangulation_elem = dynamic_cast(elem); + IfcGeom::BRepElement* brep_elem = dynamic_cast(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(representation); - IfcGeom::Representation::Triangulation* triangulated_representation = dynamic_cast*>(representation); + IfcGeom::Representation::Triangulation* triangulated_representation = dynamic_cast(representation); + IfcGeom::Representation::BRep* brep_representation = dynamic_cast(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::Representation::Representation*> { +%typemap(out) boost::variant { // 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 // I couldn't get the vector typemap to be applied when %extending Iterator constructor. // anyway it does not matter as SWIG generates C code without actual constructors %inline %{ - template - IfcGeom::Iterator* construct_iterator_with_include_exclude_(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector elems, bool include, int num_threads) { + IfcGeom::Iterator* construct_iterator_with_include_exclude(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector elems, bool include, int num_threads) { std::set elems_set(elems.begin(), elems.end()); IfcGeom::entity_filter ef{ include, false, elems_set }; - return new IfcGeom::Iterator(settings, file, {ef}, num_threads); + return new IfcGeom::Iterator(settings, file, {ef}, num_threads); } - template - IfcGeom::Iterator* construct_iterator_with_include_exclude_globalid_(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector elems, bool include, int num_threads) { + IfcGeom::Iterator* construct_iterator_with_include_exclude_globalid(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector elems, bool include, int num_threads) { std::set 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(settings, file, {af}, num_threads); - } - - IfcGeom::Iterator* construct_iterator_single_precision_with_include_exclude(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector elems, bool include, int num_threads) { - return construct_iterator_with_include_exclude_(settings, file, elems, include, num_threads); - } - - IfcGeom::Iterator* construct_iterator_double_precision_with_include_exclude(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector elems, bool include, int num_threads) { - return construct_iterator_with_include_exclude_(settings, file, elems, include, num_threads); - } - - IfcGeom::Iterator* construct_iterator_single_precision_with_include_exclude_globalid(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector elems, bool include, int num_threads) { - return construct_iterator_with_include_exclude_globalid_(settings, file, elems, include, num_threads); - } - - IfcGeom::Iterator* construct_iterator_double_precision_with_include_exclude_globalid(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector elems, bool include, int num_threads) { - return construct_iterator_with_include_exclude_globalid_(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 { - static int mantissa_size() { - return std::numeric_limits::digits; - } -}; - -%extend IfcGeom::Iterator { - static int mantissa_size() { - return std::numeric_limits::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 // Specialized accessors follow later, for otherwise property definitions // would appear before templated getter functions are defined. -%extend IfcGeom::Representation::Triangulation { - %pythoncode %{ - # Hide the getters with read-only property implementations - verts = property(verts) - normals = property(normals) - %} -}; -%extend IfcGeom::Representation::Triangulation { +%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 %{ template - static boost::variant*, IfcGeom::Representation::Representation*> helper_fn_create_shape(IfcGeom::IteratorSettings& settings, IfcUtil::IfcBaseClass* instance, IfcUtil::IfcBaseClass* representation = 0) { + static boost::variant 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 } } - IfcGeom::BRepElement* 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* serialization = new IfcGeom::SerializedElement(*brep); + IfcGeom::SerializedElement* serialization = new IfcGeom::SerializedElement(*brep); delete brep; return serialization; } else if (!settings.get(IfcGeom::IteratorSettings::DISABLE_TRIANGULATION)) { - IfcGeom::TriangulationElement* triangulation = new IfcGeom::TriangulationElement(*brep); + IfcGeom::TriangulationElement* triangulation = new IfcGeom::TriangulationElement(*brep); delete brep; return triangulation; } else { @@ -455,7 +424,7 @@ struct ShapeRTTI : public boost::static_visitor 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(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 throw IfcParse::IfcException("Invalid additional representation specified"); } } - return boost::variant*, IfcGeom::Representation::Representation*>(); + return boost::variant(); } %} %inline %{ - static boost::variant*, IfcGeom::Representation::Representation*> create_shape(IfcGeom::IteratorSettings& settings, IfcUtil::IfcBaseClass* instance, IfcUtil::IfcBaseClass* representation = 0) { + static boost::variant 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 return IfcGeom::tesselate(schema_name, shp, d); } %} - -namespace IfcGeom { - %template(iterator_double_precision) Iterator; - %template(element_double_precision) Element; - %template(triangulation_element_double_precision) TriangulationElement; - %template(serialized_element_double_precision) SerializedElement; - %template(transformation_double_precision) Transformation; - %template(matrix_double_precision) Matrix; - namespace Representation { - %template(triangulation_double_precision) Triangulation; - }; -}; diff --git a/src/ifcwrap/utils/typemaps_out.i b/src/ifcwrap/utils/typemaps_out.i index b21ba55799..f95823831a 100644 --- a/src/ifcwrap/utils/typemaps_out.i +++ b/src/ifcwrap/utils/typemaps_out.i @@ -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(); } }