mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-04 17:29:24 -05:00
The cut timeline called a contour exterior only when it closed and ran clockwise, while the posts (ContourWinding.PerimeterIndex, L4/L2 on the CI Fiber) take each part's contour enclosing the largest bounding box, closed or not. A perimeter left open at a tab was therefore timed at the hole feed, and the heat map dropped the whole part as a cutout slug with its heat: on N26-2ED every washer showed no heat at all. The timeline now uses the posts' rule, so tabbed or counterclockwise perimeters take the outside feed and stay in the heat map as cut-free parts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
188 lines
7.4 KiB
C#
188 lines
7.4 KiB
C#
using System.Globalization;
|
|
using OpenNest.Data;
|
|
using OpenNest.Forms;
|
|
|
|
namespace OpenNest.Desktop.Tests.Forms;
|
|
|
|
public sealed class CutTimeReportTests : IDisposable
|
|
{
|
|
private readonly CultureInfo previous = CultureInfo.CurrentCulture;
|
|
|
|
public CutTimeReportTests() => CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
|
|
|
|
public void Dispose() => CultureInfo.CurrentCulture = previous;
|
|
|
|
private static CutParameters Entered(Units units = Units.Inches, MachineConfig? machine = null) =>
|
|
CutTimeEntry.Parameters(120, 60, 600, 1, true, units, machine);
|
|
|
|
// Two squares on the plate, two of the sheet cut.
|
|
private static Nest TwoSquares()
|
|
{
|
|
var nest = TestNests.TwoSquares();
|
|
nest.Plates[0].Quantity = 2;
|
|
return nest;
|
|
}
|
|
|
|
// The WinForms TimingForm computed these itself before the report was shared; the report
|
|
// must give the same numbers for the same inputs.
|
|
[Fact]
|
|
public void ForPlate_IsTheTimingTheWinFormsDialogShowed()
|
|
{
|
|
var nest = TwoSquares();
|
|
var plate = nest.Plates[0];
|
|
var parameters = Entered(machine: new MachineConfig { Units = UnitSystem.Inches });
|
|
|
|
var report = CutTimeReport.ForPlate(plate, parameters, nest.Units);
|
|
|
|
var info = Timing.GetTimingInfo(plate);
|
|
Assert.Equal(Timing.CalculateTime(plate, parameters), report.CutTime);
|
|
Assert.Equal(info.CutDistance, report.Info.CutDistance);
|
|
Assert.Equal(info.TravelDistance, report.Info.TravelDistance);
|
|
Assert.Equal(info.PierceCount, report.Info.PierceCount);
|
|
Assert.Equal(info.IntersectionCount, report.Info.IntersectionCount);
|
|
}
|
|
|
|
[Fact]
|
|
public void ForNest_AddsEveryPlate()
|
|
{
|
|
var nest = TwoSquares();
|
|
nest.Plates.Add(TestNests.TwoSquares().Plates[0]);
|
|
var parameters = Entered();
|
|
|
|
var report = CutTimeReport.ForNest(nest, parameters);
|
|
|
|
Assert.Equal(Timing.CalculateTime(nest, parameters), report.CutTime);
|
|
Assert.Equal(Timing.GetTimingInfo(nest).CutDistance, report.Info.CutDistance);
|
|
Assert.Equal(
|
|
Timing.CalculateTime(nest.Plates[0], parameters) + Timing.CalculateTime(nest.Plates[1], parameters),
|
|
report.CutTime);
|
|
}
|
|
|
|
// Full speed: each square is its part's perimeter, so its 40 in run at the 120 in/min outside
|
|
// feed, 20 s, plus a 1 s pierce; two squares, two sheets, and the rapid between them at 600
|
|
// in/min.
|
|
[Fact]
|
|
public void ForPlate_FullSpeed_TheHandWorkedTime()
|
|
{
|
|
var nest = TwoSquares();
|
|
var report = CutTimeReport.ForPlate(nest.Plates[0], Entered(), Units.Inches);
|
|
|
|
var rapid = TimeSpan.FromMinutes(20.0 / 600);
|
|
var sheet = 2 * (TimeSpan.FromSeconds(20) + TimeSpan.FromSeconds(1)) + rapid;
|
|
Assert.Equal(sheet.TotalSeconds * 2, report.CutTime.TotalSeconds, 6);
|
|
Assert.Equal("01m 28s", report.CutTimeText);
|
|
}
|
|
|
|
[Fact]
|
|
public void Texts_AreWordedAsTheWinFormsTimingWindow()
|
|
{
|
|
var nest = TwoSquares();
|
|
var report = CutTimeReport.ForPlate(nest.Plates[0], Entered(), Units.Inches);
|
|
|
|
// Quantity 2: two squares of 40 in, twice.
|
|
Assert.Equal("160 in", report.CutDistanceText);
|
|
Assert.Equal(report.Info.PierceCount.ToString(), report.PierceCountText);
|
|
Assert.Equal(report.Info.IntersectionCount.ToString(), report.IntersectionCountText);
|
|
Assert.Equal("120 in/min", report.FeedrateText);
|
|
Assert.Equal("600 in/min", report.RapidText);
|
|
Assert.Equal("01s", report.PierceTimeText);
|
|
}
|
|
|
|
[Fact]
|
|
public void Millimeters_ReadPerSecond()
|
|
{
|
|
Assert.Equal("250 mm/sec", CutTimeReport.RateText(250, Units.Millimeters));
|
|
Assert.Equal("12.3457 mm", CutTimeReport.DistanceText(12.345678, Units.Millimeters));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(3723, "1h 02m 03s")]
|
|
[InlineData(90000, "25h 00m 00s")]
|
|
[InlineData(125, "02m 05s")]
|
|
[InlineData(45, "45s")]
|
|
[InlineData(5, "05s")]
|
|
[InlineData(0, "00s")]
|
|
public void FormatTime_AsTheWinFormsTimingWindow(int seconds, string expected) =>
|
|
Assert.Equal(expected, CutTimeReport.FormatTime(TimeSpan.FromSeconds(seconds)));
|
|
|
|
[Fact]
|
|
public void FormatTime_UnderAMinute_RoundsTheSeconds() =>
|
|
Assert.Equal("13s", CutTimeReport.FormatTime(TimeSpan.FromSeconds(12.6)));
|
|
|
|
[Fact]
|
|
public void Entry_TheWinFormsBoxValues()
|
|
{
|
|
var machine = new MachineConfig { Units = UnitSystem.Millimeters };
|
|
|
|
var parameters = CutTimeEntry.Parameters(250, 120.5m, 1000, 0.75m, false, Units.Inches, machine);
|
|
|
|
Assert.Equal(250, parameters.Feedrate);
|
|
Assert.Equal(120.5, parameters.HoleFeedrate);
|
|
Assert.Equal(1000, parameters.RapidTravelRate);
|
|
Assert.Equal(TimeSpan.FromSeconds(0.75), parameters.PierceTime);
|
|
Assert.False(parameters.SkipScribe);
|
|
Assert.Equal(Units.Inches, parameters.Units);
|
|
var expected = machine.GetMotionOrPlaceholder().ToProfile(UnitSystem.Millimeters, Units.Inches);
|
|
Assert.Equal(expected.CutAcceleration, parameters.Motion.CutAcceleration);
|
|
}
|
|
|
|
[Fact]
|
|
public void Entry_FullSpeed_HasNoMotion() =>
|
|
Assert.Null(CutTimeEntry.Parameters(1, 1, 1, 0, true, Units.Inches, null).Motion);
|
|
|
|
[Fact]
|
|
public void Entry_Clamp_TakesTheBoxRange()
|
|
{
|
|
Assert.Equal(CutTimeEntry.MaximumRate, CutTimeEntry.Clamp(20000, CutTimeEntry.MinimumRate, CutTimeEntry.MaximumRate));
|
|
Assert.Equal(CutTimeEntry.MinimumRate, CutTimeEntry.Clamp(0, CutTimeEntry.MinimumRate, CutTimeEntry.MaximumRate));
|
|
Assert.Equal(0.5m, CutTimeEntry.Clamp(0.5, 0, CutTimeEntry.DialogMaximumPierce));
|
|
}
|
|
|
|
// The saved settings round trip through the boxes unchanged.
|
|
[Fact]
|
|
public void Entry_FromSavedSettings_GivesTheSavedParameters()
|
|
{
|
|
var saved = new SavedCutTimeSettings(250, 120.5m, 1000, 0.75m, false, SavedCutTimeSettings.FullSpeed);
|
|
var loaded = saved.ToCutParameters(Units.Inches, null);
|
|
|
|
var entered = CutTimeEntry.Parameters(
|
|
(decimal)loaded.Feedrate, (decimal)loaded.HoleFeedrate!.Value, (decimal)loaded.RapidTravelRate,
|
|
(decimal)loaded.PierceTime.TotalSeconds, loaded.SkipScribe, Units.Inches, null);
|
|
|
|
Assert.Equal(saved, saved.With(entered));
|
|
}
|
|
|
|
[Fact]
|
|
public void MachineChoices_FullSpeedFirst_ThenByName_MarkingPlaceholders()
|
|
{
|
|
var machines = new List<MachineConfig>
|
|
{
|
|
new() { Name = "Zeta", Motion = new MotionConfig() },
|
|
new() { Name = "alpha" },
|
|
};
|
|
|
|
var choices = CutTimeMachineChoice.For(machines);
|
|
|
|
Assert.Equal(["None (full speed)", "alpha (placeholder)", "Zeta"], choices.Select(c => c.ToString()));
|
|
Assert.Null(choices[0].GetMotion(Units.Inches));
|
|
Assert.NotNull(choices[1].GetMotion(Units.Inches));
|
|
}
|
|
|
|
[Fact]
|
|
public void MachineChoices_SavedIndex()
|
|
{
|
|
var id = Guid.NewGuid();
|
|
var choices = CutTimeMachineChoice.For(
|
|
[
|
|
new MachineConfig { Name = "b" },
|
|
new MachineConfig { Id = id, Name = "c" },
|
|
new MachineConfig { Name = "a" },
|
|
]);
|
|
|
|
Assert.Equal(3, CutTimeMachineChoice.SavedIndex(choices, id.ToString()));
|
|
Assert.Equal(1, CutTimeMachineChoice.SavedIndex(choices, ""));
|
|
Assert.Equal(0, CutTimeMachineChoice.SavedIndex(choices, SavedCutTimeSettings.FullSpeed));
|
|
Assert.Equal(0, CutTimeMachineChoice.SavedIndex(CutTimeMachineChoice.For([]), ""));
|
|
}
|
|
}
|