From 6b161d7a8b43f89b73524e513165896987228fa0 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Mon, 30 Nov 2026 19:38:44 -0500 Subject: [PATCH] feat(data): store a nest's thickness name and show it Nests showed only the decimal (0.135), while the shop thinks in gauges. A nest now keeps a ThicknessName in its file, record and the server (schema v20), set from Nest Information's new box, which suggests the machine's name or the nearest standard gauge. The Open list, status bar and reports show "10 ga (0.135)"; nests saved without a name get one looked up for display only. Co-Authored-By: Claude Opus 5.5 --- OpenNest.Avalonia/EditNestDialog.cs | 2 + OpenNest.Core/Nest.cs | 20 ++- OpenNest.Data/MachineCuttingDefaults.cs | 18 ++- OpenNest.Data/NestRecord.cs | 6 + OpenNest.Data/NestRecordFactory.cs | 2 + OpenNest.Data/NestSaveSession.cs | 2 +- OpenNest.Data/StandardThicknesses.cs | 16 +++ OpenNest.Data/ThicknessNames.cs | 68 +++++++++++ .../Forms/MainStatusTextTests.cs | 9 +- .../Forms/NestInfoValuesTests.cs | 13 ++ .../NestReportExportTests.cs | 6 + OpenNest.Desktop/Forms/MainStatusText.cs | 26 +++- OpenNest.Desktop/NestInfoValues.cs | 9 +- OpenNest.Desktop/NestReportExport.cs | 18 ++- OpenNest.Desktop/NewNestSource.cs | 1 + OpenNest.IO/NestFormat.cs | 5 + OpenNest.IO/NestReader.cs | 1 + OpenNest.IO/NestWriter.cs | 1 + .../DrawingLibraryDatabaseTests.cs | 8 +- .../DrawingSetDatabaseTests.cs | 4 +- OpenNest.Server.Tests/MaterialListTests.cs | 2 +- .../NestMaterialGradeTests.cs | 2 +- OpenNest.Server.Tests/NestStockCodesTests.cs | 2 +- .../NestThicknessNameTests.cs | 73 +++++++++++ OpenNest.Server.Tests/NestUnitsTests.cs | 2 +- .../SetReleaseDrawingTests.cs | 2 +- OpenNest.Server.Tests/SetReleaseTests.cs | 2 +- OpenNest.Server.Tests/SharedSettingsTests.cs | 2 +- OpenNest.Server/NestDatabase.cs | 31 ++++- OpenNest.Server/NestMetadata.cs | 1 + OpenNest.Tests/Data/ThicknessNamesTests.cs | 115 ++++++++++++++++++ .../IO/NestStatusSerializationTests.cs | 14 +++ .../Forms/EditNestInfoFormTests.cs | 64 ++++++++++ .../Forms/Commands/NestStorageController.cs | 5 +- OpenNest/Forms/EditNestForm.cs | 3 +- OpenNest/Forms/EditNestInfoForm.Designer.cs | 51 +++++--- OpenNest/Forms/EditNestInfoForm.cs | 60 ++++++++- OpenNest/Forms/MachineSettings.cs | 16 +++ OpenNest/Forms/MainStatusBar.cs | 2 +- OpenNest/Forms/SavedNestsForm.cs | 11 +- docs/machine-cutting-defaults.md | 5 +- docs/nest-file-format.md | 3 + docs/nest-storage.md | 21 +++- 43 files changed, 661 insertions(+), 63 deletions(-) create mode 100644 OpenNest.Data/ThicknessNames.cs create mode 100644 OpenNest.Server.Tests/NestThicknessNameTests.cs create mode 100644 OpenNest.Tests/Data/ThicknessNamesTests.cs diff --git a/OpenNest.Avalonia/EditNestDialog.cs b/OpenNest.Avalonia/EditNestDialog.cs index f6b15ba9..b455281b 100644 --- a/OpenNest.Avalonia/EditNestDialog.cs +++ b/OpenNest.Avalonia/EditNestDialog.cs @@ -353,6 +353,8 @@ namespace OpenNest.Avalonia { Name = (name.Text ?? "").Trim(), Thickness = thicknessValue, + // No box edits the name here yet: it stays with its thickness and goes with it. + ThicknessName = thicknessValue == shown.Thickness ? shown.ThicknessName : "", MaterialName = material.Text, MaterialGrade = grade.Text, Customer = customer.Text ?? "", diff --git a/OpenNest.Core/Nest.cs b/OpenNest.Core/Nest.cs index 65cedc57..319a8aab 100644 --- a/OpenNest.Core/Nest.cs +++ b/OpenNest.Core/Nest.cs @@ -53,20 +53,38 @@ namespace OpenNest public string MadeBy { get; set; } = ""; - /// The stock thickness. A different value clears every plate's . + /// + /// The stock thickness. A different value clears every plate's + /// and the , which named the old value. + /// public double Thickness { get { return thickness; } set { if (value != thickness) + { ClearStockItemCodes(); + ThicknessName = ""; + } thickness = value; } } private double thickness; + /// + /// The name the shop calls , such as a gauge ("10 ga") or a fraction + /// ("1/4\""); blank when it has none. Set it after the thickness: a new thickness clears it. + /// + public string ThicknessName + { + get { return thicknessName; } + set { thicknessName = value?.Trim() ?? ""; } + } + + private string thicknessName = ""; + /// /// The stock material. A different name or grade (ignoring case and spacing) clears every /// plate's : the coded items are another material. diff --git a/OpenNest.Data/MachineCuttingDefaults.cs b/OpenNest.Data/MachineCuttingDefaults.cs index 257fd621..a4430e38 100644 --- a/OpenNest.Data/MachineCuttingDefaults.cs +++ b/OpenNest.Data/MachineCuttingDefaults.cs @@ -28,16 +28,24 @@ public static class MachineCuttingDefaults public static ThicknessConfig? Find(MachineConfig? machine, Nest nest) { ArgumentNullException.ThrowIfNull(nest); - var name = nest.Material?.Name; - if (machine == null || string.IsNullOrWhiteSpace(name) || !double.IsFinite(nest.Thickness) || nest.Thickness <= 0) + return Find(machine, nest.Material?.Name, nest.Material?.Grade, nest.Thickness, nest.Units); + } + + /// + /// The thickness settings of for + /// ( when set, otherwise the first grade on file) and + /// in , or null when the machine has none. + /// + public static ThicknessConfig? Find(MachineConfig? machine, string? materialName, string? grade, double value, Units units) + { + if (machine == null || string.IsNullOrWhiteSpace(materialName) || !double.IsFinite(value) || value <= 0) return null; - var grade = nest.Material.Grade; - var material = string.IsNullOrWhiteSpace(grade) ? machine.GetMaterial(name) : machine.GetMaterial(name, grade); + var material = string.IsNullOrWhiteSpace(grade) ? machine.GetMaterial(materialName) : machine.GetMaterial(materialName, grade); if (material == null) return null; - var thickness = nest.Thickness * Scale(nest.Units, machine.Units); + var thickness = value * Scale(units, machine.Units); var tolerance = ThicknessToleranceInches * Scale(Units.Inches, machine.Units); return material.Thicknesses .Where(t => System.Math.Abs(t.Value - thickness) <= tolerance) diff --git a/OpenNest.Data/NestRecord.cs b/OpenNest.Data/NestRecord.cs index a828b968..6492d728 100644 --- a/OpenNest.Data/NestRecord.cs +++ b/OpenNest.Data/NestRecord.cs @@ -34,6 +34,12 @@ public sealed class NestRecord public double Thickness { get; set; } + /// + /// The shop's name for , such as "10 ga"; blank when the nest names + /// none or the server predates thickness names. + /// + public string ThicknessName { get; set; } = ""; + /// /// The nest's units, which is in. The server reads them from the /// archive like the counts; inches when the archive has none or the server predates them. diff --git a/OpenNest.Data/NestRecordFactory.cs b/OpenNest.Data/NestRecordFactory.cs index 04923ca7..ee336332 100644 --- a/OpenNest.Data/NestRecordFactory.cs +++ b/OpenNest.Data/NestRecordFactory.cs @@ -23,6 +23,7 @@ public static class NestRecordFactory nest.DateCreated = record.DateCreated; nest.Material = NestMaterialSelection.ApplyRecorded(nest.Material, record.Material, record.MaterialGrade); nest.Thickness = record.Thickness; + nest.ThicknessName = record.ThicknessName; } /// @@ -46,6 +47,7 @@ public static class NestRecordFactory Material = nest.Material?.Name ?? "", MaterialGrade = nest.Material?.Grade ?? "", Thickness = nest.Thickness, + ThicknessName = nest.ThicknessName ?? "", Units = nest.Units, Status = nest.Status, // The trailing empty plate is the editor's new-plate slot, not a plate of the nest. diff --git a/OpenNest.Data/NestSaveSession.cs b/OpenNest.Data/NestSaveSession.cs index 2613c3b8..c3723837 100644 --- a/OpenNest.Data/NestSaveSession.cs +++ b/OpenNest.Data/NestSaveSession.cs @@ -128,6 +128,6 @@ public sealed class NestSaveSession private static bool SameEditableMetadata(NestRecord a, NestRecord b) => a.Name == b.Name && a.Customer == b.Customer && a.DateCreated == b.DateCreated && a.DateModified == b.DateModified && a.Material == b.Material && a.MaterialGrade == b.MaterialGrade - && a.Thickness == b.Thickness && a.Status == b.Status && a.PlateCount == b.PlateCount && a.PartCount == b.PartCount + && a.Thickness == b.Thickness && a.ThicknessName == b.ThicknessName && a.Status == b.Status && a.PlateCount == b.PlateCount && a.PartCount == b.PartCount && a.Comments == b.Comments && a.MadeBy == b.MadeBy; } diff --git a/OpenNest.Data/StandardThicknesses.cs b/OpenNest.Data/StandardThicknesses.cs index 24ebcf2b..3b58d59b 100644 --- a/OpenNest.Data/StandardThicknesses.cs +++ b/OpenNest.Data/StandardThicknesses.cs @@ -61,6 +61,22 @@ public static partial class StandardThicknesses return Entries.FirstOrDefault(e => System.Math.Abs(ValueIn(e, units) - value) < tolerance); } + /// + /// The entry nearest (in ) within + /// , or null. A loose tolerance names the rounded decimals + /// shops type, such as 0.135 for 10 ga or 0.188 for 3/16". + /// + public static Entry? FindNearest(double value, Units units, double toleranceInches) + { + if (!double.IsFinite(value) || value <= 0) + return null; + var inches = units == Units.Millimeters ? value / MillimetersPerInch : value; + return Entries + .Where(e => System.Math.Abs(e.Inches - inches) <= toleranceInches) + .OrderBy(e => System.Math.Abs(e.Inches - inches)) + .FirstOrDefault(); + } + /// /// Reads a thickness box: a list label, a gauge ("16 ga", "16ga", "#16"), a fraction of /// an inch ("3/32", "1-1/4", "1 1/4\"") or a non-negative number. Blank text reads as 0. diff --git a/OpenNest.Data/ThicknessNames.cs b/OpenNest.Data/ThicknessNames.cs new file mode 100644 index 00000000..f764e4d9 --- /dev/null +++ b/OpenNest.Data/ThicknessNames.cs @@ -0,0 +1,68 @@ +using System.Globalization; + +namespace OpenNest.Data; + +/// +/// The shop's names for thicknesses, such as "10 ga" for 0.135, and the "10 ga (0.135)" text +/// that shows them. A nest stores its name (); one without is +/// named here: the machine's name for its material and thickness first, otherwise the nearest +/// standard gauge or plate fraction. +/// +public static class ThicknessNames +{ + // As machine thicknesses match: decimals typed to three places (0.135 for 10 ga, 0.188 for + // 3/16") still name their gauge, and gauges are far further apart. + private const double ToleranceInches = 0.001; + + /// "10 ga (0.135)", or the plain decimal when is blank. + public static string Format(string? name, double thickness) + { + var number = thickness.ToString("0.####", CultureInfo.CurrentCulture); + return string.IsNullOrWhiteSpace(name) ? number : $"{name.Trim()} ({number})"; + } + + /// The thickness text for : its name, or one looked up, then the decimal. + public static string Format(Nest nest, IEnumerable machines) + { + ArgumentNullException.ThrowIfNull(nest); + var name = string.IsNullOrWhiteSpace(nest.ThicknessName) ? For(machines, nest) : nest.ThicknessName; + return Format(name, nest.Thickness); + } + + /// The thickness text for a saved nest: its stored name, or one looked up, then the decimal. + public static string Format(NestRecord record, IEnumerable machines) + { + ArgumentNullException.ThrowIfNull(record); + var name = string.IsNullOrWhiteSpace(record.ThicknessName) + ? For(machines, record.Material, record.MaterialGrade, record.Thickness, record.Units) + : record.ThicknessName; + return Format(name, record.Thickness); + } + + /// The name for the thickness of ; blank when nothing names it. + public static string For(IEnumerable machines, Nest nest) + { + ArgumentNullException.ThrowIfNull(nest); + return For(machines, nest.Material?.Name, nest.Material?.Grade, nest.Thickness, nest.Units); + } + + /// + /// The name for (in ) of + /// : the first of that names it, otherwise + /// the nearest standard gauge or plate fraction; blank when nothing names it. + /// + public static string For(IEnumerable machines, string? material, string? grade, double thickness, Units units) + { + if (!double.IsFinite(thickness) || thickness <= 0) + return ""; + + foreach (var machine in machines ?? Enumerable.Empty()) + { + var name = MachineCuttingDefaults.Find(machine, material, grade, thickness, units)?.Name; + if (!string.IsNullOrWhiteSpace(name)) + return name.Trim(); + } + + return StandardThicknesses.FindNearest(thickness, units, ToleranceInches)?.Name ?? ""; + } +} diff --git a/OpenNest.Desktop.Tests/Forms/MainStatusTextTests.cs b/OpenNest.Desktop.Tests/Forms/MainStatusTextTests.cs index 11cef2e6..45e63cfd 100644 --- a/OpenNest.Desktop.Tests/Forms/MainStatusTextTests.cs +++ b/OpenNest.Desktop.Tests/Forms/MainStatusTextTests.cs @@ -37,7 +37,14 @@ public sealed class MainStatusTextTests : IDisposable { var nest = new Nest { Thickness = 0.5, Units = Units.Inches, Material = new Material("Mild Steel", "A36", 0.2836) }; - Assert.Equal("Material: Mild Steel A36 · 0.5 in", MainStatusText.Material(nest)); + Assert.Equal("Material: Mild Steel A36 · 1/2\" (0.5 in)", MainStatusText.Material(nest)); + + nest.Thickness = 0.135; + nest.ThicknessName = "Ten"; + Assert.Equal("Material: Mild Steel A36 · Ten (0.135 in)", MainStatusText.Material(nest)); + + nest.Thickness = 0.3; + Assert.Equal("Material: Mild Steel A36 · 0.3 in", MainStatusText.Material(nest)); } [Fact] diff --git a/OpenNest.Desktop.Tests/Forms/NestInfoValuesTests.cs b/OpenNest.Desktop.Tests/Forms/NestInfoValuesTests.cs index df530fe5..6993e961 100644 --- a/OpenNest.Desktop.Tests/Forms/NestInfoValuesTests.cs +++ b/OpenNest.Desktop.Tests/Forms/NestInfoValuesTests.cs @@ -12,6 +12,7 @@ public class NestInfoValuesTests nest.Customer = "Acme"; nest.Notes = "rush"; nest.Thickness = 0.25; + nest.ThicknessName = "1/4\""; nest.Material = new Material("Steel", "A36"); nest.Status = NestStatus.ToBeCut; nest.MadeBy = "someone"; @@ -42,6 +43,7 @@ public class NestInfoValuesTests Assert.Equal("Acme", target.Customer); Assert.Equal("rush", target.Notes); Assert.Equal(0.25, target.Thickness); + Assert.Equal("1/4\"", target.ThicknessName); Assert.Equal("Steel", target.Material.Name); Assert.Equal("A36", target.Material.Grade); Assert.Equal(NestStatus.ToBeCut, target.Status); @@ -103,6 +105,17 @@ public class NestInfoValuesTests Assert.NotEqual(before, NestInfoValues.UndoableKey(nest)); } + [Fact] + public void UndoableKey_RecordsAThicknessNameEdit() + { + var nest = InfoNest(); + var before = NestInfoValues.UndoableKey(nest); + + nest.ThicknessName = "3 ga"; + + Assert.NotEqual(before, NestInfoValues.UndoableKey(nest)); + } + [Fact] public void MaterialNames_MergeThePostsAndTheCatalogOncePerName() { diff --git a/OpenNest.Desktop.Tests/NestReportExportTests.cs b/OpenNest.Desktop.Tests/NestReportExportTests.cs index d51fb21a..9c8a2e47 100644 --- a/OpenNest.Desktop.Tests/NestReportExportTests.cs +++ b/OpenNest.Desktop.Tests/NestReportExportTests.cs @@ -97,10 +97,16 @@ public sealed class NestReportExportTests : IDisposable nest.Machine = new NestMachine(own.Id, own.Name); var named = NestReportExport.Capture(nest, At, new[] { own }, new Dictionary()); + nest.ThicknessName = "Sixteen"; + var stored = NestReportExport.Capture(nest, At, new[] { own }, new Dictionary()); nest.Thickness = 0.25; + var standard = NestReportExport.Capture(nest, At, new[] { own }, new Dictionary()); + nest.Thickness = 0.3; var unnamed = NestReportExport.Capture(nest, At, new[] { own }, new Dictionary()); Assert.Equal("16 ga", named.ThicknessName); + Assert.Equal("Sixteen", stored.ThicknessName); + Assert.Equal("1/4\"", standard.ThicknessName); Assert.Equal("", unnamed.ThicknessName); } diff --git a/OpenNest.Desktop/Forms/MainStatusText.cs b/OpenNest.Desktop/Forms/MainStatusText.cs index 91282ebe..545a663b 100644 --- a/OpenNest.Desktop/Forms/MainStatusText.cs +++ b/OpenNest.Desktop/Forms/MainStatusText.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Reflection; +using OpenNest.Data; using OpenNest.Desktop; using OpenNest.Geometry; @@ -56,17 +57,31 @@ namespace OpenNest.Forms return "Machine: " + (string.IsNullOrWhiteSpace(machine.Name) ? "(unnamed)" : machine.Name.Trim()); } - /// The material text for (see ). + /// + /// The material text for (see + /// ), its thickness named by + /// or, without one, the nearest standard gauge or fraction. + /// public static string Material(Nest nest) { ArgumentNullException.ThrowIfNull(nest); - return Material(nest.Material?.Name, nest.Material?.Grade, nest.Thickness, nest.Units); + var thicknessName = string.IsNullOrWhiteSpace(nest.ThicknessName) + ? ThicknessNames.For(Array.Empty(), nest) + : nest.ThicknessName; + return Material(nest.Material?.Name, nest.Material?.Grade, nest.Thickness, nest.Units, thicknessName); } /// /// Status text for the nest's material, grade and thickness, e.g. "Material: Steel A36 · 0.25 in". /// - public static string Material(string name, string grade, double thickness, Units units) + public static string Material(string name, string grade, double thickness, Units units) => + Material(name, grade, thickness, units, null); + + /// + /// Status text for the nest's material, grade and thickness, the thickness after its name + /// when it has one, e.g. "Material: Steel A36 · 10 ga (0.135 in)". + /// + public static string Material(string name, string grade, double thickness, Units units, string thicknessName) { var parts = new List(); var description = string.Join(" ", new[] { name?.Trim(), grade?.Trim() } @@ -74,7 +89,10 @@ namespace OpenNest.Forms if (description.Length > 0) parts.Add(description); if (thickness > 0) - parts.Add(thickness.ToString("0.####", CultureInfo.CurrentCulture) + " " + UnitsHelper.GetShortString(units)); + { + var value = thickness.ToString("0.####", CultureInfo.CurrentCulture) + " " + UnitsHelper.GetShortString(units); + parts.Add(string.IsNullOrWhiteSpace(thicknessName) ? value : $"{thicknessName.Trim()} ({value})"); + } return "Material: " + (parts.Count == 0 ? "(none)" : string.Join(" · ", parts)); } diff --git a/OpenNest.Desktop/NestInfoValues.cs b/OpenNest.Desktop/NestInfoValues.cs index 6e44f170..450991a2 100644 --- a/OpenNest.Desktop/NestInfoValues.cs +++ b/OpenNest.Desktop/NestInfoValues.cs @@ -7,7 +7,7 @@ using OpenNest.Geometry; namespace OpenNest.Desktop; /// -/// What Nest > Edit (the Edit Nest dialog) edits: the nest's name, dates, thickness, +/// What Nest > Edit (the Edit Nest dialog) edits: the nest's name, dates, thickness and its name, /// material and grade, customer, status, author, units, notes and its plate defaults (size, /// part and edge spacing, quadrant). reads a nest, /// is when the dialog's Done button is enabled and writes the nest as @@ -35,6 +35,9 @@ public sealed record NestInfoValues /// The thickness in . public double Thickness { get; init; } + /// The shop's name for the thickness, such as "10 ga"; blank when it has none. + public string ThicknessName { get; init; } = ""; + public string MaterialName { get; init; } = ""; public string MaterialGrade { get; init; } = ""; @@ -78,6 +81,7 @@ public sealed record NestInfoValues DateCreated = nest.DateCreated, DateLastModified = nest.DateLastModified, Thickness = nest.Thickness, + ThicknessName = nest.ThicknessName ?? "", MaterialName = nest.Material?.Name ?? "", MaterialGrade = nest.Material?.Grade ?? "", Status = nest.Status, @@ -123,6 +127,7 @@ public sealed record NestInfoValues nest.DateCreated = DateCreated; nest.DateLastModified = DateLastModified; nest.Thickness = Thickness; + nest.ThicknessName = ThicknessName; nest.Material = NestMaterialSelection.Apply(nest.Material, MaterialName, MaterialGrade); nest.Status = Status; nest.MadeBy = MadeBy; @@ -151,7 +156,7 @@ public sealed record NestInfoValues { ArgumentNullException.ThrowIfNull(nest); var defaults = nest.PlateDefaults; - return string.Join("|", nest.Units, nest.Notes, nest.Customer, nest.Thickness, nest.Material?.Name, + return string.Join("|", nest.Units, nest.Notes, nest.Customer, nest.Thickness, nest.ThicknessName, nest.Material?.Name, nest.Material?.Grade, defaults.Size, defaults.PartSpacing, defaults.EdgeSpacing.Left, defaults.EdgeSpacing.Bottom, defaults.EdgeSpacing.Right, defaults.EdgeSpacing.Top, defaults.Quadrant); } diff --git a/OpenNest.Desktop/NestReportExport.cs b/OpenNest.Desktop/NestReportExport.cs index ff72bfc7..9c1e8af1 100644 --- a/OpenNest.Desktop/NestReportExport.cs +++ b/OpenNest.Desktop/NestReportExport.cs @@ -37,7 +37,7 @@ public static class NestReportExport /// The report of , captured synchronously while the caller keeps the /// nest stable. The nest material's density comes from (the nest's /// machine, may be null) and the catalog when the material has - /// none, and the thickness's name ("16 ga") from the machine's cutting defaults; with + /// none, and the thickness's name ("16 ga", see ); with /// each plate gets an estimated cut time. /// Capturing reads the nest only: no quantity, selection or dirty-state change. /// @@ -53,13 +53,21 @@ public static class NestReportExport var catalogDensity = MaterialDensityLookup.Resolve(material?.Name, material?.Grade, machine, materials); return NestReportBuilder.Capture(nest, generatedAt, cutParameters, catalogDensity) with { - ThicknessName = MachineThicknessName(machine, nest), + ThicknessName = ThicknessName(machine, nest), }; } - /// The name the machine config gives the nest's thickness ("16 ga"), or empty. - public static string MachineThicknessName(MachineConfig machine, Nest nest) => - MachineCuttingDefaults.Find(machine, nest)?.Name?.Trim() ?? ""; + /// + /// The nest's thickness name ("16 ga"): its own , else the + /// machine's, else the nearest standard gauge or fraction (), or empty. + /// + public static string ThicknessName(MachineConfig machine, Nest nest) + { + ArgumentNullException.ThrowIfNull(nest); + return string.IsNullOrWhiteSpace(nest.ThicknessName) + ? ThicknessNames.For(new[] { machine }, nest) + : nest.ThicknessName.Trim(); + } /// /// The report captured as the desktop apps do, from machines already read: the nest's diff --git a/OpenNest.Desktop/NewNestSource.cs b/OpenNest.Desktop/NewNestSource.cs index 4a149ab7..f4181734 100644 --- a/OpenNest.Desktop/NewNestSource.cs +++ b/OpenNest.Desktop/NewNestSource.cs @@ -102,6 +102,7 @@ public sealed class NewNestSource { nest.Material = new Material(release.MaterialName, release.MaterialGrade); nest.Thickness = release.Thickness; + nest.ThicknessName = ThicknessNames.For(new[] { machine }, nest); MachineCuttingDefaults.ApplySpacingTo(nest, machine); } return nest; diff --git a/OpenNest.IO/NestFormat.cs b/OpenNest.IO/NestFormat.cs index 39c701fb..2de0822f 100644 --- a/OpenNest.IO/NestFormat.cs +++ b/OpenNest.IO/NestFormat.cs @@ -38,6 +38,11 @@ namespace OpenNest.IO public MachineDto Machine { get; init; } public double Thickness { get; init; } + + /// Nest.ThicknessName; omitted when blank, and older files have none. + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string ThicknessName { get; init; } + public MaterialDto Material { get; init; } = new(); public PlateDefaultsDto PlateDefaults { get; init; } = new(); public List Drawings { get; init; } = new(); diff --git a/OpenNest.IO/NestReader.cs b/OpenNest.IO/NestReader.cs index a6836b7e..f0dd7b3e 100644 --- a/OpenNest.IO/NestReader.cs +++ b/OpenNest.IO/NestReader.cs @@ -740,6 +740,7 @@ namespace OpenNest.IO var pd = dto.PlateDefaults; var matDto = dto.Material ?? pd.Material; nest.Thickness = dto.Thickness > 0 ? dto.Thickness : pd.Thickness; + nest.ThicknessName = dto.ThicknessName ?? ""; nest.Material = new Material(matDto.Name, matDto.Grade, matDto.Density); // Plate defaults diff --git a/OpenNest.IO/NestWriter.cs b/OpenNest.IO/NestWriter.cs index 7021a3bc..4641deb8 100644 --- a/OpenNest.IO/NestWriter.cs +++ b/OpenNest.IO/NestWriter.cs @@ -143,6 +143,7 @@ namespace OpenNest.IO ? new MachineDto { Id = machine.Id, Name = machine.Name } : null, Thickness = nest.Thickness, + ThicknessName = string.IsNullOrEmpty(nest.ThicknessName) ? null : nest.ThicknessName, Material = new MaterialDto { Name = nest.Material.Name ?? "", diff --git a/OpenNest.Server.Tests/DrawingLibraryDatabaseTests.cs b/OpenNest.Server.Tests/DrawingLibraryDatabaseTests.cs index 7619e706..67a0db9d 100644 --- a/OpenNest.Server.Tests/DrawingLibraryDatabaseTests.cs +++ b/OpenNest.Server.Tests/DrawingLibraryDatabaseTests.cs @@ -23,7 +23,7 @@ public sealed class DrawingLibraryDatabaseTests using (var database = new NestDatabase(factory.DatabasePath, pooling: false)) Assert.Empty(database.QueryDrawings(new DrawingLibraryQuery { IncludeArchived = true }).Items); Assert.Equal(before, NestDigest(factory.DatabasePath)); - Assert.Equal(19L, Scalar(factory.DatabasePath, "PRAGMA user_version")); + Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version")); } using var upgraded = new NestDatabase(factory.DatabasePath, pooling: false); @@ -44,7 +44,7 @@ public sealed class DrawingLibraryDatabaseTests using (var database = new NestDatabase(factory.DatabasePath, pooling: false)) { - Assert.Equal(19L, Scalar(factory.DatabasePath, "PRAGMA user_version")); + Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version")); Assert.Equal(before, NestDigest(factory.DatabasePath)); // Two distinct blobs across four revisions: the bracket's notes edit and the // plate both reuse the bracket's first package. @@ -81,7 +81,7 @@ public sealed class DrawingLibraryDatabaseTests { using var factory = new ServerFactory(); using (new NestDatabase(factory.DatabasePath, pooling: false)) { } - Execute(factory.DatabasePath, "PRAGMA user_version=20"); + Execute(factory.DatabasePath, "PRAGMA user_version=21"); Assert.Throws(() => new NestDatabase(factory.DatabasePath, pooling: false)); } @@ -106,7 +106,7 @@ public sealed class DrawingLibraryDatabaseTests """); using var upgraded = new NestDatabase(factory.DatabasePath, pooling: false); - Assert.Equal(19L, Scalar(factory.DatabasePath, "PRAGMA user_version")); + Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version")); Assert.Equal(-3, upgraded.GetDrawing(record.Id)!.Settings.Priority); Assert.Equal(-3, Assert.Single(upgraded.DrawingHistory(record.Id, 0, 100)!.Items).Settings.Priority); Assert.Equal(int.MaxValue, upgraded.GetDrawing(other.Id)!.Settings.Priority); diff --git a/OpenNest.Server.Tests/DrawingSetDatabaseTests.cs b/OpenNest.Server.Tests/DrawingSetDatabaseTests.cs index c36cd79c..9792c3a1 100644 --- a/OpenNest.Server.Tests/DrawingSetDatabaseTests.cs +++ b/OpenNest.Server.Tests/DrawingSetDatabaseTests.cs @@ -23,7 +23,7 @@ public sealed class DrawingSetDatabaseTests using (var database = new NestDatabase(factory.DatabasePath, pooling: false)) Assert.Empty(database.QueryDrawingSets(new DrawingSetQuery { IncludeArchived = true }).Items); Assert.Equal(before, Digest(factory.DatabasePath)); - Assert.Equal(19L, Scalar(factory.DatabasePath, "PRAGMA user_version")); + Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version")); } using var upgraded = new NestDatabase(factory.DatabasePath, pooling: false); @@ -48,7 +48,7 @@ public sealed class DrawingSetDatabaseTests Assert.Equal(before, Digest(factory.DatabasePath)); Execute(factory.DatabasePath, "DROP TABLE ix_drawing_set_members_drawing"); using var database = new NestDatabase(factory.DatabasePath, pooling: false); - Assert.Equal(19L, Scalar(factory.DatabasePath, "PRAGMA user_version")); + Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version")); } [Fact] diff --git a/OpenNest.Server.Tests/MaterialListTests.cs b/OpenNest.Server.Tests/MaterialListTests.cs index 5177668b..c4d9d2c7 100644 --- a/OpenNest.Server.Tests/MaterialListTests.cs +++ b/OpenNest.Server.Tests/MaterialListTests.cs @@ -25,7 +25,7 @@ public sealed class MaterialListTests using var upgraded = new NestDatabase(factory.DatabasePath, pooling: false); - Assert.Equal(19L, Scalar(factory.DatabasePath, "PRAGMA user_version")); + Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version")); Assert.Empty(upgraded.ListMaterials()); Assert.Equal((" Stainless ", "304"), (upgraded.Get(nest)!.Material, upgraded.Get(nest)!.MaterialGrade)); Assert.Equal(drawing.MaterialName, upgraded.GetDrawing(drawing.Id)!.MaterialName); diff --git a/OpenNest.Server.Tests/NestMaterialGradeTests.cs b/OpenNest.Server.Tests/NestMaterialGradeTests.cs index d8f614c1..faa130cb 100644 --- a/OpenNest.Server.Tests/NestMaterialGradeTests.cs +++ b/OpenNest.Server.Tests/NestMaterialGradeTests.cs @@ -75,7 +75,7 @@ public sealed class NestMaterialGradeTests Assert.Equal("Stainless", record.Material); Assert.Equal("", record.MaterialGrade); Assert.Equal("", Assert.Single(upgraded.History(id, 0, 10)!.Items).MaterialGrade); - Assert.Equal(19L, Scalar(factory.DatabasePath, "PRAGMA user_version")); + Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version")); } private static NestRecord Record(string name, string material, string grade) => new() diff --git a/OpenNest.Server.Tests/NestStockCodesTests.cs b/OpenNest.Server.Tests/NestStockCodesTests.cs index 087ab69a..67bc2c6c 100644 --- a/OpenNest.Server.Tests/NestStockCodesTests.cs +++ b/OpenNest.Server.Tests/NestStockCodesTests.cs @@ -119,7 +119,7 @@ public sealed class NestStockCodesTests database.SetDeleted(deleted, false, record.Revision); Assert.Equal(["SHEET-1", "SHEET-2"], database.StockCodesInUse(null).Select(u => u.ItemCode)); } - Assert.Equal(19L, Scalar(factory.DatabasePath, "PRAGMA user_version")); + Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version")); } private static Nest Nest(string name, NestStatus status, params string[][] plateCodes) diff --git a/OpenNest.Server.Tests/NestThicknessNameTests.cs b/OpenNest.Server.Tests/NestThicknessNameTests.cs new file mode 100644 index 00000000..77475403 --- /dev/null +++ b/OpenNest.Server.Tests/NestThicknessNameTests.cs @@ -0,0 +1,73 @@ +using OpenNest.Data; +using static OpenNest.Server.Tests.TestDatabase; + +namespace OpenNest.Server.Tests; + +public sealed class NestThicknessNameTests +{ + [Fact] + public void ThicknessName_RoundTripsThroughInsertUpdateAndHistory() + { + using var factory = new ServerFactory(); + using var database = new NestDatabase(factory.DatabasePath, pooling: false); + var id = Guid.NewGuid(); + + var created = database.Insert(id, Record("Job", "10 ga"), [1]); + Assert.Equal("10 ga", created.ThicknessName); + + var unchanged = database.UpdateMetadata(id, Record("Job", "10 ga"), created.Revision)!; + Assert.Equal(created.Revision, unchanged.Revision); + + var updated = database.UpdateMetadata(id, Record("Job", "10 gauge"), created.Revision)!; + Assert.Equal("10 gauge", updated.ThicknessName); + Assert.Equal(created.Revision + 1, updated.Revision); + + var history = database.History(id, 0, 10)!; + Assert.Equal(["10 gauge", "10 ga"], history.Items.Select(r => r.ThicknessName)); + } + + [Fact] + public void Query_SearchesThicknessNames() + { + using var factory = new ServerFactory(); + using var database = new NestDatabase(factory.DatabasePath, pooling: false); + database.Insert(Guid.NewGuid(), Record("A", "10 ga"), [1]); + database.Insert(Guid.NewGuid(), Record("B", "16 ga"), [1]); + + var found = database.Query(new NestQuery { Search = "16 ga" }); + + Assert.Equal("B", Assert.Single(found.Items).Name); + } + + [Fact] + public void Version19Database_GainsBlankThicknessNamesAndKeepsRecords() + { + using var factory = new ServerFactory(); + var id = Guid.NewGuid(); + using (var database = new NestDatabase(factory.DatabasePath, pooling: false)) + database.Insert(id, Record("Legacy", "10 ga"), [1]); + Execute(factory.DatabasePath, """ + ALTER TABLE nests DROP COLUMN thicknessName; + ALTER TABLE nest_revisions DROP COLUMN thicknessName; + PRAGMA user_version=19; + """); + + using var upgraded = new NestDatabase(factory.DatabasePath, pooling: false); + + var record = upgraded.Get(id)!; + Assert.Equal(0.135, record.Thickness); + Assert.Equal("", record.ThicknessName); + Assert.Equal("", Assert.Single(upgraded.History(id, 0, 10)!.Items).ThicknessName); + Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version")); + } + + private static NestRecord Record(string name, string thicknessName) => new() + { + Name = name, + Material = "Mild Steel", + Thickness = 0.135, + ThicknessName = thicknessName, + DateCreated = new DateTime(2026, 1, 1), + DateModified = new DateTime(2026, 1, 2), + }; +} diff --git a/OpenNest.Server.Tests/NestUnitsTests.cs b/OpenNest.Server.Tests/NestUnitsTests.cs index afef63b7..dee4bc49 100644 --- a/OpenNest.Server.Tests/NestUnitsTests.cs +++ b/OpenNest.Server.Tests/NestUnitsTests.cs @@ -77,7 +77,7 @@ public sealed class NestUnitsTests Assert.Equal([Units.Millimeters, Units.Millimeters], upgraded.History(metric, 0, 10)!.Items.Select(r => r.Units)); Assert.Equal(Units.Inches, upgraded.Get(inch)!.Units); Assert.Equal(Units.Inches, upgraded.Get(unreadable)!.Units); - Assert.Equal(19L, Scalar(factory.DatabasePath, "PRAGMA user_version")); + Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version")); } private static NestRecord Record(string name, Units units) => new() diff --git a/OpenNest.Server.Tests/SetReleaseDrawingTests.cs b/OpenNest.Server.Tests/SetReleaseDrawingTests.cs index 930186b1..6a41120c 100644 --- a/OpenNest.Server.Tests/SetReleaseDrawingTests.cs +++ b/OpenNest.Server.Tests/SetReleaseDrawingTests.cs @@ -152,7 +152,7 @@ public sealed class SetReleaseDrawingTests using var upgraded = new NestDatabase(factory.DatabasePath, pooling: false); - Assert.Equal(19L, Scalar(factory.DatabasePath, "PRAGMA user_version")); + Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version")); var kept = upgraded.GetRelease(releaseId)!; Assert.Empty(kept.Drawings); Assert.Equal(((Guid?)kit.Id, drawing, 2), (kept.Nests[0].Items.Single().SetId, kept.Nests[0].Items.Single().DrawingId, kept.Nests[0].Items.Single().Quantity)); diff --git a/OpenNest.Server.Tests/SetReleaseTests.cs b/OpenNest.Server.Tests/SetReleaseTests.cs index 58ca473c..52a1ed05 100644 --- a/OpenNest.Server.Tests/SetReleaseTests.cs +++ b/OpenNest.Server.Tests/SetReleaseTests.cs @@ -295,7 +295,7 @@ public sealed class SetReleaseTests using var upgraded = new NestDatabase(factory.DatabasePath, pooling: false); - Assert.Equal(19L, Scalar(factory.DatabasePath, "PRAGMA user_version")); + Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version")); Assert.Equal(0L, Scalar(factory.DatabasePath, "SELECT COUNT(*) FROM sqlite_master WHERE name LIKE 'set_release%' OR name LIKE 'ix_set_release%'")); var release = upgraded.GetRelease(releaseId)!; Assert.Equal(("Legacy notes", "Legacy operator", false), (release.Notes, release.ReleasedBy, release.IsUndone)); diff --git a/OpenNest.Server.Tests/SharedSettingsTests.cs b/OpenNest.Server.Tests/SharedSettingsTests.cs index 3d3a897a..cc3fb297 100644 --- a/OpenNest.Server.Tests/SharedSettingsTests.cs +++ b/OpenNest.Server.Tests/SharedSettingsTests.cs @@ -101,7 +101,7 @@ public sealed class SharedSettingsTests using var upgraded = new NestDatabase(factory.DatabasePath, pooling: false); - Assert.Equal(19L, Scalar(factory.DatabasePath, "PRAGMA user_version")); + Assert.Equal(20L, Scalar(factory.DatabasePath, "PRAGMA user_version")); Assert.Empty(upgraded.ListSharedSettings()); } diff --git a/OpenNest.Server/NestDatabase.cs b/OpenNest.Server/NestDatabase.cs index db2411dd..77e4899e 100644 --- a/OpenNest.Server/NestDatabase.cs +++ b/OpenNest.Server/NestDatabase.cs @@ -154,10 +154,10 @@ public sealed partial class NestDatabase : IDisposable command.Transaction = transaction; command.CommandText = """ INSERT INTO nests (id, name, customer, dateCreated, dateModified, material, - materialGrade, thickness, units, status, plateCount, partCount, comments, madeBy, + materialGrade, thickness, thicknessName, units, status, plateCount, partCount, comments, madeBy, fileSize, savedAt, file) VALUES ($id, $name, $customer, $dateCreated, $dateModified, $material, - $materialGrade, $thickness, $units, $status, $plateCount, $partCount, $comments, + $materialGrade, $thickness, $thicknessName, $units, $status, $plateCount, $partCount, $comments, $madeBy, $fileSize, $savedAt, $file) """; AddRecordParameters(command, id, record, file, updateFile: true); @@ -212,7 +212,7 @@ public sealed partial class NestDatabase : IDisposable UPDATE nests SET name = $name, customer = $customer, dateCreated = $dateCreated, dateModified = $dateModified, material = $material, - materialGrade = $materialGrade, thickness = $thickness, units = $units, status = $status, plateCount = $plateCount, + materialGrade = $materialGrade, thickness = $thickness, thicknessName = $thicknessName, units = $units, status = $status, plateCount = $plateCount, partCount = $partCount, comments = $comments, madeBy = $madeBy, savedAt = $savedAt, revision = $revision, restoredFromRevision=$source{fileClause} WHERE id = $id @@ -319,7 +319,7 @@ public sealed partial class NestDatabase : IDisposable private static bool SameMetadata(NestRecord a, NestRecord b) => a.Name == b.Name && a.Customer == b.Customer && a.DateCreated == b.DateCreated && a.DateModified == b.DateModified && a.Material == b.Material && a.MaterialGrade == b.MaterialGrade && - a.Thickness == b.Thickness && a.Units == b.Units && a.Status == b.Status && a.PlateCount == b.PlateCount && a.PartCount == b.PartCount && + a.Thickness == b.Thickness && a.ThicknessName == b.ThicknessName && a.Units == b.Units && a.Status == b.Status && a.PlateCount == b.PlateCount && a.PartCount == b.PartCount && a.Comments == b.Comments && a.MadeBy == b.MadeBy; private void Snapshot(Guid id, SqliteTransaction transaction) @@ -352,7 +352,7 @@ public sealed partial class NestDatabase : IDisposable command.Transaction = transaction; command.CommandText = "PRAGMA user_version"; var version = (long)command.ExecuteScalar()!; - if (version > 19) throw new InvalidOperationException("Database schema is newer than this server."); + if (version > 20) throw new InvalidOperationException("Database schema is newer than this server."); if (version == 0) { command.CommandText = """ @@ -469,6 +469,22 @@ public sealed partial class NestDatabase : IDisposable command.CommandText = DrawingGeometrySchema; command.ExecuteNonQuery(); } + if (version < 20) + { + // Thickness names ("10 ga"); existing records stay blank until saved again, and + // clients name their thickness from the machines meanwhile. + foreach (var table in new[] { "nests", "nest_revisions" }) + { + command.CommandText = $"SELECT COUNT(*) FROM pragma_table_info('{table}') WHERE name='thicknessName'"; + if ((long)command.ExecuteScalar()! == 0) + { + command.CommandText = $"ALTER TABLE {table} ADD COLUMN thicknessName TEXT NOT NULL DEFAULT ''"; + command.ExecuteNonQuery(); + } + } + command.CommandText = "PRAGMA user_version=20"; + command.ExecuteNonQuery(); + } transaction.Commit(); } } @@ -542,7 +558,7 @@ public sealed partial class NestDatabase : IDisposable private const string RecordColumns = """ id, name, customer, dateCreated, dateModified, material, thickness, status, plateCount, partCount, comments, madeBy, fileSize, savedAt, revision, deleted, restoredFromRevision, - materialGrade, units + materialGrade, units, thicknessName """; // Case-insensitive (ASCII) substring over the text columns and the status's stored @@ -552,6 +568,7 @@ public sealed partial class NestDatabase : IDisposable OR customer LIKE $pattern ESCAPE '\' OR material LIKE $pattern ESCAPE '\' OR materialGrade LIKE $pattern ESCAPE '\' + OR thicknessName LIKE $pattern ESCAPE '\' OR madeBy LIKE $pattern ESCAPE '\' OR comments LIKE $pattern ESCAPE '\' OR status LIKE $pattern ESCAPE '\' @@ -650,6 +667,7 @@ public sealed partial class NestDatabase : IDisposable command.Parameters.AddWithValue("$material", record.Material); command.Parameters.AddWithValue("$materialGrade", record.MaterialGrade); command.Parameters.AddWithValue("$thickness", record.Thickness); + command.Parameters.AddWithValue("$thicknessName", record.ThicknessName ?? ""); command.Parameters.AddWithValue("$units", record.Units.ToString()); command.Parameters.AddWithValue("$status", record.Status.ToString()); command.Parameters.AddWithValue("$plateCount", record.PlateCount); @@ -689,6 +707,7 @@ public sealed partial class NestDatabase : IDisposable RestoredFromRevision = reader.IsDBNull(first + 16) ? null : reader.GetInt32(first + 16), MaterialGrade = reader.GetString(first + 17), Units = Enum.TryParse(reader.GetString(first + 18), true, out var units) ? units : Units.Inches, + ThicknessName = reader.GetString(first + 19), }; } } diff --git a/OpenNest.Server/NestMetadata.cs b/OpenNest.Server/NestMetadata.cs index 212e6532..e37779fd 100644 --- a/OpenNest.Server/NestMetadata.cs +++ b/OpenNest.Server/NestMetadata.cs @@ -52,6 +52,7 @@ internal static class NestMetadata if (record.Customer is null) return "customer must be a string."; if (record.Material is null) return "material must be a string."; if (record.MaterialGrade is null) return "materialGrade must be a string."; + if (record.ThicknessName is null) return "thicknessName must be a string."; if (record.Comments is null) return "comments must be a string."; if (record.MadeBy is null) return "madeBy must be a string."; if (!Enum.IsDefined(record.Status)) return "status must be draft, quote, toBeCut or hasBeenCut."; diff --git a/OpenNest.Tests/Data/ThicknessNamesTests.cs b/OpenNest.Tests/Data/ThicknessNamesTests.cs new file mode 100644 index 00000000..bdc71fbc --- /dev/null +++ b/OpenNest.Tests/Data/ThicknessNamesTests.cs @@ -0,0 +1,115 @@ +using OpenNest.Data; + +namespace OpenNest.Tests.Data; + +public class ThicknessNamesTests +{ + private static MachineConfig Machine(UnitSystem units = UnitSystem.Inches, double value = 0.135, string name = "10 ga") => new() + { + Name = "Fiber 1", + Units = units, + Materials = + { + new MaterialConfig + { + Name = "Mild Steel", + Grade = "HR", + Thicknesses = { new ThicknessConfig { Value = value, Name = name } }, + }, + }, + }; + + [Fact] + public void Format_PutsTheDecimalInParentheses() + { + Assert.Equal("10 ga (0.135)", ThicknessNames.Format(" 10 ga ", 0.135)); + Assert.Equal("0.135", ThicknessNames.Format("", 0.135)); + Assert.Equal("0.135", ThicknessNames.Format(null, 0.135)); + } + + [Fact] + public void For_TakesTheMachinesNameForTheMaterialAndThickness() + { + var machines = new[] { Machine(name: "10 gauge") }; + + Assert.Equal("10 gauge", ThicknessNames.For(machines, "mild steel", "hr", 0.135, Units.Inches)); + // Another material falls back to the standard gauges. + Assert.Equal("10 ga", ThicknessNames.For(machines, "Aluminum", "", 0.135, Units.Inches)); + } + + [Fact] + public void For_ConvertsBetweenTheNestAndMachineUnits() + { + var machines = new[] { Machine(UnitSystem.Millimeters, 3.429, "10 gauge") }; + + Assert.Equal("10 gauge", ThicknessNames.For(machines, "Mild Steel", "HR", 0.135, Units.Inches)); + } + + [Fact] + public void For_SkipsAMachineThatLeavesTheThicknessUnnamed() + { + var machines = new[] { Machine(name: ""), Machine(name: "Ten") }; + + Assert.Equal("Ten", ThicknessNames.For(machines, "Mild Steel", "HR", 0.135, Units.Inches)); + } + + [Theory] + [InlineData(0.135, "10 ga")] + [InlineData(0.06, "16 ga")] + [InlineData(0.075, "14 ga")] + [InlineData(0.105, "12 ga")] + [InlineData(0.188, "3/16\"")] + [InlineData(0.25, "1/4\"")] + [InlineData(0.3, "")] + [InlineData(0, "")] + public void For_NamesTheShopsRoundedDecimalsByTheNearestStandardEntry(double thickness, string expected) + { + Assert.Equal(expected, ThicknessNames.For(Array.Empty(), "Mild Steel", "HR", thickness, Units.Inches)); + } + + [Fact] + public void For_ReadsMillimeterNests() + { + Assert.Equal("10 ga", ThicknessNames.For(Array.Empty(), "", "", 3.43, Units.Millimeters)); + } + + [Fact] + public void FormatRecord_PrefersTheStoredName() + { + var record = new NestRecord { Material = "Mild Steel", MaterialGrade = "HR", Thickness = 0.135, ThicknessName = "Ten" }; + var machines = new[] { Machine() }; + + Assert.Equal("Ten (0.135)", ThicknessNames.Format(record, machines)); + record.ThicknessName = ""; + Assert.Equal("10 ga (0.135)", ThicknessNames.Format(record, machines)); + record.Thickness = 0; + Assert.Equal("0", ThicknessNames.Format(record, machines)); + } + + [Fact] + public void NewThickness_ClearsTheNameOfTheOldOne() + { + var nest = new Nest { Thickness = 0.135, ThicknessName = " 10 ga " }; + Assert.Equal("10 ga", nest.ThicknessName); + + nest.Thickness = 0.135; + Assert.Equal("10 ga", nest.ThicknessName); + + nest.Thickness = 0.25; + Assert.Equal("", nest.ThicknessName); + } + + [Fact] + public void NestRecord_CarriesTheNameBothWays() + { + var nest = new Nest { Name = "N1", Thickness = 0.135, ThicknessName = "10 ga" }; + + var record = NestRecordFactory.FromNest(nest, Guid.Empty, 0); + Assert.Equal("10 ga", record.ThicknessName); + + var loaded = new Nest(); + NestRecordFactory.ApplyMetadata(loaded, record); + Assert.Equal(0.135, loaded.Thickness); + Assert.Equal("10 ga", loaded.ThicknessName); + } +} diff --git a/OpenNest.Tests/IO/NestStatusSerializationTests.cs b/OpenNest.Tests/IO/NestStatusSerializationTests.cs index eeaadd9a..7f1f4c18 100644 --- a/OpenNest.Tests/IO/NestStatusSerializationTests.cs +++ b/OpenNest.Tests/IO/NestStatusSerializationTests.cs @@ -23,6 +23,20 @@ public class NestStatusSerializationTests Assert.Equal("AJ", loaded.MadeBy); } + [Fact] + public void RoundTrip_ThicknessName_Preserved() + { + var nest = CreateMinimalNest(); + nest.Thickness = 0.135; + nest.ThicknessName = "10 ga"; + + var loaded = RoundTrip(nest); + + Assert.Equal(0.135, loaded.Thickness); + Assert.Equal("10 ga", loaded.ThicknessName); + Assert.Equal("", RoundTrip(CreateMinimalNest()).ThicknessName); + } + [Fact] public void RoundTrip_DefaultStatus_IsQuote() { diff --git a/OpenNest.WinForms.Tests/Forms/EditNestInfoFormTests.cs b/OpenNest.WinForms.Tests/Forms/EditNestInfoFormTests.cs index c83f2efe..32b3ab50 100644 --- a/OpenNest.WinForms.Tests/Forms/EditNestInfoFormTests.cs +++ b/OpenNest.WinForms.Tests/Forms/EditNestInfoFormTests.cs @@ -74,6 +74,70 @@ public class EditNestInfoFormTests }); } + [Fact] + public void ThicknessName_FollowsTheThickness_AndKeepsATypedName() + { + RunSta(() => + { + using var form = new EditNestInfoForm(); + form.SetThicknessMachines(new[] + { + new Data.MachineConfig + { + Materials = + { + new Data.MaterialConfig + { + Name = "Stainless", + Grade = "304", + Thicknesses = { new Data.ThicknessConfig { Value = 0.06, Name = "16 ga SS" } }, + }, + }, + }, + }); + var nest = AcceptanceNest(); + form.LoadNestInfo(nest); + var thickness = (OpenNest.Controls.ThicknessComboBox)form.Controls.Find("thicknessBox", true).Single(); + + // A nest without a stored name shows the suggestion. + Assert.Equal("1/4\"", form.ThicknessName); + + thickness.Text = "0.06"; + Assert.Equal("16 ga SS", form.ThicknessName); + + thickness.SelectedItem = "16 ga - 0.0598"; + Assert.Equal("16 ga", form.ThicknessName); + + // A typed name stays through a material change, not through a new thickness. + thickness.Text = "0.135"; + form.ThicknessName = "Ten"; + form.MaterialName = "Aluminum"; + Assert.Equal("Ten", form.ThicknessName); + thickness.Text = "0.5"; + Assert.Equal("1/2\"", form.ThicknessName); + + form.ThicknessName = "Half"; + form.SaveNestInfo(nest); + Assert.Equal(0.5, nest.Thickness); + Assert.Equal("Half", nest.ThicknessName); + }); + } + + [Fact] + public void ThicknessName_ShowsTheStoredName() + { + RunSta(() => + { + using var form = new EditNestInfoForm(); + var nest = AcceptanceNest(); + nest.ThicknessName = "Quarter"; + + form.LoadNestInfo(nest); + + Assert.Equal("Quarter", form.ThicknessName); + }); + } + [Fact] public void NewNestDefaultsChoice_NeedsTheOfferAndTheCheck() { diff --git a/OpenNest/Forms/Commands/NestStorageController.cs b/OpenNest/Forms/Commands/NestStorageController.cs index d6e71a54..191313e3 100644 --- a/OpenNest/Forms/Commands/NestStorageController.cs +++ b/OpenNest/Forms/Commands/NestStorageController.cs @@ -54,7 +54,10 @@ namespace OpenNest.Forms.Commands { var repository = NestStorage.CreateRepository(); var serverUrl = NestStorage.Settings.ServerUrl; - using var dlg = new SavedNestsForm(repository, serverUrl); + using var dlg = new SavedNestsForm(repository, serverUrl) + { + ThicknessMachines = MachineSettings.LoadMachines(), + }; if (dlg.ShowDialog(owner) != DialogResult.OK) return; diff --git a/OpenNest/Forms/EditNestForm.cs b/OpenNest/Forms/EditNestForm.cs index 10521b01..84a88825 100644 --- a/OpenNest/Forms/EditNestForm.cs +++ b/OpenNest/Forms/EditNestForm.cs @@ -895,7 +895,7 @@ namespace OpenNest.Forms ); var snapshot = PartPrintoutBuilder.Capture(Nest, drawings, DateTimeOffset.Now, catalogDensity) with { - ThicknessName = NestReportExport.MachineThicknessName(machine, Nest), + ThicknessName = NestReportExport.ThicknessName(machine, Nest), }; PartPrintoutWriter.Write(snapshot, destination); } @@ -936,6 +936,7 @@ namespace OpenNest.Forms OfferNewNestDefaults = true, }; form.SetMaterialCatalog(MachineSettings.LoadMaterials()); + form.SetThicknessMachines(MachineSettings.LoadThicknessNameMachines(Nest)); form.LoadNestInfo(Nest); _ = ShowReleaseOriginAsync(form); var statusBefore = Nest.Status; diff --git a/OpenNest/Forms/EditNestInfoForm.Designer.cs b/OpenNest/Forms/EditNestInfoForm.Designer.cs index 62c99cdc..23dd11bf 100644 --- a/OpenNest/Forms/EditNestInfoForm.Designer.cs +++ b/OpenNest/Forms/EditNestInfoForm.Designer.cs @@ -46,6 +46,8 @@ this.labelPartSpacing = new System.Windows.Forms.Label(); this.partSpacingBox = new OpenNest.Controls.NumericUpDown(); this.labelThk = new System.Windows.Forms.Label(); + this.labelThicknessName = new System.Windows.Forms.Label(); + this.thicknessNameBox = new System.Windows.Forms.TextBox(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.useForNewNestsBox = new System.Windows.Forms.CheckBox(); this.quadrantSelect1 = new OpenNest.Controls.QuadrantSelect(); @@ -352,6 +354,22 @@ this.labelThk.Size = new System.Drawing.Size(126, 16); this.labelThk.TabIndex = 6; this.labelThk.Text = "Thickness :"; + // + // labelThicknessName + // + this.labelThicknessName.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.labelThicknessName.AutoSize = true; + this.labelThicknessName.Name = "labelThicknessName"; + this.labelThicknessName.Size = new System.Drawing.Size(126, 16); + this.labelThicknessName.TabIndex = 8; + this.labelThicknessName.Text = "Thickness name :"; + // + // thicknessNameBox + // + this.thicknessNameBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.thicknessNameBox.Name = "thicknessNameBox"; + this.thicknessNameBox.Size = new System.Drawing.Size(224, 22); + this.thicknessNameBox.TabIndex = 9; // // groupBox3 // @@ -410,29 +428,31 @@ this.tableLayoutPanel3.ColumnCount = 2; this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel3.Controls.Add(this.tableLayoutPanel4, 1, 7); + this.tableLayoutPanel3.Controls.Add(this.tableLayoutPanel4, 1, 8); this.tableLayoutPanel3.Controls.Add(this.label1, 0, 0); this.tableLayoutPanel3.Controls.Add(this.nameBox, 1, 0); - this.tableLayoutPanel3.Controls.Add(this.label2, 0, 6); + this.tableLayoutPanel3.Controls.Add(this.label2, 0, 7); this.tableLayoutPanel3.Controls.Add(this.labelThk, 0, 3); this.tableLayoutPanel3.Controls.Add(this.thicknessBox, 1, 3); - this.tableLayoutPanel3.Controls.Add(this.labelMaterial, 0, 4); - this.tableLayoutPanel3.Controls.Add(this.materialBox, 1, 4); - this.tableLayoutPanel3.Controls.Add(this.labelGrade, 0, 5); - this.tableLayoutPanel3.Controls.Add(this.gradeBox, 1, 5); + this.tableLayoutPanel3.Controls.Add(this.labelThicknessName, 0, 4); + this.tableLayoutPanel3.Controls.Add(this.thicknessNameBox, 1, 4); + this.tableLayoutPanel3.Controls.Add(this.labelMaterial, 0, 5); + this.tableLayoutPanel3.Controls.Add(this.materialBox, 1, 5); + this.tableLayoutPanel3.Controls.Add(this.labelGrade, 0, 6); + this.tableLayoutPanel3.Controls.Add(this.gradeBox, 1, 6); this.tableLayoutPanel3.Controls.Add(this.label3, 0, 1); this.tableLayoutPanel3.Controls.Add(this.label4, 0, 2); - this.tableLayoutPanel3.Controls.Add(this.customerBox, 1, 6); + this.tableLayoutPanel3.Controls.Add(this.customerBox, 1, 7); this.tableLayoutPanel3.Controls.Add(this.textBox1, 1, 1); this.tableLayoutPanel3.Controls.Add(this.textBox2, 1, 2); - this.tableLayoutPanel3.Controls.Add(this.label5, 0, 7); - this.tableLayoutPanel3.Controls.Add(this.labelStatus, 0, 8); - this.tableLayoutPanel3.Controls.Add(this.statusBox, 1, 8); - this.tableLayoutPanel3.Controls.Add(this.labelMadeBy, 0, 9); - this.tableLayoutPanel3.Controls.Add(this.madeByBox, 1, 9); + this.tableLayoutPanel3.Controls.Add(this.label5, 0, 8); + this.tableLayoutPanel3.Controls.Add(this.labelStatus, 0, 9); + this.tableLayoutPanel3.Controls.Add(this.statusBox, 1, 9); + this.tableLayoutPanel3.Controls.Add(this.labelMadeBy, 0, 10); + this.tableLayoutPanel3.Controls.Add(this.madeByBox, 1, 10); this.tableLayoutPanel3.Location = new System.Drawing.Point(6, 6); this.tableLayoutPanel3.Name = "tableLayoutPanel3"; - this.tableLayoutPanel3.RowCount = 10; + this.tableLayoutPanel3.RowCount = 11; this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F)); this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F)); this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F)); @@ -443,7 +463,8 @@ this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F)); this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F)); this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F)); - this.tableLayoutPanel3.Size = new System.Drawing.Size(362, 311); + this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F)); + this.tableLayoutPanel3.Size = new System.Drawing.Size(362, 342); this.tableLayoutPanel3.TabIndex = 0; // // tableLayoutPanel4 @@ -780,6 +801,8 @@ private System.Windows.Forms.TextBox sizeBox; private Controls.ThicknessComboBox thicknessBox; private System.Windows.Forms.Label labelThk; + private System.Windows.Forms.Label labelThicknessName; + private System.Windows.Forms.TextBox thicknessNameBox; private System.Windows.Forms.Label labelPartSpacing; private Controls.NumericUpDown partSpacingBox; private Controls.BottomPanel bottomPanel1; diff --git a/OpenNest/Forms/EditNestInfoForm.cs b/OpenNest/Forms/EditNestInfoForm.cs index 34d24537..b5b93e60 100644 --- a/OpenNest/Forms/EditNestInfoForm.cs +++ b/OpenNest/Forms/EditNestInfoForm.cs @@ -17,6 +17,9 @@ namespace OpenNest.Forms private string gradeMaterialKey = ""; private bool offerNewNestDefaults; private string shownMadeBy = ""; + private List thicknessMachines = new(); + private string suggestedThicknessName = ""; + private double? namedThickness; public EditNestInfoForm() { @@ -40,8 +43,17 @@ namespace OpenNest.Forms }; Disposed += (sender, e) => timer.Dispose(); nameBox.TextChanged += (sender, e) => EnableCheck(); - thicknessBox.TextChanged += (sender, e) => EnableCheck(); - materialBox.TextChanged += (sender, e) => RefreshGrades(); + thicknessBox.TextChanged += (sender, e) => + { + EnableCheck(); + RefreshThicknessName(); + }; + materialBox.TextChanged += (sender, e) => + { + RefreshGrades(); + RefreshThicknessName(); + }; + gradeBox.TextChanged += (sender, e) => RefreshThicknessName(); EnableCheck(); } @@ -162,6 +174,46 @@ namespace OpenNest.Forms set { thicknessBox.Value = value; } } + /// + /// The shop's name for the thickness, such as "10 ga". It follows the thickness: a new + /// thickness, or a new material while the name is blank or the one suggested, takes the + /// machines' name for it () or the nearest standard gauge. + /// + public string ThicknessName + { + get { return thicknessNameBox.Text.Trim(); } + set { thicknessNameBox.Text = value ?? ""; } + } + + /// + /// The machines whose thickness names the dialog suggests, the nest's own first. Set it + /// before . + /// + public void SetThicknessMachines(IEnumerable machines) + { + thicknessMachines = (machines ?? Enumerable.Empty()).Where(m => m != null).ToList(); + RefreshThicknessName(); + } + + private void RefreshThicknessName() + { + if (!thicknessBox.TryGetValue(out var value)) + return; + + // A picked list entry ("16 ga - 0.0598") names itself. + var text = thicknessBox.Text.Trim(); + var picked = StandardThicknesses.Entries.FirstOrDefault(entry => + string.Equals(StandardThicknesses.Label(entry, GetUnits()), text, StringComparison.OrdinalIgnoreCase)); + var suggested = picked?.Name + ?? ThicknessNames.For(thicknessMachines, MaterialName, MaterialGrade, value, GetUnits()); + var current = ThicknessName; + // A new thickness replaces any name; a new material only a blank or suggested one. + if (namedThickness != value || current.Length == 0 || current == suggestedThicknessName) + ThicknessName = suggested; + suggestedThicknessName = suggested; + namedThickness = value; + } + public string MaterialName { get { return materialBox.Text; } @@ -294,6 +346,7 @@ namespace OpenNest.Forms DateCreated = DateCreated, DateLastModified = DateLastModified, Thickness = Thickness, + ThicknessName = ThicknessName, MaterialName = MaterialName, MaterialGrade = MaterialGrade, Status = Status, @@ -318,6 +371,9 @@ namespace OpenNest.Forms Thickness = values.Thickness; MaterialName = values.MaterialName; MaterialGrade = values.MaterialGrade; + // A stored name stands; a nest without one shows the suggested name. + if (!string.IsNullOrWhiteSpace(values.ThicknessName)) + ThicknessName = values.ThicknessName; Status = values.Status; MadeBy = values.MadeBy; shownMadeBy = MadeBy; diff --git a/OpenNest/Forms/MachineSettings.cs b/OpenNest/Forms/MachineSettings.cs index 394a6cbb..aef4dbc4 100644 --- a/OpenNest/Forms/MachineSettings.cs +++ b/OpenNest/Forms/MachineSettings.cs @@ -28,6 +28,22 @@ namespace OpenNest.Forms /// Every readable machine configuration, for choosing acceleration limits. public static List LoadMachines() => Source.LoadMachines(); + /// + /// The machines whose names for thicknesses takes: its own first, + /// then every other readable one. + /// + public static List LoadThicknessNameMachines(Nest nest) + { + var machines = LoadMachines(); + var own = nest?.Machine is { } assigned ? machines.FirstOrDefault(m => m.Id == assigned.Id) : null; + if (own != null) + { + machines.Remove(own); + machines.Insert(0, own); + } + return machines; + } + /// Every readable machine configuration on this PC, shared or not, for uploading. public static List LoadLocalMachines() => Source.LoadLocalMachines(); diff --git a/OpenNest/Forms/MainStatusBar.cs b/OpenNest/Forms/MainStatusBar.cs index f1e78d2e..d7cf3825 100644 --- a/OpenNest/Forms/MainStatusBar.cs +++ b/OpenNest/Forms/MainStatusBar.cs @@ -219,7 +219,7 @@ namespace OpenNest.Forms var nest = form.Nest; machine.Text = FormatMachine(nest.Machine); - material.Text = FormatMaterial(nest.Material?.Name, nest.Material?.Grade, nest.Thickness, nest.Units); + material.Text = MainStatusText.Material(nest); plateUtil.Text = MainStatusText.Utilization(form.PlateView.Plate.Utilization()); } diff --git a/OpenNest/Forms/SavedNestsForm.cs b/OpenNest/Forms/SavedNestsForm.cs index 027c5d8f..19c7e6d4 100644 --- a/OpenNest/Forms/SavedNestsForm.cs +++ b/OpenNest/Forms/SavedNestsForm.cs @@ -83,6 +83,12 @@ public sealed class SavedNestsForm : Form /// Set to the chosen record's id when the dialog closes with OK. public Guid SelectedId { get; private set; } + /// + /// The machines that name a listed nest's thickness when it stores no name of its own + /// (see ); with none, only the standard gauges and fractions do. + /// + public IReadOnlyList ThicknessMachines { get; set; } = Array.Empty(); + public SavedNestsForm(INestRepository repository, string serverUrl = null) { this.repository = repository; @@ -122,7 +128,7 @@ public sealed class SavedNestsForm : Form AddNestColumn("Made by", NestSortField.MadeBy, 90); AddNestColumn("Material", NestSortField.Material, 150); AddNestColumn("Grade", NestSortField.MaterialGrade, 80); - AddNestColumn("Thickness", NestSortField.Thickness, 80, alignRight: true); + AddNestColumn("Thickness", NestSortField.Thickness, 120, alignRight: true); AddNestColumn("Created", NestSortField.DateCreated, 140); AddNestColumn("Saved", NestSortField.SavedAt, 140); AddNestColumn("File size", NestSortField.FileSize, 80, alignRight: true); @@ -487,7 +493,7 @@ public sealed class SavedNestsForm : Form record.MadeBy, record.Material, record.MaterialGrade, - record.Thickness.ToString("0.####", CultureInfo.CurrentCulture), + ThicknessNames.Format(record, ThicknessMachines), FormatDate(record.DateCreated), FormatDate(record.SavedAt), FormatFileSize(record.FileSize), @@ -934,6 +940,7 @@ public sealed class SavedNestsForm : Form if (IsDisposed) return; using var dialog = new EditNestInfoForm { AllowRename = true }; dialog.SetMaterialCatalog(MachineSettings.LoadMaterials()); + dialog.SetThicknessMachines(MachineSettings.LoadThicknessNameMachines(nest)); dialog.LoadNestInfo(nest); while (true) { diff --git a/docs/machine-cutting-defaults.md b/docs/machine-cutting-defaults.md index 52528e14..00df1de9 100644 --- a/docs/machine-cutting-defaults.md +++ b/docs/machine-cutting-defaults.md @@ -15,8 +15,9 @@ 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 +A thickness's **Name / Gauge** ("16 ga") is display only: the tree shows it, Nest Information +suggests it as the nest's thickness name, and the Open list and nest reports show a nest +without its own name by 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. Opening Machine Configuration diff --git a/docs/nest-file-format.md b/docs/nest-file-format.md index 2895a663..4b10629f 100644 --- a/docs/nest-file-format.md +++ b/docs/nest-file-format.md @@ -9,6 +9,9 @@ opening and saving with an older application loses that state. `nest.json` carries the workflow fields shown in the nest info dialog: `name`, `customer`, `dateCreated`, `dateLastModified`, `notes`, `material`, `thickness`, plus `status` (`"Draft"`, `"Quote"`, `"ToBeCut"`, `"HasBeenCut"`) and `madeBy`. +`thicknessName` is the shop's name for the thickness ("10 ga", `Nest.ThicknessName`); it +is omitted when blank, older files have none, and older readers ignore it. A new +thickness value clears it, so a reader sets it after the thickness. Status and made-by are additive: files written before them load as Quote with an empty maker, and an unrecognized status value likewise falls back to Quote. Builds before `Draft` therefore open a Draft nest as Quote, and saving it there keeps Quote. diff --git a/docs/nest-storage.md b/docs/nest-storage.md index 8c4d2e31..f5ff5ebf 100644 --- a/docs/nest-storage.md +++ b/docs/nest-storage.md @@ -5,7 +5,7 @@ The desktop app can save nests two ways: - **File mode** (default, unchanged behavior): Save/Save As write a `.nest` ZIP archive to disk via the normal file dialog. See [nest-file-format.md](nest-file-format.md). - **Database mode**: Open browses server records 100 at a time. The Find box - searches name, customer, material, grade, made by, comments and status on the server + searches name, customer, material, grade, thickness name, made by, comments and status on the server after a short typing pause (Enter in the box searches at once); clicking a column header sorts every match on the server (click again to reverse); the arrow buttons move between pages and the title and find bar show the range and @@ -89,6 +89,7 @@ entry, never programs or geometry, and takes the archive-derived fields below fr | `material` | string | Material name (type), e.g. `Stainless`. Read from the uploaded archive (nest material, else plate defaults' on an explicit null); a metadata-only PUT may change it, and the desktop applies the record's value when opening the nest. | | `materialGrade` | string | Optional; default blank. Older servers drop it. A blank grade on a record saved before schema v8 is treated as unrecorded: opening keeps the archive's grade while the material name matches. | | `thickness` | number | Read from the uploaded archive (nest thickness, else plate defaults' when not positive); editable like `material`. | +| `thicknessName` | string | Optional; default blank. The shop's name for the thickness ("10 ga"), from the client like `materialGrade`. Older servers drop it. A blank name is filled in for display only (see [Thickness names](#thickness-names)). | | `units` | `"inches"` \| `"millimeters"` | The nest's units, which `thickness` is in. Server-computed from the uploaded archive (absent or unknown values are inches, as `NestReader` reads them); ignored on upload and kept by a metadata-only PUT. Schema v12 read every stored archive, current and historical, to fill it. Older servers omit it, which readers take as inches. | | `status` | `"draft"` \| `"quote"` \| `"toBeCut"` \| `"hasBeenCut"` | Default `quote`. | | `plateCount` / `partCount` | integer | Server-computed from the uploaded archive (non-cutoff parts only; a trailing plate with no parts or cut-offs is not counted); ignored on upload and kept by a metadata-only PUT. | @@ -270,7 +271,7 @@ only the requested page of metadata (never archive bytes): - `search` (optional): trimmed, at most 200 characters, no NUL characters; blank means no filter. Case-insensitive substring of the whole text in `name`, `customer`, `material`, - `materialGrade`, `madeBy`, `comments` or the status (`ToBeCut` or the display name `To Be Cut`). + `materialGrade`, `thicknessName`, `madeBy`, `comments` or the status (`ToBeCut` or the display name `To Be Cut`). `%`, `_` and `\` are literal. Dates and numbers are not matched as text. Case folding is ASCII-only (SQLite `LIKE`). - Exact filters (optional, all must match; used to find draft nests a release @@ -1122,6 +1123,22 @@ Schema v8 adds a `materialGrade` text column (default blank) to `nests` and A server older than v8 refuses to open a v8 database, so rolling back needs the pre-upgrade backup. +### Thickness names + +Schema v20 adds a `thicknessName` text column (default blank) to `nests` and +`nest_revisions`; existing records keep a blank name until they are next saved. +A server older than v20 refuses to open a v20 database, so rolling back needs the +pre-upgrade backup. + +The Open list's Thickness column shows the name with the decimal in parentheses, +"10 ga (0.135)", still sorting by the decimal. A record without a name is named for +display only (`ThicknessNames`): the first machine configuration that names its +material and thickness, otherwise the nearest standard steel gauge or plate fraction +within 0.001 in, so 0.135 reads as 10 ga and 0.188 as 3/16". Nest Information has a +**Thickness name** box that fills in the same way (a picked list entry names itself, +the nest's own machine is asked first); a new thickness replaces the name, a new +material only a blank or suggested one, and a typed name is kept. + ## Material list endpoints The server keeps the company material list: each material with its grades. Both