From a1d8fbdbe9d3b3e121db84a92d07d331ba8c5959 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Sat, 27 Jul 2024 15:25:07 +0500 Subject: [PATCH] Fix missing materials from sets #5093 #4832 Regression in ifcopenshell 0.8 - missing materials and styles from IfcMaterialProfileSets, IfcMaterialProfileSetUsages, IfcMaterialLayerSet. --- src/ifcgeom/mapping/mapping.cpp | 43 ++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/ifcgeom/mapping/mapping.cpp b/src/ifcgeom/mapping/mapping.cpp index 67e650b177..d9d140dc54 100644 --- a/src/ifcgeom/mapping/mapping.cpp +++ b/src/ifcgeom/mapping/mapping.cpp @@ -299,14 +299,45 @@ const IfcUtil::IfcBaseEntity* mapping::get_single_material_association(const Ifc single_material = associated_material->as(); // NB: Single-layer layersets are also considered, regardless of --enable-layerset-slicing, this // in accordance with other viewers. - if (!single_material && associated_material->as()) { - IfcSchema::IfcMaterialLayerSet* layerset = associated_material->as()->ForLayerSet(); - if (settings_.get().value ? layerset->MaterialLayers()->size() >= 1 : layerset->MaterialLayers()->size() == 1) { - IfcSchema::IfcMaterialLayer* layer = (*layerset->MaterialLayers()->begin()); - if (layer->Material()) { - single_material = layer->Material(); + if (!single_material) { + if (associated_material->as() || associated_material->as()) { + IfcSchema::IfcMaterialLayerSet* layerset; + if (auto *m = associated_material->as()) { + if (m->get("ForLayerSet")->isNull()) { + Logger::Warning("Missing ForLayerSet for:", m); + return nullptr; + } + layerset = m->ForLayerSet(); + } else { + layerset = associated_material->as(); + } + if (settings_.get().value ? layerset->MaterialLayers()->size() >= 1 : layerset->MaterialLayers()->size() == 1) { + IfcSchema::IfcMaterialLayer* layer = (*layerset->MaterialLayers()->begin()); + if (auto *m_ = layer->Material()) { + single_material = m_; + } } } +#ifdef SCHEMA_HAS_IfcMaterialProfileSet + if (associated_material->as() || associated_material->as()) { + IfcSchema::IfcMaterialProfileSet* profileset; + if (auto* m = associated_material->as()) { + if (m->get("ForProfileSet")->isNull()) { + Logger::Warning("Missing ForProfileSet for:", m); + return nullptr; + } + profileset = m->ForProfileSet(); + } else { + profileset = associated_material->as(); + } + if (settings_.get().value ? profileset->MaterialProfiles()->size() >= 1 : profileset->MaterialProfiles()->size() == 1) { + IfcSchema::IfcMaterialProfile* profile = (*profileset->MaterialProfiles()->begin()); + if (auto *m_ = profile->Material()) { + single_material = m_; + } + } + } +#endif } } }