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.
public void WriteTo(IDictionary settings)
{
ArgumentNullException.ThrowIfNull(settings);
settings[DrawRapidName] = UserSettingText.Format(DrawRapid);
settings[DrawBoundsName] = UserSettingText.Format(DrawBounds);
}
}