From 37e3a65ffb7989e0de071cf789583461f3d87e4f Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 29 Apr 2021 19:35:21 +1000 Subject: [PATCH] Decouple pset APIs from blenderbim namespace --- .../ifcopenshell/api/pset/add_pset.py | 1 - src/ifcopenshell-python/ifcopenshell/api/pset/data.py | 5 +++-- .../ifcopenshell/api/pset/edit_pset.py | 6 ++++-- .../ifcopenshell/api/pset/edit_qto.py | 6 ++++-- src/ifcopenshell-python/ifcopenshell/util/pset.py | 9 +++++++++ 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/pset/add_pset.py b/src/ifcopenshell-python/ifcopenshell/api/pset/add_pset.py index 48b5ef8eec..47e2fd31a4 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/pset/add_pset.py +++ b/src/ifcopenshell-python/ifcopenshell/api/pset/add_pset.py @@ -1,5 +1,4 @@ import ifcopenshell -import blenderbim.bim.schema # TODO: refactor class Usecase: diff --git a/src/ifcopenshell-python/ifcopenshell/api/pset/data.py b/src/ifcopenshell-python/ifcopenshell/api/pset/data.py index 9b1410fe77..d76a350360 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/pset/data.py +++ b/src/ifcopenshell-python/ifcopenshell/api/pset/data.py @@ -1,6 +1,6 @@ import ifcopenshell import ifcopenshell.util.attribute -import blenderbim.bim.schema # TODO: refactor elsewhere +import ifcopenshell.util.pset class Data: @@ -17,6 +17,7 @@ class Data: @classmethod def load(cls, file, product_id): cls._file = file + cls._psetqto = ifcopenshell.util.pset.get_template("IFC4") cls._schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(file.schema) if not file: return @@ -150,7 +151,7 @@ class Data: @classmethod def get_properties_from_template(cls, name): - template = blenderbim.bim.schema.ifc.psetqto.get_by_name(name) + template = cls._psetqto.get_by_name(name) if not template: return properties = [] diff --git a/src/ifcopenshell-python/ifcopenshell/api/pset/edit_pset.py b/src/ifcopenshell-python/ifcopenshell/api/pset/edit_pset.py index dd76185234..adf235b046 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/pset/edit_pset.py +++ b/src/ifcopenshell-python/ifcopenshell/api/pset/edit_pset.py @@ -1,4 +1,4 @@ -import blenderbim.bim.schema # TODO: refactor +import ifcopenshell class Usecase: @@ -20,7 +20,9 @@ class Usecase: self.settings["pset"].Name = self.settings["Name"] def load_pset_template(self): - self.pset_template = blenderbim.bim.schema.ifc.psetqto.get_by_name(self.settings["pset"].Name) + # TODO: add IFC2X3 PsetQto template support + self.psetqto = ifcopenshell.util.pset.get_template("IFC4") + self.pset_template = self.psetqto.get_by_name(self.settings["pset"].Name) def update_existing_properties(self): for prop in self.get_properties(): diff --git a/src/ifcopenshell-python/ifcopenshell/api/pset/edit_qto.py b/src/ifcopenshell-python/ifcopenshell/api/pset/edit_qto.py index bd43f646af..67650ef10b 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/pset/edit_qto.py +++ b/src/ifcopenshell-python/ifcopenshell/api/pset/edit_qto.py @@ -1,4 +1,4 @@ -import blenderbim.bim.schema # TODO: refactor +import ifcopenshell class Usecase: @@ -20,7 +20,9 @@ class Usecase: self.settings["qto"].Name = self.settings["Name"] def load_qto_template(self): - self.qto_template = blenderbim.bim.schema.ifc.psetqto.get_by_name(self.settings["qto"].Name) + # TODO: add IFC2X3 PsetQto template support + self.psetqto = ifcopenshell.util.pset.get_template("IFC4") + self.qto_template = self.psetqto.get_by_name(self.settings["qto"].Name) def update_existing_properties(self): for prop in self.settings["qto"].Quantities or []: diff --git a/src/ifcopenshell-python/ifcopenshell/util/pset.py b/src/ifcopenshell-python/ifcopenshell/util/pset.py index 43e0afc529..1f6bf735bb 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/pset.py +++ b/src/ifcopenshell-python/ifcopenshell/util/pset.py @@ -6,6 +6,15 @@ from typing import List, Generator, Optional import ifcopenshell from ifcopenshell.entity_instance import entity_instance +templates = {} + + +def get_template(schema): + global templates + if schema not in templates: + templates[schema] = PsetQto(schema) + return templates[schema] + class PsetQto: templates_path = {