From 2008081d9ac80b2211b11bf4f8a64220a92eac5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Perdig=C3=A3o?= Date: Fri, 6 Sep 2024 14:43:01 -0300 Subject: [PATCH] Implementation of #5317. The number in the input UI will be replaced if the user presses a number. This behavior will be different if the user press "=" or backspace. --- src/bonsai/bonsai/bim/module/model/wall.py | 50 +++++++++---------- .../bonsai/bim/module/project/operator.py | 48 +++++++++--------- 2 files changed, 46 insertions(+), 52 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/model/wall.py b/src/bonsai/bonsai/bim/module/model/wall.py index d06323ae95..8c1a61a5a0 100644 --- a/src/bonsai/bonsai/bim/module/model/wall.py +++ b/src/bonsai/bonsai/bim/module/model/wall.py @@ -327,6 +327,7 @@ class DrawPolylineWall(bpy.types.Operator): self.input_type = None self.input_value_xy = [None, None] self.input_ui = tool.Polyline.create_input_ui() + self.is_typing = False self.snap_angle = None self.snapping_points = [] self.instructions = """TAB: Cycle Input @@ -433,15 +434,11 @@ class DrawPolylineWall(bpy.types.Operator): 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 = self.input_ui.get_text_value(self.input_type) + self.is_typing = False + self.number_input = self.input_ui.get_formatted_value(self.input_type) self.number_input = list(self.number_input) self.number_output = "".join(self.number_input) - if self.input_type != "A": - self.number_output = self.input_ui.get_formatted_value(self.input_type) - self.input_ui.set_value(self.input_type, self.number_output) - PolylineDecorator.set_input_ui(self.input_ui, self.input_type) tool.Blender.update_viewport() @@ -449,14 +446,11 @@ class DrawPolylineWall(bpy.types.Operator): self.recalculate_inputs(context) self.is_input_on = True self.input_type = "D" - - self.number_input = self.input_ui.get_text_value(self.input_type) - print("NI", self.number_input) + self.is_typing = False + self.number_input = self.input_ui.get_formatted_value(self.input_type) self.number_input = list(self.number_input) self.number_output = "".join(self.number_input) - self.number_output = self.input_ui.get_formatted_value(self.input_type) self.input_ui.set_value(self.input_type, self.number_output) - PolylineDecorator.set_input_ui(self.input_ui, self.input_type) tool.Blender.update_viewport() @@ -464,8 +458,6 @@ class DrawPolylineWall(bpy.types.Operator): self.recalculate_inputs(context) self.is_input_on = True self.input_type = "D" - self.number_input = [] - print("WALL", self.input_type) PolylineDecorator.set_input_ui(self.input_ui, self.input_type) tool.Blender.update_viewport() @@ -473,32 +465,36 @@ class DrawPolylineWall(bpy.types.Operator): self.recalculate_inputs(context) self.is_input_on = True self.input_type = event.type - self.number_input = [] self.input_ui.set_value(self.input_type, "") PolylineDecorator.set_input_ui(self.input_ui, 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 not self.is_typing and event.ascii != "=": + self.number_input = [] + 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) - if not self.number_input: - self.number_output = "0" - self.input_ui.set_value(self.input_type, self.number_output) - PolylineDecorator.set_input_ui(self.input_ui, self.input_type) - tool.Blender.update_viewport() + self.number_input.pop(-1) + elif event.ascii == "=": + if self.number_input[0] == "=": + self.number_input.pop(0) + else: + self.number_input.insert(0, "=") else: self.number_input.append(event.ascii) - self.number_output = "".join(self.number_input) - if self.number_input: - self.input_ui.set_value(self.input_type, self.number_output) - PolylineDecorator.set_input_ui(self.input_ui, self.input_type) - tool.Blender.update_viewport() + if not self.number_input: + self.number_output = "0" + + self.is_typing = True + self.number_output = "".join(self.number_input) + self.input_ui.set_value(self.input_type, self.number_output) + PolylineDecorator.set_input_ui(self.input_ui, self.input_type) + tool.Blender.update_viewport() if not self.is_input_on and event.value == "RELEASE" and event.type in {"RET", "NUMPAD_ENTER", "RIGHTMOUSE"}: self.create_walls_from_polyline(context) @@ -549,7 +545,7 @@ class DrawPolylineWall(bpy.types.Operator): PolylineDecorator.install(context) tool.Snap.set_use_default_container(True) PolylineDecorator.set_use_default_container(True) - tool.Polyline.set_use_default_container(True) # <--- + tool.Polyline.set_use_default_container(True) tool.Snap.set_snap_plane_method("XY") PolylineDecorator.set_instructions(self.instructions) PolylineDecorator.set_input_ui(self.input_ui, self.input_type) diff --git a/src/bonsai/bonsai/bim/module/project/operator.py b/src/bonsai/bonsai/bim/module/project/operator.py index b862a9cee2..94d3527854 100644 --- a/src/bonsai/bonsai/bim/module/project/operator.py +++ b/src/bonsai/bonsai/bim/module/project/operator.py @@ -2311,6 +2311,7 @@ class MeasureTool(bpy.types.Operator): self.input_type = None self.input_value_xy = [None, None] self.input_ui = tool.Polyline.create_input_ui(init_z=True) + self.is_typing = False self.snap_angle = None self.snapping_points = [] self.instructions = """TAB: Cycle Input @@ -2396,15 +2397,11 @@ class MeasureTool(bpy.types.Operator): 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 = self.input_ui.get_text_value(self.input_type) + self.is_typing = False + self.number_input = self.input_ui.get_formatted_value(self.input_type) self.number_input = list(self.number_input) self.number_output = "".join(self.number_input) - if self.input_type != "A": - self.number_output = self.input_ui.get_formatted_value(self.input_type) - self.input_ui.set_value(self.input_type, self.number_output) - PolylineDecorator.set_input_ui(self.input_ui, self.input_type) tool.Blender.update_viewport() @@ -2412,13 +2409,11 @@ class MeasureTool(bpy.types.Operator): self.recalculate_inputs(context) self.is_input_on = True self.input_type = "D" - - self.number_input = self.input_ui.get_text_value(self.input_type) + self.is_typing = False + self.number_input = self.input_ui.get_formatted_value(self.input_type) self.number_input = list(self.number_input) self.number_output = "".join(self.number_input) - self.number_output = self.input_ui.get_formatted_value(self.input_type) self.input_ui.set_value(self.input_type, self.number_output) - PolylineDecorator.set_input_ui(self.input_ui, self.input_type) tool.Blender.update_viewport() @@ -2426,7 +2421,6 @@ class MeasureTool(bpy.types.Operator): self.recalculate_inputs(context) self.is_input_on = True self.input_type = "D" - self.number_input = [] PolylineDecorator.set_input_ui(self.input_ui, self.input_type) tool.Blender.update_viewport() @@ -2434,32 +2428,36 @@ class MeasureTool(bpy.types.Operator): self.recalculate_inputs(context) self.is_input_on = True self.input_type = event.type - self.number_input = [] self.input_ui.set_value(self.input_type, "") PolylineDecorator.set_input_ui(self.input_ui, 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 not self.is_typing and event.ascii != "=": + self.number_input = [] + 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) - if not self.number_input: - self.number_output = "0" - self.input_ui.set_value(self.input_type, self.number_output) - PolylineDecorator.set_input_ui(self.input_ui, self.input_type) - tool.Blender.update_viewport() + self.number_input.pop(-1) + elif event.ascii == "=": + if self.number_input[0] == "=": + self.number_input.pop(0) + else: + self.number_input.insert(0, "=") else: self.number_input.append(event.ascii) - self.number_output = "".join(self.number_input) - if self.number_input: - self.input_ui.set_value(self.input_type, self.number_output) - PolylineDecorator.set_input_ui(self.input_ui, self.input_type) - tool.Blender.update_viewport() + if not self.number_input: + self.number_output = "0" + + self.is_typing = True + self.number_output = "".join(self.number_input) + self.input_ui.set_value(self.input_type, self.number_output) + PolylineDecorator.set_input_ui(self.input_ui, self.input_type) + tool.Blender.update_viewport() if not self.is_input_on and event.value == "RELEASE" and event.type in {"RET", "NUMPAD_ENTER", "RIGHTMOUSE"}: PolylineDecorator.uninstall() @@ -2531,7 +2529,7 @@ class MeasureTool(bpy.types.Operator): PolylineDecorator.install(context) tool.Snap.set_use_default_container(False) PolylineDecorator.set_use_default_container(False) - tool.Polyline.set_use_default_container(False) # <--- + tool.Polyline.set_use_default_container(False) tool.Snap.set_snap_plane_method(None) tool.Snap.set_snap_axis_method(None) PolylineDecorator.set_instructions(self.instructions)