feat: unify ActionAddPart into ActionClone and add group fill support

Merge ActionAddPart into ActionClone by adding a Drawing constructor,
eliminating the redundant class. ActionClone now handles both adding
new parts from a drawing and cloning selected part groups. Added
Ctrl+F fill support for groups using FillLinear pattern tiling, and
adopted quadrant-aware push directions from ActionAddPart. Refactored
FillLinear to extract shared helpers and add a Fill(Pattern) overload
for tiling arbitrary part groups across the work area.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 09:56:48 -05:00
parent 5807255931
commit 40b40ca4ba
7 changed files with 237 additions and 297 deletions
+40 -2
View File
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using OpenNest.Controls;
using OpenNest.Geometry;
@@ -13,6 +14,11 @@ namespace OpenNest.Actions
private double lastScale;
public ActionClone(PlateView plateView, Drawing drawing)
: this(plateView, new List<Part> { new Part(drawing) })
{
}
public ActionClone(PlateView plateView, List<Part> partsToClone)
: base(plateView)
{
@@ -53,6 +59,11 @@ namespace OpenNest.Actions
case Keys.Enter:
Apply();
break;
case Keys.F:
if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
Fill();
break;
}
}
@@ -111,11 +122,38 @@ namespace OpenNest.Actions
{
if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
{
plateView.PushSelected(PushDirection.Left);
plateView.PushSelected(PushDirection.Down);
switch (plateView.Plate.Quadrant)
{
case 1:
plateView.PushSelected(PushDirection.Left);
plateView.PushSelected(PushDirection.Down);
break;
case 2:
plateView.PushSelected(PushDirection.Right);
plateView.PushSelected(PushDirection.Down);
break;
case 3:
plateView.PushSelected(PushDirection.Right);
plateView.PushSelected(PushDirection.Up);
break;
case 4:
plateView.PushSelected(PushDirection.Left);
plateView.PushSelected(PushDirection.Up);
break;
}
}
parts.ForEach(p => plateView.Plate.Parts.Add(p.BasePart.Clone() as Part));
}
private void Fill()
{
var engine = new NestEngine(plateView.Plate);
var groupParts = parts.Select(p => p.BasePart).ToList();
engine.Fill(groupParts);
}
}
}