Adds the full Cincinnati material/etch library list as the committed default config (seeded into Posts/ on build only when no runtime config exists), plus a Selected Library override in the PropertyGrid backed by a TypeConverter that populates from MaterialLibraries. MainForm calls the new IPostProcessorNestAware hook before showing the config so the dropdown opens preselected to the best match by nest material and nearest thickness. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace OpenNest.Posts.Cincinnati;
|
|
|
|
public sealed class MaterialLibraryResolver
|
|
{
|
|
private const double ThicknessTolerance = 0.001;
|
|
|
|
private readonly List<MaterialLibraryEntry> _materialLibraries;
|
|
private readonly List<EtchLibraryEntry> _etchLibraries;
|
|
private readonly string _selectedLibrary;
|
|
|
|
public MaterialLibraryResolver(CincinnatiPostConfig config)
|
|
{
|
|
_materialLibraries = config.MaterialLibraries ?? new List<MaterialLibraryEntry>();
|
|
_etchLibraries = config.EtchLibraries ?? new List<EtchLibraryEntry>();
|
|
_selectedLibrary = config.SelectedLibrary ?? "";
|
|
}
|
|
|
|
public string ResolveCutLibrary(string materialName, double thickness, string gas)
|
|
{
|
|
if (!string.IsNullOrEmpty(_selectedLibrary))
|
|
return EnsureLibExtension(_selectedLibrary);
|
|
|
|
var entry = _materialLibraries.FirstOrDefault(e =>
|
|
string.Equals(e.Material, materialName, StringComparison.OrdinalIgnoreCase) &&
|
|
System.Math.Abs(e.Thickness - thickness) <= ThicknessTolerance &&
|
|
string.Equals(e.Gas, gas, StringComparison.OrdinalIgnoreCase));
|
|
|
|
return EnsureLibExtension(entry?.Library ?? "");
|
|
}
|
|
|
|
public string ResolveEtchLibrary(string gas)
|
|
{
|
|
var entry = _etchLibraries.FirstOrDefault(e =>
|
|
string.Equals(e.Gas, gas, StringComparison.OrdinalIgnoreCase));
|
|
|
|
return EnsureLibExtension(entry?.Library ?? "");
|
|
}
|
|
|
|
private static string EnsureLibExtension(string library)
|
|
{
|
|
if (string.IsNullOrEmpty(library))
|
|
return library;
|
|
|
|
if (!library.EndsWith(".lib", StringComparison.OrdinalIgnoreCase))
|
|
return library + ".lib";
|
|
|
|
return library;
|
|
}
|
|
|
|
public static string ResolveGas(Nest nest, CincinnatiPostConfig config)
|
|
{
|
|
return !string.IsNullOrEmpty(nest.AssistGas) ? nest.AssistGas : config.DefaultAssistGas;
|
|
}
|
|
}
|