Files
OpenNest/OpenNest.Desktop/Interaction/CutSimulationStatus.cs
T
ajandClaude Opus 5.5 6cb56a6afd feat(desktop): share the cut-time report and cut simulation playhead
CutTimeReport computes and words what Calculate Cut Time shows for a plate
or nest (time from the simulation with acceleration plus clamp removal,
distances and counts from the timing info) as the WinForms timing window.
CutTimeEntry and CutTimeMachineChoice hold the dialog's box ranges, the
entered values' cut parameters and the Acceleration list's entries.
CutSimulationPlayback is the simulator's playhead without drawing: play,
pause and speed, scrubbing, part, cutout and move stepping, retiming that
keeps the torch in place and which parts it has not reached;
CutSimulationStatus words its status rows.

The WinForms timing window, cut parameters dialog, machine box, simulator
and overlay now call them; their behavior is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 18:45:44 -05:00

57 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using OpenNest.CNC;
using OpenNest.Forms;
namespace OpenNest.Desktop.Interaction;
/// <summary>
/// The Cut Simulator's status rows, worded as the WinForms simulator: the time as "elapsed /
/// total", the part as "n of m", its drawing, and the motion with the speed at the playhead.
/// </summary>
public sealed record CutSimulationStatus(string Time, string Part, string Drawing, string Motion)
{
public const string NothingToCut = "Nothing to cut";
/// <summary>The rows for <paramref name="playback"/> on <paramref name="plate"/> in <paramref name="units"/>.</summary>
public static CutSimulationStatus For(CutSimulationPlayback playback, Plate plate, Units units)
{
ArgumentNullException.ThrowIfNull(playback);
var sim = playback.Simulation;
if (sim == null || sim.Steps.Count == 0)
return new CutSimulationStatus(NothingToCut, string.Empty, string.Empty, string.Empty);
var time = playback.Time;
var timeText = $"{CutTimeReport.FormatTime(time)} / {CutTimeReport.FormatTime(sim.TotalTime)}";
var index = sim.IndexAt(time);
if (index >= sim.Steps.Count)
return new CutSimulationStatus(timeText, $"{sim.PartCount} of {sim.PartCount}", string.Empty, "Done");
var step = sim.Steps[index];
var drawing = plate != null && step.PartIndex < plate.Parts.Count ? plate.Parts[step.PartIndex].BaseDrawing?.Name : null;
var state = step.Kind switch
{
CutSimulationStepKind.Rapid => "Rapid",
CutSimulationStepKind.Pierce => "Piercing",
CutSimulationStepKind.Scribe => "Scribing",
_ => "Cutting",
};
if (step.Kind != CutSimulationStepKind.Pierce)
state += $" · {FeedText(step.SpeedAt(time - step.StartTime), units)}";
return new CutSimulationStatus(timeText, $"{step.PartIndex + 1} of {sim.PartCount}", drawing ?? string.Empty, state);
}
/// <summary>
/// A speed in units per second as the feed reads: inch feeds per minute, millimeter feeds per
/// second, as <see cref="Timing"/> uses them.
/// </summary>
public static string FeedText(double unitsPerSecond, Units units)
{
var rate = units == Units.Millimeters ? unitsPerSecond : unitsPerSecond * 60;
return $"{rate:n0} {UnitsHelper.GetShortTimeUnitPair(units)}";
}
/// <summary>The speed list's text for <paramref name="speed"/>, as "5×".</summary>
public static string SpeedText(double speed) => $"{speed:g}×";
}