From 35d77239b96a84a02817064da3da82374a27891e Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Thu, 12 Nov 2026 07:18:59 -0500 Subject: [PATCH] feat(machine-config): fill a blank thickness name from the standard gauges Reports now take a thickness's name from the machine config, so a blank Name / Gauge leaves the report with just the decimal. Machine Configuration now fills a blank name from the standard steel gauge or plate fraction table when the thickness value changes, and keeps following the value while the name is still the old value's standard one; a typed name is never replaced. A new thickness starts named for its default 0.25 (1/4"). Existing blank names are not filled on open, so viewing a machine never marks it dirty; editing the value fills them. Co-Authored-By: Claude Opus 5.5 --- .../Forms/MachineCutsFormsTests.cs | 50 +++++++++++++++++ OpenNest/Forms/MachineConfigForm.cs | 53 ++++++++++++------- docs/machine-cutting-defaults.md | 6 +++ 3 files changed, 91 insertions(+), 18 deletions(-) diff --git a/OpenNest.WinForms.Tests/Forms/MachineCutsFormsTests.cs b/OpenNest.WinForms.Tests/Forms/MachineCutsFormsTests.cs index df893dcd..878e37b9 100644 --- a/OpenNest.WinForms.Tests/Forms/MachineCutsFormsTests.cs +++ b/OpenNest.WinForms.Tests/Forms/MachineCutsFormsTests.cs @@ -132,6 +132,56 @@ public class MachineCutsFormsTests }); } + [Fact] + public void GeneralTab_BlankNameFollowsTheValueToItsStandardGaugeUntilOneIsTyped() + { + RunSta(() => + { + var directory = Path.Combine(Path.GetTempPath(), "OpenNestTests", Guid.NewGuid().ToString()); + Directory.CreateDirectory(directory); + try + { + var provider = new LocalJsonProvider(directory); + provider.SaveMachine(new MachineConfig + { + Name = "Laser", + Units = UnitSystem.Inches, + Materials = { new MaterialConfig { Name = "Mild Steel", Thicknesses = { new ThicknessConfig { Value = 0.3 } } } }, + }); + + using var form = new MachineConfigForm(provider); + var node = Descendants(Find(form, "_tree").Nodes).Single(n => n.Tag is ThicknessConfig); + typeof(MachineConfigForm) + .GetMethod("Tree_AfterSelect", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)! + .Invoke(form, new object[] { null, new TreeViewEventArgs(node) }); + var shown = (ThicknessConfig)node.Tag; + + var page = All(form).Single().TabPages.Cast().Single(p => p.Text == "General"); + var value = All(page).First(); + var name = All(page).Single(b => b.PlaceholderText == "e.g. 16 ga"); + Assert.Equal("", shown.Name); + + value.Value = 0.0598m; + Assert.Equal("16 ga", shown.Name); + Assert.Equal("0.0598 (16 ga)", node.Text); + + // Still the old value's standard name, so it follows; no standard match clears it. + value.Value = 0.25m; + Assert.Equal("1/4\"", shown.Name); + value.Value = 0.3m; + Assert.Equal("", shown.Name); + + name.Text = "Shop plate"; + value.Value = 0.0598m; + Assert.Equal("Shop plate", shown.Name); + } + finally + { + Directory.Delete(directory, recursive: true); + } + }); + } + private static IEnumerable Descendants(TreeNodeCollection nodes) => nodes.Cast().SelectMany(n => Descendants(n.Nodes).Prepend(n)); diff --git a/OpenNest/Forms/MachineConfigForm.cs b/OpenNest/Forms/MachineConfigForm.cs index 60133b31..0f58af74 100644 --- a/OpenNest/Forms/MachineConfigForm.cs +++ b/OpenNest/Forms/MachineConfigForm.cs @@ -643,24 +643,6 @@ namespace OpenNest.Forms var layout = CreateDetailLayout(); var row = 0; - AddField( - layout, - ref row, - "Thickness:", - CreateLabeledNumeric( - thickness.Value, - v => - { - thickness.Value = v; - node.Text = ThicknessLabel(thickness); - MarkDirty(); - }, - 4, - LengthUnitSuffix, - 100, - 0.001m - ) - ); var nameBox = CreateTextBox( thickness.Name, v => @@ -671,6 +653,30 @@ namespace OpenNest.Forms } ); nameBox.PlaceholderText = "e.g. 16 ga"; + AddField( + layout, + ref row, + "Thickness:", + CreateLabeledNumeric( + thickness.Value, + v => + { + // A blank name, or one still the standard name of the old value, follows + // the value to its standard gauge or fraction; a typed name stays. + var name = nameBox.Text.Trim(); + var follows = name.Length == 0 || name == StandardThicknessName(thickness.Value); + thickness.Value = v; + if (follows && StandardThicknessName(v) is var standard && standard != name) + nameBox.Text = standard; + node.Text = ThicknessLabel(thickness); + MarkDirty(); + }, + 4, + LengthUnitSuffix, + 100, + 0.001m + ) + ); AddField(layout, ref row, "Name / Gauge:", nameBox); AddField( layout, @@ -1165,6 +1171,16 @@ namespace OpenNest.Forms return panel; } + /// + /// The standard gauge or plate fraction (in the machine's units) + /// matches, such as "16 ga" or "1/4\"", or empty when it matches none. + /// + private string StandardThicknessName(double value) => + StandardThicknesses.Find( + value, + _currentMachine?.Units == UnitSystem.Millimeters ? Units.Millimeters : Units.Inches + )?.Name ?? ""; + private string LengthUnitSuffix(object _) => _currentMachine?.Units == UnitSystem.Millimeters ? "mm" : "in"; @@ -1538,6 +1554,7 @@ namespace OpenNest.Forms var materialNode = _tree.SelectedNode; var thickness = new ThicknessConfig { Value = 0.250 }; + thickness.Name = StandardThicknessName(thickness.Value); material.Thicknesses.Add(thickness); var node = BuildThicknessNode(thickness); materialNode.Nodes.Add(node); diff --git a/docs/machine-cutting-defaults.md b/docs/machine-cutting-defaults.md index c34c0954..6226fe6e 100644 --- a/docs/machine-cutting-defaults.md +++ b/docs/machine-cutting-defaults.md @@ -15,6 +15,12 @@ decimals (PEP stores 3/16 as 0.188) finds the machine's 0.1875; the nearest one file, nothing changes and the previous behavior applies. Lengths are converted from the machine's units to the nest's. +A thickness's **Name / Gauge** ("16 ga") is display only: the tree shows it and nest reports +put it before the decimal. In Machine Configuration a blank name, or one still the standard +name of the old value, follows the thickness value to its standard steel gauge or plate +fraction (`StandardThicknesses`, matched to the displayed precision); a typed name is kept. +A new thickness starts with the name of its default value. + ## Where the Cutting Parameters dialog saves Every setting in Plan Cutting's Cutting Parameters dialog and the Place Lead-in panel is kept on