Files
OpenNest/OpenNest.Desktop/NestDefaultsChoices.cs
T
ajandClaude Opus 5.5 6f1d21173d feat(desktop): share nest info, Clear Nest and the nest defaults choices
NestInfoValues is what Nest > Edit edits (name, dates, thickness,
material and grade, customer, status, author, units, notes and the plate
defaults): read from a nest, when Done is enabled, how it writes the
nest, which Made By to remember, the material and grade lists and the
fields undo puts back. NestCommands holds its commit as one "Nest Info"
step (a changed material or thickness takes the machine's spacing and an
untouched trailing sheet follows), the defaults "Use these defaults for
new nests" saves, and Clear Nest as one "Clear Nest" step with its
question and busy message. NestDefaultsChoices holds the Tools > Nest
Defaults dialog's machine order, common-line list and box ranges.

The WinForms Edit Nest dialog, nest window and Nest Defaults dialog
delegate to them with unchanged behavior.

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

80 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using OpenNest.CommonLines;
using OpenNest.Data;
namespace OpenNest.Desktop;
/// <summary>
/// The Tools &gt; Nest Defaults dialog's lists and limits, toolkit-neutral: the machines by
/// name with the one new nests are assigned selected, the common-line choices, the boxes'
/// ranges and how a saved value is shown in them.
/// </summary>
public static class NestDefaultsChoices
{
/// <summary>The smallest plate width or length the boxes take.</summary>
public const double SizeMinimum = 0.001;
/// <summary>The smallest spacing the boxes take.</summary>
public const double SpacingMinimum = 0;
/// <summary>The largest size or spacing the boxes take.</summary>
public const double Maximum = 1000000;
/// <summary>Decimals the boxes show.</summary>
public const int Decimals = 4;
public const string QuadrantHint = "Click a quadrant to select it.";
public const string CommonLineToolTip =
"The common-line usage new nests start with. Only drawings with \"Allow common line\" set in Drawing Properties take part.";
/// <summary>The common-line list, in the order the WinForms box shows it.</summary>
public static IReadOnlyList<(string Text, CommonLineUsage Usage)> CommonLineUsages { get; } =
[
("Off", CommonLineUsage.Off),
("When it adds parts", CommonLineUsage.WhenItAddsParts),
("Whenever available", CommonLineUsage.Whenever),
];
/// <summary>The list index of <paramref name="usage"/>; an unknown usage shows as Off.</summary>
public static int CommonLineIndex(CommonLineUsage usage)
{
for (var i = 0; i < CommonLineUsages.Count; i++)
{
if (CommonLineUsages[i].Usage == usage)
return i;
}
return 0;
}
/// <summary>The usage at list index <paramref name="index"/>; none selected is Off.</summary>
public static CommonLineUsage CommonLineAt(int index) =>
index >= 0 && index < CommonLineUsages.Count ? CommonLineUsages[index].Usage : CommonLineUsage.Off;
/// <summary>The machines to choose from, by name.</summary>
public static IReadOnlyList<MachineConfig> SortedMachines(IEnumerable<MachineConfig> machines) =>
(machines ?? Enumerable.Empty<MachineConfig>())
.OrderBy(m => m.Name, StringComparer.CurrentCultureIgnoreCase)
.ToList();
/// <summary>
/// The machine id to save: the chosen machine's, or with none to choose (no machines on
/// file) the <paramref name="savedMachineId"/> kept as it was.
/// </summary>
public static Guid? MachineIdToSave(MachineConfig chosen, Guid? savedMachineId) =>
chosen?.Id ?? savedMachineId;
/// <summary>
/// <paramref name="value"/> as a box between <paramref name="minimum"/> and
/// <paramref name="maximum"/> shows it: clamped, with NaN or infinity as the minimum.
/// </summary>
public static double Clamp(double value, double minimum, double maximum)
{
if (double.IsNaN(value) || double.IsInfinity(value))
return minimum;
return System.Math.Clamp(value, minimum, maximum);
}
}