mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-04 19:39:25 -05:00
The cut order comes from Plan Cutting or the user (Manual Sequence, Sequence by Path). The PEP-era sequencers (Right/Left/Bottom Side, Edge Start, Least Code, Advanced) and the parked heat-aware one predate the cutting planner. Only Auto Sequence still ran one (Least Code), and its order was replaced as soon as the plate was planned. Removes Plate > Sequence Parts > Auto Sequence and Nest > Auto Sequence All Plates, the sequencers and their factory, and the old PlateProcessor with its rapid planners, which only tests used. The cutoff ordering rules stay (OrderCutOffsFirst, PlaceCutOffs) and are now tested on given routes. SequenceMethod and SequenceParameters stay so saved cutting settings keep loading. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
2.4 KiB
C#
71 lines
2.4 KiB
C#
using OpenNest.CNC;
|
|
using OpenNest.Geometry;
|
|
|
|
namespace OpenNest.Tests;
|
|
|
|
/// <summary>
|
|
/// Gives every unlocked part on a plate its lead-ins from the plate's cutting parameters, left
|
|
/// to right, the way the retired Assign Lead-ins command did. Post fixtures use it to build
|
|
/// programs with lead-ins without running Plan Cutting, so their expected output is unchanged.
|
|
/// </summary>
|
|
internal static class TestLeadIns
|
|
{
|
|
public static void Apply(Plate plate)
|
|
{
|
|
var parameters = plate.CuttingParameters;
|
|
if (parameters == null)
|
|
return;
|
|
|
|
// Left to right, then bottom to top, starting from the plate's exit corner.
|
|
var sequenced = plate.Parts.OrderBy(p => p.Location.X).ThenBy(p => p.Location.Y).ToList();
|
|
var exitPoint = ExitPoint(plate);
|
|
// The first pass fixes each part's pierce; the second faces each part toward the next pierce.
|
|
var piercePoints = Pass(null);
|
|
Pass(piercePoints);
|
|
|
|
Vector[] Pass(Vector[] nextPiercePoints)
|
|
{
|
|
var pierces = new Vector[sequenced.Count];
|
|
var current = exitPoint;
|
|
for (var i = 0; i < sequenced.Count; i++)
|
|
{
|
|
var part = sequenced[i];
|
|
if (!part.LeadInsLocked)
|
|
{
|
|
if (part.HasManualLeadIns)
|
|
part.RemoveLeadIns();
|
|
var approach = current - part.Location;
|
|
if (nextPiercePoints != null && i + 1 < sequenced.Count)
|
|
part.ApplyLeadIns(parameters, approach, nextPiercePoints[i + 1] - part.Location);
|
|
else
|
|
part.ApplyLeadIns(parameters, approach);
|
|
}
|
|
pierces[i] = Pierce(part);
|
|
current = part.Location;
|
|
}
|
|
return pierces;
|
|
}
|
|
}
|
|
|
|
private static Vector ExitPoint(Plate plate)
|
|
{
|
|
var xExtent = plate.Size.Length;
|
|
var yExtent = plate.Size.Width;
|
|
return plate.Quadrant switch
|
|
{
|
|
2 => new Vector(0, yExtent),
|
|
3 => new Vector(0, 0),
|
|
4 => new Vector(xExtent, 0),
|
|
_ => new Vector(xExtent, yExtent),
|
|
};
|
|
}
|
|
|
|
private static Vector Pierce(Part part)
|
|
{
|
|
foreach (var code in part.Program.Codes)
|
|
if (code is Motion motion)
|
|
return motion.EndPoint + part.Location;
|
|
return part.Location;
|
|
}
|
|
}
|