using System.Windows.Forms;
using OpenNest.CNC;
using OpenNest.Controls;
using OpenNest.Engine.Jobs;
using OpenNest.Forms;
using OpenNest.Geometry;
namespace OpenNest.WinForms.Tests.Forms;
// The picks read here have already completed on this STA thread; nothing blocks.
#pragma warning disable xUnit1031
///
/// The Auto Nest progress window's top layouts: one card per layout with its sheets, and the
/// pick of the layout to use, during the run and once it has finished.
///
public class NestProgressFormLayoutsTests
{
private static readonly Drawing Bracket = new("bracket", Rectangle());
private static readonly NestPlateStock Stock = new("sheet", new Size(48, 96), quantity: null, partSpacing: 0.25);
private static Program Rectangle()
{
var program = new Program();
program.MoveTo(0, 0);
program.LineTo(10, 0);
program.LineTo(10, 20);
program.LineTo(0, 20);
program.LineTo(0, 0);
return program;
}
private static NestLayoutChoice Layout(params (double X, double Y)[] at)
{
var parts = at.Select(p =>
{
var part = new Part(Bracket) { Location = new Vector(p.X, p.Y) };
part.UpdateBounds();
return part;
}).ToList();
return new NestLayoutChoice(new[] { new ProposedPlate(0, Stock, parts) }, _ => null!);
}
private static NestLayoutChoice Columns() => Layout((0, 0), (0, 28), (10, 0));
private static NestLayoutChoice Row() => Layout((0, 0), (40, 0), (86, 0));
private static void WithForm(Action> test) => StaTestThread.Run(() =>
{
using var cts = new CancellationTokenSource();
var stopped = false;
using var form = new NestProgressForm(cts) { AllowAccept = false, HoldOpenUntilCompleted = true };
form.ShowPlanStrip(new ColorScheme(), () => stopped = true);
form.Show();
try
{
test(form, cts, () => stopped);
}
finally
{
form.ShowCompleted();
form.Close();
}
}, TimeSpan.FromSeconds(30), "The STA test did not complete.");
private static Button Button(Form form, string name) =>
Assert.IsType