mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-23 06:37:52 -05:00
A release now ends in nests ready to cut rather than empty drafts, and a merge no longer leaves the draft it cleared waiting for someone to run Auto Nest. "Nest after release" (on by default) runs Auto Nest headless on every released group, new or merged, before anything is uploaded. NestRenest removes every plate and nests each drawing's required quantity onto sheets from the nest's plate defaults and plate-size options. It keeps a layout only when it is valid and keepable, so an invalid result never reaches the server; the nest is saved without sheets and the operator is told to run Auto Nest. Unplaced copies stay as remaining quantity, and the status column lists sheets, utilization and what did not fit. A new Nesting progress stage reports each group, and cancelling while nesting saves nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
100 lines
3.7 KiB
C#
100 lines
3.7 KiB
C#
using OpenNest.Engine;
|
|
using OpenNest.Engine.Jobs;
|
|
using OpenNest.Geometry;
|
|
using OpenNest.Shapes;
|
|
|
|
namespace OpenNest.Tests.Engine;
|
|
|
|
public class NestRenestTests
|
|
{
|
|
private static Nest NestOf(params (string Name, double Length, double Width, int Quantity)[] drawings)
|
|
{
|
|
var nest = new Nest("N26-0001");
|
|
nest.PlateDefaults.Size = new Size(48, 96);
|
|
foreach (var (name, length, width, quantity) in drawings)
|
|
{
|
|
var drawing = new RectangleShape { Name = name, Length = length, Width = width }.GetDrawing();
|
|
drawing.Quantity.Required = quantity;
|
|
nest.Drawings.Add(drawing);
|
|
}
|
|
return nest;
|
|
}
|
|
|
|
[Fact]
|
|
public void Run_DiscardsTheOldLayout_AndNestsTheWholeDemandFromThePlateDefaults()
|
|
{
|
|
var nest = NestOf(("SYN-A", 4, 2, 6), ("SYN-B", 3, 3, 2));
|
|
var old = nest.CreatePlate();
|
|
old.Size = new Size(10, 10);
|
|
old.Parts.Add(new Part(nest.Drawings.First()));
|
|
nest.CreatePlate();
|
|
|
|
var result = NestRenest.Run(nest, "Rectangles");
|
|
|
|
Assert.True(result.Nested, result.Note);
|
|
Assert.DoesNotContain(old, nest.Plates);
|
|
var plate = Assert.Single(nest.Plates);
|
|
Assert.Equal(new Size(48, 96), plate.Size);
|
|
Assert.Equal(8, plate.Parts.Count);
|
|
Assert.All(nest.Drawings, d => Assert.Equal((d.Quantity.Required, 0), (d.Quantity.Nested, d.Quantity.Remaining)));
|
|
Assert.Equal((1, plate.Utilization()), (result.Sheets, result.Utilization));
|
|
Assert.Empty(result.Unplaced);
|
|
Assert.StartsWith("Nested on 1 sheet, ", result.Note);
|
|
}
|
|
|
|
[Fact]
|
|
public void Run_LeavesCopiesThatDoNotFit_AsRemainingQuantity_AndListsThem()
|
|
{
|
|
var nest = NestOf(("SYN-SMALL", 4, 2, 2), ("SYN-HUGE", 200, 200, 1));
|
|
|
|
var result = NestRenest.Run(nest, "Rectangles");
|
|
|
|
Assert.True(result.Nested, result.Note);
|
|
Assert.Equal(2, nest.Plates.Sum(p => p.Parts.Count));
|
|
var huge = nest.Drawings.Single(d => d.Name == "SYN-HUGE");
|
|
Assert.Equal(1, huge.Quantity.Remaining);
|
|
Assert.Same(huge, Assert.Single(result.Unplaced).Drawing);
|
|
Assert.Contains(" 1 copy not placed, left to nest: ", result.Note);
|
|
Assert.Contains("SYN-HUGE: 1 not placed", result.Note);
|
|
}
|
|
|
|
[Fact]
|
|
public void Run_WhenTheLayoutIsInvalid_LeavesTheNestWithoutPlates()
|
|
{
|
|
var nest = NestOf(("SYN-A", 4, 2, 2));
|
|
var old = nest.CreatePlate();
|
|
old.Parts.Add(new Part(nest.Drawings.First()));
|
|
|
|
var result = NestRenest.Run(nest, new OverlappingEngine(), "overlapping");
|
|
|
|
Assert.False(result.Nested);
|
|
Assert.Equal(NestRenest.NotKeptNote, result.Note);
|
|
Assert.Empty(nest.Plates);
|
|
Assert.Equal(2, nest.Drawings.First().Quantity.Remaining);
|
|
}
|
|
|
|
[Fact]
|
|
public void Run_WhenCanceled_KeepsNothing()
|
|
{
|
|
var nest = NestOf(("SYN-A", 4, 2, 2));
|
|
using var canceled = new CancellationTokenSource();
|
|
canceled.Cancel();
|
|
|
|
Assert.Throws<OperationCanceledException>(() => NestRenest.Run(nest, "Rectangles", token: canceled.Token));
|
|
Assert.Empty(nest.Plates);
|
|
}
|
|
|
|
/// <summary>Puts every copy at the same spot, so the layout never validates.</summary>
|
|
private sealed class OverlappingEngine : INestingEngine
|
|
{
|
|
public NestJobResult Solve(NestJob job, IProgress<NestJobProgress>? progress = null,
|
|
CancellationToken token = default)
|
|
{
|
|
var builder = new NestJobResultBuilder(job);
|
|
builder.AddSheet(job.Plates[0], Enumerable.Range(0, job.Parts[0].Quantity)
|
|
.Select(_ => (job.Parts[0].Id, 5.0, 5.0, 0.0)).ToArray());
|
|
return builder.Build(NestJobStopReason.Completed);
|
|
}
|
|
}
|
|
}
|