Files
OpenNest/OpenNest.Data/MachineConfig.cs
T
ajandClaude Opus 5.5 9c78b4ebec feat(machines): assign each nest a machine and keep the support grid per machine
The support grid was one shared support-grid.json, off by default, and a nest
had no machine at all, so a plasma table and a fiber laser could not have
different grids, and nothing could pick machine-specific behavior later
(lead-ins differ between laser and plasma; tabbing depends on the grid).

- Nest.Machine (id + name) persists as top-level `machine` in nest.json;
  malformed values load as none.
- MachineConfig.SupportGrid holds each machine's grid; a machine without one
  still falls back to the legacy support-grid.json.
- New and BOM import assign the Tools > Nest Defaults machine (first by name
  when none is chosen) and give the nest that machine's grid.
- Nest > Machine reassigns a nest and swaps in the new machine's grid;
  Nest > Support Grid saves machine defaults to the nest's machine.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 10:17:28 -04:00

54 lines
2.2 KiB
C#

using OpenNest.Math;
namespace OpenNest.Data;
public class MachineConfig
{
public Guid Id { get; set; } = Guid.NewGuid();
public int SchemaVersion { get; set; } = 1;
public string Name { get; set; } = "";
public MachineType Type { get; set; } = MachineType.Laser;
public UnitSystem Units { get; set; } = UnitSystem.Inches;
public List<MaterialConfig> Materials { get; set; } = new();
/// <summary>Acceleration limits; null until entered, when <see cref="GetMotionOrPlaceholder"/> stands in.</summary>
public MotionConfig? Motion { get; set; }
/// <summary>
/// The support grid nests assigned this machine rest on; null until saved from
/// Nest &gt; Support Grid, when the legacy shared support-grid.json stands in.
/// </summary>
public SupportGridSettings? SupportGrid { get; set; }
public MotionConfig GetMotionOrPlaceholder() => Motion ?? MotionConfig.Placeholder(Units);
public ThicknessConfig? GetParameters(string material, double thickness) =>
GetParameters(material, null, thickness);
public ThicknessConfig? GetParameters(string material, string? grade, double thickness)
{
var mat = grade is null ? GetMaterial(material) : GetMaterial(material, grade);
return mat?.Thicknesses.FirstOrDefault(t => t.Value.IsEqualTo(thickness));
}
/// <summary>
/// Returns the first material matching <paramref name="name"/>, regardless of
/// grade. Use <see cref="GetMaterial(string, string)"/> when the material may
/// have more than one grade on file.
/// </summary>
public MaterialConfig? GetMaterial(string name) =>
Materials.FirstOrDefault(m => SharedListNames.Key(m.Name) == SharedListNames.Key(name));
public MaterialConfig? GetMaterial(string name, string grade) =>
Materials.FirstOrDefault(m =>
SharedListNames.Key(m.Name) == SharedListNames.Key(name)
&& SharedListNames.Key(m.Grade) == SharedListNames.Key(grade)
);
/// <summary>
/// Returns every grade on file for the given material name.
/// </summary>
public IEnumerable<MaterialConfig> GetGrades(string name) =>
Materials.Where(m => SharedListNames.Key(m.Name) == SharedListNames.Key(name));
}