From d4dfde512644d76f6702905377faf06699c57b75 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Tue, 1 Dec 2026 12:31:48 -0500 Subject: [PATCH] feat(simulator): move inputs to a Settings tab and time with the nest's machine The Cut Simulator had grown a row per input and was crowding the window. The slider now leads, with the time under it, then the transport and four equal jump buttons spanning exactly the slider's track. Part, drawing, motion and the heat view sit on a Status tab; the feeds, pierce, heat input and etch choice move to a Settings tab, so the window is shorter and the time stays visible while settings change. The Acceleration picker is gone: the simulator always times with the nest's machine (Nest > Machine), shown by name on the Settings tab, and falls back to full speed when the nest has none. Calculate Cut Time's remembered machine is left alone. The Avalonia simulator follows suit. Co-Authored-By: Claude Opus 5.5 --- OpenNest.Avalonia/CutSimulatorWindow.cs | 26 ++- OpenNest.Avalonia/CutTimeDialog.cs | 8 + OpenNest.Avalonia/MainWindow.CutTime.cs | 5 +- .../Forms/CutSimulatorFormTests.cs | 139 +++++++++++++++ OpenNest/Forms/CutSimulatorForm.cs | 168 ++++++++++++++---- docs/cut-time-estimates.md | 9 +- 6 files changed, 298 insertions(+), 57 deletions(-) create mode 100644 OpenNest.WinForms.Tests/Forms/CutSimulatorFormTests.cs diff --git a/OpenNest.Avalonia/CutSimulatorWindow.cs b/OpenNest.Avalonia/CutSimulatorWindow.cs index 04123edd..b060b2e7 100644 --- a/OpenNest.Avalonia/CutSimulatorWindow.cs +++ b/OpenNest.Avalonia/CutSimulatorWindow.cs @@ -36,16 +36,18 @@ namespace OpenNest.Avalonia private readonly Slider track; private readonly TextBlock timeText, partText, drawingText, motionText; private readonly NumberField feed, holeFeed, rapid, pierce; - private readonly ComboBox machineBox; + private readonly MachineConfig machine; private readonly CheckBox skipEtch; private readonly Units units; private Plate plate; private bool updatingTrack; private bool rebuildQueued; - public CutSimulatorWindow(NestView view, IReadOnlyList machines) + /// The nest's machine, whose acceleration times the moves, or null for full speed. + public CutSimulatorWindow(NestView view, MachineConfig machine) { this.view = view; + this.machine = machine; units = view.Tab.Document.Nest.Units; Title = "Cut Simulator"; SizeToContent = SizeToContent.WidthAndHeight; @@ -95,7 +97,7 @@ namespace OpenNest.Avalonia status.HorizontalAlignment = HorizontalAlignment.Left; var saved = CutTimeSettingsFile.Read(); - var loaded = saved.ToCutParameters(units, SavedCutTimeSettings.ChooseMachine(machines, saved.Machine)); + var loaded = saved.ToCutParameters(units, machine); var rate = UnitsHelper.GetShortTimeUnitPair(units); feed = new NumberField("Feed", loaded.Feedrate, CutTimeEntry.MinimumRate, CutTimeEntry.MaximumRate, 0, rate, 130); holeFeed = new NumberField("HoleFeed", loaded.HoleFeedrate ?? loaded.Feedrate, CutTimeEntry.MinimumRate, @@ -116,16 +118,13 @@ namespace OpenNest.Avalonia AddRate(rates, 1, 0, "Rapid", rapid); AddRate(rates, 1, 2, "Pierce", pierce); - var choices = CutTimeMachineChoice.For(machines); - machineBox = new ComboBox + var machineText = new TextBlock { Name = "Machine", - ItemsSource = choices, - SelectedIndex = CutTimeMachineChoice.SavedIndex(choices, saved.Machine), - MinWidth = 200, + Text = machine?.Name ?? "None (full speed)", VerticalAlignment = VerticalAlignment.Center, }; - ToolTip.SetTip(machineBox, "Machine whose acceleration limits time the moves (Tools > Machine Configuration)"); + ToolTip.SetTip(machineText, "The nest's machine, whose acceleration limits time the moves (Nest > Machine)"); skipEtch = new CheckBox { Name = "SkipEtch", @@ -134,8 +133,8 @@ namespace OpenNest.Avalonia Margin = new Thickness(12, 0, 0, 0), }; ToolTip.SetTip(skipEtch, "Leave out contours that only etch, as the CI Fiber post does by default"); - var motion = Row(new TextBlock { Text = "Acceleration", VerticalAlignment = VerticalAlignment.Center }, - machineBox, skipEtch); + var motion = Row(new TextBlock { Text = "Machine", VerticalAlignment = VerticalAlignment.Center }, + machineText, skipEtch); var layout = new StackPanel { Margin = new Thickness(10), Spacing = 8 }; foreach (var part in new Control[] { transport, jumps, track, status, rates, motion }) @@ -157,7 +156,6 @@ namespace OpenNest.Avalonia }; foreach (var field in new[] { feed, holeFeed, rapid, pierce }) field.Changed += (_, _) => Rebuild(); - machineBox.SelectionChanged += (_, _) => Rebuild(); skipEtch.IsCheckedChanged += (_, _) => Rebuild(); timer.Tick += (_, _) => playback.Advance(); @@ -177,7 +175,7 @@ namespace OpenNest.Avalonia /// The parameters the boxes time the cut with. private CutParameters GetCutParameters() => CutTimeEntry.Parameters(feed.Value, holeFeed.Value, rapid.Value, pierce.Value, skipEtch.IsChecked == true, - units, (machineBox.SelectedItem as CutTimeMachineChoice)?.Machine); + units, machine); private void ApplySpeed() { @@ -310,7 +308,7 @@ namespace OpenNest.Avalonia private void OnClosed(object sender, EventArgs e) { - CutTimeSettingsFile.Save(GetCutParameters(), (machineBox.SelectedItem as CutTimeMachineChoice)?.Machine); + CutTimeSettingsFile.Save(GetCutParameters()); timer.Stop(); playback.Changed -= OnPlaybackChanged; playback.Clear(); diff --git a/OpenNest.Avalonia/CutTimeDialog.cs b/OpenNest.Avalonia/CutTimeDialog.cs index 33b8ff03..07008f10 100644 --- a/OpenNest.Avalonia/CutTimeDialog.cs +++ b/OpenNest.Avalonia/CutTimeDialog.cs @@ -193,6 +193,14 @@ namespace OpenNest.Avalonia public static SavedCutTimeSettings Read() => SavedCutTimeSettings.Read(UserSettingsFile.Read(UserSettingsFile.DefaultPath)); + /// + /// Remembers the feeds, pierce and etch choice, leaving the remembered machine alone (the + /// simulator times with the nest's machine, not a choice of its own). + /// + public static void Save(CutParameters parameters) => + UserSettingsFile.Update(UserSettingsFile.DefaultPath, settings => + SavedCutTimeSettings.Read(settings).With(parameters).WriteTo(settings)); + /// Remembers the feeds, pierce, etch choice and machine (null for full speed). public static void Save(CutParameters parameters, MachineConfig machine) => UserSettingsFile.Update(UserSettingsFile.DefaultPath, settings => diff --git a/OpenNest.Avalonia/MainWindow.CutTime.cs b/OpenNest.Avalonia/MainWindow.CutTime.cs index baa4939e..a1815be8 100644 --- a/OpenNest.Avalonia/MainWindow.CutTime.cs +++ b/OpenNest.Avalonia/MainWindow.CutTime.cs @@ -1,3 +1,4 @@ +using System.Linq; using System.Threading.Tasks; using Avalonia.Input; using Avalonia.Interactivity; @@ -79,7 +80,9 @@ namespace OpenNest.Avalonia inspection = null; return; } - simulator = new CutSimulatorWindow(view, machines); + var nestMachine = view.Tab.Document.Nest.Machine; + var machine = nestMachine == null ? null : machines.FirstOrDefault(m => m.Id == nestMachine.Id); + simulator = new CutSimulatorWindow(view, machine); simulator.Closed += (_, _) => { inspection?.Dispose(); diff --git a/OpenNest.WinForms.Tests/Forms/CutSimulatorFormTests.cs b/OpenNest.WinForms.Tests/Forms/CutSimulatorFormTests.cs new file mode 100644 index 00000000..75734bab --- /dev/null +++ b/OpenNest.WinForms.Tests/Forms/CutSimulatorFormTests.cs @@ -0,0 +1,139 @@ +using System.Reflection; +using System.Windows.Forms; +using OpenNest.Forms; +using OpenNest.Geometry; + +namespace OpenNest.WinForms.Tests.Forms; + +public class CutSimulatorFormTests +{ + [Fact] + public void InputsSitOnTheSettingsTabAndBothTabsFitWithoutResizing() => RunSta(() => + { + using var editor = Editor(); + editor.Show(); + editor.PlateManager.LoadAt(0); + editor.SimulateCutting(); + var simulator = (CutSimulatorForm)typeof(EditNestForm) + .GetField("cutSimulatorForm", BindingFlags.Instance | BindingFlags.NonPublic)! + .GetValue(editor)!; + try + { + var tabs = Field(simulator, "tabs"); + Assert.Equal(new[] { "Status", "Settings" }, tabs.TabPages.Cast().Select(p => p.Text)); + var settings = tabs.TabPages[1]; + foreach (var input in new[] { "feedBox", "holeFeedBox", "rapidBox", "pierceBox", "heatPowerBox", "skipEtchBox", "machineLabel" }) + Assert.Same(settings, PageOf(Field(simulator, input))); + Assert.Same(tabs.TabPages[0], PageOf(Field(simulator, "heatBox"))); + // The time stays above the tabs so it can be read while settings change. + Assert.Null(PageOf(Field(simulator, "timeLabel"))); + + var size = simulator.Size; + foreach (TabPage page in tabs.TabPages) + { + tabs.SelectedTab = page; + simulator.PerformLayout(); + Application.DoEvents(); + Assert.Equal(size, simulator.Size); + foreach (var control in Descendants(page.Controls[0]).Where(c => c.Visible)) + { + var bounds = page.RectangleToClient(control.RectangleToScreen(control.ClientRectangle)); + Assert.True(page.ClientRectangle.Contains(bounds), + $"{control.GetType().Name} '{control.Text}' at {bounds} is clipped by the {page.Text} tab ({page.ClientRectangle})."); + } + } + } + finally + { + simulator.Close(); + } + }); + + [Fact] + public void TheSliderLeadsAndTheJumpButtonsSpanItsTrackEvenly() => RunSta(() => + { + using var editor = Editor(); + editor.Show(); + editor.PlateManager.LoadAt(0); + editor.SimulateCutting(); + var simulator = (CutSimulatorForm)typeof(EditNestForm) + .GetField("cutSimulatorForm", BindingFlags.Instance | BindingFlags.NonPublic)! + .GetValue(editor)!; + try + { + Application.DoEvents(); + var track = Field(simulator, "trackBar"); + var play = Field