mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-01 06:41:42 -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>
102 lines
3.4 KiB
C#
102 lines
3.4 KiB
C#
using OpenNest.Geometry;
|
|
|
|
namespace OpenNest.Desktop.Tests.Plates;
|
|
|
|
public class PlateEditValuesTests
|
|
{
|
|
private static SheetOutline Ell() => new(new[]
|
|
{
|
|
new Vector(0, 0), new Vector(96, 0), new Vector(96, 24), new Vector(48, 24), new Vector(48, 48), new Vector(0, 48),
|
|
});
|
|
|
|
[Fact]
|
|
public void FromPlate_ReadsEveryValue_AndApplyToWritesThemBack()
|
|
{
|
|
var plate = new Plate(new Size(48, 96)) { Quantity = 4, PartSpacing = 0.25, Quadrant = 3 };
|
|
plate.EdgeSpacing.Left = 1;
|
|
plate.EdgeSpacing.Top = 2;
|
|
plate.EdgeSpacing.Right = 3;
|
|
plate.EdgeSpacing.Bottom = 4;
|
|
|
|
var values = PlateEditValues.FromPlate(plate);
|
|
Assert.Equal(new Size(48, 96), values.Size);
|
|
Assert.Equal(4, values.Quantity);
|
|
Assert.Equal(0.25, values.PartSpacing);
|
|
Assert.Equal(3, values.Quadrant);
|
|
Assert.Equal((1, 2, 3, 4), (values.LeftSpacing, values.TopSpacing, values.RightSpacing, values.BottomSpacing));
|
|
Assert.Null(values.Outline);
|
|
|
|
var other = new Plate(new Size(10, 10));
|
|
values.ApplyTo(other);
|
|
Assert.Equal(PlateEditValues.FromPlate(plate), PlateEditValues.FromPlate(other));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(1, 1, 1, 1, true)]
|
|
[InlineData(48, 48, 1, 1, false)] // left + right reach the length
|
|
[InlineData(1, 1, 24, 24, false)] // top + bottom reach the width
|
|
public void CanApply_NeedsRoomOnTheSheetBothWays(double left, double right, double top, double bottom, bool expected)
|
|
{
|
|
var values = new PlateEditValues
|
|
{
|
|
Size = new Size(48, 96),
|
|
LeftSpacing = left,
|
|
RightSpacing = right,
|
|
TopSpacing = top,
|
|
BottomSpacing = bottom,
|
|
};
|
|
|
|
Assert.Equal(expected, values.CanApply);
|
|
}
|
|
|
|
[Fact]
|
|
public void CanApplyWithSize_NeedsASizeThatParses()
|
|
{
|
|
var values = new PlateEditValues();
|
|
|
|
Assert.True(values.CanApplyWithSize("48 x 96", out var size));
|
|
Assert.Equal(new Size(48, 96), size);
|
|
Assert.False(values.CanApplyWithSize("48 by", out _));
|
|
Assert.False(values.CanApplyWithSize("0 x 0", out _));
|
|
}
|
|
|
|
[Fact]
|
|
public void AnOutline_SetsTheSize_AndApplyKeepsIt()
|
|
{
|
|
var plate = new Plate(new Size(60, 120));
|
|
var values = PlateEditValues.FromPlate(plate).WithOutline(Ell());
|
|
|
|
Assert.Equal(new Size(48, 96), values.Size);
|
|
values.ApplyTo(plate);
|
|
|
|
Assert.Equal(Ell(), plate.Outline);
|
|
Assert.Equal(new Size(48, 96), plate.Size);
|
|
}
|
|
|
|
[Fact]
|
|
public void ClearingTheOutline_LeavesARectangleOfTheSameSize()
|
|
{
|
|
var plate = new Plate { Outline = Ell(), Quadrant = 2 };
|
|
var values = PlateEditValues.FromPlate(plate).WithOutline(null);
|
|
|
|
values.ApplyTo(plate);
|
|
|
|
Assert.Null(plate.Outline);
|
|
Assert.Equal(new Size(48, 96), plate.Size);
|
|
Assert.Equal(2, plate.Quadrant);
|
|
}
|
|
|
|
[Fact]
|
|
public void OutlineText_DescribesTheSheet()
|
|
{
|
|
Assert.Equal("Rectangular sheet", PlateEditValues.OutlineText(null));
|
|
Assert.Equal("6 vertices", PlateEditValues.OutlineText(Ell()));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(Units.Inches, 0.25)]
|
|
[InlineData(Units.Millimeters, 1)]
|
|
public void SpacingIncrement_IsAQuarterInchOrAMillimeter(Units units, double expected) =>
|
|
Assert.Equal(expected, PlateEditValues.SpacingIncrement(units));
|
|
}
|