Files
IfcOpenShell/src/ifcgeom_schema_agnostic/Serialization.cpp
T

30 lines
1.4 KiB
C++
Raw Normal View History

2017-12-22 17:37:58 +01:00
#include "Serialization.h"
#include <boost/algorithm/string/case_conv.hpp>
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 <typename Fn, typename T>
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);
2018-08-13 11:43:28 +02:00
if (schema_name_lower == "ifc2x3") {
2017-12-22 17:37:58 +01:00
return fn1(shape, t);
2018-08-13 11:43:28 +02:00
} else if (schema_name_lower == "ifc4") {
2017-12-22 17:37:58 +01:00
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);
}