feat(posts): let posts load and save their settings as JSON

IJsonConfigPostProcessor lets a host keep a post's settings somewhere other
than the JSON file beside the post DLL. The CL-707, CI Fiber and Gravograph
posts implement it; LoadConfig keeps the current settings when the JSON is
unusable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Opus 5.5 committed 2026-10-25 20:02:08 -04:00
1 parent 84e6adbcf2
commit 9f3c22dc4f
4 files changed
+49 -9

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
namespace OpenNest
{
/// <summary>
/// A configurable post whose settings travel as JSON, so a host can keep them somewhere other
/// than the post's own file (the nest server's shared copy, for one).
/// </summary>
public interface IJsonConfigPostProcessor : IConfigurablePostProcessor
{
/// <summary>The settings as the post's own file holds them.</summary>
string SerializeConfig();
/// <summary>
/// Replaces the settings with <paramref name="json"/>, in the post's file format; the
/// file itself is not written. Throws <see cref="System.Text.Json.JsonException"/> and
/// keeps the current settings when the JSON is not usable.
/// </summary>
void LoadConfig(string json);
}
}
@@ -10,7 +10,7 @@ using OpenNest.CNC;
namespace OpenNest.Posts.Cincinnati
{
public sealed class CincinnatiPostProcessor
: IConfigurablePostProcessor,
: IJsonConfigPostProcessor,
IPostProcessorNestAware,
IMaterialProvidingPostProcessor
{
@@ -24,7 +24,7 @@ namespace OpenNest.Posts.Cincinnati
public string Author => "OpenNest";
public string Description => "Cincinnati CL-707/CL-800/CL-900/CL-940/CLX family";
public CincinnatiPostConfig Config { get; }
public CincinnatiPostConfig Config { get; private set; }
object IConfigurablePostProcessor.Config => Config;
@@ -81,10 +81,17 @@ namespace OpenNest.Posts.Cincinnati
public void SaveConfig()
{
var configPath = GetConfigPath();
var json = JsonSerializer.Serialize(Config, JsonOptions);
var json = SerializeConfig();
File.WriteAllText(configPath, json);
}
public string SerializeConfig() => JsonSerializer.Serialize(Config, JsonOptions);
public void LoadConfig(string json) =>
Config =
JsonSerializer.Deserialize<CincinnatiPostConfig>(json, JsonOptions)
?? throw new JsonException("The post settings are empty.");
private static string GetConfigPath()
{
var assemblyPath = typeof(CincinnatiPostProcessor).Assembly.Location;
@@ -17,7 +17,7 @@ namespace OpenNest.Posts.CincinnatiCIFiber
/// structure of the machine sample (see <see cref="CIFiberProgramWriter"/>).
/// </summary>
public sealed class CIFiberPostProcessor
: IConfigurablePostProcessor,
: IJsonConfigPostProcessor,
IMultiFilePostProcessor,
IPostVerificationSupport
{
@@ -33,7 +33,7 @@ namespace OpenNest.Posts.CincinnatiCIFiber
public string Description =>
"CI Fiber family laser (TF5200 / nLight CLX), e.g. CI Fiber 4020 8kW";
public CIFiberPostConfig Config { get; }
public CIFiberPostConfig Config { get; private set; }
object IConfigurablePostProcessor.Config => Config;
@@ -62,10 +62,17 @@ namespace OpenNest.Posts.CincinnatiCIFiber
public void SaveConfig()
{
var configPath = GetConfigPath();
var json = JsonSerializer.Serialize(Config, JsonOptions);
var json = SerializeConfig();
File.WriteAllText(configPath, json);
}
public string SerializeConfig() => JsonSerializer.Serialize(Config, JsonOptions);
public void LoadConfig(string json) =>
Config =
JsonSerializer.Deserialize<CIFiberPostConfig>(json, JsonOptions)
?? throw new JsonException("The post settings are empty.");
private static string GetConfigPath()
{
var assemblyPath = typeof(CIFiberPostProcessor).Assembly.Location;
@@ -17,7 +17,7 @@ namespace OpenNest.Posts.GravographIS
/// (Scribe) and a cut pass (Cut), each with its own feed/depth from <see cref="Config"/>.
/// The cut pass pauses by default so the operator can swap/adjust the tool.
/// </summary>
public sealed class GravographISPostProcessor : IConfigurablePostProcessor
public sealed class GravographISPostProcessor : IJsonConfigPostProcessor
{
private static readonly JsonSerializerOptions JsonOptions = new()
{
@@ -38,7 +38,7 @@ namespace OpenNest.Posts.GravographIS
public bool AllowReverse { get; set; } = true;
public GravographISPostConfig Config { get; }
public GravographISPostConfig Config { get; private set; }
object IConfigurablePostProcessor.Config => Config;
@@ -67,10 +67,17 @@ namespace OpenNest.Posts.GravographIS
public void SaveConfig()
{
var configPath = GetConfigPath();
var json = JsonSerializer.Serialize(Config, JsonOptions);
var json = SerializeConfig();
File.WriteAllText(configPath, json);
}
public string SerializeConfig() => JsonSerializer.Serialize(Config, JsonOptions);
public void LoadConfig(string json) =>
Config =
JsonSerializer.Deserialize<GravographISPostConfig>(json, JsonOptions)
?? throw new JsonException("The post settings are empty.");
private static string GetConfigPath()
{
var assemblyPath = typeof(GravographISPostProcessor).Assembly.Location;