mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-28 14:01:34 -05:00
feat(ui): duplicate a plate by Ctrl+dragging it or from its right-click menu
Copying a layout meant recreating the plate and copying its parts by hand. Ctrl+drag a row in the Plates list drops a copy at that slot; the row's right-click menu has Duplicate Plate, which inserts the copy after it. Plate.CopyLayout copies the sheet (size, outline, spacing, quadrant, grain, clamps, support bed), the parts with their programs and lead-in state, common-line groups and cut-off definitions, regenerated in their places in the sequence, as a save and reload would. The copy is one sheet with no stock item codes, since those name particular physical sheets. The desktop gives it its own cutting parameters and records it as one undo step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
872cd8e4b8
commit
a9fc9f0afb
7 files changed
+334
-7
No files matched your search
@@ -209,6 +209,47 @@ namespace OpenNest
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether <see cref="DuplicatePlate"/> can copy the plate at <paramref name="fromIndex"/>
|
||||
/// to <paramref name="toIndex"/>: any plate but the trailing empty sentinel, landing
|
||||
/// anywhere from the first place to just before the sentinel.
|
||||
/// </summary>
|
||||
public bool CanDuplicatePlate(int fromIndex, int toIndex) =>
|
||||
fromIndex >= 0 && fromIndex < MovableCount
|
||||
&& toIndex >= 0 && toIndex <= MovableCount
|
||||
&& HasLayout(nest.Plates[fromIndex]);
|
||||
|
||||
private static bool HasLayout(Plate plate) => plate.Parts.Count > 0 || plate.CutOffs.Count > 0;
|
||||
|
||||
/// <summary>
|
||||
/// Inserts a copy of the plate at <paramref name="fromIndex"/> (see
|
||||
/// <see cref="Plate.CopyLayout"/>) so it lands at <paramref name="toIndex"/>, and makes
|
||||
/// the copy the current plate. The trailing empty sentinel stays last.
|
||||
/// </summary>
|
||||
/// <returns>The copy, or null when <see cref="CanDuplicatePlate"/> is false.</returns>
|
||||
public Plate DuplicatePlate(int fromIndex, int toIndex)
|
||||
{
|
||||
if (!CanDuplicatePlate(fromIndex, toIndex))
|
||||
return null;
|
||||
|
||||
var copy = nest.Plates[fromIndex].CopyLayout();
|
||||
suppressNavigation = true;
|
||||
try
|
||||
{
|
||||
nest.Plates.Insert(toIndex, copy);
|
||||
}
|
||||
finally
|
||||
{
|
||||
suppressNavigation = false;
|
||||
}
|
||||
|
||||
EnsureSentinel();
|
||||
PlateListChanged?.Invoke(this, EventArgs.Empty);
|
||||
CurrentIndex = nest.Plates.IndexOf(copy);
|
||||
FireCurrentPlateChanged();
|
||||
return copy;
|
||||
}
|
||||
|
||||
public void BeginBatch()
|
||||
{
|
||||
batching = true;
|
||||
|
||||
Reference in new issue
Block a user