mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-16 14:55:36 -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>
108 lines
4.5 KiB
C#
108 lines
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using OpenNest.Engine;
|
|
using OpenNest.Engine.Jobs;
|
|
using OpenNest.Engine.Jobs.Adapters;
|
|
using OpenNest.Geometry;
|
|
|
|
namespace OpenNest.Forms
|
|
{
|
|
/// <summary>
|
|
/// Desktop progress adapter for every whole-job engine. Building, validation and binding
|
|
/// belong to the shared NestPipeline.
|
|
/// </summary>
|
|
internal static class JobEngineNest
|
|
{
|
|
/// <summary>
|
|
/// Forwards job progress to a NestProgress sink. An engine's optional LegacyProgress detail
|
|
/// (live preview parts) passes through; otherwise the stage and committed counts become a
|
|
/// description. Committed counts are authoritative only after PlateCommitted.
|
|
/// </summary>
|
|
public static IProgress<NestJobProgress> CreateProgress(
|
|
string engineName,
|
|
IProgress<NestProgress> progress
|
|
) => new ProgressAdapter(engineName, progress, null);
|
|
|
|
/// <summary>
|
|
/// As <see cref="CreateProgress(string, IProgress{NestProgress})"/>, and also sends each
|
|
/// best-plan-so-far report's sheets to <paramref name="plans"/>.
|
|
/// </summary>
|
|
public static IProgress<NestJobProgress> CreateProgress(
|
|
string engineName,
|
|
IProgress<NestProgress> progress,
|
|
IProgress<IReadOnlyList<ProposedPlate>> plans
|
|
) => new ProgressAdapter(engineName, progress, plans == null ? null : value =>
|
|
{
|
|
if (value.Stage == NestJobStage.PlanImproved)
|
|
plans.Report(value.PlanSheets);
|
|
});
|
|
|
|
/// <summary>
|
|
/// As <see cref="CreateProgress(string, IProgress{NestProgress})"/>, and also sends every
|
|
/// plan the engine reports to <paramref name="layouts"/> as a layout the user may choose:
|
|
/// its best so far and the alternatives beside it.
|
|
/// </summary>
|
|
public static IProgress<NestJobProgress> CreateLayoutProgress(
|
|
string engineName,
|
|
IProgress<NestProgress> progress,
|
|
IProgress<NestLayoutReport> layouts
|
|
) => new ProgressAdapter(engineName, progress, value => layouts.Report(new NestLayoutReport(
|
|
new NestLayoutChoice(value.PlanSheets, value.AcceptPlan), value.Stage == NestJobStage.PlanImproved)));
|
|
|
|
public static string Describe(string engineName, NestJobProgress value) => value.Stage switch
|
|
{
|
|
NestJobStage.PlateCommitted =>
|
|
$"{engineName}: committed plate {value.CommittedPlates} ({value.CommittedParts} parts placed)",
|
|
NestJobStage.PlanImproved =>
|
|
$"{engineName}: found a better plan ({value.Plan?.Plates.Count ?? 0} sheets)",
|
|
_ => $"{engineName}: evaluating plate {WorkingPlate(value)} on stock {value.StockId}",
|
|
};
|
|
|
|
/// <summary>One-based plate under evaluation; nesters that do not know it report -1.</summary>
|
|
private static int WorkingPlate(NestJobProgress value) =>
|
|
value.PlateIndex >= 0 ? value.PlateIndex + 1 : value.CommittedPlates + 1;
|
|
|
|
private sealed class ProgressAdapter(
|
|
string engineName,
|
|
IProgress<NestProgress> progress,
|
|
Action<NestJobProgress> plans
|
|
) : IProgress<NestJobProgress>
|
|
{
|
|
public void Report(NestJobProgress value)
|
|
{
|
|
if (value == null)
|
|
return;
|
|
|
|
// A plan sink shows plans as sheets; the plate row keeps tracking the search.
|
|
// An alternative plan is never a stage of the search.
|
|
if (value.Stage == NestJobStage.PlanAlternative
|
|
|| (value.Stage == NestJobStage.PlanImproved && plans != null))
|
|
{
|
|
if (value.PlanSheets != null)
|
|
plans?.Invoke(value);
|
|
return;
|
|
}
|
|
|
|
if (value.LegacyProgress != null)
|
|
{
|
|
progress.Report(value.LegacyProgress);
|
|
return;
|
|
}
|
|
|
|
progress.Report(
|
|
new NestProgress
|
|
{
|
|
Phase = NestPhase.Custom,
|
|
PlateNumber =
|
|
value.Stage == NestJobStage.PlateCommitted
|
|
? value.CommittedPlates
|
|
: WorkingPlate(value),
|
|
Description = Describe(engineName, value),
|
|
}
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|