Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Fix ADVANCED_FACE bounds consumption with named-arg forms
Yuechen Li78f9c5b594ab
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.csindex 3230168f..93dfa3f0 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs@@ -116,6 +116,40 @@ public sealed class Step242ImporterTestsAssert.StartsWith("Degenerate direction vector", diagnostic.Message, StringComparison.Ordinal);}++ [Fact]+ public void Step242_AdvancedFace_Bounds_SingleAggregate_ConsumesCorrectly()+ {+ var text = LoadFixture("testdata/step242/syntax-robustness/advanced-face-bounds-single-aggregate.step");++ var import = Step242Importer.ImportBody(text);++ Assert.True(import.IsSuccess);+ Assert.DoesNotContain(import.Diagnostics, d => d.Message.Contains("ADVANCED_FACE surface: expected entity reference or inline entity constructor.", StringComparison.Ordinal));+ }++ [Fact]+ public void Step242_AdvancedFace_Bounds_MultiAggregate_ConsumesCorrectly()+ {+ var text = LoadFixture("testdata/step242/syntax-robustness/advanced-face-bounds-multi-aggregate.step");++ var import = Step242Importer.ImportBody(text);++ Assert.DoesNotContain(import.Diagnostics, d => d.Message.Contains("ADVANCED_FACE surface: expected entity reference or inline entity constructor.", StringComparison.Ordinal));+ Assert.DoesNotContain(import.Diagnostics, d => string.Equals(d.Source, "Importer.StepSyntax.AdvancedFaceBounds", StringComparison.Ordinal));+ }++ [Fact]+ public void Step242_FreeCAD_Repro_ImportsPastAdvancedFaceBounds()+ {+ var text = LoadFixture("testdata/step242/syntax-robustness/freecad-pad-repro.step");++ var import = Step242Importer.ImportBody(text);++ Assert.True(import.IsSuccess);+ Assert.DoesNotContain(import.Diagnostics, d => d.Message.Contains("ADVANCED_FACE surface", StringComparison.Ordinal));+ }+[Fact]public void Step242_AdvancedFace_Surface_AllowsInlinePlaneConstructor(){diff --git a/Aetheris.Kernel.Core/Step242/Step242Importer.cs b/Aetheris.Kernel.Core/Step242/Step242Importer.csindex ae571244..1fd7e8be 100644--- a/Aetheris.Kernel.Core/Step242/Step242Importer.cs+++ b/Aetheris.Kernel.Core/Step242/Step242Importer.cs@@ -103,7 +103,12 @@ public static class Step242Importer}var faceEntity = faceEntityResult.Value;- var surfaceResult = Step242SubsetDecoder.ReadEntityRefOrInlineConstructor(faceEntity, 1, "ADVANCED_FACE surface");+ var advancedFaceOffset = faceEntity.Arguments.Count >= 4+ && (faceEntity.Arguments[0] is Step242StringValue || faceEntity.Arguments[0] is Step242OmittedValue)+ ? 1+ : 0;++ var surfaceResult = Step242SubsetDecoder.ReadEntityRefOrInlineConstructor(faceEntity, advancedFaceOffset + 1, "ADVANCED_FACE surface");if (!surfaceResult.IsSuccess){return KernelResult<BrepBody>.Failure(surfaceResult.Diagnostics);@@ -132,7 +137,7 @@ public static class Step242Importervar isSphericalFace = string.Equals(surfaceName, "SPHERICAL_SURFACE", StringComparison.OrdinalIgnoreCase);- var boundRefsResult = Step242SubsetDecoder.ReadReferenceList(faceEntity, 0, "ADVANCED_FACE bounds");+ var boundRefsResult = Step242SubsetDecoder.ReadAdvancedFaceBounds(faceEntity, advancedFaceOffset, "ADVANCED_FACE bounds");if (!boundRefsResult.IsSuccess){return KernelResult<BrepBody>.Failure(boundRefsResult.Diagnostics);@@ -143,7 +148,7 @@ public static class Step242Importerreturn Failure("ADVANCED_FACE without bounds is unsupported in M23 subset.", $"Entity:{faceEntity.Id}");}- var faceSameSenseResult = Step242SubsetDecoder.ReadBoolean(faceEntity, 2, "ADVANCED_FACE same_sense");+ var faceSameSenseResult = Step242SubsetDecoder.ReadBoolean(faceEntity, advancedFaceOffset + 2, "ADVANCED_FACE same_sense");if (!faceSameSenseResult.IsSuccess){return KernelResult<BrepBody>.Failure(faceSameSenseResult.Diagnostics);diff --git a/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.cs b/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.csindex 2a080d73..93af798d 100644--- a/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.cs+++ b/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.cs@@ -119,6 +119,16 @@ internal static class Step242SubsetDecoderreturn KernelResult<IReadOnlyList<Step242EntityReference>>.Success(refs);}+ public static KernelResult<IReadOnlyList<Step242EntityReference>> ReadAdvancedFaceBounds(Step242ParsedEntity entity, int argumentIndex, string context)+ {+ if (argumentIndex < 0 || argumentIndex >= entity.Arguments.Count)+ {+ return FailureList($"{context}: missing argument at index {argumentIndex}.", "Importer.StepSyntax.AdvancedFaceBounds");+ }++ return ReadAdvancedFaceBoundsValue(entity.Arguments[argumentIndex], context);+ }+public static KernelResult<bool> ReadBoolean(Step242ParsedEntity entity, int argumentIndex, string context){if (argumentIndex < 0 || argumentIndex >= entity.Arguments.Count)@@ -618,6 +628,34 @@ internal static class Step242SubsetDecoderreturn UnwrapTypedValue(typed.Arguments[0], context, source);}+ private static KernelResult<IReadOnlyList<Step242EntityReference>> ReadAdvancedFaceBoundsValue(Step242Value value, string context)+ {+ const string source = "Importer.StepSyntax.AdvancedFaceBounds";++ if (value is not Step242ListValue list)+ {+ return FailureList($"{context}: expected aggregate list of face bounds.", source);+ }++ if (list.Items.Count == 1 && list.Items[0] is Step242ListValue nested)+ {+ list = nested;+ }++ var refs = new List<Step242EntityReference>(list.Items.Count);+ for (var i = 0; i < list.Items.Count; i++)+ {+ if (list.Items[i] is not Step242EntityReference reference)+ {+ return FailureList($"{context}: aggregate item {i} must be an entity reference (#id).", source);+ }++ refs.Add(reference);+ }++ return KernelResult<IReadOnlyList<Step242EntityReference>>.Success(refs);+ }+private static KernelResult<Step242EntityReference> FailureRef(string message, string source) => Failure<Step242EntityReference>(message, source);private static KernelResult<IReadOnlyList<Step242EntityReference>> FailureList(string message, string source) => Failure<IReadOnlyList<Step242EntityReference>>(message, source);diff --git a/testdata/step242/manifests/nist.v0.report.json b/testdata/step242/manifests/nist.v0.report.jsonindex 216e09e4..f279c1e7 100644--- a/testdata/step242/manifests/nist.v0.report.json+++ b/testdata/step242/manifests/nist.v0.report.json@@ -7,8 +7,8 @@"firstFailureLayer": "importer-topology","firstDiagnostic": {"code": "NotImplemented",- "source": "Importer.StepSyntax.InlineEntity",- "messagePrefix": "ADVANCED_FACE surface"+ "source": "Importer.EntityFamily",+ "messagePrefix": "EDGE_CURVE geometry \u0027B_SPLINE_CURVE_WITH_KNOTS\u0027 is unsupported."},"diagnosticCount": 1,"exceptionEscaped": false,@@ -28,11 +28,11 @@"path": "testdata/step242/nist/CTC/nist_ctc_02_asme1_ap242-e2.stp","sizeBytes": 1958442,"status": "importFail",- "firstFailureLayer": "importer-topology",+ "firstFailureLayer": "importer-geometry","firstDiagnostic": {- "code": "NotImplemented",- "source": "Importer.StepSyntax.InlineEntity",- "messagePrefix": "ADVANCED_FACE surface"+ "code": "InvalidArgument",+ "source": "Importer.Geometry.Cone",+ "messagePrefix": "CONICAL_SURFACE radius"},"diagnosticCount": 1,"exceptionEscaped": false,@@ -52,18 +52,18 @@"path": "testdata/step242/nist/CTC/nist_ctc_03_asme1_ap242-e2.stp","sizeBytes": 667521,"status": "importFail",- "firstFailureLayer": "importer-topology",+ "firstFailureLayer": "tessellator","firstDiagnostic": {"code": "NotImplemented",- "source": "Importer.StepSyntax.InlineEntity",- "messagePrefix": "ADVANCED_FACE surface"+ "source": "",+ "messagePrefix": "Face 61 planar loop triangulation requires a convex polygon."},"diagnosticCount": 1,"exceptionEscaped": false,"topologyCounts": {- "vertices": 0,- "edges": 0,- "faces": 0+ "vertices": 236,+ "edges": 354,+ "faces": 120},"tessellationCounts": {"facePatches": 0,@@ -223,8 +223,8 @@"firstFailureLayer": "importer-topology","firstDiagnostic": {"code": "NotImplemented",- "source": "Importer.StepSyntax.InlineEntity",- "messagePrefix": "ADVANCED_FACE surface"+ "source": "Importer.EntityFamily",+ "messagePrefix": "EDGE_CURVE geometry \u0027B_SPLINE_CURVE_WITH_KNOTS\u0027 is unsupported."},"diagnosticCount": 1,"exceptionEscaped": false,@@ -366,9 +366,9 @@"status": "importFail","firstFailureLayer": "importer-topology","firstDiagnostic": {- "code": "NotImplemented",- "source": "Importer.StepSyntax.InlineEntity",- "messagePrefix": "ADVANCED_FACE surface"+ "code": "ValidationFailed",+ "source": "Importer.LoopRole.DegenerateLoop",+ "messagePrefix": "Loop projection is degenerate."},"diagnosticCount": 1,"exceptionEscaped": false,diff --git a/testdata/step242/syntax-robustness/advanced-face-bounds-multi-aggregate.step b/testdata/step242/syntax-robustness/advanced-face-bounds-multi-aggregate.stepnew file mode 100644index 00000000..8db1654f--- /dev/null+++ b/testdata/step242/syntax-robustness/advanced-face-bounds-multi-aggregate.step@@ -0,0 +1,30 @@+ISO-10303-21;+HEADER;+ENDSEC;+DATA;+#1=MANIFOLD_SOLID_BREP('solid',#2);+#2=CLOSED_SHELL($,(#3));+#3=ADVANCED_FACE('',((#4,#40)),#5,.T.);+#4=FACE_OUTER_BOUND($,#6,.T.);+#40=FACE_BOUND($,#41,.T.);+#5=PLANE($,#30);+#6=EDGE_LOOP($,(#7));+#7=ORIENTED_EDGE($,$,$,#8,.T.);+#8=EDGE_CURVE($,#9,#9,#11,.T.);+#9=VERTEX_POINT($,#12);+#11=CIRCLE($,#31,1.0);+#12=CARTESIAN_POINT($,(1,0,0));+#41=EDGE_LOOP($,(#42));+#42=ORIENTED_EDGE($,$,$,#43,.T.);+#43=EDGE_CURVE($,#44,#44,#45,.T.);+#44=VERTEX_POINT($,#46);+#45=CIRCLE($,#47,0.5);+#46=CARTESIAN_POINT($,(0.5,0,0));+#47=AXIS2_PLACEMENT_3D($,#14,#15,#16);+#30=AXIS2_PLACEMENT_3D($,#14,#15,#16);+#31=AXIS2_PLACEMENT_3D($,#14,#15,#16);+#14=CARTESIAN_POINT($,(0,0,0));+#15=DIRECTION($,(0,0,1));+#16=DIRECTION($,(1,0,0));+ENDSEC;+END-ISO-10303-21;diff --git a/testdata/step242/syntax-robustness/advanced-face-bounds-single-aggregate.step b/testdata/step242/syntax-robustness/advanced-face-bounds-single-aggregate.stepnew file mode 100644index 00000000..5fa4bd1b--- /dev/null+++ b/testdata/step242/syntax-robustness/advanced-face-bounds-single-aggregate.step@@ -0,0 +1,22 @@+ISO-10303-21;+HEADER;+ENDSEC;+DATA;+#1=MANIFOLD_SOLID_BREP('solid',#2);+#2=CLOSED_SHELL($,(#3));+#3=ADVANCED_FACE('',(#4),#5,.T.);+#4=FACE_OUTER_BOUND($,#6,.T.);+#5=PLANE($,#30);+#6=EDGE_LOOP($,(#7));+#7=ORIENTED_EDGE($,$,$,#8,.T.);+#8=EDGE_CURVE($,#9,#9,#11,.T.);+#9=VERTEX_POINT($,#12);+#11=CIRCLE($,#31,1.0);+#12=CARTESIAN_POINT($,(1,0,0));+#30=AXIS2_PLACEMENT_3D($,#14,#15,#16);+#31=AXIS2_PLACEMENT_3D($,#14,#15,#16);+#14=CARTESIAN_POINT($,(0,0,0));+#15=DIRECTION($,(0,0,1));+#16=DIRECTION($,(1,0,0));+ENDSEC;+END-ISO-10303-21;diff --git a/testdata/step242/syntax-robustness/freecad-pad-repro.step b/testdata/step242/syntax-robustness/freecad-pad-repro.stepnew file mode 100644index 00000000..7c295ae4--- /dev/null+++ b/testdata/step242/syntax-robustness/freecad-pad-repro.step@@ -0,0 +1,22 @@+ISO-10303-21;+HEADER;+ENDSEC;+DATA;+#1=MANIFOLD_SOLID_BREP('solid',#2);+#2=CLOSED_SHELL($,(#17));+#17=ADVANCED_FACE('',(#18),#52,.F.);+#18=FACE_OUTER_BOUND($,#6,.T.);+#6=EDGE_LOOP($,(#7));+#7=ORIENTED_EDGE($,$,$,#8,.T.);+#8=EDGE_CURVE($,#9,#9,#11,.T.);+#9=VERTEX_POINT($,#12);+#11=CIRCLE($,#31,1.0);+#12=CARTESIAN_POINT($,(1,0,0));+#52=PLANE('',#53);+#53=AXIS2_PLACEMENT_3D('',#14,#15,#16);+#31=AXIS2_PLACEMENT_3D('',#14,#15,#16);+#14=CARTESIAN_POINT('',(0,0,0));+#15=DIRECTION('',(0,0,1));+#16=DIRECTION('',(1,0,0));+ENDSEC;+END-ISO-10303-21;