diff --git a/OpenNest.Data/MachineCuttingDefaults.cs b/OpenNest.Data/MachineCuttingDefaults.cs
index cef1fbcf..c02fc8e8 100644
--- a/OpenNest.Data/MachineCuttingDefaults.cs
+++ b/OpenNest.Data/MachineCuttingDefaults.cs
@@ -227,6 +227,64 @@ public static class MachineCuttingDefaults
return true;
}
+ ///
+ /// The plate sizes the machine lists for the nest's material and thickness (its Plate Sizes
+ /// tab), as plate-size options in the nest's units with the shorter side as the width, in
+ /// the order listed; empty when it lists none or has no settings for the nest. A standard
+ /// size ("60x120", ) is in inches; a custom one is in the machine's
+ /// units. A label that is not two positive dimensions, or repeats an earlier size, is skipped.
+ ///
+ public static List PlateOptionsFor(MachineConfig? machine, Nest nest)
+ {
+ ArgumentNullException.ThrowIfNull(nest);
+ var options = new List();
+ if (Find(machine, nest)?.PlateSizes is not { Count: > 0 } labels)
+ return options;
+
+ foreach (var label in labels)
+ {
+ double width, length, scale;
+ if (OpenNest.Shapes.PlateSizes.TryGet(label, out var standard))
+ (width, length, scale) = (standard.Width, standard.Length, Scale(Units.Inches, nest.Units));
+ else if (TryParsePlateSize(label, out width, out length))
+ scale = Scale(machine!.Units, nest.Units);
+ else
+ continue;
+
+ var (shorter, longer) = (System.Math.Min(width, length) * scale, System.Math.Max(width, length) * scale);
+ if (options.Any(o => System.Math.Abs(o.Width - shorter) <= OpenNest.Math.Tolerance.Epsilon
+ && System.Math.Abs(o.Length - longer) <= OpenNest.Math.Tolerance.Epsilon))
+ continue;
+ options.Add(new PlateOption { Width = shorter, Length = longer });
+ }
+ return options;
+ }
+
+ ///
+ /// Gives the nest the machine's plate sizes for its material and thickness as its plate-size
+ /// options (), replacing any it had, so Auto Nest chooses among
+ /// them. Returns false, changing nothing, when the machine lists none for the nest.
+ ///
+ public static bool ApplyPlateSizesTo(Nest nest, MachineConfig? machine)
+ {
+ var options = PlateOptionsFor(machine, nest);
+ if (options.Count == 0)
+ return false;
+ nest.PlateOptions = options;
+ return true;
+ }
+
+ // "50x100", "50 x 100" or "50X100": two positive finite dimensions.
+ private static bool TryParsePlateSize(string? label, out double width, out double length)
+ {
+ width = length = 0;
+ var parts = (label ?? "").Split(new[] { 'x', 'X', '×' }, StringSplitOptions.TrimEntries);
+ return parts.Length == 2
+ && double.TryParse(parts[0], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out width)
+ && double.TryParse(parts[1], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out length)
+ && double.IsFinite(width) && double.IsFinite(length) && width > 0 && length > 0;
+ }
+
///
/// Runs , then, when it changed the nest's material, grade or
/// thickness, applies the machine's spacing for them (). A
diff --git a/OpenNest.Tests/Data/MachineCuttingDefaultsTests.cs b/OpenNest.Tests/Data/MachineCuttingDefaultsTests.cs
index facedc3c..5cae7cb1 100644
--- a/OpenNest.Tests/Data/MachineCuttingDefaultsTests.cs
+++ b/OpenNest.Tests/Data/MachineCuttingDefaultsTests.cs
@@ -134,6 +134,60 @@ public class MachineCuttingDefaultsTests
Assert.Equal(new Spacing(1, 2, 3, 4), nest.PlateDefaults.EdgeSpacing);
}
+ private static MachineConfig SizedMachine(UnitSystem units, params string[] sizes)
+ {
+ var machine = Machine(LineArc, units: units);
+ machine.Materials[0].Thicknesses[0].Value = units == UnitSystem.Millimeters ? 6.35 : 0.25;
+ machine.Materials[0].Thicknesses[0].PlateSizes = sizes.ToList();
+ return machine;
+ }
+
+ [Fact]
+ public void PlateOptionsFor_ListsTheThicknessesPlateSizes_ShorterSideFirst()
+ {
+ var machine = SizedMachine(UnitSystem.Inches, "60x120", "48X96", "100 x 50", "60x120", "120x60", "bogus", "0x10", "");
+
+ var options = MachineCuttingDefaults.PlateOptionsFor(machine, NestOf(0.25, "A36"));
+
+ Assert.Equal(new[] { (60.0, 120.0), (48.0, 96.0), (50.0, 100.0) }, options.Select(o => (o.Width, o.Length)));
+ Assert.All(options, o => Assert.Equal((0.0, (int?)null, (string)null), (o.Cost, o.Quantity, o.Id)));
+ }
+
+ [Fact]
+ public void PlateOptionsFor_StandardSizesAreInches_CustomOnesTheMachinesUnits()
+ {
+ var machine = SizedMachine(UnitSystem.Millimeters, "48x96", "1500x3000");
+
+ var inches = MachineCuttingDefaults.PlateOptionsFor(machine, NestOf(0.25, "A36"));
+ var millimeters = MachineCuttingDefaults.PlateOptionsFor(machine, NestOf(6.35, "A36", Units.Millimeters));
+
+ Assert.Equal(new[] { 48, 96, 1500 / 25.4, 3000 / 25.4 }, inches.SelectMany(o => new[] { o.Width, o.Length }), new DoubleTolerance(1e-9));
+ Assert.Equal(new[] { 48 * 25.4, 96 * 25.4, 1500, 3000 }, millimeters.SelectMany(o => new[] { o.Width, o.Length }), new DoubleTolerance(1e-9));
+ }
+
+ [Fact]
+ public void ApplyPlateSizesTo_ReplacesTheNestsOptions_OnlyWhenTheMachineListsSome()
+ {
+ var nest = NestOf(0.25, "A36");
+ nest.PlateOptions = new List { new() { Width = 72, Length = 144, Cost = 5 } };
+
+ Assert.False(MachineCuttingDefaults.ApplyPlateSizesTo(nest, SizedMachine(UnitSystem.Inches)));
+ Assert.False(MachineCuttingDefaults.ApplyPlateSizesTo(nest, null));
+ Assert.False(MachineCuttingDefaults.ApplyPlateSizesTo(NestOf(0.5, "A36"), SizedMachine(UnitSystem.Inches, "60x120")));
+ Assert.Equal(72, Assert.Single(nest.PlateOptions).Width);
+
+ Assert.True(MachineCuttingDefaults.ApplyPlateSizesTo(nest, SizedMachine(UnitSystem.Inches, "60x120")));
+ var option = Assert.Single(nest.PlateOptions);
+ Assert.Equal((60.0, 120.0, 0.0), (option.Width, option.Length, option.Cost));
+ }
+
+ private sealed class DoubleTolerance(double tolerance) : IEqualityComparer
+ {
+ public bool Equals(double x, double y) => System.Math.Abs(x - y) <= tolerance;
+
+ public int GetHashCode(double obj) => 0;
+ }
+
[Fact]
public void Spacing_SurvivesTheMachineFile()
{
diff --git a/OpenNest.WinForms.Tests/Forms/SetReleaseFormsTests.cs b/OpenNest.WinForms.Tests/Forms/SetReleaseFormsTests.cs
index cc6048b9..899faad3 100644
--- a/OpenNest.WinForms.Tests/Forms/SetReleaseFormsTests.cs
+++ b/OpenNest.WinForms.Tests/Forms/SetReleaseFormsTests.cs
@@ -411,6 +411,57 @@ public class SetReleaseFormsTests
"The nest after release test did not complete.");
}
+ [Fact]
+ public void NestAfterRelease_NestsOnTheMachinesPlateSizesForTheMaterial_NotThePlateDefault()
+ {
+ StaTestThread.Run(
+ () =>
+ {
+ var library = new PackageLibrary();
+ var a = library.Add("SYN-A", "Synthetic Steel");
+ var sets = new InMemoryDrawingSets();
+ var set = CreateSet(sets, (a, 3));
+ var opened = new List();
+ var machine = new MachineConfig
+ {
+ Name = "Fiber 1",
+ Units = UnitSystem.Inches,
+ Materials =
+ {
+ new MaterialConfig
+ {
+ Name = "Synthetic Steel",
+ Grade = "Grade A",
+ Thicknesses = { new ThicknessConfig { Value = 0.25, PlateSizes = { "48x96" } } },
+ },
+ },
+ };
+
+ var (host, panel) = ShowPanel(sets, library, new MemoryNests(), (nest, _) => opened.Add(nest));
+ using var _ = host;
+ panel.CreateNest = (group, _) =>
+ {
+ var nest = new Nest("N26-0201") { Units = group.Units };
+ nest.PlateDefaults.Size = new OpenNest.Geometry.Size(60, 120);
+ return Task.FromResult(nest);
+ };
+ panel.FindMachine = _ => machine;
+ Field(panel, "nestAfterReleaseCheckBox").Checked = true;
+ panel.AddSet(set);
+
+ Run(panel.ReleaseAsync());
+
+ var nest = Assert.Single(opened);
+ Assert.Equal(3, nest.Plates.Sum(p => p.Parts.Count * p.Quantity));
+ Assert.All(nest.Plates, p => Assert.Equal((48.0, 96.0),
+ (System.Math.Min(p.Size.Width, p.Size.Length), System.Math.Max(p.Size.Width, p.Size.Length))));
+ var option = Assert.Single(nest.PlateOptions);
+ Assert.Equal((48.0, 96.0), (option.Width, option.Length));
+ },
+ TestTimeout,
+ "The machine plate sizes release test did not complete.");
+ }
+
[Fact]
public void NestAfterRelease_Unticked_SaysAMergedDraftIsLeftWithoutSheets()
{
diff --git a/OpenNest/Controls/ReleasePanel.cs b/OpenNest/Controls/ReleasePanel.cs
index 137b47fd..a6be787b 100644
--- a/OpenNest/Controls/ReleasePanel.cs
+++ b/OpenNest/Controls/ReleasePanel.cs
@@ -78,6 +78,13 @@ namespace OpenNest.Controls
internal Func> Renest
{ get; set; } = RenestAsync;
+ ///
+ /// The machine configuration of a nest being released, whose plate sizes for the nest's
+ /// material and thickness Nest after release offers; replaced by tests.
+ ///
+ internal Func FindMachine { get; set; } =
+ nest => MachineSettings.FindMachine(nest.Machine);
+
///
/// The MaterialLedger stock one Make Nests run nests on; replaced by tests.
///
@@ -751,10 +758,17 @@ namespace OpenNest.Controls
cancellation = new CancellationTokenSource();
UpdateCommands();
var merges = await RereadMergesAsync(ChosenMerges(), cancellation.Token);
- session = new SetReleaseSession(sets, library, nests, serverUrl, ReadPackage, WriteNest, CreateNest, ReadNest,
- !nestAfter ? null
+ Func> renest = !nestAfter ? null
: live == null ? (nest, token) => Renest(nest, ledger, token)
- : LiveRenest(live, ledger));
+ : LiveRenest(live, ledger);
+ session = new SetReleaseSession(sets, library, nests, serverUrl, ReadPackage, WriteNest, CreateNest, ReadNest,
+ renest == null ? null : (nest, token) =>
+ {
+ // After the ledger, Auto Nest chooses among the machine's plate sizes for
+ // the nest's material and thickness, when it lists any.
+ MachineCuttingDefaults.ApplyPlateSizesTo(nest, FindMachine(nest));
+ return renest(nest, token);
+ });
var progress = new Progress(ShowProgress);
if (live != null)
{
diff --git a/docs/automatic-nesting.md b/docs/automatic-nesting.md
index 4dcfea11..581d1eb6 100644
--- a/docs/automatic-nesting.md
+++ b/docs/automatic-nesting.md
@@ -301,7 +301,8 @@ batch stays the only authority, and another programmer can hold the same drop fi
Make Nests in the drawing sets window (with **Nest after release** ticked) uses the same
stock without the dialog: each released group nests on its free ledger stock first,
-substitutes included, then on the Nest Defaults sheet and the nest's plate-size options. See
+substitutes included, then on the plate sizes the nest's machine lists for its material and
+thickness (or, when it lists none, the Nest Defaults sheet and the nest's plate-size options). See
[Make Nests](nest-storage.md#make-nests-the-release-panel-desktop) for the details.
**Setup (per PC).** Tools > Options > MaterialLedger takes the ledger URL and the API
diff --git a/docs/machine-cutting-defaults.md b/docs/machine-cutting-defaults.md
index fdf5cd7c..b1edac37 100644
--- a/docs/machine-cutting-defaults.md
+++ b/docs/machine-cutting-defaults.md
@@ -92,6 +92,16 @@ with no material or thickness gives it the record's (`LibraryDrawingInsert`), an
spacing. Drawings from files carry no thickness, so they leave the nest blank. Plates are kept as they are, except
an untouched trailing empty sheet, which follows the plate defaults.
+## Plate sizes
+
+Each thickness's Plate Sizes tab lists the sheet sizes stocked for it: standard sizes
+(`PlateSizes`, always inches) and custom ones typed as `W x L` in the machine's units.
+Make Nests with Nest after release ticked nests each released nest on these, after any
+MaterialLedger stock: they become the nest's plate-size options, in the nest's units, and
+Auto Nest chooses among them (`MachineCuttingDefaults.ApplyPlateSizesTo`). A thickness
+listing none leaves the nest's plate defaults and options as they were. File > New, BOM
+import and the Auto Nest dialog do not read them.
+
## Cut-offs
The plate view's part clearance, overtravel, minimum segment length and direction come from
diff --git a/docs/nest-storage.md b/docs/nest-storage.md
index 8521149c..42accbf3 100644
--- a/docs/nest-storage.md
+++ b/docs/nest-storage.md
@@ -807,9 +807,14 @@ every drawing's required quantity with the selected engine, in two steps:
(`OpenNest.Desktop.ReleaseRenest`). A draft being merged into is renested from
scratch, but the codes it was saved with still count as on another nest, so
its own earlier sheets are not offered again.
-2. **Then the plate defaults.** Copies the ledger stock cannot hold are nested on
- the nest's plate defaults (Tools > Nest Defaults) and plate-size options.
- These sheets have no ledger code.
+2. **Then the machine's plate sizes.** Copies the ledger stock cannot hold are
+ nested on the plate sizes the nest's machine lists for its material, grade and
+ thickness (Tools > Machine Configuration, the thickness's Plate Sizes tab), with
+ Auto Nest choosing among them; the nest keeps them as its plate-size options, replacing
+ any a merged draft had (`MachineCuttingDefaults.ApplyPlateSizesTo`). When the
+ machine lists none for the nest, they are nested on the nest's plate defaults
+ (Tools > Nest Defaults) and plate-size options, as before. These sheets have no
+ ledger code.
When the nest has no material or thickness, or the ledger is not set up on the
PC, cannot be reached, rejects the API key, has no mapping for the material or