Added 'Backspace' event to remove last polyline point

This commit is contained in:
Bruno Perdigão
2024-07-30 20:59:32 -03:00
committed by Bruno Perdigão
parent 10035662dd
commit 61641acf56
2 changed files with 24 additions and 13 deletions
@@ -298,6 +298,7 @@ class DrawPolylineWall(bpy.types.Operator):
def __init__(self):
self.mousemove_count = 0
self.action_count = 0
self.visible_objs = None
def get_visible_objects(self, context):
@@ -523,16 +524,16 @@ class DrawPolylineWall(bpy.types.Operator):
tool.Snaping.update_snaping_point(intersection, "Plane")
def draw_polyline(self, context):
tool.Snaping.insert_polyline_point()
def modal(self, context, event):
# NOTE Blender seem to have a bug where some event types are triggered twice.
# The use of self.action_count is to prevent that. However, it's necessary to
# check if this behavior happens in every OS. Reference: https://blender.stackexchange.com/questions/30985/modal-operator-double-keytrigger-release-triggered-twice-on-ubuntu
if event.type == 'MOUSEMOVE':
self.mousemove_count += 1
tool.Blender.update_viewport()
print(self.action_count)
else:
self.mousemove_count = 0
@@ -549,7 +550,21 @@ class DrawPolylineWall(bpy.types.Operator):
return {'RUNNING_MODAL'}
if event.type == 'LEFTMOUSE':
self.draw_polyline(context)
if self.action_count == 0:
tool.Snaping.insert_polyline_point()
self.action_count += 1
return {'RUNNING_MODAL'}
if self.action_count == 1:
self.action_count = 0
if event.type == 'BACK_SPACE':
if self.action_count == 0:
tool.Snaping.remove_last_polyline_point()
tool.Blender.update_viewport()
self.action_count += 1
return {'RUNNING_MODAL'}
if self.action_count == 1:
self.action_count = 0
if event.type in {'MIDDLEMOUSE', 'WHEELUPMOUSE', 'WHEELDOWNMOUSE'}:
return {'PASS_THROUGH'}
+4 -8
View File
@@ -79,13 +79,6 @@ class Snaping(blenderbim.core.tool.Snaping):
def insert_polyline_point(cls):
snap_vertex = bpy.context.scene.BIMModelProperties.snap_mouse_point[0]
polyline_data = bpy.context.scene.BIMModelProperties.polyline_point
print(len(polyline_data))
if len(polyline_data) > 0:
print("X", snap_vertex.x, polyline_data[-1].x)
if snap_vertex.x == polyline_data[-1].x and\
snap_vertex.y == polyline_data[-1].y and\
snap_vertex.z == polyline_data[-1].z:
return
polyline_point = bpy.context.scene.BIMModelProperties.polyline_point.add()
polyline_point.x = snap_vertex.x
@@ -96,4 +89,7 @@ class Snaping(blenderbim.core.tool.Snaping):
def clear_polyline(cls):
bpy.context.scene.BIMModelProperties.polyline_point.clear()
@classmethod
def remove_last_polyline_point(cls):
polyline_data = bpy.context.scene.BIMModelProperties.polyline_point
polyline_data.remove(len(polyline_data) - 1)