mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 02:07:36 +00:00
AbstractKernel::convert - more generic approach
This commit is contained in:
@@ -29,16 +29,9 @@ bool ifcopenshell::geometry::kernels::AbstractKernel::convert(const taxonomy::pt
|
|||||||
try {
|
try {
|
||||||
return dispatch_conversion<0>::dispatch(this, item->kind(), item, results);
|
return dispatch_conversion<0>::dispatch(this, item->kind(), item, results);
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
std::string prev_exception;
|
std::string prev_exception = std::string(e.what());
|
||||||
try {
|
try {
|
||||||
prev_exception = std::string(e.what());
|
return dispatch_with_upgrade<0>::dispatch(this, item, results);
|
||||||
// Try to upgrade. Works for circles and ellipses.
|
|
||||||
auto concrete_item = ifcopenshell::geometry::taxonomy::template dcast<ifcopenshell::geometry::taxonomy::edge>(item);
|
|
||||||
if (concrete_item) {
|
|
||||||
return convert_impl(concrete_item, results);
|
|
||||||
}
|
|
||||||
Logger::Error(prev_exception + " Upgrade also didn't worked.", item->instance);
|
|
||||||
return false;
|
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
Logger::Error(prev_exception + " Conversion for upgraded element failed with: " + std::string(e.what()), item->instance);
|
Logger::Error(prev_exception + " Conversion for upgraded element failed with: " + std::string(e.what()), item->instance);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -102,6 +102,26 @@ namespace {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
struct dispatch_with_upgrade {
|
||||||
|
static bool dispatch(ifcopenshell::geometry::kernels::AbstractKernel* kernel, const ifcopenshell::geometry::taxonomy::ptr item, IfcGeom::ConversionResults& results) {
|
||||||
|
auto concrete_item = ifcopenshell::geometry::taxonomy::template dcast<ifcopenshell::geometry::taxonomy::type_by_kind::type<N>>(item);
|
||||||
|
if (concrete_item) {
|
||||||
|
return kernel->convert_impl(concrete_item, results);
|
||||||
|
} else {
|
||||||
|
return dispatch_with_upgrade<N + 1>::dispatch(kernel, item, results);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct dispatch_with_upgrade<ifcopenshell::geometry::taxonomy::type_by_kind::max> {
|
||||||
|
static bool dispatch(ifcopenshell::geometry::kernels::AbstractKernel*, const ifcopenshell::geometry::taxonomy::ptr item, IfcGeom::ConversionResults&) {
|
||||||
|
Logger::Error("No conversion with upgrade for " + std::to_string(item->kind()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <class T, class Tuple>
|
template <class T, class Tuple>
|
||||||
struct TupleTypeIndex;
|
struct TupleTypeIndex;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user