mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-07 22:42:10 -04:00
PlateView now follows Plate.PartsReordered, which an applied cutting plan raises once per changed plate: it puts its layout parts in the plate's order (the drawn part numbers are the cutting order), marks them dirty so new programs are redrawn, and raises its own PartsReordered. The overlap overlay treats a reorder like any other part change and marks its report out of date.
43 lines
1.4 KiB
C#
43 lines
1.4 KiB
C#
using OpenNest.Controls;
|
|
using OpenNest.Geometry;
|
|
|
|
namespace OpenNest.WinForms.Tests.Controls;
|
|
|
|
public class PlateViewReorderTests
|
|
{
|
|
[Fact]
|
|
public void FollowsAnInPlaceReorderOfItsCurrentPlateOnly() => StaTestThread.Run(() =>
|
|
{
|
|
var plate = new Plate(100, 100);
|
|
foreach (var x in new[] { 1.0, 12.0, 23.0 })
|
|
plate.Parts.Add(new Part(new Drawing($"part {x}", Square()), new Vector(x, 1)));
|
|
using var view = new PlateView { Plate = plate };
|
|
var parts = plate.Parts.ToArray();
|
|
var raised = 0;
|
|
view.PartsReordered += (_, _) => raised++;
|
|
|
|
plate.Parts.Reorder(new[] { parts[2], parts[0], parts[1] });
|
|
|
|
// Part numbers are drawn from the layout order, so it must follow the plate.
|
|
Assert.Equal(1, raised);
|
|
Assert.Equal(new[] { parts[2], parts[0], parts[1] }, view.LayoutParts.Select(layout => layout.BasePart));
|
|
Assert.All(view.LayoutParts, layout => Assert.True(layout.IsDirty));
|
|
|
|
view.Plate = new Plate(60, 120);
|
|
plate.Parts.Reorder(parts);
|
|
Assert.Equal(1, raised);
|
|
Assert.Empty(view.LayoutParts);
|
|
}, TimeSpan.FromMinutes(1), "The STA test did not complete.");
|
|
|
|
private static CNC.Program Square()
|
|
{
|
|
var program = new CNC.Program();
|
|
program.MoveTo(0, 0);
|
|
program.LineTo(0, 10);
|
|
program.LineTo(10, 10);
|
|
program.LineTo(10, 0);
|
|
program.LineTo(0, 0);
|
|
return program;
|
|
}
|
|
}
|