Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Verify Firmament sphere export end-to-end

Yuechen Lied8a87fff082
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242ExporterTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242ExporterTests.cs
index 78c7e6cf..a1b7165d 100644
--- a/Aetheris.Kernel.Core.Tests/Step242/Step242ExporterTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242ExporterTests.cs
@@ -1,5 +1,4 @@
using Aetheris.Kernel.Core.Brep;
-using Aetheris.Kernel.Core.Diagnostics;
using Aetheris.Kernel.Core.Step242;
using System.Globalization;
@@ -391,19 +390,20 @@ END-ISO-10303-21;";
}
[Fact]
- public void ExportBody_Sphere_ReturnsNotImplementedDiagnostic_InsteadOfThrowing()
+ public void ExportBody_Sphere_ExportsCanonicalLooplessPrimitiveDeterministically()
{
var sphereResult = BrepPrimitives.CreateSphere(3d);
Assert.True(sphereResult.IsSuccess);
- var export = Step242Exporter.ExportBody(sphereResult.Value);
+ var first = Step242Exporter.ExportBody(sphereResult.Value);
+ var second = Step242Exporter.ExportBody(sphereResult.Value);
- Assert.False(export.IsSuccess);
- var diagnostic = Assert.Single(export.Diagnostics);
- Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);
- Assert.Equal(KernelDiagnosticSeverity.Error, diagnostic.Severity);
- Assert.Equal("Face:1", diagnostic.Source);
- Assert.Contains("boundary loops", diagnostic.Message, StringComparison.Ordinal);
+ Assert.True(first.IsSuccess);
+ Assert.True(second.IsSuccess);
+ Assert.Equal(first.Value, second.Value);
+ Assert.Contains("SPHERICAL_SURFACE", first.Value, StringComparison.Ordinal);
+ Assert.Contains("MANIFOLD_SOLID_BREP", first.Value, StringComparison.Ordinal);
+ Assert.Contains("ADVANCED_FACE('',(),", first.Value, StringComparison.Ordinal);
}
[Fact]
diff --git a/Aetheris.Kernel.Core/Step242/Step242Exporter.cs b/Aetheris.Kernel.Core/Step242/Step242Exporter.cs
index 862fb408..94fdbcc0 100644
--- a/Aetheris.Kernel.Core/Step242/Step242Exporter.cs
+++ b/Aetheris.Kernel.Core/Step242/Step242Exporter.cs
@@ -46,11 +46,6 @@ public static class Step242Exporter
foreach (var face in shell.FaceIds.OrderBy(id => id.Value).Select(model.GetFace))
{
- if (face.LoopIds.Count == 0)
- {
- return Failure("Faces without boundary loops are not supported in M22 export subset.", $"Face:{face.Id.Value}");
- }
-
if (!body.Bindings.TryGetFaceBinding(face.Id, out var faceBinding))
{
return Failure("Face is missing surface binding.", $"Face:{face.Id.Value}");
@@ -61,6 +56,11 @@ public static class Step242Exporter
return Failure("Face surface geometry was not found.", $"Surface:{faceBinding.SurfaceGeometryId.Value}");
}
+ if (face.LoopIds.Count == 0 && !CanExportLooplessFace(body, face, surface))
+ {
+ return Failure("Faces without boundary loops are not supported in M22 export subset unless they are the canonical loopless sphere primitive.", $"Face:{face.Id.Value}");
+ }
+
var surfaceIdResult = BuildSurface(writer, surface, face.Id);
if (!surfaceIdResult.IsSuccess)
{
@@ -226,6 +226,13 @@ public static class Step242Exporter
};
}
+ private static bool CanExportLooplessFace(BrepBody body, Face face, SurfaceGeometry surface) =>
+ surface.Kind == SurfaceGeometryKind.Sphere
+ && body.Topology.Faces.Count() == 1
+ && body.Topology.Edges.Count() == 0
+ && body.Topology.Vertices.Count() == 0
+ && face.LoopIds.Count == 0;
+
private static string BuildAxisPlacement(Step242TextWriter writer, Point3D origin, Direction3D axis, Direction3D referenceAxis)
{
var originId = writer.AddEntity("CARTESIAN_POINT", "$", PointList(origin));
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
index ed291a7e..5954a753 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
@@ -28,6 +28,19 @@ public sealed class FirmamentBuildAndExportTests
"cylinder");
}
+
+ [Fact]
+ public void Run_SphereBasicExample_Writes_Default_Export_Artifact()
+ {
+ AssertExampleBuildAndExport(
+ "testdata/firmament/examples/sphere_basic.firmament",
+ "sphere_basic.step",
+ "ball",
+ 0,
+ "primitive",
+ "sphere");
+ }
+
[Fact]
public void Run_BoxWithHoleExample_Writes_Default_Export_Artifact()
{
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.cs
index a03197fb..624b4552 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.cs
@@ -8,6 +8,7 @@ public sealed class FirmamentExamplePackSmokeTests
[
"testdata/firmament/examples/box_basic.firmament",
"testdata/firmament/examples/cylinder_basic.firmament",
+ "testdata/firmament/examples/sphere_basic.firmament",
"testdata/firmament/examples/box_with_hole.firmament",
"testdata/firmament/examples/placed_primitive.firmament",
"testdata/firmament/examples/cnc_min_tool_radius_demo.firmament"
@@ -30,6 +31,7 @@ public sealed class FirmamentExamplePackSmokeTests
[Theory]
[InlineData("testdata/firmament/examples/box_basic.firmament", "base", 0, "primitive", "box")]
[InlineData("testdata/firmament/examples/cylinder_basic.firmament", "post", 0, "primitive", "cylinder")]
+ [InlineData("testdata/firmament/examples/sphere_basic.firmament", "ball", 0, "primitive", "sphere")]
[InlineData("testdata/firmament/examples/box_with_hole.firmament", "base", 0, "primitive", "box")]
[InlineData("testdata/firmament/examples/placed_primitive.firmament", "post", 1, "primitive", "cylinder")]
public void ExamplePack_GoldenPath_Examples_Export(string fixturePath, string expectedFeatureId, int expectedOpIndex, string expectedBodyCategory, string expectedFeatureKind)
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs
index 0f947522..af7dfd3e 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs
@@ -104,6 +104,28 @@ public sealed class FirmamentStepExporterTests
Assert.Equal(first.Value.StepText, File.ReadAllText(artifactPath));
}
+
+ [Fact]
+ public void Export_SphereExample_Exports_Successfully_With_Metadata_Deterministic_Text_And_Persisted_Artifact()
+ {
+ var first = ExportFixture("testdata/firmament/examples/sphere_basic.firmament");
+ var second = ExportFixture("testdata/firmament/examples/sphere_basic.firmament");
+
+ Assert.True(first.IsSuccess);
+ Assert.True(second.IsSuccess);
+ Assert.Equal("ball", first.Value.ExportedFeatureId);
+ Assert.Equal(0, first.Value.ExportedOpIndex);
+ Assert.Equal("primitive", first.Value.ExportedBodyCategory);
+ Assert.Equal("sphere", first.Value.ExportedFeatureKind);
+ Assert.NotEmpty(first.Value.StepText);
+ Assert.Equal(first.Value.StepText, second.Value.StepText);
+ Assert.Contains("SPHERICAL_SURFACE", first.Value.StepText, StringComparison.Ordinal);
+
+ var artifactPath = WriteExportArtifact("m10d-sphere.step", first.Value.StepText);
+ Assert.True(File.Exists(artifactPath));
+ Assert.Equal(first.Value.StepText, File.ReadAllText(artifactPath));
+ }
+
[Fact]
public void Export_MultipleExecutedGeometryBodies_Selects_Last_Executed_Geometric_Feature_Body()
{
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentValidationExecutionTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentValidationExecutionTests.cs
index ecd01fdd..47bbbffe 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentValidationExecutionTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentValidationExecutionTests.cs
@@ -40,15 +40,15 @@ public sealed class FirmamentValidationExecutionTests
}
[Fact]
- public void Compile_Executes_ExpectExists_For_Empty_SelectorResolution_As_Deterministic_Failure()
+ public void Compile_Rejects_Sphere_Edge_Selector_After_Contract_Is_Reduced_To_Truthful_Surface_Only()
{
var result = CompileFixture("testdata/firmament/fixtures/m6b-invalid-selector-empty.firmament");
- Assert.True(result.Compilation.IsSuccess);
- var validation = Assert.Single(result.Compilation.Value.ValidationExecutionResult!.Validations);
- Assert.True(validation.IsExecuted);
- Assert.False(validation.IsSuccess);
- Assert.Equal("Selector 'sphere.edges' resolved to no topology elements.", validation.Reason);
+ Assert.False(result.Compilation.IsSuccess);
+ var diagnostic = Assert.Single(result.Compilation.Diagnostics);
+ Assert.Equal(
+ "[FIRM-REF-0006] Validation op 'expect_exists' at index 1 has selector port 'edges' not allowed for feature kind 'sphere' on feature id 'sphere' via field 'target'.",
+ diagnostic.Message);
}
[Fact]
@@ -122,6 +122,43 @@ ops[7]:
});
}
+
+ [Fact]
+ public void Compile_Executes_Sphere_Selector_Contract_With_Truthful_Runtime_Counts()
+ {
+ const string source = """
+firmament:
+ version: 1
+
+model:
+ name: sphere_selector_truth
+ units: mm
+
+ops[2]:
+ -
+ op: sphere
+ id: ball
+ radius: 4
+ -
+ op: expect_selectable
+ target: ball.surface
+ count: 1
+""";
+
+ var result = Compile(source);
+
+ Assert.True(result.Compilation.IsSuccess);
+ var validation = Assert.Single(result.Compilation.Value.ValidationExecutionResult!.Validations);
+ Assert.True(validation.IsExecuted);
+ Assert.True(validation.IsSuccess);
+ Assert.Null(validation.Reason);
+
+ var body = Assert.Single(result.Compilation.Value.PrimitiveExecutionResult!.ExecutedPrimitives).Body;
+ Assert.Single(body.Topology.Faces);
+ Assert.Empty(body.Topology.Edges);
+ Assert.Empty(body.Topology.Vertices);
+ }
+
[Fact]
public void Compile_Executes_ExpectSelectable_With_Count_Mismatch_As_Deterministic_Failure()
{
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentValidationTargetFeatureExistenceTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentValidationTargetFeatureExistenceTests.cs
index cac529aa..fe09cc77 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentValidationTargetFeatureExistenceTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentValidationTargetFeatureExistenceTests.cs
@@ -129,6 +129,38 @@ public sealed partial class FirmamentValidationTargetFeatureExistenceTests
var compiler = new FirmamentCompiler();
return compiler.Compile(new FirmamentCompileRequest(new FirmamentSourceDocument(fixtureText)));
}
+
+ [Theory]
+ [InlineData("edges")]
+ [InlineData("vertices")]
+ public void Compiler_Rejects_Sphere_SelectorPorts_Removed_From_Truthful_Contract(string portToken)
+ {
+ var source = $$"""
+firmament:
+ version: 1
+
+model:
+ name: sphere_contract_reduction
+ units: mm
+
+ops[2]:
+ -
+ op: sphere
+ id: sphere
+ radius: 4
+ -
+ op: expect_exists
+ target: sphere.{{portToken}}
+""";
+
+ var result = new FirmamentCompiler().Compile(new FirmamentCompileRequest(new FirmamentSourceDocument(source)));
+
+ Assert.False(result.Compilation.IsSuccess);
+ var diagnostic = Assert.Single(result.Compilation.Diagnostics);
+ Assert.Equal(
+ $"[{FirmamentDiagnosticCodes.ValidationTargetSelectorPortNotAllowedForFeatureKind.Value}] Validation op 'expect_exists' at index 1 has selector port '{portToken}' not allowed for feature kind 'sphere' on feature id 'sphere' via field 'target'.",
+ diagnostic.Message);
+ }
}
public sealed partial class FirmamentValidationTargetFeatureExistenceTests
@@ -139,7 +171,6 @@ public sealed partial class FirmamentValidationTargetFeatureExistenceTests
[InlineData("cyl.side_face", "Face", "One")]
[InlineData("cyl.circular_edges", "EdgeSet", "Many")]
[InlineData("sphere.surface", "Face", "One")]
- [InlineData("sphere.vertices", "VertexSet", "Many")]
public void Compiler_Attaches_SelectorContractMetadata_For_Legal_SelectorTargets(string selectorTarget, string expectedResultKind, string expectedCardinality)
{
var source = $$"""
diff --git a/Aetheris.Kernel.Firmament/Validation/FirmamentSelectorContracts.cs b/Aetheris.Kernel.Firmament/Validation/FirmamentSelectorContracts.cs
index 66528d5b..3bcccdcd 100644
--- a/Aetheris.Kernel.Firmament/Validation/FirmamentSelectorContracts.cs
+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentSelectorContracts.cs
@@ -28,9 +28,7 @@ internal static class FirmamentSelectorContracts
private static readonly IReadOnlyDictionary<string, FirmamentSelectorPortContract> SpherePorts =
new Dictionary<string, FirmamentSelectorPortContract>(StringComparer.Ordinal)
{
- ["surface"] = new(FirmamentSelectorResultKind.Face, FirmamentSelectorCardinality.One),
- ["edges"] = new(FirmamentSelectorResultKind.EdgeSet, FirmamentSelectorCardinality.Many),
- ["vertices"] = new(FirmamentSelectorResultKind.VertexSet, FirmamentSelectorCardinality.Many)
+ ["surface"] = new(FirmamentSelectorResultKind.Face, FirmamentSelectorCardinality.One)
};
private static readonly IReadOnlyDictionary<string, FirmamentSelectorPortContract> BooleanPorts =
diff --git a/docs/firmament-selectors.md b/docs/firmament-selectors.md
index 21454e5a..9ce856a6 100644
--- a/docs/firmament-selectors.md
+++ b/docs/firmament-selectors.md
@@ -44,8 +44,12 @@ Current verified primitive-body topology for `cylinder` is:
#### `sphere`
- `surface` → `Face`, `One`
-- `edges` → `EdgeSet`, `Many`
-- `vertices` → `VertexSet`, `Many`
+
+Current verified primitive-body topology for `sphere` is:
+
+- `surface` = 1 spherical face
+- `edges` = 0 (not part of the truthful selector contract)
+- `vertices` = 0 (not part of the truthful selector contract)
### Boolean features
diff --git a/testdata/firmament/examples/README.md b/testdata/firmament/examples/README.md
index 8da3ba49..ef42cccf 100644
--- a/testdata/firmament/examples/README.md
+++ b/testdata/firmament/examples/README.md
@@ -4,6 +4,7 @@ This directory contains small canonical Firmament examples for the current v1 su
- `box_basic.firmament` — minimal single-box golden-path example; helper export path: `testdata/firmament/exports/box_basic.step`.
- `cylinder_basic.firmament` — minimal single-cylinder export example; helper export path: `testdata/firmament/exports/cylinder_basic.step`.
+- `sphere_basic.firmament` — minimal single-sphere export example; helper export path: `testdata/firmament/exports/sphere_basic.step`.
- `box_with_hole.firmament` — box plus subtract-with-cylinder boolean syntax example; helper export path: `testdata/firmament/exports/box_with_hole.step`.
- `placed_primitive.firmament` — selector-based placement using `place.on` and `offset[3]`; helper export path: `testdata/firmament/exports/placed_primitive.step`.
- `cnc_min_tool_radius_demo.firmament` — schema-aware CNC example using `minimum_tool_radius` with a subtract cylinder sized to pass the current rule.
diff --git a/testdata/firmament/examples/sphere_basic.firmament b/testdata/firmament/examples/sphere_basic.firmament
new file mode 100644
index 00000000..39930a02
--- /dev/null
+++ b/testdata/firmament/examples/sphere_basic.firmament
@@ -0,0 +1,12 @@
+firmament:
+ version: 1
+
+model:
+ name: sphere_basic
+ units: mm
+
+ops[1]:
+ -
+ op: sphere
+ id: ball
+ radius: 12
diff --git a/testdata/firmament/exports/m10d-sphere.step b/testdata/firmament/exports/m10d-sphere.step
new file mode 100644
index 00000000..6f2a82c2
--- /dev/null
+++ b/testdata/firmament/exports/m10d-sphere.step
@@ -0,0 +1,30 @@
+ISO-10303-21;
+HEADER;
+FILE_DESCRIPTION(('Aetheris AP242 subset export'),'2;1');
+FILE_NAME('aetheris_export.step','1970-01-01T00:00:00',('Aetheris'),('Aetheris'),'Aetheris.Kernel','Aetheris.Kernel','');
+FILE_SCHEMA(('AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF'));
+ENDSEC;
+DATA;
+#1=CARTESIAN_POINT($,(0,0,0));
+#2=DIRECTION($,(0,0,1));
+#3=DIRECTION($,(1,0,0));
+#4=AXIS2_PLACEMENT_3D($,#1,#2,#3);
+#5=SPHERICAL_SURFACE($,#4,12);
+#6=ADVANCED_FACE('',(),#5,.T.);
+#7=CLOSED_SHELL($,(#6));
+#8=MANIFOLD_SOLID_BREP('AetherisBody',#7);
+#9=APPLICATION_CONTEXT('mechanical design');
+#10=PRODUCT_CONTEXT('',#9,'mechanical');
+#11=PRODUCT('AETHERIS','AetherisBody','',(#10));
+#12=PRODUCT_DEFINITION_FORMATION('','',#11);
+#13=PRODUCT_DEFINITION_CONTEXT('design',#9,'design');
+#14=PRODUCT_DEFINITION('','',#12,#13);
+#15=PRODUCT_DEFINITION_SHAPE('','',#14);
+#16=(LENGTH_UNIT()NAMED_UNIT(*)SI_UNIT(.MILLI.,.METRE.));
+#17=(NAMED_UNIT(*)PLANE_ANGLE_UNIT()SI_UNIT($,.RADIAN.));
+#18=(NAMED_UNIT(*)SI_UNIT($,.STERADIAN.)SOLID_ANGLE_UNIT());
+#19=(GEOMETRIC_REPRESENTATION_CONTEXT(3)GLOBAL_UNIT_ASSIGNED_CONTEXT((#16,#17,#18))REPRESENTATION_CONTEXT('3','3D'));
+#20=SHAPE_REPRESENTATION('AetherisBody',(#8),#19);
+#21=SHAPE_DEFINITION_REPRESENTATION(#15,#20);
+ENDSEC;
+END-ISO-10303-21;
diff --git a/testdata/firmament/exports/sphere_basic.step b/testdata/firmament/exports/sphere_basic.step
new file mode 100644
index 00000000..6f2a82c2
--- /dev/null
+++ b/testdata/firmament/exports/sphere_basic.step
@@ -0,0 +1,30 @@
+ISO-10303-21;
+HEADER;
+FILE_DESCRIPTION(('Aetheris AP242 subset export'),'2;1');
+FILE_NAME('aetheris_export.step','1970-01-01T00:00:00',('Aetheris'),('Aetheris'),'Aetheris.Kernel','Aetheris.Kernel','');
+FILE_SCHEMA(('AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF'));
+ENDSEC;
+DATA;
+#1=CARTESIAN_POINT($,(0,0,0));
+#2=DIRECTION($,(0,0,1));
+#3=DIRECTION($,(1,0,0));
+#4=AXIS2_PLACEMENT_3D($,#1,#2,#3);
+#5=SPHERICAL_SURFACE($,#4,12);
+#6=ADVANCED_FACE('',(),#5,.T.);
+#7=CLOSED_SHELL($,(#6));
+#8=MANIFOLD_SOLID_BREP('AetherisBody',#7);
+#9=APPLICATION_CONTEXT('mechanical design');
+#10=PRODUCT_CONTEXT('',#9,'mechanical');
+#11=PRODUCT('AETHERIS','AetherisBody','',(#10));
+#12=PRODUCT_DEFINITION_FORMATION('','',#11);
+#13=PRODUCT_DEFINITION_CONTEXT('design',#9,'design');
+#14=PRODUCT_DEFINITION('','',#12,#13);
+#15=PRODUCT_DEFINITION_SHAPE('','',#14);
+#16=(LENGTH_UNIT()NAMED_UNIT(*)SI_UNIT(.MILLI.,.METRE.));
+#17=(NAMED_UNIT(*)PLANE_ANGLE_UNIT()SI_UNIT($,.RADIAN.));
+#18=(NAMED_UNIT(*)SI_UNIT($,.STERADIAN.)SOLID_ANGLE_UNIT());
+#19=(GEOMETRIC_REPRESENTATION_CONTEXT(3)GLOBAL_UNIT_ASSIGNED_CONTEXT((#16,#17,#18))REPRESENTATION_CONTEXT('3','3D'));
+#20=SHAPE_REPRESENTATION('AetherisBody',(#8),#19);
+#21=SHAPE_DEFINITION_REPRESENTATION(#15,#20);
+ENDSEC;
+END-ISO-10303-21;
diff --git a/testdata/firmament/fixtures/m4a-valid-mixed-bare-and-selector-targets.firmament b/testdata/firmament/fixtures/m4a-valid-mixed-bare-and-selector-targets.firmament
index ff4edc52..60f2b25c 100644
--- a/testdata/firmament/fixtures/m4a-valid-mixed-bare-and-selector-targets.firmament
+++ b/testdata/firmament/fixtures/m4a-valid-mixed-bare-and-selector-targets.firmament
@@ -18,5 +18,5 @@ ops[4]:
target: core.surface
-
op: expect_selectable
- target: core.edges
+ target: core.surface
count: 1