fix assigning material usages / reloading reprs after c4ae9578e #4843

This commit is contained in:
Andrej730
2024-06-25 17:46:42 +05:00
parent ef9bbd8de6
commit f364643d7e
5 changed files with 33 additions and 3 deletions
@@ -515,6 +515,22 @@ def regenerate_profile_usage(usecase_path, ifc_file, settings):
def ensure_material_assigned(usecase_path: str, ifc_file: ifcopenshell.file, settings: dict[str, Any]) -> None:
elements = settings["products"]
material = settings.get("material")
if material:
assigned_material = settings["material"]
else:
material_type: ifcopenshell.util.element.MATERIAL_TYPE = settings["type"]
element = elements[0]
if material_type == "IfcMaterial":
assigned_material = ifcopenshell.util.element.get_material(element, should_inherit=False)
assert assigned_material # Type checker.
# 1) Material usages just inherit the style from the type material, so can't override it.
# 2) If type is Set and no material argument were provided, then Set was just created
# and not yet have any IfcMaterials.
elif material_type.endswith("Usage") or material_type.endswith("Set"):
return
elif material_type == "IfcMaterialList":
assert False, "Current assign_material implementation requires 'material' argument for IfcMaterialList."
for element in elements[:]:
if element.is_a("IfcElementType"):
@@ -526,6 +526,10 @@ class Geometry(blenderbim.core.tool.Geometry):
return False
own_material = ifcopenshell.util.element.get_material(element, should_inherit=False)
if own_material:
# Material usages just inherit the style from the type material, so can't override it.
if own_material.is_a("IfcMaterialUsageDefinition"):
return False
own_material = ifcopenshell.util.element.get_materials(element, should_inherit=False)[0]
inherited_style = cls.get_inherited_material_style(element)
style = tool.Material.get_style(own_material) if own_material else None
if inherited_style != style:
+1 -2
View File
@@ -1268,7 +1268,6 @@ class Model(blenderbim.core.tool.Model):
after material assignment or material unassignment.
"""
style_object = None
if assigned_material:
# NOTE: currently only IfcMaterials are supported
# for anyone else we just switch representation.
@@ -1340,7 +1339,7 @@ class Model(blenderbim.core.tool.Model):
occurrences = [
e
for e in ifcopenshell.util.element.get_types(element_type)
if not ifcopenshell.util.element.get_material(e, should_inherit=False)
if not tool.Geometry.has_material_style_override(e)
]
return occurrences
@@ -27,7 +27,7 @@ from typing import Optional, Union
def assign_material(
file: ifcopenshell.file,
products: list[ifcopenshell.entity_instance],
type: str = "IfcMaterial",
type: ifcopenshell.util.element.MATERIAL_TYPE = "IfcMaterial",
material: Optional[ifcopenshell.entity_instance] = None,
) -> Union[ifcopenshell.entity_instance, list[ifcopenshell.entity_instance], None]:
"""Assigns a material to the list of products
@@ -23,6 +23,17 @@ from typing import Any, Callable, Optional, Union, Literal, overload
from collections import namedtuple
MATERIAL_TYPE = Literal[
"IfcMaterial",
"IfcMaterialConstituentSet",
"IfcMaterialLayerSet",
"IfcMaterialLayerSetUsage",
"IfcMaterialProfileSet",
"IfcMaterialProfileSetUsage",
"IfcMaterialList",
]
def get_pset(
element: ifcopenshell.entity_instance,
name: str,