mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-26 10:47:39 -05:00
fix(posts): refuse wrong-process output and keep settings across updates
Ahead of the new laser schedule, three ways a post could silently cut with the wrong process, and one way its settings silently reset: - Cincinnati CL wrote no G89 when no cut library matched the nest's material, thickness and gas (or no etch library for etch features), so the controller cut with whatever library it loaded last. It now refuses, unless the new "Require libraries" setting is turned off. - Cincinnati CL declared G20/G21 from its own setting without comparing the nest's units, so a metric nest posted 25.4x too large. It now refuses a mismatch. - CI Fiber posted any material missing from its table as the default code (MSN), so stainless or aluminum ran with mild-steel technology. A named, unmapped material is now refused; the default code covers only nests with no material. - Posts saved their settings beside their DLL, inside the install folder a Velopack update replaces, so every update reset them to the shipped defaults. Saves now go to %APPDATA%\OpenNest\Posts and the shipped JSON only seeds them; constructing a post no longer writes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
82d54aec87
commit
e8c52a354d
18 files changed
+299
-106
No files matched your search
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace OpenNest
|
||||
{
|
||||
/// <summary>
|
||||
/// Where a post keeps its own settings: %APPDATA%\OpenNest\Posts\<post assembly>.json.
|
||||
/// The install folder holds only the shipped defaults, because an update replaces it and
|
||||
/// would silently reset every edit saved there. The shipped JSON is read until the first save.
|
||||
/// </summary>
|
||||
public static class PostSettingsFile
|
||||
{
|
||||
/// <summary>Replaces <see cref="Directory"/>, so test runs never read or write the user's settings.</summary>
|
||||
public static string DirectoryOverride { get; set; }
|
||||
|
||||
public static string Directory => DirectoryOverride ?? Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "OpenNest", "Posts");
|
||||
|
||||
public static string PathFor(Assembly post) =>
|
||||
Path.Combine(Directory, Path.GetFileNameWithoutExtension(post.Location) + ".json");
|
||||
|
||||
/// <summary>The defaults deployed beside the post's assembly.</summary>
|
||||
public static string ShippedPathFor(Assembly post) => Path.ChangeExtension(post.Location, ".json");
|
||||
|
||||
/// <summary>The saved settings, else the shipped defaults, else null.</summary>
|
||||
public static string Read(Assembly post)
|
||||
{
|
||||
var saved = PathFor(post);
|
||||
if (File.Exists(saved))
|
||||
return File.ReadAllText(saved);
|
||||
var shipped = ShippedPathFor(post);
|
||||
return File.Exists(shipped) ? File.ReadAllText(shipped) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves through a temporary file, so a failed write leaves the previous settings intact.
|
||||
/// </summary>
|
||||
public static void Write(Assembly post, string json)
|
||||
{
|
||||
var path = PathFor(post);
|
||||
System.IO.Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
var temp = path + ".tmp";
|
||||
File.WriteAllText(temp, json);
|
||||
File.Move(temp, path, overwrite: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ public class CincinnatiPostProcessorTests
|
||||
public void Post_ProducesOutput_ForSinglePlateNest()
|
||||
{
|
||||
var nest = CreateTestNest();
|
||||
var config = new CincinnatiPostConfig { ConfigurationName = "CL940", PostedAccuracy = 4 };
|
||||
var config = new CincinnatiPostConfig { RequireLibraries = false, ConfigurationName = "CL940", PostedAccuracy = 4 };
|
||||
var post = new CincinnatiPostProcessor(config);
|
||||
|
||||
using var ms = new MemoryStream();
|
||||
@@ -43,7 +43,7 @@ public class CincinnatiPostProcessorTests
|
||||
public void Post_EmitsLeadOutVariable()
|
||||
{
|
||||
var nest = CreateTestNest();
|
||||
var config = new CincinnatiPostConfig { PostedAccuracy = 4 };
|
||||
var config = new CincinnatiPostConfig { RequireLibraries = false, PostedAccuracy = 4 };
|
||||
var post = new CincinnatiPostProcessor(config);
|
||||
|
||||
using var ms = new MemoryStream();
|
||||
@@ -59,6 +59,7 @@ public class CincinnatiPostProcessorTests
|
||||
var nest = CreateTestNest();
|
||||
var config = new CincinnatiPostConfig
|
||||
{
|
||||
RequireLibraries = false,
|
||||
PostedAccuracy = 4,
|
||||
ArcFeedrate = ArcFeedrateMode.Variables,
|
||||
};
|
||||
@@ -79,6 +80,7 @@ public class CincinnatiPostProcessorTests
|
||||
var nest = CreateTestNest();
|
||||
var config = new CincinnatiPostConfig
|
||||
{
|
||||
RequireLibraries = false,
|
||||
PostedAccuracy = 4,
|
||||
ArcFeedrate = ArcFeedrateMode.None,
|
||||
};
|
||||
@@ -97,7 +99,7 @@ public class CincinnatiPostProcessorTests
|
||||
public void Post_EmitsG90InPreamble()
|
||||
{
|
||||
var nest = CreateTestNest();
|
||||
var config = new CincinnatiPostConfig { PostedAccuracy = 4 };
|
||||
var config = new CincinnatiPostConfig { RequireLibraries = false, PostedAccuracy = 4 };
|
||||
var post = new CincinnatiPostProcessor(config);
|
||||
|
||||
using var ms = new MemoryStream();
|
||||
@@ -110,7 +112,7 @@ public class CincinnatiPostProcessorTests
|
||||
[Fact]
|
||||
public void Post_ImplementsIPostProcessor()
|
||||
{
|
||||
var post = new CincinnatiPostProcessor(new CincinnatiPostConfig());
|
||||
var post = new CincinnatiPostProcessor(new CincinnatiPostConfig { RequireLibraries = false });
|
||||
IPostProcessor pp = post;
|
||||
|
||||
Assert.Equal("Cincinnati CL-707", pp.Name);
|
||||
@@ -120,7 +122,7 @@ public class CincinnatiPostProcessorTests
|
||||
[Fact]
|
||||
public void Post_ImplementsIConfigurablePostProcessor()
|
||||
{
|
||||
var post = new CincinnatiPostProcessor(new CincinnatiPostConfig());
|
||||
var post = new CincinnatiPostProcessor(new CincinnatiPostConfig { RequireLibraries = false });
|
||||
var configurable = post as IConfigurablePostProcessor;
|
||||
|
||||
Assert.NotNull(configurable);
|
||||
@@ -137,7 +139,7 @@ public class CincinnatiPostProcessorTests
|
||||
plate2.Parts.Add(new Part(new Drawing("Part1", CreateSquareProgram())));
|
||||
nest.Plates.Add(plate2);
|
||||
|
||||
var config = new CincinnatiPostConfig { PostedAccuracy = 4 };
|
||||
var config = new CincinnatiPostConfig { RequireLibraries = false, PostedAccuracy = 4 };
|
||||
var post = new CincinnatiPostProcessor(config);
|
||||
|
||||
using var ms = new MemoryStream();
|
||||
@@ -154,7 +156,7 @@ public class CincinnatiPostProcessorTests
|
||||
public void Post_ToFile_CreatesFile()
|
||||
{
|
||||
var nest = CreateTestNest();
|
||||
var config = new CincinnatiPostConfig { PostedAccuracy = 4 };
|
||||
var config = new CincinnatiPostConfig { RequireLibraries = false, PostedAccuracy = 4 };
|
||||
var post = new CincinnatiPostProcessor(config);
|
||||
var tempFile = Path.GetTempFileName() + ".CNC";
|
||||
|
||||
@@ -177,6 +179,7 @@ public class CincinnatiPostProcessorTests
|
||||
{
|
||||
var config = new CincinnatiPostConfig
|
||||
{
|
||||
RequireLibraries = false,
|
||||
ConfigurationName = "CL940_CORONA",
|
||||
DefaultAssistGas = "N2",
|
||||
DefaultEtchGas = "N2",
|
||||
@@ -239,6 +242,7 @@ public class CincinnatiPostProcessorTests
|
||||
var nest = CreateTestNest();
|
||||
var config = new CincinnatiPostConfig
|
||||
{
|
||||
RequireLibraries = false,
|
||||
PostedAccuracy = 4,
|
||||
UsePartSubprograms = true,
|
||||
PartSubprogramStart = 200,
|
||||
@@ -279,6 +283,7 @@ public class CincinnatiPostProcessorTests
|
||||
|
||||
var config = new CincinnatiPostConfig
|
||||
{
|
||||
RequireLibraries = false,
|
||||
PostedAccuracy = 4,
|
||||
UsePartSubprograms = true,
|
||||
PartSubprogramStart = 200,
|
||||
@@ -317,6 +322,7 @@ public class CincinnatiPostProcessorTests
|
||||
|
||||
var config = new CincinnatiPostConfig
|
||||
{
|
||||
RequireLibraries = false,
|
||||
PostedAccuracy = 4,
|
||||
UsePartSubprograms = true,
|
||||
PartSubprogramStart = 200,
|
||||
@@ -349,6 +355,7 @@ public class CincinnatiPostProcessorTests
|
||||
|
||||
var config = new CincinnatiPostConfig
|
||||
{
|
||||
RequireLibraries = false,
|
||||
PostedAccuracy = 4,
|
||||
UsePartSubprograms = true,
|
||||
PartSubprogramStart = 200,
|
||||
@@ -373,6 +380,7 @@ public class CincinnatiPostProcessorTests
|
||||
{
|
||||
var config = new CincinnatiPostConfig
|
||||
{
|
||||
RequireLibraries = false,
|
||||
UsePartSubprograms = true,
|
||||
PartSubprogramStart = 300,
|
||||
};
|
||||
@@ -408,7 +416,7 @@ public class CincinnatiPostProcessorTests
|
||||
plate.Parts.Add(new Part(drawing, new Vector(1, 1)));
|
||||
nest.Plates.Add(plate);
|
||||
|
||||
var config = new CincinnatiPostConfig { UsePartSubprograms = true, PostedAccuracy = 4 };
|
||||
var config = new CincinnatiPostConfig { RequireLibraries = false, UsePartSubprograms = true, PostedAccuracy = 4 };
|
||||
var post = new CincinnatiPostProcessor(config);
|
||||
|
||||
using var ms = new MemoryStream();
|
||||
|
||||
@@ -188,6 +188,43 @@ public class CincinnatiPostRegressionTests
|
||||
Assert.Empty(libraries);
|
||||
else
|
||||
Assert.Equal(new[] { $"P{expected}.lib" }, libraries);
|
||||
|
||||
// Without a G89 the controller cuts with whatever library it loaded last, so by
|
||||
// default a nest with no matching library is refused.
|
||||
config.RequireLibraries = true;
|
||||
if (expected == "")
|
||||
Assert.Throws<System.InvalidOperationException>(() => Post(nest, config));
|
||||
else
|
||||
Post(nest, config);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EtchFeatures_WithoutAnEtchLibrary_AreRefused()
|
||||
{
|
||||
var nest = SquaresNest(("A", new Vector(5, 5)));
|
||||
var config = Config(partSubprograms: false);
|
||||
config.RequireLibraries = true;
|
||||
config.SelectedLibrary = "MS250O2";
|
||||
Post(nest, config);
|
||||
|
||||
foreach (var move in nest.Plates[0].Parts[0].Program.Codes.OfType<LinearMove>().Take(4))
|
||||
move.Layer = LayerType.Scribe;
|
||||
|
||||
Assert.Throws<System.InvalidOperationException>(() => Post(nest, config));
|
||||
config.EtchLibraries = new() { new() { Gas = config.DefaultEtchGas, Library = "ETCHN2" } };
|
||||
Post(nest, config);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NestUnits_OtherThanThePostedUnits_AreRefused()
|
||||
{
|
||||
var nest = SquaresNest(("A", new Vector(5, 5)));
|
||||
nest.Units = Units.Millimeters;
|
||||
var config = Config(partSubprograms: false);
|
||||
|
||||
Assert.Throws<System.InvalidOperationException>(() => Post(nest, config));
|
||||
config.PostedUnits = Units.Millimeters;
|
||||
Post(nest, config);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
||||
@@ -20,6 +20,7 @@ internal static class CincinnatiReplay
|
||||
UsePartSubprograms = partSubprograms,
|
||||
UseAntiDive = false,
|
||||
PalletExchange = PalletMode.None,
|
||||
RequireLibraries = false,
|
||||
};
|
||||
|
||||
internal static string Post(Nest nest, bool partSubprograms) => Post(nest, Config(partSubprograms));
|
||||
|
||||
@@ -46,7 +46,7 @@ public class HeadLockedCutOffPostTests
|
||||
public void ClPost_WithoutLockCodes_RefusesBeforeWriting()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
var post = new CincinnatiPostProcessor(new CincinnatiPostConfig());
|
||||
var post = new CincinnatiPostProcessor(new CincinnatiPostConfig { RequireLibraries = false });
|
||||
|
||||
var refusal = Assert.Throws<InvalidOperationException>(() => post.Post(Nest(farEdgeFirst: false), stream));
|
||||
|
||||
@@ -92,6 +92,7 @@ public class HeadLockedCutOffPostTests
|
||||
{
|
||||
var post = new CincinnatiPostProcessor(new CincinnatiPostConfig
|
||||
{
|
||||
RequireLibraries = false,
|
||||
HeadHeightLockCode = LockCode,
|
||||
HeadHeightUnlockCode = UnlockCode,
|
||||
});
|
||||
|
||||
@@ -97,7 +97,7 @@ public class HeadRaisePostTests
|
||||
|
||||
private static List<string> ClLines(Nest nest, M47Mode mode)
|
||||
{
|
||||
var post = new CincinnatiPostProcessor(new CincinnatiPostConfig { ExteriorM47 = mode, InteriorM47 = mode });
|
||||
var post = new CincinnatiPostProcessor(new CincinnatiPostConfig { RequireLibraries = false, ExteriorM47 = mode, InteriorM47 = mode });
|
||||
using var stream = new MemoryStream();
|
||||
post.Post(nest, stream);
|
||||
return Lines(stream);
|
||||
|
||||
@@ -62,7 +62,7 @@ public class UserVariablePostTests
|
||||
plate.Parts.Add(new Part(drawing2, new Vector(50, 0)));
|
||||
nest.Plates.Add(plate);
|
||||
|
||||
var config = new CincinnatiPostConfig { UserVariableStart = 200 };
|
||||
var config = new CincinnatiPostConfig { RequireLibraries = false, UserVariableStart = 200 };
|
||||
var post = new CincinnatiPostProcessor(config);
|
||||
var output = PostToString(post, nest);
|
||||
|
||||
@@ -89,7 +89,7 @@ public class UserVariablePostTests
|
||||
plate.Parts.Add(new Part(drawing2, new Vector(50, 0)));
|
||||
nest.Plates.Add(plate);
|
||||
|
||||
var config = new CincinnatiPostConfig { UserVariableStart = 200 };
|
||||
var config = new CincinnatiPostConfig { RequireLibraries = false, UserVariableStart = 200 };
|
||||
var post = new CincinnatiPostProcessor(config);
|
||||
var output = PostToString(post, nest);
|
||||
|
||||
@@ -103,7 +103,7 @@ public class UserVariablePostTests
|
||||
[Fact]
|
||||
public void UserVariables_StartNumberConfigurable()
|
||||
{
|
||||
var config = new CincinnatiPostConfig { UserVariableStart = 300 };
|
||||
var config = new CincinnatiPostConfig { RequireLibraries = false, UserVariableStart = 300 };
|
||||
var output = PostNestWithVariables("width = 48.0\nG90\nG01X$widthY0", config);
|
||||
|
||||
Assert.Contains("#300=48", output);
|
||||
@@ -115,6 +115,7 @@ public class UserVariablePostTests
|
||||
// Create a plate with a vertical cutoff
|
||||
var config = new CincinnatiPostConfig
|
||||
{
|
||||
RequireLibraries = false,
|
||||
SheetWidthVariable = 110,
|
||||
SheetLengthVariable = 111,
|
||||
};
|
||||
@@ -150,7 +151,7 @@ public class UserVariablePostTests
|
||||
public void CutOff_SegmentedCut_OnlyEdgeUsesVariable()
|
||||
{
|
||||
// Create a plate with a part in the middle and a vertical cutoff
|
||||
var config = new CincinnatiPostConfig { SheetWidthVariable = 110 };
|
||||
var config = new CincinnatiPostConfig { RequireLibraries = false, SheetWidthVariable = 110 };
|
||||
var nest = new Nest { Name = "Test" };
|
||||
var plate = new Plate(new Size(48, 96));
|
||||
|
||||
@@ -188,7 +189,7 @@ public class UserVariablePostTests
|
||||
plate.Parts.Add(new Part(drawing, new Vector(0, 0)));
|
||||
nest.Plates.Add(plate);
|
||||
|
||||
config ??= new CincinnatiPostConfig { UserVariableStart = 200 };
|
||||
config ??= new CincinnatiPostConfig { RequireLibraries = false, UserVariableStart = 200 };
|
||||
var post = new CincinnatiPostProcessor(config);
|
||||
return PostToString(post, nest);
|
||||
}
|
||||
|
||||
@@ -450,7 +450,19 @@ public class CIFiberPostProcessorTests
|
||||
|
||||
Assert.Equal("SSN", config.ResolveMaterialCode("stainless"));
|
||||
Assert.Equal("SSN", config.ResolveMaterialCode(" STAINLESS "));
|
||||
Assert.Equal("MSN", config.ResolveMaterialCode("Aluminum"));
|
||||
Assert.Null(config.ResolveMaterialCode("Aluminum"));
|
||||
Assert.Equal("MSN", config.ResolveMaterialCode(""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UnmappedMaterial_IsRefusedRatherThanPostedAsTheDefault()
|
||||
{
|
||||
var nest = MakeMultiSheetNest();
|
||||
nest.Material = new Material("Stainless");
|
||||
var post = new CIFiberPostProcessor(new CIFiberPostConfig());
|
||||
|
||||
var ex = Assert.Throws<InvalidOperationException>(() => post.Post(nest, new MemoryStream()));
|
||||
Assert.Contains("Stainless", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -17,7 +17,7 @@ public class DisplayPerimeterPostTests
|
||||
|
||||
private static IPostProcessor Post(string name) => name switch
|
||||
{
|
||||
"cincinnati" => new CincinnatiPostProcessor(new CincinnatiPostConfig { ConfigurationName = "CL940", PostedAccuracy = 4 }),
|
||||
"cincinnati" => new CincinnatiPostProcessor(new CincinnatiPostConfig { RequireLibraries = false, ConfigurationName = "CL940", PostedAccuracy = 4 }),
|
||||
"cifiber" => new CIFiberPostProcessor(new CIFiberPostConfig { ConfigurationName = "CI FIBER 8K" }),
|
||||
_ => new GravographISPostProcessor(),
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ using OpenNest.IO;
|
||||
|
||||
namespace OpenNest.Tests.Diagnostics;
|
||||
|
||||
[Collection(OpenNest.Tests.PostSettings.PostSettingsFileTests.Collection)]
|
||||
public class ConsolePostVerificationTests
|
||||
{
|
||||
[Fact]
|
||||
@@ -12,11 +13,19 @@ public class ConsolePostVerificationTests
|
||||
{
|
||||
var directory = Path.Combine(Path.GetTempPath(), "opennest-post-verification-" + Guid.NewGuid());
|
||||
Directory.CreateDirectory(directory);
|
||||
// Post with the shipped settings, never this PC's saved ones.
|
||||
PostSettingsFile.DirectoryOverride = Path.Combine(directory, "post-settings");
|
||||
try
|
||||
{
|
||||
var input = Path.Combine(directory, "job.nest");
|
||||
var output = Path.Combine(directory, "job.cnc");
|
||||
var nest = new Nest("VerificationFixture");
|
||||
// A stock the shipped post has a cut library for, so only verification can refuse it.
|
||||
var nest = new Nest("VerificationFixture")
|
||||
{
|
||||
Material = new Material("Carbon Steel"),
|
||||
Thickness = 0.188,
|
||||
AssistGas = "O2",
|
||||
};
|
||||
var program = new OpenNest.CNC.Program();
|
||||
program.Codes.Add(new RapidMove(0, 0));
|
||||
program.Codes.Add(new LinearMove(2, 0));
|
||||
@@ -56,6 +65,7 @@ public class ConsolePostVerificationTests
|
||||
}
|
||||
finally
|
||||
{
|
||||
PostSettingsFile.DirectoryOverride = null;
|
||||
Directory.Delete(directory, recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using OpenNest.Posts.Cincinnati;
|
||||
using OpenNest.Posts.CincinnatiCIFiber;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenNest.Tests.PostSettings;
|
||||
|
||||
/// <summary>
|
||||
/// An update replaces the install folder, so a post's edited settings must live outside it:
|
||||
/// saves go to the user's settings directory and the shipped JSON only seeds them.
|
||||
/// </summary>
|
||||
[Collection(Collection)]
|
||||
public class PostSettingsFileTests : IDisposable
|
||||
{
|
||||
/// <summary>Tests that set <see cref="PostSettingsFile.DirectoryOverride"/> share it, so they never run together.</summary>
|
||||
public const string Collection = "PostSettingsFile";
|
||||
|
||||
private readonly string directory =
|
||||
Path.Combine(Path.GetTempPath(), "opennest-post-settings-" + Guid.NewGuid());
|
||||
|
||||
public PostSettingsFileTests() => PostSettingsFile.DirectoryOverride = directory;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
PostSettingsFile.DirectoryOverride = null;
|
||||
if (Directory.Exists(directory))
|
||||
Directory.Delete(directory, recursive: true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Save_WritesTheUserCopy_AndLeavesTheShippedDefaultsUntouched()
|
||||
{
|
||||
var assembly = typeof(CincinnatiPostProcessor).Assembly;
|
||||
var shipped = PostSettingsFile.ShippedPathFor(assembly);
|
||||
var shippedBefore = File.ReadAllText(shipped);
|
||||
|
||||
var post = new CincinnatiPostProcessor();
|
||||
Assert.NotEmpty(post.Config.MaterialLibraries);
|
||||
post.Config.ConfigurationName = "EDITED";
|
||||
post.SaveConfig();
|
||||
|
||||
Assert.Equal(shippedBefore, File.ReadAllText(shipped));
|
||||
Assert.StartsWith(directory, PostSettingsFile.PathFor(assembly));
|
||||
Assert.Equal("EDITED", new CincinnatiPostProcessor().Config.ConfigurationName);
|
||||
Assert.False(File.Exists(PostSettingsFile.PathFor(assembly) + ".tmp"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructing_WithNoSavedCopy_ReadsTheShippedDefaultsWithoutWriting()
|
||||
{
|
||||
var post = new CIFiberPostProcessor();
|
||||
|
||||
Assert.Contains("Carbon Steel", post.Config.MaterialCodes.Keys);
|
||||
Assert.False(Directory.Exists(directory));
|
||||
}
|
||||
}
|
||||
@@ -354,6 +354,13 @@ namespace OpenNest.Posts.Cincinnati
|
||||
[PostSetting(LibrariesSection, 1)]
|
||||
public List<MaterialLibraryEntry> MaterialLibraries { get; set; } = new();
|
||||
|
||||
[DisplayName("Require libraries")]
|
||||
[Description(
|
||||
"Refuse to post a nest with no matching cut library, or etch features with no etch library. Turn off only if the controller's library is always loaded by hand: without a G89 it cuts with whatever library it loaded last."
|
||||
)]
|
||||
[PostSetting(LibrariesSection, 3)]
|
||||
public bool RequireLibraries { get; set; } = true;
|
||||
|
||||
[DisplayName("Etch libraries")]
|
||||
[Description("Etch library (G89 file) for each etch gas.")]
|
||||
[PostSetting(LibrariesSection, 2)]
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -58,19 +59,13 @@ namespace OpenNest.Posts.Cincinnati
|
||||
Config.SelectedLibrary = entry?.Library ?? "";
|
||||
}
|
||||
|
||||
/// <summary>Loads this PC's saved settings, else the shipped defaults (see <see cref="PostSettingsFile"/>).</summary>
|
||||
public CincinnatiPostProcessor()
|
||||
{
|
||||
var configPath = GetConfigPath();
|
||||
if (File.Exists(configPath))
|
||||
{
|
||||
var json = File.ReadAllText(configPath);
|
||||
Config = JsonSerializer.Deserialize<CincinnatiPostConfig>(json, JsonOptions);
|
||||
}
|
||||
else
|
||||
{
|
||||
Config = new CincinnatiPostConfig();
|
||||
SaveConfig();
|
||||
}
|
||||
var json = PostSettingsFile.Read(typeof(CincinnatiPostProcessor).Assembly);
|
||||
Config = json == null
|
||||
? new CincinnatiPostConfig()
|
||||
: JsonSerializer.Deserialize<CincinnatiPostConfig>(json, JsonOptions) ?? new CincinnatiPostConfig();
|
||||
}
|
||||
|
||||
public CincinnatiPostProcessor(CincinnatiPostConfig config)
|
||||
@@ -78,12 +73,7 @@ namespace OpenNest.Posts.Cincinnati
|
||||
Config = config;
|
||||
}
|
||||
|
||||
public void SaveConfig()
|
||||
{
|
||||
var configPath = GetConfigPath();
|
||||
var json = SerializeConfig();
|
||||
File.WriteAllText(configPath, json);
|
||||
}
|
||||
public void SaveConfig() => PostSettingsFile.Write(typeof(CincinnatiPostProcessor).Assembly, SerializeConfig());
|
||||
|
||||
public string SerializeConfig() => JsonSerializer.Serialize(Config, JsonOptions);
|
||||
|
||||
@@ -92,20 +82,13 @@ namespace OpenNest.Posts.Cincinnati
|
||||
JsonSerializer.Deserialize<CincinnatiPostConfig>(json, JsonOptions)
|
||||
?? throw new JsonException("The post settings are empty.");
|
||||
|
||||
private static string GetConfigPath()
|
||||
{
|
||||
var assemblyPath = typeof(CincinnatiPostProcessor).Assembly.Location;
|
||||
var dir = Path.GetDirectoryName(assemblyPath);
|
||||
var name = Path.GetFileNameWithoutExtension(assemblyPath);
|
||||
return Path.Combine(dir, name + ".json");
|
||||
}
|
||||
|
||||
public void Post(Nest nest, Stream outputStream)
|
||||
{
|
||||
// Refuse before writing anything: a head-locked overcut needs the lock codes.
|
||||
HeadHeightLock.EnsurePostable(nest, Config.HasHeadHeightLockCodes(), Name);
|
||||
// M47 raises the head before a marked rapid; the markers must be well formed.
|
||||
HeadRaise.EnsurePostable(nest, true, Name);
|
||||
EnsureProcessResolvable(nest);
|
||||
|
||||
// 1. Create variable manager and register standard variables
|
||||
var vars = CreateVariableManager();
|
||||
@@ -266,10 +249,52 @@ namespace OpenNest.Posts.Cincinnati
|
||||
DisplayPerimeterTail.EnsurePostable(nest);
|
||||
HeadHeightLock.EnsurePostable(nest, Config.HasHeadHeightLockCodes(), Name);
|
||||
HeadRaise.EnsurePostable(nest, true, Name);
|
||||
EnsureProcessResolvable(nest);
|
||||
using var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write);
|
||||
Post(nest, fs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Refuses a nest the controller would cut with the wrong process: coordinates in other
|
||||
/// units than the G20/G21 the post declares, or features with no G89 library, which
|
||||
/// leave the controller on whatever library it loaded last.
|
||||
/// </summary>
|
||||
private void EnsureProcessResolvable(Nest nest)
|
||||
{
|
||||
if (nest.Units != Config.PostedUnits)
|
||||
throw new InvalidOperationException(
|
||||
$"The nest is in {nest.Units} but the {Name} post writes {Config.PostedUnits}. "
|
||||
+ "Change the post's Posted units, or the nest's units, so they match.");
|
||||
|
||||
var parts = nest.Plates.SelectMany(p => p.Parts).Where(p => p?.Program != null).ToList();
|
||||
if (!Config.RequireLibraries || parts.Count == 0)
|
||||
return;
|
||||
|
||||
var resolver = new MaterialLibraryResolver(Config);
|
||||
var gas = MaterialLibraryResolver.ResolveGas(nest, Config);
|
||||
if (parts.Any(p => HasMoves(p.Program, etch: false))
|
||||
&& string.IsNullOrEmpty(resolver.ResolveCutLibrary(nest.Material?.Name ?? "", nest.Thickness, gas)))
|
||||
throw new InvalidOperationException(
|
||||
$"The {Name} post has no cut library for {nest.Material?.Name ?? "(no material)"} "
|
||||
+ $"{nest.Thickness} with {gas} assist gas. Add a row to the post's cut libraries "
|
||||
+ "or select a library before posting.");
|
||||
|
||||
if (parts.Any(p => HasMoves(p.Program, etch: true))
|
||||
&& string.IsNullOrEmpty(resolver.ResolveEtchLibrary(Config.DefaultEtchGas)))
|
||||
throw new InvalidOperationException(
|
||||
$"The nest has etch features but the {Name} post has no etch library for "
|
||||
+ $"{Config.DefaultEtchGas} gas. Add one to the post's etch libraries before posting.");
|
||||
}
|
||||
|
||||
private static bool HasMoves(Program program, bool etch) =>
|
||||
program.Codes.Any(code => code switch
|
||||
{
|
||||
LinearMove line => (line.Layer == LayerType.Scribe) == etch,
|
||||
ArcMove arc => (arc.Layer == LayerType.Scribe) == etch,
|
||||
_ => false,
|
||||
})
|
||||
|| program.Codes.OfType<SubProgramCall>().Any(call => call.Program != null && HasMoves(call.Program, etch));
|
||||
|
||||
private Dictionary<(int drawingId, string varName), int> RegisterUserVariables(
|
||||
ProgramVariableManager vars,
|
||||
List<Plate> plates
|
||||
|
||||
@@ -237,21 +237,27 @@ namespace OpenNest.Posts.CincinnatiCIFiber
|
||||
return copy;
|
||||
}
|
||||
|
||||
/// <summary>Fallback V.E.MATERIAL code when the material name has no mapping.</summary>
|
||||
/// <summary>V.E.MATERIAL code for a nest with no material name.</summary>
|
||||
[DisplayName("Default material code")]
|
||||
[Description("Code used when the nest material has no entry in the table above.")]
|
||||
[Description(
|
||||
"Code used when the nest has no material. A named material missing from the table above is refused rather than posted with this code, so stainless or aluminum is never cut as steel."
|
||||
)]
|
||||
[PostSetting(MaterialSection, 1)]
|
||||
public string DefaultMaterialCode { get; set; } = "MSN";
|
||||
|
||||
/// <summary>
|
||||
/// The V.E.MATERIAL code for <paramref name="materialName"/>, or null when a named
|
||||
/// material has no mapping (or an unnamed one has no default): the caller must refuse.
|
||||
/// </summary>
|
||||
public string ResolveMaterialCode(string materialName)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(materialName)
|
||||
&& MaterialCodes != null
|
||||
&& MaterialCodes.TryGetValue(materialName.Trim(), out var code)
|
||||
&& !string.IsNullOrWhiteSpace(code))
|
||||
return code;
|
||||
string code;
|
||||
if (string.IsNullOrWhiteSpace(materialName))
|
||||
code = DefaultMaterialCode;
|
||||
else if (MaterialCodes == null || !MaterialCodes.TryGetValue(materialName.Trim(), out code))
|
||||
code = null;
|
||||
|
||||
return DefaultMaterialCode ?? "MSN";
|
||||
return string.IsNullOrWhiteSpace(code) ? null : code;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -37,21 +37,13 @@ namespace OpenNest.Posts.CincinnatiCIFiber
|
||||
|
||||
object IConfigurablePostProcessor.Config => Config;
|
||||
|
||||
/// <summary>Loads this PC's saved settings, else the shipped defaults (see <see cref="PostSettingsFile"/>).</summary>
|
||||
public CIFiberPostProcessor()
|
||||
{
|
||||
var configPath = GetConfigPath();
|
||||
if (File.Exists(configPath))
|
||||
{
|
||||
var json = File.ReadAllText(configPath);
|
||||
Config =
|
||||
JsonSerializer.Deserialize<CIFiberPostConfig>(json, JsonOptions)
|
||||
?? new CIFiberPostConfig();
|
||||
}
|
||||
else
|
||||
{
|
||||
Config = new CIFiberPostConfig();
|
||||
SaveConfig();
|
||||
}
|
||||
var json = PostSettingsFile.Read(typeof(CIFiberPostProcessor).Assembly);
|
||||
Config = json == null
|
||||
? new CIFiberPostConfig()
|
||||
: JsonSerializer.Deserialize<CIFiberPostConfig>(json, JsonOptions) ?? new CIFiberPostConfig();
|
||||
}
|
||||
|
||||
public CIFiberPostProcessor(CIFiberPostConfig config)
|
||||
@@ -59,12 +51,7 @@ namespace OpenNest.Posts.CincinnatiCIFiber
|
||||
Config = config ?? throw new ArgumentNullException(nameof(config));
|
||||
}
|
||||
|
||||
public void SaveConfig()
|
||||
{
|
||||
var configPath = GetConfigPath();
|
||||
var json = SerializeConfig();
|
||||
File.WriteAllText(configPath, json);
|
||||
}
|
||||
public void SaveConfig() => PostSettingsFile.Write(typeof(CIFiberPostProcessor).Assembly, SerializeConfig());
|
||||
|
||||
public string SerializeConfig() => JsonSerializer.Serialize(Config, JsonOptions);
|
||||
|
||||
@@ -73,13 +60,6 @@ namespace OpenNest.Posts.CincinnatiCIFiber
|
||||
JsonSerializer.Deserialize<CIFiberPostConfig>(json, JsonOptions)
|
||||
?? throw new JsonException("The post settings are empty.");
|
||||
|
||||
private static string GetConfigPath()
|
||||
{
|
||||
var assemblyPath = typeof(CIFiberPostProcessor).Assembly.Location;
|
||||
var dir = Path.GetDirectoryName(assemblyPath);
|
||||
var name = Path.GetFileNameWithoutExtension(assemblyPath);
|
||||
return Path.Combine(dir, name + ".json");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes every sheet into one program. A stream holds a single program,
|
||||
|
||||
@@ -75,9 +75,28 @@ namespace OpenNest.Posts.CincinnatiCIFiber
|
||||
|
||||
HeadHeightLock.EnsurePostable(nest, _config.HasHeadHeightLockCodes(), "Cincinnati CI Fiber");
|
||||
HeadRaise.EnsurePostable(nest, _config.HasHeadRaiseCode(), "Cincinnati CI Fiber");
|
||||
EnsureMaterialMapped(nest);
|
||||
Write(nest, PostedSheets(nest), 1, w);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Refuses a material with no V.E.MATERIAL code: posting it under another material's
|
||||
/// code would have the machine cut it with that material's technology.
|
||||
/// </summary>
|
||||
private void EnsureMaterialMapped(Nest nest)
|
||||
{
|
||||
var materialName = nest.Material?.Name ?? "";
|
||||
if (_config.ResolveMaterialCode(materialName) == null)
|
||||
throw new InvalidOperationException(MissingMaterialMessage(materialName));
|
||||
}
|
||||
|
||||
private static string MissingMaterialMessage(string materialName) =>
|
||||
string.IsNullOrWhiteSpace(materialName)
|
||||
? "The nest has no material and the Cincinnati CI Fiber post has no default material code. "
|
||||
+ "Set the nest's material before posting."
|
||||
: $"The Cincinnati CI Fiber post has no material code for \"{materialName.Trim()}\". "
|
||||
+ "Add it to the post's material codes before posting.";
|
||||
|
||||
/// <summary>
|
||||
/// Writes one sheet as a complete program. Contour labels restart at 1;
|
||||
/// <paramref name="sheetNumber"/> only labels the sheet comment.
|
||||
@@ -91,6 +110,7 @@ namespace OpenNest.Posts.CincinnatiCIFiber
|
||||
|
||||
HeadHeightLock.EnsurePostable(nest, _config.HasHeadHeightLockCodes(), "Cincinnati CI Fiber");
|
||||
HeadRaise.EnsurePostable(nest, _config.HasHeadRaiseCode(), "Cincinnati CI Fiber");
|
||||
EnsureMaterialMapped(nest);
|
||||
Write(nest, new[] { sheet }, sheetNumber, w);
|
||||
}
|
||||
|
||||
@@ -164,7 +184,8 @@ namespace OpenNest.Posts.CincinnatiCIFiber
|
||||
thickness = thickness.Substring(1); // sample posts ".060"
|
||||
CIFiberFormatter.Line(w, $"( Material = {materialName} {thickness} )".TrimEnd());
|
||||
|
||||
var code = _config.ResolveMaterialCode(materialName);
|
||||
var code = _config.ResolveMaterialCode(materialName)
|
||||
?? throw new InvalidOperationException(MissingMaterialMessage(materialName));
|
||||
CIFiberFormatter.Line(w, $"V.E.MATERIAL = \"{code}\"");
|
||||
CIFiberFormatter.Line(w, $"V.E.THICKNESS = {_fmt.Fixed(nest.Thickness)}");
|
||||
|
||||
|
||||
@@ -42,21 +42,13 @@ namespace OpenNest.Posts.GravographIS
|
||||
|
||||
object IConfigurablePostProcessor.Config => Config;
|
||||
|
||||
/// <summary>Loads this PC's saved settings, else the shipped defaults (see <see cref="PostSettingsFile"/>).</summary>
|
||||
public GravographISPostProcessor()
|
||||
{
|
||||
var configPath = GetConfigPath();
|
||||
if (File.Exists(configPath))
|
||||
{
|
||||
var json = File.ReadAllText(configPath);
|
||||
Config =
|
||||
JsonSerializer.Deserialize<GravographISPostConfig>(json, JsonOptions)
|
||||
?? new GravographISPostConfig();
|
||||
}
|
||||
else
|
||||
{
|
||||
Config = new GravographISPostConfig();
|
||||
SaveConfig();
|
||||
}
|
||||
var json = PostSettingsFile.Read(typeof(GravographISPostProcessor).Assembly);
|
||||
Config = json == null
|
||||
? new GravographISPostConfig()
|
||||
: JsonSerializer.Deserialize<GravographISPostConfig>(json, JsonOptions) ?? new GravographISPostConfig();
|
||||
}
|
||||
|
||||
public GravographISPostProcessor(GravographISPostConfig config)
|
||||
@@ -64,12 +56,7 @@ namespace OpenNest.Posts.GravographIS
|
||||
Config = config ?? throw new ArgumentNullException(nameof(config));
|
||||
}
|
||||
|
||||
public void SaveConfig()
|
||||
{
|
||||
var configPath = GetConfigPath();
|
||||
var json = SerializeConfig();
|
||||
File.WriteAllText(configPath, json);
|
||||
}
|
||||
public void SaveConfig() => PostSettingsFile.Write(typeof(GravographISPostProcessor).Assembly, SerializeConfig());
|
||||
|
||||
public string SerializeConfig() => JsonSerializer.Serialize(Config, JsonOptions);
|
||||
|
||||
@@ -78,14 +65,6 @@ namespace OpenNest.Posts.GravographIS
|
||||
JsonSerializer.Deserialize<GravographISPostConfig>(json, JsonOptions)
|
||||
?? throw new JsonException("The post settings are empty.");
|
||||
|
||||
private static string GetConfigPath()
|
||||
{
|
||||
var assemblyPath = typeof(GravographISPostProcessor).Assembly.Location;
|
||||
var dir = Path.GetDirectoryName(assemblyPath);
|
||||
var name = Path.GetFileNameWithoutExtension(assemblyPath);
|
||||
return Path.Combine(dir, name + ".json");
|
||||
}
|
||||
|
||||
public void Post(Nest nest, Stream outputStream)
|
||||
{
|
||||
if (nest == null)
|
||||
|
||||
@@ -7,7 +7,7 @@ building nests and posts the same way:
|
||||
| Kind | Key | What it holds | This PC's own copy |
|
||||
|---|---|---|---|
|
||||
| `machine` | machine id | A Tools > Machine Configuration entry: materials, grades, thicknesses, leads, kerf, cut-offs, motion limits, plate sizes, support grid, clamps | `%APPDATA%\OpenNest\Machines\<id>.json` |
|
||||
| `post` | post type name, e.g. `OpenNest.Posts.CincinnatiCIFiber.CIFiberPostProcessor` | A post's settings, as its JSON file holds them | `<post>.json` beside the post DLL in `Posts\` |
|
||||
| `post` | post type name, e.g. `OpenNest.Posts.CincinnatiCIFiber.CIFiberPostProcessor` | A post's settings, as its JSON file holds them | `%APPDATA%\OpenNest\Posts\<post>.json`, else the shipped `<post>.json` beside the post DLL in `Posts\` until the first save (an update replaces the install folder, so edits are never saved there) |
|
||||
| `clamps` | `default` | Legacy clamp settings, read only to copy them onto a machine once (machines now hold their clamps) | `%APPDATA%\OpenNest\clamps.json` |
|
||||
| `nest-defaults` | `default` | Tools > Nest Defaults: units, sheet size, quadrant, spacing, default machine | `%APPDATA%\OpenNest\defaults.json` |
|
||||
|
||||
|
||||
Reference in new issue
Block a user