| 317 | } |
| 318 | |
| 319 | const IfcUtil::IfcBaseEntity* mapping::get_single_material_association(const IfcUtil::IfcBaseEntity* product_) { |
| 320 | auto product = product_->as<IfcSchema::IfcObjectDefinition>(); |
| 321 | IfcSchema::IfcMaterial* single_material = 0; |
| 322 | IfcSchema::IfcRelAssociatesMaterial::list::ptr associated_materials = product->HasAssociations()->as<IfcSchema::IfcRelAssociatesMaterial>(); |
| 323 | if (associated_materials->size() == 1) { |
| 324 | IfcSchema::IfcMaterialSelect* associated_material = nullptr; |
| 325 | |
| 326 | try { |
| 327 | associated_material = (*associated_materials->begin())->RelatingMaterial(); |
| 328 | } catch(IfcParse::IfcException& e) { |
| 329 | Logger::Error(e.what()); |
| 330 | } |
| 331 | |
| 332 | if (associated_material) { |
| 333 | single_material = associated_material->as<IfcSchema::IfcMaterial>(); |
| 334 | // NB: Single-layer layersets are also considered, regardless of --enable-layerset-slicing, this |
| 335 | // in accordance with other viewers. |
| 336 | if (!single_material) { |
| 337 | if (associated_material->as<IfcSchema::IfcMaterialLayerSetUsage>() || associated_material->as<IfcSchema::IfcMaterialLayerSet>()) { |
| 338 | IfcSchema::IfcMaterialLayerSet* layerset; |
| 339 | if (auto *m = associated_material->as<IfcSchema::IfcMaterialLayerSetUsage>()) { |
| 340 | if (m->get("ForLayerSet").isNull()) { |
| 341 | Logger::Warning("Missing ForLayerSet for:", m); |
| 342 | return nullptr; |
| 343 | } |
| 344 | layerset = m->ForLayerSet(); |
| 345 | } else { |
| 346 | layerset = associated_material->as<IfcSchema::IfcMaterialLayerSet>(); |
| 347 | } |
| 348 | if (settings_.get<settings::LayersetFirst>().value ? layerset->MaterialLayers()->size() >= 1 : layerset->MaterialLayers()->size() == 1) { |
| 349 | IfcSchema::IfcMaterialLayer* layer = (*layerset->MaterialLayers()->begin()); |
| 350 | if (auto *m_ = layer->Material()) { |
| 351 | single_material = m_; |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | #ifdef SCHEMA_HAS_IfcMaterialProfileSet |
| 356 | if (associated_material->as<IfcSchema::IfcMaterialProfileSetUsage>() || associated_material->as<IfcSchema::IfcMaterialProfileSet>()) { |
| 357 | IfcSchema::IfcMaterialProfileSet* profileset; |
| 358 | if (auto* m = associated_material->as<IfcSchema::IfcMaterialProfileSetUsage>()) { |
| 359 | if (m->get("ForProfileSet").isNull()) { |
| 360 | Logger::Warning("Missing ForProfileSet for:", m); |
| 361 | return nullptr; |
| 362 | } |
| 363 | profileset = m->ForProfileSet(); |
| 364 | } else { |
| 365 | profileset = associated_material->as<IfcSchema::IfcMaterialProfileSet>(); |
| 366 | } |
| 367 | if (settings_.get<settings::LayersetFirst>().value ? profileset->MaterialProfiles()->size() >= 1 : profileset->MaterialProfiles()->size() == 1) { |
| 368 | IfcSchema::IfcMaterialProfile* profile = (*profileset->MaterialProfiles()->begin()); |
| 369 | if (auto *m_ = profile->Material()) { |
| 370 | single_material = m_; |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | #endif |
| 375 | |
| 376 | #ifdef SCHEMA_HAS_IfcMaterialConstituentSet |