mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-03 13:19:25 -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>
72 lines
2.5 KiB
C#
72 lines
2.5 KiB
C#
namespace OpenNest.Desktop.Tests.Plates;
|
|
|
|
public sealed class SheetOutlineImportTests : IDisposable
|
|
{
|
|
private readonly string directory = Path.Combine(Path.GetTempPath(), "opennest-outline-" + Guid.NewGuid().ToString("N"));
|
|
|
|
public SheetOutlineImportTests() => Directory.CreateDirectory(directory);
|
|
|
|
public void Dispose() => Directory.Delete(directory, recursive: true);
|
|
|
|
private string Write(string name, string svg)
|
|
{
|
|
var path = Path.Combine(directory, name);
|
|
File.WriteAllText(path, svg);
|
|
return path;
|
|
}
|
|
|
|
// A 96 x 48 sheet with a 10 x 10 hole.
|
|
private const string Body =
|
|
"<path d='M0 0 H96 V48 H0 Z'/><path d='M20 20 H30 V30 H20 Z'/>";
|
|
|
|
[Fact]
|
|
public void Read_TakesTheLargestContourAsTheSheetAndTheOthersAsObstacles()
|
|
{
|
|
var path = Write("sheet.svg",
|
|
$"<svg xmlns='http://www.w3.org/2000/svg' width='96in' height='48in' viewBox='0 0 96 48'>{Body}</svg>");
|
|
|
|
Assert.Null(SvgScale.SizeToAsk(path));
|
|
var outline = SheetOutlineImport.Read(path, Units.Inches);
|
|
|
|
Assert.Equal(96, outline.Size.Length, 3);
|
|
Assert.Equal(48, outline.Size.Width, 3);
|
|
Assert.Single(outline.Obstacles);
|
|
}
|
|
|
|
[Fact]
|
|
public void AnSvgWithoutAStatedSize_AsksForItsScale()
|
|
{
|
|
var path = Write("bare.svg", $"<svg xmlns='http://www.w3.org/2000/svg'>{Body}</svg>");
|
|
|
|
var size = SvgScale.SizeToAsk(path);
|
|
|
|
Assert.NotNull(size);
|
|
var outline = SheetOutlineImport.Read(path, Units.Inches, svgUserUnitsPerInch: 1);
|
|
Assert.Equal(96, outline.Size.Length, 3);
|
|
}
|
|
|
|
[Fact]
|
|
public void AFileWithNoClosedContour_IsAReadFailure()
|
|
{
|
|
var path = Write("line.svg",
|
|
"<svg xmlns='http://www.w3.org/2000/svg' width='10in' height='10in' viewBox='0 0 10 10'><path d='M0 0 L10 10'/></svg>");
|
|
|
|
var error = Record.Exception(() => SheetOutlineImport.Read(path, Units.Inches));
|
|
|
|
Assert.NotNull(error);
|
|
Assert.True(SheetOutlineImport.IsReadFailure(error));
|
|
Assert.StartsWith("The file does not hold a sheet outline: ", SheetOutlineImport.FailureText(error));
|
|
}
|
|
|
|
[Fact]
|
|
public void ADxfIsNeverAskedForAScale() =>
|
|
Assert.Null(SvgScale.SizeToAsk(Path.Combine(directory, "sheet.dxf")));
|
|
|
|
[Fact]
|
|
public void ImportedSizeText_ShowsTheSizeInTheNestsUnits()
|
|
{
|
|
Assert.Equal("Imported size: 1.000 x 0.500 in", SvgScale.ImportedSizeText(96, 48, 96, Units.Inches));
|
|
Assert.Equal("Imported size: 25.4 x 12.7 mm", SvgScale.ImportedSizeText(96, 48, 96, Units.Millimeters));
|
|
}
|
|
}
|