Files
OpenNest/OpenNest.Desktop/DrawingListRow.cs
T
ajandClaude Opus 5.5 8d1204e917 feat(desktop): share the Drawings tab rows, drawing commands and properties
Moves the Drawings tab's row content (quantity, size, area, highlight and
quantity bar, the hidden-list note), Delete Drawing, Remove Unused Drawings
and the Drawing Properties dialog's values and color rules into
OpenNest.Desktop so the Avalonia app can share them. The WinForms list,
nest window and Edit Drawing form delegate to them unchanged.

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

84 lines
3.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
namespace OpenNest.Desktop;
/// <summary>The bar down a Drawings tab row's left edge, for a drawing with a required quantity.</summary>
public enum DrawingQuantityBar
{
/// <summary>No quantity is required (or quantities are hidden): no bar.</summary>
None,
/// <summary>All of the required quantity is nested: a green bar.</summary>
Complete,
/// <summary>Some of the required quantity is still to nest: an orange bar.</summary>
Short,
}
/// <summary>
/// One row of the Drawings tab list, as the WinForms list draws it beside the drawing's
/// thumbnail: its name, "[on this plate] nested of required nested", its size and its area in
/// square units. A drawing whose nested parts left none remaining is highlighted, and a drawing
/// with a required quantity carries a bar saying whether all of it is nested.
/// </summary>
public sealed record DrawingListRow(
Drawing Drawing,
string Name,
string Quantity,
string Size,
string Area,
bool IsHighlighted,
DrawingQuantityBar Bar)
{
/// <summary>The note an emptied list shows when Hide Fully Nested Drawings hid every drawing.</summary>
public const string AllHiddenText = "All drawings are fully nested and hidden.\n\nClick here to show them.";
/// <summary>
/// The row of <paramref name="drawing"/>. Its count on <paramref name="plate"/> (the plate
/// shown beside the list; null omits it) prefixes the quantity when there is one. With
/// <paramref name="hideQuantity"/> the row has no quantity, highlight or bar.
/// </summary>
public static DrawingListRow For(Drawing drawing, Plate plate, Units units, bool hideQuantity = false)
{
ArgumentNullException.ThrowIfNull(drawing);
var quantity = drawing.Quantity;
string quantityText = null;
var bar = DrawingQuantityBar.None;
if (!hideQuantity)
{
quantityText = $"{quantity.Nested} of {quantity.Required} nested";
var onPlate = plate?.Parts.Count(part => part.BaseDrawing == drawing) ?? 0;
if (onPlate > 0)
quantityText = $"[{onPlate}] {quantityText}";
if (quantity.Required > 0)
bar = quantity.Nested >= quantity.Required ? DrawingQuantityBar.Complete : DrawingQuantityBar.Short;
}
return new DrawingListRow(
drawing,
drawing.Name,
quantityText,
drawing.Program.BoundingBox().Size.ToString(4),
$"{System.Math.Round(drawing.Area, 4)} sq/{UnitsHelper.GetShortString(units)}",
!hideQuantity && quantity.Nested > 0 && quantity.Remaining == 0,
bar);
}
/// <summary>The rows of <paramref name="drawings"/>, in their order.</summary>
public static IReadOnlyList<DrawingListRow> For(IEnumerable<Drawing> drawings, Plate plate, Units units)
{
ArgumentNullException.ThrowIfNull(drawings);
return drawings.Select(drawing => For(drawing, plate, units)).ToList();
}
/// <summary>
/// The note the list shows in place of rows: <see cref="AllHiddenText"/> when Hide Fully
/// Nested Drawings (<paramref name="hideFullyNested"/>) emptied a list of a nest that has
/// drawings, so they don't look lost; otherwise null. The filter stays the user's choice.
/// </summary>
public static string EmptyText(bool hideFullyNested, int drawingCount) =>
hideFullyNested && drawingCount > 0 ? AllHiddenText : null;
}