From 9e383959c8f227356ff64d0cc89216558d93bc31 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 10 Feb 2023 16:58:36 +0500 Subject: [PATCH] door black formatting --- .../blenderbim/bim/module/model/door.py | 106 ++++++++---------- .../api/geometry/add_door_representation.py | 54 ++++----- 2 files changed, 76 insertions(+), 84 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/model/door.py b/src/blenderbim/blenderbim/bim/module/model/door.py index fc9ec47319..e367e91787 100644 --- a/src/blenderbim/blenderbim/bim/module/model/door.py +++ b/src/blenderbim/blenderbim/bim/module/model/door.py @@ -86,7 +86,7 @@ def update_door_modifier_representation(context): representation_data["context"] = ifc_context model_representation = ifcopenshell.api.run("geometry.add_door_representation", ifc_file, **representation_data) replace_ifc_representation_for_object(ifc_file, ifc_context, obj, model_representation) - + # PLAN_VIEW representation ifc_context = get_ifc_context_or_create(ifc_file, "Plan", "Body", "PLAN_VIEW") representation_data["context"] = ifc_context @@ -109,81 +109,79 @@ def update_door_modifier_representation(context): def bm_sort_out_geom(geom_data): - geom_dict = { - 'verts': [], - 'edges': [], - 'faces': [] - } + geom_dict = {"verts": [], "edges": [], "faces": []} for el in geom_data: if isinstance(el, BMVert): - geom_dict['verts'].append(el) + geom_dict["verts"].append(el) elif isinstance(el, BMFace): - geom_dict['faces'].append(el) + geom_dict["faces"].append(el) else: - geom_dict['edges'].append(el) + geom_dict["edges"].append(el) return geom_dict -def bm_mirror(bm, verts, - mirror_axes: Vector = V(1,0,0).freeze(), - mirror_point: Vector = V(0,0,0).freeze(), - create_copy=False): - +def bm_mirror( + bm, verts, mirror_axes: Vector = V(1, 0, 0).freeze(), mirror_point: Vector = V(0, 0, 0).freeze(), create_copy=False +): matrix = Matrix.Translation(mirror_point) for i, v in enumerate(mirror_axes): if not v: continue - mirror_axis = V(0,0,0) + mirror_axis = V(0, 0, 0) mirror_axis[i] = 1.0 matrix = matrix @ Matrix.Scale(-1, 4, mirror_axis) matrix = matrix @ Matrix.Translation(-mirror_point) - # `bmesh.ops.mirror` has no option to mirror existing geometry without creating new + # `bmesh.ops.mirror` has no option to mirror existing geometry without creating new # and matrix kind of work diffrently than transform so I chose `bmesh.ops.transform` if create_copy: faces = set() - for v in verts: faces.update(v.link_faces) + for v in verts: + faces.update(v.link_faces) duplicated = bmesh.ops.duplicate(bm, geom=list(faces)) - verts = bm_sort_out_geom(duplicated['geom'])['verts'] + verts = bm_sort_out_geom(duplicated["geom"])["verts"] bmesh.ops.transform(bm, verts=verts, matrix=matrix, space=Matrix.Identity(4)) return verts def create_bm_extruded_profile( - bm, points, edges=None, faces=None, - position: Vector = V(0,0,0).freeze(), - magnitude=1.0, - extrusion_vector: Vector = V(0,0,1).freeze() - ): + bm, + points, + edges=None, + faces=None, + position: Vector = V(0, 0, 0).freeze(), + magnitude=1.0, + extrusion_vector: Vector = V(0, 0, 1).freeze(), +): bm.verts.index_update() bm.edges.index_update() bm.faces.ensure_lookup_table() if not edges: last_point = len(points) - 1 - edges = [(i, i+1) for i in range(last_point)] + edges = [(i, i + 1) for i in range(last_point)] edges.append((last_point, 0)) new_verts = [bm.verts.new(v) for v in points] new_edges = [bm.edges.new([new_verts[vi] for vi in edge]) for edge in edges] if not faces: - new_faces = bmesh.ops.contextual_create(bm, geom=new_edges)['faces'] + new_faces = bmesh.ops.contextual_create(bm, geom=new_edges)["faces"] else: new_faces = [bm.faces.new([new_verts[vi] for vi in face]) for face in faces] extruded = bmesh.ops.extrude_face_region(bm, geom=new_faces) extrusion_vector = extrusion_vector * magnitude - extruded_verts = bm_sort_out_geom(extruded['geom'])['verts'] + extruded_verts = bm_sort_out_geom(extruded["geom"])["verts"] bmesh.ops.translate(bm, vec=extrusion_vector, verts=extruded_verts) bmesh.ops.translate(bm, vec=position, verts=new_verts + extruded_verts) return new_verts + extruded_verts -def create_bm_door_lining(bm, size: Vector, thickness: Vector, position:Vector=V(0,0,0).freeze()): +def create_bm_door_lining(bm, size: Vector, thickness: Vector, position: Vector = V(0, 0, 0).freeze()): """`thickness` of the profile is defined as list in the following order: `(SIDE, TOP)` `thickness` can be also defined just as 1 float value. @@ -197,14 +195,14 @@ def create_bm_door_lining(bm, size: Vector, thickness: Vector, position:Vector=V width, depth, height = size verts = [ - (0, [width - th_side, 0.0, height-th_up]), + (0, [width - th_side, 0.0, height - th_up]), (1, [0.0, 0.0, height]), - (2, [th_side, 0.0, height-th_up]), + (2, [th_side, 0.0, height - th_up]), (3, [0.0, 0.0, 0.0]), (4, [width - th_side, 0.0, 0.0]), (5, [width, 0.0, height]), (6, [th_side, 0.0, 0.0]), - (7, [width, 0.0, 0.0]) + (7, [width, 0.0, 0.0]), ] edges = [ @@ -289,9 +287,8 @@ def update_door_modifier_bmesh(context): # handle dimensions (hardcoded) handle_size = V(120, 40, 20) * 0.001 * si_conversion - handle_offset = V(60, 0, 1000) * 0.001 * si_conversion # to the handle center - handle_center_offset = V(handle_size.y/2, 0, handle_size.z)/2 - + handle_offset = V(60, 0, 1000) * 0.001 * si_conversion # to the handle center + handle_center_offset = V(handle_size.y / 2, 0, handle_size.z) / 2 if transfom_offset: panel_height = transfom_offset + transom_thickness - lining_to_panel_offset_x - threshold_thickness @@ -319,13 +316,13 @@ def update_door_modifier_bmesh(context): casing_verts = [] if not lining_offset and casing_thickness: casing_wall_overlap = max(casing_thickness - lining_thickness_default, 0) - casing_size = V(overall_width + casing_wall_overlap*2, casing_depth, overall_height+casing_wall_overlap) + casing_size = V(overall_width + casing_wall_overlap * 2, casing_depth, overall_height + casing_wall_overlap) casing_position = V(-casing_wall_overlap, -casing_depth, 0) outer_casing_verts = create_bm_door_lining(bm, casing_size, casing_thickness, casing_position) inner_casing_thickness = [ - casing_thickness-panel_lining_overlap_x, - casing_thickness-panel_top_lining_overlap_x + casing_thickness - panel_lining_overlap_x, + casing_thickness - panel_top_lining_overlap_x, ] inner_casing_position = V(-casing_wall_overlap, lining_depth, 0) inner_casing_verts = create_bm_door_lining(bm, casing_size, inner_casing_thickness, inner_casing_position) @@ -343,28 +340,28 @@ def update_door_modifier_bmesh(context): V(0, 0, 0), V(0, -handle_size.y, 0), V(handle_size.x, -handle_size.y, 0), - V(handle_size.x, -handle_size.y/2, 0), - V(handle_size.y/2, -handle_size.y/2, 0), - V(handle_size.y/2, 0, 0), + V(handle_size.x, -handle_size.y / 2, 0), + V(handle_size.y / 2, -handle_size.y / 2, 0), + V(handle_size.y / 2, 0, 0), ] handle_position = panel_position + handle_offset - handle_center_offset - door_handle_verts = create_bm_extruded_profile(bm, handle_points, - magnitude=handle_size.z, - position=handle_position) + door_handle_verts = create_bm_extruded_profile(bm, handle_points, magnitude=handle_size.z, position=handle_position) door_handles_verts.extend(door_handle_verts) - if door_type == 'SINGLE_SWING_LEFT': - bm_mirror(bm, door_handle_verts, - mirror_axes=V(1,0,0), - mirror_point=panel_position + V(panel_size.x/2, 0, 0)) + if door_type == "SINGLE_SWING_LEFT": + bm_mirror( + bm, door_handle_verts, mirror_axes=V(1, 0, 0), mirror_point=panel_position + V(panel_size.x / 2, 0, 0) + ) - door_handle_mirrored_verts = bm_mirror(bm, door_handle_verts, - mirror_axes=V(0, 1, 0), - mirror_point=handle_position + V(0, panel_size.y/2, 0), - create_copy=True) + door_handle_mirrored_verts = bm_mirror( + bm, + door_handle_verts, + mirror_axes=V(0, 1, 0), + mirror_point=handle_position + V(0, panel_size.y / 2, 0), + create_copy=True, + ) door_handles_verts.extend(door_handle_mirrored_verts) - # add on top window if not transom_thickness: window_lining_verts = [] @@ -422,12 +419,7 @@ class BIM_OT_add_door(Operator): obj.location = spawn_location body_context = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Body", "MODEL_VIEW") element = blenderbim.core.root.assign_class( - tool.Ifc, - tool.Collector, - tool.Root, - obj=obj, - ifc_class="IfcDoor", - should_add_representation=False + tool.Ifc, tool.Collector, tool.Root, obj=obj, ifc_class="IfcDoor", should_add_representation=False ) element.PredefinedType = "DOOR" diff --git a/src/ifcopenshell-python/ifcopenshell/api/geometry/add_door_representation.py b/src/ifcopenshell-python/ifcopenshell/api/geometry/add_door_representation.py index 01271b3e74..8a322b7bc4 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/geometry/add_door_representation.py +++ b/src/ifcopenshell-python/ifcopenshell/api/geometry/add_door_representation.py @@ -25,7 +25,7 @@ import collections def create_ifc_door_lining( - builder: ShapeBuilder, size: Vector, thickness: Vector, position: Vector = V(0,0,0).freeze() + builder: ShapeBuilder, size: Vector, thickness: Vector, position: Vector = V(0, 0, 0).freeze() ): """`thickness` of the profile is defined as list in the following order: `(SIDE, TOP)` @@ -42,21 +42,21 @@ def create_ifc_door_lining( V(size.x, 0.0, size.z), V(size.x, 0.0, 0.0), V(size.x - th_side, 0.0, 0.0), - V(size.x - th_side, 0.0, size.z-th_up), - V(th_side, 0.0, size.z-th_up), + V(size.x - th_side, 0.0, size.z - th_up), + V(th_side, 0.0, size.z - th_up), V(th_side, 0.0, 0.0), ] door_lining = builder.polyline(points, closed=True) - door_lining = builder.extrude(door_lining, size.y, extrusion_vector=V(0,1,0)) + door_lining = builder.extrude(door_lining, size.y, extrusion_vector=V(0, 1, 0)) builder.translate(door_lining, position) return door_lining -def create_ifc_box(builder: ShapeBuilder, size: Vector, position: Vector = V(0,0,0).freeze()): +def create_ifc_box(builder: ShapeBuilder, size: Vector, position: Vector = V(0, 0, 0).freeze()): rect = builder.rectangle(size.xy) - box = builder.extrude(rect, size.z, position=position, extrusion_vector=V(0,0,1)) + box = builder.extrude(rect, size.z, position=position, extrusion_vector=V(0, 0, 1)) return box @@ -182,8 +182,8 @@ class Usecase: # handle dimensions (hardcoded) handle_size = self.convert_si_to_unit(V(120, 40, 20) * 0.001) - handle_offset = self.convert_si_to_unit(V(60, 0, 1000) * 0.001) # to the handle center - handle_center_offset = V(handle_size.y/2, 0, handle_size.z)/2 + handle_offset = self.convert_si_to_unit(V(60, 0, 1000) * 0.001) # to the handle center + handle_center_offset = V(handle_size.y / 2, 0, handle_size.z) / 2 if transfom_offset: panel_height = transfom_offset + transom_thickness - lining_to_panel_offset_x - threshold_thickness @@ -197,8 +197,9 @@ class Usecase: lining_thickness = [lining_thickness_default, top_lining_thickness] def l_shape_check(lining_thickness): - return lining_to_panel_offset_y_full < lining_depth \ - and any(lining_to_panel_offset_x < th for th in lining_thickness) + return lining_to_panel_offset_y_full < lining_depth and any( + lining_to_panel_offset_x < th for th in lining_thickness + ) # create 2d representation if self.settings["context"].TargetView == "PLAN_VIEW": @@ -236,7 +237,7 @@ class Usecase: builder.translate([semicircle, door], V(lining_to_panel_offset_x, lining_depth)) if door_type == "SINGLE_SWING_RIGHT": - builder.mirror([semicircle, door], mirror_axes=V(1,0), mirror_point=V(overall_width/2, 0)) + builder.mirror([semicircle, door], mirror_axes=V(1, 0), mirror_point=V(overall_width / 2, 0)) representation_2d = builder.get_representation(self.settings["context"], items_2d) return representation_2d @@ -275,7 +276,7 @@ class Usecase: casing_items = [] if not lining_offset and casing_thickness: casing_wall_overlap = max(casing_thickness - lining_thickness_default, 0) - casing_size = V(overall_width + casing_wall_overlap*2, casing_depth, overall_height + casing_wall_overlap) + casing_size = V(overall_width + casing_wall_overlap * 2, casing_depth, overall_height + casing_wall_overlap) casing_position = V(-casing_wall_overlap, -casing_depth, 0) outer_casing = create_ifc_door_lining(builder, casing_size, casing_thickness, casing_position) casing_items.append(outer_casing) @@ -285,9 +286,7 @@ class Usecase: casing_thickness - panel_top_lining_overlap_x, ] inner_casing_position = V(-casing_wall_overlap, lining_depth, 0) - inner_casing = create_ifc_door_lining( - builder, casing_size, inner_casing_thickness, inner_casing_position - ) + inner_casing = create_ifc_door_lining(builder, casing_size, inner_casing_thickness, inner_casing_position) casing_items.append(inner_casing) # add door panel @@ -301,9 +300,9 @@ class Usecase: V(0, 0), V(0, -handle_size.y), V(handle_size.x, -handle_size.y), - V(handle_size.x, -handle_size.y/2), - V(handle_size.y/2, -handle_size.y/2), - V(handle_size.y/2, 0), + V(handle_size.x, -handle_size.y / 2), + V(handle_size.y / 2, -handle_size.y / 2), + V(handle_size.y / 2, 0), ] handle_polyline = builder.polyline(handle_points, closed=True) @@ -312,15 +311,14 @@ class Usecase: door_handle = builder.extrude(handle_polyline, handle_size.z, position=handle_position) door_handles_items.append(door_handle) - if door_type == 'SINGLE_SWING_LEFT': - builder.mirror(door_handle, mirror_axes=V(1,0), - mirror_point=panel_position.xy + V(panel_size.x/2, 0)) + if door_type == "SINGLE_SWING_LEFT": + builder.mirror(door_handle, mirror_axes=V(1, 0), mirror_point=panel_position.xy + V(panel_size.x / 2, 0)) - door_handle_mirrored = builder.mirror(door_handle, mirror_axes=V(0, 1), - mirror_point=handle_position.xy + V(0, panel_size.y/2), - create_copy=True) + door_handle_mirrored = builder.mirror( + door_handle, mirror_axes=V(0, 1), mirror_point=handle_position.xy + V(0, panel_size.y / 2), create_copy=True + ) door_handles_items.append(door_handle_mirrored) - + # add on top window if not transom_thickness: window_lining_items = [] @@ -344,7 +342,9 @@ class Usecase: window_position, ) - lining_offset_items = lining_items + panel_items + window_lining_items + frame_items + glass_items + door_handles_items + lining_offset_items = ( + lining_items + panel_items + window_lining_items + frame_items + glass_items + door_handles_items + ) builder.translate(lining_offset_items, V(0, lining_offset, 0)) output_items = lining_offset_items + threshold_items + casing_items @@ -355,5 +355,5 @@ class Usecase: def convert_si_to_unit(self, value): si_conversion = 1 / self.settings["unit_scale"] if isinstance(value, Vector): - return V(*[i*si_conversion for i in value]) + return V(*[i * si_conversion for i in value]) return value * si_conversion