mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 17:57:02 +00:00
@@ -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:
|
def ensure_material_assigned(usecase_path: str, ifc_file: ifcopenshell.file, settings: dict[str, Any]) -> None:
|
||||||
elements = settings["products"]
|
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[:]:
|
for element in elements[:]:
|
||||||
if element.is_a("IfcElementType"):
|
if element.is_a("IfcElementType"):
|
||||||
|
|||||||
@@ -526,6 +526,10 @@ class Geometry(blenderbim.core.tool.Geometry):
|
|||||||
return False
|
return False
|
||||||
own_material = ifcopenshell.util.element.get_material(element, should_inherit=False)
|
own_material = ifcopenshell.util.element.get_material(element, should_inherit=False)
|
||||||
if own_material:
|
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)
|
inherited_style = cls.get_inherited_material_style(element)
|
||||||
style = tool.Material.get_style(own_material) if own_material else None
|
style = tool.Material.get_style(own_material) if own_material else None
|
||||||
if inherited_style != style:
|
if inherited_style != style:
|
||||||
|
|||||||
@@ -1268,7 +1268,6 @@ class Model(blenderbim.core.tool.Model):
|
|||||||
after material assignment or material unassignment.
|
after material assignment or material unassignment.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
style_object = None
|
|
||||||
if assigned_material:
|
if assigned_material:
|
||||||
# NOTE: currently only IfcMaterials are supported
|
# NOTE: currently only IfcMaterials are supported
|
||||||
# for anyone else we just switch representation.
|
# for anyone else we just switch representation.
|
||||||
@@ -1340,7 +1339,7 @@ class Model(blenderbim.core.tool.Model):
|
|||||||
occurrences = [
|
occurrences = [
|
||||||
e
|
e
|
||||||
for e in ifcopenshell.util.element.get_types(element_type)
|
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
|
return occurrences
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ from typing import Optional, Union
|
|||||||
def assign_material(
|
def assign_material(
|
||||||
file: ifcopenshell.file,
|
file: ifcopenshell.file,
|
||||||
products: list[ifcopenshell.entity_instance],
|
products: list[ifcopenshell.entity_instance],
|
||||||
type: str = "IfcMaterial",
|
type: ifcopenshell.util.element.MATERIAL_TYPE = "IfcMaterial",
|
||||||
material: Optional[ifcopenshell.entity_instance] = None,
|
material: Optional[ifcopenshell.entity_instance] = None,
|
||||||
) -> Union[ifcopenshell.entity_instance, list[ifcopenshell.entity_instance], None]:
|
) -> Union[ifcopenshell.entity_instance, list[ifcopenshell.entity_instance], None]:
|
||||||
"""Assigns a material to the list of products
|
"""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
|
from collections import namedtuple
|
||||||
|
|
||||||
|
|
||||||
|
MATERIAL_TYPE = Literal[
|
||||||
|
"IfcMaterial",
|
||||||
|
"IfcMaterialConstituentSet",
|
||||||
|
"IfcMaterialLayerSet",
|
||||||
|
"IfcMaterialLayerSetUsage",
|
||||||
|
"IfcMaterialProfileSet",
|
||||||
|
"IfcMaterialProfileSetUsage",
|
||||||
|
"IfcMaterialList",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_pset(
|
def get_pset(
|
||||||
element: ifcopenshell.entity_instance,
|
element: ifcopenshell.entity_instance,
|
||||||
name: str,
|
name: str,
|
||||||
|
|||||||
Reference in New Issue
Block a user