Skip to content

Commit

Permalink
feat: add option to lock overlay parameters on recall
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan-hm authored Jun 25, 2024
1 parent fe6efb5 commit 3c719cc
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 13 deletions.
6 changes: 6 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ class NDPreferences(AddonPreferences):
default="RESET",
)

lock_overlay_parameters_on_recall: BoolProperty(
name="Lock Overlay Parameters on Recall",
default=True,
)

overlay_pinned: BoolProperty(
name="Overlay Pinned",
default=False,
Expand Down Expand Up @@ -526,6 +531,7 @@ def draw_ui(self, box):
["unit_increment_size"],
["enable_quick_favourites"],
["lock_overlay_pinning"],
["lock_overlay_parameters_on_recall"],
["enable_sidebar"],
["enable_axis_helper"],
["axis_base_thickness", "axis_active_thickness", "axis_inactive_opacity"]]
Expand Down
8 changes: 7 additions & 1 deletion bevels/bevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, toggle_operator_passthrough, register_draw_handler, unregister_draw_handler, draw_header, draw_property, draw_hint
from .. lib.events import capture_modifier_keys, pressed
from .. lib.preferences import get_preferences
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, set_stream, has_stream
from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, add_smooth_by_angle, rectify_smooth_by_angle


Expand Down Expand Up @@ -264,6 +264,12 @@ def summon_old_operator(self, context):
self.clamp_overlap_prev = self.clamp_overlap = self.bevel.use_clamp_overlap
self.angle_prev = self.angle = degrees(self.bevel.angle_limit)

if get_preferences().lock_overlay_parameters_on_recall:
self.segments_input_stream = set_stream(self.segments)
self.width_input_stream = set_stream(self.width)
self.profile_input_stream = set_stream(self.profile)
self.angle_input_stream = set_stream(self.angle)


def add_smooth_shading(self, context):
if not get_preferences().enable_auto_smooth:
Expand Down
8 changes: 7 additions & 1 deletion bevels/edge_bevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, toggle_operator_passthrough, register_draw_handler, unregister_draw_handler, draw_header, draw_property, draw_hint
from .. lib.events import capture_modifier_keys, pressed
from .. lib.preferences import get_preferences
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream, set_stream
from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle, add_smooth_by_angle


Expand Down Expand Up @@ -266,6 +266,12 @@ def summon_old_operator(self, context, mods):
self.loop_slide_prev = self.loop_slide = self.bevel.loop_slide
self.clamp_overlap_prev = self.clamp_overlap = self.bevel.use_clamp_overlap

if get_preferences().lock_overlay_parameters_on_recall:
self.segments_input_stream = set_stream(self.segments)
self.weight_input_stream = set_stream(self.weight)
self.width_input_stream = set_stream(self.width)
self.profile_input_stream = set_stream(self.profile)


def add_smooth_shading(self, context):
if not get_preferences().enable_auto_smooth:
Expand Down
7 changes: 6 additions & 1 deletion bevels/vertex_bevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, toggle_operator_passthrough, register_draw_handler, unregister_draw_handler, draw_header, draw_property, draw_hint
from .. lib.events import capture_modifier_keys, pressed
from .. lib.preferences import get_preferences
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream, set_stream
from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle, add_smooth_by_angle


Expand Down Expand Up @@ -240,6 +240,11 @@ def summon_old_operator(self, context):
self.segments_prev = self.segments = self.bevel.segments
self.profile_prev = self.profile = self.bevel.profile

if get_preferences().lock_overlay_parameters_on_recall:
self.segments_input_stream = set_stream(self.segments)
self.width_input_stream = set_stream(self.width)
self.profile_input_stream = set_stream(self.profile)


def prepare_new_operator(self, context):
self.summoned = False
Expand Down
7 changes: 6 additions & 1 deletion deform/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from .. lib.preferences import get_preferences
from .. lib.collections import move_to_utils_collection, isolate_in_utils_collection, hide_utils_collection
from .. lib.math import generate_bounding_box, v3_average
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream, set_stream
from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle


Expand Down Expand Up @@ -259,6 +259,11 @@ def summon_old_operator(self, context, mods):
self.lattice_points_w = self.lattice_points_w_prev = self.lattice_obj.data.points_w
self.interpolation_mode = self.interpolation_mode_prev = self.interpolation_modes.index(self.lattice_obj.data.interpolation_type_u)

if get_preferences().lock_overlay_parameters_on_recall:
self.lattice_points_u_input_stream = set_stream(self.lattice_points_u)
self.lattice_points_v_input_stream = set_stream(self.lattice_points_v)
self.lattice_points_w_input_stream = set_stream(self.lattice_points_w)


def add_lattice_object(self, context):
bpy.ops.object.duplicate()
Expand Down
10 changes: 9 additions & 1 deletion deform/simple_deform.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from .. lib.events import capture_modifier_keys, pressed
from .. lib.preferences import get_preferences
from .. lib.axis import init_axis, register_axis_handler, unregister_axis_handler
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream, set_stream
from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle


Expand Down Expand Up @@ -79,6 +79,10 @@ def do_modal(self, context, event):

elif pressed(event, {'M'}):
self.current_method = (self.current_method + 1) % len(self.methods)
self.angle_input_stream = new_stream()
self.factor_input_stream = new_stream()
self.factor = 0
self.angle = 0
self.dirty = True

elif pressed(event, {'A'}):
Expand Down Expand Up @@ -192,6 +196,10 @@ def summon_old_operator(self, context, mods):
self.angle_prev = self.angle = degrees(self.deform.angle)
self.factor_prev = self.factor = self.deform.factor

if get_preferences().lock_overlay_parameters_on_recall:
self.angle_input_stream = set_stream(self.angle)
self.factor_input_stream = set_stream(self.factor)


def add_simple_deform_modifier(self, context):
deform = new_modifier(self.target_object, mod_deform, 'SIMPLE_DEFORM', rectify=True)
Expand Down
6 changes: 5 additions & 1 deletion extrusion/profile_extrude.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from .. lib.events import capture_modifier_keys, pressed
from .. lib.preferences import get_preferences
from .. lib.axis import init_axis, register_axis_handler, unregister_axis_handler
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream, set_stream
from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle, add_smooth_by_angle


Expand Down Expand Up @@ -196,6 +196,10 @@ def summon_old_operator(self, context, mods):
self.weighting_offset_strength_prev = self.weighting_offset.strength
self.offset_prev = self.offset = self.displace.strength

if get_preferences().lock_overlay_parameters_on_recall:
self.extrusion_length_input_stream = set_stream(self.extrusion_length)
self.offset_input_stream = set_stream(self.offset)


def calculate_weighting_offset_strength(self):
if self.weighting == -1:
Expand Down
7 changes: 6 additions & 1 deletion extrusion/screw.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from .. lib.events import capture_modifier_keys, pressed
from .. lib.preferences import get_preferences
from .. lib.axis import init_axis, register_axis_handler, unregister_axis_handler
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream, set_stream
from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, add_smooth_by_angle, rectify_smooth_by_angle


Expand Down Expand Up @@ -228,6 +228,11 @@ def summon_old_operator(self, context, mods):
self.angle_prev = self.angle = degrees(self.screw.angle)
self.flip_normals_prev = self.flip_normals = self.screw.use_normal_flip

if get_preferences().lock_overlay_parameters_on_recall:
self.offset_input_stream = set_stream(self.offset)
self.angle_input_stream = set_stream(self.angle)
self.segments_input_stream = set_stream(self.segments)


def add_smooth_shading(self, context):
if not get_preferences().enable_auto_smooth:
Expand Down
6 changes: 5 additions & 1 deletion extrusion/solidify.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .. lib.overlay import init_overlay, register_draw_handler, unregister_draw_handler, draw_header, draw_property, draw_hint
from .. lib.events import capture_modifier_keys, pressed
from .. lib.preferences import get_preferences, get_scene_unit_factor
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream, set_stream
from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle, add_smooth_by_angle


Expand Down Expand Up @@ -181,6 +181,10 @@ def summon_old_operator(self, context, mods):
self.complex_mode_prev = self.complex_mode = (self.solidify.solidify_mode == 'NON_MANIFOLD')
self.offset_prev = self.offset = self.displace.strength

if get_preferences().lock_overlay_parameters_on_recall:
self.thickness_input_stream = set_stream(self.thickness)
self.offset_input_stream = set_stream(self.offset)


def add_smooth_shading(self, context):
if not get_preferences().enable_auto_smooth:
Expand Down
4 changes: 4 additions & 0 deletions lib/numeric_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def update_stream(input_stream, type):
return ok, value, raw


def set_stream(value):
return True, value, str(value)


def no_stream(input_stream):
ok, value, raw = input_stream

Expand Down
2 changes: 1 addition & 1 deletion lib/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def draw_property(cls, property_content, metadata_content, active=False, alt_mod

if is_value is not None:
reset_behaviour = get_preferences().overlay_reset_key_behaviour
blf.draw(0, "Manual Override — [{}] to {}.".format(get_preferences().overlay_reset_key, "reset" if reset_behaviour == "RESET" else "unlock"))
blf.draw(0, "{} — [{}] to {}.".format(metadata_content, get_preferences().overlay_reset_key, "reset" if reset_behaviour == "RESET" else "unlock"))
else:
blf.draw(0, metadata_content)

Expand Down
6 changes: 5 additions & 1 deletion replicate/array_cubed.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .. lib.events import capture_modifier_keys, pressed
from .. lib.preferences import get_preferences
from .. lib.axis import init_axis, register_axis_handler, unregister_axis_handler
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream, set_stream
from .. lib.modifiers import new_modifier, remove_modifiers_starting_with


Expand Down Expand Up @@ -220,6 +220,10 @@ def summon_old_operator(self, context, mods):
self.axes_prev[axis] = [array, array.count, offset, array.use_relative_offset]
self.axes[axis] = [array, array.count, offset, array.use_relative_offset]

if get_preferences().lock_overlay_parameters_on_recall:
self.count_streams = [set_stream(self.axes[0][IDX_COUNT]), set_stream(self.axes[1][IDX_COUNT]), set_stream(self.axes[2][IDX_COUNT])]
self.offset_streams = [set_stream(self.axes[0][IDX_OFFSET]), set_stream(self.axes[1][IDX_OFFSET]), set_stream(self.axes[2][IDX_OFFSET])]


def add_array_modifier(self, context, name, axis):
array = new_modifier(context.active_object, name, 'ARRAY', rectify=True)
Expand Down
7 changes: 6 additions & 1 deletion replicate/circular_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from .. lib.collections import move_to_utils_collection, hide_utils_collection
from .. lib.preferences import get_preferences
from .. lib.objects import set_origin
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream, set_stream
from .. lib.modifiers import new_modifier, remove_modifiers_ending_with


Expand Down Expand Up @@ -269,6 +269,11 @@ def summon_old_operator(self, context, mods):
self.count = self.count_prev = self.array.count
self.offset = self.offset_prev = self.displace.strength

if get_preferences().lock_overlay_parameters_on_recall:
self.count_input_stream = set_stream(self.count)
self.angle_input_stream = set_stream(self.angle)
self.offset_input_stream = set_stream(self.offset)


def add_array_modifier(self):
array = new_modifier(self.reference_obj, mod_array, 'ARRAY', rectify=True)
Expand Down
7 changes: 6 additions & 1 deletion sketch/circularize.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, toggle_operator_passthrough, register_draw_handler, unregister_draw_handler, draw_header, draw_property, draw_hint
from .. lib.events import capture_modifier_keys, pressed
from .. lib.preferences import get_preferences
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream, set_stream
from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle, add_smooth_by_angle


Expand Down Expand Up @@ -140,6 +140,11 @@ def summon_old_operator(self, context, mods):

self.segments_prev = self.segments = self.bevel.segments

if get_preferences().lock_overlay_parameters_on_recall:
self.segments_input_stream = set_stream(self.segments)
self.width_input_stream = set_stream(self.bevel.width)
self.profile_input_stream = set_stream(self.bevel.profile)


def prepare_new_operator(self, context):
self.summoned = False
Expand Down
7 changes: 6 additions & 1 deletion sketch/recon_poly.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from .. lib.objects import add_single_vertex_object, align_object_to_3d_cursor
from .. lib.events import capture_modifier_keys, pressed
from .. lib.preferences import get_preferences
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream
from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream, set_stream
from .. lib.modifiers import new_modifier


Expand Down Expand Up @@ -245,6 +245,11 @@ def summon_old_operator(self, context, mods):
self.rotation_snapshot = self.obj.rotation_euler.copy()
self.obj.rotation_euler = self.rotation_prev

if get_preferences().lock_overlay_parameters_on_recall:
self.segments_input_stream = set_stream(self.segments)
self.inner_radius_input_stream = set_stream(self.inner_radius)
self.width_input_stream = set_stream(self.width)


@classmethod
def poll(cls, context):
Expand Down

0 comments on commit 3c719cc

Please sign in to comment.