mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-01 18:03:16 -05:00
PlateCommands ports the WinForms nest window's plate commands, each one undo step under its WinForms label: Remove Plate, Remove Empty Plates, Duplicate Plate (the copy current, with its own cutting parameters), Move Plate and its Alt+Up/Alt+Down target, Rotate Plate (90 degrees either way or 180), Resize Plate to its parts by the auto-size factor, Set Nest Default Plate, and Edit Plate's commit, where an empty plate's new settings become the nest's defaults and the nested quantities are counted again. NewNestDefaults is what Set as Default saves for new nests: the plate, the saved common-line usage and the nest's machine. PlateEditValues is what Edit Plate edits (quantity, size, part and edge spacing, quadrant, outline), when Done applies and how it writes the plate; SheetOutlineImport reads an outline from a CAD file, and SvgScale holds the scale prompt for an SVG that does not state its size. PlateListRow is the Plates list's row text and its drag drop slots; QuadrantPick the quadrant picker's hit test and cells. The WinForms nest window, plate list, Edit Plate dialog, quadrant picker, SVG scale prompt and Save Current as Defaults delegate to them with unchanged behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
115 lines
4.2 KiB
C#
115 lines
4.2 KiB
C#
using System;
|
|
using OpenNest.Geometry;
|
|
|
|
namespace OpenNest.Desktop;
|
|
|
|
/// <summary>
|
|
/// What the Edit Plate dialog edits: quantity, size, part and edge spacing, quadrant and the
|
|
/// sheet outline. <see cref="FromPlate"/> reads a plate, <see cref="CanApply"/> is when the
|
|
/// dialog's Done button is enabled and <see cref="ApplyTo"/> writes the plate as Done does.
|
|
/// </summary>
|
|
public sealed record PlateEditValues
|
|
{
|
|
/// <summary>The range of the dialog's quantity and spacing boxes (the WinForms box defaults).</summary>
|
|
public const double BoxMinimum = 0;
|
|
|
|
public const double BoxMaximum = 100;
|
|
|
|
/// <summary>Decimals the spacing boxes show.</summary>
|
|
public const int SpacingDecimals = 4;
|
|
|
|
public Size Size { get; init; }
|
|
|
|
public int Quantity { get; init; } = 1;
|
|
|
|
public double PartSpacing { get; init; }
|
|
|
|
public double LeftSpacing { get; init; }
|
|
|
|
public double TopSpacing { get; init; }
|
|
|
|
public double RightSpacing { get; init; }
|
|
|
|
public double BottomSpacing { get; init; }
|
|
|
|
/// <summary>The plate origin's quadrant, 1 to 4.</summary>
|
|
public int Quadrant { get; init; } = 1;
|
|
|
|
/// <summary>
|
|
/// The sheet outline the plate gets: null for a rectangular sheet. An outlined sheet's size
|
|
/// is its outline's bounds (<see cref="WithOutline"/>).
|
|
/// </summary>
|
|
public SheetOutline Outline { get; init; }
|
|
|
|
/// <summary>The plate's current settings.</summary>
|
|
public static PlateEditValues FromPlate(Plate plate)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(plate);
|
|
return new PlateEditValues
|
|
{
|
|
Size = plate.Size,
|
|
Quantity = plate.Quantity,
|
|
PartSpacing = plate.PartSpacing,
|
|
LeftSpacing = plate.EdgeSpacing.Left,
|
|
TopSpacing = plate.EdgeSpacing.Top,
|
|
RightSpacing = plate.EdgeSpacing.Right,
|
|
BottomSpacing = plate.EdgeSpacing.Bottom,
|
|
Quadrant = plate.Quadrant,
|
|
Outline = plate.Outline,
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// These settings with <paramref name="outline"/> (null clears it, keeping the size); an
|
|
/// outline sets the size to its bounds.
|
|
/// </summary>
|
|
public PlateEditValues WithOutline(SheetOutline outline) =>
|
|
outline == null
|
|
? this with { Outline = null }
|
|
: this with { Outline = outline, Size = outline.Size };
|
|
|
|
/// <summary>
|
|
/// Whether Done applies: the edge spacings leave room on the sheet both ways.
|
|
/// </summary>
|
|
public bool CanApply =>
|
|
LeftSpacing + RightSpacing < Size.Length && TopSpacing + BottomSpacing < Size.Width;
|
|
|
|
/// <summary>
|
|
/// Whether Done applies with <paramref name="sizeText"/> typed in the size box: it must
|
|
/// parse as a size ("width x length"), and <see cref="CanApply"/> then holds for it.
|
|
/// </summary>
|
|
public bool CanApplyWithSize(string sizeText, out Size size) =>
|
|
Size.TryParse(sizeText, out size) && (this with { Size = size }).CanApply;
|
|
|
|
/// <summary>Writes the settings to <paramref name="plate"/>, as the dialog's Done does.</summary>
|
|
public void ApplyTo(Plate plate)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(plate);
|
|
// The outline carries its own size; setting the size would drop it.
|
|
if (Outline != null)
|
|
plate.Outline = Outline;
|
|
else
|
|
{
|
|
plate.Size = Size;
|
|
plate.Outline = null;
|
|
}
|
|
plate.EdgeSpacing.Left = LeftSpacing;
|
|
plate.EdgeSpacing.Top = TopSpacing;
|
|
plate.EdgeSpacing.Right = RightSpacing;
|
|
plate.EdgeSpacing.Bottom = BottomSpacing;
|
|
plate.PartSpacing = PartSpacing;
|
|
plate.Quantity = Quantity;
|
|
plate.Quadrant = Quadrant;
|
|
}
|
|
|
|
/// <summary>The dialog's outline line: "Rectangular sheet" or its vertices and obstacles.</summary>
|
|
public static string OutlineText(SheetOutline outline) =>
|
|
outline == null
|
|
? "Rectangular sheet"
|
|
: $"{outline.Points.Count} vertices"
|
|
+ (outline.Obstacles.Count == 0 ? "" : $", {outline.Obstacles.Count} obstacle(s)");
|
|
|
|
/// <summary>The step of the spacing boxes: a quarter inch, or one millimeter.</summary>
|
|
public static double SpacingIncrement(Units units) => units == Units.Inches ? 0.25 : 1;
|
|
}
|