mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-03 12:09:25 -05:00
PlannedDoor_PostsExactlyItsCutsAndNeverTheOutline posts the same nest twice; the Cincinnati header stamps the clock to the second, so CI failed when the two posts straddled a second boundary. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
129 lines
4.9 KiB
C#
129 lines
4.9 KiB
C#
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using OpenNest.CNC;
|
|
using OpenNest.CNC.CuttingPlanning;
|
|
using OpenNest.Diagnostics;
|
|
using OpenNest.Engine.CuttingPlanning;
|
|
using OpenNest.Geometry;
|
|
using OpenNest.Posts.Cincinnati;
|
|
using OpenNest.Posts.CincinnatiCIFiber;
|
|
using OpenNest.Posts.GravographIS;
|
|
|
|
namespace OpenNest.Tests.CuttingPlanning;
|
|
|
|
/// <summary>No post may cut a supplied blank's display perimeter, planned or not.</summary>
|
|
public class DisplayPerimeterPostTests
|
|
{
|
|
public static IEnumerable<object[]> Posts() => [["cincinnati"], ["cifiber"], ["gravograph"]];
|
|
|
|
private static IPostProcessor Post(string name) => name switch
|
|
{
|
|
"cincinnati" => new CincinnatiPostProcessor(new CincinnatiPostConfig { RequireLibraries = false, ConfigurationName = "CL940", PostedAccuracy = 4 }),
|
|
"cifiber" => new CIFiberPostProcessor(new CIFiberPostConfig { ConfigurationName = "CI FIBER 8K" }),
|
|
_ => new GravographISPostProcessor(),
|
|
};
|
|
|
|
private static string Output(string post, Nest nest)
|
|
{
|
|
// The engraver's writer refuses this fixture's sheet for its work envelope, so compare the
|
|
// geometry its extractor hands the writer: the step that reads part programs.
|
|
if (post == "gravograph")
|
|
return string.Join("\n", new NestPolylineExtractor().ExtractLayered(nest).Select(poly =>
|
|
poly.Layer + ":" + string.Join(";", poly.Points.Select(v => FormattableString.Invariant($"{v.X:R},{v.Y:R}")))));
|
|
using var stream = new MemoryStream();
|
|
Post(post).Post(nest, stream);
|
|
// Posts stamp the wall clock (Cincinnati to the second, CI Fiber to the minute), so two
|
|
// posts of the same nest can straddle a boundary.
|
|
return Regex.Replace(Encoding.UTF8.GetString(stream.ToArray()),
|
|
@"(\d{2}-\d{2}-\d{4}|[A-Z][a-z]+ \d{1,2}, \d{4}) +\d{2}:\d{2}(:\d{2})? [AP]M", "<posted-at>");
|
|
}
|
|
|
|
private static (Nest Nest, Part Part) DoorNest()
|
|
{
|
|
var nest = new Nest("Door") { Units = Units.Inches };
|
|
var drawing = new Drawing("door", DisplayPerimeterTests.Door());
|
|
nest.Drawings.Add(drawing);
|
|
var plate = new Plate(new Size(20, 30));
|
|
var part = new Part(drawing, Vector.Zero);
|
|
plate.Parts.Add(part);
|
|
nest.Plates.Add(plate);
|
|
return (nest, part);
|
|
}
|
|
|
|
private static (Nest Nest, Part Part) PlannedDoorNest()
|
|
{
|
|
var (nest, part) = DoorNest();
|
|
var proposal = CuttingPlanBatch.Capture([nest.Plates[0]], ExplicitContourTests.Parameters(), false).Plan();
|
|
Assert.Equal(CuttingCommitStatus.Applied, proposal.Apply(acceptWarnings: false).Status);
|
|
Assert.True(DisplayPerimeterTail.HasTail(part.Program));
|
|
return (nest, part);
|
|
}
|
|
|
|
[Theory]
|
|
[MemberData(nameof(Posts))]
|
|
public void PlannedDoor_PostsExactlyItsCutsAndNeverTheOutline(string post)
|
|
{
|
|
var (planned, _) = PlannedDoorNest();
|
|
var (stripped, part) = PlannedDoorNest();
|
|
// The same applied plan with its tail removed by hand: what the machine may run.
|
|
Assert.True(part.RestoreLeadInProgram(DisplayPerimeterTail.WithoutTail(part.Program), locked: true));
|
|
|
|
Assert.Equal(Output(post, stripped), Output(post, planned));
|
|
}
|
|
|
|
[Theory]
|
|
[MemberData(nameof(Posts))]
|
|
public void UnplannedDoor_IsRefusedByEveryPost(string post)
|
|
{
|
|
var (nest, _) = DoorNest();
|
|
|
|
var error = Assert.Throws<InvalidOperationException>(() => Output(post, nest));
|
|
|
|
Assert.Contains("display perimeter", error.Message);
|
|
Assert.Contains("Plan Cutting", error.Message);
|
|
}
|
|
|
|
[Theory]
|
|
[MemberData(nameof(Posts))]
|
|
public void UnplannedDoor_IsRefusedBeforeTheOutputFileIsTouched(string post)
|
|
{
|
|
var (nest, _) = DoorNest();
|
|
var directory = Directory.CreateTempSubdirectory("display-perimeter-post-");
|
|
try
|
|
{
|
|
var path = Path.Combine(directory.FullName, "door.cnc");
|
|
File.WriteAllText(path, "PREVIOUS GOOD PROGRAM");
|
|
|
|
Assert.Throws<InvalidOperationException>(() => Post(post).Post(nest, path));
|
|
|
|
Assert.Equal("PREVIOUS GOOD PROGRAM", File.ReadAllText(path));
|
|
Assert.Single(directory.GetFiles());
|
|
}
|
|
finally
|
|
{
|
|
directory.Delete(recursive: true);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void UnplannedDoor_PrePostReviewNamesTheDisplayPerimeter()
|
|
{
|
|
var (nest, _) = DoorNest();
|
|
|
|
var report = PostVerificationAnalyzer.Analyze(nest);
|
|
|
|
Assert.Contains(report.Findings, f => f.Message.Contains("display perimeter", StringComparison.OrdinalIgnoreCase));
|
|
Assert.False(report.CanPost(false));
|
|
}
|
|
|
|
[Fact]
|
|
public void PlannedDoor_PrePostReviewIsClean()
|
|
{
|
|
var (nest, _) = PlannedDoorNest();
|
|
|
|
var report = PostVerificationAnalyzer.Analyze(nest);
|
|
|
|
Assert.DoesNotContain(report.Findings, f => f.Message.Contains("display perimeter", StringComparison.OrdinalIgnoreCase));
|
|
}
|
|
}
|