2017-12-22 17:37:58 +01:00
|
|
|
#include "Serialization.h"
|
2026-04-17 11:24:09 +02:00
|
|
|
#include "opencascade_geometry_ifc_writer_plugin.h"
|
2017-12-22 17:37:58 +01:00
|
|
|
|
2026-04-14 13:50:23 +02:00
|
|
|
#include "../../ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h"
|
|
|
|
|
#include "../../ifcparse/file.h"
|
2017-12-22 17:37:58 +01:00
|
|
|
|
2026-04-14 13:50:23 +02:00
|
|
|
#include <boost/algorithm/string/case_conv.hpp>
|
2026-01-04 10:40:02 +01:00
|
|
|
|
2026-04-14 13:50:23 +02:00
|
|
|
namespace {
|
|
|
|
|
std::string writer_schema_key(const std::string& schema_name) {
|
|
|
|
|
return boost::to_upper_copy(schema_name);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-04 10:40:02 +01:00
|
|
|
|
2026-04-14 13:50:23 +02:00
|
|
|
IfcGeom::opencascade_geometry_ifc_writer_registry& IfcGeom::opencascade_geometry_ifc_writer_registry_instance() {
|
|
|
|
|
static opencascade_geometry_ifc_writer_registry registry;
|
|
|
|
|
return registry;
|
|
|
|
|
}
|
2021-05-11 22:29:16 +02:00
|
|
|
|
2026-04-14 13:50:23 +02:00
|
|
|
void IfcGeom::opencascade_geometry_ifc_writer_registry::bind(const std::string& schema_name, serialise_fn serialise, tesselate_fn tesselate, const ifcopenshell::plugin::module& module) {
|
|
|
|
|
entry entry;
|
|
|
|
|
entry.serialise_ = serialise;
|
|
|
|
|
entry.tesselate_ = tesselate;
|
2026-04-17 11:24:09 +02:00
|
|
|
entry.module_ = module.meta().id.empty() ? ifcopenshell::plugin::module(opencascade_geometry_ifc_writer_plugin_metadata(schema_name)) : module;
|
2026-04-14 13:50:23 +02:00
|
|
|
entries_[writer_schema_key(schema_name)] = entry;
|
2017-12-22 17:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
2026-04-14 13:50:23 +02:00
|
|
|
express::Base IfcGeom::opencascade_geometry_ifc_writer_registry::tesselate(ifcopenshell::file& f, const ConversionResultShape& shape, double deflection) const {
|
2026-05-06 21:17:25 +02:00
|
|
|
auto iter = entries_.find(writer_schema_key(f.schema()->name()));
|
|
|
|
|
if (iter == entries_.end()) {
|
|
|
|
|
load_opencascade_geometry_ifc_writer_plugin(const_cast<opencascade_geometry_ifc_writer_registry&>(*this), f.schema()->name());
|
|
|
|
|
iter = entries_.find(writer_schema_key(f.schema()->name()));
|
|
|
|
|
}
|
2026-04-14 13:50:23 +02:00
|
|
|
if (iter == entries_.end()) {
|
|
|
|
|
throw ifcopenshell::exception("No geometry serialization available for " + f.schema()->name());
|
|
|
|
|
}
|
|
|
|
|
return iter->second.tesselate_(f, shape, deflection);
|
|
|
|
|
}
|
2017-12-22 17:37:58 +01:00
|
|
|
|
2026-04-14 13:50:23 +02:00
|
|
|
express::Base IfcGeom::opencascade_geometry_ifc_writer_registry::serialise(ifcopenshell::file& f, const ConversionResultShape& shape, bool advanced) const {
|
2026-05-06 21:17:25 +02:00
|
|
|
auto iter = entries_.find(writer_schema_key(f.schema()->name()));
|
|
|
|
|
if (iter == entries_.end()) {
|
|
|
|
|
load_opencascade_geometry_ifc_writer_plugin(const_cast<opencascade_geometry_ifc_writer_registry&>(*this), f.schema()->name());
|
|
|
|
|
iter = entries_.find(writer_schema_key(f.schema()->name()));
|
|
|
|
|
}
|
2026-04-14 13:50:23 +02:00
|
|
|
if (iter == entries_.end()) {
|
|
|
|
|
throw ifcopenshell::exception("No geometry serialization available for " + f.schema()->name());
|
|
|
|
|
}
|
|
|
|
|
return iter->second.serialise_(f, shape, advanced);
|
|
|
|
|
}
|
2026-01-04 10:40:02 +01:00
|
|
|
|
2026-04-14 13:50:23 +02:00
|
|
|
express::Base IfcGeom::tesselate(ifcopenshell::file& f, const ConversionResultShape& shape, double deflection) {
|
|
|
|
|
return opencascade_geometry_ifc_writer_registry_instance().tesselate(f, shape, deflection);
|
|
|
|
|
}
|
2022-07-17 21:13:46 +02:00
|
|
|
|
2026-04-14 13:50:23 +02:00
|
|
|
express::Base IfcGeom::serialise(ifcopenshell::file& f, const ConversionResultShape& shape, bool advanced) {
|
|
|
|
|
return opencascade_geometry_ifc_writer_registry_instance().serialise(f, shape, advanced);
|
|
|
|
|
}
|
2022-07-17 21:13:46 +02:00
|
|
|
|
2026-04-14 13:50:23 +02:00
|
|
|
express::Base IfcGeom::tesselate(ifcopenshell::file& f, const TopoDS_Shape& shape, double deflection) {
|
|
|
|
|
ifcopenshell::geometry::OpenCascadeShape converted(shape);
|
|
|
|
|
return tesselate(f, converted, deflection);
|
|
|
|
|
}
|
2022-07-17 21:13:46 +02:00
|
|
|
|
2026-04-14 13:50:23 +02:00
|
|
|
express::Base IfcGeom::serialise(ifcopenshell::file& f, const TopoDS_Shape& shape, bool advanced) {
|
|
|
|
|
ifcopenshell::geometry::OpenCascadeShape converted(shape);
|
|
|
|
|
return serialise(f, converted, advanced);
|
|
|
|
|
}
|