Files
OpenNest/OpenNest.Core/PlateDisplayNumbering.cs
T
ajandClaude Opus 5.5 872cd8e4b8 fix(ui): show the plate size on the new-plate header
The empty new-plate header read only "New plate (empty)", so the sheet
size of the plate about to be nested was hidden until parts were added.
FormatHeader now appends the size (and quantity above one) there too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 16:48:52 -05:00

73 lines
3.2 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.Collections.Generic;
namespace OpenNest
{
/// <summary>
/// Display-only plate numbering for labels. The editor keeps one trailing empty plate as the
/// "new plate" workspace (PlateManager.EnsureSentinel), and that sentinel is excluded from the
/// shown total so a one-plate nest reads "Plate 1 of 1". Navigation, storage indexes, exported
/// names and batch selection keep using the real collection positions; an interior empty plate
/// keeps its slot and its number.
/// </summary>
public static class PlateDisplayNumbering
{
/// <summary>
/// The number shown for the plate at <paramref name="storageIndex"/>: real collection
/// positions count as 1-based plate numbers. Returns null for the trailing "new plate"
/// sentinel and for indexes outside the collection.
/// </summary>
public static int? DisplayedPlateNumber(IList<Plate> plates, int storageIndex)
{
if (plates == null || storageIndex < 0 || storageIndex >= plates.Count)
return null;
if (IsTrailingSentinel(plates, storageIndex))
return null;
return storageIndex + 1;
}
/// <summary>
/// The number shown in an "of M" total: the plates minus only a trailing empty sentinel.
/// An all-empty collection shows nothing (the caller says "No plates").
/// </summary>
public static int DisplayedPlateCount(IList<Plate> plates)
{
if (plates == null || plates.Count == 0)
return 0;
var last = plates[plates.Count - 1];
return plates.Count - (last != null && last.Parts.Count == 0 ? 1 : 0);
}
/// <summary>True when <paramref name="storageIndex"/> is the trailing empty new-plate sentinel.</summary>
public static bool IsTrailingSentinel(IList<Plate> plates, int storageIndex)
{
if (plates == null || plates.Count == 0)
return false;
if (storageIndex != plates.Count - 1)
return false;
var plate = plates[storageIndex];
return plate != null && plate.Parts.Count == 0;
}
/// <summary>
/// Header text for the plate at <paramref name="storageIndex"/>, including the trailing
/// new-plate sentinel. The plate size follows when given; a quantity above one is
/// appended as "×N"; a single sheet shows no quantity.
/// </summary>
public static string FormatHeader(IList<Plate> plates, int storageIndex, string plateSizeText, int quantity = 1)
{
var displayed = DisplayedPlateNumber(plates, storageIndex);
if (displayed == null && !IsTrailingSentinel(plates, storageIndex))
return "No plates";
var text = displayed == null
? "New plate (empty)"
: string.Format("Plate {0} of {1}", displayed.Value, DisplayedPlateCount(plates));
if (!string.IsNullOrEmpty(plateSizeText))
text += " | " + plateSizeText;
if (quantity > 1)
text += " | ×" + quantity;
return text;
}
}
}