- Move ProgramVariable and ProgramVariableManager from OpenNest.Posts.Cincinnati to OpenNest.Core/CNC (namespace OpenNest.CNC) so they can be used internally in nest programs - Add parameterless constructor to CincinnatiPostProcessor that loads config from a .json file next to the DLL (creates defaults on first run) - Enums serialize as readable strings (e.g., "Inches", "ControllerSide") - Config file: OpenNest.Posts.Cincinnati.json in the Posts/ directory Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace OpenNest.CNC
|
|
{
|
|
public sealed class ProgramVariableManager
|
|
{
|
|
private readonly Dictionary<int, ProgramVariable> _variables = new();
|
|
|
|
public ProgramVariable GetOrCreate(string name, int number, string expression = null)
|
|
{
|
|
if (_variables.TryGetValue(number, out var existing))
|
|
return existing;
|
|
|
|
var variable = new ProgramVariable(number, name, expression);
|
|
_variables[number] = variable;
|
|
return variable;
|
|
}
|
|
|
|
public List<string> EmitDeclarations()
|
|
{
|
|
return _variables.Values
|
|
.Where(v => v.Expression != null)
|
|
.OrderBy(v => v.Number)
|
|
.Select(v => $"{v.Reference}={v.Expression} ({FormatComment(v.Name)})")
|
|
.ToList();
|
|
}
|
|
|
|
private static string FormatComment(string name)
|
|
{
|
|
// "LeadInFeedrate" -> "LEAD IN FEEDRATE"
|
|
var sb = new StringBuilder();
|
|
foreach (var c in name)
|
|
{
|
|
if (char.IsUpper(c) && sb.Length > 0)
|
|
sb.Append(' ');
|
|
sb.Append(char.ToUpper(c));
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
}
|