Files
OpenNest/OpenNest.Desktop/SavedCutOffHeadLock.cs
T
ajandClaude Opus 5.5 725e90dada refactor(desktop): share the new cut-off head-lock defaults
SavedCutOffHeadLock reads and writes CutOffLockHeadHeight and
CutOffHeadLockOvercutInches in the WinForms format and converts the
overcut, always stored in inches, to and from each nest's units, using
1.5 in when the saved overcut is not a positive number. The WinForms
CutOffHeadLockDefaults now calls it, with unchanged behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 21:13:53 -05:00

57 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
namespace OpenNest.Desktop;
/// <summary>
/// Whether new cut-offs lock the head height and overcut the far sheet edge, kept between
/// sessions under the WinForms names CutOffLockHeadHeight ("True"/"False") and
/// CutOffHeadLockOvercutInches (a double, always inches) and converted to each nest's units.
/// </summary>
public sealed record SavedCutOffHeadLock(bool LockHeadHeight, double OvercutInches)
{
public const string LockHeadHeightName = "CutOffLockHeadHeight";
public const string OvercutInchesName = "CutOffHeadLockOvercutInches";
public const double DefaultOvercutInches = 1.5;
private const double MillimetersPerInch = 25.4;
/// <summary>The WinForms setting defaults: unlocked, 1.5 in overcut.</summary>
public static SavedCutOffHeadLock Unsaved { get; } = new(false, DefaultOvercutInches);
/// <summary>The saved values; a missing or unreadable one is its WinForms default.</summary>
public static SavedCutOffHeadLock Read(IReadOnlyDictionary<string, string> settings)
{
ArgumentNullException.ThrowIfNull(settings);
return new SavedCutOffHeadLock(
UserSettingText.ReadBool(settings, LockHeadHeightName, Unsaved.LockHeadHeight),
UserSettingText.ReadDouble(settings, OvercutInchesName, Unsaved.OvercutInches));
}
/// <summary>Stores both values in the WinForms format.</summary>
public void WriteTo(IDictionary<string, string> settings)
{
ArgumentNullException.ThrowIfNull(settings);
settings[LockHeadHeightName] = UserSettingText.Format(LockHeadHeight);
settings[OvercutInchesName] = UserSettingText.Format(OvercutInches);
}
/// <summary>
/// Sets the new cut-off lock and overcut of <paramref name="settings"/> for a nest in
/// <paramref name="units"/>; a saved overcut that is not a positive number is 1.5 in.
/// </summary>
public void ApplyTo(CutOffSettings settings, Units units)
{
ArgumentNullException.ThrowIfNull(settings);
var inches = OvercutInches;
if (!double.IsFinite(inches) || inches <= 0)
inches = DefaultOvercutInches;
settings.LockHeadHeight = LockHeadHeight;
settings.HeadLockOvercut = units == Units.Millimeters ? inches * MillimetersPerInch : inches;
}
/// <summary>What to save for a cut-off choice made in a nest in <paramref name="units"/>.</summary>
public static SavedCutOffHeadLock From(bool lockHeadHeight, double overcut, Units units) =>
new(lockHeadHeight, units == Units.Millimeters ? overcut / MillimetersPerInch : overcut);
}