mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-29 01:21:09 -04:00
Clamps are physical fixtures that differ between machines, but one global clamps.json served every machine, so a plasma table and a fiber laser could not have different rails. - MachineConfig.Clamps holds each machine's rail in the machine's units, edited on a new Clamps tab in Tools > Machine Configuration. - New and BOM import give a nest the rail of the machine they assign; Nest > Clamps loads and saves the nest's machine's clamps. Each nest keeps its own copy, so machine edits never move existing nests' clamps. - At startup, while no machine has clamps, the legacy clamps.json (or the server's shared copy) is copied once into the default or only machine; with several machines and no default the user picks one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.6 KiB
C#
33 lines
1.6 KiB
C#
namespace OpenNest.Data;
|
|
|
|
/// <summary>
|
|
/// Moves the single legacy clamps.json (or its shared copy) onto a machine once. The legacy
|
|
/// rail is copied only while no machine has clamps of its own; after that it is never read.
|
|
/// </summary>
|
|
public static class LegacyClampMigration
|
|
{
|
|
/// <summary>
|
|
/// Whether <paramref name="legacy"/> (null when there is no legacy file) still has to be
|
|
/// copied: it lists at least one clamp and none of <paramref name="machines"/> has clamps yet.
|
|
/// </summary>
|
|
public static bool IsNeeded(ClampSettings? legacy, IReadOnlyCollection<MachineConfig> machines) =>
|
|
legacy is { ClampCount: > 0 } && machines.Count > 0 && machines.All(m => m.Clamps == null);
|
|
|
|
/// <summary>
|
|
/// The machine that takes the legacy rail without asking: the nest defaults' machine when it
|
|
/// is on file, otherwise the only machine. Null when there are several and none is the
|
|
/// default, so the user has to choose.
|
|
/// </summary>
|
|
public static MachineConfig? Target(IReadOnlyCollection<MachineConfig> machines, Guid? defaultMachineId) =>
|
|
machines.FirstOrDefault(m => m.Id == defaultMachineId)
|
|
?? (machines.Count == 1 ? machines.First() : null);
|
|
|
|
/// <summary>Gives <paramref name="machine"/> the legacy rail, converted to the machine's units.</summary>
|
|
public static void Apply(ClampSettings legacy, MachineConfig machine)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(legacy);
|
|
ArgumentNullException.ThrowIfNull(machine);
|
|
machine.Clamps = MachineClamps.FromSettings(legacy, machine.Units);
|
|
}
|
|
}
|