using System; using System.Collections.Generic; namespace OpenNest.Desktop.Rendering; /// /// One plate view's View menu toggles, with the WinForms defaults: rapids off, bounds on, and /// pierce points, offset outline, cut direction and support off. Only rapids and bounds are kept /// between sessions, under the WinForms names PlateViewDrawRapid and PlateViewDrawBounds: /// each nest view reads them when it opens and writes its own when it closes. /// public sealed class PlateViewOptions { public const string DrawRapidName = "PlateViewDrawRapid"; public const string DrawBoundsName = "PlateViewDrawBounds"; /// The origin axes through world (0, 0). public bool DrawOrigin { get; set; } = true; public bool DrawRapid { get; set; } public bool DrawPiercePoints { get; set; } /// The box around the selected parts. public bool DrawBounds { get; set; } = true; /// Each part's outline offset by the plate's part spacing. public bool DrawOffset { get; set; } public bool DrawCutDirection { get; set; } /// The support bed, each part's contacts and center of gravity. public bool DrawSupport { get; set; } /// The chord tolerance of the offset outline. public double OffsetTolerance { get; set; } = 0.001; /// A view's toggles with the saved rapids and bounds; missing or unreadable values are defaults. public static PlateViewOptions Read(IReadOnlyDictionary settings) { ArgumentNullException.ThrowIfNull(settings); var options = new PlateViewOptions(); options.DrawRapid = UserSettingText.ReadBool(settings, DrawRapidName, options.DrawRapid); options.DrawBounds = UserSettingText.ReadBool(settings, DrawBoundsName, options.DrawBounds); return options; } /// /// Stores the rapids and bounds toggles in the WinForms format. As the WinForms settings /// provider does, a toggle still at its default is left out unless the file already holds it, /// so a later default change still applies. /// public void WriteTo(IDictionary settings) { ArgumentNullException.ThrowIfNull(settings); var defaults = new PlateViewOptions(); Write(settings, DrawRapidName, DrawRapid, defaults.DrawRapid); Write(settings, DrawBoundsName, DrawBounds, defaults.DrawBounds); } private static void Write(IDictionary settings, string name, bool value, bool fallback) { if (value != fallback || settings.ContainsKey(name)) settings[name] = UserSettingText.Format(value); } }