| 920 | |
| 921 | |
| 922 | class Material(Facet): |
| 923 | def __init__(self, value=None, uri=None, cardinality: Cardinality = "required", instructions=None): |
| 924 | self.parameters = ["value", "@uri", "@cardinality", "@instructions"] |
| 925 | self.applicability_templates = [ |
| 926 | "All data with a {value} material", |
| 927 | "All data with a material", |
| 928 | ] |
| 929 | self.requirement_templates = [ |
| 930 | "Shall have a material of {value}", |
| 931 | "Shall have a material", |
| 932 | ] |
| 933 | self.prohibited_templates = [ |
| 934 | "Shall not have a material of {value}", |
| 935 | "Shall not have a material", |
| 936 | ] |
| 937 | super().__init__(value, uri, cardinality, instructions) |
| 938 | |
| 939 | def filter( |
| 940 | self, ifc_file: ifcopenshell.file, elements: Optional[list[ifcopenshell.entity_instance]] |
| 941 | ) -> list[ifcopenshell.entity_instance]: |
| 942 | if isinstance(elements, list): |
| 943 | return super().filter(ifc_file, elements) |
| 944 | return ifc_file.by_type("IfcObjectDefinition") |
| 945 | |
| 946 | def __call__(self, inst: ifcopenshell.entity_instance, logger: Optional[Logger] = None) -> MaterialResult: |
| 947 | material = ifcopenshell.util.element.get_material(inst, should_skip_usage=True) |
| 948 | |
| 949 | is_pass = material is not None |
| 950 | reason = None |
| 951 | |
| 952 | if not is_pass: |
| 953 | if self.cardinality == "optional": |
| 954 | return MaterialResult(True) |
| 955 | reason = {"type": "NOVALUE"} |
| 956 | |
| 957 | if is_pass and self.value: |
| 958 | if material.is_a("IfcMaterial"): |
| 959 | values = {material.Name, getattr(material, "Category", None)} |
| 960 | elif material.is_a("IfcMaterialList"): |
| 961 | values = set() |
| 962 | for mat in material.Materials or []: |
| 963 | values.update([mat.Name, getattr(mat, "Category", None)]) |
| 964 | elif material.is_a("IfcMaterialLayerSet"): |
| 965 | values = {material.LayerSetName} |
| 966 | for item in material.MaterialLayers or []: |
| 967 | values.update( |
| 968 | [ |
| 969 | getattr(item, "Name", None), |
| 970 | getattr(item, "Category", None), |
| 971 | item.Material.Name, |
| 972 | getattr(item.Material, "Category", None), |
| 973 | ] |
| 974 | ) |
| 975 | elif material.is_a("IfcMaterialProfileSet"): |
| 976 | values = {material.Name} |
| 977 | for item in material.MaterialProfiles or []: |
| 978 | values.update( |
| 979 | [item.Name, item.Category, item.Material.Name, getattr(item.Material, "Category", None)] |
no outgoing calls