diff --git a/src/ifcgeom/IfcGeom.h b/src/ifcgeom/IfcGeom.h index 7fc6c62d60..df4b14da1e 100644 --- a/src/ifcgeom/IfcGeom.h +++ b/src/ifcgeom/IfcGeom.h @@ -322,8 +322,8 @@ public: }; -IFC_GEOM_API IfcSchema::IfcProductDefinitionShape* tesselate(const TopoDS_Shape& shape, double deflection); -IFC_GEOM_API IfcSchema::IfcProductDefinitionShape* serialise(const TopoDS_Shape& shape, bool advanced); +IfcUtil::IfcBaseClass* MAKE_TYPE_NAME(tesselate_)(const TopoDS_Shape& shape, double deflection); +IfcUtil::IfcBaseClass* MAKE_TYPE_NAME(serialise_)(const TopoDS_Shape& shape, bool advanced); } #endif diff --git a/src/ifcgeom/IfcGeomSerialisation.cpp b/src/ifcgeom/IfcGeomSerialisation.cpp index 4a1811f932..8dcb2129ca 100644 --- a/src/ifcgeom/IfcGeomSerialisation.cpp +++ b/src/ifcgeom/IfcGeomSerialisation.cpp @@ -493,7 +493,7 @@ int convert_to_ifc(const TopoDS_Shape& s, U*& item, bool advanced) { return faces->size(); } -IfcSchema::IfcProductDefinitionShape* IfcGeom::serialise(const TopoDS_Shape& shape, bool advanced) { +IfcUtil::IfcBaseClass* IfcGeom::serialise(const TopoDS_Shape& shape, bool advanced) { #ifndef USE_IFC4 advanced = false; #endif @@ -604,7 +604,7 @@ IfcSchema::IfcProductDefinitionShape* IfcGeom::serialise(const TopoDS_Shape& sha return new IfcSchema::IfcProductDefinitionShape(boost::none, boost::none, reps); } -IfcSchema::IfcProductDefinitionShape* IfcGeom::tesselate(const TopoDS_Shape& shape, double deflection) { +IfcUtil::IfcBaseClass* IfcGeom::tesselate(const TopoDS_Shape& shape, double deflection) { BRepMesh_IncrementalMesh(shape, deflection); IfcSchema::IfcFace::list::ptr faces(new IfcSchema::IfcFace::list); diff --git a/src/ifcgeom_schema_agnostic/Serialization.cpp b/src/ifcgeom_schema_agnostic/Serialization.cpp new file mode 100644 index 0000000000..79f41a726c --- /dev/null +++ b/src/ifcgeom_schema_agnostic/Serialization.cpp @@ -0,0 +1,30 @@ +#include "Serialization.h" + +#include + +namespace IfcGeom { + extern IfcUtil::IfcBaseClass* tesselate_Ifc2x3(const TopoDS_Shape& shape, double deflection); + extern IfcUtil::IfcBaseClass* tesselate_Ifc4(const TopoDS_Shape& shape, double deflection); + extern IfcUtil::IfcBaseClass* serialise_Ifc2x3(const TopoDS_Shape& shape, bool advanced); + extern IfcUtil::IfcBaseClass* serialise_Ifc4(const TopoDS_Shape& shape, bool advanced); +} + +template +IfcUtil::IfcBaseClass* execute_based_on_schema(Fn fn1, Fn fn2, const std::string& schema_name, const TopoDS_Shape& shape, T t) { + const std::string schema_name_lower = boost::to_lower_copy(schema_name); + if (schema_name == "ifc2x3") { + return fn1(shape, t); + } else if (schema_name == "ifc4") { + return fn2(shape, t); + } else { + throw IfcParse::IfcException("No geometry serialization available for " + schema_name); + } +} + +IfcUtil::IfcBaseClass* IfcGeom::tesselate(const std::string& schema_name, const TopoDS_Shape& shape, double deflection) { + return execute_based_on_schema(IfcGeom::tesselate_Ifc2x3, IfcGeom::tesselate_Ifc4, schema_name, shape, deflection); +} + +IfcUtil::IfcBaseClass* IfcGeom::serialise(const std::string& schema_name, const TopoDS_Shape& shape, bool advanced) { + return execute_based_on_schema(IfcGeom::serialise_Ifc2x3, IfcGeom::serialise_Ifc4, schema_name, shape, advanced); +} \ No newline at end of file diff --git a/src/ifcgeom_schema_agnostic/Serialization.h b/src/ifcgeom_schema_agnostic/Serialization.h new file mode 100644 index 0000000000..be3d79bd3f --- /dev/null +++ b/src/ifcgeom_schema_agnostic/Serialization.h @@ -0,0 +1,11 @@ +#include "../ifcgeom/ifc_geom_api.h" +#include "../ifcparse/IfcBaseClass.h" + +#include + +#include + +namespace IfcGeom { + IFC_GEOM_API IfcUtil::IfcBaseClass* tesselate(const std::string& schema_name, const TopoDS_Shape& shape, double deflection); + IFC_GEOM_API IfcUtil::IfcBaseClass* serialise(const std::string& schema_name, const TopoDS_Shape& shape, bool advanced); +} diff --git a/src/ifcwrap/IfcGeomWrapper.i b/src/ifcwrap/IfcGeomWrapper.i index df13b77d4a..f8342a5ef6 100644 --- a/src/ifcwrap/IfcGeomWrapper.i +++ b/src/ifcwrap/IfcGeomWrapper.i @@ -439,27 +439,25 @@ struct ShapeRTTI : public boost::static_visitor } %} -/* %inline %{ - IfcUtil::IfcBaseClass* serialise(const std::string& s, bool advanced=true) { - std::stringstream stream(s); + IfcUtil::IfcBaseClass* serialise(const std::string& schema_name, const std::string& shape_str, bool advanced=true) { + std::stringstream stream(shape_str); BRepTools_ShapeSet shapes; shapes.Read(stream); const TopoDS_Shape& shp = shapes.Shape(shapes.NbShapes()); - return IfcGeom::serialise(shp, advanced); + return IfcGeom::serialise(schema_name, shp, advanced); } - IfcUtil::IfcBaseClass* tesselate(const std::string& s, double d) { - std::stringstream stream(s); + IfcUtil::IfcBaseClass* tesselate(const std::string& schema_name, const std::string& shape_str, double d) { + std::stringstream stream(shape_str); BRepTools_ShapeSet shapes; shapes.Read(stream); const TopoDS_Shape& shp = shapes.Shape(shapes.NbShapes()); - return IfcGeom::tesselate(shp, d); + return IfcGeom::tesselate(schema_name, shp, d); } %} -*/ namespace IfcGeom { %template(iterator_single_precision) Iterator; diff --git a/src/ifcwrap/IfcPython.i b/src/ifcwrap/IfcPython.i index 76d666b219..a7f178da6c 100644 --- a/src/ifcwrap/IfcPython.i +++ b/src/ifcwrap/IfcPython.i @@ -71,8 +71,9 @@ %module ifcopenshell_wrapper %{ #include "../ifcgeom_schema_agnostic/IfcGeomIterator.h" + #include "../ifcgeom_schema_agnostic/Serialization.h" #include "../ifcgeom/IfcGeomTree.h" - + #include "../ifcparse/Ifc2x3.h" #include "../ifcparse/Ifc4.h" #include "../ifcparse/IfcBaseClass.h"