Files
OpenNest/OpenNest.Desktop/UserSettingText.cs
T
ajandClaude Opus 5.5 a687e8b193 feat(desktop): shared last cut-time settings in the WinForms format
SavedCutTimeSettings reads and writes the cut-time values last used in
Calculate Cut Time or the simulator under the names and text the WinForms
app already stores (LastFeedrate, LastHoleFeedrate, LastRapidFeedrate,
LastPierceTime as invariant decimals, CutTimeSkipEtch "True"/"False",
CutTimeMachine as a machine id or "none"), with each unreadable value
falling back to its WinForms default. It also holds the rules: never-saved
values use the cut-parameter defaults, no hole feed uses the feed, and the
saved machine falls back to the first by name. The WinForms app's
SavedCutParameters and machine box now call it; their behaviour is
unchanged.

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

44 lines
2.2 KiB
C#

using System.Collections.Generic;
using System.Globalization;
namespace OpenNest.Desktop;
/// <summary>
/// Setting values in the text form the WinForms app stores in user-settings.json: what
/// System.Configuration's invariant type converters write and read ("True"/"False", a decimal
/// in "G" form, a double in round-trip "R" form). A value they cannot read stands for the
/// setting's default, as it does in WinForms.
/// </summary>
public static class UserSettingText
{
/// <summary>The stored decimal under <paramref name="name"/>, or <paramref name="fallback"/>.</summary>
public static decimal ReadDecimal(IReadOnlyDictionary<string, string> settings, string name, decimal fallback) =>
settings.TryGetValue(name, out var text)
&& decimal.TryParse(text?.Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out var value)
? value
: fallback;
/// <summary>The stored double under <paramref name="name"/>, or <paramref name="fallback"/>.</summary>
public static double ReadDouble(IReadOnlyDictionary<string, string> settings, string name, double fallback) =>
settings.TryGetValue(name, out var text)
&& double.TryParse(text?.Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out var value)
? value
: fallback;
/// <summary>The stored "True"/"False" under <paramref name="name"/>, or <paramref name="fallback"/>.</summary>
public static bool ReadBool(IReadOnlyDictionary<string, string> settings, string name, bool fallback) =>
settings.TryGetValue(name, out var text) && bool.TryParse(text?.Trim(), out var value)
? value
: fallback;
/// <summary>The stored text under <paramref name="name"/>, or <paramref name="fallback"/>.</summary>
public static string ReadString(IReadOnlyDictionary<string, string> settings, string name, string fallback) =>
settings.TryGetValue(name, out var text) && text is not null ? text : fallback;
public static string Format(decimal value) => value.ToString("G", CultureInfo.InvariantCulture);
public static string Format(double value) => value.ToString("R", CultureInfo.InvariantCulture);
public static string Format(bool value) => value ? "True" : "False";
}