Files
OpenNest/OpenNest.Desktop/PlateListRow.cs
T
ajandClaude Opus 5.5 4e831ab6f8 feat(desktop): share the plate list and plate commands
PlateCommands ports the WinForms nest window's plate commands, each one
undo step under its WinForms label: Remove Plate, Remove Empty Plates,
Duplicate Plate (the copy current, with its own cutting parameters),
Move Plate and its Alt+Up/Alt+Down target, Rotate Plate (90 degrees
either way or 180), Resize Plate to its parts by the auto-size factor,
Set Nest Default Plate, and Edit Plate's commit, where an empty plate's
new settings become the nest's defaults and the nested quantities are
counted again. NewNestDefaults is what Set as Default saves for new
nests: the plate, the saved common-line usage and the nest's machine.

PlateEditValues is what Edit Plate edits (quantity, size, part and edge
spacing, quadrant, outline), when Done applies and how it writes the
plate; SheetOutlineImport reads an outline from a CAD file, and SvgScale
holds the scale prompt for an SVG that does not state its size.
PlateListRow is the Plates list's row text and its drag drop slots;
QuadrantPick the quadrant picker's hit test and cells.

The WinForms nest window, plate list, Edit Plate dialog, quadrant
picker, SVG scale prompt and Save Current as Defaults delegate to them
with unchanged behavior.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 20:11:38 -05:00

57 lines
2.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Linq;
namespace OpenNest.Desktop;
/// <summary>
/// One row of the Plates tab list, as the WinForms list draws it: the plate's number ("New
/// plate" for the trailing empty plate), its size, part count ("Empty" for the new plate),
/// utilization once it holds parts, and how many sheets are cut from it when more than one.
/// </summary>
public sealed record PlateListRow(string Name, string Size, string Parts, string Utilization, string Quantity)
{
/// <summary>The row of the plate at <paramref name="index"/> among <paramref name="plates"/>.</summary>
public static PlateListRow For(IList<Plate> plates, int index)
{
ArgumentNullException.ThrowIfNull(plates);
var plate = plates[index];
var isNewPlate = IsNewPlate(plates, index);
var partCount = plate.Parts.Count(part => !part.BaseDrawing.IsCutOff);
return new PlateListRow(
isNewPlate ? "New plate" : $"Plate {index + 1}",
plate.Size.ToString(4),
isNewPlate ? "Empty" : $"{partCount} {(partCount == 1 ? "part" : "parts")}",
partCount > 0 ? $"{plate.Utilization():P0} utilized" : "",
plate.Quantity > 1 ? $"×{plate.Quantity}" : "");
}
/// <summary>Every plate's row, in order.</summary>
public static IReadOnlyList<PlateListRow> For(IList<Plate> plates)
{
ArgumentNullException.ThrowIfNull(plates);
return Enumerable.Range(0, plates.Count).Select(i => For(plates, i)).ToList();
}
/// <summary>The trailing empty plate the list shows as "New plate".</summary>
public static bool IsNewPlate(IList<Plate> plates, int index) =>
index == plates.Count - 1 && plates[index].Parts.Count == 0;
/// <summary>
/// The gap a plate row dragged in the list is dropped into, 0 (before the first plate)
/// through <paramref name="movableCount"/> (after the last movable plate): before the row
/// under the pointer when in its upper half, after it otherwise. The new-plate row and below
/// (<paramref name="rowIndex"/> -1) drop after the last plate.
/// </summary>
public static int DropSlot(int rowIndex, bool upperHalf, int movableCount)
{
if (rowIndex < 0)
return movableCount;
var slot = upperHalf ? rowIndex : rowIndex + 1;
return System.Math.Min(slot, movableCount);
}
/// <summary>The index a plate dragged from <paramref name="from"/> lands at when dropped in <paramref name="slot"/>.</summary>
public static int DropTarget(int from, int slot) => slot > from ? slot - 1 : slot;
}