mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-15 11:11:54 -04:00
MaterialConfig only ever had one grade per material name, so the tree
and GetMaterial/GetParameters couldn't represent e.g. Mild Steel A36
vs. A1011 as distinct, independently-parameterized entries. Prep work
for an upcoming drawing database that will store material + grade per
drawing and needs to resolve cut parameters by that pair.
- MachineConfig gains GetMaterial(name, grade), GetGrades(name), and a
GetParameters(material, grade, thickness) overload, all keyed through
the existing SharedListNames normalization. The name-only overloads
stay for back-compat ("first grade found").
- MachineConfigForm's tree gains a real tier: Machine -> Material name
(synthetic grouping node) -> Grade -> Thickness. Add/remove gained
"Add Grade" and split "Delete Material" (all grades) from "Delete
Grade" (one entry). Renaming a grade's Name relocates its node to the
matching (or a new) group on focus-loss, keeping the tree in sync
without a full reload.
- No schema/JSON changes; existing machine files keep working as-is.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
43 lines
1.7 KiB
C#
43 lines
1.7 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();
|
|
|
|
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));
|
|
}
|