From 9fc75c1e2772c32622dbca5e85d7c82d08f760a2 Mon Sep 17 00:00:00 2001 From: Tristan Strathearn Date: Fri, 15 Jul 2022 11:36:03 +1000 Subject: [PATCH] feat: add toggleable exclusive view (x-ray option) option to geo_lift, panel, and view_align operators --- lib/objects.py | 1 - sketch/geo_lift.py | 19 +++++++++++++++++++ sketch/panel.py | 12 ++++++++++++ sketch/view_align.py | 19 +++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/objects.py b/lib/objects.py index 264ee8d..1b38aef 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -97,7 +97,6 @@ def create_duplicate_liftable_geometry(context, mode, object_name, ignore_comple object_eval = context.active_object.evaluated_get(depsgraph) context.active_object.modifiers.clear() - context.active_object.show_in_front = True vertex_groups = context.active_object.vertex_groups.values() for vg in vertex_groups: diff --git a/sketch/geo_lift.py b/sketch/geo_lift.py index b21213b..35b4c46 100644 --- a/sketch/geo_lift.py +++ b/sketch/geo_lift.py @@ -63,6 +63,10 @@ def modal(self, context, event): self.selection_type = (self.selection_type + 1) % 3 self.set_selection_mode(context) + elif pressed(event, {'E'}): + self.xray_mode = not self.xray_mode + self.dirty = True + elif self.key_one: self.selection_type = 0 self.set_selection_mode(context) @@ -78,13 +82,18 @@ def modal(self, context, event): elif self.key_movement_passthrough: return {'PASS_THROUGH'} + if self.dirty: + self.operate(context) + update_overlay(self, context, event) return {'RUNNING_MODAL'} def invoke(self, context, event): + self.dirty = False self.selection_type = 2 # ['VERT', 'EDGE', 'FACE'] + self.xray_mode = False self.register_mode() self.target_obj = context.active_object @@ -141,6 +150,11 @@ def has_invalid_selection(self, context): return False + def operate(self, context): + context.active_object.show_in_front = self.xray_mode + self.dirty = False + + def finish(self, context): if self.has_invalid_selection(context): self.clean_up(context) @@ -179,6 +193,11 @@ def draw_text_callback(self): "Selection Type [S,1,2,3]: {0}".format(['Vertex', 'Edge', 'Face'][self.selection_type]), "Type of geometry to select (Vertex, Edge, Face)") + draw_hint( + self, + "Exclusive View [E]: {0}".format("On" if self.xray_mode else "Off"), + "Show the target object in front of all other objects") + def register(): bpy.utils.register_class(ND_OT_geo_lift) diff --git a/sketch/panel.py b/sketch/panel.py index e02107e..998c779 100644 --- a/sketch/panel.py +++ b/sketch/panel.py @@ -83,6 +83,10 @@ def modal(self, context, event): self.individual = not self.individual self.dirty = True + elif pressed(event, {'E'}): + self.xray_mode = not self.xray_mode + self.dirty = True + elif self.key_step_up: if self.stage == 1: if no_stream(self.inset_input_stream) and self.key_no_modifiers: @@ -136,6 +140,7 @@ def invoke(self, context, event): self.dirty = False + self.xray_mode = False self.individual = False self.inset = 0 self.stage = 0 @@ -198,6 +203,8 @@ def delete_panel_faces(self, faces): def operate(self, context): + self.panel_obj.show_in_front = self.xray_mode + if self.stage == 1: bmesh.ops.delete(self.panel_bm, geom=self.panel_bm.verts, context='VERTS') self.panel_bm.from_mesh(self.panel_mesh_snapshot) @@ -280,6 +287,11 @@ def draw_text_callback(self): "Individual Faces [F]: {}".format("Yes" if self.individual else "No"), "Inset individual faces (Yes, No)") + draw_hint( + self, + "Exclusive View [E]: {0}".format("On" if self.xray_mode else "Off"), + "Show the target object in front of all other objects") + def register(): bpy.utils.register_class(ND_OT_panel) diff --git a/sketch/view_align.py b/sketch/view_align.py index 8f72f0f..6885f9a 100644 --- a/sketch/view_align.py +++ b/sketch/view_align.py @@ -59,6 +59,10 @@ def modal(self, context, event): self.selection_type = (self.selection_type + 1) % 3 self.set_selection_mode(context) + elif pressed(event, {'E'}): + self.xray_mode = not self.xray_mode + self.dirty = True + elif self.key_one: self.selection_type = 0 self.set_selection_mode(context) @@ -80,12 +84,17 @@ def modal(self, context, event): elif self.key_movement_passthrough: return {'PASS_THROUGH'} + if self.dirty: + self.operate(context) + update_overlay(self, context, event) return {'RUNNING_MODAL'} def invoke(self, context, event): + self.dirty = False + self.xray_mode = False self.selection_type = 2 # ['VERT', 'EDGE', 'FACE'] self.skip_geo_select = event.alt @@ -216,6 +225,11 @@ def determine_selection_type(self, context): self.selection_type = 2 + def operate(self, context): + context.active_object.show_in_front = self.xray_mode + self.dirty = False + + def finish(self, context): if self.has_invalid_selection(context): self.clean_up(context) @@ -253,6 +267,11 @@ def draw_text_callback(self): "Selection Type [S,1,2,3]: {0}".format(['Vertex', 'Edge', 'Face'][self.selection_type]), "Type of geometry to select (Vertex, Edge, Face)") + draw_hint( + self, + "Exclusive View [E]: {0}".format("On" if self.xray_mode else "Off"), + "Show the target object in front of all other objects") + def register(): bpy.utils.register_class(ND_OT_view_align)