mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-27 12:41:06 -04:00
Interactive Fill ran the best-fit pair phase first. The first pair computation for a drawing can take about a minute, and until it finished the progress dialog showed no layout, Accept stayed disabled and the status text did not change. The fill now packs the part boxes (RectBestFit) before the pair phase and reports that layout, so Accept is available at once. The layout is only a fallback: strategies still run in their usual order, and a completed fill picks the same winner as before. While the pairs are computed, the detail line reads "Computing best-fit pairs (may take a minute)...". Accept or Stop now stops the wait. The computation keeps running in the background and is cached for the next fill. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using OpenNest.Engine.Fill;
|
|
|
|
namespace OpenNest.Engine.Strategies
|
|
{
|
|
public class PairsFillStrategy : IFillStrategy
|
|
{
|
|
private static readonly AsyncLocal<bool> active = new();
|
|
|
|
public string Name => "Pairs";
|
|
public NestPhase Phase => NestPhase.Pairs;
|
|
public int Order => 100;
|
|
|
|
public List<Part> Fill(FillContext context)
|
|
{
|
|
// Prevent recursive PairFiller — remnant fills within PairFiller
|
|
// create a new engine that runs the full pipeline, which would
|
|
// invoke PairsFillStrategy again, causing deep recursion.
|
|
if (active.Value)
|
|
return null;
|
|
|
|
if (context.PartType == PartType.Circle)
|
|
return null;
|
|
|
|
active.Value = true;
|
|
try
|
|
{
|
|
var comparer = context.Policy?.Comparer;
|
|
var dedup = GridDedup.GetOrCreate(context.SharedState);
|
|
var filler = new PairFiller(context.Plate, comparer, dedup);
|
|
var result = filler.Fill(
|
|
context.Item,
|
|
context.WorkArea,
|
|
context.Token,
|
|
context.ReportProgress
|
|
);
|
|
|
|
if (result.BestFits != null)
|
|
context.SharedState["BestFits"] = result.BestFits;
|
|
|
|
return result.Parts;
|
|
}
|
|
finally
|
|
{
|
|
active.Value = false;
|
|
}
|
|
}
|
|
}
|
|
}
|