This commit is contained in:
Andrej730
2025-02-04 17:37:48 +05:00
parent bd2c3a0ca1
commit ecd7282150
@@ -23,6 +23,7 @@ from logging import Logger
from collections import defaultdict from collections import defaultdict
from typing import List, Dict, Tuple, Optional from typing import List, Dict, Tuple, Optional
class Patcher: class Patcher:
""" """
Assigns fractions to material constituents based on their "width". Assigns fractions to material constituents based on their "width".
@@ -61,7 +62,7 @@ class Patcher:
# Get length unit from project # Get length unit from project
length_unit = ifcopenshell.util.unit.get_project_unit(self.file, "LENGTHUNIT") length_unit = ifcopenshell.util.unit.get_project_unit(self.file, "LENGTHUNIT")
for constituent_set in self.file.by_type('IfcMaterialConstituentSet'): for constituent_set in self.file.by_type("IfcMaterialConstituentSet"):
if not (constituents := constituent_set.MaterialConstituents): if not (constituents := constituent_set.MaterialConstituents):
continue continue
@@ -81,9 +82,7 @@ class Patcher:
continue continue
# Calculate constituent widths and total width # Calculate constituent widths and total width
constituent_widths, total_width = self.calculate_constituent_widths( constituent_widths, total_width = self.calculate_constituent_widths(constituents, elements, unit_scale)
constituents, elements, unit_scale
)
if not constituent_widths: if not constituent_widths:
continue continue
@@ -100,21 +99,27 @@ class Patcher:
def get_element_quantities(self, element: ifcopenshell.entity_instance) -> Dict[str, float]: def get_element_quantities(self, element: ifcopenshell.entity_instance) -> Dict[str, float]:
"""Get width quantities for an element.""" """Get width quantities for an element."""
qtos = [v for k,v in ifcopenshell.util.element.get_psets(element, qtos_only=True).items() qtos = [
if k.endswith("BaseQuantities")] v
for k, v in ifcopenshell.util.element.get_psets(element, qtos_only=True).items()
if k.endswith("BaseQuantities")
]
if qtos: if qtos:
return {k:v["properties"]["Width"] for k,v in qtos[0].items() return {
if isinstance(v,dict) and k: v["properties"]["Width"]
(v.get("Discrimination") or "").lower() == "layer" and for k, v in qtos[0].items()
v.get("properties",{}).get("Width", "") is not None} if isinstance(v, dict)
and (v.get("Discrimination") or "").lower() == "layer"
and v.get("properties", {}).get("Width", "") is not None
}
return {} return {}
def calculate_constituent_widths( def calculate_constituent_widths(
self, self,
constituents: List[ifcopenshell.entity_instance], constituents: List[ifcopenshell.entity_instance],
elements: set[ifcopenshell.entity_instance], elements: set[ifcopenshell.entity_instance],
unit_scale: float unit_scale: float,
) -> Tuple[Dict[ifcopenshell.entity_instance, float], float]: ) -> Tuple[Dict[ifcopenshell.entity_instance, float], float]:
"""Calculate the widths of constituents based on associated quantities.""" """Calculate the widths of constituents based on associated quantities."""
if not elements: if not elements:
return {}, 0.0 return {}, 0.0