From 47b4e8e9a496ec871a347a88d3979396a4c70f58 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Mon, 16 Nov 2026 07:14:51 -0500 Subject: [PATCH] feat(shape-library): remember the last shape, quantity and inputs The Shape Library opened on the first shape with preview defaults every time, so repeat work meant retyping the same dimensions. It now reopens on the shape last shown, with the last quantity, and each shape starts from the values (and configuration) it was last left with. The inputs are kept as JSON in a new ShapeLibraryInputs user setting. Saved values that no longer read as their parameter's type are skipped, and a set that no longer makes a shape falls back to the defaults, so a changed shape definition cannot leave the dialog stuck on a bad input. Co-Authored-By: Claude Opus 5.5 --- .../Forms/ShapeLibraryFormTests.cs | 79 ++++++++++++++ OpenNest/Forms/EditNestForm.cs | 3 +- OpenNest/Forms/MainForm.Nest.cs | 3 +- OpenNest/Forms/ShapeLibraryForm.cs | 100 +++++++++++++++++- OpenNest/Forms/ShapeLibraryInputs.cs | 59 +++++++++++ OpenNest/Properties/Settings.Designer.cs | 13 +++ OpenNest/Properties/Settings.settings | 3 + 7 files changed, 253 insertions(+), 7 deletions(-) create mode 100644 OpenNest/Forms/ShapeLibraryInputs.cs diff --git a/OpenNest.WinForms.Tests/Forms/ShapeLibraryFormTests.cs b/OpenNest.WinForms.Tests/Forms/ShapeLibraryFormTests.cs index 3c693641..20b0a7df 100644 --- a/OpenNest.WinForms.Tests/Forms/ShapeLibraryFormTests.cs +++ b/OpenNest.WinForms.Tests/Forms/ShapeLibraryFormTests.cs @@ -388,6 +388,85 @@ public class ShapeLibraryFormTests Assert.NotEmpty(Find(form, "previewBox").Plate.Parts); }); + [Fact] + public void LastInputsReopenOnTheLastShapeWithEachShapesValues() => ArchUnitsTests.RunSta(() => + { + string json; + using (var form = new ShapeLibraryForm(lastInputs: new ShapeLibraryInputs())) + { + SelectShape(form, typeof(RectangleShape)); + var box = OpenEditor(form, "Length"); + box.Text = "20 1/2"; + Press(box, Keys.Enter); + Find(form, "quantityUpDown").Value = 5; + SelectShape(form, typeof(CircleShape)); + json = form.LastInputs.ToJson(); + } + + using var reopened = new ShapeLibraryForm(lastInputs: ShapeLibraryInputs.Parse(json)); + var preview = Find(reopened, "previewBox"); + Assert.Equal(nameof(CircleShape), reopened.LastInputs.LastShape); + Assert.Equal(5, Find(reopened, "quantityUpDown").Value); + + SelectShape(reopened, typeof(RectangleShape)); + Assert.Equal(20.5, preview.Plate.Parts.Single().BoundingBox.Length, 6); + }); + + [Fact] + public void LastInputsKeepTheChosenConfigurationAndItsEditedValues() => ArchUnitsTests.RunSta(() => + { + string json; + string configuration; + using (var form = new ShapeLibraryForm(lastInputs: new ShapeLibraryInputs())) + { + SelectShape(form, typeof(PipeFlangeShape)); + var configs = Find(form, "configComboBox"); + Assert.True(configs.Items.Count > 1); + configs.SelectedIndex = configs.Items.Count - 1; + configuration = (string)configs.SelectedItem!; + form.EditParameter("Blind"); + json = form.LastInputs.ToJson(); + } + + using var reopened = new ShapeLibraryForm(lastInputs: ShapeLibraryInputs.Parse(json)); + Assert.Equal(configuration, Find(reopened, "configComboBox").SelectedItem); + var blind = Assert.Single(reopened.LastInputs.Shapes[nameof(PipeFlangeShape)].Values, v => v.Key == "Blind"); + var saved = ShapeLibraryInputs.Parse(json).Shapes[nameof(PipeFlangeShape)].Values["Blind"]; + Assert.Equal(saved.GetBoolean(), blind.Value.GetBoolean()); + }); + + [Fact] + public void SavedValuesThatNoLongerMakeAShapeFallBackToTheDefaults() => ArchUnitsTests.RunSta(() => + { + double defaultLength; + using (var form = new ShapeLibraryForm()) + { + SelectShape(form, typeof(RectangleShape)); + defaultLength = Find(form, "previewBox").Plate.Parts.Single().BoundingBox.Length; + } + + var inputs = ShapeLibraryInputs.Parse( + """{"LastShape":"RectangleShape","Shapes":{"RectangleShape":{"Values":{"Length":0,"Width":"wide"}}}}"""); + using var reopened = new ShapeLibraryForm(lastInputs: inputs); + + Assert.Equal(defaultLength, Find(reopened, "previewBox").Plate.Parts.Single().BoundingBox.Length, 6); + Assert.True(Find