diff --git a/OpenNest.WinForms.Tests/Controls/ActionCloneTests.cs b/OpenNest.WinForms.Tests/Controls/ActionCloneTests.cs index 48082853..9c91a9de 100644 --- a/OpenNest.WinForms.Tests/Controls/ActionCloneTests.cs +++ b/OpenNest.WinForms.Tests/Controls/ActionCloneTests.cs @@ -114,6 +114,32 @@ public class ActionCloneTests Assert.Equal(0, copy.Bottom, 6); }, TimeSpan.FromMinutes(1), "The STA test did not complete."); + [Theory] + [InlineData(Keys.Shift)] + [InlineData(Keys.Control)] + public void RepeatedModifiedClicksWithoutMovingStackNoCopies(Keys modifiers) => StaTestThread.Run(() => + { + var plate = new Plate(48, 96) { PartSpacing = 0 }; + using var view = new PlateView { Plate = plate, Size = new System.Drawing.Size(600, 600) }; + view.ZoomToFit(); + view.SetAction(typeof(ActionClone), Square("new")); + var action = Assert.IsType(view.Actions.CurrentAction); + action.PlacementOrder = OpenNest.Engine.Fill.SettleOrder.VerticalFirst; + var preview = Assert.Single(view.SelectedParts); + preview.BasePart.Location = new Vector(1, 20); + + action.Apply(modifiers); + Assert.Equal(new Vector(1, 20), preview.BasePart.BoundingBox.Location); + action.Apply(modifiers); + action.Apply(modifiers); + + Assert.Equal(3, plate.Parts.Count); + var bottoms = plate.Parts.Select(p => p.BoundingBox.Bottom).OrderBy(y => y).ToList(); + Assert.Equal(0, bottoms[0], 6); + Assert.InRange(bottoms[1], 4, 4.01); + Assert.InRange(bottoms[2], 8, 8.02); + }, TimeSpan.FromMinutes(1), "The STA test did not complete."); + [Fact] public void ADialogsFakeMouseMoveLeavesNudgedPreviewsInPlace() => StaTestThread.Run(() => { diff --git a/OpenNest/Actions/ActionClone.cs b/OpenNest/Actions/ActionClone.cs index de7eb48b..03c54af3 100644 --- a/OpenNest/Actions/ActionClone.cs +++ b/OpenNest/Actions/ActionClone.cs @@ -209,7 +209,9 @@ namespace OpenNest.Actions change.MarkChanged(); var shift = (modifiers & Keys.Shift) == Keys.Shift; var boxesOnly = !shift && (modifiers & Keys.Control) == Keys.Control; - if (shift || boxesOnly) + var settles = shift || boxesOnly; + var home = parts.GetBoundingBox().Location; + if (settles) { var movingParts = parts.Select(p => p.BasePart).ToList(); @@ -251,6 +253,15 @@ namespace OpenNest.Actions foreach (var (members, kerf) in commonLines) plateView.Plate.JoinCommonLine(members.Select(i => placed[i]), kerf); + // Put the previews back where they were clicked: left on the settled copy, the + // next click without moving the mouse would settle from inside it and stack on it. + if (settles) + { + var back = home - parts.GetBoundingBox().Location; + parts.ForEach(p => p.Offset(back)); + plateView.Invalidate(); + } + if (plateView.Plate.CutOffs.Count > 0) plateView.Plate.RegenerateCutOffs(plateView.CutOffSettings); change.Complete();