Files
IfcOpenShell/src/ifcgeom/Serialization/Serialization.cpp
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
3.2 KiB
C++
Raw Normal View History

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-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-08-08 07:42:45 +02:00
ifcopenshell::geom::opencascade_geometry_ifc_writer_registry& ifcopenshell::geom::opencascade_geometry_ifc_writer_registry_instance() {
2026-04-14 13:50:23 +02:00
static opencascade_geometry_ifc_writer_registry registry;
return registry;
}
2026-08-08 07:42:45 +02:00
void ifcopenshell::geom::opencascade_geometry_ifc_writer_registry::bind(const std::string& schema_name, serialise_fn serialise, tesselate_fn tesselate, const ifcopenshell::plugin::module& module) {
2026-04-14 13:50:23 +02:00
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-08-08 07:42:45 +02:00
express::base ifcopenshell::geom::opencascade_geometry_ifc_writer_registry::tesselate(ifcopenshell::file& f, const conversion_result_shape& 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-08-08 07:42:45 +02:00
express::base ifcopenshell::geom::opencascade_geometry_ifc_writer_registry::serialise(ifcopenshell::file& f, const conversion_result_shape& 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-08-08 07:42:45 +02:00
express::base ifcopenshell::geom::tesselate(ifcopenshell::file& f, const conversion_result_shape& shape, double deflection) {
2026-04-14 13:50:23 +02:00
return opencascade_geometry_ifc_writer_registry_instance().tesselate(f, shape, deflection);
}
2022-07-17 21:13:46 +02:00
2026-08-08 07:42:45 +02:00
express::base ifcopenshell::geom::serialise(ifcopenshell::file& f, const conversion_result_shape& shape, bool advanced) {
2026-04-14 13:50:23 +02:00
return opencascade_geometry_ifc_writer_registry_instance().serialise(f, shape, advanced);
}
2022-07-17 21:13:46 +02:00
2026-08-08 07:42:45 +02:00
express::base ifcopenshell::geom::tesselate(ifcopenshell::file& f, const TopoDS_Shape& shape, double deflection) {
ifcopenshell::geom::open_cascade_shape converted(shape);
2026-04-14 13:50:23 +02:00
return tesselate(f, converted, deflection);
}
2022-07-17 21:13:46 +02:00
2026-08-08 07:42:45 +02:00
express::base ifcopenshell::geom::serialise(ifcopenshell::file& f, const TopoDS_Shape& shape, bool advanced) {
ifcopenshell::geom::open_cascade_shape converted(shape);
2026-04-14 13:50:23 +02:00
return serialise(f, converted, advanced);
}