From 939d7bfff2710987b5a712609c8863bb15f5f9b6 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Thu, 22 Oct 2026 09:42:13 -0400 Subject: [PATCH] feat(desktop): adjust nest quantities from the drawing library dialog After adding library drawings the operator had to close the dialog to see what the nest now needed, and fixing a quantity meant leaving it for Edit Drawing one part at a time. The new In This Nest tab lists the nest's drawings (cutoffs excluded) with their library revision and required, nested and remaining quantities, refreshes after each add, and edits Required in place. An edit applies to the nest immediately, like an add, and the nest window refreshes its drawing list when the dialog closes. Out-of-range values are refused both when the cell is validated and when they are applied, because DataGridView only validates on leaving the cell and EndEdit commits without it. Co-Authored-By: Claude Opus 5.5 --- .../Forms/DrawingLibraryFormTests.cs | 64 +++++++ OpenNest/Forms/DrawingLibraryForm.Designer.cs | 157 +++++++++++++++++- OpenNest/Forms/DrawingLibraryForm.cs | 135 ++++++++++++++- OpenNest/Forms/EditNestForm.cs | 2 +- docs/nest-storage.md | 8 + 5 files changed, 363 insertions(+), 3 deletions(-) diff --git a/OpenNest.WinForms.Tests/Forms/DrawingLibraryFormTests.cs b/OpenNest.WinForms.Tests/Forms/DrawingLibraryFormTests.cs index c2ca8a00..e4ddec9f 100644 --- a/OpenNest.WinForms.Tests/Forms/DrawingLibraryFormTests.cs +++ b/OpenNest.WinForms.Tests/Forms/DrawingLibraryFormTests.cs @@ -91,6 +91,70 @@ public class DrawingLibraryFormTests "The drawing library preview test did not complete."); } + [Fact] + public void InThisNestTab_ListsTheNestsDrawings_AndEditsTheirRequiredQuantity() + { + StaTestThread.Run( + () => + { + var library = new FakeLibrary(); + var record = library.Add("SYN-606", "Synthetic Steel", "Grade A", 0.25, Units.Inches, ""); + var nest = MatchingNest(); + var local = new RectangleShape { Name = "LOCAL-1", Length = 3, Width = 1 }.GetDrawing(); + local.Quantity.Required = 4; + nest.Drawings.Add(local); + var cutoff = new RectangleShape { Name = "CUTOFF", Length = 1, Width = 1 }.GetDrawing(); + cutoff.IsCutOff = true; + nest.Drawings.Add(cutoff); + + using var form = new DrawingLibraryForm(library, Server, nest); + form.ShowMessage = (text, _, _) => throw new Xunit.Sdk.XunitException(text); + form.LoadPreview = (_, _) => Task.FromResult(null!); + form.Show(); + var grid = Field(form, "drawingGrid"); + var nestGrid = Field(form, "nestGrid"); + var nestTab = Field(form, "nestTab"); + + Assert.Equal("In This Nest (1)", nestTab.Text); + Assert.Equal("LOCAL-1", Assert.Single(nestGrid.Rows.Cast()).Cells["nestNameColumn"].Value); + Assert.Equal("Not from the library", nestGrid.Rows[0].Cells["nestLibraryColumn"].Value); + + PumpUntil(() => grid.Rows.Count == 1, "the library page"); + Field(form, "quantityBox").Value = 2; + Run(form.AddSelectedAsync()); + Assert.Equal("In This Nest (2)", nestTab.Text); + Assert.Equal($"Revision {record.Revision}", nestGrid.Rows[1].Cells["nestLibraryColumn"].Value); + Assert.Equal(2, nestGrid.Rows[1].Cells["nestRequiredColumn"].Value); + + Field(form, "tabControl").SelectedTab = nestTab; + var required = nestGrid.Rows[0].Cells["nestRequiredColumn"]; + + nestGrid.CurrentCell = required; + Assert.True(nestGrid.BeginEdit(true)); + nestGrid.EditingControl!.Text = "-1"; + nestGrid.NotifyCurrentCellDirty(true); + // Leaving the cell validates it and keeps the editor open on a bad number. + Assert.Throws(() => nestGrid.CurrentCell = nestGrid.Rows[0].Cells["nestNameColumn"]); + Assert.NotEmpty(nestGrid.Rows[0].ErrorText); + // A commit that skips validation is refused when it is applied. + nestGrid.EndEdit(); + Assert.Equal(4, local.Quantity.Required); + Assert.Equal(4, required.Value); + Assert.False(form.QuantitiesChanged); + + Assert.True(nestGrid.BeginEdit(true)); + nestGrid.EditingControl!.Text = "9"; + nestGrid.NotifyCurrentCellDirty(true); + Assert.True(nestGrid.EndEdit()); + Assert.Equal(9, local.Quantity.Required); + Assert.Equal(9, nestGrid.Rows[0].Cells["nestRemainingColumn"].Value); + Assert.True(form.QuantitiesChanged); + Assert.Contains("11 parts required", Field