Refactor polyline tool instructions.

Follows 8fc0d7a808
This commit is contained in:
Bruno Perdigão
2025-01-23 09:27:14 -03:00
parent 88dc9d7633
commit 8b678309fd
3 changed files with 54 additions and 39 deletions
+37 -27
View File
@@ -474,6 +474,7 @@ class PolylineOperator:
return context.space_data.type == "VIEW_3D"
def __init__(self):
self.unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
self.mousemove_count = 0
self.action_count = 0
self.visible_objs = []
@@ -509,19 +510,21 @@ class PolylineOperator:
self.is_typing = False
self.snap_angle = None
self.snapping_points = []
self.instructions = """TAB: Cycle Input
D: Distance Input
A: Angle Lock
M: Modify Snap Point
C: Close Polyline
BACKSPACE: Remove Point
X, Y: Choose Axis
"""
self.snap_info = """
Snap:
Axis:
Plane:
"""
self.instructions = {
'Cycle Input': {'icons':True, 'keys': ['EVENT_TAB']},
'Distance Input': {'icons':True, 'keys': ['EVENT_D']},
'Angle Lock': {'icons':True, 'keys': ['EVENT_A']},
'Increment Angle': {'icons':True, 'keys': ['EVENT_SHIFT', 'MOUSE_MMB_SCROLL']},
'Modify Snap Point': {'icons':True, 'keys': ['EVENT_M']},
'Close Polyline': {'icons':True, 'keys': ['EVENT_C']},
'Remove Point': {'icons':True, 'keys': ['EVENT_BACKSPACE']},
}
self.info = [
"Axis: ",
"Plane: ",
"Snap: ",
]
self.tool_state = tool.Polyline.create_tool_state()
@@ -586,23 +589,30 @@ class PolylineOperator:
self.tool_state.axis_method = None
tool.Blender.update_viewport()
def handle_instructions(self, context: bpy.types.Context, custom_instructions: str = "") -> None:
self.snap_info = f"""|
Axis: {self.tool_state.axis_method}
Plane: {self.tool_state.plane_method}
Snap: {self.snapping_points[0][1]}
"""
instructions = self.instructions + custom_instructions + self.snap_info
def handle_instructions(self, context: bpy.types.Context, custom_instructions: dict = {}, custom_info: str = "") -> None:
self.info = [
f"Axis: {self.tool_state.axis_method}",
f"Plane: {self.tool_state.plane_method}",
f"Snap: {self.snapping_points[0][1]}",
]
instructions = self.instructions | custom_instructions if custom_instructions else self.instructions
infos = self.info + custom_info if custom_info else self.info
def draw_instructions(self: bpy.types.Header, context: bpy.types.Context) -> None:
for line in instructions.splitlines():
line = line.strip()
split = line.split(":", 1)
if (key := split[0]) not in ("TAB", "D", "A", "M", "C", "E", "BACKSPACE"):
self.layout.label(text=line)
continue
for action, settings in instructions.items():
if settings["icons"]:
for key in settings["keys"]:
self.layout.label(text="", icon=key)
self.layout.label(text=action)
else:
key = settings["keys"][0]
self.layout.label(text=key+action)
self.layout.label(text=split[1], icon=f"EVENT_{key}")
self.layout.label(text="|")
for info in infos:
self.layout.label(text=info)
context.workspace.status_text_set(draw_instructions)
@@ -433,6 +433,18 @@ class DrawPolylineWall(bpy.types.Operator, PolylineOperator):
"""
self.handle_instructions(context, wall_config)
custom_instructions = {
'Choose Axis': {'icons':True, 'keys': ['EVENT_X', 'EVENT_Y']}
}
wall_config = [
f"Direction: {props.direction_sense}",
f"Offset Type: {props.offset_type}",
f"Offset Value: {tool.Polyline.format_input_ui_units(props.offset * self.unit_scale)}",
]
self.handle_instructions(context, custom_instructions, wall_config)
self.handle_mouse_move(context, event, should_round=True)
self.choose_axis(event)
@@ -2388,17 +2388,6 @@ class MeasureTool(bpy.types.Operator, PolylineOperator):
else:
self.input_ui = tool.Polyline.create_input_ui(init_z=True)
self.input_options = ["D", "A", "X", "Y", "Z"]
self.instructions = """TAB: Cycle Input
D: Distance Input
A: Angle Input
M: Modify Snap Point
C: Close Polyline
E: Erase previous polylines
BACKSPACE: Remove Point
X, Y, Z: Choose Axis
S-X, S-Y, S-Z: Choose Plane
L: Lock axis
"""
def modal(self, context, event):
PolylineDecorator.update(event, self.tool_state, self.input_ui, self.snapping_points[0])
@@ -2410,7 +2399,11 @@ class MeasureTool(bpy.types.Operator, PolylineOperator):
self.handle_mouse_move(context, event)
return {"PASS_THROUGH"}
self.handle_instructions(context)
custom_instructions = {
'Choose Axis': {'icons':True, 'keys': ['EVENT_X', 'EVENT_Y', 'EVENT_Z']},
'Choose Plane': {'icons':True, 'keys': ['EVENT_SHIFT', 'EVENT_X', 'EVENT_Y', 'EVENT_Z']},
}
self.handle_instructions(context, custom_instructions)
self.handle_mouse_move(context, event)