From d1caa3242f58c86673c81928cbb13bdd3c0a6b51 Mon Sep 17 00:00:00 2001 From: Cyril Waechter Date: Tue, 30 Nov 2021 11:24:19 +0100 Subject: [PATCH] Refactor to usecase as asked in #1881 (#1907) --- .../bim/module/boundary/operator.py | 6 +++--- .../api/boundary/edit_attributes.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 src/ifcopenshell-python/ifcopenshell/api/boundary/edit_attributes.py diff --git a/src/blenderbim/blenderbim/bim/module/boundary/operator.py b/src/blenderbim/blenderbim/bim/module/boundary/operator.py index f40bb5b130..cda964bcb9 100644 --- a/src/blenderbim/blenderbim/bim/module/boundary/operator.py +++ b/src/blenderbim/blenderbim/bim/module/boundary/operator.py @@ -257,12 +257,12 @@ class EditBoundaryAttributes(bpy.types.Operator): def _execute(self, context): bprops = context.active_object.bim_boundary_properties boundary = tool.Ifc.get_entity(context.active_object) + attributes = dict() for ifc_attribute, blender_property in EDITABLE_ATTRIBUTES.items(): - if not hasattr(boundary, ifc_attribute): - continue obj = getattr(bprops, blender_property, None) entity = tool.Ifc.get_entity(obj) - setattr(boundary, ifc_attribute, entity) + attributes[blender_property] = entity + ifcopenshell.api.run("boundary.edit_attributes", tool.Ifc.get(), entity=boundary, **attributes) bpy.ops.bim.disable_editing_boundary() return {"FINISHED"} diff --git a/src/ifcopenshell-python/ifcopenshell/api/boundary/edit_attributes.py b/src/ifcopenshell-python/ifcopenshell/api/boundary/edit_attributes.py new file mode 100644 index 0000000000..77e8187394 --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/boundary/edit_attributes.py @@ -0,0 +1,19 @@ +class Usecase: + def __init__(self, file, **kwargs): + """location, axis and ref_direction defines the plane""" + self.file = file + self.entity: "IfcRelSpaceBoundary" + self.relating_space: "IfcSpace | IfcExternalSpatialElement" + self.related_building_element: "IfcElement" + self.parent_boundary: "IfcRelSpaceBoundary" = None + self.corresponding_boundary: "IfcRelSpaceBoundary" = None + for key, value in kwargs.items(): + setattr(self, key, value) + + def execute(self): + self.entity.RelatingSpace = self.relating_space + self.entity.RelatedBuildingElement = self.related_building_element + if hasattr(self.entity, "ParentBoundary"): + self.entity.ParentBoundary = self.parent_boundary + if hasattr(self.entity, "CorrespondingBoundary"): + self.entity.CorrespondingBoundary = self.corresponding_boundary