mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-16 09:05:34 -05:00
feat(desktop): undo fills, pattern tiles, auto nest and clear nest
Placement edits were only caught by the fingerprint safety net, so they undid as an anonymous "Change" or folded into the next edit. Each now records one labelled step: Fill (at the commit, so a stopped fill that keeps nothing records nothing), Fill Area, Pattern Tile, Auto Nest (from the kept proposal only; Make Nests tabs too), Clear Nest, Remove Empty Plates and Center Parts. Clear Nest no longer warns that it cannot be undone. Pattern Tile onto a new plate created a plate beside the empty sentinel, which the plate manager dropped at once, so the pattern landed on a detached plate; it now fills the sentinel. The undo tests share one harness that compares a text description of the nest before an edit and after Undo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d1270f5208
commit
223bfea47c
11 files changed
+371
-96
No files matched your search
@@ -35,6 +35,10 @@ public class MainFormReleaseNestingTests
|
||||
Assert.StartsWith("Nested on 1 sheet", first.Note);
|
||||
Assert.Equal(6, saved.Plates.Sum(p => p.Parts.Count * p.Quantity));
|
||||
Assert.Equal(Guid.Empty, tab.Document.RemoteId);
|
||||
// The kept layout is one undoable step in the tab; undo waits for the release.
|
||||
Assert.Equal(1, tab.History.UndoCount);
|
||||
Assert.Equal("Auto Nest", tab.History.UndoLabel);
|
||||
Assert.False(main.TryUndo(tab));
|
||||
Run(host.RenestAsync(unsaved, CancellationToken.None));
|
||||
Assert.Equal(2, Tabs(main).Count);
|
||||
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
using System.Windows.Forms;
|
||||
using OpenNest.Actions;
|
||||
using OpenNest.Engine;
|
||||
using OpenNest.Engine.Strategies;
|
||||
using OpenNest.Forms;
|
||||
using OpenNest.Geometry;
|
||||
|
||||
namespace OpenNest.WinForms.Tests.Forms;
|
||||
|
||||
// Each desktop edit records one labelled undo entry and Undo puts the nest back. Reads
|
||||
// Application.OpenForms through the busy guards, so it must not overlap fill-lifetime tests.
|
||||
[Collection("Fill operation lifetime")]
|
||||
public class UndoRecordingTests
|
||||
{
|
||||
// Placement
|
||||
|
||||
[Fact]
|
||||
public void AFillRecordsOneEntryAtItsCommit() => UndoTestEnv.Run(env =>
|
||||
{
|
||||
env.Editor.PlateManager.LoadAt(2);
|
||||
var square = env.Nest.Drawings.Single();
|
||||
using var fill = UseFill(context => [new Part(context.Item.Drawing, context.WorkArea.Location)]);
|
||||
|
||||
env.AssertOneUndoableEdit("Fill", () =>
|
||||
{
|
||||
env.View.FillWithProgress([new Part(square)], env.View.Plate.WorkArea());
|
||||
WaitForFill(env);
|
||||
});
|
||||
});
|
||||
|
||||
[Fact]
|
||||
public void AFillThatPlacesNothingRecordsNothing() => UndoTestEnv.Run(env =>
|
||||
{
|
||||
env.Editor.PlateManager.LoadAt(2);
|
||||
using var fill = UseFill(_ => []);
|
||||
|
||||
env.View.FillWithProgress([new Part(env.Nest.Drawings.Single())], env.View.Plate.WorkArea());
|
||||
WaitForFill(env);
|
||||
|
||||
Assert.Equal(0, env.Editor.History.UndoCount);
|
||||
});
|
||||
|
||||
[Fact]
|
||||
public void FillAreaRecordsOneEntry() => UndoTestEnv.Run(env =>
|
||||
{
|
||||
env.Editor.PlateManager.LoadAt(2);
|
||||
using var fill = UseFill(context => [new Part(context.Item.Drawing, context.WorkArea.Location)]);
|
||||
env.View.SetAction(typeof(ActionFillArea), env.Nest.Drawings.Single());
|
||||
var action = (ActionFillArea)env.View.Actions.CurrentAction;
|
||||
UndoTestEnv.SetBackingField(action, "SelectedArea", new Box(0, 0, 50, 50));
|
||||
|
||||
env.AssertOneUndoableEdit("Fill Area", () => UndoTestEnv.Invoke(action, "FillArea"));
|
||||
});
|
||||
|
||||
[Theory]
|
||||
[InlineData(PatternTileTarget.CurrentPlate)]
|
||||
[InlineData(PatternTileTarget.NewPlate)]
|
||||
public void PatternTileRecordsOneEntry(PatternTileTarget target) => UndoTestEnv.Run(env =>
|
||||
{
|
||||
env.Editor.PlateManager.LoadAt(0);
|
||||
var square = env.Nest.Drawings.Single();
|
||||
var result = new PatternTileResult
|
||||
{
|
||||
Target = target,
|
||||
PlateSize = new Geometry.Size(60, 60),
|
||||
Parts = [new Part(square, new Vector(1, 1)), new Part(square, new Vector(12, 1)), new Part(square, new Vector(23, 1))],
|
||||
};
|
||||
|
||||
env.AssertOneUndoableEdit("Pattern Tile", () => MainForm.ApplyPatternTile(env.Editor, result));
|
||||
});
|
||||
|
||||
[Fact]
|
||||
public void ClearNestRecordsOneEntry() => UndoTestEnv.Run(env =>
|
||||
env.AssertOneUndoableEdit("Clear Nest", env.Editor.ClearNest));
|
||||
|
||||
[Fact]
|
||||
public void RemoveEmptyPlatesRecordsOneEntry() => UndoTestEnv.Run(env =>
|
||||
env.AssertOneUndoableEdit("Remove Empty Plates", env.Editor.RemoveEmptyPlates));
|
||||
|
||||
[Fact]
|
||||
public void CenterPartsRecordsOneEntry() => UndoTestEnv.Run(env =>
|
||||
{
|
||||
env.Editor.PlateManager.LoadAt(0);
|
||||
env.AssertOneUndoableEdit("Center Parts", () => env.Click("CenterParts_Click"));
|
||||
});
|
||||
|
||||
private static IDisposable UseFill(Func<FillContext, List<Part>> fill)
|
||||
{
|
||||
var prior = EngineSelection.EngineName;
|
||||
EngineSelection.EngineName = EngineSelection.DefaultEngineName;
|
||||
var strategies = FillStrategyRegistry.UseForTesting([new TestFill(fill)]);
|
||||
return new Restore(() =>
|
||||
{
|
||||
strategies.Dispose();
|
||||
EngineSelection.EngineName = prior;
|
||||
});
|
||||
}
|
||||
|
||||
private static void WaitForFill(UndoTestEnv env)
|
||||
{
|
||||
var deadline = DateTime.UtcNow.AddSeconds(30);
|
||||
while (env.View.IsFillInProgress)
|
||||
{
|
||||
Assert.True(DateTime.UtcNow < deadline, "The fill did not finish.");
|
||||
Application.DoEvents();
|
||||
Thread.Sleep(5);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class TestFill(Func<FillContext, List<Part>> fill) : IFillStrategy
|
||||
{
|
||||
public string Name => "Undo recording test fill";
|
||||
public NestPhase Phase => NestPhase.Linear;
|
||||
public int Order => 0;
|
||||
public List<Part> Fill(FillContext context) => fill(context);
|
||||
}
|
||||
|
||||
private sealed class Restore(System.Action restore) : IDisposable
|
||||
{
|
||||
public void Dispose() => restore();
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,6 @@ using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
using OpenNest.Controls;
|
||||
using OpenNest.Forms;
|
||||
using OpenNest.Geometry;
|
||||
using Size = OpenNest.Geometry.Size;
|
||||
|
||||
namespace OpenNest.WinForms.Tests.Forms;
|
||||
|
||||
@@ -346,62 +344,13 @@ public class UndoRedoTests
|
||||
Assert.True(redo.Enabled);
|
||||
});
|
||||
|
||||
private sealed record Env(MainForm Host, EditNestForm Editor);
|
||||
private static void Run(Action<UndoTestEnv> body) => UndoTestEnv.Run(body);
|
||||
|
||||
private static void Run(Action<Env> body) => StaTestThread.Run(() =>
|
||||
{
|
||||
using var host = new Host();
|
||||
host.Show();
|
||||
using var editor = new EditNestForm(BuildNest()) { MdiParent = host };
|
||||
editor.PlateView.SetOverlapAutoCheck(null);
|
||||
editor.Show();
|
||||
editor.Activate();
|
||||
body(new Env(host, editor));
|
||||
}, TimeSpan.FromMinutes(1), "The STA test did not complete.");
|
||||
|
||||
private static Nest BuildNest()
|
||||
{
|
||||
var nest = new Nest("undo");
|
||||
var square = new Drawing("square", Square());
|
||||
nest.Drawings.Add(square);
|
||||
int[] partsPerPlate = { 2, 2, 0, 1 };
|
||||
foreach (var count in partsPerPlate)
|
||||
{
|
||||
var plate = nest.CreatePlate();
|
||||
plate.Size = new Size(100, 100);
|
||||
for (var i = 0; i < count; i++)
|
||||
plate.Parts.Add(new Part(square, new Vector(5 + i * 20, 5)));
|
||||
}
|
||||
return nest;
|
||||
}
|
||||
|
||||
private static ToolStripMenuItem MenuItem(MainForm host, string name) =>
|
||||
(ToolStripMenuItem)typeof(MainForm).GetField(name, BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(host)!;
|
||||
private static ToolStripMenuItem MenuItem(MainForm host, string name) => UndoTestEnv.MenuItem(host, name);
|
||||
|
||||
private static void Mouse(PlateView view, string method, MouseButtons button, Point location) =>
|
||||
typeof(PlateView).GetMethod(method, BindingFlags.Instance | BindingFlags.NonPublic)!
|
||||
.Invoke(view, new object[] { new MouseEventArgs(button, 1, location.X, location.Y, 0) });
|
||||
UndoTestEnv.Mouse(view, method, button, location);
|
||||
|
||||
private static void SetBackingField(object target, string property, object value) =>
|
||||
target.GetType()
|
||||
.GetField($"<{property}>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic)!
|
||||
.SetValue(target, value);
|
||||
|
||||
private static CNC.Program Square()
|
||||
{
|
||||
var program = new CNC.Program();
|
||||
program.MoveTo(0, 0);
|
||||
program.LineTo(0, 10);
|
||||
program.LineTo(10, 10);
|
||||
program.LineTo(10, 0);
|
||||
program.LineTo(0, 0);
|
||||
return program;
|
||||
}
|
||||
|
||||
private sealed class Host : MainForm
|
||||
{
|
||||
// No startup migrations/automatic new document, and no settings save at close.
|
||||
protected override void OnLoad(EventArgs e) { }
|
||||
protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { }
|
||||
}
|
||||
UndoTestEnv.SetBackingField(target, property, value);
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using OpenNest.Controls;
|
||||
using OpenNest.Forms;
|
||||
using OpenNest.Geometry;
|
||||
using Size = OpenNest.Geometry.Size;
|
||||
|
||||
namespace OpenNest.WinForms.Tests.Forms;
|
||||
|
||||
/// <summary>A main window with one nest window open, for undo tests.</summary>
|
||||
internal sealed record UndoTestEnv(MainForm Host, EditNestForm Editor)
|
||||
{
|
||||
public PlateView View => Editor.PlateView;
|
||||
|
||||
public Nest Nest => Editor.Nest;
|
||||
|
||||
/// <summary>
|
||||
/// Runs <paramref name="body"/> on an STA thread with a nest of four plates holding 2, 2, 0
|
||||
/// and 1 squares of drawing "square", plus the empty new-plate sentinel.
|
||||
/// </summary>
|
||||
public static void Run(Action<UndoTestEnv> body, Func<Nest>? nest = null) => StaTestThread.Run(() =>
|
||||
{
|
||||
using var host = new TestHost();
|
||||
host.Show();
|
||||
using var editor = new EditNestForm((nest ?? BuildNest)()) { MdiParent = host };
|
||||
editor.PlateView.SetOverlapAutoCheck(null);
|
||||
editor.Show();
|
||||
editor.Activate();
|
||||
body(new UndoTestEnv(host, editor));
|
||||
}, TimeSpan.FromMinutes(1), "The STA test did not complete.");
|
||||
|
||||
/// <summary>
|
||||
/// Runs <paramref name="edit"/> and checks it recorded exactly one entry named
|
||||
/// <paramref name="label"/> that changed the nest, and that Undo puts the nest back.
|
||||
/// </summary>
|
||||
public void AssertOneUndoableEdit(string label, Action edit)
|
||||
{
|
||||
var before = Describe(Nest);
|
||||
var count = Editor.History.UndoCount;
|
||||
|
||||
edit();
|
||||
|
||||
Assert.Equal(count + 1, Editor.History.UndoCount);
|
||||
Assert.Equal(label, Editor.History.UndoLabel);
|
||||
var after = Describe(Nest);
|
||||
Assert.NotEqual(before, after);
|
||||
Assert.True(Host.TryUndo(Editor), "Undo was refused.");
|
||||
Assert.Equal(before, Describe(Nest));
|
||||
Assert.True(Host.TryRedo(Editor), "Redo was refused.");
|
||||
Assert.Equal(after, Describe(Nest));
|
||||
}
|
||||
|
||||
public static Nest BuildNest()
|
||||
{
|
||||
var nest = new Nest("undo");
|
||||
var square = new Drawing("square", Square(10));
|
||||
nest.Drawings.Add(square);
|
||||
int[] partsPerPlate = { 2, 2, 0, 1 };
|
||||
foreach (var count in partsPerPlate)
|
||||
{
|
||||
var plate = nest.CreatePlate();
|
||||
plate.Size = new Size(100, 100);
|
||||
for (var i = 0; i < count; i++)
|
||||
plate.Parts.Add(new Part(square, new Vector(5 + i * 20, 5)));
|
||||
}
|
||||
return nest;
|
||||
}
|
||||
|
||||
public static CNC.Program Square(double side)
|
||||
{
|
||||
var program = new CNC.Program();
|
||||
program.MoveTo(0, 0);
|
||||
program.LineTo(0, side);
|
||||
program.LineTo(side, side);
|
||||
program.LineTo(side, 0);
|
||||
program.LineTo(0, 0);
|
||||
return program;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What the nest holds, as text: plates with their stock, settings, parts, cut-offs and
|
||||
/// clamps, drawings with their quantities, and nest-level settings. Undo compares it.
|
||||
/// </summary>
|
||||
public static string Describe(Nest nest)
|
||||
{
|
||||
var text = new StringBuilder();
|
||||
void Line(FormattableString line) => text.AppendLine(line.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
Line($"machine {nest.Machine?.Id} support {nest.SupportBed != null} units {nest.Units}");
|
||||
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))
|
||||
{
|
||||
var box = drawing.Program.BoundingBox();
|
||||
Line($"drawing {drawing.Name} required {drawing.Quantity.Required} codes {drawing.Program.Length} box {box.Width:F4}x{box.Length:F4} priority {drawing.Priority}");
|
||||
}
|
||||
foreach (var plate in nest.Plates)
|
||||
{
|
||||
Line($"plate {plate.Size} x{plate.Quantity} spacing {plate.PartSpacing} edge {plate.EdgeSpacing.Left},{plate.EdgeSpacing.Bottom},{plate.EdgeSpacing.Right},{plate.EdgeSpacing.Top} quadrant {plate.Quadrant} params {plate.CuttingParameters != null}");
|
||||
var clamps = plate.ClampZones.Select(z => FormattableString.Invariant($"{z.Id}@{z.Bounds.X:F4},{z.Bounds.Y:F4},{z.Bounds.Width:F4},{z.Bounds.Length:F4}"));
|
||||
Line($" clamps [{string.Join(";", clamps)}] removed {plate.RemovedClamps.Count} support {plate.SupportBed != null} stock {string.Join(",", plate.StockItemCodes)}");
|
||||
foreach (var part in plate.Parts)
|
||||
Line($" part {part.BaseDrawing.Name} {part.Location.X:F4},{part.Location.Y:F4} r{part.Rotation:F6} leads {part.HasManualLeadIns} locked {part.LeadInsLocked} codes {part.Program.Length}");
|
||||
foreach (var cutOff in plate.CutOffs)
|
||||
Line($" cutoff {cutOff.Axis} {cutOff.Position.X:F4},{cutOff.Position.Y:F4}");
|
||||
}
|
||||
return text.ToString();
|
||||
}
|
||||
|
||||
public static ToolStripMenuItem MenuItem(MainForm host, string name) =>
|
||||
(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);
|
||||
|
||||
/// <summary>Calls a MainForm menu handler with no sender.</summary>
|
||||
public void Click(string handler) =>
|
||||
typeof(MainForm).GetMethod(handler, BindingFlags.Instance | BindingFlags.NonPublic)!
|
||||
.Invoke(Host, new object?[] { null, EventArgs.Empty });
|
||||
|
||||
public static void Mouse(PlateView view, string method, MouseButtons button, System.Drawing.Point location) =>
|
||||
typeof(PlateView).GetMethod(method, BindingFlags.Instance | BindingFlags.NonPublic)!
|
||||
.Invoke(view, new object[] { new MouseEventArgs(button, 1, location.X, location.Y, 0) });
|
||||
|
||||
public static void SetBackingField(object target, string property, object value)
|
||||
{
|
||||
for (var type = target.GetType(); type != null; type = type.BaseType)
|
||||
{
|
||||
var field = type.GetField($"<{property}>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
if (field == null)
|
||||
continue;
|
||||
field.SetValue(target, value);
|
||||
return;
|
||||
}
|
||||
throw new MissingFieldException(target.GetType().Name, property);
|
||||
}
|
||||
|
||||
private sealed class TestHost : MainForm
|
||||
{
|
||||
// No startup migrations/automatic new document, and no settings save at close.
|
||||
protected override void OnLoad(EventArgs e) { }
|
||||
protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { }
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,7 @@ namespace OpenNest.Actions
|
||||
}
|
||||
else
|
||||
{
|
||||
using var change = plateView.BeginChange("Fill Area");
|
||||
var parts = PlateFillService.FillItem(
|
||||
strategy,
|
||||
plateView.Plate,
|
||||
@@ -81,8 +82,11 @@ namespace OpenNest.Actions
|
||||
null,
|
||||
CancellationToken.None
|
||||
);
|
||||
if (parts.Count > 0)
|
||||
change.MarkChanged();
|
||||
plateView.Plate.Parts.AddRange(parts);
|
||||
plateView.Invalidate();
|
||||
change.Complete();
|
||||
}
|
||||
|
||||
Update();
|
||||
|
||||
@@ -889,8 +889,14 @@ namespace OpenNest.Controls
|
||||
|
||||
public void ClearPreviewParts() => previewManager.ClearPreviewParts();
|
||||
|
||||
public void AcceptPreviewParts(List<Part> parts) =>
|
||||
public void AcceptPreviewParts(List<Part> parts)
|
||||
{
|
||||
using var change = BeginChange("Fill");
|
||||
if (parts?.Count > 0)
|
||||
change.MarkChanged();
|
||||
previewManager.AcceptPreviewParts(parts);
|
||||
change.Complete();
|
||||
}
|
||||
|
||||
// UI-thread state: closing the progress window only requests cancellation.
|
||||
public bool IsFillInProgress { get; private set; }
|
||||
@@ -953,11 +959,14 @@ namespace OpenNest.Controls
|
||||
|
||||
if (parts.Count > 0 && (!cts.IsCancellationRequested || progressForm.Accepted))
|
||||
{
|
||||
// Recorded at the commit: a stopped fill that keeps nothing records nothing.
|
||||
using var change = BeginChange("Fill");
|
||||
SetActiveParts(parts);
|
||||
AcceptPreviewParts(parts);
|
||||
|
||||
if (Plate.CutOffs.Count > 0)
|
||||
Plate.RegenerateCutOffs(cutOffSettings);
|
||||
change.Complete();
|
||||
|
||||
sw.Stop();
|
||||
Status = $"Fill: {parts.Count} parts in {sw.ElapsedMilliseconds} ms";
|
||||
|
||||
@@ -116,19 +116,26 @@ namespace OpenNest.Forms.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
var applied = NestPipelineCommit.ApplyToEmptyPlates(result, target.PlateManager,
|
||||
allowInvalid, cts.Token);
|
||||
AssignLedgerStock(result, applied);
|
||||
if (applied.Count > 0)
|
||||
target.PlateManager.LoadAt(target.Nest.Plates.IndexOf(applied[0]));
|
||||
if (plateOptions?.Count > 0)
|
||||
IReadOnlyList<Plate> applied;
|
||||
// Recorded from the commit only: a stopped or discarded run records nothing.
|
||||
using (var change = target.BeginChange(Caption))
|
||||
{
|
||||
// Ledger rows and quantities are request-local inventory; the nest keeps
|
||||
// only the hand-typed offers.
|
||||
if (savedOptions?.Count > 0)
|
||||
target.Nest.PlateOptions = savedOptions;
|
||||
target.Nest.SalvageRate = salvageRate;
|
||||
target.Nest.MinimumRemnantDimension = minRemnantSize;
|
||||
change.MarkChanged();
|
||||
applied = NestPipelineCommit.ApplyToEmptyPlates(result, target.PlateManager,
|
||||
allowInvalid, cts.Token);
|
||||
AssignLedgerStock(result, applied);
|
||||
if (applied.Count > 0)
|
||||
target.PlateManager.LoadAt(target.Nest.Plates.IndexOf(applied[0]));
|
||||
if (plateOptions?.Count > 0)
|
||||
{
|
||||
// Ledger rows and quantities are request-local inventory; the nest keeps
|
||||
// only the hand-typed offers.
|
||||
if (savedOptions?.Count > 0)
|
||||
target.Nest.PlateOptions = savedOptions;
|
||||
target.Nest.SalvageRate = salvageRate;
|
||||
target.Nest.MinimumRemnantDimension = minRemnantSize;
|
||||
}
|
||||
change.Complete();
|
||||
}
|
||||
target.PlateView.Invalidate();
|
||||
if (allowInvalid)
|
||||
|
||||
@@ -998,7 +998,21 @@ namespace OpenNest.Forms
|
||||
|
||||
public void ClearNest()
|
||||
{
|
||||
using var change = BeginChange("Clear Nest");
|
||||
if (PlateManager.CanClearAll)
|
||||
change.MarkChanged();
|
||||
PlateManager.ClearAll();
|
||||
change.Complete();
|
||||
}
|
||||
|
||||
public void RemoveEmptyPlates()
|
||||
{
|
||||
using var change = BeginChange("Remove Empty Plates");
|
||||
// The trailing empty plate comes back as the new-plate sentinel.
|
||||
if (Nest.Plates.Count >= 2 && Nest.Plates.SkipLast(1).Any(plate => plate.Parts.Count == 0))
|
||||
change.MarkChanged();
|
||||
Nest.Plates.RemoveEmptyPlates();
|
||||
change.Complete();
|
||||
}
|
||||
|
||||
public void AutoSequenceCurrentPlate()
|
||||
|
||||
@@ -177,7 +177,7 @@ namespace OpenNest.Forms
|
||||
view.Invalidate();
|
||||
}
|
||||
|
||||
private void RemoveEmptyPlates_Click(object sender, EventArgs e) => WithActive(f => f.Nest.Plates.RemoveEmptyPlates());
|
||||
private void RemoveEmptyPlates_Click(object sender, EventArgs e) => WithActive(f => f.RemoveEmptyPlates());
|
||||
|
||||
private void ClearNest_Click(object sender, EventArgs e)
|
||||
{
|
||||
@@ -197,7 +197,7 @@ namespace OpenNest.Forms
|
||||
|
||||
var result = MessageBox.Show(
|
||||
this,
|
||||
"Remove all plates and parts from this nest?\nOne empty plate will remain. This cannot be undone.",
|
||||
"Remove all plates and parts from this nest?\nOne empty plate will remain.",
|
||||
"Clear Nest",
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Warning,
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace OpenNest.Forms
|
||||
|
||||
// A merged draft's sheets are already gone; whatever the new nest started with goes too.
|
||||
if (tab.PlateManager.CanClearAll)
|
||||
tab.PlateManager.ClearAll();
|
||||
tab.ClearNest();
|
||||
nest.UpdateDrawingQuantities();
|
||||
var request = NestRenest.CreateRequest(nest, EngineSelection.EngineName, AutoNestForm.DefaultMinRemnantSize);
|
||||
if (request == null)
|
||||
@@ -70,8 +70,14 @@ namespace OpenNest.Forms
|
||||
}
|
||||
cts.Token.ThrowIfCancellationRequested();
|
||||
|
||||
var kept = NestRenest.Keep(result,
|
||||
r => NestPipelineCommit.ApplyToEmptyPlates(r, tab.PlateManager, token: cts.Token));
|
||||
var kept = NestRenest.Keep(result, r =>
|
||||
{
|
||||
using var change = tab.BeginChange("Auto Nest");
|
||||
change.MarkChanged();
|
||||
var applied = NestPipelineCommit.ApplyToEmptyPlates(r, tab.PlateManager, token: cts.Token);
|
||||
change.Complete();
|
||||
return applied;
|
||||
});
|
||||
if (kept.Nested)
|
||||
tab.PlateManager.LoadFirst();
|
||||
tab.PlateView.ZoomToFit();
|
||||
|
||||
@@ -112,32 +112,40 @@ namespace OpenNest.Forms
|
||||
if (form.ShowDialog(this) != DialogResult.OK || form.Result == null)
|
||||
return;
|
||||
|
||||
var result = form.Result;
|
||||
|
||||
if (result.Target == PatternTileTarget.CurrentPlate)
|
||||
{
|
||||
activeForm.PlateView.Plate.Parts.Clear();
|
||||
|
||||
foreach (var part in result.Parts)
|
||||
activeForm.PlateView.Plate.Parts.Add(part);
|
||||
|
||||
activeForm.PlateView.ZoomToFit();
|
||||
}
|
||||
else
|
||||
{
|
||||
var plate = activeForm.Nest.CreatePlate();
|
||||
plate.Size = result.PlateSize;
|
||||
|
||||
foreach (var part in result.Parts)
|
||||
plate.Parts.Add(part);
|
||||
|
||||
activeForm.PlateManager.LoadLast();
|
||||
}
|
||||
|
||||
activeForm.Nest.UpdateDrawingQuantities();
|
||||
ApplyPatternTile(activeForm, form.Result);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ApplyPatternTile(EditNestForm editForm, PatternTileResult result)
|
||||
{
|
||||
using var change = editForm.BeginChange("Pattern Tile");
|
||||
change.MarkChanged();
|
||||
if (result.Target == PatternTileTarget.CurrentPlate)
|
||||
{
|
||||
editForm.PlateView.Plate.Parts.Clear();
|
||||
|
||||
foreach (var part in result.Parts)
|
||||
editForm.PlateView.Plate.Parts.Add(part);
|
||||
|
||||
editForm.PlateView.ZoomToFit();
|
||||
}
|
||||
else
|
||||
{
|
||||
// The empty new-plate sentinel takes the pattern; a plate created beside it
|
||||
// would be dropped as a second trailing empty plate before the parts arrive.
|
||||
var plate = editForm.PlateManager.GetOrCreateEmpty();
|
||||
plate.Size = result.PlateSize;
|
||||
|
||||
foreach (var part in result.Parts)
|
||||
plate.Parts.Add(part);
|
||||
|
||||
editForm.PlateManager.LoadAt(editForm.Nest.Plates.IndexOf(plate));
|
||||
}
|
||||
|
||||
editForm.Nest.UpdateDrawingQuantities();
|
||||
change.Complete();
|
||||
}
|
||||
|
||||
private void SetOffsetIncrement_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (activeForm == null)
|
||||
@@ -246,10 +254,14 @@ namespace OpenNest.Forms
|
||||
|
||||
var offset = view.Plate.OffsetToCenterPartsInWorkArea();
|
||||
|
||||
using var change = view.BeginChange("Center Parts");
|
||||
if (offset.X != 0 || offset.Y != 0)
|
||||
change.MarkChanged();
|
||||
foreach (var part in view.Parts)
|
||||
part.Offset(offset);
|
||||
|
||||
view.Invalidate();
|
||||
change.Complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user