diff --git a/OpenNest.Core/CNC/CuttingPlanning/OwnedCuttingParameters.cs b/OpenNest.Core/CNC/CuttingPlanning/OwnedCuttingParameters.cs index 050cde9b..2472b0c1 100644 --- a/OpenNest.Core/CNC/CuttingPlanning/OwnedCuttingParameters.cs +++ b/OpenNest.Core/CNC/CuttingPlanning/OwnedCuttingParameters.cs @@ -45,7 +45,6 @@ internal static class OwnedCuttingParameters TabBySize = source.TabBySize, TabSizeMinWidth = Dimension(source.TabSizeMinWidth), TabSizeMaxWidth = Dimension(source.TabSizeMaxWidth), - TabHeldMaxLength = Dimension(source.TabHeldMaxLength), SliceTippingSlugs = source.SliceTippingSlugs, LabelMode = source.LabelMode, Sequencing = new SequenceParameters diff --git a/OpenNest.Core/CNC/CuttingPlanning/StateFingerprint.cs b/OpenNest.Core/CNC/CuttingPlanning/StateFingerprint.cs index 1dfd262a..f4a5009e 100644 --- a/OpenNest.Core/CNC/CuttingPlanning/StateFingerprint.cs +++ b/OpenNest.Core/CNC/CuttingPlanning/StateFingerprint.cs @@ -93,7 +93,6 @@ internal static class StateFingerprint Flag(p.TabBySize); Number(p.TabSizeMinWidth); Number(p.TabSizeMaxWidth); - Number(p.TabHeldMaxLength); // Only when on, so fingerprints taken before the setting existed still match. if (p.SliceTippingSlugs) text.Append("slugSlices;"); diff --git a/OpenNest.Core/CNC/CuttingStrategy/CuttingParameters.cs b/OpenNest.Core/CNC/CuttingStrategy/CuttingParameters.cs index 2fc3e8d8..80fc5d32 100644 --- a/OpenNest.Core/CNC/CuttingStrategy/CuttingParameters.cs +++ b/OpenNest.Core/CNC/CuttingStrategy/CuttingParameters.cs @@ -92,19 +92,6 @@ namespace OpenNest.CNC.CuttingStrategy && width >= TabSizeMinWidth - Math.Tolerance.Epsilon && width <= TabSizeMaxWidth + Math.Tolerance.Epsilon; - /// - /// With on a plate with a support bed, the longest part (the - /// long side of its outline's minimum-area bounding rectangle) its tab alone holds: such a - /// part the bed cannot hold level is tabbed, and any tab clear of inside corners steadies - /// it. 0 turns the rule off. New settings start at 6; settings saved without it read as 0. - /// - public double TabHeldMaxLength { get; set; } = 6; - - /// Whether a part long is held by its tab alone (see ). - public bool TabHoldsAt(double length) => - TabHeldMaxLength > 0 && double.IsFinite(TabHeldMaxLength) - && length <= TabHeldMaxLength + Math.Tolerance.Epsilon; - /// /// Slices the slug of each cutout its plate's support bed cannot hold level along the /// bed's contact lines before the cutout is cut, so the slug drops as pieces between the diff --git a/OpenNest.Core/Diagnostics/PartSupportReview.cs b/OpenNest.Core/Diagnostics/PartSupportReview.cs index 8c882f57..255c0e42 100644 --- a/OpenNest.Core/Diagnostics/PartSupportReview.cs +++ b/OpenNest.Core/Diagnostics/PartSupportReview.cs @@ -104,14 +104,12 @@ internal static class PartSupportReview { var held = !support.HasBed ? FormattableString.Invariant($"is {support.Width:0.####} wide, in the width range tabbed by size,") - : support.IsHeldByTab - ? FormattableString.Invariant($"is {support.Length:0.####} long, short enough for its tab alone to hold,") : support.Margin == double.NegativeInfinity ? "rests on no support contact" : support.Margin < 0 ? FormattableString.Invariant($"has its center of gravity {-support.Margin:0.####} outside its support contacts") : FormattableString.Invariant($"has its center of gravity only {support.Margin:0.####} inside its support contacts"); - var needs = support.HasBed && !support.IsHeldByTab + var needs = support.HasBed ? FormattableString.Invariant($" (needs {support.RequiredMargin:0.####})") : ""; return $"The part {held}{needs} and it has no tab; it may tip once cut free." + (support.BestTabPoint is { } suggested diff --git a/OpenNest.Core/Support/SupportAnalyzer.cs b/OpenNest.Core/Support/SupportAnalyzer.cs index 25d063ed..8a56e372 100644 --- a/OpenNest.Core/Support/SupportAnalyzer.cs +++ b/OpenNest.Core/Support/SupportAnalyzer.cs @@ -106,23 +106,8 @@ namespace OpenNest.Support } /// - /// The part's length: the long side of its outline's minimum-area bounding rectangle, or - /// NaN when its material could not be read. - /// - public static double Length(SupportMaterial material) - { - ArgumentNullException.ThrowIfNull(material); - if (!material.IsComplete || material.Outline.Count < 3) - return double.NaN; - var box = BoundingRectangle(material.Outline); - return System.Math.Max(box.Width, box.Height); - } - - /// - /// , a bed analysis of a part the bed cannot hold level, for a - /// part short enough for its tab alone to hold - /// (): its contacts and - /// margin are kept, any tab clear of inside corners steadies it, and the best tab point is + /// , a bed analysis of a part the bed cannot hold level, for the + /// part held by its support tab: its contacts and margin are kept, any tab clear of inside corners steadies it, and the best tab point is /// chosen as without a bed (). /// public static PartSupport HeldByTab(PartSupport support, SupportMaterial material) @@ -133,7 +118,7 @@ namespace OpenNest.Support return support; var best = BestTabPoint(material.Outline, support.CenterOfGravity, support.InsideCorners, support.InsideCornerClearance, _ => double.PositiveInfinity, out _); - return support.WithTabHold(best, Length(material)); + return support.WithTabHold(best); } // The outline point a tab steadies the part most from, by `score`, clear of every inside @@ -447,9 +432,9 @@ namespace OpenNest.Support // A part on a plate with no bed, tabbed for its width: it rests on nothing modeled, and a // tab anywhere clear of inside corners is as good as any other. - // A copy of `source` held by its tab alone: it keeps its contacts and margin, and any tab + // A copy of `source` held by its support tab: it keeps its contacts and margin, and any tab // clear of inside corners steadies it. - private PartSupport(PartSupport source, Vector? bestTabPoint, double length) + private PartSupport(PartSupport source, Vector? bestTabPoint) { CenterOfGravity = source.CenterOfGravity; Contacts = source.Contacts; @@ -461,10 +446,9 @@ namespace OpenNest.Support BestTabPoint = bestTabPoint; BestTabMargin = double.PositiveInfinity; IsHeldByTab = true; - Length = length; } - internal PartSupport WithTabHold(Vector? bestTabPoint, double length) => new(this, bestTabPoint, length); + internal PartSupport WithTabHold(Vector? bestTabPoint) => new(this, bestTabPoint); internal PartSupport(Vector centerOfGravity, Vector? bestTabPoint, IReadOnlyList insideCorners, double insideCornerClearance, double width) @@ -487,15 +471,11 @@ namespace OpenNest.Support public bool HasBed { get; } = true; /// - /// True for a part on a bed that cannot hold it level but short enough for its tab alone - /// to hold (): any tab clear of inside corners - /// steadies it. + /// True for a part on a bed that cannot hold it level, held by its support tab instead + /// (): any tab clear of inside corners steadies it. /// public bool IsHeldByTab { get; } - /// The part's length when (see ); NaN otherwise. - public double Length { get; } = double.NaN; - /// The part's width when analyzed without a bed (see ); NaN otherwise. public double Width { get; } = double.NaN; diff --git a/OpenNest.Core/Support/SupportTabSettings.cs b/OpenNest.Core/Support/SupportTabSettings.cs index 46acfe8a..65c0543c 100644 --- a/OpenNest.Core/Support/SupportTabSettings.cs +++ b/OpenNest.Core/Support/SupportTabSettings.cs @@ -35,9 +35,8 @@ namespace OpenNest.Support /// /// The analysis that tabs a part, or null when support tabs are off or the part is - /// outside the rule: by the bed, the bed's analysis, held by its tab alone - /// () when the bed cannot hold it level and its - /// length is within ; by size (no bed, or + /// outside the rule: by the bed, the bed's analysis, held by its tab + /// () when the bed cannot hold it level; by size (no bed, or /// ), a no-bed analysis /// () of a part whose width is in /// 's range. The part needs a tab when @@ -56,7 +55,6 @@ namespace OpenNest.Support { var support = SupportAnalyzer.Analyze(bed, quadrant, material, insideCornerClearance); return support is { IsComplete: true, IsSupported: false } - && parameters.TabHoldsAt(SupportAnalyzer.Length(material)) ? SupportAnalyzer.HeldByTab(support, material) : support; } diff --git a/OpenNest.Data/MachineCuttingDefaults.cs b/OpenNest.Data/MachineCuttingDefaults.cs index a3cdadcb..257fd621 100644 --- a/OpenNest.Data/MachineCuttingDefaults.cs +++ b/OpenNest.Data/MachineCuttingDefaults.cs @@ -128,7 +128,6 @@ public static class MachineCuttingDefaults Tabs = parameters.SupportTabs, TabBySize = parameters.TabBySize, TabSize = (parameters.TabConfig?.Size ?? previous?.TabSize ?? new ThicknessCuttingConfig().TabSize) * scale, - TabHeldMaxLength = parameters.TabHeldMaxLength * scale, TabSizeMinWidth = parameters.TabSizeMinWidth * scale, TabSizeMaxWidth = parameters.TabSizeMaxWidth * scale, SliceTippingSlugs = parameters.SliceTippingSlugs, @@ -147,7 +146,6 @@ public static class MachineCuttingDefaults // The thickness's tabs replace any retired "Tab every part" the fallback still carries. parameters.TabsEnabled = false; parameters.TabConfig = new NormalTab { Size = cutting.TabSize * scale }; - parameters.TabHeldMaxLength = cutting.TabHeldMaxLength * scale; parameters.TabSizeMinWidth = cutting.TabSizeMinWidth * scale; parameters.TabSizeMaxWidth = cutting.TabSizeMaxWidth * scale; parameters.SliceTippingSlugs = cutting.SliceTippingSlugs; diff --git a/OpenNest.Data/ThicknessCuttingConfig.cs b/OpenNest.Data/ThicknessCuttingConfig.cs index 624cbb04..22f0c8a6 100644 --- a/OpenNest.Data/ThicknessCuttingConfig.cs +++ b/OpenNest.Data/ThicknessCuttingConfig.cs @@ -22,9 +22,6 @@ public class ThicknessCuttingConfig public double TabSize { get; set; } = 0.03; - /// The longest part its tab alone holds; 0 turns the rule off. - public double TabHeldMaxLength { get; set; } = 6; - public double TabSizeMinWidth { get; set; } /// The widest part tabbed by size; 0 tabs nothing by size. diff --git a/OpenNest.Engine/CuttingPlanning/SupportTabCapture.cs b/OpenNest.Engine/CuttingPlanning/SupportTabCapture.cs index a390e089..529644ba 100644 --- a/OpenNest.Engine/CuttingPlanning/SupportTabCapture.cs +++ b/OpenNest.Engine/CuttingPlanning/SupportTabCapture.cs @@ -81,15 +81,13 @@ internal static class SupportTabCapture var part = source.SourceOrdinal + 1; var held = !support.HasBed ? FormattableString.Invariant($"is {support.Width:0.####} wide, in the width range tabbed by size,") - : support.IsHeldByTab - ? FormattableString.Invariant($"is {support.Length:0.####} long, short enough for its tab alone to hold,") : support.Margin == double.NegativeInfinity ? "rests on no support contact" : support.Margin < 0 ? FormattableString.Invariant($"has its center of gravity {-support.Margin:0.####} outside its support contacts") : FormattableString.Invariant($"has its center of gravity only {support.Margin:0.####} inside its support contacts"); var why = $"drawing pin {prepared.PinNumberOf(prepared.PerimeterOrdinal)} cuts its outside without a tab"; - var needs = support.HasBed && !support.IsHeldByTab ? FormattableString.Invariant($" (needs {support.RequiredMargin:0.####})") : ""; + var needs = support.HasBed ? FormattableString.Invariant($" (needs {support.RequiredMargin:0.####})") : ""; return new CuttingPlanFinding(source.SourceOrdinal, source.SourcePart, null, null, PostVerificationKind.PartSupport, $"Part {part} {held}{needs} and {why}; it may tip once cut free."); } diff --git a/OpenNest.IO.Tests/SupportGridPersistenceTests.cs b/OpenNest.IO.Tests/SupportGridPersistenceTests.cs index 5aedc753..a60141e7 100644 --- a/OpenNest.IO.Tests/SupportGridPersistenceTests.cs +++ b/OpenNest.IO.Tests/SupportGridPersistenceTests.cs @@ -122,15 +122,10 @@ public class SupportGridPersistenceTests } [Fact] - public void TabHeldLengthRoundTripsInCuttingParameters() + public void SettingsSavedWithTheRetiredTabHeldLengthStillRead() { - var parameters = new CuttingParameters { SupportTabs = true, TabHeldMaxLength = 2 }; + var restored = CuttingParametersSerializer.Deserialize("""{"supportTabs":true,"tabHeldMaxLength":2}"""); - var restored = CuttingParametersSerializer.Deserialize(CuttingParametersSerializer.Serialize(parameters)); - var snapshot = CuttingParametersSerializer.FromDto(CuttingParametersSerializer.ToDto(parameters)); - - Assert.Equal(2, restored.TabHeldMaxLength); - Assert.Equal(2, snapshot.TabHeldMaxLength); - Assert.Equal(0, CuttingParametersSerializer.Deserialize("{}").TabHeldMaxLength); + Assert.True(restored.SupportTabs); } } diff --git a/OpenNest.IO/CuttingParametersDto.cs b/OpenNest.IO/CuttingParametersDto.cs index c74b0aac..72423364 100644 --- a/OpenNest.IO/CuttingParametersDto.cs +++ b/OpenNest.IO/CuttingParametersDto.cs @@ -37,7 +37,6 @@ public class CuttingParametersDto // The size range's JSON keys keep their names from when only plates with no support bed used it. public double NoBedTabMinWidth { get; set; } public double NoBedTabMaxWidth { get; set; } - public double TabHeldMaxLength { get; set; } // 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; } diff --git a/OpenNest.IO/CuttingParametersSerializer.cs b/OpenNest.IO/CuttingParametersSerializer.cs index 9039fbca..c9f1939b 100644 --- a/OpenNest.IO/CuttingParametersSerializer.cs +++ b/OpenNest.IO/CuttingParametersSerializer.cs @@ -93,7 +93,6 @@ public static class CuttingParametersSerializer TabBySize = parameters.TabBySize, NoBedTabMinWidth = parameters.TabSizeMinWidth, NoBedTabMaxWidth = parameters.TabSizeMaxWidth, - TabHeldMaxLength = parameters.TabHeldMaxLength, SliceTippingSlugs = parameters.SliceTippingSlugs, LabelMode = parameters.LabelMode, Sequencing = ToSequenceDto(parameters.Sequencing), @@ -132,7 +131,6 @@ public static class CuttingParametersSerializer TabBySize = dto.TabBySize, TabSizeMinWidth = dto.NoBedTabMinWidth, TabSizeMaxWidth = dto.NoBedTabMaxWidth, - TabHeldMaxLength = dto.TabHeldMaxLength, SliceTippingSlugs = dto.SliceTippingSlugs, LabelMode = dto.ResolvedLabelMode, Sequencing = FromSequenceDto(dto.Sequencing), diff --git a/OpenNest.Tests/CuttingPlanning/OwnedCuttingParameterTests.cs b/OpenNest.Tests/CuttingPlanning/OwnedCuttingParameterTests.cs index 6cf28851..094225cf 100644 --- a/OpenNest.Tests/CuttingPlanning/OwnedCuttingParameterTests.cs +++ b/OpenNest.Tests/CuttingPlanning/OwnedCuttingParameterTests.cs @@ -44,7 +44,6 @@ public class OwnedCuttingParameterTests SupportTabs = true, TabSizeMinWidth = 0.5, TabSizeMaxWidth = 4, - TabHeldMaxLength = 2, RoundLeadInAngles = true, LeadInAngleIncrement = 30, Sequencing = new SequenceParameters diff --git a/OpenNest.Tests/CuttingPlanning/ShortestPathEntryTests.cs b/OpenNest.Tests/CuttingPlanning/ShortestPathEntryTests.cs index ea9cdd96..ff33ec80 100644 --- a/OpenNest.Tests/CuttingPlanning/ShortestPathEntryTests.cs +++ b/OpenNest.Tests/CuttingPlanning/ShortestPathEntryTests.cs @@ -89,7 +89,6 @@ public class ShortestPathEntryTests var bed = new SupportGrid(2, 2, offsetX: 0.7, stabilityMargin: stabilityMargin); var parameters = Parameters(); parameters.SupportTabs = true; - parameters.TabHeldMaxLength = 0; var parts = Strips(3); var snapshot = CuttingPlanService.Capture(new CuttingPlanRequest(parts, Start, confirmedParameters: parameters, preservePartOrder: true) diff --git a/OpenNest.Tests/CuttingPlanning/TutorialNestPlanningTests.cs b/OpenNest.Tests/CuttingPlanning/TutorialNestPlanningTests.cs index c12619a6..b9ec7e7b 100644 --- a/OpenNest.Tests/CuttingPlanning/TutorialNestPlanningTests.cs +++ b/OpenNest.Tests/CuttingPlanning/TutorialNestPlanningTests.cs @@ -39,7 +39,6 @@ public class TutorialNestPlanningTests "test-data", "help-tutorial", "first-nest.nest")).Read(); var parameters = CuttingParametersSerializer.Deserialize(Settings); parameters.SupportTabs = supportTabs; - parameters.TabHeldMaxLength = new CuttingParameters().TabHeldMaxLength; var plate = nest.Plates[0]; Assert.NotNull(plate.SupportBed); diff --git a/OpenNest.Tests/Data/ThicknessCuttingSettingsTests.cs b/OpenNest.Tests/Data/ThicknessCuttingSettingsTests.cs index 4b9d1ab6..12788edd 100644 --- a/OpenNest.Tests/Data/ThicknessCuttingSettingsTests.cs +++ b/OpenNest.Tests/Data/ThicknessCuttingSettingsTests.cs @@ -12,7 +12,6 @@ public class ThicknessCuttingSettingsTests Tabs = true, TabBySize = true, TabSize = 0.03, - TabHeldMaxLength = 4, TabSizeMinWidth = 0.5, TabSizeMaxWidth = 3, PierceClearance = 0.05, @@ -88,7 +87,6 @@ public class ThicknessCuttingSettingsTests Assert.True(thin.SupportTabs); Assert.True(thin.TabBySize); Assert.Equal(0.03, thin.TabConfig.Size); - Assert.Equal(4, thin.TabHeldMaxLength); Assert.Equal(0.5, thin.TabSizeMinWidth); Assert.Equal(3, thin.TabSizeMaxWidth); Assert.Equal(0.05, thin.PierceClearance); diff --git a/OpenNest.Tests/Support/TabHeldSupportTabTests.cs b/OpenNest.Tests/Support/TabHeldSupportTabTests.cs index 2eb08dde..a2f19021 100644 --- a/OpenNest.Tests/Support/TabHeldSupportTabTests.cs +++ b/OpenNest.Tests/Support/TabHeldSupportTabTests.cs @@ -10,9 +10,8 @@ using OpenNest.Tests.CuttingPlanning; namespace OpenNest.Tests.Support; /// -/// Support tabs on a bed for parts short enough for their tab alone to hold -/// (): a part the bed cannot hold level is still -/// tabbed, but any tab clear of inside corners steadies it, so it is not reported. +/// Support tabs on a bed: a part the bed cannot hold level is tabbed and held by its tab, however +/// long it is, so any tab clear of inside corners steadies it and it is not reported. /// public class TabHeldSupportTabTests { @@ -21,12 +20,11 @@ public class TabHeldSupportTabTests // A 2 inch laser grid; a 1.5 inch square rests on one of its points at most. private static readonly SupportGrid Bed = new(2, 2, 0, 0, registrationTolerance: 0.125, stabilityMargin: 0.25); - private static CuttingParameters Parameters(double tabHeldMaxLength) + private static CuttingParameters Parameters() { var parameters = ExplicitContourTests.Parameters(); parameters.SupportTabs = true; parameters.TabConfig = new NormalTab { Size = TabSize }; - parameters.TabHeldMaxLength = tabHeldMaxLength; return parameters; } @@ -50,16 +48,6 @@ public class TabHeldSupportTabTests return entry.DistanceTo(cutEnd); } - [Theory] - [InlineData(0, false)] // off - [InlineData(1, false)] - [InlineData(1.5, true)] // the bound is inclusive - [InlineData(2, true)] - public void TheLimitHoldsPartsUpToIt(double max, bool holdsALengthOfOneAndAHalf) - { - Assert.Equal(holdsALengthOfOneAndAHalf, new CuttingParameters { TabHeldMaxLength = max }.TabHoldsAt(1.5)); - } - [Theory] [InlineData(0)] [InlineData(45)] @@ -68,7 +56,7 @@ public class TabHeldSupportTabTests [InlineData(180)] [InlineData(270)] [InlineData(315)] - public void LengthOfATriangleWithTwoLeastBoxes_DoesNotDependOnItsRotation(double degrees) + public void WidthOfATriangleWithTwoLeastBoxes_DoesNotDependOnItsRotation(double degrees) { // A 5 x 5 right triangle fits its legs' square and its hypotenuse's 7.07 x 3.54 box, both // of area 25: the squarer box is the one measured, whatever way the part is turned. @@ -78,27 +66,18 @@ public class TabHeldSupportTabTests part.Rotate(degrees * System.Math.PI / 180); var material = SupportMaterial.FromPart(part); - Assert.Equal(5, SupportAnalyzer.Length(material), 6); Assert.Equal(5, SupportAnalyzer.Width(material), 6); } [Fact] - public void NewSettingsHoldPartsUpToSixLong() + public void Analyze_HoldsAPartTheBedCannotByAnyClearTab() { - Assert.Equal(6, new CuttingParameters().TabHeldMaxLength); - Assert.True(new CuttingParameters().TabHoldsAt(5)); - } - - [Fact] - public void Analyze_HoldsAShortPartTheBedCannotByAnyClearTab() - { - var (_, _, part) = Square(Parameters(2)); + var (_, _, part) = Square(Parameters()); var material = SupportMaterial.FromPart(part); - var held = SupportTabSettings.Analyze(Parameters(2), Bed, 1, material); - var bedOnly = SupportTabSettings.Analyze(Parameters(0), Bed, 1, material); + var held = SupportTabSettings.Analyze(Parameters(), Bed, 1, material); + var bedOnly = SupportAnalyzer.Analyze(Bed, 1, material); - Assert.Equal(1.5, SupportAnalyzer.Length(material), 6); Assert.False(bedOnly.IsHeldByTab); Assert.False(bedOnly.TabCanSupport); Assert.True(held.IsHeldByTab); @@ -108,41 +87,45 @@ public class TabHeldSupportTabTests Assert.True(held.TabCanSupport); Assert.True(held.AcceptsTabAt(new Vector(3, 3.75))); Assert.True(held.IsSteadiedByTabAt(new Vector(4.5, 3.75))); - Assert.False(SupportTabSettings.Analyze(Parameters(1), Bed, 1, material).IsHeldByTab); + } + + [Fact] + public void Analyze_HoldsALongStripTheBedCannotByItsTab() + { + // A 12 x 0.5 strip between grid rows rests on no contact at all. + var nest = new Nest("strip"); + var plate = new Plate(20, 20) { CuttingParameters = Parameters() }; + nest.Plates.Add(plate); + nest.SetSupportBed(Bed); + var part = new Part(new Drawing("strip", LeadPathValidationTests.Rectangle(0, 0, 12, 0.5)), new Vector(1, 2.75)); + plate.Parts.Add(part); + + var support = SupportTabSettings.Analyze(Parameters(), Bed, 1, SupportMaterial.FromPart(part)); + + Assert.False(support.IsSupported); + Assert.True(support.IsHeldByTab); + Assert.True(support.TabCanSupport); } [Fact] public void Analyze_LeavesAPartTheBedHoldsAlone() { // A 5 inch square rests on a 2 x 2 block of grid points around its center. - var (_, _, part) = Square(Parameters(6), 5); + var (_, _, part) = Square(Parameters(), 5); - var support = SupportTabSettings.Analyze(Parameters(6), Bed, 1, SupportMaterial.FromPart(part)); + var support = SupportTabSettings.Analyze(Parameters(), Bed, 1, SupportMaterial.FromPart(part)); Assert.True(support.IsSupported); Assert.False(support.IsHeldByTab); } [Fact] - public void PlanCutting_TabsAShortPartNoTabCanSteady_WithoutTheLimit_AndDoesNotWarn() + public void PlanCutting_TabsAPartWithoutAWarning() { - var (_, plate, _) = Square(Parameters(0)); + var (_, plate, _) = Square(Parameters()); var result = CuttingPlanService.Plan(CuttingPlanRequest.ForPlate(plate, Vector.Zero, - confirmedParameters: Parameters(0))); - - // Tabbed, a part counts as steady wherever its tab is. - Assert.True(result.Status == CuttingPlanStatus.Ready, string.Join("\n", result.Findings.Select(f => f.Message))); - Assert.Empty(result.Findings); - } - - [Fact] - public void PlanCutting_TabsAShortPartWithoutAWarning() - { - var (_, plate, _) = Square(Parameters(2)); - - var result = CuttingPlanService.Plan(CuttingPlanRequest.ForPlate(plate, Vector.Zero, - confirmedParameters: Parameters(2))); + confirmedParameters: Parameters())); Assert.True(result.Status == CuttingPlanStatus.Ready, string.Join("\n", result.Findings.Select(f => f.Message))); Assert.Equal(TabSize, TabGap(Assert.Single(result.ProposedOrder)), 6); @@ -158,12 +141,12 @@ public class TabHeldSupportTabTests disc.MoveTo(2, 1); disc.ArcTo(2, 1, 1, 1, RotationType.CCW); var nest = new Nest("round"); - var plate = new Plate(20, 20) { CuttingParameters = Parameters(2) }; + var plate = new Plate(20, 20) { CuttingParameters = Parameters() }; nest.Plates.Add(plate); nest.SetSupportBed(Bed); plate.Parts.Add(new Part(new Drawing("disc", disc), new Vector(3, 3))); - var proposal = CuttingPlanBatch.Capture([plate], Parameters(2), preservePartOrder: false).Plan(); + var proposal = CuttingPlanBatch.Capture([plate], Parameters(), preservePartOrder: false).Plan(); Assert.True(proposal.CanApply, string.Join("\n", proposal.Describe("in"))); Assert.Equal(TabSize, TabGap(Assert.Single(proposal.Plates[0].Result.ProposedOrder)), 6); @@ -173,19 +156,19 @@ public class TabHeldSupportTabTests } [Fact] - public void PrePost_WarnsOnlyAboutAnUntabbedShortPart() + public void PrePost_WarnsOnlyAboutAnUntabbedPart() { var lead = new Line(new Vector(0, 0), new Vector(0, 1.5)); - var (untabbed, _, bare) = Square(Parameters(2)); - bare.ApplySingleLeadIn(Parameters(2), new Vector(0, 0.75), lead, ContourType.External); - var (tabbed, _, held) = Square(Parameters(2)); - var withTabs = Parameters(2); + var (untabbed, _, bare) = Square(Parameters()); + bare.ApplySingleLeadIn(Parameters(), new Vector(0, 0.75), lead, ContourType.External); + var (tabbed, _, held) = Square(Parameters()); + var withTabs = Parameters(); withTabs.TabsEnabled = true; held.ApplySingleLeadIn(withTabs, new Vector(0, 0.75), lead, ContourType.External); var finding = Assert.Single(PostVerificationAnalyzer.Analyze(untabbed).Findings, f => f.Kind == PostVerificationKind.PartSupport); - Assert.Contains("short enough for its tab alone to hold", finding.Message); + Assert.Contains("support contact", finding.Message); Assert.Contains("no tab", finding.Message); Assert.DoesNotContain(PostVerificationAnalyzer.Analyze(tabbed).Findings, f => f.Kind == PostVerificationKind.PartSupport); diff --git a/OpenNest/Controls/CuttingPanel.cs b/OpenNest/Controls/CuttingPanel.cs index 74d0f9d1..45d2b2a8 100644 --- a/OpenNest/Controls/CuttingPanel.cs +++ b/OpenNest/Controls/CuttingPanel.cs @@ -12,10 +12,16 @@ namespace OpenNest.Controls // Every field label shares this column so inputs line up across sections. private const int FieldIndent = 16; private const int InputWidth = 100; + // The leads column's width when the panel lays out side by side. + private const int LeadsColumnWidth = 360; private static readonly Color HintColor = SystemColors.GrayText; + // The whole panel: the source line above one column, or above the leads and option + // columns side by side. private readonly TableLayoutPanel layout; + // The column sections are being added to while the panel is built. + private TableLayoutPanel column; private readonly ToolTip toolTip = new ToolTip { AutoPopDelay = 15000 }; private readonly TabControl tabControl; @@ -27,10 +33,8 @@ namespace OpenNest.Controls private readonly NumericUpDown nudTabWidth; private readonly RadioButton rbSupportTab; private readonly RadioButton rbTabBySize; - private readonly TableLayoutPanel supportTabOptions; private readonly NumericUpDown nudTabSizeMin; private readonly NumericUpDown nudTabSizeMax; - private readonly NumericUpDown nudTabHeldMax; private readonly CheckBox chkSliceSlugs; private readonly ComboBox cboLabelMode; private readonly NumericUpDown nudPierceClearance; @@ -84,7 +88,11 @@ namespace OpenNest.Controls /// False leaves out the lead-in and lead-out editors (Machine Configuration edits a /// thickness's leads on their own tabs); lead-in angle rounding stays. /// - public CuttingPanel(bool showLeads) + /// + /// True puts the leads in a column of their own beside the other settings, for a dialog; + /// false stacks everything in one column, for a narrow side panel. + /// + public CuttingPanel(bool showLeads, bool sideBySide = false) { AutoScroll = true; BackColor = Color.White; @@ -94,10 +102,23 @@ namespace OpenNest.Controls Dock = DockStyle.Top, AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, - ColumnCount = 1, + ColumnCount = sideBySide ? 2 : 1, Padding = new Padding(10, 2, 10, 10), }; - layout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100)); + var leadsColumn = layout; + var optionsColumn = layout; + if (sideBySide) + { + layout.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, LeadsColumnWidth)); + layout.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); + leadsColumn = CreateColumn(new Padding(0)); + optionsColumn = CreateColumn(new Padding(20, 0, 0, 0)); + } + else + { + layout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100)); + } + column = layout; // Where these settings are saved: the nest's machine thickness, or this PC. sourceLabel = new Label @@ -108,8 +129,15 @@ namespace OpenNest.Controls Visible = false, }; layout.Controls.Add(sourceLabel); + if (sideBySide) + { + layout.SetColumnSpan(sourceLabel, 2); + layout.Controls.Add(leadsColumn, 0, 1); + layout.Controls.Add(optionsColumn, 1, 1); + } // Leads: one tab per contour type, sized for the type with the most fields. + column = leadsColumn; if (showLeads) AddSection("Leads"); @@ -134,7 +162,7 @@ namespace OpenNest.Controls tabControl.Controls.Add(tabExternal); tabControl.Controls.Add(tabInternal); if (showLeads) - layout.Controls.Add(tabControl); + column.Controls.Add(tabControl); chkRoundLeadInAngles = new CheckBox { @@ -150,7 +178,7 @@ namespace OpenNest.Controls nudLeadInAngleIncrement.Width = 56; nudLeadInAngleIncrement.Enabled = false; toolTip.SetToolTip(chkRoundLeadInAngles, "Snaps each lead-in's angle to a multiple of this many degrees."); - layout.Controls.Add(CreateInline(chkRoundLeadInAngles, nudLeadInAngleIncrement, CreateHint("°"))); + column.Controls.Add(CreateInline(chkRoundLeadInAngles, nudLeadInAngleIncrement, CreateHint("°"))); chkRoundLeadInAngles.CheckedChanged += (s, e) => { @@ -160,6 +188,7 @@ namespace OpenNest.Controls nudLeadInAngleIncrement.ValueChanged += (s, e) => OnParametersChanged(); // Tabs + column = optionsColumn; AddSection("Tabs"); chkTabsEnabled = new CheckBox @@ -168,7 +197,9 @@ namespace OpenNest.Controls AutoSize = true, Margin = new Padding(0, 3, 0, 3), }; - layout.Controls.Add(chkTabsEnabled); + toolTip.SetToolTip(chkTabsEnabled, + "Plan Cutting tabs the parts chosen below; a tabbed part stays in the sheet on its tab."); + column.Controls.Add(chkTabsEnabled); tabOptions = ControlFactory.SettingsGrid(FieldIndent); tabOptions.Enabled = false; @@ -179,42 +210,22 @@ namespace OpenNest.Controls // Plan Cutting tabs only the parts the plate's support grid cannot hold level. rbSupportTab = new RadioButton { - Text = "Only tab parts the support grid can't hold level", + Text = "Tab parts the support grid can't hold level", AutoSize = true, Checked = true, Margin = new Padding(0, 4, 0, 0), }; toolTip.SetToolTip(rbSupportTab, - "Plan Cutting tabs each part that would tip once cut free, where it best keeps the part level."); + "Plan Cutting tabs each part that would tip once cut free, and its tab holds it wherever the tab goes. " + + "A plate with no support bed tabs by the size range instead."); AddSpanningRow(tabOptions, rbSupportTab); - // A part up to this long is held by its tab alone, wherever the tab goes. 0 turns it off. - supportTabOptions = new TableLayoutPanel - { - AutoSize = true, - AutoSizeMode = AutoSizeMode.GrowAndShrink, - ColumnCount = 1, - Margin = new Padding(FieldIndent + 2, 0, 0, 0), - }; - nudTabHeldMax = CreateNumeric(0, 0.25); - nudTabHeldMax.Width = 80; - toolTip.SetToolTip(nudTabHeldMax, - "Parts this short stay in the sheet on their tab, so a tab anywhere holds them without the grid."); - supportTabOptions.Controls.Add( - CreateInline( - CreateHint("Tab alone holds parts up to", new Padding(0, 0, 4, 0)), - nudTabHeldMax, - CreateHint("long (0 = off)", new Padding(6, 0, 0, 0)) - ) - ); - AddSpanningRow(tabOptions, supportTabOptions); - // Tabs the parts whose narrow side is in the range below, whatever the support grid. rbTabBySize = new RadioButton { Text = "Tab parts by size", AutoSize = true, - Margin = new Padding(0, 2, 0, 0), + Margin = new Padding(0, 2, 0, 2), }; toolTip.SetToolTip(rbTabBySize, "Ignores the support grid: tabs every part whose narrow side is in the range below."); @@ -223,51 +234,36 @@ namespace OpenNest.Controls // The size range: the narrow side of each part's smallest bounding box, at any angle. // Tabs by size use it, and so do support grid tabs on a plate with no support bed. A // maximum of 0 tabs nothing. - var sizeRange = new TableLayoutPanel - { - AutoSize = true, - AutoSizeMode = AutoSizeMode.GrowAndShrink, - ColumnCount = 1, - Margin = new Padding(FieldIndent + 2, 0, 0, 0), - }; - sizeRange.Controls.Add( - CreateHint("By size, or with no support bed, tab parts whose narrow side is:", new Padding(0, 4, 0, 2)) - ); nudTabSizeMin = CreateNumeric(0, 0.25); nudTabSizeMin.Width = 80; nudTabSizeMax = CreateNumeric(0, 0.25); nudTabSizeMax.Width = 80; nudTabSizeMax.Maximum = (decimal)SupportTabSettings.TabEveryPartMaxWidth; - toolTip.SetToolTip(nudTabSizeMax, - "The narrow side of the part's smallest bounding box, at any angle, so a part's rotation does not matter."); - sizeRange.Controls.Add( - CreateInline( - nudTabSizeMin, - CreateHint("to", new Padding(4, 0, 4, 0)), - nudTabSizeMax, - CreateHint("(0 = none)", new Padding(6, 0, 0, 0)) - ) + const string sizeRangeTip = + "By size, or on a plate with no support bed, parts whose narrow side is in this range are tabbed. " + + "The narrow side of the part's smallest bounding box, at any angle, so its rotation does not matter. " + + "A maximum of 0 tabs none."; + toolTip.SetToolTip(nudTabSizeMin, sizeRangeTip); + toolTip.SetToolTip(nudTabSizeMax, sizeRangeTip); + var sizeRange = CreateInline( + nudTabSizeMin, + CreateHint("to", new Padding(4, 0, 4, 0)), + nudTabSizeMax ); - AddSpanningRow(tabOptions, sizeRange); - layout.Controls.Add(tabOptions); + AddRow(tabOptions, "Narrow side from:", sizeRange, FieldIndent); + column.Controls.Add(tabOptions); chkTabsEnabled.CheckedChanged += (s, e) => { tabOptions.Enabled = chkTabsEnabled.Checked; - UpdateSupportTabOptions(); OnParametersChanged(); }; // The two choices toggle together, so one handler sees every change. - rbSupportTab.CheckedChanged += (s, e) => - { - UpdateSupportTabOptions(); - OnParametersChanged(); - }; + rbSupportTab.CheckedChanged += (s, e) => OnParametersChanged(); nudTabWidth.ValueChanged += (s, e) => OnParametersChanged(); nudTabSizeMin.ValueChanged += (s, e) => OnParametersChanged(); nudTabSizeMax.ValueChanged += (s, e) => OnParametersChanged(); - nudTabHeldMax.ValueChanged += (s, e) => OnParametersChanged(); // Cutouts: slugs that would tip are cut in pieces that drop between the supports. AddSection("Cutouts"); @@ -281,7 +277,7 @@ namespace OpenNest.Controls toolTip.SetToolTip(chkSliceSlugs, "Plan Cutting first cuts each cutout slug that would tip along the support grid's lines, " + "stopping a kerf short of the cutout, so its pieces drop between the supports."); - layout.Controls.Add(chkSliceSlugs); + column.Controls.Add(chkSliceSlugs); chkSliceSlugs.CheckedChanged += (s, e) => OnParametersChanged(); // Marks: the part number and bend groups etched in each drawing's label box. @@ -301,7 +297,7 @@ namespace OpenNest.Controls "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); + column.Controls.Add(marksGrid); cboLabelMode.SelectedIndexChanged += (s, e) => OnParametersChanged(); // Pierce @@ -317,7 +313,7 @@ namespace OpenNest.Controls AddRow(pierceGrid, "Pierce zone diameter:", nudPierceDiameter, 0, "0 = off"); toolTip.SetToolTip(nudPierceDiameter, "Diameter of the crater a pierce blows through the plate. Each pierce keeps half of it from all part material."); - layout.Controls.Add(pierceGrid); + column.Controls.Add(pierceGrid); nudPierceClearance.ValueChanged += (s, e) => OnParametersChanged(); nudPierceDiameter.ValueChanged += (s, e) => OnParametersChanged(); @@ -392,7 +388,6 @@ namespace OpenNest.Controls parameters.TabBySize = rbTabBySize.Checked; parameters.TabSizeMinWidth = (double)nudTabSizeMin.Value; parameters.TabSizeMaxWidth = (double)nudTabSizeMax.Value; - parameters.TabHeldMaxLength = (double)nudTabHeldMax.Value; parameters.SliceTippingSlugs = chkSliceSlugs.Checked; parameters.LabelMode = (PartLabelMode)System.Math.Max(0, cboLabelMode.SelectedIndex); return parameters; @@ -418,9 +413,7 @@ namespace OpenNest.Controls nudTabWidth.Value = Clamp(nudTabWidth, p.TabConfig.Size); nudTabSizeMin.Value = Clamp(nudTabSizeMin, p.TabSizeMinWidth); nudTabSizeMax.Value = Clamp(nudTabSizeMax, p.TabSizeMaxWidth); - nudTabHeldMax.Value = Clamp(nudTabHeldMax, p.TabHeldMaxLength); tabOptions.Enabled = chkTabsEnabled.Checked; - UpdateSupportTabOptions(); chkSliceSlugs.Checked = p.SliceTippingSlugs; // A mode the list does not offer (set in code; files load it as Off) shows as Off. cboLabelMode.SelectedIndex = System.Enum.IsDefined(p.LabelMode) ? (int)p.LabelMode : (int)PartLabelMode.Off; @@ -441,11 +434,6 @@ namespace OpenNest.Controls internalLeads.PreviewParameters = parameters; } - private void UpdateSupportTabOptions() - { - supportTabOptions.Enabled = chkTabsEnabled.Checked && rbSupportTab.Checked; - } - private static decimal Clamp(NumericUpDown control, double value) => double.IsFinite(value) ? System.Math.Clamp((decimal)value, control.Minimum, control.Maximum) @@ -469,12 +457,27 @@ namespace OpenNest.Controls Anchor = AnchorStyles.Left | AnchorStyles.Right, TextAlign = ContentAlignment.BottomLeft, Font = new Font(Font, FontStyle.Bold), - Margin = new Padding(0, layout.Controls.Count == 0 ? 4 : 12, 0, 4), + Margin = new Padding(0, column.Controls.Count == (column == layout ? 1 : 0) ? 4 : 12, 0, 4), Padding = new Padding(0, 0, 0, 3), }; header.Paint += (s, e) => e.Graphics.DrawLine(SystemPens.ControlLight, 0, header.Height - 1, header.Width, header.Height - 1); - layout.Controls.Add(header); + column.Controls.Add(header); + } + + // One column of sections, in a cell of the side-by-side layout. + private static TableLayoutPanel CreateColumn(Padding margin) + { + var result = new TableLayoutPanel + { + AutoSize = true, + AutoSizeMode = AutoSizeMode.GrowAndShrink, + ColumnCount = 1, + Dock = DockStyle.Fill, + Margin = margin, + }; + result.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100)); + return result; } private static void AddRow( diff --git a/OpenNest/Forms/CuttingParametersDialog.cs b/OpenNest/Forms/CuttingParametersDialog.cs index c4cdfe84..6d9fd234 100644 --- a/OpenNest/Forms/CuttingParametersDialog.cs +++ b/OpenNest/Forms/CuttingParametersDialog.cs @@ -18,7 +18,8 @@ namespace OpenNest.Forms ShowInTaskbar = false; StartPosition = FormStartPosition.CenterParent; - cuttingPanel = new CuttingPanel { Dock = DockStyle.Fill }; + // The leads beside the other settings, so the dialog stays short. + cuttingPanel = new CuttingPanel(showLeads: true, sideBySide: true) { Dock = DockStyle.Fill }; var btnOk = new Button { diff --git a/docs/cutting-planner.md b/docs/cutting-planner.md index 3fb6c05a..9f673749 100644 --- a/docs/cutting-planner.md +++ b/docs/cutting-planner.md @@ -40,9 +40,8 @@ var result = CuttingPlanService.Plan(snapshot, cancellationToken); tabbed perimeter whose automatic entries are ranked by the route, clear of inside corners, not by how well the tab steadies it. A tabbed part counts as steady wherever its tab is: it is never warned about and stays crossable once - cut, though the plan [goes around it where it can](#tabbed-parts-are-avoided-first). A tab in an inside corner is noted on the plan without changing its status. A part no - longer than `TabHeldMaxLength` is held by its tab - alone, so any tab clear of inside corners steadies it. Without a bed, or with + cut, though the plan [goes around it where it can](#tabbed-parts-are-avoided-first). A tab in an inside corner is noted on the plan without changing its status. Every such + part is held by its tab, so any tab clear of inside corners steadies it. Without a bed, or with `CuttingParameters.TabBySize`, the parts whose width is in `TabSizeMinWidth`..`TabSizeMaxWidth` are tabbed instead, and with no range set the plan notes that nothing was tabbed; see [support tabs](support-tabs.md). diff --git a/docs/support-tabs.md b/docs/support-tabs.md index ff20babb..093d2083 100644 --- a/docs/support-tabs.md +++ b/docs/support-tabs.md @@ -128,24 +128,23 @@ once cut, while a detour to the steadiest point lengthens the way for every part steadiest instead, a long strip resting on one line of contacts started mid-length, or on its side away from the next cut, so the head left it back over the strip. Lead checks are unchanged. -## Parts the tab alone holds +## Tabbed parts are held by their tab -A tabbed part stays in the sheet on its tab, and a part short enough does not need the bed at -all: the tab holds it wherever it goes. Cutting Parameters > Tabs > "Tab alone holds parts up to" -sets `CuttingParameters.TabHeldMaxLength`: on a plate with a support bed, a part the bed cannot -hold level whose length (the long side of its outline's minimum-area bounding rectangle, -`SupportAnalyzer.Length`) is at most that, bound included, is still tabbed, but +A tabbed part stays in the sheet on its tab, however long it is. On a plate with a support bed, +`SupportTabSettings.Analyze` tabs every part the bed cannot hold level and `SupportAnalyzer.HeldByTab` marks its analysis `IsHeldByTab`: it keeps its contacts and margin, every tab clear of inside corners steadies it, and its best tab point is chosen as for a part -tabbed by size (below). A part the bed holds is not tabbed. 0 turns the rule off; new settings -start at 6, while settings saved without the field read as 0, so saved settings keep their -meaning. Some outlines have two minimum-area rectangles (a right isosceles triangle fits both -its legs' square and its hypotenuse's 2:1 box), and which one rounding finds depends on how the -part is turned; of rectangles tied for area, `SupportAnalyzer` measures the one with the shorter -long side, so a drawing's length and width are the same at every rotation. -`SupportTabSettings.Analyze` applies it for Plan Cutting, hand-placed lead-ins and the pre-post -review alike, so such a part warns only when it is cut with no tab at all. View > Draw Support -does not read cutting settings and still shows it red, since it would tip without its tab. +tabbed by size (below). A part the bed holds is not tabbed. The former length limit ("Tab alone +holds parts up to", `TabHeldMaxLength`) is gone; settings and nests saved with it read +unchanged and ignore it. `SupportTabSettings.Analyze` applies this for Plan Cutting, +hand-placed lead-ins and the pre-post review alike, so such a part warns only when it is cut +with no tab at all. View > Draw Support does not read cutting settings and still shows it red, +since it would tip without its tab. + +Some outlines have two minimum-area rectangles (a right isosceles triangle fits both its legs' +square and its hypotenuse's 2:1 box), and which one rounding finds depends on how the part is +turned; of rectangles tied for area, `SupportAnalyzer` measures the one with the shorter long +side, so a drawing's width is the same at every rotation. ## Tabbing by size @@ -178,9 +177,9 @@ settings and the cutting panel): a plate's recorded parameters and drawing pins `TabsEnabled` and replay as planned. If none of those entries has a lead-in that fits, the part is still tabbed. The search falls -back to every entry (`SupportEntries.Any`), ordered by how well the tab steadies the part; of -the entries whose lead-in fits, it keeps every one that holds the part level, or else only the -steadiest. The open-scrap pierce fallback then tries that catalog. +back to every entry (`SupportEntries.Any`), inside corners included; since every tab holds a +tabbed part, the route decides among those whose lead-in fits. The open-scrap pierce fallback +then tries that catalog. A tabbed part counts as steady wherever its tab is: where its tab lands is never a warning. No message says a tab cannot steady its part, and once cut a tabbed part stays crossable, as its retained material allows, whether or not its tab holds it level. Plan Cutting