using System; using OpenNest.CNC; using OpenNest.Forms; namespace OpenNest.Desktop.Interaction; /// /// 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. /// public sealed record CutSimulationStatus(string Time, string Part, string Drawing, string Motion) { public const string NothingToCut = "Nothing to cut"; /// The rows for on in . 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); } /// /// A speed in units per second as the feed reads: inch feeds per minute, millimeter feeds per /// second, as uses them. /// public static string FeedText(double unitsPerSecond, Units units) { var rate = units == Units.Millimeters ? unitsPerSecond : unitsPerSecond * 60; return $"{rate:n0} {UnitsHelper.GetShortTimeUnitPair(units)}"; } /// The speed list's text for , as "5×". public static string SpeedText(double speed) => $"{speed:g}×"; }