Files
OpenNest/OpenNest.WinForms.Tests/Controls/CuttingPanelTests.cs
T
ajandClaude Sonnet 5.5 2a59ffb951 feat(labels): etch the part number and bend groups in the label box
Plan Cutting adds each part's label to the clean program it plans from
when CuttingParameters.EtchPartLabels is on (off by default, kept per
machine thickness like the other cutting options), so it is emitted as
scribe marks: shown, counted in cut time, posted through the etch path
and never part of nesting geometry.

The text is the drawing name plus its bend groups ("1234-AB"). A group
is the bend line's direction against the sheet grain in 15 degree steps
(BendGrain.Bucket), named by a fixed letter: A across the grain, B with
it, then C to L. A built-in single-stroke font (StrokeFont) draws it,
centered in the box and shrunk to fit down to half the box height.

Locked or unplanned parts, drawings without a box and common-line
members get no label. A plan-time warning for a label that cannot fit,
a letter beside each bend's etch dashes and a per-group list in the
reports are left for later.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-22 17:51:01 -05:00

106 lines
3.7 KiB
C#

using OpenNest.CNC.CuttingStrategy;
using OpenNest.Controls;
namespace OpenNest.WinForms.Tests.Controls;
public class CuttingPanelTests
{
[Fact]
public void BuildParameters_KeepsTheSettingsThePanelHasNoFieldFor()
{
StaTestThread.Run(() =>
{
using var panel = new CuttingPanel();
panel.LoadFromParameters(new CuttingParameters
{
MachineName = "CL-980",
MaterialName = "Stainless Steel",
Grade = "304",
Thickness = 0.075,
Kerf = 0.008,
ExternalLeadIn = new ArcLeadIn { Radius = 0.0625 },
ExternalLeadOut = new NoLeadOut(),
SupportTabs = true,
TabConfig = new NormalTab { Size = 0.25 },
});
var built = panel.BuildParameters();
// Without the stamp, the machine's leads would replace these edits on the next open.
Assert.Equal("CL-980", built.MachineName);
Assert.Equal("Stainless Steel", built.MaterialName);
Assert.Equal("304", built.Grade);
Assert.Equal(0.075, built.Thickness);
Assert.Equal(0.008, built.Kerf);
Assert.IsType<NoLeadOut>(built.ExternalLeadOut);
Assert.True(built.SupportTabs);
}, TimeSpan.FromSeconds(30), "The cutting panel did not build its parameters.");
}
[Fact]
public void TabBySize_RoundTripsWithItsRange()
{
StaTestThread.Run(() =>
{
using var panel = new CuttingPanel();
panel.LoadFromParameters(new CuttingParameters
{
SupportTabs = true,
TabBySize = true,
TabSizeMinWidth = 0.5,
TabSizeMaxWidth = 3,
TabConfig = new NormalTab { Size = 0.03 },
});
var built = panel.BuildParameters();
Assert.True(built.SupportTabs);
Assert.True(built.TabBySize);
Assert.False(built.TabsEnabled);
Assert.Equal(0.5, built.TabSizeMinWidth);
Assert.Equal(3, built.TabSizeMaxWidth);
}, TimeSpan.FromSeconds(30), "The cutting panel did not build tabs by size.");
}
[Fact]
public void EtchPartLabels_IsOffByDefault_AndRoundTrips()
{
StaTestThread.Run(() =>
{
using var panel = new CuttingPanel();
panel.LoadFromParameters(new CuttingParameters());
Assert.False(panel.BuildParameters().EtchPartLabels);
panel.LoadFromParameters(new CuttingParameters { EtchPartLabels = true });
Assert.True(panel.BuildParameters().EtchPartLabels);
}, TimeSpan.FromSeconds(30), "The cutting panel did not round-trip the part label option.");
}
[Fact]
public void TabEveryPart_LoadsAsTabsBySizeOverEveryWidth()
{
StaTestThread.Run(() =>
{
using var panel = new CuttingPanel();
var saved = new CuttingParameters
{
TabsEnabled = true,
TabConfig = new NormalTab { Size = 0.03 },
TabSizeMaxWidth = 2,
};
panel.LoadFromParameters(saved);
var built = panel.BuildParameters();
Assert.False(built.TabsEnabled);
Assert.True(built.SupportTabs);
Assert.True(built.TabBySize);
Assert.Equal(0, built.TabSizeMinWidth);
Assert.Equal(OpenNest.Support.SupportTabSettings.TabEveryPartMaxWidth, built.TabSizeMaxWidth);
// The caller's settings are not changed.
Assert.True(saved.TabsEnabled);
Assert.False(saved.SupportTabs);
}, TimeSpan.FromSeconds(30), "The cutting panel did not migrate Tab every part.");
}
}