mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-31 04:01:06 -04:00
Machine Configuration held one lead-in and lead-out per thickness and applied it to every contour. Each thickness now has Outside Cuts and Inside Cuts tabs; inside cuts follow the outside leads until "Same as outside cuts" is cleared, and configurations without inside leads keep applying one pair to both. The lead type lists, per-type fields and preview from Cutting Settings are now a reusable LeadsEditor control that both dialogs use. The machine tabs hide what the configuration cannot hold: the arc sweep, the clean-hole kerf (taken from the thickness) and Line + Line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
103 lines
4.7 KiB
C#
103 lines
4.7 KiB
C#
using System.Windows.Forms;
|
|
using OpenNest.Data;
|
|
using OpenNest.Forms;
|
|
|
|
namespace OpenNest.WinForms.Tests.Forms;
|
|
|
|
/// <summary>
|
|
/// The Outside Cuts and Inside Cuts tabs of a thickness in Machine Configuration: inside cuts
|
|
/// follow the outside leads until "Same as outside cuts" is cleared, which gives them a copy.
|
|
/// </summary>
|
|
public class MachineCutsFormsTests
|
|
{
|
|
[Fact]
|
|
public void InsideCutsTab_GivesHolesTheirOwnLeads()
|
|
{
|
|
RunSta(() =>
|
|
{
|
|
var directory = Path.Combine(Path.GetTempPath(), "OpenNestTests", Guid.NewGuid().ToString());
|
|
Directory.CreateDirectory(directory);
|
|
try
|
|
{
|
|
var provider = new LocalJsonProvider(directory);
|
|
var thickness = new ThicknessConfig
|
|
{
|
|
Value = 0.25,
|
|
LeadIn = new LeadConfig { Type = "Arc", Radius = 0.125 },
|
|
LeadOut = new LeadConfig { Type = "None" },
|
|
};
|
|
provider.SaveMachine(new MachineConfig
|
|
{
|
|
Name = "Laser",
|
|
Materials = { new MaterialConfig { Name = "Mild Steel", Thicknesses = { thickness } } },
|
|
});
|
|
|
|
using var form = new MachineConfigForm(provider);
|
|
var node = Descendants(Find<TreeView>(form, "_tree").Nodes).Single(n => n.Tag is ThicknessConfig);
|
|
// A hidden tree raises no AfterSelect, so show the thickness as selecting it would.
|
|
typeof(MachineConfigForm)
|
|
.GetMethod("Tree_AfterSelect", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!
|
|
.Invoke(form, new object[] { null, new TreeViewEventArgs(node) });
|
|
var shown = (ThicknessConfig)node.Tag;
|
|
|
|
var pages = All<TabControl>(form).Single().TabPages.Cast<TabPage>().ToList();
|
|
Assert.DoesNotContain(pages, p => p.Text is "Lead In" or "Lead Out");
|
|
var outside = pages.Single(p => p.Text == "Outside Cuts");
|
|
Assert.DoesNotContain(All<ComboBox>(outside), c => c.Items.Contains("Clean Hole"));
|
|
|
|
var inside = pages.Single(p => p.Text == "Inside Cuts");
|
|
var same = All<CheckBox>(inside).Single(c => c.Text == "Same as outside cuts");
|
|
Assert.True(same.Checked);
|
|
Assert.All(All<ComboBox>(inside), c => Assert.False(c.Enabled));
|
|
Assert.NotNull(All<OpenNest.Controls.LeadPreview>(inside).Single().Parameters);
|
|
|
|
same.Checked = false;
|
|
Assert.Equal("Arc", shown.InsideLeadIn!.Type);
|
|
Assert.Equal(0.125, shown.InsideLeadIn.Radius);
|
|
Assert.NotSame(shown.LeadIn, shown.InsideLeadIn);
|
|
Assert.All(All<ComboBox>(inside), c => Assert.True(c.Enabled));
|
|
|
|
All<ComboBox>(inside).Single(c => c.Items.Contains("Clean Hole")).SelectedItem = "Clean Hole";
|
|
Assert.Equal("Clean Hole", shown.InsideLeadIn.Type);
|
|
Assert.Equal("Arc", shown.LeadIn.Type);
|
|
// Only the chosen type's fields show: line length and arc radius.
|
|
var leadInGrid = All<NumericUpDown>(inside).ToList();
|
|
Assert.Equal(2, leadInGrid.Count);
|
|
leadInGrid[1].Value = 0.07m;
|
|
Assert.Equal(0.07, shown.InsideLeadIn.Radius, 6);
|
|
Assert.Equal(0.125, shown.LeadIn.Radius);
|
|
var preview = All<OpenNest.Controls.LeadPreview>(inside).Single().Parameters;
|
|
Assert.Equal(0.07, Assert.IsType<OpenNest.CNC.CuttingStrategy.CleanHoleLeadIn>(preview.InternalLeadIn).ArcRadius, 6);
|
|
|
|
same.Checked = true;
|
|
Assert.Null(shown.InsideLeadIn);
|
|
Assert.Null(shown.InsideLeadOut);
|
|
}
|
|
finally
|
|
{
|
|
Directory.Delete(directory, recursive: true);
|
|
}
|
|
});
|
|
}
|
|
|
|
private static IEnumerable<TreeNode> Descendants(TreeNodeCollection nodes) =>
|
|
nodes.Cast<TreeNode>().SelectMany(n => Descendants(n.Nodes).Prepend(n));
|
|
|
|
private static T Find<T>(Control root, string name) where T : Control =>
|
|
Assert.IsType<T>(root.Controls.Find(name, true).Single());
|
|
|
|
private static IEnumerable<T> All<T>(Control root) where T : Control
|
|
{
|
|
foreach (Control child in root.Controls)
|
|
{
|
|
if (child is T match)
|
|
yield return match;
|
|
foreach (var nested in All<T>(child))
|
|
yield return nested;
|
|
}
|
|
}
|
|
|
|
private static void RunSta(System.Action action) =>
|
|
StaTestThread.Run(action, Timeout.InfiniteTimeSpan, "The STA test did not complete.");
|
|
}
|