Fix - Measure tool plane method now works with object snap.

This commit is contained in:
Bruno Perdigão
2024-11-08 16:05:22 -03:00
parent b416df538a
commit f08959aaa9
3 changed files with 50 additions and 3 deletions
@@ -41,6 +41,10 @@ def transparent_color(color, alpha=0.1):
color[3] = alpha
return color
def highlight_color(color, alpha=0.1):
color = [i + (1 - i) * 0.5 for i in color]
return color
class ProfileDecorator:
installed = None
@@ -628,17 +632,48 @@ class PolylineDecorator:
# Point related to the mouse
mouse_point = [Vector((snap_prop.x, snap_prop.y, snap_prop.z))]
# Plane Method or Default Container
default_container_elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
projection_point = []
if self.tool_state and self.tool_state.use_default_container:
if self.tool_state.plane_method:
plane_origin = self.tool_state.plane_origin
axis1 = None
axis2 = None
if self.tool_state.plane_method == "XY":
projection_point = [Vector((snap_prop.x, snap_prop.y, self.tool_state.plane_origin.z))]
axis1 = [(plane_origin.x - 10000, plane_origin.y, plane_origin.z), (plane_origin.x + 10000, plane_origin.y, plane_origin.z)]
axis2 = [(plane_origin.x, plane_origin.y - 10000, plane_origin.z), (plane_origin.x, plane_origin.y + 100000, plane_origin.z)]
axis_color1 = decorator_color_x_axis
axis_color2 = decorator_color_y_axis
elif self.tool_state.plane_method == "XZ":
projection_point = [Vector((snap_prop.x, self.tool_state.plane_origin.y, snap_prop.z))]
axis1 = [(plane_origin.x - 10000, plane_origin.y, plane_origin.z), (plane_origin.x + 10000, plane_origin.y, plane_origin.z)]
axis2 = [(plane_origin.x, plane_origin.y, plane_origin.z - 10000), (plane_origin.x, plane_origin.y, plane_origin.z + 100000)]
axis_color1 = decorator_color_x_axis
axis_color2 = decorator_color_z_axis
elif self.tool_state.plane_method == "YZ":
projection_point = [Vector((self.tool_state.plane_origin.x, snap_prop.y, snap_prop.z))]
axis1 = [(plane_origin.x, plane_origin.y - 10000, plane_origin.z), (plane_origin.x, plane_origin.y + 10000, plane_origin.z)]
axis2 = [(plane_origin.x, plane_origin.y, plane_origin.z - 10000), (plane_origin.x, plane_origin.y, plane_origin.z + 100000)]
axis_color1 = decorator_color_y_axis
axis_color2 = decorator_color_z_axis
else:
return
# When a point is above the plane it projects the point
# to the plane and creates a line
if snap_prop.snap_type != "Plane" and snap_prop.z != 0:
if snap_prop.snap_type != "Plane":
if self.tool_state.use_default_container and snap_prop.z != 0:
projection_point = [Vector((snap_prop.x, snap_prop.y, default_container_elevation))]
self.line_shader.uniform_float("lineWidth", 1.0)
projection_point = [Vector((snap_prop.x, snap_prop.y, default_container_elevation))]
self.draw_batch("POINTS", projection_point, decorator_color_unselected)
edges = [[0, 1]]
self.draw_batch("LINES", mouse_point + projection_point, decorator_color_unselected, edges)
if axis1 and axis2:
self.line_shader.uniform_float("lineWidth", 1.5)
self.draw_batch("LINES", axis1, highlight_color(axis_color1), [(0, 1)])
self.draw_batch("LINES", axis2, highlight_color(axis_color2), [(0, 1)])
# Create polyline with selected points
polyline_data = context.scene.BIMPolylineProperties.insertion_polyline
+10
View File
@@ -85,6 +85,7 @@ class Polyline(bonsai.core.tool.Polyline):
# angle_axis_end: Vector
axis_method: str = None
plane_method: str = None
plane_origin: Vector = Vector((0.0, 0.0, 0.0))
instructions: str = """TAB: Cycle Input
M: Modify Snap Point
C: Close
@@ -467,6 +468,15 @@ class Polyline(bonsai.core.tool.Polyline):
if tool_state and tool_state.use_default_container:
z = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
# Lock one dimension when in plane method
if tool_state.plane_origin:
if tool_state.plane_method == "XY":
z = tool_state.plane_origin.z
elif tool_state.plane_method == "XZ":
y = tool_state.plane_origin.y
elif tool_state.plane_method == "YZ":
x = tool_state.plane_origin.x
if x is None and y is None:
x = snap_vertex.x
y = snap_vertex.y
+2
View File
@@ -404,6 +404,8 @@ class Snap(bonsai.core.tool.Snap):
elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
plane_origin, plane_normal = select_plane_method()
tool_state.plane_origin = plane_origin # This will be used along with plane method
intersection = tool.Raycast.ray_cast_to_plane(context, event, plane_origin, plane_normal)
axis_start = None