Files
IfcOpenShell/src/ifcgeom/abstract_mapping.cpp
T

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

57 lines
2.1 KiB
C++
Raw Normal View History

2019-08-16 17:40:13 +02:00
#include "abstract_mapping.h"
2026-03-31 15:32:36 +02:00
#include "../ifcparse/file.h"
2026-04-17 11:24:09 +02:00
#include "../ifcgeom/mapping_plugin.h"
2019-08-16 17:40:13 +02:00
2026-04-17 11:24:09 +02:00
#include <boost/algorithm/string/case_conv.hpp>
2023-03-21 20:15:01 +01:00
2026-04-14 13:50:23 +02:00
namespace {
std::string mapping_key(const std::string& schema_name) {
return boost::to_lower_copy(schema_name);
}
2019-08-16 17:40:13 +02:00
}
2026-04-14 13:50:23 +02:00
ifcopenshell::geometry::impl::mapping_registry& ifcopenshell::geometry::impl::mapping_registry_instance() {
static mapping_registry registry;
return registry;
2019-08-16 17:40:13 +02:00
}
2026-04-14 13:50:23 +02:00
void ifcopenshell::geometry::impl::mapping_registry::bind(const std::string& schema_name, ifcopenshell::geometry::impl::mapping_fn fn, const plugin::module& module) {
auto& entry = entries_[mapping_key(schema_name)];
entry.fn_ = fn;
2026-04-17 11:24:09 +02:00
entry.module_ = module.meta().id.empty() ? plugin::module(mapping_plugin_metadata(schema_name)) : module;
2026-04-14 13:50:23 +02:00
}
ifcopenshell::geometry::abstract_mapping* ifcopenshell::geometry::impl::mapping_registry::construct(ifcopenshell::file* file, Settings& s) {
2019-08-16 17:40:13 +02:00
const std::string schema_name_lower = boost::to_lower_copy(file->schema()->name());
2026-05-06 21:17:25 +02:00
auto it = entries_.find(schema_name_lower);
if (it == entries_.end()) {
load_mapping_plugin(*this, file->schema()->name());
it = entries_.find(schema_name_lower);
}
2026-04-14 13:50:23 +02:00
if (it == entries_.end()) {
2026-03-31 15:32:36 +02:00
throw ifcopenshell::exception("No geometry mapping registered for " + schema_name_lower);
2019-08-16 17:40:13 +02:00
}
2026-04-14 13:50:23 +02:00
auto new_mapping = it->second.fn_(file, s);
2023-03-21 20:15:01 +01:00
new_mapping->initialize_settings();
return new_mapping;
2019-08-16 17:40:13 +02:00
}
2026-04-14 13:50:23 +02:00
ifcopenshell::geometry::impl::MappingFactoryImplementation& ifcopenshell::geometry::impl::mapping_implementations() {
static MappingFactoryImplementation impl;
return impl;
}
ifcopenshell::geometry::impl::MappingFactoryImplementation::MappingFactoryImplementation() {
mapping_registry_instance();
}
void ifcopenshell::geometry::impl::MappingFactoryImplementation::bind(const std::string& schema_name, ifcopenshell::geometry::impl::mapping_fn fn) {
2026-04-17 11:24:09 +02:00
mapping_registry_instance().bind(schema_name, fn, plugin::module(mapping_plugin_metadata(schema_name)));
2026-04-14 13:50:23 +02:00
}
ifcopenshell::geometry::abstract_mapping* ifcopenshell::geometry::impl::MappingFactoryImplementation::construct(ifcopenshell::file* file, Settings& s) {
return mapping_registry_instance().construct(file, s);
}