mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-25 03:37:39 -05:00
fix(planning): cut the remnant cut-offs last
The last strip line stops at the remnant's full-length horizontal separator, so it never counted as separating the sheet and the planner cut it wherever the route passed it, often first (N26-264). That frees the X-tail remnant early and loses the mass that absorbs heat while the parts are cut. A continuous line from a sheet edge or separator to another now counts as a separator too (CutOff.Separators, found in rounds), so Plan Cutting and Part Sequencing cut it after every part, just before the separator it stops on. The problem-nest harness now adds scrap cut-offs with KeepHorizontalRemnant, as both desktop entry points do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5de628760f
commit
6c4ebe49b3
10 files changed
+212
-40
No files matched your search
@@ -86,10 +86,12 @@ internal sealed class CuttingDependencyGraph
|
||||
if (nodes[cut].SeparatesSheet)
|
||||
{
|
||||
// Cutting a line that splits the sheet comes after every part and every other
|
||||
// cutoff, so the head never travels back across the separated edge. Such a line
|
||||
// is continuous, so it passes through no part and needs no crossing edge.
|
||||
// cutoff, so the head never travels back across the separated edge and the
|
||||
// remnant's mass stays on to the end. Among separators, a line stopping on others
|
||||
// (a later round) goes before them. Such a line is continuous, so it passes
|
||||
// through no part and needs no crossing edge.
|
||||
for (var other = 0; other < nodes.Count; other++)
|
||||
if (!nodes[other].SeparatesSheet)
|
||||
if (!nodes[other].SeparatesSheet || nodes[other].SeparatorRound > nodes[cut].SeparatorRound)
|
||||
edges[cut].Add(other);
|
||||
continue;
|
||||
}
|
||||
@@ -208,11 +210,11 @@ internal sealed class DependencyNode
|
||||
private LeadMaterialSnapshot material;
|
||||
|
||||
internal DependencyNode(bool isCutOff, CutOffDefinition cutOff, Box placedBounds, Box cleanBounds,
|
||||
Func<LeadMaterialSnapshot> materialFactory, bool separatesSheet = false, bool cutFirst = false)
|
||||
Func<LeadMaterialSnapshot> materialFactory, int? separatorRound = null, bool cutFirst = false)
|
||||
{
|
||||
IsCutOff = isCutOff;
|
||||
CutFirst = !isCutOff && cutFirst;
|
||||
SeparatesSheet = isCutOff && separatesSheet;
|
||||
SeparatorRound = isCutOff ? separatorRound : null;
|
||||
CutOff = cutOff;
|
||||
PlacedBounds = Copy(placedBounds);
|
||||
CleanBounds = cleanBounds == null ? null : Copy(cleanBounds);
|
||||
@@ -223,8 +225,13 @@ internal sealed class DependencyNode
|
||||
}
|
||||
|
||||
internal bool IsCutOff { get; }
|
||||
/// <summary>A cutoff whose placed program is one continuous cut across the whole sheet.</summary>
|
||||
internal bool SeparatesSheet { get; }
|
||||
/// <summary>
|
||||
/// A cutoff whose placed program is one continuous cut splitting off a piece of the sheet,
|
||||
/// alone or with the separators it stops on (see CutOff.Separators).
|
||||
/// </summary>
|
||||
internal bool SeparatesSheet => SeparatorRound != null;
|
||||
/// <summary>The separator's round: 0 across the whole sheet, higher for lines stopping on earlier rounds.</summary>
|
||||
internal int? SeparatorRound { get; }
|
||||
/// <summary>A part whose drawing asks to be cut before the plate's other parts.</summary>
|
||||
internal bool CutFirst { get; }
|
||||
internal CutOffDefinition CutOff { get; }
|
||||
|
||||
@@ -57,6 +57,8 @@ public static class CuttingPlanService
|
||||
// Each cut-off part cuts one trimmed segment of its line and precedes only the parts
|
||||
// in that segment's span (docs/automatic-scrap-cutoffs.md), not every part the line passes.
|
||||
var spans = new Dictionary<CutOff, Dictionary<Part, (double Start, double End)>>(ReferenceEqualityComparer.Instance);
|
||||
// Lines splitting off a piece of the sheet, alone or with the separators they stop on.
|
||||
IReadOnlyDictionary<Part, int> separators = null;
|
||||
var nodes = new List<DependencyNode>();
|
||||
// Reuse the reader's coordinate validation without publishing its native kernel.
|
||||
var identities = new HashSet<Part>(ReferenceEqualityComparer.Instance);
|
||||
@@ -84,7 +86,9 @@ public static class CuttingPlanService
|
||||
throw new ArgumentException("Placed cutoff program has no nonzero cutting motions.");
|
||||
var defined = definitions.TryGetValue(source.BaseDrawing, out var definition);
|
||||
var sheet = request.Plate.BoundingBox(includeParts: false);
|
||||
var separates = defined && CutOff.SeparatesSheet(source, definition, sheet);
|
||||
separators ??= CutOff.Separators(request.Parts, definitions.Values, sheet);
|
||||
int? round = defined && separators.TryGetValue(source, out var found) ? found : null;
|
||||
var separates = round != null;
|
||||
CutOffDefinition nominal = null;
|
||||
if (defined)
|
||||
{
|
||||
@@ -99,7 +103,7 @@ public static class CuttingPlanService
|
||||
: new(definition.Axis, definition.Position, definition.StartLimit, definition.EndLimit,
|
||||
definition.Gaps);
|
||||
}
|
||||
nodes.Add(new(true, nominal, source.BoundingBox, null, null, separates));
|
||||
nodes.Add(new(true, nominal, source.BoundingBox, null, null, round));
|
||||
// A head-locked far-edge segment may be cut from either end (docs/automatic-scrap-cutoffs.md).
|
||||
FixedProgramPlacement reversed = null;
|
||||
if (defined && CutOff.ReverseAtFarEdge(source.Program) is { } flipped)
|
||||
|
||||
@@ -40,8 +40,8 @@ namespace OpenNest.Engine.Sequencing
|
||||
/// Moves the given cutoffs' segment parts to where the cutoff rules need them while every
|
||||
/// other part and cutoff keeps its position: each segment just before the first part in
|
||||
/// its span of the nominal line (see <see cref="CutOffSegments"/>), or last when it splits
|
||||
/// the whole sheet. One that crosses nothing stays put, unless it would follow a
|
||||
/// sheet-separating cutoff.
|
||||
/// off a piece of the sheet (<see cref="CutOff.Separators(Plate)"/>), before any separator it
|
||||
/// stops on. One that crosses nothing stays put, unless it would follow a separator.
|
||||
/// </summary>
|
||||
public static void PlaceCutOffs(Plate plate, IEnumerable<CutOff> definitions)
|
||||
{
|
||||
@@ -54,15 +54,13 @@ namespace OpenNest.Engine.Sequencing
|
||||
return;
|
||||
var movingParts = new HashSet<Part>(moving.Select(item => item.Segment.Part), ReferenceEqualityComparer.Instance);
|
||||
|
||||
var existing = new Dictionary<Drawing, CutOff>(ReferenceEqualityComparer.Instance);
|
||||
foreach (var cutOff in plate.CutOffs)
|
||||
existing[cutOff.Drawing] = cutOff;
|
||||
var order = plate.Parts.ToList();
|
||||
var separators = CutOff.Separators(plate);
|
||||
var separating = new List<Part>();
|
||||
foreach (var (definition, segment) in moving)
|
||||
{
|
||||
var part = segment.Part;
|
||||
if (CutOff.SeparatesSheet(part, definition, bounds))
|
||||
if (separators.ContainsKey(part))
|
||||
{
|
||||
order.Remove(part);
|
||||
separating.Add(part);
|
||||
@@ -72,14 +70,20 @@ namespace OpenNest.Engine.Sequencing
|
||||
&& CuttingDependencyGraph.CutOffCrosses(definition.Axis, definition.Position,
|
||||
segment.SpanStart, segment.SpanEnd, other.BoundingBox, bounds, definition.Gaps));
|
||||
if (target < 0)
|
||||
target = order.FindIndex(other => other.BaseDrawing.IsCutOff && !movingParts.Contains(other)
|
||||
&& existing.TryGetValue(other.BaseDrawing, out var cut) && CutOff.SeparatesSheet(other, cut, bounds));
|
||||
target = order.FindIndex(other => !movingParts.Contains(other) && separators.ContainsKey(other));
|
||||
if (target < 0 || target > order.IndexOf(part))
|
||||
continue;
|
||||
order.Remove(part);
|
||||
order.Insert(target, part);
|
||||
}
|
||||
order.AddRange(separating);
|
||||
// Each moved separator goes last, but before a staying separator of an earlier round:
|
||||
// one it may stop on.
|
||||
foreach (var part in separating.OrderByDescending(part => separators[part]))
|
||||
{
|
||||
var before = order.FindIndex(other => !movingParts.Contains(other)
|
||||
&& separators.TryGetValue(other, out var round) && round < separators[part]);
|
||||
order.Insert(before < 0 ? order.Count : before, part);
|
||||
}
|
||||
|
||||
// Touch only the moved cutoff parts; real parts never leave the plate.
|
||||
foreach (var part in movingParts)
|
||||
@@ -110,11 +114,12 @@ namespace OpenNest.Engine.Sequencing
|
||||
foreach (var segment in CutOffSegments.Of(cutOff, ordered, bounds))
|
||||
spans[segment.Part] = (segment.SpanStart, segment.SpanEnd);
|
||||
|
||||
// A cutoff that splits the whole sheet goes after every part and other cutoff, so the
|
||||
// head never travels back across it. It passes through no part.
|
||||
var separating = ordered.Where(part => part.BaseDrawing.IsCutOff
|
||||
&& definitions.TryGetValue(part.BaseDrawing, out var definition)
|
||||
&& CutOff.SeparatesSheet(part, definition, bounds)).ToList();
|
||||
// A cutoff that splits off a piece of the sheet goes after every part and other cutoff,
|
||||
// so the head never travels back across it and the remnant's mass stays on to the end;
|
||||
// one stopping on other separators goes before them. It passes through no part.
|
||||
var separators = CutOff.Separators(ordered, plate.CutOffs, bounds);
|
||||
var separating = ordered.Where(separators.ContainsKey)
|
||||
.OrderByDescending(part => separators[part]).ToList();
|
||||
if (separating.Count > 0)
|
||||
{
|
||||
var last = new HashSet<Part>(separating, ReferenceEqualityComparer.Instance);
|
||||
|
||||
Reference in new issue
Block a user