From 35221ed77294927038e5c28a70d5f0ddc3ed3f93 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 11 Sep 2024 11:56:21 +0500 Subject: [PATCH] AbstractKernel::convert to use upgrade to edge as a fallback --- src/ifcgeom/AbstractKernel.cpp | 18 ++++++++++++++++-- src/ifcgeom/taxonomy.cpp | 4 ++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/ifcgeom/AbstractKernel.cpp b/src/ifcgeom/AbstractKernel.cpp index a82e7c1641..4a59c24521 100644 --- a/src/ifcgeom/AbstractKernel.cpp +++ b/src/ifcgeom/AbstractKernel.cpp @@ -29,8 +29,22 @@ bool ifcopenshell::geometry::kernels::AbstractKernel::convert(const taxonomy::pt try { return dispatch_conversion<0>::dispatch(this, item->kind(), item, results); } catch (std::exception& e) { - Logger::Error(e, item->instance); - return false; + std::string prev_exception; + try { + prev_exception = std::string(e.what()); + // Try to upgrade. Works for circles and ellipses. + auto concrete_item = ifcopenshell::geometry::taxonomy::template dcast(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) { + Logger::Error(prev_exception + " Conversion for upgraded element failed with: " + std::string(e.what()), item->instance); + return false; + } catch (...) { + return false; + } } catch (...) { // @todo we can't log OCCT exceptions here, can we do some reraising to solve this? return false; diff --git a/src/ifcgeom/taxonomy.cpp b/src/ifcgeom/taxonomy.cpp index 0c78b84601..818802dd2d 100644 --- a/src/ifcgeom/taxonomy.cpp +++ b/src/ifcgeom/taxonomy.cpp @@ -624,12 +624,16 @@ boost::optional ifcopenshell::geometry::taxonomy::curve_to_edge_upgra edge_ = make(); if (circle_) { (*edge_)->basis = circle_; + (*edge_)->instance = circle_->instance; } else if (ellipse_) { (*edge_)->basis = ellipse_; + (*edge_)->instance = ellipse_->instance; } else if (line_) { (*edge_)->basis = line_; + (*edge_)->instance = line_->instance; } else if (bspline_curve_) { (*edge_)->basis = bspline_curve_; + (*edge_)->instance = bspline_curve_->instance; } if (circle_ || ellipse_) {