Changed decorator name to PolylineDecorator

This commit is contained in:
Bruno Perdigão
2024-08-17 20:29:50 -03:00
committed by Bruno Perdigão
parent 10616df494
commit ff203b2a13
4 changed files with 164 additions and 66 deletions
@@ -296,7 +296,7 @@ class ProfileDecorator:
return points, listEdg return points, listEdg
class WallPolylineDecorator: class PolylineDecorator:
is_installed = False is_installed = False
handlers = [] handlers = []
mouse_pos = None mouse_pos = None
+24 -25
View File
@@ -37,7 +37,7 @@ from bonsai.bim.ifc import IfcStore
from math import pi, sin, cos, degrees from math import pi, sin, cos, degrees
from mathutils import Vector, Matrix from mathutils import Vector, Matrix
from bonsai.bim.module.model.opening import FilledOpeningGenerator from bonsai.bim.module.model.opening import FilledOpeningGenerator
from bonsai.bim.module.model.decorator import WallPolylineDecorator from bonsai.bim.module.model.decorator import PolylineDecorator
from typing import Optional from typing import Optional
from lark import Lark, Transformer from lark import Lark, Transformer
@@ -487,13 +487,13 @@ class DrawPolylineWall(bpy.types.Operator):
self.report({"WARNING"}, "The number typed is not valid.") self.report({"WARNING"}, "The number typed is not valid.")
else: else:
if self.input_type in {"X", "Y"}: if self.input_type in {"X", "Y"}:
self.input_panel = WallPolylineDecorator.calculate_distance_and_angle(context, self.is_input_on) self.input_panel = PolylineDecorator.calculate_distance_and_angle(context, self.is_input_on)
elif self.input_type in {"D", "A"}: elif self.input_type in {"D", "A"}:
self.input_panel = WallPolylineDecorator.calculate_x_and_y(context) self.input_panel = PolylineDecorator.calculate_x_y_and_z(context)
self.input_panel[self.input_type] = self.number_output self.input_panel[self.input_type] = self.number_output
WallPolylineDecorator.set_input_panel(self.input_panel, self.input_type) PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Blender.update_viewport() tool.Blender.update_viewport()
# TODO This is creating a hack in generate function from DumbWallGenerator # TODO This is creating a hack in generate function from DumbWallGenerator
@@ -527,7 +527,7 @@ class DrawPolylineWall(bpy.types.Operator):
self.mousemove_count += 1 self.mousemove_count += 1
self.is_input_on = False self.is_input_on = False
self.input_type = "OFF" self.input_type = "OFF"
WallPolylineDecorator.set_input_panel(self.input_panel, self.input_type) PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Snap.clear_snaping_ref() tool.Snap.clear_snaping_ref()
tool.Blender.update_viewport() tool.Blender.update_viewport()
else: else:
@@ -540,32 +540,31 @@ class DrawPolylineWall(bpy.types.Operator):
if self.mousemove_count > 3: if self.mousemove_count > 3:
tool.Snap.snaping_movement(context, event, self.objs_2d_bbox) tool.Snap.snaping_movement(context, event, self.objs_2d_bbox)
WallPolylineDecorator.set_mouse_position(event) PolylineDecorator.set_mouse_position(event)
self.input_panel = WallPolylineDecorator.calculate_distance_and_angle(context, self.is_input_on) self.input_panel = PolylineDecorator.calculate_distance_and_angle(context, self.is_input_on)
tool.Blender.update_viewport() tool.Blender.update_viewport()
return {"RUNNING_MODAL"} return {"RUNNING_MODAL"}
if event.value == "RELEASE" and event.type == "BACK_SPACE":
tool.Snap.remove_last_polyline_point()
tool.Blender.update_viewport()
if event.value == "RELEASE" and event.type == "LEFTMOUSE": if event.value == "RELEASE" and event.type == "LEFTMOUSE":
tool.Snap.insert_polyline_point() tool.Snap.insert_polyline_point()
tool.Blender.update_viewport() tool.Blender.update_viewport()
if event.value == "PRESS" and event.type == "C": if event.value == "PRESS" and event.type == "C":
tool.Snap.close_polyline() tool.Snap.close_polyline()
WallPolylineDecorator.set_input_panel(self.input_panel, self.input_type) PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Blender.update_viewport() tool.Blender.update_viewport()
if not self.is_input_on:
if event.value == "RELEASE" and event.type == "BACK_SPACE":
tool.Snap.remove_last_polyline_point()
tool.Blender.update_viewport()
if self.is_input_on and event.value == "PRESS" and event.type == "TAB": if self.is_input_on and event.value == "PRESS" and event.type == "TAB":
self.recalculate_inputs(context) self.recalculate_inputs(context)
index = self.input_options.index(self.input_type) index = self.input_options.index(self.input_type)
size = len(self.input_options) size = len(self.input_options)
self.input_type = self.input_options[((index + 1) % size)] self.input_type = self.input_options[((index + 1) % size)]
self.number_input = [] self.number_input = []
WallPolylineDecorator.set_input_panel(self.input_panel, self.input_type) PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Blender.update_viewport() tool.Blender.update_viewport()
if not self.is_input_on and event.value == "RELEASE" and event.type == "TAB": if not self.is_input_on and event.value == "RELEASE" and event.type == "TAB":
@@ -573,7 +572,7 @@ class DrawPolylineWall(bpy.types.Operator):
self.is_input_on = True self.is_input_on = True
self.input_type = "X" self.input_type = "X"
self.number_input = [] self.number_input = []
WallPolylineDecorator.set_input_panel(self.input_panel, self.input_type) PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Blender.update_viewport() tool.Blender.update_viewport()
if not self.is_input_on and event.ascii in self.number_options: if not self.is_input_on and event.ascii in self.number_options:
@@ -581,7 +580,7 @@ class DrawPolylineWall(bpy.types.Operator):
self.is_input_on = True self.is_input_on = True
self.input_type = "D" self.input_type = "D"
self.number_input = [] self.number_input = []
WallPolylineDecorator.set_input_panel(self.input_panel, self.input_type) PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Blender.update_viewport() tool.Blender.update_viewport()
if event.value == "RELEASE" and event.type in self.input_options: if event.value == "RELEASE" and event.type in self.input_options:
@@ -589,7 +588,7 @@ class DrawPolylineWall(bpy.types.Operator):
self.is_input_on = True self.is_input_on = True
self.input_type = event.type self.input_type = event.type
self.number_input = [] self.number_input = []
WallPolylineDecorator.set_input_panel(self.input_panel, self.input_type) PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Blender.update_viewport() tool.Blender.update_viewport()
if self.input_type in self.input_options: if self.input_type in self.input_options:
@@ -603,7 +602,7 @@ class DrawPolylineWall(bpy.types.Operator):
self.number_input = self.number_input[:-1] self.number_input = self.number_input[:-1]
self.number_output = "".join(self.number_input) self.number_output = "".join(self.number_input)
self.input_panel[self.input_type] = self.number_output self.input_panel[self.input_type] = self.number_output
WallPolylineDecorator.set_input_panel(self.input_panel, self.input_type) PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Blender.update_viewport() tool.Blender.update_viewport()
else: else:
self.number_input.append(event.ascii) self.number_input.append(event.ascii)
@@ -645,11 +644,11 @@ class DrawPolylineWall(bpy.types.Operator):
if event.value == "RELEASE" and event.type in {"RIGHTMOUSE", "ESC"}: if event.value == "RELEASE" and event.type in {"RIGHTMOUSE", "ESC"}:
self.is_input_on = False self.is_input_on = False
self.input_type = "OFF" self.input_type = "OFF"
WallPolylineDecorator.set_input_panel(self.input_panel, self.input_type) PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Blender.update_viewport() tool.Blender.update_viewport()
else: else:
if event.value == "RELEASE" and event.type in {"RIGHTMOUSE", "ESC"}: if event.value == "RELEASE" and event.type in {"RIGHTMOUSE", "ESC"}:
WallPolylineDecorator.uninstall() PolylineDecorator.uninstall()
tool.Snap.clear_polyline() tool.Snap.clear_polyline()
tool.Blender.update_viewport() tool.Blender.update_viewport()
return {"CANCELLED"} return {"CANCELLED"}
@@ -658,17 +657,17 @@ class DrawPolylineWall(bpy.types.Operator):
def invoke(self, context, event): def invoke(self, context, event):
if context.space_data.type == "VIEW_3D": if context.space_data.type == "VIEW_3D":
WallPolylineDecorator.install(context) PolylineDecorator.install(context)
tool.Snap.set_use_default_container(True) tool.Snap.set_use_default_container(True)
WallPolylineDecorator.set_use_default_container(True) PolylineDecorator.set_use_default_container(True)
tool.Snap.set_snap_plane_method("XY") tool.Snap.set_snap_plane_method("XY")
WallPolylineDecorator.set_input_panel(self.input_panel, self.input_type) PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
self.visible_objs = tool.Raycast.get_visible_objects(context) self.visible_objs = tool.Raycast.get_visible_objects(context)
for obj in self.visible_objs: for obj in self.visible_objs:
self.objs_2d_bbox.append(tool.Raycast.get_objects_2d_bounding_boxes(context, obj)) self.objs_2d_bbox.append(tool.Raycast.get_objects_2d_bounding_boxes(context, obj))
tool.Snap.snaping_movement(context, event, self.objs_2d_bbox) tool.Snap.snaping_movement(context, event, self.objs_2d_bbox)
WallPolylineDecorator.set_mouse_position(event) PolylineDecorator.set_mouse_position(event)
self.input_panel = WallPolylineDecorator.calculate_distance_and_angle(context, self.is_input_on) self.input_panel = PolylineDecorator.calculate_distance_and_angle(context, self.is_input_on)
tool.Blender.update_viewport() tool.Blender.update_viewport()
context.window_manager.modal_handler_add(self) context.window_manager.modal_handler_add(self)
return {"RUNNING_MODAL"} return {"RUNNING_MODAL"}
+135 -36
View File
@@ -52,7 +52,7 @@ from bpy.app.handlers import persistent
from ifcopenshell.geom import ShapeElementType from ifcopenshell.geom import ShapeElementType
from bonsai.bim.module.project.data import LinksData from bonsai.bim.module.project.data import LinksData
from bonsai.bim.module.project.decorator import ProjectDecorator, ClippingPlaneDecorator from bonsai.bim.module.project.decorator import ProjectDecorator, ClippingPlaneDecorator
from bonsai.bim.module.model.decorator import WallPolylineDecorator from bonsai.bim.module.model.decorator import PolylineDecorator
from typing import Union from typing import Union
@@ -2311,78 +2311,177 @@ class MeasureTool(bpy.types.Operator):
self.input_options = ["X", "Y", "D", "A"] self.input_options = ["X", "Y", "D", "A"]
self.input_type = "OFF" self.input_type = "OFF"
self.input_value_xy = [None, None] self.input_value_xy = [None, None]
self.input_panel = {"X": "", "Y": "", "Z": "", "D": "", "A": ""} self.input_panel = {"X": "", "Y": "", "Z": "", "D": "", "A": "", "AREA": ""}
self.snap_angle = None self.snap_angle = None
def recalculate_inputs(self, context):
if self.number_input:
is_valid, self.number_output = tool.Snap.validate_input(self.number_output)
self.input_panel[self.input_type] = self.number_output
if not is_valid:
self.report({"WARNING"}, "The number typed is not valid.")
else:
if self.input_type in {"X", "Y", "Z"}:
self.input_panel = PolylineDecorator.calculate_distance_and_angle(context, self.is_input_on)
elif self.input_type in {"D", "A"}:
self.input_panel = PolylineDecorator.calculate_x_y_and_z(context)
self.input_panel[self.input_type] = self.number_output
PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Blender.update_viewport()
def modal(self, context, event): def modal(self, context, event):
if event.type == "MOUSEMOVE": if not self.is_input_on:
self.mousemove_count += 1 if event.type == "MOUSEMOVE":
self.input_type = "OFF" self.mousemove_count += 1
WallPolylineDecorator.set_input_panel(self.input_panel, self.input_type) self.is_input_on = False
tool.Blender.update_viewport() self.input_type = "OFF"
else: PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
self.mousemove_count = 0 tool.Snap.clear_snaping_ref()
tool.Blender.update_viewport()
else:
self.mousemove_count = 0
if self.mousemove_count == 2: if self.mousemove_count == 2:
self.objs_2d_bbox = [] self.objs_2d_bbox = []
for obj in self.visible_objs: for obj in self.visible_objs:
self.objs_2d_bbox.append(tool.Raycast.get_objects_2d_bounding_boxes(context, obj)) self.objs_2d_bbox.append(tool.Raycast.get_objects_2d_bounding_boxes(context, obj))
if self.mousemove_count > 3: if self.mousemove_count > 3:
tool.Snap.snaping_movement(context, event, self.objs_2d_bbox) tool.Snap.snaping_movement(context, event, self.objs_2d_bbox)
WallPolylineDecorator.set_mouse_position(event) PolylineDecorator.set_mouse_position(event)
self.input_panel = WallPolylineDecorator.calculate_distance_and_angle(context, False) self.input_panel = PolylineDecorator.calculate_distance_and_angle(context, self.is_input_on)
tool.Blender.update_viewport() PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
return {"RUNNING_MODAL"} self.input_panel = PolylineDecorator.calculate_area(context)
tool.Blender.update_viewport()
return {"RUNNING_MODAL"}
if event.type in {"MIDDLEMOUSE", "WHEELUPMOUSE", "WHEELDOWNMOUSE"}: if event.value == "RELEASE" and event.type == "BACK_SPACE":
return {"PASS_THROUGH"} tool.Snap.remove_last_polyline_point()
tool.Blender.update_viewport()
if event.value == "RELEASE" and event.type == "LEFTMOUSE": if event.value == "RELEASE" and event.type == "LEFTMOUSE":
tool.Snap.insert_polyline_point() tool.Snap.insert_polyline_point()
tool.Blender.update_viewport() tool.Blender.update_viewport()
if event.value == "RELEASE" and event.type == "BACK_SPACE": if event.value == "PRESS" and event.type == "C":
tool.Snap.remove_last_polyline_point() tool.Snap.close_polyline()
PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Blender.update_viewport()
if self.is_input_on and event.value == "PRESS" and event.type == "TAB":
self.recalculate_inputs(context)
index = self.input_options.index(self.input_type)
size = len(self.input_options)
self.input_type = self.input_options[((index + 1) % size)]
self.number_input = []
PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Blender.update_viewport()
if not self.is_input_on and event.value == "RELEASE" and event.type == "TAB":
self.recalculate_inputs(context)
self.is_input_on = True
self.input_type = "X"
self.number_input = []
PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Blender.update_viewport()
if not self.is_input_on and event.ascii in self.number_options:
self.recalculate_inputs(context)
self.is_input_on = True
self.input_type = "D"
self.number_input = []
PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Blender.update_viewport()
if event.value == "RELEASE" and event.type in self.input_options:
self.recalculate_inputs(context)
self.is_input_on = True
self.input_type = event.type
self.number_input = []
PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Blender.update_viewport()
if self.input_type in self.input_options:
if (event.ascii in self.number_options) or (event.value == "RELEASE" and event.type == "BACK_SPACE"):
if event.type == "BACK_SPACE":
if len(self.number_input) <= 1:
self.number_input = []
else:
self.number_input = self.number_input[:-1]
self.number_output = "".join(self.number_input)
self.input_panel[self.input_type] = self.number_output
PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Blender.update_viewport()
else:
self.number_input.append(event.ascii)
self.number_output = "".join(self.number_input)
if self.number_input:
self.input_panel[self.input_type] = self.number_output
PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Blender.update_viewport()
if self.is_input_on and event.value == "RELEASE" and event.type in {"RET", "NUMPAD_ENTER"}:
self.recalculate_inputs(context)
tool.Snap.insert_polyline_point(
float(self.input_panel["X"]), float(self.input_panel["Y"]), float(self.input_panel["Z"])
)
self.is_input_on = False
self.input_type = "OFF"
self.number_input = []
self.number_output = ""
PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Blender.update_viewport() tool.Blender.update_viewport()
if event.shift and event.type == "X": if event.shift and event.type == "X":
tool.Snap.set_use_default_container(False) tool.Snap.set_use_default_container(False)
WallPolylineDecorator.set_use_default_container(False) PolylineDecorator.set_use_default_container(False)
tool.Snap.set_snap_plane_method("YZ") tool.Snap.set_snap_plane_method("YZ")
if event.shift and event.type == "Y": if event.shift and event.type == "Y":
tool.Snap.set_use_default_container(False) tool.Snap.set_use_default_container(False)
WallPolylineDecorator.set_use_default_container(False) PolylineDecorator.set_use_default_container(False)
tool.Snap.set_snap_plane_method("XZ") tool.Snap.set_snap_plane_method("XZ")
if event.shift and event.type == "Z": if event.shift and event.type == "Z":
tool.Snap.set_use_default_container(False) tool.Snap.set_use_default_container(False)
WallPolylineDecorator.set_use_default_container(False) PolylineDecorator.set_use_default_container(False)
tool.Snap.set_snap_plane_method("XY") tool.Snap.set_snap_plane_method("XY")
if event.value == "RELEASE" and event.type in {"RIGHTMOUSE", "ESC"}: if event.type in {"MIDDLEMOUSE", "WHEELUPMOUSE", "WHEELDOWNMOUSE"}:
WallPolylineDecorator.uninstall() return {"PASS_THROUGH"}
tool.Snap.clear_polyline()
tool.Blender.update_viewport() if self.is_input_on:
return {"FINISHED"} if event.value == "RELEASE" and event.type in {"RIGHTMOUSE", "ESC"}:
self.is_input_on = False
self.input_type = "OFF"
PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
tool.Blender.update_viewport()
else:
if event.value == "RELEASE" and event.type in {"RIGHTMOUSE", "ESC"}:
PolylineDecorator.uninstall()
tool.Snap.clear_polyline()
tool.Blender.update_viewport()
return {"CANCELLED"}
return {"RUNNING_MODAL"} return {"RUNNING_MODAL"}
def invoke(self, context, event): def invoke(self, context, event):
if context.space_data.type == "VIEW_3D": if context.space_data.type == "VIEW_3D":
WallPolylineDecorator.install(context) PolylineDecorator.install(context)
tool.Snap.set_use_default_container(False) tool.Snap.set_use_default_container(False)
WallPolylineDecorator.set_use_default_container(False) PolylineDecorator.set_use_default_container(False)
tool.Snap.set_snap_plane_method("No Plane") tool.Snap.set_snap_plane_method("No Plane")
WallPolylineDecorator.set_input_panel(self.input_panel, self.input_type) PolylineDecorator.set_input_panel(self.input_panel, self.input_type)
self.visible_objs = tool.Raycast.get_visible_objects(context) self.visible_objs = tool.Raycast.get_visible_objects(context)
for obj in self.visible_objs: for obj in self.visible_objs:
self.objs_2d_bbox.append(tool.Raycast.get_objects_2d_bounding_boxes(context, obj)) self.objs_2d_bbox.append(tool.Raycast.get_objects_2d_bounding_boxes(context, obj))
tool.Snap.snaping_movement(context, event, self.objs_2d_bbox) tool.Snap.snaping_movement(context, event, self.objs_2d_bbox)
WallPolylineDecorator.set_mouse_position(event) PolylineDecorator.set_mouse_position(event)
self.input_panel = WallPolylineDecorator.calculate_distance_and_angle(context, self.is_input_on) self.input_panel = PolylineDecorator.calculate_distance_and_angle(context, self.is_input_on)
tool.Blender.update_viewport() tool.Blender.update_viewport()
context.window_manager.modal_handler_add(self) context.window_manager.modal_handler_add(self)
return {"RUNNING_MODAL"} return {"RUNNING_MODAL"}
+4 -4
View File
@@ -19,7 +19,7 @@
import bpy import bpy
import bonsai.core.tool import bonsai.core.tool
import bonsai.tool as tool import bonsai.tool as tool
from bonsai.bim.module.model.decorator import WallPolylineDecorator from bonsai.bim.module.model.decorator import PolylineDecorator
import math import math
import mathutils import mathutils
from mathutils import Matrix, Vector from mathutils import Matrix, Vector
@@ -222,7 +222,7 @@ class Snap(bonsai.core.tool.Snap):
pivot_axis = "X" pivot_axis = "X"
rectangle_data = create_axis_rectangle_data(last_point) rectangle_data = create_axis_rectangle_data(last_point)
WallPolylineDecorator.set_axis_rectangle(rectangle_data) PolylineDecorator.set_axis_rectangle(rectangle_data)
for axis in snap_axis: for axis in snap_axis:
rot_mat = Matrix.Rotation(math.radians(360 - axis), 3, pivot_axis) rot_mat = Matrix.Rotation(math.radians(360 - axis), 3, pivot_axis)
start, end = create_axis_line_data(rot_mat, last_point) start, end = create_axis_line_data(rot_mat, last_point)
@@ -230,7 +230,7 @@ class Snap(bonsai.core.tool.Snap):
proximity = rot_intersection.y proximity = rot_intersection.y
if cls.snap_plane_method == "XZ": if cls.snap_plane_method == "XZ":
proximity = rot_intersection.z proximity = rot_intersection.z
WallPolylineDecorator.set_angle_axis_line(start, end) PolylineDecorator.set_angle_axis_line(start, end)
if lock_axis: if lock_axis:
is_on_rot_axis = True is_on_rot_axis = True
else: else:
@@ -379,7 +379,7 @@ class Snap(bonsai.core.tool.Snap):
elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
plane_origin, plane_normal = select_plane_method() plane_origin, plane_normal = select_plane_method()
WallPolylineDecorator.set_plane(plane_origin, plane_normal) PolylineDecorator.set_plane(plane_origin, plane_normal)
intersection = tool.Raycast.ray_cast_to_plane(context, event, plane_origin, plane_normal) intersection = tool.Raycast.ray_cast_to_plane(context, event, plane_origin, plane_normal)
if cls.snap_plane_method in {"XY", "XZ", "YZ"}: if cls.snap_plane_method in {"XY", "XZ", "YZ"}: