diff --git a/OpenNest.WinForms.Tests/Forms/NestProgressFormLayoutsTests.cs b/OpenNest.WinForms.Tests/Forms/NestProgressFormLayoutsTests.cs index ed6d503c..325b7b64 100644 --- a/OpenNest.WinForms.Tests/Forms/NestProgressFormLayoutsTests.cs +++ b/OpenNest.WinForms.Tests/Forms/NestProgressFormLayoutsTests.cs @@ -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); }); } diff --git a/OpenNest/Forms/Commands/AutoNestCommand.cs b/OpenNest/Forms/Commands/AutoNestCommand.cs index a3717a9f..02442ffc 100644 --- a/OpenNest/Forms/Commands/AutoNestCommand.cs +++ b/OpenNest/Forms/Commands/AutoNestCommand.cs @@ -15,7 +15,8 @@ namespace OpenNest.Forms.Commands /// /// 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. runs inside the commit's undo record. Returns the plates /// committed, or null when nothing was kept. /// + /// 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. internal static async Task> ReviewAndCommitAsync(IWin32Window owner, EditNestForm target, - NestPipelineResult result, ServerNestDecision server, Action> applying, CancellationToken token) + NestPipelineResult result, ServerNestDecision server, Action> 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())); + /// /// Solves 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. internal static async Task SolveAsync(IWin32Window owner, EditNestForm target, NestPipelineRequest request, CancellationTokenSource cts, bool chooseLayout = false, + TimeSpan? choiceTimeout = null) => + (await SolveAndPickAsync(owner, target, request, cts, chooseLayout, choiceTimeout)).Result; + + /// + /// , also telling whether the user picked the layout in the + /// progress window (Picked) rather than having the run's result taken for them. + /// + 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 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 { diff --git a/OpenNest/Forms/NestProgressForm.cs b/OpenNest/Forms/NestProgressForm.cs index 5a13e19d..8c7e3eed 100644 --- a/OpenNest/Forms/NestProgressForm.cs +++ b/OpenNest/Forms/NestProgressForm.cs @@ -218,6 +218,10 @@ namespace OpenNest.Forms /// The layout the user chose to use; null when none was chosen. internal NestLayoutChoice ChosenLayout { get; private set; } + /// 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. + internal bool LayoutPickedByUser { get; private set; } + /// /// Adds a layout from the running solve to the cards added by ; /// 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;