mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 14:23:53 +00:00
Unify polyline tool cleanup
Route all polyline tools through a single PolylineOperator.cleanup that tears down the decorators, polyline, and raycast cache, and uninstall ProductDecorator unconditionally since it is idempotent. Generated with the assistance of an AI coding tool.
This commit is contained in:
committed by
Bruno Perdigão
parent
a6d59bf61c
commit
edbce75f4e
@@ -26,7 +26,7 @@ import ifcopenshell.util.unit
|
||||
from mathutils import Vector
|
||||
|
||||
import bonsai.tool as tool
|
||||
from bonsai.bim.module.model.decorator import GpuSnapDecorator, PolylineDecorator
|
||||
from bonsai.bim.module.model.decorator import GpuSnapDecorator, PolylineDecorator, ProductDecorator
|
||||
|
||||
|
||||
class PolylineOperator:
|
||||
@@ -425,6 +425,7 @@ class PolylineOperator:
|
||||
context.workspace.status_text_set(text=None)
|
||||
PolylineDecorator.uninstall()
|
||||
GpuSnapDecorator.uninstall()
|
||||
ProductDecorator.uninstall()
|
||||
tool.Polyline.clear_polyline()
|
||||
tool.Raycast.clear_cache()
|
||||
tool.Blender.update_viewport()
|
||||
|
||||
@@ -221,8 +221,7 @@ class DrawOccurrence(bpy.types.Operator, PolylineOperator, tool.Ifc.Operator):
|
||||
|
||||
if not self.relating_type:
|
||||
self.report({"WARNING"}, "You need to select a type.")
|
||||
PolylineDecorator.uninstall()
|
||||
tool.Blender.update_viewport()
|
||||
self.cleanup(context)
|
||||
return {"FINISHED"}
|
||||
|
||||
PolylineDecorator.update(event, self.tool_state, self.input_ui, self.snapping_points[0])
|
||||
@@ -239,11 +238,7 @@ class DrawOccurrence(bpy.types.Operator, PolylineOperator, tool.Ifc.Operator):
|
||||
|
||||
if not self.tool_state.is_input_on and event.value == "RELEASE" and event.type in {"RIGHTMOUSE"}:
|
||||
self.tool_state.axis_method = None
|
||||
context.workspace.status_text_set(text=None)
|
||||
ProductDecorator.uninstall()
|
||||
PolylineDecorator.uninstall()
|
||||
tool.Polyline.clear_polyline()
|
||||
tool.Blender.update_viewport()
|
||||
self.cleanup(context)
|
||||
return {"FINISHED"}
|
||||
|
||||
if event.value == "RELEASE" and event.type == "LEFTMOUSE":
|
||||
@@ -251,7 +246,6 @@ class DrawOccurrence(bpy.types.Operator, PolylineOperator, tool.Ifc.Operator):
|
||||
|
||||
cancel = self.handle_cancelation(context, event)
|
||||
if cancel is not None:
|
||||
ProductDecorator.uninstall()
|
||||
return cancel
|
||||
|
||||
return {"RUNNING_MODAL"}
|
||||
|
||||
@@ -1181,8 +1181,7 @@ class DrawPolylineProfile(bpy.types.Operator, PolylineOperator, tool.Ifc.Operato
|
||||
def _modal(self, context, event):
|
||||
if not self.relating_type:
|
||||
self.report({"WARNING"}, "You need to select a profile type.")
|
||||
PolylineDecorator.uninstall()
|
||||
tool.Blender.update_viewport()
|
||||
self.cleanup(context)
|
||||
return {"FINISHED"}
|
||||
|
||||
PolylineDecorator.update(event, self.tool_state, self.input_ui, self.snapping_points[0])
|
||||
@@ -1210,12 +1209,8 @@ class DrawPolylineProfile(bpy.types.Operator, PolylineOperator, tool.Ifc.Operato
|
||||
and event.type in {"RET", "NUMPAD_ENTER", "RIGHTMOUSE"}
|
||||
):
|
||||
self.create_profiles_from_polyline(context)
|
||||
context.workspace.status_text_set(text=None)
|
||||
self.tool_state.plane_method = None
|
||||
ProductDecorator.uninstall()
|
||||
PolylineDecorator.uninstall()
|
||||
tool.Polyline.clear_polyline()
|
||||
tool.Blender.update_viewport()
|
||||
self.cleanup(context)
|
||||
return {"FINISHED"}
|
||||
|
||||
self.handle_keyboard_input(context, event)
|
||||
@@ -1223,7 +1218,6 @@ class DrawPolylineProfile(bpy.types.Operator, PolylineOperator, tool.Ifc.Operato
|
||||
|
||||
cancel = self.handle_cancelation(context, event)
|
||||
if cancel is not None:
|
||||
ProductDecorator.uninstall()
|
||||
return cancel
|
||||
|
||||
return {"RUNNING_MODAL"}
|
||||
|
||||
@@ -905,8 +905,7 @@ class DrawPolylineSlab(bpy.types.Operator, PolylineOperator, tool.Ifc.Operator):
|
||||
def _modal(self, context, event):
|
||||
if not self.relating_type:
|
||||
self.report({"WARNING"}, "You need to select a slab type.")
|
||||
PolylineDecorator.uninstall()
|
||||
tool.Blender.update_viewport()
|
||||
self.cleanup(context)
|
||||
return {"FINISHED"}
|
||||
|
||||
PolylineDecorator.update(event, self.tool_state, self.input_ui, self.snapping_points[0])
|
||||
@@ -952,11 +951,7 @@ class DrawPolylineSlab(bpy.types.Operator, PolylineOperator, tool.Ifc.Operator):
|
||||
and event.type in {"RET", "NUMPAD_ENTER", "RIGHTMOUSE"}
|
||||
):
|
||||
self.create_slab_from_polyline(context)
|
||||
context.workspace.status_text_set(text=None)
|
||||
ProductDecorator.uninstall()
|
||||
PolylineDecorator.uninstall()
|
||||
tool.Polyline.clear_polyline()
|
||||
tool.Blender.update_viewport()
|
||||
self.cleanup(context)
|
||||
return {"FINISHED"}
|
||||
|
||||
self.handle_keyboard_input(context, event)
|
||||
@@ -964,7 +959,6 @@ class DrawPolylineSlab(bpy.types.Operator, PolylineOperator, tool.Ifc.Operator):
|
||||
|
||||
cancel = self.handle_cancelation(context, event)
|
||||
if cancel is not None:
|
||||
ProductDecorator.uninstall()
|
||||
return cancel
|
||||
|
||||
return {"RUNNING_MODAL"}
|
||||
|
||||
@@ -623,10 +623,7 @@ class ExtendWallsToPolylinePoint(bpy.types.Operator, PolylineOperator, tool.Ifc.
|
||||
self.connection,
|
||||
)
|
||||
|
||||
tool.Polyline.clear_polyline()
|
||||
context.workspace.status_text_set(text=None)
|
||||
PolylineDecorator.uninstall()
|
||||
tool.Blender.update_viewport()
|
||||
self.cleanup(context)
|
||||
return {"FINISHED"}
|
||||
|
||||
self.handle_keyboard_input(context, event)
|
||||
@@ -1070,8 +1067,7 @@ class DrawPolylineWall(bpy.types.Operator, PolylineOperator, tool.Ifc.Operator):
|
||||
def _modal(self, context, event):
|
||||
if not self.relating_type:
|
||||
self.report({"WARNING"}, "You need to select a wall type.")
|
||||
PolylineDecorator.uninstall()
|
||||
tool.Blender.update_viewport()
|
||||
self.cleanup(context)
|
||||
return {"FINISHED"}
|
||||
|
||||
PolylineDecorator.update(event, self.tool_state, self.input_ui, self.snapping_points[0])
|
||||
@@ -1119,12 +1115,8 @@ class DrawPolylineWall(bpy.types.Operator, PolylineOperator, tool.Ifc.Operator):
|
||||
and event.type in {"RET", "NUMPAD_ENTER", "RIGHTMOUSE"}
|
||||
):
|
||||
self.create_walls_from_polyline(context)
|
||||
context.workspace.status_text_set(text=None)
|
||||
self.tool_state.plane_method = None
|
||||
ProductDecorator.uninstall()
|
||||
PolylineDecorator.uninstall()
|
||||
tool.Polyline.clear_polyline()
|
||||
tool.Blender.update_viewport()
|
||||
self.cleanup(context)
|
||||
return {"FINISHED"}
|
||||
|
||||
self.handle_keyboard_input(context, event)
|
||||
@@ -1132,7 +1124,6 @@ class DrawPolylineWall(bpy.types.Operator, PolylineOperator, tool.Ifc.Operator):
|
||||
|
||||
cancel = self.handle_cancelation(context, event)
|
||||
if cancel is not None:
|
||||
ProductDecorator.uninstall()
|
||||
return cancel
|
||||
|
||||
return {"RUNNING_MODAL"}
|
||||
|
||||
@@ -3389,11 +3389,7 @@ class MeasureFaceAreaTool(bpy.types.Operator, PolylineOperator):
|
||||
tool.Blender.update_viewport()
|
||||
|
||||
if event.value == "RELEASE" and event.type in {"ESC", "RIGHTMOUSE"}:
|
||||
polyline_props.insertion_polyline.clear()
|
||||
context.workspace.status_text_set(text=None)
|
||||
PolylineDecorator.uninstall()
|
||||
FaceAreaDecorator.uninstall()
|
||||
tool.Blender.update_viewport()
|
||||
self.cleanup(context)
|
||||
return {"CANCELLED"}
|
||||
|
||||
return {"RUNNING_MODAL"}
|
||||
@@ -3405,6 +3401,10 @@ class MeasureFaceAreaTool(bpy.types.Operator, PolylineOperator):
|
||||
FaceAreaDecorator.install(context)
|
||||
return {"RUNNING_MODAL"}
|
||||
|
||||
def cleanup(self, context):
|
||||
FaceAreaDecorator.uninstall()
|
||||
super().cleanup(context)
|
||||
|
||||
|
||||
class ClearMeasurement(bpy.types.Operator):
|
||||
bl_idname = "bim.clear_measurement"
|
||||
@@ -3522,11 +3522,9 @@ class ImageScalingTool(bpy.types.Operator, PolylineOperator):
|
||||
return {"RUNNING_MODAL"}
|
||||
|
||||
def cancel_tool(self, context: bpy.types.Context) -> set["rna_enums.OperatorReturnItems"]:
|
||||
context.workspace.status_text_set(text=None)
|
||||
if hasattr(self, "tool_state"):
|
||||
self.tool_state.plane_method = None
|
||||
PolylineDecorator.uninstall()
|
||||
tool.Blender.update_viewport()
|
||||
self.cleanup(context)
|
||||
return {"CANCELLED"}
|
||||
|
||||
def handle_custom_instructions(self, context: bpy.types.Context) -> None:
|
||||
@@ -3597,10 +3595,8 @@ class ImageScalingTool(bpy.types.Operator, PolylineOperator):
|
||||
|
||||
self.report({"INFO"}, f"Applied scale factor: {scale_factor:.4f}")
|
||||
|
||||
context.workspace.status_text_set(text=None)
|
||||
self.tool_state.plane_method = None
|
||||
PolylineDecorator.uninstall()
|
||||
tool.Blender.update_viewport()
|
||||
self.cleanup(context)
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user