mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-16 17:15:33 -05:00
5776fa80 dropped a tabbed outside's lead-out when it would reach the lead-in,
which silently changed the user's cutting settings. The emitter now keeps the
lead-out as configured again. Plan Cutting plans strictly first, as before;
only when that is refused because such a lead-out may cut its tab free does it
plan again keeping the lead-outs. Each affected part gets a "Tab lead-out"
issue (new PostVerificationKind.TabLeadOut), is treated as cut free for later
rapids, and the plan is UNVERIFIED, so applying it needs explicit acceptance.
The short reorder pass never settles for such a plan, so a clean route still
wins. Locked, fixed and posted programs keep the incomplete-check finding.
The "no single tab can steady it" support warnings caused more trouble than
they solved, so a tabbed part now counts as steady wherever its tab is: Plan
Cutting and the pre-post review warn only about a part cut with no tab at
all, and a tabbed part stays crossable once cut instead of being avoided as
one that may tip. Entry choice still prefers the steadiest tab point.
The problem-nest corpus is unchanged except N26-2AM, whose baseline is now
BestEffort with 15 tab lead-out warnings.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
122 lines
5.7 KiB
C#
122 lines
5.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using OpenNest.CNC;
|
|
using OpenNest.CNC.CuttingPlanning;
|
|
using OpenNest.Geometry;
|
|
using OpenNest.Support;
|
|
|
|
namespace OpenNest.Diagnostics;
|
|
|
|
/// <summary>
|
|
/// Pre-post review of part support (docs/support-tabs.md). Every part whose cutting parameters
|
|
/// ask for support tabs and that needs one (<see cref="SupportTabSettings.Analyze"/>: its plate's
|
|
/// support bed cannot hold it level or, by size, its width is in the size range) must be
|
|
/// cut with a tab that keeps it level, however its program was made (planned, placed by hand or
|
|
/// locked); by size any tab will do. The tab is the gap the outside cut leaves between its end and its start. Reports
|
|
/// only; a part whose material or program cannot be read is reported as not checked.
|
|
/// </summary>
|
|
internal static class PartSupportReview
|
|
{
|
|
internal static void Add(Plate plate, int plateNumber, List<PostVerificationFinding> findings,
|
|
CancellationToken token)
|
|
{
|
|
var bed = plate.SupportBed;
|
|
for (var index = 0; index < plate.Parts.Count; index++)
|
|
{
|
|
token.ThrowIfCancellationRequested();
|
|
var part = plate.Parts[index];
|
|
var parameters = part?.CuttingParameters ?? plate.CuttingParameters;
|
|
if (part?.BaseDrawing == null || part.BaseDrawing.IsCutOff || !SupportTabSettings.CanTab(parameters, bed))
|
|
continue;
|
|
var partNumber = index + 1;
|
|
try
|
|
{
|
|
var support = SupportTabSettings.Analyze(parameters, bed, plate.Quadrant, SupportMaterial.FromPart(part));
|
|
if (support == null)
|
|
continue;
|
|
if (!support.IsComplete)
|
|
{
|
|
findings.Add(new(PostVerificationKind.Incomplete, plateNumber, partNumber, null,
|
|
"Support check: " + support.Reason));
|
|
continue;
|
|
}
|
|
if (support.IsSupported)
|
|
continue;
|
|
// A tabbed part counts as steady wherever its tab is.
|
|
if (OutsideTab(ExecutionMotionReader.Read(part.Program, part.Location, null, token)) != null)
|
|
continue;
|
|
findings.Add(new(PostVerificationKind.PartSupport, plateNumber, partNumber, null,
|
|
Message(support))
|
|
{ Location = support.CenterOfGravity });
|
|
}
|
|
catch (Exception exception) when (exception is ArgumentException or InvalidOperationException
|
|
or NotSupportedException or ArithmeticException)
|
|
{
|
|
findings.Add(new(PostVerificationKind.Incomplete, plateNumber, partNumber, null,
|
|
"Support check: " + exception.Message));
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The middle of the gap the outside cut leaves open, or null when it closes: the outside cut
|
|
/// is the chain of cutting motions with the largest extent.
|
|
/// </summary>
|
|
internal static Vector? OutsideTab(OwnedExecution execution)
|
|
{
|
|
Vector? start = null, end = null, bestStart = null, bestEnd = null;
|
|
var minX = double.PositiveInfinity; var minY = double.PositiveInfinity;
|
|
var maxX = double.NegativeInfinity; var maxY = double.NegativeInfinity;
|
|
var bestArea = -1.0;
|
|
foreach (var motion in execution.Motions.Append(null))
|
|
{
|
|
if (motion is { Rapid: false, Layer: LayerType.Cut or LayerType.Display })
|
|
{
|
|
start ??= motion.Start ?? motion.End;
|
|
end = motion.End;
|
|
foreach (var p in new[] { motion.Start ?? motion.End, motion.End, motion.Curve?.Midpoint ?? motion.End })
|
|
{
|
|
minX = System.Math.Min(minX, p.X); minY = System.Math.Min(minY, p.Y);
|
|
maxX = System.Math.Max(maxX, p.X); maxY = System.Math.Max(maxY, p.Y);
|
|
}
|
|
continue;
|
|
}
|
|
// Anything else ends a chain: a rapid, a lead, a scribe or a break cut.
|
|
if (start != null && (maxX - minX) * (maxY - minY) > bestArea)
|
|
{
|
|
bestArea = (maxX - minX) * (maxY - minY);
|
|
bestStart = start;
|
|
bestEnd = end;
|
|
}
|
|
start = end = null;
|
|
minX = minY = double.PositiveInfinity;
|
|
maxX = maxY = double.NegativeInfinity;
|
|
}
|
|
if (bestStart is not { } first || bestEnd is not { } last
|
|
|| first.DistanceTo(last) <= PostVerificationGeometry.Epsilon)
|
|
return null;
|
|
return (first + last) * 0.5;
|
|
}
|
|
|
|
private static string Message(PartSupport support)
|
|
{
|
|
var held = !support.HasBed
|
|
? FormattableString.Invariant($"is {support.Width:0.####} wide, in the width range tabbed by size,")
|
|
: support.IsHeldByTab
|
|
? FormattableString.Invariant($"is {support.Length:0.####} long, short enough for its tab alone to hold,")
|
|
: support.Margin == double.NegativeInfinity
|
|
? "rests on no support contact"
|
|
: support.Margin < 0
|
|
? FormattableString.Invariant($"has its center of gravity {-support.Margin:0.####} outside its support contacts")
|
|
: FormattableString.Invariant($"has its center of gravity only {support.Margin:0.####} inside its support contacts");
|
|
var needs = support.HasBed && !support.IsHeldByTab
|
|
? FormattableString.Invariant($" (needs {support.RequiredMargin:0.####})") : "";
|
|
return $"The part {held}{needs} and it has no tab; it may tip once cut free."
|
|
+ (support.BestTabPoint is { } suggested
|
|
? FormattableString.Invariant($" Tab it near ({suggested.X:0.####}, {suggested.Y:0.####}).")
|
|
: "");
|
|
}
|
|
}
|