mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-03 06:29:26 -05:00
Merge M05 status bar and engine list into the Avalonia port work
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # OpenNest.Avalonia/MainWindow.axaml
This commit is contained in:
commit
14641f1392
17 files changed
+777
-99
No files matched your search
@@ -0,0 +1,60 @@
|
||||
using OpenNest.Data;
|
||||
using OpenNest.Forms;
|
||||
|
||||
namespace OpenNest.Desktop.Tests.Forms;
|
||||
|
||||
public class MachineMenuTests
|
||||
{
|
||||
private static MachineConfig Machine(string name) => new() { Name = name };
|
||||
|
||||
[Fact]
|
||||
public void NoNest_ListsOnlyADisabledNote()
|
||||
{
|
||||
var item = Assert.Single(MachineMenu.Items(null!, new[] { Machine("Laser") }));
|
||||
|
||||
Assert.Equal(MachineMenu.NoNestText, item.Text);
|
||||
Assert.False(item.Enabled);
|
||||
Assert.Null(item.Machine);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Machines_AreListedByNameWithTheNestsChecked()
|
||||
{
|
||||
var laser = Machine("laser");
|
||||
var fiber = Machine("Fiber");
|
||||
var nest = new Nest { Machine = new NestMachine(laser.Id, laser.Name) };
|
||||
|
||||
var items = MachineMenu.Items(nest, new[] { laser, fiber });
|
||||
|
||||
Assert.Equal(new[] { "Fiber", "laser" }, items.Select(i => i.Text));
|
||||
Assert.Equal(new[] { false, true }, items.Select(i => i.Checked));
|
||||
Assert.All(items, i => Assert.True(i.Enabled));
|
||||
Assert.Same(fiber, items[0].Machine);
|
||||
Assert.True(MachineMenu.IsAssigned(nest, laser));
|
||||
Assert.False(MachineMenu.IsAssigned(nest, fiber));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AMachineNoLongerOnFile_StaysCheckedAndDisabled()
|
||||
{
|
||||
var nest = new Nest { Machine = new NestMachine(Guid.NewGuid(), "Old Plasma") };
|
||||
|
||||
var items = MachineMenu.Items(nest, new[] { Machine("Laser") });
|
||||
|
||||
Assert.Equal(2, items.Count);
|
||||
var gone = items[1];
|
||||
Assert.Equal("Old Plasma (not on file)", gone.Text);
|
||||
Assert.True(gone.Checked);
|
||||
Assert.False(gone.Enabled);
|
||||
Assert.Null(gone.Machine);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoMachines_PointsToMachineConfiguration()
|
||||
{
|
||||
var item = Assert.Single(MachineMenu.Items(new Nest(), Array.Empty<MachineConfig>()));
|
||||
|
||||
Assert.Equal(MachineMenu.NoMachinesText, item.Text);
|
||||
Assert.False(item.Enabled);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using OpenNest.Desktop.Interaction;
|
||||
using OpenNest.Desktop.Tests.Interaction;
|
||||
using OpenNest.Forms;
|
||||
using OpenNest.Geometry;
|
||||
|
||||
namespace OpenNest.Desktop.Tests.Forms;
|
||||
|
||||
public sealed class MainStatusTextTests : IDisposable
|
||||
{
|
||||
private readonly CultureInfo previous = CultureInfo.CurrentCulture;
|
||||
|
||||
public MainStatusTextTests() => CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
|
||||
|
||||
public void Dispose() => CultureInfo.CurrentCulture = previous;
|
||||
|
||||
[Fact]
|
||||
public void Location_ShowsBothCoordinatesToFourPlaces() =>
|
||||
Assert.Equal("Location: [1,234.5000, -0.1250]", MainStatusText.Location(new Vector(1234.5, -0.125)));
|
||||
|
||||
[Fact]
|
||||
public void Utilization_ShowsOnePlaceOfPercent() =>
|
||||
Assert.Equal("Util: 61.3 %", MainStatusText.Utilization(0.6125));
|
||||
|
||||
[Fact]
|
||||
public void Material_ShowsNameGradeAndThicknessWithUnits()
|
||||
{
|
||||
Assert.Equal("Material: Steel A36 · 0.25 in", MainStatusText.Material("Steel", " A36 ", 0.25, Units.Inches));
|
||||
Assert.Equal("Material: 304 SS · 3 mm", MainStatusText.Material(" 304 SS ", "", 3, Units.Millimeters));
|
||||
Assert.Equal("Material: 0.1875 in", MainStatusText.Material(null, null, 0.1875, Units.Inches));
|
||||
Assert.Equal("Material: (none)", MainStatusText.Material("", " ", 0, Units.Inches));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Material_ReadsTheNest()
|
||||
{
|
||||
var nest = new Nest { Thickness = 0.5, Units = Units.Inches, Material = new Material("Mild Steel", "A36", 0.2836) };
|
||||
|
||||
Assert.Equal("Material: Mild Steel A36 · 0.5 in", MainStatusText.Material(nest));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Machine_ShowsTheNestsMachine()
|
||||
{
|
||||
Assert.Equal("Machine: CL-980", MainStatusText.Machine(new NestMachine(Guid.NewGuid(), " CL-980 ")));
|
||||
Assert.Equal("Machine: (unnamed)", MainStatusText.Machine(new NestMachine(Guid.NewGuid(), "")));
|
||||
Assert.Equal("Machine: (none)", MainStatusText.Machine(null!));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Version_DropsBuildMetadata()
|
||||
{
|
||||
Assert.Equal("v1.2.3", MainStatusText.Version("1.2.3"));
|
||||
Assert.DoesNotContain("+", MainStatusText.DisplayVersion(typeof(MainStatusText).Assembly));
|
||||
Assert.Equal(
|
||||
typeof(MainStatusText).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!
|
||||
.InformationalVersion.Split('+')[0],
|
||||
MainStatusText.DisplayVersion(typeof(MainStatusText).Assembly));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LocationMode_FollowsTheMouseUnlessSavedOff()
|
||||
{
|
||||
var settings = new Dictionary<string, string>();
|
||||
Assert.True(MainStatusText.ReadLocationFollowsMouse(settings));
|
||||
|
||||
MainStatusText.WriteLocationFollowsMouse(settings, false);
|
||||
Assert.Equal("False", settings[MainStatusText.LocationFollowsMouseName]);
|
||||
Assert.False(MainStatusText.ReadLocationFollowsMouse(settings));
|
||||
|
||||
settings[MainStatusText.LocationFollowsMouseName] = "nonsense";
|
||||
Assert.True(MainStatusText.ReadLocationFollowsMouse(settings));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PlateWork_IsBusyWhileAJobRunsOrAToolIsMidTask()
|
||||
{
|
||||
var plate = InteractionFixtures.Plate();
|
||||
var host = new TestToolHost(plate);
|
||||
var tools = new[] { host.Tools.Current };
|
||||
|
||||
Assert.False(PlateWorkGuard.IsBusy(false, tools));
|
||||
Assert.True(PlateWorkGuard.IsBusy(true, tools));
|
||||
|
||||
// As the WinForms select action: a selection is work in progress.
|
||||
host.Selection.Select(plate.Parts[0]);
|
||||
Assert.True(PlateWorkGuard.IsBusy(false, tools));
|
||||
Assert.False(PlateWorkGuard.IsBusy(false, Array.Empty<PlateTool>()));
|
||||
}
|
||||
}
|
||||
@@ -330,4 +330,33 @@ public sealed class MachineSettingsSourceTests : IDisposable
|
||||
|
||||
Assert.Equal(0.75, settings.PartClearance);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMachine_AssignsItAndGivesTheViewsAndTheUntouchedSheetItsDefaults()
|
||||
{
|
||||
var machine = CuttingMachine();
|
||||
var thickness = machine.Materials[0].Thicknesses[0];
|
||||
thickness.CutOff = new CutOffConfig { PartClearance = 0.75 };
|
||||
thickness.PartSpacing = 0.3;
|
||||
new LocalJsonProvider(MachinesDirectory).SaveMachine(machine);
|
||||
var nest = NestFor(machine, 0.25);
|
||||
nest.Machine = null;
|
||||
var used = nest.CreatePlate();
|
||||
used.PartSpacing = 0.1;
|
||||
used.Parts.Add(new Part(new Drawing("square", new CNC.Program())));
|
||||
using var plates = new PlateManager(nest);
|
||||
plates.EnsureSentinel();
|
||||
var sentinel = nest.Plates[^1];
|
||||
var views = new[] { new CutOffSettings { PartClearance = 0.1 }, new CutOffSettings { PartClearance = 0.2 } };
|
||||
|
||||
Machines().ApplyMachine(nest, machine, plates, views);
|
||||
|
||||
Assert.Equal(machine.Id, nest.Machine!.Id);
|
||||
Assert.Equal("Fiber 1", nest.Machine.Name);
|
||||
Assert.All(views, settings => Assert.Equal(0.75, settings.PartClearance));
|
||||
Assert.Equal(0.3, nest.PlateDefaults.PartSpacing);
|
||||
Assert.Equal(0.3, sentinel.PartSpacing);
|
||||
// A sheet in use keeps its own spacing.
|
||||
Assert.Equal(0.1, used.PartSpacing);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user