Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

FORGE-M0c: route reusable library parts via Firmament connector

Yuechen Lidbb8b22ce88e
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentConnectorLibraryPartTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentConnectorLibraryPartTests.cs
new file mode 100644
index 00000000..4515c666
--- /dev/null
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentConnectorLibraryPartTests.cs
@@ -0,0 +1,54 @@
+using Aetheris.Kernel.Core.Geometry;
+using Aetheris.Kernel.Firmament.Connectors;
+using Aetheris.Kernel.Firmament.Lanes;
+using Aetheris.Kernel.Firmament.Lowering;
+using Aetheris.Kernel.Firmament.ParsedModel;
+using Aetheris.Kernel.StandardLibrary;
+
+namespace Aetheris.Kernel.Firmament.Tests;
+
+public sealed class FirmamentConnectorLibraryPartTests
+{
+ [Fact]
+ public void StandardLibrary_CubeWithHole_Part_Succeeds()
+ {
+ var result = StandardLibraryReusableParts.CreateCubeWithCylindricalHole();
+
+ Assert.True(result.IsSuccess);
+ Assert.NotEmpty(result.Value.Topology.Faces);
+ Assert.Contains(
+ result.Value.Topology.Faces,
+ face => result.Value.TryGetFaceSurfaceGeometry(face.Id, out var surface)
+ && surface?.Kind == SurfaceGeometryKind.Cylinder);
+ }
+
+ [Fact]
+ public void Firmament_Connector_Resolves_StandardLibrary_Part()
+ {
+ var result = FirmamentPartLibraryConnector.ResolvePart("standard_library/cube_with_cylindrical_hole");
+
+ Assert.True(result.IsSuccess);
+ Assert.NotEmpty(result.Value.Topology.Faces);
+ }
+
+ [Fact]
+ public void Firmament_Uses_CubeWithHole_LibraryPart_EndToEnd()
+ {
+ var source = FirmamentCorpusHarness.ReadFixtureText("testdata/firmament/examples/library_part_cube_with_hole_basic.firmament");
+
+ var compile = FirmamentCorpusHarness.Compile(source);
+
+ Assert.True(compile.Compilation.IsSuccess);
+ var execution = compile.Compilation.Value.PrimitiveExecutionResult!;
+ var primitive = Assert.Single(execution.ExecutedPrimitives);
+ Assert.Equal("lib_part_1", primitive.FeatureId);
+ Assert.Equal(FirmamentLoweredPrimitiveKind.LibraryPart, primitive.Kind);
+ }
+
+ [Fact]
+ public void LaneConnectorResponsibility_Is_Not_Blurred()
+ {
+ Assert.False(FirmamentLaneOperationCatalog.IsLaneRoutedOperation(FirmamentKnownOpKind.LibraryPart));
+ Assert.True(FirmamentLaneOperationCatalog.IsLaneRoutedOperation(FirmamentKnownOpKind.RoundedCornerBox));
+ }
+}
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.cs
index f945d5f8..8ef919e9 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.cs
@@ -16,6 +16,7 @@ public sealed class FirmamentExamplePackSmokeTests
"testdata/firmament/examples/hexagonal_prism_basic.firmament",
"testdata/firmament/examples/straight_slot_basic.firmament",
"testdata/firmament/examples/rounded_corner_box_basic.firmament",
+ "testdata/firmament/examples/library_part_cube_with_hole_basic.firmament",
"testdata/firmament/examples/box_add_basic.firmament",
"testdata/firmament/examples/boolean_add_basic.firmament",
"testdata/firmament/examples/boolean_subtract_basic.firmament",
@@ -53,6 +54,7 @@ public sealed class FirmamentExamplePackSmokeTests
[InlineData("testdata/firmament/examples/hexagonal_prism_basic.firmament", "hex1", 0, "primitive", "hexagonalprism")]
[InlineData("testdata/firmament/examples/straight_slot_basic.firmament", "slot1", 0, "primitive", "straightslot")]
[InlineData("testdata/firmament/examples/rounded_corner_box_basic.firmament", "rbox1", 0, "primitive", "roundedcornerbox")]
+ [InlineData("testdata/firmament/examples/library_part_cube_with_hole_basic.firmament", "lib_part_1", 0, "primitive", "librarypart")]
[InlineData("testdata/firmament/examples/box_add_basic.firmament", "joined", 1, "boolean", "add")]
[InlineData("testdata/firmament/examples/boolean_add_basic.firmament", "joined", 2, "boolean", "add")]
[InlineData("testdata/firmament/examples/boolean_subtract_basic.firmament", "carved", 2, "boolean", "subtract")]
diff --git a/Aetheris.Kernel.Firmament/Connectors/FirmamentPartLibraryConnector.cs b/Aetheris.Kernel.Firmament/Connectors/FirmamentPartLibraryConnector.cs
new file mode 100644
index 00000000..b9ce2316
--- /dev/null
+++ b/Aetheris.Kernel.Firmament/Connectors/FirmamentPartLibraryConnector.cs
@@ -0,0 +1,29 @@
+using Aetheris.Kernel.Core.Brep;
+using Aetheris.Kernel.Core.Diagnostics;
+using Aetheris.Kernel.Core.Results;
+using Aetheris.Kernel.StandardLibrary;
+
+namespace Aetheris.Kernel.Firmament.Connectors;
+
+internal static class FirmamentPartLibraryConnector
+{
+ private const string StandardLibraryPrefix = "standard_library/";
+
+ public static KernelResult<BrepBody> ResolvePart(string partReference)
+ {
+ ArgumentException.ThrowIfNullOrWhiteSpace(partReference);
+
+ if (!partReference.StartsWith(StandardLibraryPrefix, StringComparison.Ordinal))
+ {
+ return KernelResult<BrepBody>.Failure([
+ new KernelDiagnostic(
+ KernelDiagnosticCode.InvalidArgument,
+ KernelDiagnosticSeverity.Error,
+ $"Part reference '{partReference}' is not mapped by the Firmament connector. Expected prefix '{StandardLibraryPrefix}'.")
+ ]);
+ }
+
+ var partName = partReference[StandardLibraryPrefix.Length..];
+ return StandardLibraryReusableParts.TryCreate(partName);
+ }
+}
diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
index e637b0b1..6cc7f491 100644
--- a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
@@ -11,6 +11,7 @@ using Aetheris.Kernel.Core.Math;
using Aetheris.Kernel.Core.Numerics;
using Aetheris.Kernel.Core.Results;
using Aetheris.Kernel.Core.Topology;
+using Aetheris.Kernel.Firmament.Connectors;
using Aetheris.Kernel.Firmament.Lowering;
using Aetheris.Kernel.Firmament.Validation;
using Aetheris.Kernel.StandardLibrary;
@@ -417,6 +418,8 @@ internal static class FirmamentPrimitiveExecutor
((FirmamentLoweredRoundedCornerBoxParameters)primitive.Parameters).Depth,
((FirmamentLoweredRoundedCornerBoxParameters)primitive.Parameters).Height,
((FirmamentLoweredRoundedCornerBoxParameters)primitive.Parameters).CornerRadius),
+ FirmamentLoweredPrimitiveKind.LibraryPart => FirmamentPartLibraryConnector.ResolvePart(
+ ((FirmamentLoweredLibraryPartParameters)primitive.Parameters).PartReference),
_ => KernelResult<BrepBody>.Failure([new KernelDiagnostic(KernelDiagnosticCode.NotImplemented, KernelDiagnosticSeverity.Error, $"Primitive execution for kind '{primitive.Kind}' is not implemented.")])
};
}
diff --git a/Aetheris.Kernel.Firmament/Formatting/FirmamentCanonicalFormatter.cs b/Aetheris.Kernel.Firmament/Formatting/FirmamentCanonicalFormatter.cs
index 9bd505b9..358b3d31 100644
--- a/Aetheris.Kernel.Firmament/Formatting/FirmamentCanonicalFormatter.cs
+++ b/Aetheris.Kernel.Firmament/Formatting/FirmamentCanonicalFormatter.cs
@@ -173,6 +173,9 @@ internal static class FirmamentCanonicalFormatter
EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "height");
EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "corner_radius");
break;
+ case FirmamentKnownOpKind.LibraryPart:
+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "part");
+ break;
case FirmamentKnownOpKind.Add:
EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "to");
EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "with");
diff --git a/Aetheris.Kernel.Firmament/Lanes/FirmamentLaneOperationCatalog.cs b/Aetheris.Kernel.Firmament/Lanes/FirmamentLaneOperationCatalog.cs
new file mode 100644
index 00000000..82ce878a
--- /dev/null
+++ b/Aetheris.Kernel.Firmament/Lanes/FirmamentLaneOperationCatalog.cs
@@ -0,0 +1,8 @@
+using Aetheris.Kernel.Firmament.ParsedModel;
+
+namespace Aetheris.Kernel.Firmament.Lanes;
+
+internal static class FirmamentLaneOperationCatalog
+{
+ public static bool IsLaneRoutedOperation(FirmamentKnownOpKind kind) => kind != FirmamentKnownOpKind.LibraryPart;
+}
diff --git a/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLowerer.cs b/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLowerer.cs
index 69a845a1..806ee8ca 100644
--- a/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLowerer.cs
+++ b/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLowerer.cs
@@ -120,6 +120,15 @@ internal static class FirmamentPrimitiveLowerer
Placement: LowerPlacement(entry.Placement)));
break;
+ case FirmamentKnownOpKind.LibraryPart:
+ loweredPrimitives.Add(new FirmamentLoweredPrimitive(
+ OpIndex: index,
+ FeatureId: entry.RawFields["id"],
+ Kind: FirmamentLoweredPrimitiveKind.LibraryPart,
+ Parameters: new FirmamentLoweredLibraryPartParameters(entry.RawFields["part"]),
+ Placement: LowerPlacement(entry.Placement)));
+ break;
+
case FirmamentKnownOpKind.Add:
loweredBooleans.Add(LowerBoolean(index, entry, FirmamentLoweredBooleanKind.Add, "to"));
break;
diff --git a/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLoweringPlan.cs b/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLoweringPlan.cs
index dad59e55..e37d21c5 100644
--- a/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLoweringPlan.cs
+++ b/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLoweringPlan.cs
@@ -59,7 +59,8 @@ public enum FirmamentLoweredPrimitiveKind
TriangularPrism,
HexagonalPrism,
StraightSlot,
- RoundedCornerBox
+ RoundedCornerBox,
+ LibraryPart
}
public abstract record FirmamentLoweredPrimitiveParameters;
@@ -102,3 +103,6 @@ public sealed record FirmamentLoweringSkippedOp(
FirmamentKnownOpKind KnownKind,
FirmamentOpFamily Family,
string Reason);
+
+public sealed record FirmamentLoweredLibraryPartParameters(string PartReference)
+ : FirmamentLoweredPrimitiveParameters;
diff --git a/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.cs b/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.cs
index a8e0214d..818154ec 100644
--- a/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.cs
+++ b/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.cs
@@ -11,6 +11,7 @@ public enum FirmamentKnownOpKind
HexagonalPrism,
StraightSlot,
RoundedCornerBox,
+ LibraryPart,
Add,
Subtract,
Intersect,
@@ -39,6 +40,7 @@ internal static class FirmamentKnownOpKinds
["hexagonal_prism"] = FirmamentKnownOpKind.HexagonalPrism,
["straight_slot"] = FirmamentKnownOpKind.StraightSlot,
["rounded_corner_box"] = FirmamentKnownOpKind.RoundedCornerBox,
+ ["library_part"] = FirmamentKnownOpKind.LibraryPart,
["add"] = FirmamentKnownOpKind.Add,
["subtract"] = FirmamentKnownOpKind.Subtract,
["intersect"] = FirmamentKnownOpKind.Intersect,
@@ -68,6 +70,7 @@ internal static class FirmamentKnownOpKinds
FirmamentKnownOpKind.HexagonalPrism => FirmamentOpFamily.Primitive,
FirmamentKnownOpKind.StraightSlot => FirmamentOpFamily.Primitive,
FirmamentKnownOpKind.RoundedCornerBox => FirmamentOpFamily.Primitive,
+ FirmamentKnownOpKind.LibraryPart => FirmamentOpFamily.Primitive,
FirmamentKnownOpKind.Add => FirmamentOpFamily.Boolean,
FirmamentKnownOpKind.Subtract => FirmamentOpFamily.Boolean,
FirmamentKnownOpKind.Intersect => FirmamentOpFamily.Boolean,
diff --git a/Aetheris.Kernel.Firmament/README.md b/Aetheris.Kernel.Firmament/README.md
index 766323e8..2e37bd41 100644
--- a/Aetheris.Kernel.Firmament/README.md
+++ b/Aetheris.Kernel.Firmament/README.md
@@ -18,3 +18,6 @@ The top-level lanes (`Connectors`, `ParsedModel`, `Lanes`, `Mapping`, `Diagnosti
Pre-M0 composition seam note: `ImportOrchestrator.CreateDefault(...)` now supports additive registration while keeping STEP/AP242 as the default import composition, so Firmament can later register its own source-family connector/lane without reshaping STEP-specific wiring.
Canonical corpus note: repository `.firmament` fixtures under `testdata/firmament/fixtures/` are maintained only in canonical TOON-style Firmament syntax; JSON-shaped source text is supported by parser compatibility but is not canonical corpus form.
+
+
+FORGE-M0c note: reusable external/library parts are routed through `Connectors/FirmamentPartLibraryConnector.cs` (currently `standard_library/*`), while operation/schema parsing/validation/lowering remains lane-owned.
diff --git a/Aetheris.Kernel.Firmament/Validation/FirmamentPmiValidator.cs b/Aetheris.Kernel.Firmament/Validation/FirmamentPmiValidator.cs
index b1e1f8b8..55fbabee 100644
--- a/Aetheris.Kernel.Firmament/Validation/FirmamentPmiValidator.cs
+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentPmiValidator.cs
@@ -326,6 +326,7 @@ internal static class FirmamentPmiValidator
or FirmamentKnownOpKind.HexagonalPrism
or FirmamentKnownOpKind.StraightSlot
or FirmamentKnownOpKind.RoundedCornerBox
+ or FirmamentKnownOpKind.LibraryPart
or FirmamentKnownOpKind.Add
or FirmamentKnownOpKind.Subtract
or FirmamentKnownOpKind.Intersect
diff --git a/Aetheris.Kernel.Firmament/Validation/FirmamentPrimitiveRequiredFieldValidator.cs b/Aetheris.Kernel.Firmament/Validation/FirmamentPrimitiveRequiredFieldValidator.cs
index fc09177d..7bd7073c 100644
--- a/Aetheris.Kernel.Firmament/Validation/FirmamentPrimitiveRequiredFieldValidator.cs
+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentPrimitiveRequiredFieldValidator.cs
@@ -33,6 +33,7 @@ internal static class FirmamentPrimitiveRequiredFieldValidator
FirmamentKnownOpKind.HexagonalPrism => ValidateHexagonalPrism(entry, index),
FirmamentKnownOpKind.StraightSlot => ValidateStraightSlot(entry, index),
FirmamentKnownOpKind.RoundedCornerBox => ValidateRoundedCornerBox(entry, index),
+ FirmamentKnownOpKind.LibraryPart => ValidateLibraryPart(entry, index),
_ => KernelResult<bool>.Success(true)
};
@@ -308,6 +309,27 @@ internal static class FirmamentPrimitiveRequiredFieldValidator
return ValidatePlacement(entry, opIndex);
}
+
+ private static KernelResult<bool> ValidateLibraryPart(FirmamentParsedOpEntry entry, int opIndex)
+ {
+ if (!TryGetRequiredNonEmptyScalar(entry, "id", opIndex, out var missingOrTypeDiagnostic))
+ {
+ return KernelResult<bool>.Failure([missingOrTypeDiagnostic!]);
+ }
+
+ if (!TryGetRequiredNonEmptyScalar(entry, "part", opIndex, out var partDiagnostic))
+ {
+ return KernelResult<bool>.Failure([partDiagnostic!]);
+ }
+
+ var placementResult = ValidatePlacement(entry, opIndex);
+ if (!placementResult.IsSuccess)
+ {
+ return placementResult;
+ }
+
+ return KernelResult<bool>.Success(true);
+ }
private static KernelResult<bool> ValidateStraightSlot(FirmamentParsedOpEntry entry, int opIndex)
{
if (!TryGetRequiredNonEmptyScalar(entry, "id", opIndex, out var missingOrTypeDiagnostic))
diff --git a/Aetheris.Kernel.Firmament/Validation/FirmamentSelectorContracts.cs b/Aetheris.Kernel.Firmament/Validation/FirmamentSelectorContracts.cs
index 7d0b8716..0084889e 100644
--- a/Aetheris.Kernel.Firmament/Validation/FirmamentSelectorContracts.cs
+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentSelectorContracts.cs
@@ -74,6 +74,7 @@ internal static class FirmamentSelectorContracts
case FirmamentKnownOpKind.HexagonalPrism:
case FirmamentKnownOpKind.StraightSlot:
case FirmamentKnownOpKind.RoundedCornerBox:
+ case FirmamentKnownOpKind.LibraryPart:
allowedPorts = BoxAllowedPorts;
return true;
case FirmamentKnownOpKind.Cone:
@@ -125,6 +126,7 @@ internal static class FirmamentSelectorContracts
case FirmamentKnownOpKind.HexagonalPrism:
case FirmamentKnownOpKind.StraightSlot:
case FirmamentKnownOpKind.RoundedCornerBox:
+ case FirmamentKnownOpKind.LibraryPart:
contracts = BoxPorts;
return true;
case FirmamentKnownOpKind.Cone:
diff --git a/Aetheris.Kernel.StandardLibrary/StandardLibraryReusableParts.cs b/Aetheris.Kernel.StandardLibrary/StandardLibraryReusableParts.cs
new file mode 100644
index 00000000..ee033c8b
--- /dev/null
+++ b/Aetheris.Kernel.StandardLibrary/StandardLibraryReusableParts.cs
@@ -0,0 +1,44 @@
+using Aetheris.Kernel.Core.Brep;
+using Aetheris.Kernel.Core.Brep.Boolean;
+using Aetheris.Kernel.Core.Diagnostics;
+using Aetheris.Kernel.Core.Results;
+
+namespace Aetheris.Kernel.StandardLibrary;
+
+public static class StandardLibraryReusableParts
+{
+ public const string CubeWithCylindricalHolePartName = "cube_with_cylindrical_hole";
+
+ public static KernelResult<BrepBody> TryCreate(string partName)
+ {
+ return string.Equals(partName, CubeWithCylindricalHolePartName, StringComparison.Ordinal)
+ ? CreateCubeWithCylindricalHole()
+ : KernelResult<BrepBody>.Failure([
+ new KernelDiagnostic(
+ KernelDiagnosticCode.InvalidArgument,
+ KernelDiagnosticSeverity.Error,
+ $"StandardLibrary part '{partName}' was not found.")
+ ]);
+ }
+
+ public static KernelResult<BrepBody> CreateCubeWithCylindricalHole()
+ {
+ const double cubeSize = 20d;
+ const double holeRadius = 3d;
+ const double holeHeight = 24d;
+
+ var cubeResult = BrepPrimitives.CreateBox(cubeSize, cubeSize, cubeSize);
+ if (!cubeResult.IsSuccess)
+ {
+ return cubeResult;
+ }
+
+ var holeResult = BrepPrimitives.CreateCylinder(holeRadius, holeHeight);
+ if (!holeResult.IsSuccess)
+ {
+ return holeResult;
+ }
+
+ return BrepBoolean.Subtract(cubeResult.Value, holeResult.Value);
+ }
+}
diff --git a/testdata/firmament/examples/library_part_cube_with_hole_basic.firmament b/testdata/firmament/examples/library_part_cube_with_hole_basic.firmament
new file mode 100644
index 00000000..be8f1350
--- /dev/null
+++ b/testdata/firmament/examples/library_part_cube_with_hole_basic.firmament
@@ -0,0 +1,12 @@
+firmament:
+ version: 1
+
+model:
+ name: library_part_cube_with_hole_basic
+ units: mm
+
+ops[1]:
+ -
+ op: library_part
+ id: lib_part_1
+ part: standard_library/cube_with_cylindrical_hole