feat(auto-nest): skip the Keep/Discard review after the user picks a layout

Using a layout in the progress window already chooses it, so the review
that followed only repeated the choice. The review still runs when the
layout was taken for the user (one layout, Make Nests' countdown, server
nests), and the validation review still runs for a layout that breaks
rules. Unplaced parts, which only the review named, are listed after the
commit instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Opus 5.5 committed 2026-11-23 00:19:07 -05:00
1 parent 5aa2c45536
commit aa5675dc64
3 files changed
+46 -11

No files matched your search

@@ -104,6 +104,7 @@ public class NestProgressFormLayoutsTests
Assert.True(stopped());
Assert.False(cts.IsCancellationRequested);
Assert.Same(row, form.ChosenLayout);
Assert.True(form.LayoutPickedByUser);
// Already chosen: the finished search does not ask again.
Assert.True(form.ChooseLayoutAsync(Columns()).Result);
Assert.Same(row, form.ChosenLayout);
@@ -124,6 +125,7 @@ public class NestProgressFormLayoutsTests
Button(form, "useLayoutButton").PerformClick();
Assert.True(pick.Result);
Assert.Same(final, form.ChosenLayout);
Assert.True(form.LayoutPickedByUser);
Assert.False(stopped());
Assert.False(cts.IsCancellationRequested);
});
@@ -171,6 +173,8 @@ public class NestProgressFormLayoutsTests
Assert.True(pick.IsCompleted);
Assert.True(pick.Result);
Assert.Same(final, form.ChosenLayout);
// Taken for the user, not picked: the Keep/Discard review still asks.
Assert.False(form.LayoutPickedByUser);
Assert.False(stopped());
Assert.False(cts.IsCancellationRequested);
});
@@ -217,5 +221,6 @@ public class NestProgressFormLayoutsTests
Assert.True(form.ChooseLayoutAsync(final).Result);
Assert.Same(final, form.ChosenLayout);
Assert.False(form.LayoutPickedByUser);
});
}
+36 -11
View File
@@ -15,7 +15,8 @@ namespace OpenNest.Forms.Commands
/// <summary>
/// Auto Nest from the confirmed dialog to the committed plates: owned modal progress with
/// the best plan so far as a sheet strip, whole-job solve, validation review, a Keep/Discard
/// review of the final sheets, commit to empty plates and the result notices. The plate view
/// review of the final sheets (skipped when the user picked the layout in the progress
/// window), commit to empty plates and the result notices. The plate view
/// never shows Auto Nest parts before they are kept: the result is a set of sheets, not
/// parts on the current plate.
/// The caller owns the busy guard, the nesting lockout and the cancellation source.
@@ -120,6 +121,7 @@ namespace OpenNest.Forms.Commands
});
NestPipelineResult result;
ServerNestDecision server = null;
var picked = false;
if (nestOnServer)
{
var solved = await ServerAutoNest.SolveAsync(owner, target, request, cts);
@@ -128,7 +130,7 @@ namespace OpenNest.Forms.Commands
}
else
{
result = await SolveAsync(owner, target, request, cts, chooseLayout: true);
(result, picked) = await SolveAndPickAsync(owner, target, request, cts, chooseLayout: true);
}
cts.Token.ThrowIfCancellationRequested();
@@ -145,7 +147,7 @@ namespace OpenNest.Forms.Commands
target.Nest.SalvageRate = salvageRate;
target.Nest.MinimumRemnantDimension = minRemnantSize;
}
}, cts.Token);
}, cts.Token, layoutPicked: picked);
}
catch (OperationCanceledException) when (cts.IsCancellationRequested)
{
@@ -166,8 +168,12 @@ namespace OpenNest.Forms.Commands
/// too. <paramref name="applying"/> runs inside the commit's undo record. Returns the plates
/// committed, or null when nothing was kept.
/// </summary>
/// <param name="layoutPicked">The user already chose this layout in the progress window:
/// the Keep/Discard review is skipped, and any unplaced parts are named after the commit
/// instead. The validation review still runs when the layout broke rules.</param>
internal static async Task<IReadOnlyList<Plate>> ReviewAndCommitAsync(IWin32Window owner, EditNestForm target,
NestPipelineResult result, ServerNestDecision server, Action<IReadOnlyList<Plate>> applying, CancellationToken token)
NestPipelineResult result, ServerNestDecision server, Action<IReadOnlyList<Plate>> applying, CancellationToken token,
bool layoutPicked = false)
{
var allowInvalid = false;
if (!result.IsValid)
@@ -181,12 +187,13 @@ namespace OpenNest.Forms.Commands
allowInvalid = true;
}
var costs = result.IsValid && result.CanKeep ? NestCostSummary.FromAccepted(result) : null;
var costText = costs?.Basis == "supplied-cost"
? $"Gross sheet cost: {costs.GrossTotal:G}; estimated salvage credit: {costs.SalvageCredit:G}; net score: {costs.NetScore:G}"
: null;
using (var review = new NestReviewForm(result, target.PlateView.ColorScheme, costText))
if (!layoutPicked)
{
var costs = result.IsValid && result.CanKeep ? NestCostSummary.FromAccepted(result) : null;
var costText = costs?.Basis == "supplied-cost"
? $"Gross sheet cost: {costs.GrossTotal:G}; estimated salvage credit: {costs.SalvageCredit:G}; net score: {costs.NetScore:G}"
: null;
using var review = new NestReviewForm(result, target.PlateView.ColorScheme, costText);
if (review.ShowDialog(owner) != DialogResult.OK)
{
await (server?.DiscardAsync() ?? Task.CompletedTask);
@@ -216,10 +223,17 @@ namespace OpenNest.Forms.Commands
target.OverlapDisplay = OverlapDisplayMode.Both;
await target.CheckOverlapsAsync();
}
// Never drop demand silently: without the review, name what was left out here.
if (layoutPicked && result.Unplaced.Count > 0)
MessageBox.Show(owner, UnplacedNotice(result), Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
ShowResultNotices(owner, target, applied);
return applied;
}
internal static string UnplacedNotice(NestPipelineResult result) =>
$"Not placed ({result.Unplaced.Sum(u => u.Count)}):\n\n"
+ string.Join("\n", result.Unplaced.Select(u => u.Describe()));
/// <summary>
/// Solves <paramref name="request"/> off the UI thread behind the owned modal progress
/// window, with the best plan so far as a sheet strip; its Stop cancels
@@ -236,6 +250,15 @@ namespace OpenNest.Forms.Commands
/// until the user picks or discards.</param>
internal static async Task<NestPipelineResult> SolveAsync(IWin32Window owner, EditNestForm target,
NestPipelineRequest request, CancellationTokenSource cts, bool chooseLayout = false,
TimeSpan? choiceTimeout = null) =>
(await SolveAndPickAsync(owner, target, request, cts, chooseLayout, choiceTimeout)).Result;
/// <summary>
/// <see cref="SolveAsync"/>, also telling whether the user picked the layout in the
/// progress window (Picked) rather than having the run's result taken for them.
/// </summary>
internal static async Task<(NestPipelineResult Result, bool Picked)> SolveAndPickAsync(IWin32Window owner,
EditNestForm target, NestPipelineRequest request, CancellationTokenSource cts, bool chooseLayout = false,
TimeSpan? choiceTimeout = null)
{
using var progressForm = new NestProgressForm(cts, showPlateRow: true)
@@ -260,7 +283,7 @@ namespace OpenNest.Forms.Commands
});
var jobProgress = JobEngineNest.CreateLayoutProgress(request.EngineName, progress, layouts);
async Task<NestPipelineResult> RunSolveAsync()
async Task<(NestPipelineResult, bool)> RunSolveAsync()
{
try
{
@@ -283,7 +306,9 @@ namespace OpenNest.Forms.Commands
throw new OperationCanceledException(cts.Token);
}
var chosen = progressForm.ChosenLayout;
return chosen == null ? result : await Task.Run(() => chosen.Accept(cts.Token));
return chosen == null
? (result, false)
: (await Task.Run(() => chosen.Accept(cts.Token)), progressForm.LayoutPickedByUser);
}
finally
{
+5
View File
@@ -218,6 +218,10 @@ namespace OpenNest.Forms
/// <summary>The layout the user chose to use; null when none was chosen.</summary>
internal NestLayoutChoice ChosenLayout { get; private set; }
/// <summary>True when the user used a layout here (Use This Layout or a double-click),
/// rather than the run's result being taken for them.</summary>
internal bool LayoutPickedByUser { get; private set; }
/// <summary>
/// Adds a layout from the running solve to the cards added by <see cref="ShowPlanStrip"/>;
/// <paramref name="best"/> marks the engine's best so far.
@@ -340,6 +344,7 @@ namespace OpenNest.Forms
return;
StopChoiceCountdown();
ChosenLayout = layoutList.Selected;
LayoutPickedByUser = true;
layoutList.AllowSelection = false;
useLayoutButton.Enabled = false;
stopButton.Enabled = false;