mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-04 17:29:24 -05:00
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 <noreply@anthropic.com>
140 lines
5.6 KiB
C#
140 lines
5.6 KiB
C#
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<TabControl>(simulator, "tabs");
|
|
Assert.Equal(new[] { "Status", "Settings" }, tabs.TabPages.Cast<TabPage>().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<Control>(simulator, input)));
|
|
Assert.Same(tabs.TabPages[0], PageOf(Field<Control>(simulator, "heatBox")));
|
|
// The time stays above the tabs so it can be read while settings change.
|
|
Assert.Null(PageOf(Field<Control>(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<TrackBar>(simulator, "trackBar");
|
|
var play = Field<Button>(simulator, "playButton");
|
|
Assert.True(Screen(track).Bottom <= Screen(play).Top, "The slider sits above the transport buttons.");
|
|
|
|
var jumps = new[] { "previousPartButton", "previousContourButton", "nextContourButton", "nextPartButton" }
|
|
.Select(name => Screen(Field<Button>(simulator, name))).ToArray();
|
|
Assert.True(jumps.Max(b => b.Width) - jumps.Min(b => b.Width) <= 1,
|
|
$"Jump buttons differ in width: {string.Join(", ", jumps.Select(b => b.Width))}");
|
|
// Ordinary buttons: the row never stretches them taller than the play button.
|
|
Assert.All(jumps, b => Assert.True(b.Height < Screen(play).Height, $"Jump button is {b.Height} px tall."));
|
|
|
|
var channel = new int[4];
|
|
var handle = System.Runtime.InteropServices.GCHandle.Alloc(channel, System.Runtime.InteropServices.GCHandleType.Pinned);
|
|
try
|
|
{
|
|
SendMessage(track.Handle, 0x0400 + 26, IntPtr.Zero, handle.AddrOfPinnedObject());
|
|
}
|
|
finally
|
|
{
|
|
handle.Free();
|
|
}
|
|
var start = track.PointToScreen(new System.Drawing.Point(channel[0], 0)).X;
|
|
var end = track.PointToScreen(new System.Drawing.Point(channel[2], 0)).X;
|
|
Assert.InRange(jumps[0].Left - start, -1, 1);
|
|
Assert.InRange(jumps[^1].Right - end, -1, 1);
|
|
}
|
|
finally
|
|
{
|
|
simulator.Close();
|
|
}
|
|
});
|
|
|
|
private static System.Drawing.Rectangle Screen(Control control) =>
|
|
control.RectangleToScreen(control.ClientRectangle);
|
|
|
|
[System.Runtime.InteropServices.DllImport("user32.dll")]
|
|
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
|
|
|
private static TabPage? PageOf(Control control)
|
|
{
|
|
for (var parent = control.Parent; parent != null; parent = parent.Parent)
|
|
{
|
|
if (parent is TabPage page)
|
|
return page;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private static IEnumerable<Control> Descendants(Control root)
|
|
{
|
|
foreach (Control child in root.Controls)
|
|
{
|
|
yield return child;
|
|
foreach (var nested in Descendants(child))
|
|
yield return nested;
|
|
}
|
|
}
|
|
|
|
private static T Field<T>(object owner, string name) where T : class =>
|
|
(T)owner.GetType().GetField(name, BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(owner)!;
|
|
|
|
private static EditNestForm Editor()
|
|
{
|
|
var nest = new Nest();
|
|
var plate = nest.CreatePlate();
|
|
plate.Size = new OpenNest.Geometry.Size(48, 48);
|
|
var drawing = new Drawing("square", TestPrograms.Square(10));
|
|
nest.Drawings.Add(drawing);
|
|
plate.Parts.Add(new Part(drawing, new Vector(5, 5)));
|
|
return new EditNestForm(nest);
|
|
}
|
|
|
|
private static void RunSta(System.Action action) =>
|
|
StaTestThread.Run(action, TimeSpan.FromSeconds(30), "Cut simulator form test timed out.");
|
|
}
|