From 77206cb761662c92c7facb78af423b5d9016359b Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 27 Jul 2021 09:42:42 +1000 Subject: [PATCH] Fix #1588. Profiles now auto recalculate cardinal points after editing. --- .../blenderbim/bim/module/model/profile.py | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/model/profile.py b/src/blenderbim/blenderbim/bim/module/model/profile.py index f98c91b894..e3e3d8ce06 100644 --- a/src/blenderbim/blenderbim/bim/module/model/profile.py +++ b/src/blenderbim/blenderbim/bim/module/model/profile.py @@ -22,8 +22,7 @@ def element_listener(element, obj): def mode_callback(obj, data): for obj in set(bpy.context.selected_objects + [bpy.context.active_object]): if ( - obj.mode != "EDIT" - or not obj.data + not obj.data or not isinstance(obj.data, (bpy.types.Mesh, bpy.types.Curve, bpy.types.TextCurve)) or not obj.BIMObjectProperties.ifc_definition_id or not bpy.context.scene.BIMProjectProperties.is_authoring @@ -33,11 +32,43 @@ def mode_callback(obj, data): parametric = ifcopenshell.util.element.get_psets(product).get("EPset_Parametric") if not parametric or parametric["Engine"] != "BlenderBIM.DumbProfile": return - IfcStore.edited_objs.add(obj) - bm = bmesh.from_edit_mesh(obj.data) - bmesh.ops.dissolve_limit(bm, angle_limit=pi / 180 * 1, verts=bm.verts, edges=bm.edges) - bmesh.update_edit_mesh(obj.data) - bm.free() + if obj.mode == "EDIT": + IfcStore.edited_objs.add(obj) + bm = bmesh.from_edit_mesh(obj.data) + bmesh.ops.dissolve_limit(bm, angle_limit=pi / 180 * 1, verts=bm.verts, edges=bm.edges) + bmesh.update_edit_mesh(obj.data) + bm.free() + else: + material_usage = ifcopenshell.util.element.get_material(product) + x, y = obj.dimensions[0:2] + if not material_usage.CardinalPoint: + new_origin = obj.matrix_world @ (Vector(obj.bound_box[0]) + (Vector((x, y, 0)) / 2)) + elif material_usage.CardinalPoint == 1: + new_origin = obj.matrix_world @ Vector(obj.bound_box[4]) + elif material_usage.CardinalPoint == 2: + new_origin = obj.matrix_world @ (Vector(obj.bound_box[0]) + (Vector((x, 0, 0)) / 2)) + elif material_usage.CardinalPoint == 3: + new_origin = obj.matrix_world @ Vector(obj.bound_box[0]) + elif material_usage.CardinalPoint == 4: + new_origin = obj.matrix_world @ (Vector(obj.bound_box[4]) + (Vector((0, y, 0)) / 2)) + elif material_usage.CardinalPoint == 5: + new_origin = obj.matrix_world @ (Vector(obj.bound_box[0]) + (Vector((x, y, 0)) / 2)) + elif material_usage.CardinalPoint == 6: + new_origin = obj.matrix_world @ (Vector(obj.bound_box[0]) + (Vector((0, y, 0)) / 2)) + elif material_usage.CardinalPoint == 7: + new_origin = obj.matrix_world @ Vector(obj.bound_box[7]) + elif material_usage.CardinalPoint == 8: + new_origin = obj.matrix_world @ (Vector(obj.bound_box[3]) + (Vector((x, 0, 0)) / 2)) + elif material_usage.CardinalPoint == 9: + new_origin = obj.matrix_world @ Vector(obj.bound_box[3]) + if (obj.matrix_world.translation - new_origin).length < 0.001: + return + obj.data.transform( + Matrix.Translation( + (obj.matrix_world.inverted().to_quaternion() @ (obj.matrix_world.translation - new_origin)) + ) + ) + obj.matrix_world.translation = new_origin def ensure_solid(usecase_path, ifc_file, settings):