mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-28 00:21:34 -05:00
feat(desktop): undo machine changes and Nest Info edits
The nest's machine and its Nest Info fields were the last edits only the fingerprint safety net could catch (and it misses most of them). Machine is now one step, together with the support grid and cut-off settings the machine brings. Nest Info is one step for what Undo can put back (units, material, thickness, customer, notes and plate defaults); the name, status, author and creation date stay as they are through Undo, so an edit of only those records nothing. The sheet strip only shows Auto Nest proposals; what it shows is committed through Auto Nest, which is already recorded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2e72469d6c
commit
16afb41c26
4 files changed
+75
-10
No files matched your search
@@ -485,6 +485,43 @@ public class UndoRecordingTests
|
||||
env.AssertOneUndoableEdit("Add Part", () => UndoTestEnv.Invoke(env.View, "OnDragDrop", drop));
|
||||
});
|
||||
|
||||
// Nest
|
||||
|
||||
[Fact]
|
||||
public void AssigningAMachineRecordsOneEntry() => UndoTestEnv.Run(env =>
|
||||
{
|
||||
var machine = new Data.MachineConfig { Name = "Undo test laser" };
|
||||
env.AssertOneUndoableEdit("Machine", () => UndoTestEnv.Invoke(env.Host, "AssignMachine", machine));
|
||||
Assert.Equal(machine.Id, env.Nest.Machine!.Id);
|
||||
});
|
||||
|
||||
[Fact]
|
||||
public void EditingNestInfoRecordsOneEntry() => UndoTestEnv.Run(env =>
|
||||
{
|
||||
UndoTestEnv.AcceptWhenShown<EditNestInfoForm>(form =>
|
||||
{
|
||||
form.Notes = "edited";
|
||||
form.Customer = "someone";
|
||||
});
|
||||
env.AssertOneUndoableEdit("Nest Info", () => Assert.True(env.Editor.ShowNestInfoEditorAsync().IsCompleted));
|
||||
Assert.Equal("edited", env.Nest.Notes);
|
||||
});
|
||||
|
||||
[Fact]
|
||||
public void ANestInfoEditOfOnlyItsIdentityRecordsNothing() => UndoTestEnv.Run(env =>
|
||||
{
|
||||
UndoTestEnv.AcceptWhenShown<EditNestInfoForm>(form =>
|
||||
{
|
||||
form.Status = NestStatus.HasBeenCut;
|
||||
form.MadeBy = "someone else";
|
||||
});
|
||||
|
||||
Assert.True(env.Editor.ShowNestInfoEditorAsync().IsCompleted);
|
||||
|
||||
Assert.Equal(NestStatus.HasBeenCut, env.Nest.Status);
|
||||
Assert.Equal(0, env.Editor.History.UndoCount);
|
||||
});
|
||||
|
||||
private static void Click(PlateView view, System.Drawing.Point at)
|
||||
{
|
||||
UndoTestEnv.Mouse(view, "OnMouseMove", MouseButtons.None, at);
|
||||
|
||||
@@ -124,6 +124,7 @@ internal sealed record UndoTestEnv(MainForm Host, EditNestForm Editor)
|
||||
void Line(FormattableString line) => text.AppendLine(line.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
Line($"machine {nest.Machine?.Id} support {nest.SupportBed != null} units {nest.Units}");
|
||||
Line($"material {nest.Material?.Name} {nest.Material?.Grade} thickness {nest.Thickness} customer {nest.Customer} notes {nest.Notes}");
|
||||
Line($"defaults {nest.PlateDefaults.Size} {nest.PlateDefaults.PartSpacing} {nest.PlateDefaults.ClampRail != null}");
|
||||
Line($"options {nest.PlateOptions.Count} salvage {nest.SalvageRate} remnant {nest.MinimumRemnantDimension}");
|
||||
foreach (var drawing in nest.Drawings.OrderBy(d => d.Name))
|
||||
@@ -155,9 +156,16 @@ internal sealed record UndoTestEnv(MainForm Host, EditNestForm Editor)
|
||||
(ToolStripMenuItem)typeof(MainForm).GetField(name, BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(host)!;
|
||||
|
||||
/// <summary>Calls a private or internal instance method of <paramref name="target"/>.</summary>
|
||||
public static object? Invoke(object target, string method, params object?[] args) =>
|
||||
target.GetType().GetMethod(method, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)!
|
||||
.Invoke(target, args);
|
||||
public static object? Invoke(object target, string method, params object?[] args)
|
||||
{
|
||||
for (var type = target.GetType(); type != null; type = type.BaseType)
|
||||
{
|
||||
var found = type.GetMethod(method, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly);
|
||||
if (found != null)
|
||||
return found.Invoke(target, args);
|
||||
}
|
||||
throw new MissingMethodException(target.GetType().Name, method);
|
||||
}
|
||||
|
||||
/// <summary>Calls a MainForm menu handler with no sender.</summary>
|
||||
public void Click(string handler) =>
|
||||
|
||||
@@ -821,9 +821,18 @@ namespace OpenNest.Forms
|
||||
if (form.NestName != Nest.Name && !await ConfirmRenameAsync(form.NestName))
|
||||
continue;
|
||||
|
||||
PlateManager.ChangePlateDefaults(() => form.SaveNestInfo(Nest));
|
||||
// The material, thickness or units may have changed.
|
||||
MachineSettings.ApplyCutOffDefaults(PlateView, Nest);
|
||||
// The name, status, author and creation date stay as they are through undo, so
|
||||
// an edit of only those records nothing.
|
||||
using (var change = BeginChange("Nest Info"))
|
||||
{
|
||||
var before = UndoableNestInfo();
|
||||
PlateManager.ChangePlateDefaults(() => form.SaveNestInfo(Nest));
|
||||
if (UndoableNestInfo() != before)
|
||||
change.MarkChanged();
|
||||
// The material, thickness or units may have changed.
|
||||
MachineSettings.ApplyCutOffDefaults(PlateView, Nest);
|
||||
change.Complete();
|
||||
}
|
||||
Text = Nest.Name;
|
||||
drawingListBox1.Units = Nest.Units;
|
||||
drawingListBox1.Invalidate();
|
||||
@@ -833,6 +842,15 @@ namespace OpenNest.Forms
|
||||
}
|
||||
}
|
||||
|
||||
// What Nest Info edits that undo puts back: everything but the identity fields.
|
||||
private string UndoableNestInfo()
|
||||
{
|
||||
var defaults = Nest.PlateDefaults;
|
||||
return string.Join("|", Nest.Units, Nest.Notes, Nest.Customer, Nest.Thickness, Nest.Material?.Name,
|
||||
Nest.Material?.Grade, defaults.Size, defaults.PartSpacing, defaults.EdgeSpacing.Left,
|
||||
defaults.EdgeSpacing.Bottom, defaults.EdgeSpacing.Right, defaults.EdgeSpacing.Top, defaults.Quadrant);
|
||||
}
|
||||
|
||||
private void HoldStatus_CloseoutNoteRequested(object sender, int openHolds)
|
||||
{
|
||||
if (IsDisposed)
|
||||
|
||||
@@ -96,12 +96,14 @@ namespace OpenNest.Forms
|
||||
return;
|
||||
}
|
||||
|
||||
MachineSettings.AssignMachine(nest, machine);
|
||||
foreach (var view in views)
|
||||
editForm.RecordChange("Machine", () =>
|
||||
{
|
||||
MachineSettings.ApplyCutOffDefaults(view, nest);
|
||||
MachineSettings.AssignMachine(nest, machine);
|
||||
foreach (var view in views)
|
||||
MachineSettings.ApplyCutOffDefaults(view, nest);
|
||||
});
|
||||
foreach (var view in views)
|
||||
view.Invalidate();
|
||||
}
|
||||
statusBar.UpdatePlate();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user