From 9f3c22dc4f21b0965468dfa9a5ebc48b06e75108 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Sun, 25 Oct 2026 20:02:08 -0400 Subject: [PATCH] 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 --- OpenNest.Core/IJsonConfigPostProcessor.cs | 19 +++++++++++++++++++ .../CincinnatiPostProcessor.cs | 13 ++++++++++--- .../CIFiberPostProcessor.cs | 13 ++++++++++--- .../GravographISPostProcessor.cs | 13 ++++++++++--- 4 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 OpenNest.Core/IJsonConfigPostProcessor.cs diff --git a/OpenNest.Core/IJsonConfigPostProcessor.cs b/OpenNest.Core/IJsonConfigPostProcessor.cs new file mode 100644 index 00000000..92794278 --- /dev/null +++ b/OpenNest.Core/IJsonConfigPostProcessor.cs @@ -0,0 +1,19 @@ +namespace OpenNest +{ + /// + /// 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). + /// + public interface IJsonConfigPostProcessor : IConfigurablePostProcessor + { + /// The settings as the post's own file holds them. + string SerializeConfig(); + + /// + /// Replaces the settings with , in the post's file format; the + /// file itself is not written. Throws and + /// keeps the current settings when the JSON is not usable. + /// + void LoadConfig(string json); + } +} diff --git a/Posts/OpenNest.Posts.Cincinnati/CincinnatiPostProcessor.cs b/Posts/OpenNest.Posts.Cincinnati/CincinnatiPostProcessor.cs index 69f58b2e..5c76fa63 100644 --- a/Posts/OpenNest.Posts.Cincinnati/CincinnatiPostProcessor.cs +++ b/Posts/OpenNest.Posts.Cincinnati/CincinnatiPostProcessor.cs @@ -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(json, JsonOptions) + ?? throw new JsonException("The post settings are empty."); + private static string GetConfigPath() { var assemblyPath = typeof(CincinnatiPostProcessor).Assembly.Location; diff --git a/Posts/OpenNest.Posts.CincinnatiCIFiber/CIFiberPostProcessor.cs b/Posts/OpenNest.Posts.CincinnatiCIFiber/CIFiberPostProcessor.cs index d0dc08cf..1e65ab38 100644 --- a/Posts/OpenNest.Posts.CincinnatiCIFiber/CIFiberPostProcessor.cs +++ b/Posts/OpenNest.Posts.CincinnatiCIFiber/CIFiberPostProcessor.cs @@ -17,7 +17,7 @@ namespace OpenNest.Posts.CincinnatiCIFiber /// structure of the machine sample (see ). /// 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(json, JsonOptions) + ?? throw new JsonException("The post settings are empty."); + private static string GetConfigPath() { var assemblyPath = typeof(CIFiberPostProcessor).Assembly.Location; diff --git a/Posts/OpenNest.Posts.GravographIS/GravographISPostProcessor.cs b/Posts/OpenNest.Posts.GravographIS/GravographISPostProcessor.cs index 9de13734..c2e4e054 100644 --- a/Posts/OpenNest.Posts.GravographIS/GravographISPostProcessor.cs +++ b/Posts/OpenNest.Posts.GravographIS/GravographISPostProcessor.cs @@ -17,7 +17,7 @@ namespace OpenNest.Posts.GravographIS /// (Scribe) and a cut pass (Cut), each with its own feed/depth from . /// The cut pass pauses by default so the operator can swap/adjust the tool. /// - 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(json, JsonOptions) + ?? throw new JsonException("The post settings are empty."); + private static string GetConfigPath() { var assemblyPath = typeof(GravographISPostProcessor).Assembly.Location;