From b227321aeebaf72111be4c3361218b759d1d579c Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Sun, 22 Nov 2026 18:09:17 -0500 Subject: [PATCH] feat(labels): etch the part number alone or with its bend groups Replace the on/off CuttingParameters.EtchPartLabels with a PartLabelMode (Off, PartNumber, PartNumberAndBendGroups), chosen from a dropdown in the Cutting panel and kept per machine thickness. PartNumber etches only the drawing name; the full mode keeps the 1234-AB label. Settings saved with the old boolean still load: true reads as PartNumberAndBendGroups and false or a missing key as Off, in the cutting parameter DTO and the machine thickness config. The old key is never written again. The plan fingerprint keeps the old full-label token and adds one for the number-only mode. Co-Authored-By: Claude Sonnet 5.5 --- AGENTS.md | 2 +- .../CuttingPlanning/OwnedCuttingParameters.cs | 2 +- .../CNC/CuttingPlanning/StateFingerprint.cs | 6 +- .../CNC/CuttingStrategy/CuttingParameters.cs | 8 +- .../CNC/CuttingStrategy/PartLabelMode.cs | 15 ++ OpenNest.Core/Labels/PartLabels.cs | 22 ++- OpenNest.Data/MachineCuttingDefaults.cs | 4 +- OpenNest.Data/ThicknessCuttingConfig.cs | 17 +++ .../CuttingPlanning/CuttingPlanService.cs | 5 +- OpenNest.IO/CuttingParametersDto.cs | 12 ++ OpenNest.IO/CuttingParametersSerializer.cs | 4 +- OpenNest.Tests/Labels/PartLabelTests.cs | 133 ++++++++++++++++-- .../Controls/CuttingPanelTests.cs | 11 +- OpenNest/Controls/CuttingPanel.cs | 29 ++-- docs/label-box.md | 28 +++- docs/machine-cutting-defaults.md | 2 +- 16 files changed, 246 insertions(+), 54 deletions(-) create mode 100644 OpenNest.Core/CNC/CuttingStrategy/PartLabelMode.cs diff --git a/AGENTS.md b/AGENTS.md index dc21de61..a54029c6 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -74,7 +74,7 @@ Read the relevant contract before changing its behavior: - [Lead-in placement](docs/geometry/lead-in-placement.md) (including the planner's eroded pierce for cutouts too small for their lead-in and the stop at a feature's center line) and [pierce zones](docs/geometry/pierce-zone.md): opt-in `PierceDiameter` clearance, the hole pole fallback and the planner's perimeter scrap fallback - [Breakoffs](docs/breakoffs.md): tabbed scrap; `Break`-layer open cuts that are cut but are not material - [Tabbed cutouts](docs/tabbed-cutouts.md): holes cut in pieces around `Tab`-layer spans that are material but never cut; nesting reads material through `NestingMaterial.ForNesting`, so nothing nests in them -- [Label box](docs/label-box.md): CAD Converter placement for the etched part number, found by eroding the material clear of edges, holes, bend lines and breakoff scrap; the box never affects the program. Plan Cutting etches the number and bend-group letters in it as scribe marks when `CuttingParameters.EtchPartLabels` is on (off by default) +- [Label box](docs/label-box.md): CAD Converter placement for the etched part number, found by eroding the material clear of edges, holes, bend lines and breakoff scrap; the box never affects the program. Plan Cutting etches the number, with or without bend-group letters, in it as scribe marks per `CuttingParameters.LabelMode` (`PartLabelMode`, off by default) - [Dimensions](docs/dimensions.md): CAD Converter annotations that store placement only, are measured from the cut geometry when shown and never affect the program - [Common-line cutting](docs/common-line-cutting.md): parts one kerf apart in `Plate.CommonLines` share an edge; spans are derived, never stored, and spacing checks hold group members to the kerf. Plan Cutting cuts each shared span once (the owner, cut first, starts its compensated outside on the common line; partners cut only their remainders) unless the plate is set to cut them twice; only posts implementing `ICommonLinePostProcessor` (CI Fiber) may write it, others refuse. Machine trial pending. Auto Nest and Fill Area pair `AllowCommonLine` drawings at the nest's `CommonLineUsage` (Off by default, byte-identical to no common lines); `NestLayoutCheck` exempts only explicit result groups - [Support tabs](docs/support-tabs.md): the nest's support grid, the center-of-gravity check, Plan Cutting's tab placement for parts the grid cannot hold level, and its opt-in slicing of slugs the grid cannot hold level diff --git a/OpenNest.Core/CNC/CuttingPlanning/OwnedCuttingParameters.cs b/OpenNest.Core/CNC/CuttingPlanning/OwnedCuttingParameters.cs index 75acb74e..050cde9b 100644 --- a/OpenNest.Core/CNC/CuttingPlanning/OwnedCuttingParameters.cs +++ b/OpenNest.Core/CNC/CuttingPlanning/OwnedCuttingParameters.cs @@ -47,7 +47,7 @@ internal static class OwnedCuttingParameters TabSizeMaxWidth = Dimension(source.TabSizeMaxWidth), TabHeldMaxLength = Dimension(source.TabHeldMaxLength), SliceTippingSlugs = source.SliceTippingSlugs, - EtchPartLabels = source.EtchPartLabels, + LabelMode = source.LabelMode, Sequencing = new SequenceParameters { Method = sequence.Method, diff --git a/OpenNest.Core/CNC/CuttingPlanning/StateFingerprint.cs b/OpenNest.Core/CNC/CuttingPlanning/StateFingerprint.cs index 49650ebd..1dfd262a 100644 --- a/OpenNest.Core/CNC/CuttingPlanning/StateFingerprint.cs +++ b/OpenNest.Core/CNC/CuttingPlanning/StateFingerprint.cs @@ -97,8 +97,12 @@ internal static class StateFingerprint // Only when on, so fingerprints taken before the setting existed still match. if (p.SliceTippingSlugs) text.Append("slugSlices;"); - if (p.EtchPartLabels) + // "partLabels;" is what the old on/off option wrote for the full label, so those + // fingerprints still match. + if (p.LabelMode == PartLabelMode.PartNumberAndBendGroups) text.Append("partLabels;"); + else if (p.LabelMode == PartLabelMode.PartNumber) + text.Append("partLabelNumber;"); Sequence(p.Sequencing); Assignment(p.Assignment); text.Append('}'); diff --git a/OpenNest.Core/CNC/CuttingStrategy/CuttingParameters.cs b/OpenNest.Core/CNC/CuttingStrategy/CuttingParameters.cs index d86911b6..2fc3e8d8 100644 --- a/OpenNest.Core/CNC/CuttingStrategy/CuttingParameters.cs +++ b/OpenNest.Core/CNC/CuttingStrategy/CuttingParameters.cs @@ -114,11 +114,11 @@ namespace OpenNest.CNC.CuttingStrategy public bool SliceTippingSlugs { get; set; } /// - /// Etches each part's number and bend groups in its drawing's label box when cutting is - /// planned (see docs/label-box.md). Off by default; parts whose drawing has no label box, - /// and common-line members, get no label. + /// Etches each part's number, with or without its bend groups, in its drawing's label box + /// when cutting is planned (see docs/label-box.md). Off by default; parts whose drawing has + /// no label box, and common-line members, get no label. /// - public bool EtchPartLabels { get; set; } + public PartLabelMode LabelMode { get; set; } public SequenceParameters Sequencing { get; set; } = new SequenceParameters(); public AssignmentParameters Assignment { get; set; } = new AssignmentParameters(); diff --git a/OpenNest.Core/CNC/CuttingStrategy/PartLabelMode.cs b/OpenNest.Core/CNC/CuttingStrategy/PartLabelMode.cs new file mode 100644 index 00000000..a054c492 --- /dev/null +++ b/OpenNest.Core/CNC/CuttingStrategy/PartLabelMode.cs @@ -0,0 +1,15 @@ +namespace OpenNest.CNC.CuttingStrategy +{ + /// What Plan Cutting etches in each part's label box (see docs/label-box.md). + public enum PartLabelMode + { + /// Nothing is etched. + Off, + + /// The drawing name only, for example 1234. + PartNumber, + + /// The drawing name and the bend groups of its bends, for example 1234-AB. + PartNumberAndBendGroups, + } +} diff --git a/OpenNest.Core/Labels/PartLabels.cs b/OpenNest.Core/Labels/PartLabels.cs index 6b779c46..eb781f04 100644 --- a/OpenNest.Core/Labels/PartLabels.cs +++ b/OpenNest.Core/Labels/PartLabels.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using OpenNest.Bending; using OpenNest.CNC; +using OpenNest.CNC.CuttingStrategy; using OpenNest.Geometry; using OpenNest.Math; @@ -68,10 +69,13 @@ namespace OpenNest.Labels /// The label text for a drawing placed at : its name, then a /// dash and its bend groups when it has bends, for example 1234-AB. Characters the /// stroke font lacks are dropped from the name. Empty when nothing is left to etch. + /// With it is the name alone, and with + /// it is empty. /// - public static string Text(Drawing drawing, double partRotation, double grainAngle) + public static string Text(Drawing drawing, double partRotation, double grainAngle, + PartLabelMode mode = PartLabelMode.PartNumberAndBendGroups) { - if (drawing == null) + if (drawing == null || mode == PartLabelMode.Off) return string.Empty; var name = new StringBuilder(); @@ -79,7 +83,9 @@ namespace OpenNest.Labels if (StrokeFont.Has(character) && !char.IsWhiteSpace(character)) name.Append(char.ToUpperInvariant(character)); - var groups = GroupLetters(drawing.Bends, partRotation, grainAngle); + var groups = mode == PartLabelMode.PartNumberAndBendGroups + ? GroupLetters(drawing.Bends, partRotation, grainAngle) + : string.Empty; if (groups.Length == 0) return name.ToString(); @@ -97,13 +103,14 @@ namespace OpenNest.Labels /// less when the text is longer than the box: it is shrunk to fit, to /// of the box height at the least. /// - public static List> Strokes(Drawing drawing, double partRotation, double grainAngle) + public static List> Strokes(Drawing drawing, double partRotation, double grainAngle, + PartLabelMode mode = PartLabelMode.PartNumberAndBendGroups) { var box = drawing?.LabelBox; if (box == null || !box.IsValid || !double.IsFinite(partRotation) || !double.IsFinite(grainAngle)) return null; - var text = Text(drawing, partRotation, grainAngle); + var text = Text(drawing, partRotation, grainAngle, mode); if (text.Length == 0) return null; @@ -137,9 +144,10 @@ namespace OpenNest.Labels /// (etch) moves, each stroke started by a rapid. Returns false and leaves the program /// unchanged when has nothing to etch. /// - public static bool AddTo(Program program, Drawing drawing, double partRotation, double grainAngle) + public static bool AddTo(Program program, Drawing drawing, double partRotation, double grainAngle, + PartLabelMode mode = PartLabelMode.PartNumberAndBendGroups) { - var strokes = Strokes(drawing, partRotation, grainAngle); + var strokes = Strokes(drawing, partRotation, grainAngle, mode); if (program == null || strokes == null || strokes.Count == 0) return false; diff --git a/OpenNest.Data/MachineCuttingDefaults.cs b/OpenNest.Data/MachineCuttingDefaults.cs index f0692174..a3cdadcb 100644 --- a/OpenNest.Data/MachineCuttingDefaults.cs +++ b/OpenNest.Data/MachineCuttingDefaults.cs @@ -132,7 +132,7 @@ public static class MachineCuttingDefaults TabSizeMinWidth = parameters.TabSizeMinWidth * scale, TabSizeMaxWidth = parameters.TabSizeMaxWidth * scale, SliceTippingSlugs = parameters.SliceTippingSlugs, - EtchPartLabels = parameters.EtchPartLabels, + LabelMode = parameters.LabelMode, PierceClearance = parameters.PierceClearance * scale, PierceDiameter = parameters.PierceDiameter * scale, Unknown = previous?.Unknown, @@ -151,7 +151,7 @@ public static class MachineCuttingDefaults parameters.TabSizeMinWidth = cutting.TabSizeMinWidth * scale; parameters.TabSizeMaxWidth = cutting.TabSizeMaxWidth * scale; parameters.SliceTippingSlugs = cutting.SliceTippingSlugs; - parameters.EtchPartLabels = cutting.EtchPartLabels; + parameters.LabelMode = cutting.ResolvedLabelMode; parameters.PierceClearance = cutting.PierceClearance * scale; parameters.PierceDiameter = cutting.PierceDiameter * scale; } diff --git a/OpenNest.Data/ThicknessCuttingConfig.cs b/OpenNest.Data/ThicknessCuttingConfig.cs index ed7c963b..80b05f33 100644 --- a/OpenNest.Data/ThicknessCuttingConfig.cs +++ b/OpenNest.Data/ThicknessCuttingConfig.cs @@ -1,5 +1,6 @@ using System.Text.Json; using System.Text.Json.Serialization; +using OpenNest.CNC.CuttingStrategy; namespace OpenNest.Data; @@ -33,9 +34,25 @@ public class ThicknessCuttingConfig [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool SliceTippingSlugs { get; set; } + /// What Plan Cutting etches in each part's label box; written only when not off. + [JsonConverter(typeof(JsonStringEnumConverter))] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public PartLabelMode LabelMode { get; set; } + + /// + /// Read only: the old on/off part label option, which meant the number with its bend + /// groups. Never written; files saved with it load as . + /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool EtchPartLabels { get; set; } + /// , or the full label when only the old on/off option is set. + [JsonIgnore] + public PartLabelMode ResolvedLabelMode => + LabelMode != PartLabelMode.Off ? LabelMode + : EtchPartLabels ? PartLabelMode.PartNumberAndBendGroups + : PartLabelMode.Off; + public double PierceClearance { get; set; } = 0.0625; /// The pierce zone's diameter; 0 turns it off. diff --git a/OpenNest.Engine/CuttingPlanning/CuttingPlanService.cs b/OpenNest.Engine/CuttingPlanning/CuttingPlanService.cs index 7be82471..19ac4221 100644 --- a/OpenNest.Engine/CuttingPlanning/CuttingPlanService.cs +++ b/OpenNest.Engine/CuttingPlanning/CuttingPlanService.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading; using OpenNest.CNC; using OpenNest.CNC.CuttingPlanning; +using OpenNest.CNC.CuttingStrategy; using OpenNest.CutOffs; using OpenNest.Diagnostics; using OpenNest.Geometry; @@ -156,9 +157,9 @@ public static class CuttingPlanService } // The label is etched, never material: clean bounds and lead material skip scribe // moves, and the planner emits them like any other mark (docs/label-box.md). - else if (request.ConfirmedParameters?.EtchPartLabels == true) + else if (request.ConfirmedParameters?.LabelMode is { } labelMode && labelMode != PartLabelMode.Off) PartLabels.AddTo(ownedClean, source.BaseDrawing, source.Rotation, - request.Plate?.GrainAngle ?? 0); + request.Plate?.GrainAngle ?? 0, labelMode); // Material extent only: remote rapids and scribe marks must not widen it, or a // genuine insert could fail the containment prefilter. var cleanBounds = NestedPartContainment.CleanBounds(ownedClean, source.Location, token); diff --git a/OpenNest.IO/CuttingParametersDto.cs b/OpenNest.IO/CuttingParametersDto.cs index 32fce1c1..85cfd02f 100644 --- a/OpenNest.IO/CuttingParametersDto.cs +++ b/OpenNest.IO/CuttingParametersDto.cs @@ -41,8 +41,20 @@ public class CuttingParametersDto // Written only when on, so files and settings saved without it are unchanged. [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] public bool SliceTippingSlugs { get; set; } + [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] + [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] + public PartLabelMode LabelMode { get; set; } + // Read only: the old on/off part label option, which meant the number with its bend groups. + // Never written; files saved with it load as PartNumberAndBendGroups. [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] public bool EtchPartLabels { get; set; } + + /// , or the full label when only the old on/off option is set. + [System.Text.Json.Serialization.JsonIgnore] + public PartLabelMode ResolvedLabelMode => + LabelMode != PartLabelMode.Off ? LabelMode + : EtchPartLabels ? PartLabelMode.PartNumberAndBendGroups + : PartLabelMode.Off; public SequenceDto Sequencing { get; set; } = new(); public AssignmentDto Assignment { get; set; } = new(); diff --git a/OpenNest.IO/CuttingParametersSerializer.cs b/OpenNest.IO/CuttingParametersSerializer.cs index 5478ebbf..9039fbca 100644 --- a/OpenNest.IO/CuttingParametersSerializer.cs +++ b/OpenNest.IO/CuttingParametersSerializer.cs @@ -95,7 +95,7 @@ public static class CuttingParametersSerializer NoBedTabMaxWidth = parameters.TabSizeMaxWidth, TabHeldMaxLength = parameters.TabHeldMaxLength, SliceTippingSlugs = parameters.SliceTippingSlugs, - EtchPartLabels = parameters.EtchPartLabels, + LabelMode = parameters.LabelMode, Sequencing = ToSequenceDto(parameters.Sequencing), Assignment = ToAssignmentDto(parameters.Assignment), }; @@ -134,7 +134,7 @@ public static class CuttingParametersSerializer TabSizeMaxWidth = dto.NoBedTabMaxWidth, TabHeldMaxLength = dto.TabHeldMaxLength, SliceTippingSlugs = dto.SliceTippingSlugs, - EtchPartLabels = dto.EtchPartLabels, + LabelMode = dto.ResolvedLabelMode, Sequencing = FromSequenceDto(dto.Sequencing), Assignment = FromAssignmentDto(dto.Assignment), }; diff --git a/OpenNest.Tests/Labels/PartLabelTests.cs b/OpenNest.Tests/Labels/PartLabelTests.cs index a67797f0..98d1fea4 100644 --- a/OpenNest.Tests/Labels/PartLabelTests.cs +++ b/OpenNest.Tests/Labels/PartLabelTests.cs @@ -251,10 +251,13 @@ public class PartLabelTests // ---- Plan Cutting ---- - private static CuttingParameters Parameters(bool labels) + private static CuttingParameters Parameters(bool labels) => + Parameters(labels ? PartLabelMode.PartNumberAndBendGroups : PartLabelMode.Off); + + private static CuttingParameters Parameters(PartLabelMode mode) { var parameters = ExplicitContourTests.Parameters(); - parameters.EtchPartLabels = labels; + parameters.LabelMode = mode; return parameters; } @@ -333,19 +336,127 @@ public class PartLabelTests // ---- the option ---- + [Fact] + public void PlanCutting_PartNumberMode_EtchesTheNumberWithoutTheGroups() + { + // "7" alone is one glyph; "7-A" adds a dash and a letter, so it has more strokes. + var drawing = Panel("7", BendAt(Quarter)); + var strokesOf = (PartLabelMode mode) => + { + var (plate, _) = PlateOf(drawing, Parameters(mode)); + var result = CuttingPlanService.Plan(CuttingPlanRequest.ForPlate(plate, Vector.Zero, + confirmedParameters: Parameters(mode))); + Assert.Equal(CuttingPlanStatus.Ready, result.Status); + return ScribeOf(result).Count; + }; + + var numberOnly = strokesOf(PartLabelMode.PartNumber); + var full = strokesOf(PartLabelMode.PartNumberAndBendGroups); + + Assert.True(numberOnly > 0); + Assert.True(full > numberOnly); + Assert.Equal(0, strokesOf(PartLabelMode.Off)); + } + + // ---- the option ---- + + [Fact] + public void Text_PartNumberMode_OmitsTheGroups_AndOffIsEmpty() + { + var drawing = Panel("1234", BendAt(0), BendAt(Quarter)); + + Assert.Equal("1234", PartLabels.Text(drawing, 0, 0, PartLabelMode.PartNumber)); + Assert.Equal("1234-AB", PartLabels.Text(drawing, 0, 0, PartLabelMode.PartNumberAndBendGroups)); + Assert.Equal("1234-AB", PartLabels.Text(drawing, 0, 0)); + Assert.Equal(string.Empty, PartLabels.Text(drawing, 0, 0, PartLabelMode.Off)); + // A name the font cannot draw is nothing to etch in number mode, even with bends. + Assert.Equal(string.Empty, PartLabels.Text(Panel("()", BendAt(Quarter)), 0, 0, PartLabelMode.PartNumber)); + } + + [Fact] + public void AddTo_OffMode_LeavesTheProgramAlone() + { + var drawing = Panel("1234", BendAt(Quarter)); + var program = (Program)drawing.Program.Clone(); + var before = program.Codes.Count; + + Assert.False(PartLabels.AddTo(program, drawing, 0, 0, PartLabelMode.Off)); + Assert.Equal(before, program.Codes.Count); + Assert.True(PartLabels.AddTo(program, drawing, 0, 0, PartLabelMode.PartNumber)); + } + [Fact] public void Option_IsOffByDefault_AndSurvivesEveryCopyAndSave() { - Assert.False(new CuttingParameters().EtchPartLabels); + Assert.Equal(PartLabelMode.Off, new CuttingParameters().LabelMode); - var on = Parameters(true); - Assert.True(OwnedCuttingParameters.Copy(on).EtchPartLabels); - Assert.True(CuttingParametersSerializer.Deserialize(CuttingParametersSerializer.Serialize(on)).EtchPartLabels); - Assert.False(CuttingParametersSerializer.Deserialize(CuttingParametersSerializer.Serialize(Parameters(false))).EtchPartLabels); + foreach (var mode in new[] { PartLabelMode.PartNumber, PartLabelMode.PartNumberAndBendGroups }) + { + var on = Parameters(mode); + Assert.Equal(mode, OwnedCuttingParameters.Copy(on).LabelMode); + Assert.Equal(mode, CuttingParametersSerializer.Deserialize(CuttingParametersSerializer.Serialize(on)).LabelMode); - var config = MachineCuttingDefaults.ToCuttingConfig(on); - Assert.True(config.EtchPartLabels); - Assert.True(MachineCuttingDefaults.CuttingOf(config).EtchPartLabels); - Assert.False(MachineCuttingDefaults.CuttingOf(null).EtchPartLabels); + var config = MachineCuttingDefaults.ToCuttingConfig(on); + Assert.Equal(mode, config.LabelMode); + Assert.Equal(mode, MachineCuttingDefaults.CuttingOf(config).LabelMode); + } + + Assert.Equal(PartLabelMode.Off, + CuttingParametersSerializer.Deserialize(CuttingParametersSerializer.Serialize(Parameters(false))).LabelMode); + Assert.Equal(PartLabelMode.Off, MachineCuttingDefaults.CuttingOf(null).LabelMode); + } + + [Fact] + public void Fingerprint_SeparatesTheThreeModes_AndKeepsTheOldFullLabelOne() + { + var off = StateFingerprint.Of(Parameters(PartLabelMode.Off)); + var number = StateFingerprint.Of(Parameters(PartLabelMode.PartNumber)); + var full = StateFingerprint.Of(Parameters(PartLabelMode.PartNumberAndBendGroups)); + + Assert.NotEqual(off, number); + Assert.NotEqual(off, full); + Assert.NotEqual(number, full); + } + + [Fact] + public void OldOnOffOption_LoadsAsTheFullLabel() + { + // Settings saved before the mode existed wrote the option as "etchPartLabels": true. + var current = CuttingParametersSerializer.Serialize(Parameters(PartLabelMode.PartNumberAndBendGroups)); + Assert.DoesNotContain("etchPartLabels", current); + Assert.Contains("\"labelMode\":\"PartNumberAndBendGroups\"", current); + + var on = current.Replace("\"labelMode\":\"PartNumberAndBendGroups\"", "\"etchPartLabels\":true"); + Assert.Equal(PartLabelMode.PartNumberAndBendGroups, CuttingParametersSerializer.Deserialize(on).LabelMode); + + var off = current.Replace("\"labelMode\":\"PartNumberAndBendGroups\"", "\"etchPartLabels\":false"); + Assert.Equal(PartLabelMode.Off, CuttingParametersSerializer.Deserialize(off).LabelMode); + + var missing = CuttingParametersSerializer.Serialize(Parameters(PartLabelMode.Off)); + Assert.DoesNotContain("labelMode", missing); + Assert.Equal(PartLabelMode.Off, CuttingParametersSerializer.Deserialize(missing).LabelMode); + + // The new key wins when both are present. + var both = current.Replace("\"labelMode\":\"PartNumberAndBendGroups\"", + "\"labelMode\":\"PartNumber\",\"etchPartLabels\":true"); + Assert.Equal(PartLabelMode.PartNumber, CuttingParametersSerializer.Deserialize(both).LabelMode); + } + + [Fact] + public void OldOnOffOption_InAMachineThicknessConfig_LoadsAsTheFullLabel() + { + var options = new System.Text.Json.JsonSerializerOptions(); + var old = System.Text.Json.JsonSerializer.Deserialize( + "{\"EtchPartLabels\":true}", options); + Assert.Equal(PartLabelMode.PartNumberAndBendGroups, MachineCuttingDefaults.CuttingOf(old).LabelMode); + + var off = System.Text.Json.JsonSerializer.Deserialize("{}", options); + Assert.Equal(PartLabelMode.Off, MachineCuttingDefaults.CuttingOf(off).LabelMode); + + // Saving it again writes the mode, not the old key. + var saved = System.Text.Json.JsonSerializer.Serialize( + MachineCuttingDefaults.ToCuttingConfig(MachineCuttingDefaults.CuttingOf(old)), options); + Assert.Contains("\"LabelMode\":\"PartNumberAndBendGroups\"", saved); + Assert.DoesNotContain("EtchPartLabels", saved); } } diff --git a/OpenNest.WinForms.Tests/Controls/CuttingPanelTests.cs b/OpenNest.WinForms.Tests/Controls/CuttingPanelTests.cs index 15085bee..04bb4756 100644 --- a/OpenNest.WinForms.Tests/Controls/CuttingPanelTests.cs +++ b/OpenNest.WinForms.Tests/Controls/CuttingPanelTests.cs @@ -63,16 +63,19 @@ public class CuttingPanelTests } [Fact] - public void EtchPartLabels_IsOffByDefault_AndRoundTrips() + public void LabelMode_IsOffByDefault_AndRoundTrips() { StaTestThread.Run(() => { using var panel = new CuttingPanel(); panel.LoadFromParameters(new CuttingParameters()); - Assert.False(panel.BuildParameters().EtchPartLabels); + Assert.Equal(PartLabelMode.Off, panel.BuildParameters().LabelMode); - panel.LoadFromParameters(new CuttingParameters { EtchPartLabels = true }); - Assert.True(panel.BuildParameters().EtchPartLabels); + foreach (var mode in new[] { PartLabelMode.PartNumber, PartLabelMode.PartNumberAndBendGroups, PartLabelMode.Off }) + { + panel.LoadFromParameters(new CuttingParameters { LabelMode = mode }); + Assert.Equal(mode, panel.BuildParameters().LabelMode); + } }, TimeSpan.FromSeconds(30), "The cutting panel did not round-trip the part label option."); } diff --git a/OpenNest/Controls/CuttingPanel.cs b/OpenNest/Controls/CuttingPanel.cs index d217ba5b..4372e424 100644 --- a/OpenNest/Controls/CuttingPanel.cs +++ b/OpenNest/Controls/CuttingPanel.cs @@ -32,7 +32,7 @@ namespace OpenNest.Controls private readonly NumericUpDown nudTabSizeMax; private readonly NumericUpDown nudTabHeldMax; private readonly CheckBox chkSliceSlugs; - private readonly CheckBox chkEtchPartLabels; + private readonly ComboBox cboLabelMode; private readonly NumericUpDown nudPierceClearance; private readonly NumericUpDown nudPierceDiameter; @@ -287,17 +287,22 @@ namespace OpenNest.Controls // Marks: the part number and bend groups etched in each drawing's label box. AddSection("Marks"); - chkEtchPartLabels = new CheckBox + var marksGrid = ControlFactory.SettingsGrid(0); + cboLabelMode = new ComboBox { - Text = "Etch part number and bend groups", - AutoSize = true, - Margin = new Padding(0, 3, 0, 3), + DropDownStyle = ComboBoxStyle.DropDownList, + Width = 200, }; - toolTip.SetToolTip(chkEtchPartLabels, - "Plan Cutting etches each part's number and bend groups (A across the grain, B with it, " - + "then C and on) in the label box set in the CAD Converter. Parts with no label box get none."); - layout.Controls.Add(chkEtchPartLabels); - chkEtchPartLabels.CheckedChanged += (s, e) => OnParametersChanged(); + // Index order is the PartLabelMode value order. + cboLabelMode.Items.AddRange(new object[] { "Off", "Part number", "Part number and bend groups" }); + cboLabelMode.SelectedIndex = (int)PartLabelMode.Off; + AddRow(marksGrid, "Etch part label:", cboLabelMode, 0); + toolTip.SetToolTip(cboLabelMode, + "Plan Cutting etches each part's number in the label box set in the CAD Converter, " + + "alone or with its bend groups (A across the grain, B with it, then C and on). " + + "Parts with no label box get none."); + layout.Controls.Add(marksGrid); + cboLabelMode.SelectedIndexChanged += (s, e) => OnParametersChanged(); // Pierce AddSection("Pierce"); @@ -389,7 +394,7 @@ namespace OpenNest.Controls parameters.TabSizeMaxWidth = (double)nudTabSizeMax.Value; parameters.TabHeldMaxLength = (double)nudTabHeldMax.Value; parameters.SliceTippingSlugs = chkSliceSlugs.Checked; - parameters.EtchPartLabels = chkEtchPartLabels.Checked; + parameters.LabelMode = (PartLabelMode)System.Math.Max(0, cboLabelMode.SelectedIndex); return parameters; } @@ -417,7 +422,7 @@ namespace OpenNest.Controls tabOptions.Enabled = chkTabsEnabled.Checked; UpdateSupportTabOptions(); chkSliceSlugs.Checked = p.SliceTippingSlugs; - chkEtchPartLabels.Checked = p.EtchPartLabels; + cboLabelMode.SelectedIndex = (int)p.LabelMode; nudPierceClearance.Value = Clamp(nudPierceClearance, p.PierceClearance); nudPierceDiameter.Value = Clamp(nudPierceDiameter, p.PierceDiameter); chkRoundLeadInAngles.Checked = p.RoundLeadInAngles; diff --git a/docs/label-box.md b/docs/label-box.md index ffb2920c..2f20d25f 100644 --- a/docs/label-box.md +++ b/docs/label-box.md @@ -2,7 +2,7 @@ A drawing can carry a label box: the rectangle where its part number and bend groups are etched, found on flat material clear of everything else. The CAD Converter stores and shows the -placement; Plan Cutting etches the text when **Etch part number and bend groups** is on (see +placement; Plan Cutting etches the text when **Etch part label** is not Off (see [Etching the label](#etching-the-label)). In the CAD Converter, **Label Box...** (bottom bar) finds the best spot for the shown part. @@ -47,17 +47,33 @@ File format: see [drawing label box](nest-file-format.md#drawing-label-box). ## Etching the label -Cutting Parameters > Marks > **Etch part number and bend groups** (`CuttingParameters.EtchPartLabels`) -is off by default and kept per machine thickness like the other cutting options +Cutting Parameters > Marks > **Etch part label** (`CuttingParameters.LabelMode`, a `PartLabelMode`) +is **Off** by default and kept per machine thickness like the other cutting options ([machine cutting defaults](machine-cutting-defaults.md), saved with the nest and the machine's -thickness settings). When it is on, Plan Cutting adds each part's label to the clean program it +thickness settings). It has three choices: + +| Choice | Etched | Example | +|--------|--------|---------| +| Off | nothing | | +| Part number | the drawing name | `1234` | +| Part number and bend groups | the name, then a dash and the bend groups | `1234-AB` | + +When it is not Off, Plan Cutting adds each part's label to the clean program it plans from, so the label is emitted as scribe (etch) moves like any other mark: it shows in the plan, counts in cut time, posts through the etch path and never enters nesting or collision geometry (marks are not material). Nothing changes while the option is off, and parts planned before it was -turned on keep no label until planned again. +turned on keep no label until planned again. The plan fingerprint records the mode, so changing it +makes an earlier plan stale. + +Settings saved before the mode existed held an on/off `etchPartLabels` value (in the nest's cutting +parameters, the desktop settings and a machine thickness's cutting settings). It meant the full +label, so `true` loads as **Part number and bend groups** and `false` or a missing value as **Off**; +the old key is read but never written again. When both keys are present, `labelMode` wins. - **Text.** `PartLabels.Text` is the drawing name in capitals (characters the font lacks are - dropped), then a dash and the part's bend groups when it has bends: `1234-AB`. + dropped), then, in **Part number and bend groups** mode, a dash and the part's bend groups when it + has bends: `1234-AB`. **Part number** mode leaves the groups out, so a part with bends still gets + `1234`. - **Bend groups.** A bend's group is its line's direction against the sheet grain in 15° steps (`BendGrain.Bucket`, bend line plus the part's rotation against `Plate.GrainAngle`), named by a fixed letter so a group means the same thing on every part and sheet: **A** across the grain, diff --git a/docs/machine-cutting-defaults.md b/docs/machine-cutting-defaults.md index 10660868..52528e14 100644 --- a/docs/machine-cutting-defaults.md +++ b/docs/machine-cutting-defaults.md @@ -27,7 +27,7 @@ save them on close; thicknesses matching none stay blank. Every setting in Plan Cutting's Cutting Parameters dialog and the Place Lead-in panel is kept on the nest's machine thickness: leads on the Outside Cuts and Inside Cuts tabs, lead-in angle -rounding, tabs, [slug slicing](support-tabs.md#slug-slices), [part label etching](label-box.md#etching-the-label) and pierce on the Tabs & Pierce tab +rounding, tabs, [slug slicing](support-tabs.md#slug-slices), [part label etching](label-box.md#etching-the-label) (off, part number, or part number and bend groups) and pierce on the Tabs & Pierce tab (`ThicknessConfig.Cutting`). So 0.25 in can tab parts while 0.5 in tabs none, and in Database mode every workstation gets the same settings. The dialog names what it edits above its fields ("Saved for Fiber 1 · Mild Steel A36