mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-16 12:35:34 -05:00
The Auto Nest progress window lists up to three whole-job layouts as cards, the engine's best first and then the best of each other family (sheet count and free-strip direction). Every sheet shows the distance from its parts to the right edge (vertical strips) or the top (horizontal strips), dimensioned on the sheet. Any card can be used: during the search it stops it, and a finished search with more than one layout waits for the pick. The layout used is validated and bound like the engine's own result. Engines may report plans that lost to their best as NestJobStage.PlanAlternative; Irregular, Default and the time-limited solve do. Reporting never changes a layout. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
55 lines
2.5 KiB
C#
55 lines
2.5 KiB
C#
#nullable enable
|
|
using System;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using OpenNest.Engine.Jobs;
|
|
|
|
namespace OpenNest.Engine.NestingEngines;
|
|
|
|
/// <summary>Forwards a candidate run's progress except plate commits, which belong to the result
|
|
/// finally chosen; <see cref="ReportCommits"/> reports those once it is.</summary>
|
|
internal sealed class CandidateProgress(IProgress<NestJobProgress> inner) : IProgress<NestJobProgress>
|
|
{
|
|
public void Report(NestJobProgress value)
|
|
{
|
|
if (value != null && value.Stage != NestJobStage.PlateCommitted)
|
|
inner.Report(value);
|
|
}
|
|
|
|
/// <summary>Reports the plate commits of <paramref name="result"/> in order. The token is
|
|
/// observed before each commit and after the last, as while building a result.</summary>
|
|
public static void ReportCommits(NestJobResult result, IProgress<NestJobProgress>? progress,
|
|
CancellationToken token = default)
|
|
{
|
|
if (progress == null)
|
|
return;
|
|
var parts = 0;
|
|
for (var i = 0; i < result.Plates.Count; i++)
|
|
{
|
|
token.ThrowIfCancellationRequested();
|
|
var plate = result.Plates[i];
|
|
parts += plate.Placements.Count;
|
|
progress.Report(new NestJobProgress(NestJobStage.PlateCommitted, plate.StockId, plate.PlateIndex, i + 1, parts));
|
|
}
|
|
token.ThrowIfCancellationRequested();
|
|
}
|
|
|
|
/// <summary>Reports a whole-job plan as <see cref="NestJobStage.PlanImproved"/>: a proposal
|
|
/// with no committed counts. Reporting never changes the search.</summary>
|
|
public static void ReportPlan(NestJobResult plan, IProgress<NestJobProgress>? progress) =>
|
|
progress?.Report(new NestJobProgress(NestJobStage.PlanImproved, string.Empty, -1, 0, 0, Plan: plan));
|
|
|
|
/// <summary>Reports a whole-job plan that is not the best so far as
|
|
/// <see cref="NestJobStage.PlanAlternative"/>. Reporting never changes the search.</summary>
|
|
public static void ReportAlternative(NestJobResult plan, IProgress<NestJobProgress>? progress) =>
|
|
progress?.Report(new NestJobProgress(NestJobStage.PlanAlternative, string.Empty, -1, 0, 0, Plan: plan));
|
|
|
|
/// <summary>True when both results place the same parts at the same poses on the same stock,
|
|
/// sheet by sheet.</summary>
|
|
public static bool SameLayout(NestJobResult a, NestJobResult b) =>
|
|
ReferenceEquals(a, b)
|
|
|| (a.Plates.Count == b.Plates.Count
|
|
&& a.Plates.Zip(b.Plates).All(p => p.First.StockId == p.Second.StockId
|
|
&& p.First.Placements.SequenceEqual(p.Second.Placements)));
|
|
}
|