Skip to content

Commit 301cdf6

Browse files
committed
Fix creating representation with inherited materials
It should be considered as inherited material can also have a style. Though occurrence's material is still prioritized.
1 parent 882e0a4 commit 301cdf6

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/ifcgeom/Converter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_represe
107107
bool material_style_applied = false;
108108

109109
auto single_material = mapping_->get_single_material_association(product);
110+
if (!single_material) {
111+
auto type_product = mapping_->get_product_type(product);
112+
if (type_product) {
113+
single_material = mapping_->get_single_material_association(type_product);
114+
}
115+
}
116+
110117
if (single_material) {
111118
auto s = taxonomy::cast<taxonomy::style>(mapping_->map(single_material));
112119
for (auto it = shapes.begin(); it != shapes.end(); ++it) {

src/ifcgeom/abstract_mapping.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ namespace geometry {
4141
virtual void initialize_settings() = 0;
4242
virtual bool get_layerset_information(const IfcUtil::IfcBaseInterface*, layerset_information&, int&) = 0;
4343
virtual bool get_wall_neighbours(const IfcUtil::IfcBaseInterface*, std::vector<endpoint_connection>&) = 0;
44+
virtual const IfcUtil::IfcBaseEntity* get_product_type(const IfcUtil::IfcBaseEntity*) = 0;
4445
virtual const IfcUtil::IfcBaseEntity* get_single_material_association(const IfcUtil::IfcBaseEntity*) = 0;
4546
virtual double get_length_unit() const = 0;
4647
virtual IfcUtil::IfcBaseEntity* representation_of(const IfcUtil::IfcBaseEntity* product) = 0;

src/ifcgeom/mapping/mapping.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,23 @@ void mapping::get_representations(std::vector<geometry_conversion_task>& tasks,
256256
}
257257
}
258258

259-
const IfcUtil::IfcBaseEntity* mapping::get_single_material_association(const IfcUtil::IfcBaseEntity* product_) {
259+
const IfcUtil::IfcBaseEntity* mapping::get_product_type(const IfcUtil::IfcBaseEntity* product_) {
260260
auto product = product_->as<IfcSchema::IfcProduct>();
261+
auto rels = product->IsTypedBy();
262+
for (auto it = rels->begin(); it != rels->end(); ++it) {
263+
auto rel = *it;
264+
// Avoid segfault if RelatingType is unset.
265+
if (rel->get("RelatingType")->isNull()){
266+
break;
267+
return nullptr;
268+
}
269+
return rel->RelatingType();
270+
}
271+
return nullptr;
272+
}
273+
274+
const IfcUtil::IfcBaseEntity* mapping::get_single_material_association(const IfcUtil::IfcBaseEntity* product_) {
275+
auto product = product_->as<IfcSchema::IfcObjectDefinition>();
261276
IfcSchema::IfcMaterial* single_material = 0;
262277
IfcSchema::IfcRelAssociatesMaterial::list::ptr associated_materials = product->HasAssociations()->as<IfcSchema::IfcRelAssociatesMaterial>();
263278
if (associated_materials->size() == 1) {

src/ifcgeom/mapping/mapping.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ namespace geometry {
4242
virtual double get_length_unit() const { return length_unit_; }
4343
virtual aggregate_of_instance::ptr find_openings(const IfcUtil::IfcBaseEntity*);
4444
virtual IfcUtil::IfcBaseEntity* representation_of(const IfcUtil::IfcBaseEntity* product);
45-
45+
46+
virtual const IfcUtil::IfcBaseEntity* get_product_type(const IfcUtil::IfcBaseEntity* product_);
4647
virtual const IfcUtil::IfcBaseEntity* get_single_material_association(const IfcUtil::IfcBaseEntity* product);
4748
IfcSchema::IfcRepresentation* representation_mapped_to(const IfcSchema::IfcRepresentation* representation);
4849
IfcSchema::IfcProduct::list::ptr products_represented_by(const IfcSchema::IfcRepresentation* representation, bool only_direct=false);

0 commit comments

Comments
 (0)