Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Verify Firmament cylinder export and selector contract
Yuechen Lic00357f37c0c
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.csindex ab0f5c29..ed291a7e 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs@@ -16,6 +16,18 @@ public sealed class FirmamentBuildAndExportTests"box");}+ [Fact]+ public void Run_CylinderBasicExample_Writes_Default_Export_Artifact()+ {+ AssertExampleBuildAndExport(+ "testdata/firmament/examples/cylinder_basic.firmament",+ "cylinder_basic.step",+ "post",+ 0,+ "primitive",+ "cylinder");+ }+[Fact]public void Run_BoxWithHoleExample_Writes_Default_Export_Artifact(){diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.csindex aa654c85..a03197fb 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.cs@@ -7,6 +7,7 @@ public sealed class FirmamentExamplePackSmokeTestspublic static TheoryData<string> ExampleFiles =>["testdata/firmament/examples/box_basic.firmament",+ "testdata/firmament/examples/cylinder_basic.firmament","testdata/firmament/examples/box_with_hole.firmament","testdata/firmament/examples/placed_primitive.firmament","testdata/firmament/examples/cnc_min_tool_radius_demo.firmament"@@ -28,6 +29,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/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.csindex efcf46d2..0f947522 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs@@ -83,6 +83,27 @@ public sealed class FirmamentStepExporterTestsAssert.Equal(first.Value.StepText, second.Value.StepText);}+ [Fact]+ public void Export_CylinderExample_Exports_Successfully_With_Metadata_Deterministic_Text_And_Persisted_Artifact()+ {+ var first = ExportFixture("testdata/firmament/examples/cylinder_basic.firmament");+ var second = ExportFixture("testdata/firmament/examples/cylinder_basic.firmament");++ Assert.True(first.IsSuccess);+ Assert.True(second.IsSuccess);+ Assert.Equal("post", first.Value.ExportedFeatureId);+ Assert.Equal(0, first.Value.ExportedOpIndex);+ Assert.Equal("primitive", first.Value.ExportedBodyCategory);+ Assert.Equal("cylinder", first.Value.ExportedFeatureKind);+ Assert.NotEmpty(first.Value.StepText);+ Assert.Equal(first.Value.StepText, second.Value.StepText);+ Assert.Contains("CYLINDRICAL_SURFACE", first.Value.StepText, StringComparison.Ordinal);++ var artifactPath = WriteExportArtifact("m10c-cylinder.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.csindex fa981eae..ecd01fdd 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentValidationExecutionTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentValidationExecutionTests.cs@@ -67,6 +67,61 @@ public sealed class FirmamentValidationExecutionTests});}+ [Fact]+ public void Compile_Executes_Cylinder_Selector_Contract_With_Truthful_Runtime_Counts()+ {+ const string source = """+firmament:+ version: 1++model:+ name: cylinder_selector_truth+ units: mm++ops[7]:+ -+ op: cylinder+ id: cyl+ radius: 2+ height: 5+ -+ op: expect_selectable+ target: cyl.top_face+ count: 1+ -+ op: expect_selectable+ target: cyl.bottom_face+ count: 1+ -+ op: expect_selectable+ target: cyl.side_face+ count: 1+ -+ op: expect_selectable+ target: cyl.circular_edges+ count: 2+ -+ op: expect_selectable+ target: cyl.edges+ count: 3+ -+ op: expect_selectable+ target: cyl.vertices+ count: 4+""";++ var result = Compile(source);++ Assert.True(result.Compilation.IsSuccess);+ Assert.Equal(6, result.Compilation.Value.ValidationExecutionResult!.Validations.Count);+ Assert.All(result.Compilation.Value.ValidationExecutionResult.Validations, validation =>+ {+ Assert.True(validation.IsExecuted);+ Assert.True(validation.IsSuccess);+ Assert.Null(validation.Reason);+ });+ }+[Fact]public void Compile_Executes_ExpectSelectable_With_Count_Mismatch_As_Deterministic_Failure(){diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentSelectorResolver.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentSelectorResolver.csindex 9f324b26..1f26b54b 100644--- a/Aetheris.Kernel.Firmament/Execution/FirmamentSelectorResolver.cs+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentSelectorResolver.cs@@ -1,4 +1,6 @@using Aetheris.Kernel.Core.Brep;+using Aetheris.Kernel.Core.Geometry;+using Aetheris.Kernel.Core.Geometry.Curves;using Aetheris.Kernel.Firmament.ParsedModel;using Aetheris.Kernel.Firmament.Validation;@@ -28,17 +30,103 @@ internal static class FirmamentSelectorResolverreturn false;}- var count = resultKind switch+ var count = TryResolveCylinderCount(body, port, resultKind, out var cylinderCount)+ ? cylinderCount+ : resultKind switch+ {+ FirmamentSelectorResultKind.Face or FirmamentSelectorResultKind.FaceSet => body.Topology.Faces.Count(),+ FirmamentSelectorResultKind.EdgeSet => body.Topology.Edges.Count(),+ FirmamentSelectorResultKind.VertexSet => body.Topology.Vertices.Count(),+ _ => 0+ };++ resolution = new FirmamentSelectorResolution(featureId, port, resultKind, count);+ return true;+ }++ private static bool TryResolveCylinderCount(BrepBody body, string port, FirmamentSelectorResultKind resultKind, out int count)+ {+ count = 0;++ if (!LooksLikeCylinder(body))+ {+ return false;+ }++ count = port switch{- FirmamentSelectorResultKind.Face or FirmamentSelectorResultKind.FaceSet => body.Topology.Faces.Count(),- FirmamentSelectorResultKind.EdgeSet => body.Topology.Edges.Count(),- FirmamentSelectorResultKind.VertexSet => body.Topology.Vertices.Count(),+ "top_face" => CountFaces(body, surface => surface.Kind == SurfaceGeometryKind.Plane && surface.Plane!.Value.Normal.ToVector().Z > 0.5d),+ "bottom_face" => CountFaces(body, surface => surface.Kind == SurfaceGeometryKind.Plane && surface.Plane!.Value.Normal.ToVector().Z < -0.5d),+ "side_face" => CountFaces(body, surface => surface.Kind == SurfaceGeometryKind.Cylinder),+ "circular_edges" => CountEdges(body, curve => curve.Kind == CurveGeometryKind.Circle3),+ "edges" when resultKind == FirmamentSelectorResultKind.EdgeSet => body.Topology.Edges.Count(),+ "vertices" when resultKind == FirmamentSelectorResultKind.VertexSet => body.Topology.Vertices.Count(),_ => 0};- resolution = new FirmamentSelectorResolution(featureId, port, resultKind, count);return true;}++ private static bool LooksLikeCylinder(BrepBody body)+ {+ if (body.Topology.Faces.Count() != 3 || body.Topology.Edges.Count() != 3)+ {+ return false;+ }++ var cylindricalFaces = 0;+ var planarFaces = 0;++ foreach (var face in body.Topology.Faces)+ {+ if (!body.TryGetFaceSurfaceGeometry(face.Id, out var surface) || surface is null)+ {+ return false;+ }++ switch (surface.Kind)+ {+ case SurfaceGeometryKind.Cylinder:+ cylindricalFaces++;+ break;+ case SurfaceGeometryKind.Plane:+ planarFaces++;+ break;+ default:+ return false;+ }+ }++ return cylindricalFaces == 1 && planarFaces == 2;+ }++ private static int CountFaces(BrepBody body, Func<SurfaceGeometry, bool> predicate)+ {+ var count = 0;+ foreach (var face in body.Topology.Faces)+ {+ if (body.TryGetFaceSurfaceGeometry(face.Id, out var surface) && surface is not null && predicate(surface))+ {+ count++;+ }+ }++ return count;+ }++ private static int CountEdges(BrepBody body, Func<CurveGeometry, bool> predicate)+ {+ var count = 0;+ foreach (var edge in body.Topology.Edges)+ {+ if (body.TryGetEdgeCurveGeometry(edge.Id, out var curve) && curve is not null && predicate(curve))+ {+ count++;+ }+ }++ return count;+ }}internal sealed record FirmamentSelectorResolution(diff --git a/docs/firmament-selectors.md b/docs/firmament-selectors.mdindex eb4fcbab..21454e5a 100644--- a/docs/firmament-selectors.md+++ b/docs/firmament-selectors.md@@ -32,6 +32,15 @@ There is no implemented selector chaining or multi-hop traversal.- `edges` → `EdgeSet`, `Many`- `vertices` → `VertexSet`, `Many`+Current verified primitive-body topology for `cylinder` is:++- `top_face` = 1 planar cap face+- `bottom_face` = 1 planar cap face+- `side_face` = 1 cylindrical face+- `circular_edges` = 2 circular cap edges+- `edges` = 3 total edges (2 circular + 1 seam)+- `vertices` = 4 total vertices+#### `sphere`- `surface` → `Face`, `One`diff --git a/testdata/firmament/examples/README.md b/testdata/firmament/examples/README.mdindex f3419db4..8da3ba49 100644--- a/testdata/firmament/examples/README.md+++ b/testdata/firmament/examples/README.md@@ -3,6 +3,7 @@This directory contains small canonical Firmament examples for the current v1 surface.- `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`.- `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/cylinder_basic.firmament b/testdata/firmament/examples/cylinder_basic.firmamentnew file mode 100644index 00000000..6d96919c--- /dev/null+++ b/testdata/firmament/examples/cylinder_basic.firmament@@ -0,0 +1,13 @@+firmament:+ version: 1++model:+ name: cylinder_basic+ units: mm++ops[1]:+ -+ op: cylinder+ id: post+ radius: 6+ height: 18diff --git a/testdata/firmament/exports/cylinder_basic.step b/testdata/firmament/exports/cylinder_basic.stepnew file mode 100644index 00000000..f07db98b--- /dev/null+++ b/testdata/firmament/exports/cylinder_basic.step@@ -0,0 +1,79 @@+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=CYLINDRICAL_SURFACE($,#4,6);+#6=CARTESIAN_POINT($,(6,0,0));+#7=VERTEX_POINT($,#6);+#8=CARTESIAN_POINT($,(6,0,18));+#9=VERTEX_POINT($,#8);+#10=CARTESIAN_POINT($,(6,0,0));+#11=DIRECTION($,(0,0,1));+#12=VECTOR($,#11,1);+#13=LINE($,#10,#12);+#14=EDGE_CURVE($,#7,#9,#13,.T.);+#15=ORIENTED_EDGE($,$,$,#14,.T.);+#16=CARTESIAN_POINT($,(6,0,18));+#17=VERTEX_POINT($,#16);+#18=CARTESIAN_POINT($,(0,0,18));+#19=DIRECTION($,(0,0,1));+#20=DIRECTION($,(1,0,0));+#21=AXIS2_PLACEMENT_3D($,#18,#19,#20);+#22=CIRCLE($,#21,6);+#23=EDGE_CURVE($,#17,#17,#22,.T.);+#24=ORIENTED_EDGE($,$,$,#23,.T.);+#25=ORIENTED_EDGE($,$,$,#14,.F.);+#26=CARTESIAN_POINT($,(6,0,0));+#27=VERTEX_POINT($,#26);+#28=CARTESIAN_POINT($,(0,0,0));+#29=DIRECTION($,(0,0,1));+#30=DIRECTION($,(1,0,0));+#31=AXIS2_PLACEMENT_3D($,#28,#29,#30);+#32=CIRCLE($,#31,6);+#33=EDGE_CURVE($,#27,#27,#32,.T.);+#34=ORIENTED_EDGE($,$,$,#33,.F.);+#35=EDGE_LOOP($,(#15,#24,#25,#34));+#36=FACE_OUTER_BOUND('',#35,.T.);+#37=ADVANCED_FACE('',(#36),#5,.T.);+#38=CARTESIAN_POINT($,(0,0,18));+#39=DIRECTION($,(0,0,1));+#40=DIRECTION($,(1,0,0));+#41=AXIS2_PLACEMENT_3D($,#38,#39,#40);+#42=PLANE($,#41);+#43=ORIENTED_EDGE($,$,$,#23,.F.);+#44=EDGE_LOOP($,(#43));+#45=FACE_OUTER_BOUND('',#44,.T.);+#46=ADVANCED_FACE('',(#45),#42,.T.);+#47=CARTESIAN_POINT($,(0,0,0));+#48=DIRECTION($,(0,0,-1));+#49=DIRECTION($,(0,1,0));+#50=AXIS2_PLACEMENT_3D($,#47,#48,#49);+#51=PLANE($,#50);+#52=ORIENTED_EDGE($,$,$,#33,.T.);+#53=EDGE_LOOP($,(#52));+#54=FACE_OUTER_BOUND('',#53,.T.);+#55=ADVANCED_FACE('',(#54),#51,.T.);+#56=CLOSED_SHELL($,(#37,#46,#55));+#57=MANIFOLD_SOLID_BREP('AetherisBody',#56);+#58=APPLICATION_CONTEXT('mechanical design');+#59=PRODUCT_CONTEXT('',#58,'mechanical');+#60=PRODUCT('AETHERIS','AetherisBody','',(#59));+#61=PRODUCT_DEFINITION_FORMATION('','',#60);+#62=PRODUCT_DEFINITION_CONTEXT('design',#58,'design');+#63=PRODUCT_DEFINITION('','',#61,#62);+#64=PRODUCT_DEFINITION_SHAPE('','',#63);+#65=(LENGTH_UNIT()NAMED_UNIT(*)SI_UNIT(.MILLI.,.METRE.));+#66=(NAMED_UNIT(*)PLANE_ANGLE_UNIT()SI_UNIT($,.RADIAN.));+#67=(NAMED_UNIT(*)SI_UNIT($,.STERADIAN.)SOLID_ANGLE_UNIT());+#68=(GEOMETRIC_REPRESENTATION_CONTEXT(3)GLOBAL_UNIT_ASSIGNED_CONTEXT((#65,#66,#67))REPRESENTATION_CONTEXT('3','3D'));+#69=SHAPE_REPRESENTATION('AetherisBody',(#57),#68);+#70=SHAPE_DEFINITION_REPRESENTATION(#64,#69);+ENDSEC;+END-ISO-10303-21;diff --git a/testdata/firmament/exports/m10c-cylinder.step b/testdata/firmament/exports/m10c-cylinder.stepnew file mode 100644index 00000000..f07db98b--- /dev/null+++ b/testdata/firmament/exports/m10c-cylinder.step@@ -0,0 +1,79 @@+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=CYLINDRICAL_SURFACE($,#4,6);+#6=CARTESIAN_POINT($,(6,0,0));+#7=VERTEX_POINT($,#6);+#8=CARTESIAN_POINT($,(6,0,18));+#9=VERTEX_POINT($,#8);+#10=CARTESIAN_POINT($,(6,0,0));+#11=DIRECTION($,(0,0,1));+#12=VECTOR($,#11,1);+#13=LINE($,#10,#12);+#14=EDGE_CURVE($,#7,#9,#13,.T.);+#15=ORIENTED_EDGE($,$,$,#14,.T.);+#16=CARTESIAN_POINT($,(6,0,18));+#17=VERTEX_POINT($,#16);+#18=CARTESIAN_POINT($,(0,0,18));+#19=DIRECTION($,(0,0,1));+#20=DIRECTION($,(1,0,0));+#21=AXIS2_PLACEMENT_3D($,#18,#19,#20);+#22=CIRCLE($,#21,6);+#23=EDGE_CURVE($,#17,#17,#22,.T.);+#24=ORIENTED_EDGE($,$,$,#23,.T.);+#25=ORIENTED_EDGE($,$,$,#14,.F.);+#26=CARTESIAN_POINT($,(6,0,0));+#27=VERTEX_POINT($,#26);+#28=CARTESIAN_POINT($,(0,0,0));+#29=DIRECTION($,(0,0,1));+#30=DIRECTION($,(1,0,0));+#31=AXIS2_PLACEMENT_3D($,#28,#29,#30);+#32=CIRCLE($,#31,6);+#33=EDGE_CURVE($,#27,#27,#32,.T.);+#34=ORIENTED_EDGE($,$,$,#33,.F.);+#35=EDGE_LOOP($,(#15,#24,#25,#34));+#36=FACE_OUTER_BOUND('',#35,.T.);+#37=ADVANCED_FACE('',(#36),#5,.T.);+#38=CARTESIAN_POINT($,(0,0,18));+#39=DIRECTION($,(0,0,1));+#40=DIRECTION($,(1,0,0));+#41=AXIS2_PLACEMENT_3D($,#38,#39,#40);+#42=PLANE($,#41);+#43=ORIENTED_EDGE($,$,$,#23,.F.);+#44=EDGE_LOOP($,(#43));+#45=FACE_OUTER_BOUND('',#44,.T.);+#46=ADVANCED_FACE('',(#45),#42,.T.);+#47=CARTESIAN_POINT($,(0,0,0));+#48=DIRECTION($,(0,0,-1));+#49=DIRECTION($,(0,1,0));+#50=AXIS2_PLACEMENT_3D($,#47,#48,#49);+#51=PLANE($,#50);+#52=ORIENTED_EDGE($,$,$,#33,.T.);+#53=EDGE_LOOP($,(#52));+#54=FACE_OUTER_BOUND('',#53,.T.);+#55=ADVANCED_FACE('',(#54),#51,.T.);+#56=CLOSED_SHELL($,(#37,#46,#55));+#57=MANIFOLD_SOLID_BREP('AetherisBody',#56);+#58=APPLICATION_CONTEXT('mechanical design');+#59=PRODUCT_CONTEXT('',#58,'mechanical');+#60=PRODUCT('AETHERIS','AetherisBody','',(#59));+#61=PRODUCT_DEFINITION_FORMATION('','',#60);+#62=PRODUCT_DEFINITION_CONTEXT('design',#58,'design');+#63=PRODUCT_DEFINITION('','',#61,#62);+#64=PRODUCT_DEFINITION_SHAPE('','',#63);+#65=(LENGTH_UNIT()NAMED_UNIT(*)SI_UNIT(.MILLI.,.METRE.));+#66=(NAMED_UNIT(*)PLANE_ANGLE_UNIT()SI_UNIT($,.RADIAN.));+#67=(NAMED_UNIT(*)SI_UNIT($,.STERADIAN.)SOLID_ANGLE_UNIT());+#68=(GEOMETRIC_REPRESENTATION_CONTEXT(3)GLOBAL_UNIT_ASSIGNED_CONTEXT((#65,#66,#67))REPRESENTATION_CONTEXT('3','3D'));+#69=SHAPE_REPRESENTATION('AetherisBody',(#57),#68);+#70=SHAPE_DEFINITION_REPRESENTATION(#64,#69);+ENDSEC;+END-ISO-10303-21;diff --git a/testdata/firmament/fixtures/m6c-valid-selectable-count.firmament b/testdata/firmament/fixtures/m6c-valid-selectable-count.firmamentindex d4c9a5b8..4abf5edc 100644--- a/testdata/firmament/fixtures/m6c-valid-selectable-count.firmament+++ b/testdata/firmament/fixtures/m6c-valid-selectable-count.firmament@@ -43,7 +43,7 @@ ops[8]:-op: expect_selectabletarget: cyl.circular_edges- count: 3+ count: 2-op: expect_selectabletarget: join.edges