Files
OpenNest/OpenNest.Tests/TimingTests.cs
T
aj 87849e5326 feat(desktop): show clamps to pull and their time
Slice 3b task 3 (D9 + display). OpenNest.Core: TimingInfo gains
ClampRemovalMinutes (included in +, -, * so every aggregation stays
consistent); Timing.GetTimingInfo(Plate) adds plate.ClampRemovalMinutes
once per physical sheet, before the quantity multiply so it scales
with everything else cut on that sheet; CalculateTime adds it to the
estimate as a flat number of minutes regardless of the cut parameters'
unit. A plate with nothing removed is unaffected (zero).

OpenNest.Data: ClampSettings and ClampRailEditor carry RemovalMinutes
through the same three boundaries as clamp size - the rail/constructor,
the settings file (missing key falls back to
ClampRail.DefaultRemovalMinutes; present but negative/non-numeric/null
is ignored and reported Partial, same as width/depth), and
ToMachineDefaults - except it is a time, not a length, so
ConvertedTo never scales it between inches and millimeters.

Desktop: ClampsForm gets a 'Minutes to remove and replace one clamp'
field wired to the editor; PlateRenderer.DrawRemovedClamps draws each
clamp Plate.RemovedClamps lists (resolved from the full rail, since a
removed clamp is absent from Plate.ClampZones) as a dashed grey
outline with a small 'remove' marker, distinct from an active clamp's
solid hatch and still display-only - no hit test, selection or
sequencing; PlateView calls it right after the active-zone pass.
MainForm's Auto Nest completion flow lists every committed sheet with
a removal as 'Sheet N: remove clamp-X (+5 min)', using
Plate.RemovedClamps/ClampRemovalMinutes from Slice 3b tasks 1-2.

Tests: 10 new Data (ClampSettingsTests, ClampRailEditorTests) covering
round-trip/default/invalid-value handling and the never-scaled-by-units
rule; 4 new Core (TimingTests) covering the per-sheet add, the quantity
scaling, CalculateTime, and nest-level aggregation across plates.
Desktop changes (dialog field, renderer, Auto Nest summary) are
compile-verified only (-p:EnableWindowsTargeting=true), matching the
project's existing WinForms testing bar - no automated UI test exists
for the sibling DrawClampZones either.

Gates: Release OpenNest.Tests 3898 passed/31 skipped, OpenNest.IO.Tests
105 passed, OpenNest.Engine.Tests 878 passed/2 skipped; desktop and
OpenNest.WinForms.Tests cross-builds clean; scoped dotnet format
--verify-no-changes clean.

This completes Slice 3b (D8/D9) on top of Slice 3's rail-following
plates. Not published; master and other feature/clamp-zones-* branches
untouched. Windows runtime/visual acceptance not claimed - the plan's
click-through checklist (after slices 3-5) still applies.
2026-10-13 18:15:49 -04:00

63 lines
1.8 KiB
C#

using OpenNest.Api;
using OpenNest.Geometry;
namespace OpenNest.Tests;
/// <summary>
/// D9: a sheet's cut-time estimate gains the rail's removal minutes once per removed clamp,
/// scaled by the plate's cut quantity like every other timing field; a plate with nothing
/// removed is unaffected.
/// </summary>
public class TimingTests
{
private static Plate PlateWithOneRemovedClamp(double removalMinutes, int quantity = 1)
{
var plate = new Plate(3, 23) { Quantity = quantity, EdgeSpacing = new Spacing(0, 0, 0, 0) };
var rail = new ClampRail(1.5, 0.625, new[] { 6.0, 21.0 }, removalMinutes);
plate.SetClampRail(rail, new[] { "clamp-1" });
return plate;
}
[Fact]
public void PlateWithNoRemovedClampsAddsNoTime()
{
var plate = new Plate(48, 96) { Quantity = 3 };
var info = Timing.GetTimingInfo(plate);
Assert.Equal(0, info.ClampRemovalMinutes);
}
[Fact]
public void RemovedClampMinutesAreAddedOncePerPhysicalSheet()
{
var plate = PlateWithOneRemovedClamp(removalMinutes: 5, quantity: 3);
var info = Timing.GetTimingInfo(plate);
Assert.Equal(15, info.ClampRemovalMinutes); // 5 minutes x 3 physical sheets
}
[Fact]
public void CalculateTimeAddsTheRemovalMinutesToTheEstimate()
{
var info = new TimingInfo { ClampRemovalMinutes = 7 };
var time = Timing.CalculateTime(info, CutParameters.Default);
Assert.Equal(TimeSpan.FromMinutes(7), time);
}
[Fact]
public void NestTotalsSumRemovalMinutesAcrossPlates()
{
var nest = new Nest();
nest.Plates.Add(PlateWithOneRemovedClamp(removalMinutes: 5));
nest.Plates.Add(new Plate(48, 96)); // ordinary plate, no clamps
var info = Timing.GetTimingInfo(nest);
Assert.Equal(5, info.ClampRemovalMinutes);
}
}