Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

M3b: add bounded prism subtract seam with explicit kernel limit diagnostics

Yuechen Lif157ece9bb14
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
index b05a70f9..76d5fc01 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
@@ -318,17 +318,42 @@ public sealed class FirmamentPrimitiveExecutionTests
}
[Theory]
- [InlineData("testdata/firmament/fixtures/m3-prism-boolean-triangular-rejected.firmament", "tri_cut")]
- [InlineData("testdata/firmament/fixtures/m3-prism-boolean-hexagonal-rejected.firmament", "hex_cut")]
- [InlineData("testdata/firmament/fixtures/m3-prism-boolean-slot-rejected.firmament", "slot_cut")]
- public void Compile_PrismBooleanTools_AreExplicitlyRejected(string fixturePath, string featureId)
+ [InlineData("testdata/firmament/fixtures/m3b-valid-box-subtract-triangular-prism.firmament", "tri_cut")]
+ [InlineData("testdata/firmament/fixtures/m3b-valid-box-subtract-hexagonal-prism.firmament", "hex_cut")]
+ [InlineData("testdata/firmament/fixtures/m3b-valid-box-subtract-straight-slot.firmament", "slot_cut")]
+ public void Compile_BoxRoot_PrismSubtract_CanonicalCases_Hit_BoundedKernelLimit(string fixturePath, string featureId)
{
var result = CompileFixture(fixturePath);
Assert.False(result.Compilation.IsSuccess);
Assert.Contains(result.Compilation.Diagnostics, diagnostic =>
diagnostic.Message.Contains($"Boolean feature '{featureId}'", StringComparison.Ordinal)
- && diagnostic.Message.Contains("bounded prism-family booleans are explicitly deferred", StringComparison.Ordinal));
+ && diagnostic.Message.Contains("core M13 boolean rebuild supports box/box and analytic-hole families only", StringComparison.Ordinal));
+ }
+
+ [Theory]
+ [InlineData("testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-triangular-prism.firmament", "tri_cut", "triangular_prism")]
+ [InlineData("testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-hexagonal-prism.firmament", "hex_cut", "hexagonal_prism")]
+ [InlineData("testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-straight-slot.firmament", "slot_cut", "straight_slot")]
+ public void Compile_PrismSubtract_Rejects_NonBoxRoot_Inputs(string fixturePath, string featureId, string toolOp)
+ {
+ var result = CompileFixture(fixturePath);
+
+ Assert.False(result.Compilation.IsSuccess);
+ Assert.Contains(result.Compilation.Diagnostics, diagnostic =>
+ diagnostic.Message.Contains($"Boolean feature '{featureId}'", StringComparison.Ordinal)
+ && diagnostic.Message.Contains("direct box-root source feature", StringComparison.Ordinal)
+ && diagnostic.Message.Contains(toolOp, StringComparison.Ordinal));
+ }
+
+ [Fact]
+ public void Compile_PrismSubtract_Uses_Shared_BoundedPath_Diagnostics()
+ {
+ var result = CompileFixture("testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-triangular-prism.firmament");
+
+ Assert.False(result.Compilation.IsSuccess);
+ Assert.Contains(result.Compilation.Diagnostics, diagnostic =>
+ string.Equals(diagnostic.Source, "firmament.prism-bounded-subtract", StringComparison.Ordinal));
}
[Fact]
diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentBooleanToolBodyFactory.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentBooleanToolBodyFactory.cs
index 756af5e4..b3f0d129 100644
--- a/Aetheris.Kernel.Firmament/Execution/FirmamentBooleanToolBodyFactory.cs
+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentBooleanToolBodyFactory.cs
@@ -69,47 +69,9 @@ internal static class FirmamentBooleanToolBodyFactory
FirmamentPrimitiveToolParsing.ParseScalar(minorRadiusRaw));
}
- if (string.Equals(tool.OpName, "triangular_prism", StringComparison.Ordinal))
+ if (FirmamentPrismFamilyTools.IsPrismTool(tool.OpName))
{
- if (!tool.RawFields.TryGetValue("base_width", out var baseWidthRaw) || string.IsNullOrWhiteSpace(baseWidthRaw)
- || !tool.RawFields.TryGetValue("base_depth", out var baseDepthRaw) || string.IsNullOrWhiteSpace(baseDepthRaw)
- || !tool.RawFields.TryGetValue("height", out var triangularHeightRaw) || string.IsNullOrWhiteSpace(triangularHeightRaw))
- {
- return KernelResult<BrepBody>.Failure([new KernelDiagnostic(KernelDiagnosticCode.ValidationFailed, KernelDiagnosticSeverity.Error, "Boolean execution expected validated nested fields 'with.base_width', 'with.base_depth', and 'with.height' for tool op 'triangular_prism'.")]);
- }
-
- return BrepPrimitives.CreateTriangularPrism(
- FirmamentPrimitiveToolParsing.ParseScalar(baseWidthRaw),
- FirmamentPrimitiveToolParsing.ParseScalar(baseDepthRaw),
- FirmamentPrimitiveToolParsing.ParseScalar(triangularHeightRaw));
- }
-
- if (string.Equals(tool.OpName, "hexagonal_prism", StringComparison.Ordinal))
- {
- if (!tool.RawFields.TryGetValue("across_flats", out var acrossFlatsRaw) || string.IsNullOrWhiteSpace(acrossFlatsRaw)
- || !tool.RawFields.TryGetValue("height", out var hexagonalHeightRaw) || string.IsNullOrWhiteSpace(hexagonalHeightRaw))
- {
- return KernelResult<BrepBody>.Failure([new KernelDiagnostic(KernelDiagnosticCode.ValidationFailed, KernelDiagnosticSeverity.Error, "Boolean execution expected validated nested fields 'with.across_flats' and 'with.height' for tool op 'hexagonal_prism'.")]);
- }
-
- return BrepPrimitives.CreateHexagonalPrism(
- FirmamentPrimitiveToolParsing.ParseScalar(acrossFlatsRaw),
- FirmamentPrimitiveToolParsing.ParseScalar(hexagonalHeightRaw));
- }
-
- if (string.Equals(tool.OpName, "straight_slot", StringComparison.Ordinal))
- {
- if (!tool.RawFields.TryGetValue("length", out var lengthRaw) || string.IsNullOrWhiteSpace(lengthRaw)
- || !tool.RawFields.TryGetValue("width", out var widthRaw) || string.IsNullOrWhiteSpace(widthRaw)
- || !tool.RawFields.TryGetValue("height", out var slotHeightRaw) || string.IsNullOrWhiteSpace(slotHeightRaw))
- {
- return KernelResult<BrepBody>.Failure([new KernelDiagnostic(KernelDiagnosticCode.ValidationFailed, KernelDiagnosticSeverity.Error, "Boolean execution expected validated nested fields 'with.length', 'with.width', and 'with.height' for tool op 'straight_slot'.")]);
- }
-
- return BrepPrimitives.CreateStraightSlot(
- FirmamentPrimitiveToolParsing.ParseScalar(lengthRaw),
- FirmamentPrimitiveToolParsing.ParseScalar(widthRaw),
- FirmamentPrimitiveToolParsing.ParseScalar(slotHeightRaw));
+ return FirmamentPrismFamilyTools.TryCreateBody(tool);
}
return KernelResult<BrepBody>.Failure([new KernelDiagnostic(KernelDiagnosticCode.NotImplemented, KernelDiagnosticSeverity.Error, $"Boolean execution supports nested tool ops 'box', 'cylinder', 'sphere', 'cone', 'torus', 'triangular_prism', 'hexagonal_prism', and 'straight_slot' only. Got '{tool.OpName}'.")]);
diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
index 5cee3d2a..3bdf4d8f 100644
--- a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
@@ -111,17 +111,28 @@ internal static class FirmamentPrimitiveExecutor
return KernelResult<FirmamentPrimitiveExecutionResult>.Failure(toolResult.Diagnostics);
}
- if (IsBoundedPrismTool(boolean.Tool.OpName))
+ if (FirmamentPrismFamilyTools.TryGetDescriptor(boolean.Tool.OpName, out var prismTool))
{
- return KernelResult<FirmamentPrimitiveExecutionResult>.Failure(
- [
- CreateBooleanExecutionFailureDiagnostic(boolean),
- new KernelDiagnostic(
- KernelDiagnosticCode.NotImplemented,
- KernelDiagnosticSeverity.Error,
- $"Boolean feature '{boolean.FeatureId}' ({boolean.Kind.ToString().ToLowerInvariant()}): bounded prism-family booleans are explicitly deferred in M3 implementation mode; standalone primitive execution/export is supported for 'triangular_prism', 'hexagonal_prism', and 'straight_slot' only.",
- Source: "firmament")
- ]);
+ var prismResult = ExecuteBoundedPrismSubtractOnBoxRoot(
+ boolean,
+ prismTool,
+ baseBody,
+ featureGraphStates);
+ if (!prismResult.IsSuccess)
+ {
+ return KernelResult<FirmamentPrimitiveExecutionResult>.Failure(
+ [
+ CreateBooleanExecutionFailureDiagnostic(boolean),
+ .. WithBooleanContext(boolean, prismResult.Diagnostics)
+ ]);
+ }
+
+ var prismBooleanBody = prismResult.Value;
+ executedBooleans.Add(new FirmamentExecutedBoolean(boolean.OpIndex, boolean.FeatureId, boolean.Kind, prismBooleanBody));
+ publishedBodiesByFeatureId[boolean.FeatureId] = prismBooleanBody;
+ booleanExecutionBodiesByFeatureId[boolean.FeatureId] = prismBooleanBody;
+ featureGraphStates[boolean.FeatureId] = FirmamentSafeSubtractFeatureGraphState.Other;
+ continue;
}
var featureGraphValidation = FirmamentSafeSubtractFeatureGraphValidator.ValidateNextBoolean(
@@ -247,11 +258,6 @@ internal static class FirmamentPrimitiveExecutor
|| featureId.Contains("__cir", StringComparison.Ordinal)
|| featureId.Contains("__mir_", StringComparison.Ordinal);
- private static bool IsBoundedPrismTool(string opName)
- => string.Equals(opName, "triangular_prism", StringComparison.Ordinal)
- || string.Equals(opName, "hexagonal_prism", StringComparison.Ordinal)
- || string.Equals(opName, "straight_slot", StringComparison.Ordinal);
-
private static KernelResult<FirmamentExecutedPrimitiveBodies> ExecutePrimitive(FirmamentLoweredPrimitive primitive, IReadOnlyDictionary<string, BrepBody> publishedBodies)
{
var legacyResult = ExecuteLegacyPrimitive(primitive);
@@ -389,28 +395,9 @@ internal static class FirmamentPrimitiveExecutor
return TranslateBody(body, new Vector3D(0d, 0d, height * 0.5d));
}
- if (string.Equals(tool.OpName, "triangular_prism", StringComparison.Ordinal)
- && tool.RawFields.TryGetValue("height", out var triangularHeightRaw)
- && !string.IsNullOrWhiteSpace(triangularHeightRaw))
+ if (FirmamentPrismFamilyTools.IsPrismTool(tool.OpName))
{
- var height = FirmamentPrimitiveToolParsing.ParseScalar(triangularHeightRaw);
- return TranslateBody(body, new Vector3D(0d, 0d, height * 0.5d));
- }
-
- if (string.Equals(tool.OpName, "hexagonal_prism", StringComparison.Ordinal)
- && tool.RawFields.TryGetValue("height", out var hexagonalHeightRaw)
- && !string.IsNullOrWhiteSpace(hexagonalHeightRaw))
- {
- var height = FirmamentPrimitiveToolParsing.ParseScalar(hexagonalHeightRaw);
- return TranslateBody(body, new Vector3D(0d, 0d, height * 0.5d));
- }
-
- if (string.Equals(tool.OpName, "straight_slot", StringComparison.Ordinal)
- && tool.RawFields.TryGetValue("height", out var slotHeightRaw)
- && !string.IsNullOrWhiteSpace(slotHeightRaw))
- {
- var height = FirmamentPrimitiveToolParsing.ParseScalar(slotHeightRaw);
- return TranslateBody(body, new Vector3D(0d, 0d, height * 0.5d));
+ return TranslateBody(body, FirmamentPrismFamilyTools.ResolveDefaultFrameTranslation(tool));
}
return body;
@@ -418,8 +405,12 @@ internal static class FirmamentPrimitiveExecutor
private static bool ShouldUseSemanticToolPlacement(FirmamentLoweredBoolean boolean, BrepBody baseBody, BrepBody toolBody)
{
- if (boolean.Placement is null
- || boolean.Kind != FirmamentLoweredBooleanKind.Subtract)
+ if (boolean.Kind != FirmamentLoweredBooleanKind.Subtract)
+ {
+ return false;
+ }
+
+ if (boolean.Placement is null)
{
return false;
}
@@ -499,6 +490,66 @@ internal static class FirmamentPrimitiveExecutor
return TranslateBody(localFrameBody, placementTranslation);
}
+ private static KernelResult<BrepBody> ExecuteBoundedPrismSubtractOnBoxRoot(
+ FirmamentLoweredBoolean boolean,
+ FirmamentPrismToolDescriptor prismTool,
+ BrepBody baseBody,
+ IReadOnlyDictionary<string, FirmamentSafeSubtractFeatureGraphState> featureGraphStates)
+ {
+ if (boolean.Kind != FirmamentLoweredBooleanKind.Subtract)
+ {
+ return KernelResult<BrepBody>.Failure([
+ new KernelDiagnostic(
+ KernelDiagnosticCode.NotImplemented,
+ KernelDiagnosticSeverity.Error,
+ $"Bounded prism-family boolean support accepts subtract only; got '{boolean.Kind.ToString().ToLowerInvariant()}' for tool op '{prismTool.OpName}'.",
+ Source: "firmament.prism-bounded-subtract")
+ ]);
+ }
+
+ if (!featureGraphStates.TryGetValue(boolean.PrimaryReferenceFeatureId, out var sourceState)
+ || sourceState != FirmamentSafeSubtractFeatureGraphState.BoxRoot)
+ {
+ return KernelResult<BrepBody>.Failure([
+ new KernelDiagnostic(
+ KernelDiagnosticCode.ValidationFailed,
+ KernelDiagnosticSeverity.Error,
+ $"Bounded prism-family subtract requires a direct box-root source feature; '{boolean.PrimaryReferenceFeatureId}' is not a supported box root input for tool op '{prismTool.OpName}'.",
+ Source: "firmament.prism-bounded-subtract")
+ ]);
+ }
+
+ if (boolean.Placement is not null)
+ {
+ return KernelResult<BrepBody>.Failure([
+ new KernelDiagnostic(
+ KernelDiagnosticCode.ValidationFailed,
+ KernelDiagnosticSeverity.Error,
+ $"Bounded prism-family subtract on box-root supports default tool placement only; placement directives are not supported for tool op '{prismTool.OpName}'.",
+ Source: "firmament.prism-bounded-subtract")
+ ]);
+ }
+
+ if (!BrepBooleanBoxRecognition.TryRecognizeAxisAlignedBox(baseBody, ToleranceContext.Default, out _, out var reason))
+ {
+ return KernelResult<BrepBody>.Failure([
+ new KernelDiagnostic(
+ KernelDiagnosticCode.NotImplemented,
+ KernelDiagnosticSeverity.Error,
+ $"Bounded prism-family subtract requires an axis-aligned box root from BrepPrimitives.CreateBox(...); failed to recognize source body ({reason}).",
+ Source: "firmament.prism-bounded-subtract")
+ ]);
+ }
+
+ return KernelResult<BrepBody>.Failure([
+ new KernelDiagnostic(
+ KernelDiagnosticCode.NotImplemented,
+ KernelDiagnosticSeverity.Error,
+ $"Bounded prism-family subtract on box-root is validated, but execution is currently blocked: core M13 boolean rebuild supports box/box and analytic-hole families only; polyhedral prism tools ('{prismTool.OpName}') are not rebuildable yet.",
+ Source: "firmament.prism-bounded-subtract")
+ ]);
+ }
+
private static BrepBody TranslateBody(BrepBody body, Vector3D translation)
{
if (translation == Vector3D.Zero) return body;
diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentPrismFamilyTools.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentPrismFamilyTools.cs
new file mode 100644
index 00000000..a9f15401
--- /dev/null
+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentPrismFamilyTools.cs
@@ -0,0 +1,103 @@
+using Aetheris.Kernel.Core.Brep;
+using Aetheris.Kernel.Core.Diagnostics;
+using Aetheris.Kernel.Core.Math;
+using Aetheris.Kernel.Core.Results;
+using Aetheris.Kernel.Firmament.Lowering;
+
+namespace Aetheris.Kernel.Firmament.Execution;
+
+internal enum FirmamentPrismToolKind
+{
+ TriangularPrism,
+ HexagonalPrism,
+ StraightSlot
+}
+
+internal sealed record FirmamentPrismToolDescriptor(
+ FirmamentPrismToolKind Kind,
+ string OpName,
+ IReadOnlyList<string> RequiredFields,
+ Func<FirmamentLoweredToolOp, KernelResult<BrepBody>> CreateBody,
+ Func<FirmamentLoweredToolOp, double> ResolveHeight);
+
+internal static class FirmamentPrismFamilyTools
+{
+ private static readonly FirmamentPrismToolDescriptor TriangularPrismDescriptor = new(
+ FirmamentPrismToolKind.TriangularPrism,
+ "triangular_prism",
+ ["base_width", "base_depth", "height"],
+ static tool => BrepPrimitives.CreateTriangularPrism(
+ FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["base_width"]),
+ FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["base_depth"]),
+ FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["height"])),
+ static tool => FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["height"]));
+
+ private static readonly FirmamentPrismToolDescriptor HexagonalPrismDescriptor = new(
+ FirmamentPrismToolKind.HexagonalPrism,
+ "hexagonal_prism",
+ ["across_flats", "height"],
+ static tool => BrepPrimitives.CreateHexagonalPrism(
+ FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["across_flats"]),
+ FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["height"])),
+ static tool => FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["height"]));
+
+ private static readonly FirmamentPrismToolDescriptor StraightSlotDescriptor = new(
+ FirmamentPrismToolKind.StraightSlot,
+ "straight_slot",
+ ["length", "width", "height"],
+ static tool => BrepPrimitives.CreateStraightSlot(
+ FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["length"]),
+ FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["width"]),
+ FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["height"])),
+ static tool => FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["height"]));
+
+ private static readonly IReadOnlyDictionary<string, FirmamentPrismToolDescriptor> DescriptorsByOpName =
+ new Dictionary<string, FirmamentPrismToolDescriptor>(StringComparer.Ordinal)
+ {
+ [TriangularPrismDescriptor.OpName] = TriangularPrismDescriptor,
+ [HexagonalPrismDescriptor.OpName] = HexagonalPrismDescriptor,
+ [StraightSlotDescriptor.OpName] = StraightSlotDescriptor
+ };
+
+ public static bool TryGetDescriptor(string opName, out FirmamentPrismToolDescriptor descriptor)
+ => DescriptorsByOpName.TryGetValue(opName, out descriptor!);
+
+ public static bool IsPrismTool(string opName)
+ => DescriptorsByOpName.ContainsKey(opName);
+
+ public static KernelResult<BrepBody> TryCreateBody(FirmamentLoweredToolOp tool)
+ {
+ if (!TryGetDescriptor(tool.OpName, out var descriptor))
+ {
+ return KernelResult<BrepBody>.Failure([
+ new KernelDiagnostic(KernelDiagnosticCode.NotImplemented, KernelDiagnosticSeverity.Error, $"Prism-family tool lookup failed for unsupported op '{tool.OpName}'.")
+ ]);
+ }
+
+ foreach (var requiredField in descriptor.RequiredFields)
+ {
+ if (!tool.RawFields.TryGetValue(requiredField, out var raw) || string.IsNullOrWhiteSpace(raw))
+ {
+ return KernelResult<BrepBody>.Failure([
+ new KernelDiagnostic(
+ KernelDiagnosticCode.ValidationFailed,
+ KernelDiagnosticSeverity.Error,
+ $"Boolean execution expected validated nested field 'with.{requiredField}' for tool op '{descriptor.OpName}'.")
+ ]);
+ }
+ }
+
+ return descriptor.CreateBody(tool);
+ }
+
+ public static Vector3D ResolveDefaultFrameTranslation(FirmamentLoweredToolOp tool)
+ {
+ if (!TryGetDescriptor(tool.OpName, out var descriptor))
+ {
+ return Vector3D.Zero;
+ }
+
+ var height = descriptor.ResolveHeight(tool);
+ return new Vector3D(0d, 0d, height * 0.5d);
+ }
+}
diff --git a/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs b/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs
index 3d2fbafd..23e046d0 100644
--- a/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs
+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs
@@ -4,6 +4,7 @@ using System.Text.Json;
using Aetheris.Kernel.Core.Diagnostics;
using Aetheris.Kernel.Core.Results;
using Aetheris.Kernel.Firmament.Diagnostics;
+using Aetheris.Kernel.Firmament.Execution;
using Aetheris.Kernel.Firmament.ParsedModel;
namespace Aetheris.Kernel.Firmament.Validation;
@@ -102,19 +103,9 @@ internal static class FirmamentBooleanRequiredFieldValidator
return ValidateTorusTool(entry, opIndex, withFields);
}
- if (string.Equals(withOpRaw, "triangular_prism", StringComparison.Ordinal))
+ if (FirmamentPrismFamilyTools.TryGetDescriptor(withOpRaw, out var prismTool))
{
- return ValidateTriangularPrismTool(entry, opIndex, withFields);
- }
-
- if (string.Equals(withOpRaw, "hexagonal_prism", StringComparison.Ordinal))
- {
- return ValidateHexagonalPrismTool(entry, opIndex, withFields);
- }
-
- if (string.Equals(withOpRaw, "straight_slot", StringComparison.Ordinal))
- {
- return ValidateStraightSlotTool(entry, opIndex, withFields);
+ return ValidatePrismTool(entry, opIndex, withFields, prismTool);
}
return KernelResult<bool>.Success(true);
@@ -221,49 +212,32 @@ internal static class FirmamentBooleanRequiredFieldValidator
return KernelResult<bool>.Success(true);
}
- private static KernelResult<bool> ValidateTriangularPrismTool(FirmamentParsedOpEntry entry, int opIndex, IReadOnlyDictionary<string, string> withFields)
+ private static KernelResult<bool> ValidatePrismTool(
+ FirmamentParsedOpEntry entry,
+ int opIndex,
+ IReadOnlyDictionary<string, string> withFields,
+ FirmamentPrismToolDescriptor prismTool)
{
- var baseWidth = ValidatePositiveNumericWithField(entry, opIndex, withFields, "base_width");
- if (!baseWidth.IsSuccess)
+ foreach (var requiredField in prismTool.RequiredFields)
{
- return baseWidth;
- }
-
- var baseDepth = ValidatePositiveNumericWithField(entry, opIndex, withFields, "base_depth");
- if (!baseDepth.IsSuccess)
- {
- return baseDepth;
- }
-
- return ValidatePositiveNumericWithField(entry, opIndex, withFields, "height");
- }
-
- private static KernelResult<bool> ValidateHexagonalPrismTool(FirmamentParsedOpEntry entry, int opIndex, IReadOnlyDictionary<string, string> withFields)
- {
- var acrossFlats = ValidatePositiveNumericWithField(entry, opIndex, withFields, "across_flats");
- if (!acrossFlats.IsSuccess)
- {
- return acrossFlats;
- }
-
- return ValidatePositiveNumericWithField(entry, opIndex, withFields, "height");
- }
-
- private static KernelResult<bool> ValidateStraightSlotTool(FirmamentParsedOpEntry entry, int opIndex, IReadOnlyDictionary<string, string> withFields)
- {
- var length = ValidatePositiveNumericWithField(entry, opIndex, withFields, "length");
- if (!length.IsSuccess)
- {
- return length;
+ var requiredResult = ValidatePositiveNumericWithField(entry, opIndex, withFields, requiredField);
+ if (!requiredResult.IsSuccess)
+ {
+ return requiredResult;
+ }
}
- var width = ValidatePositiveNumericWithField(entry, opIndex, withFields, "width");
- if (!width.IsSuccess)
+ if (prismTool.Kind == FirmamentPrismToolKind.StraightSlot)
{
- return width;
+ _ = TryParseNumeric(withFields["length"], out var length);
+ _ = TryParseNumeric(withFields["width"], out var width);
+ if (length <= width)
+ {
+ return InvalidFieldValue("with.length", opIndex, entry.OpName, "expected a numeric value greater than 'with.width' for straight_slot");
+ }
}
- return ValidatePositiveNumericWithField(entry, opIndex, withFields, "height");
+ return KernelResult<bool>.Success(true);
}
private static KernelResult<bool> ValidatePositiveNumericWithField(FirmamentParsedOpEntry entry, int opIndex, IReadOnlyDictionary<string, string> withFields, string fieldName)
diff --git a/testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-hexagonal-prism.firmament b/testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-hexagonal-prism.firmament
new file mode 100644
index 00000000..2bb3b867
--- /dev/null
+++ b/testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-hexagonal-prism.firmament
@@ -0,0 +1,18 @@
+firmament:
+ version: 1
+
+model:
+ name: m3b_unsupported_cylinder_subtract_hexagonal_prism
+ units: mm
+
+ops[2]:
+ -
+ op: cylinder
+ id: post
+ radius: 15
+ height: 20
+ -
+ op: subtract
+ id: hex_cut
+ from: post
+ with: { op: hexagonal_prism, across_flats: 8, height: 10 }
diff --git a/testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-straight-slot.firmament b/testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-straight-slot.firmament
new file mode 100644
index 00000000..2e74693d
--- /dev/null
+++ b/testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-straight-slot.firmament
@@ -0,0 +1,18 @@
+firmament:
+ version: 1
+
+model:
+ name: m3b_unsupported_cylinder_subtract_straight_slot
+ units: mm
+
+ops[2]:
+ -
+ op: cylinder
+ id: post
+ radius: 15
+ height: 20
+ -
+ op: subtract
+ id: slot_cut
+ from: post
+ with: { op: straight_slot, length: 12, width: 4, height: 10 }
diff --git a/testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-triangular-prism.firmament b/testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-triangular-prism.firmament
new file mode 100644
index 00000000..6f3fa476
--- /dev/null
+++ b/testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-triangular-prism.firmament
@@ -0,0 +1,18 @@
+firmament:
+ version: 1
+
+model:
+ name: m3b_unsupported_cylinder_subtract_triangular_prism
+ units: mm
+
+ops[2]:
+ -
+ op: cylinder
+ id: post
+ radius: 15
+ height: 20
+ -
+ op: subtract
+ id: tri_cut
+ from: post
+ with: { op: triangular_prism, base_width: 10, base_depth: 6, height: 10 }
diff --git a/testdata/firmament/fixtures/m3b-valid-box-subtract-hexagonal-prism.firmament b/testdata/firmament/fixtures/m3b-valid-box-subtract-hexagonal-prism.firmament
new file mode 100644
index 00000000..0d0539b5
--- /dev/null
+++ b/testdata/firmament/fixtures/m3b-valid-box-subtract-hexagonal-prism.firmament
@@ -0,0 +1,17 @@
+firmament:
+ version: 1
+
+model:
+ name: m3b_valid_box_subtract_hexagonal_prism
+ units: mm
+
+ops[2]:
+ -
+ op: box
+ id: base
+ size[3]: [40, 30, 20]
+ -
+ op: subtract
+ id: hex_cut
+ from: base
+ with: { op: hexagonal_prism, across_flats: 12, height: 24 }
diff --git a/testdata/firmament/fixtures/m3b-valid-box-subtract-straight-slot.firmament b/testdata/firmament/fixtures/m3b-valid-box-subtract-straight-slot.firmament
new file mode 100644
index 00000000..9fec36a1
--- /dev/null
+++ b/testdata/firmament/fixtures/m3b-valid-box-subtract-straight-slot.firmament
@@ -0,0 +1,17 @@
+firmament:
+ version: 1
+
+model:
+ name: m3b_valid_box_subtract_straight_slot
+ units: mm
+
+ops[2]:
+ -
+ op: box
+ id: base
+ size[3]: [40, 30, 20]
+ -
+ op: subtract
+ id: slot_cut
+ from: base
+ with: { op: straight_slot, length: 24, width: 8, height: 24 }
diff --git a/testdata/firmament/fixtures/m3b-valid-box-subtract-triangular-prism.firmament b/testdata/firmament/fixtures/m3b-valid-box-subtract-triangular-prism.firmament
new file mode 100644
index 00000000..3c6f7c2c
--- /dev/null
+++ b/testdata/firmament/fixtures/m3b-valid-box-subtract-triangular-prism.firmament
@@ -0,0 +1,17 @@
+firmament:
+ version: 1
+
+model:
+ name: m3b_valid_box_subtract_triangular_prism
+ units: mm
+
+ops[2]:
+ -
+ op: box
+ id: base
+ size[3]: [40, 30, 20]
+ -
+ op: subtract
+ id: tri_cut
+ from: base
+ with: { op: triangular_prism, base_width: 18, base_depth: 10, height: 24 }