Files
OpenNest/OpenNest.Core/Timing.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

105 lines
3.4 KiB
C#

using System;
using System.Linq;
using OpenNest.Api;
using OpenNest.CNC;
using OpenNest.Converters;
using OpenNest.Geometry;
namespace OpenNest
{
public static class Timing
{
public static TimingInfo GetTimingInfo(Program pgm)
{
var entities = ConvertProgram.ToGeometry(pgm);
var shapes = ShapeBuilder.GetShapes(
entities.Where(entity => entity.Layer != SpecialLayers.Rapid)
);
var info = new TimingInfo { PierceCount = shapes.Count };
var last = entities[0];
ProcessEntity(info, last, null);
for (int i = 1; i < entities.Count; i++)
{
var entity = entities[i];
ProcessEntity(info, entity, last);
last = entity;
}
return info;
}
public static TimingInfo GetTimingInfo(Plate plate)
{
var info = new TimingInfo();
var pos = new Vector(0, 0);
foreach (var part in plate.Parts)
{
var endpt = part.Program.EndPoint() + part.Location;
info += GetTimingInfo(part.Program);
info.TravelDistance += pos.DistanceTo(endpt);
pos = endpt;
}
// D9: once per physical sheet, before the quantity multiply below scales it with
// everything else cut on that sheet.
info.ClampRemovalMinutes = plate.ClampRemovalMinutes;
info *= plate.Quantity;
return info;
}
public static TimingInfo GetTimingInfo(Nest nest)
{
var info = new TimingInfo();
return nest.Plates.Aggregate(info, (current, plate) => current + GetTimingInfo(plate));
}
private static void ProcessEntity(TimingInfo info, Entity entity, Entity lastEntity)
{
if (entity.Layer == SpecialLayers.Cut)
{
info.CutDistance += entity.Length;
if (
entity.Type == EntityType.Line
&& lastEntity != null
&& lastEntity.Type == EntityType.Line
&& lastEntity.Layer == SpecialLayers.Cut
)
info.IntersectionCount++;
}
else if (entity.Layer == SpecialLayers.Rapid)
info.TravelDistance += entity.Length;
}
public static TimeSpan CalculateTime(TimingInfo info, CutParameters cutParams)
{
var time = new TimeSpan();
switch (cutParams.Units)
{
case Units.Inches:
time += TimeSpan.FromMinutes(info.CutDistance / cutParams.Feedrate);
time += TimeSpan.FromMinutes(info.TravelDistance / cutParams.RapidTravelRate);
break;
case Units.Millimeters:
time += TimeSpan.FromSeconds(info.CutDistance / cutParams.Feedrate);
time += TimeSpan.FromSeconds(info.TravelDistance / cutParams.RapidTravelRate);
break;
}
time += TimeSpan.FromTicks(info.PierceCount * cutParams.PierceTime.Ticks);
// D9: a flat per-removed-clamp time, already in minutes regardless of cutParams.Units.
time += TimeSpan.FromMinutes(info.ClampRemovalMinutes);
return time;
}
}
}