mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-24 03:07:34 -05:00
Imported drawings are incremental programs, but PartLabels.AddTo appended absolute points, so each stroke was read as a step from the last and the label ran far off the sheet. It now writes steps from where the program stops (ConvertMode.EndPosition). On load, DrawingMarkRecovery took the etched label from applied part programs back into the drawing as a lost mark, so it was etched again by every later plan, labels off included. Drawings with a label box are now skipped. Also load a labelMode number that names no mode as if it were absent, and show such a mode as Off in the Cutting Parameters dropdown instead of throwing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
120 lines
4.3 KiB
C#
120 lines
4.3 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 LabelMode_IsOffByDefault_AndRoundTrips()
|
|
{
|
|
StaTestThread.Run(() =>
|
|
{
|
|
using var panel = new CuttingPanel();
|
|
panel.LoadFromParameters(new CuttingParameters());
|
|
Assert.Equal(PartLabelMode.Off, panel.BuildParameters().LabelMode);
|
|
|
|
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.");
|
|
}
|
|
|
|
[Fact]
|
|
public void LabelMode_ThatNamesNoChoice_ShowsAsOff()
|
|
{
|
|
StaTestThread.Run(() =>
|
|
{
|
|
using var panel = new CuttingPanel();
|
|
panel.LoadFromParameters(new CuttingParameters { LabelMode = (PartLabelMode)7 });
|
|
Assert.Equal(PartLabelMode.Off, panel.BuildParameters().LabelMode);
|
|
}, TimeSpan.FromSeconds(30), "The cutting panel did not load an unknown part label mode as Off.");
|
|
}
|
|
|
|
[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.");
|
|
}
|
|
}
|