From ddaed9e93d8a930a6d0492828fe9153a2902f922 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 18 Feb 2022 17:10:38 +1100 Subject: [PATCH] Fix bug where psets were unable to be applied for specific predefined types --- src/ifcopenshell-python/ifcopenshell/util/pset.py | 13 ++++++++++--- src/ifcopenshell-python/test/util/test_pset.py | 12 ++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/pset.py b/src/ifcopenshell-python/ifcopenshell/util/pset.py index b097435a11..5a84caaef8 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/pset.py +++ b/src/ifcopenshell-python/ifcopenshell/util/pset.py @@ -63,7 +63,9 @@ class PsetQto: if qto_only: if not prop_set.Name.startswith("Qto_"): continue - if any_class or self.is_applicable(entity, prop_set.ApplicableEntity or "IfcRoot", predefined_type): + if any_class or self.is_applicable( + entity, prop_set.ApplicableEntity or "IfcRoot", predefined_type, prop_set.TemplateType + ): result.append(prop_set) return result @@ -72,7 +74,9 @@ class PsetQto: """Return names instead of objects for other use eg. enum""" return [prop_set.Name for prop_set in self.get_applicable(ifc_class, predefined_type, pset_only, qto_only)] - def is_applicable(self, entity: entity_instance, applicables: str, predefined_type="") -> bool: + def is_applicable( + self, entity: entity_instance, applicables: str, predefined_type="", template_type="NOTDEFINED" + ) -> bool: """applicables can have multiple possible patterns : IfcBoilerType (IfcClass) IfcBoilerType/STEAM (IfcClass/PREDEFINEDTYPE) @@ -85,7 +89,10 @@ class PsetQto: continue # Uncomment if usage found # applicable_perf_history = match.group(2) or match.group(4) - if predefined_type and predefined_type != match.group(3): + matched_type = match.group(3) + if matched_type and not predefined_type: + continue + elif matched_type and predefined_type != match.group(3): continue applicable_class = match.group(1) diff --git a/src/ifcopenshell-python/test/util/test_pset.py b/src/ifcopenshell-python/test/util/test_pset.py index ea1ed1ea70..99b1f3cb52 100644 --- a/src/ifcopenshell-python/test/util/test_pset.py +++ b/src/ifcopenshell-python/test/util/test_pset.py @@ -28,8 +28,16 @@ class TestPsetQto: def test_get_applicables(self): for i in range(1000): - assert len(self.pset_qto.get_applicable("IfcMaterial")) == 14 + assert len(self.pset_qto.get_applicable("IfcMaterial")) == 9 def test_get_applicables_names(self): for i in range(1000): - assert len(self.pset_qto.get_applicable_names("IfcMaterial")) == 14 + assert len(self.pset_qto.get_applicable_names("IfcMaterial")) == 9 + + def test_getting_applicables_for_a_specific_predefined_type(self): + names = self.pset_qto.get_applicable_names("IfcAudioVisualAppliance") + assert len(names) == 17 + assert "Pset_AudioVisualApplianceTypeAmplifier" not in names + names = self.pset_qto.get_applicable_names("IfcAudioVisualAppliance", predefined_type="AMPLIFIER") + assert "Pset_AudioVisualApplianceTypeAmplifier" in names + assert len(names) == 18