From 8bf8cdf51b32c5f599c2633a8167b9c0bf502a24 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Wed, 8 Apr 2020 15:04:17 +0200 Subject: [PATCH] Guarantee schemas are initialized for serialization and tesselation --- src/ifcgeom/IfcGeomSerialisation.cpp | 15 +++++++++------ src/ifcgeom_schema_agnostic/Serialization.cpp | 6 ++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/ifcgeom/IfcGeomSerialisation.cpp b/src/ifcgeom/IfcGeomSerialisation.cpp index 181b4b3fc8..d35e3c366c 100644 --- a/src/ifcgeom/IfcGeomSerialisation.cpp +++ b/src/ifcgeom/IfcGeomSerialisation.cpp @@ -33,9 +33,12 @@ int convert_to_ifc(const TopoDS_Vertex& v, IfcSchema::IfcCartesianPoint*& p, boo template <> int convert_to_ifc(const TopoDS_Vertex& v, IfcSchema::IfcVertex*& vertex, bool advanced) { IfcSchema::IfcCartesianPoint* p; - convert_to_ifc(v, p, advanced); - vertex = new IfcSchema::IfcVertexPoint(p); - return 1; + if (convert_to_ifc(v, p, advanced)) { + vertex = new IfcSchema::IfcVertexPoint(p); + return 1; + } else { + return 0; + } } template <> @@ -71,7 +74,7 @@ void opencascade_array_to_vector2(T& t, std::vector< std::vector >& u) { } } -#ifdef USE_IFC4 +#ifdef SCHEMA_HAS_IfcRationalBSplineSurfaceWithKnots IfcSchema::IfcKnotType::Value opencascade_knotspec_to_ifc(GeomAbs_BSplKnotDistribution bspline_knot_spec) { IfcSchema::IfcKnotType::Value knot_spec = IfcSchema::IfcKnotType::IfcKnotType_UNSPECIFIED; if (bspline_knot_spec == GeomAbs_Uniform) { @@ -123,7 +126,7 @@ int convert_to_ifc(const Handle_Geom_Curve& c, IfcSchema::IfcCurve*& curve, bool return 1; } -#ifdef USE_IFC4 +#ifdef SCHEMA_HAS_IfcRationalBSplineSurfaceWithKnots else if (c->DynamicType() == STANDARD_TYPE(Geom_BSplineCurve)) { Handle_Geom_BSplineCurve bspline = Handle_Geom_BSplineCurve::DownCast(c); @@ -206,7 +209,7 @@ int convert_to_ifc(const Handle_Geom_Surface& s, IfcSchema::IfcSurface*& surface surface = new IfcSchema::IfcPlane(place); return 1; } -#ifdef USE_IFC4 +#ifdef SCHEMA_HAS_IfcRationalBSplineSurfaceWithKnots else if (s->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) { Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast(s); IfcSchema::IfcAxis2Placement3D* place; diff --git a/src/ifcgeom_schema_agnostic/Serialization.cpp b/src/ifcgeom_schema_agnostic/Serialization.cpp index 1e618c5f06..ef04e7c0f6 100644 --- a/src/ifcgeom_schema_agnostic/Serialization.cpp +++ b/src/ifcgeom_schema_agnostic/Serialization.cpp @@ -11,7 +11,13 @@ namespace IfcGeom { template IfcUtil::IfcBaseClass* execute_based_on_schema(Fn fn1, Fn fn2, const std::string& schema_name, const TopoDS_Shape& shape, T t) { + // @todo an ugly hack to guarantee schemas are initialised. + try { + IfcParse::schema_by_name("IFC2X3"); + } catch (IfcParse::IfcException&) {} + const std::string schema_name_lower = boost::to_lower_copy(schema_name); + if (schema_name_lower == "ifc2x3") { return fn1(shape, t); } else if (schema_name_lower == "ifc4") {