diff --git a/src/bonsai/bonsai/bim/module/model/wall.py b/src/bonsai/bonsai/bim/module/model/wall.py index dc84a37f3f..d881a52db3 100644 --- a/src/bonsai/bonsai/bim/module/model/wall.py +++ b/src/bonsai/bonsai/bim/module/model/wall.py @@ -296,23 +296,16 @@ class DrawPolylineWall(bpy.types.Operator, PolylineOperator): def __init__(self): super().__init__() + self.relating_type = None + relating_type_id = bpy.context.scene.BIMModelProperties.relating_type_id + if relating_type_id: + self.relating_type = tool.Ifc.get().by_id(int(relating_type_id)) def create_walls_from_polyline(self, context): - props = context.scene.BIMModelProperties - relating_type_id = props.relating_type_id - - if not relating_type_id: + if not self.relating_type: return {"FINISHED"} - self.container = None - self.container_obj = None - if container := tool.Root.get_default_container(): - self.container = container - self.container_obj = tool.Ifc.get_object(container) - - relating_type = tool.Ifc.get().by_id(int(relating_type_id)) - - walls, is_polyline_closed = DumbWallGenerator(relating_type).generate(True) + walls, is_polyline_closed = DumbWallGenerator(self.relating_type).generate(True) if walls: if is_polyline_closed: for wall1, wall2 in zip(walls, walls[1:] + [walls[0]]): @@ -322,6 +315,10 @@ class DrawPolylineWall(bpy.types.Operator, PolylineOperator): DumbWallJoiner().join_V(wall1["obj"], wall2["obj"]) def modal(self, context, event): + if not self.relating_type: + self.report({"WARNING"}, "You need to select a wall type.") + return {"FINISHED"} + PolylineDecorator.update(event, self.tool_state, self.input_ui, self.snapping_points[0]) tool.Blender.update_viewport() @@ -344,6 +341,7 @@ class DrawPolylineWall(bpy.types.Operator, PolylineOperator): self.create_walls_from_polyline(context) context.workspace.status_text_set(text=None) PolylineDecorator.uninstall() + context.scene.BIMPolylineProperties.product_preview.clear() tool.Snap.clear_polyline() tool.Blender.update_viewport() return {"FINISHED"} @@ -352,14 +350,13 @@ class DrawPolylineWall(bpy.types.Operator, PolylineOperator): self.handle_inserting_polyline(context, event) - if event.type in {"LEFTMOUSE", "RIGHTMOUSE", "ENTER", "NUMPAD_ENTER"}: - tool.Polyline.offset_polyline(context) - # tool.Polyline.create_wall_preview(context) - print(context.scene.BIMPolylineProperties.product_preview) + if event.type in {"LEFTMOUSE", "RIGHTMOUSE", "ENTER", "NUMPAD_ENTER", "BACK_SPACE"}: + tool.Polyline.create_wall_preview_vertices(context, self.relating_type) - result = self.handle_cancelation(context, event) - if result is not None: - return result + cancel = self.handle_cancelation(context, event) + if cancel is not None: + context.scene.BIMPolylineProperties.product_preview.clear() + return cancel return {"RUNNING_MODAL"} diff --git a/src/bonsai/bonsai/tool/cad.py b/src/bonsai/bonsai/tool/cad.py index 9cc7128366..b2ca966155 100644 --- a/src/bonsai/bonsai/tool/cad.py +++ b/src/bonsai/bonsai/tool/cad.py @@ -640,15 +640,12 @@ class Cad: verts = set() [verts.update(e.verts) for e in edges] - print("V", verts) - print("E", edges) rotation = Matrix.Rotation(math.pi / 2, 2, "Z") rotation_i = Matrix.Rotation(-math.pi / 2, 2, "Z") # Create loops from edges loop_edges = set(edges) - print("L1", loop_edges) loops = [] while loop_edges: edge = loop_edges.pop() @@ -668,7 +665,6 @@ class Cad: has_found_connected_edge = True loops.append(loop) - print("L2", loops) for loop in loops: all_verts = {v.index for e in loop for v in e.verts} possible_v1s = [] @@ -707,7 +703,6 @@ class Cad: v1 = start - print("V1", v1) new_verts = [] processed_verts = set() # [v0] --> v1 --> v2 @@ -742,7 +737,6 @@ class Cad: normals = [] v1co = (wp.inverted() @ mw @ v1.co).to_2d() - print("V1CO", v1co) if v2: v2co = (wp.inverted() @ mw @ v2.co).to_2d() direction = (v2co - v1co).normalized() @@ -774,11 +768,6 @@ class Cad: break v1 = v2 - print("INSIDE1", new_verts) - print("INSIDE2", new_verts) return new_verts - # [bm.edges.new((new_verts[i], new_verts[i + 1])) for i in range(len(new_verts) - 1)] - # if is_closed: - # bm.edges.new((new_verts[len(new_verts) - 1], new_verts[0])) diff --git a/src/bonsai/bonsai/tool/polyline.py b/src/bonsai/bonsai/tool/polyline.py index 3a9ef644c5..789afb10cf 100644 --- a/src/bonsai/bonsai/tool/polyline.py +++ b/src/bonsai/bonsai/tool/polyline.py @@ -23,8 +23,8 @@ import bonsai.tool as tool from bonsai.bim.module.drawing.helper import format_distance from dataclasses import dataclass from lark import Lark, Transformer -from math import radians -from mathutils import Vector +from math import degrees, radians, sin, cos +from mathutils import Vector from typing import Optional @@ -279,7 +279,7 @@ class Polyline(bonsai.core.tool.Polyline): return @classmethod - def offset_polyline(cls, context): + def create_wall_preview_vertices(cls, context, relating_type): vertices = [] polyline_data = context.scene.BIMPolylineProperties.polyline_point if len(polyline_data) < 2: @@ -297,37 +297,49 @@ class Polyline(bonsai.core.tool.Polyline): # bm.edges.ensure_lookup_table() bm.verts.index_update() bm.edges.index_update() - print("LEN", len(vertices), len(bm.verts), len(polyline_data)) - new_verts = tool.Cad.offset_edges(bm, .15) # TODO Change to Wall Thickness - print("NV", new_verts) + # Get thickness from object type + layers = tool.Model.get_material_layer_parameters(relating_type) + if not layers["thickness"]: + return + thickness = layers['thickness'] + + height = float(context.scene.BIMModelProperties.extrusion_depth) + rl = float(context.scene.BIMModelProperties.rl1) + x_angle = float(context.scene.BIMModelProperties.x_angle) + height = height * (1 / cos(x_angle)) + direction = Vector((0.0, sin(x_angle), cos(x_angle))) + scaled_direction = direction * height + + new_verts = tool.Cad.offset_edges(bm, thickness) if new_verts is not None: context.scene.BIMPolylineProperties.product_preview.clear() for v in vertices: prop = context.scene.BIMPolylineProperties.product_preview.add() prop.x = v.x prop.y = v.y - prop.z = v.z + prop.z = v.z + rl for v in new_verts[::-1]: prop = context.scene.BIMPolylineProperties.product_preview.add() prop.x = v.co.x prop.y = v.co.y - prop.z = v.co.z + prop.z = v.co.z + rl - for v in vertices: + for i, v in enumerate(vertices): + new_v = v + scaled_direction prop = context.scene.BIMPolylineProperties.product_preview.add() - prop.x = v.x - prop.y = v.y - prop.z = 3 # TODO Change to Wall Height + prop.x = new_v.x + prop.y = new_v.y + prop.z = new_v.z + rl for v in new_verts[::-1]: + new_v = Vector((v.co.x, v.co.y, v.co.z)) + scaled_direction prop = context.scene.BIMPolylineProperties.product_preview.add() - prop.x = v.co.x - prop.y = v.co.y - prop.z = 3 # TODO Change to Wall Height - # return new_verts + prop.x = new_v.x + prop.y = new_v.y + prop.z = new_v.z + rl @classmethod