mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-21 22:31:49 -04:00
feat(desktop): add automatic cut-offs, existing-work banner and clear button to the cutting planner
This commit is contained in:
1 parent
81cccfc610
commit
9f2ece37ed
3 files changed
+303
-4
No files matched your search
@@ -436,6 +436,112 @@ public class CuttingInspectionPanelTests
|
||||
panel.RequestClose();
|
||||
});
|
||||
|
||||
[Fact]
|
||||
public void AutomaticCutOffsAreStagedForThePlanAndRemovedOnCancelOrUntick() => RunSta(() =>
|
||||
{
|
||||
using var editor = Editor();
|
||||
editor.Show();
|
||||
editor.PlateManager.LoadAt(0);
|
||||
var plate = editor.PlateView.Plate;
|
||||
var original = plate.Parts.ToArray();
|
||||
editor.OpenCuttingInspection();
|
||||
var panel = editor.CuttingInspection!;
|
||||
PumpUntil(() => panel.Proposal != null && !panel.IsPlanning);
|
||||
Assert.Empty(plate.CutOffs);
|
||||
|
||||
Field<CheckBox>(panel, "autoCutOffsCheckBox").Checked = true;
|
||||
PumpUntil(() => panel.Proposal != null && !panel.IsPlanning);
|
||||
|
||||
Assert.NotNull(panel.StagedCutOffs);
|
||||
Assert.NotEmpty(plate.CutOffs);
|
||||
Assert.Equal(plate.CutOffs.Count, plate.Parts.Count(p => p.BaseDrawing.IsCutOff));
|
||||
Assert.Equal(plate.CutOffs.Count, panel.Proposal.Plates[0].Result.ProposedOrder.Count(p => p.IsCutOff));
|
||||
Assert.False(Field<FlowLayoutPanel>(panel, "existingWorkBanner").Visible); // Staged lines are not "existing".
|
||||
|
||||
Field<CheckBox>(panel, "autoCutOffsCheckBox").Checked = false;
|
||||
PumpUntil(() => panel.Proposal != null && !panel.IsPlanning);
|
||||
Assert.Null(panel.StagedCutOffs);
|
||||
Assert.Empty(plate.CutOffs);
|
||||
Assert.Equal(original, plate.Parts);
|
||||
|
||||
Field<CheckBox>(panel, "autoCutOffsCheckBox").Checked = true;
|
||||
PumpUntil(() => panel.Proposal != null && !panel.IsPlanning);
|
||||
Assert.NotEmpty(plate.CutOffs);
|
||||
panel.RequestClose();
|
||||
Assert.Null(editor.CuttingInspection);
|
||||
Assert.Empty(plate.CutOffs);
|
||||
Assert.Equal(original, plate.Parts);
|
||||
Assert.All(plate.Parts, part => Assert.False(part.HasManualLeadIns));
|
||||
});
|
||||
|
||||
[Fact]
|
||||
public void ApplyKeepsTheStagedAutomaticCutOffsInThePlannedOrder() => RunSta(() =>
|
||||
{
|
||||
using var editor = Editor();
|
||||
editor.Show();
|
||||
editor.PlateManager.LoadAt(0);
|
||||
var plate = editor.PlateView.Plate;
|
||||
editor.OpenCuttingInspection();
|
||||
var panel = editor.CuttingInspection!;
|
||||
PumpUntil(() => panel.Proposal != null && !panel.IsPlanning);
|
||||
Field<CheckBox>(panel, "autoCutOffsCheckBox").Checked = true;
|
||||
PumpUntil(() => panel.Proposal != null && !panel.IsPlanning);
|
||||
var staged = panel.StagedCutOffs!.Definitions.ToArray();
|
||||
var planned = panel.Proposal.Plates[0].Result.ProposedOrder.Select(p => p.SourcePart).ToArray();
|
||||
|
||||
Field<Button>(panel, "applyButton").PerformClick();
|
||||
|
||||
Assert.Equal(OpenNest.CNC.CuttingPlanning.CuttingCommitStatus.Applied, panel.CommitResult!.Status);
|
||||
Assert.Null(editor.CuttingInspection);
|
||||
Assert.Equal(staged, plate.CutOffs);
|
||||
Assert.Equal(planned, plate.Parts);
|
||||
Assert.All(plate.Parts.Where(p => !p.BaseDrawing.IsCutOff), part => Assert.True(part.HasManualLeadIns));
|
||||
});
|
||||
|
||||
[Fact]
|
||||
public void ExistingLeadInsShowTheRedBannerAndClearRecalculatesFromScratch() => RunSta(() =>
|
||||
{
|
||||
using var editor = Editor();
|
||||
editor.Show();
|
||||
editor.PlateManager.LoadAt(0);
|
||||
var plate = editor.PlateView.Plate;
|
||||
editor.OpenCuttingInspection();
|
||||
var first = editor.CuttingInspection!;
|
||||
PumpUntil(() => first.Proposal != null && !first.IsPlanning);
|
||||
Assert.False(Field<FlowLayoutPanel>(first, "existingWorkBanner").Visible);
|
||||
Field<Button>(first, "applyButton").PerformClick();
|
||||
Assert.All(plate.Parts, part => Assert.True(part.HasManualLeadIns));
|
||||
plate.CutOffs.Add(new CutOff(new Vector(60, 0), CutOffAxis.Vertical));
|
||||
plate.RegenerateCutOffs(editor.PlateView.CutOffSettings);
|
||||
var real = plate.Parts.Where(p => !p.BaseDrawing.IsCutOff).ToArray();
|
||||
|
||||
editor.OpenCuttingInspection();
|
||||
var panel = editor.CuttingInspection!;
|
||||
PumpUntil(() => panel.Proposal != null && !panel.IsPlanning);
|
||||
var banner = Field<FlowLayoutPanel>(panel, "existingWorkBanner");
|
||||
Assert.True(banner.Visible);
|
||||
Assert.Contains("ALREADY APPLIED: lead-ins on 2 parts and 1 cut-off on plate 1.",
|
||||
Field<Label>(panel, "existingWorkLabel").Text);
|
||||
|
||||
string? asked = null;
|
||||
panel.ConfirmClearExisting = message => { asked = message; return false; };
|
||||
Field<Button>(panel, "clearExistingButton").PerformClick();
|
||||
Assert.Contains("cannot be undone", asked);
|
||||
Assert.Single(plate.CutOffs);
|
||||
Assert.All(real, part => Assert.True(part.HasManualLeadIns));
|
||||
|
||||
panel.ConfirmClearExisting = _ => true;
|
||||
Field<Button>(panel, "clearExistingButton").PerformClick();
|
||||
PumpUntil(() => panel.Proposal != null && !panel.IsPlanning);
|
||||
|
||||
Assert.Empty(plate.CutOffs);
|
||||
Assert.Equal(real, plate.Parts);
|
||||
Assert.All(real, part => Assert.False(part.HasManualLeadIns));
|
||||
Assert.False(banner.Visible);
|
||||
Assert.True(panel.Proposal.CanApply);
|
||||
panel.RequestClose();
|
||||
});
|
||||
|
||||
private sealed class MenuHost : MainForm
|
||||
{
|
||||
protected override void OnLoad(EventArgs e) { }
|
||||
|
||||
Reference in new issue
Block a user