mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-19 05:57:39 -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
@@ -463,6 +463,81 @@ namespace OpenNest
|
||||
/// places relative to the cut-offs either way. Where only a first place is known the
|
||||
/// count is a guess, so a cut-off that splits the sheet goes last, as sequencing puts it.
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// A new, unowned plate with this plate's sheet and layout: size, outline, spacing,
|
||||
/// quadrant, grain, clamps, support bed, parts (programs and lead-in state included),
|
||||
/// common-line groups and cut-off definitions, regenerated in their places in the
|
||||
/// sequence. It is one sheet (<see cref="Quantity"/> 1) with no stock item codes, since
|
||||
/// those name particular physical sheets. Adding the parts counts them as nested at once,
|
||||
/// as every plate does, so callers add the copy to a nest.
|
||||
/// <see cref="CuttingParameters"/> is shared; callers that need an independent copy
|
||||
/// replace it.
|
||||
/// </summary>
|
||||
public Plate CopyLayout()
|
||||
{
|
||||
var copy = new Plate(Size)
|
||||
{
|
||||
Quantity = 1,
|
||||
Quadrant = Quadrant,
|
||||
PartSpacing = PartSpacing,
|
||||
EdgeSpacing = EdgeSpacing,
|
||||
GrainAngle = GrainAngle,
|
||||
CuttingParameters = CuttingParameters,
|
||||
SupportBed = SupportBed,
|
||||
CutCommonLinesTwice = CutCommonLinesTwice,
|
||||
};
|
||||
copy.Outline = Outline;
|
||||
|
||||
if (ClampRail != null)
|
||||
copy.SetClampRail(ClampRail, RemovedClamps);
|
||||
else
|
||||
foreach (var zone in ClampZones)
|
||||
copy.ClampZones.Add(new ClampZone(zone.Id, zone.Bounds));
|
||||
|
||||
var copies = new Dictionary<Part, Part>();
|
||||
foreach (var part in Parts.Where(p => !p.BaseDrawing.IsCutOff))
|
||||
{
|
||||
var clone = (Part)part.Clone();
|
||||
copy.Parts.Add(clone);
|
||||
copies[part] = clone;
|
||||
}
|
||||
|
||||
foreach (var group in CommonLines)
|
||||
{
|
||||
var members = group.Members.Where(copies.ContainsKey).Select(member => copies[member]).ToList();
|
||||
if (members.Count >= 2)
|
||||
copy.CommonLines.Add(new CommonLineGroup(members, group.Kerf));
|
||||
}
|
||||
|
||||
if (CutOffs.Count == 0)
|
||||
return copy;
|
||||
|
||||
// Cut-off segments keep their places among the parts, as a save and reload does.
|
||||
var places = new Dictionary<CutOff, IReadOnlyList<int>>();
|
||||
foreach (var cutoff in CutOffs)
|
||||
{
|
||||
var duplicate = new CutOff(cutoff.Position, cutoff.Axis)
|
||||
{
|
||||
StartLimit = cutoff.StartLimit,
|
||||
EndLimit = cutoff.EndLimit,
|
||||
HeadLockOvercut = cutoff.HeadLockOvercut,
|
||||
FarEdgeFirst = cutoff.FarEdgeFirst,
|
||||
Gaps = cutoff.Gaps,
|
||||
};
|
||||
copy.CutOffs.Add(duplicate);
|
||||
|
||||
var segments = CutOffSegments.Of(this, cutoff)
|
||||
.Select(segment => Parts.IndexOf(segment.Part))
|
||||
.Where(index => index >= 0)
|
||||
.ToArray();
|
||||
if (segments.Length > 0)
|
||||
places[duplicate] = segments;
|
||||
}
|
||||
|
||||
copy.RegenerateCutOffs(CutOffSettings ?? new CutOffSettings(), places, null);
|
||||
return copy;
|
||||
}
|
||||
|
||||
public void RegenerateCutOffs(CutOffSettings settings, IReadOnlyDictionary<CutOff, IReadOnlyList<int>> places,
|
||||
IReadOnlyDictionary<CutOff, int> firstPlaces) =>
|
||||
RegenerateCutOffs(settings, (cutoff, extents) =>
|
||||
|
||||
@@ -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