Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Update STEP242 NIST audit snapshot for inline-surface diagnostics
Yuechen Lib46d9c6b1773
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.csindex 329ae9dc..5c68c4da 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs@@ -1,3 +1,4 @@+using System.Text;using Aetheris.Kernel.Core.Brep;using Aetheris.Kernel.Core.Brep.Tessellation;using Aetheris.Kernel.Core.Diagnostics;@@ -113,4 +114,40 @@ public sealed class Step242ImporterTestsAssert.Equal("Importer.Geometry.Direction", diagnostic.Source);Assert.StartsWith("Degenerate direction vector", diagnostic.Message, StringComparison.Ordinal);}++ [Fact]+ public void Step242_AdvancedFace_Surface_AllowsInlinePlaneConstructor()+ {+ var text = LoadFixture("testdata/step242/syntax-robustness/advanced-face-inline-plane.step");++ var parseResult = Step242SubsetParser.Parse(text);+ Assert.True(parseResult.IsSuccess);++ var import = Step242Importer.ImportBody(text);++ Assert.True(import.IsSuccess);+ Assert.Single(import.Value.Topology.Faces);+ Assert.DoesNotContain(import.Diagnostics, d => d.Message.Contains("ADVANCED_FACE surface: expected entity reference argument.", StringComparison.Ordinal));+ }++ [Fact]+ public void Step242_AdvancedFace_Surface_AllowsEntityRefPlaneConstructor()+ {+ var text = LoadFixture("testdata/step242/syntax-robustness/advanced-face-ref-plane.step");++ var parseResult = Step242SubsetParser.Parse(text);+ Assert.True(parseResult.IsSuccess);++ var import = Step242Importer.ImportBody(text);++ Assert.True(import.IsSuccess);+ Assert.Single(import.Value.Topology.Faces);+ }++ private static string LoadFixture(string relativePath)+ {+ var path = Path.Combine(Step242CorpusManifestRunner.RepoRoot(), relativePath.Replace('/', Path.DirectorySeparatorChar));+ return File.ReadAllText(path, Encoding.UTF8);+ }+}diff --git a/Aetheris.Kernel.Core/Step242/Step242Importer.cs b/Aetheris.Kernel.Core/Step242/Step242Importer.csindex ccf6a0cf..2553b7bc 100644--- a/Aetheris.Kernel.Core/Step242/Step242Importer.cs+++ b/Aetheris.Kernel.Core/Step242/Step242Importer.cs@@ -103,19 +103,34 @@ public static class Step242Importer}var faceEntity = faceEntityResult.Value;- var surfaceRefResult = Step242SubsetDecoder.ReadReference(faceEntity, 1, "ADVANCED_FACE surface");- if (!surfaceRefResult.IsSuccess)+ var surfaceResult = Step242SubsetDecoder.ReadEntityRefOrInlineConstructor(faceEntity, 1, "ADVANCED_FACE surface");+ if (!surfaceResult.IsSuccess){- return KernelResult<BrepBody>.Failure(surfaceRefResult.Diagnostics);+ return KernelResult<BrepBody>.Failure(surfaceResult.Diagnostics);}- var surfaceEntityResult = document.TryGetEntity(surfaceRefResult.Value.TargetId);- if (!surfaceEntityResult.IsSuccess)+ Step242ParsedEntity? surfaceEntity = null;+ string surfaceName;+ IReadOnlyList<Step242Value>? inlineSurfaceArguments = null;++ if (surfaceResult.Value.IsReference)+ {+ var surfaceEntityResult = document.TryGetEntity(surfaceResult.Value.ReferenceId!.Value);+ if (!surfaceEntityResult.IsSuccess)+ {+ return KernelResult<BrepBody>.Failure(surfaceEntityResult.Diagnostics);+ }++ surfaceEntity = surfaceEntityResult.Value;+ surfaceName = surfaceEntityResult.Value.Name;+ }+ else{- return KernelResult<BrepBody>.Failure(surfaceEntityResult.Diagnostics);+ surfaceName = surfaceResult.Value.InlineName!;+ inlineSurfaceArguments = surfaceResult.Value.InlineArguments;}- var isSphericalFace = string.Equals(surfaceEntityResult.Value.Name, "SPHERICAL_SURFACE", StringComparison.OrdinalIgnoreCase);+ var isSphericalFace = string.Equals(surfaceName, "SPHERICAL_SURFACE", StringComparison.OrdinalIgnoreCase);var boundRefsResult = Step242SubsetDecoder.ReadReferenceList(faceEntity, 0, "ADVANCED_FACE bounds");if (!boundRefsResult.IsSuccess)@@ -134,7 +149,7 @@ public static class Step242Importerreturn KernelResult<BrepBody>.Failure(faceSameSenseResult.Diagnostics);}- var bindSurfaceResult = DecodeSurfaceGeometry(document, surfaceEntityResult.Value, faceSameSenseResult.Value, nextSurfaceGeometryId);+ var bindSurfaceResult = DecodeSurfaceGeometry(document, surfaceEntity, surfaceName, inlineSurfaceArguments, faceSameSenseResult.Value, nextSurfaceGeometryId, faceEntity.Id);if (!bindSurfaceResult.IsSuccess){return KernelResult<BrepBody>.Failure(bindSurfaceResult.Diagnostics);@@ -483,15 +498,20 @@ public static class Step242Importerprivate static KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)> DecodeSurfaceGeometry(Step242ParsedDocument document,- Step242ParsedEntity surfaceEntity,+ Step242ParsedEntity? surfaceEntity,+ string surfaceName,+ IReadOnlyList<Step242Value>? inlineSurfaceArguments,bool faceSameSense,- int nextSurfaceGeometryId)+ int nextSurfaceGeometryId,+ int faceEntityId){+ var normalizedName = surfaceName.ToUpperInvariant();+ var surfaceToDecode = surfaceEntity ?? BuildInlineSurfaceEntity(faceEntityId, normalizedName, inlineSurfaceArguments);var geometryId = new SurfaceGeometryId(nextSurfaceGeometryId);- if (string.Equals(surfaceEntity.Name, "PLANE", StringComparison.OrdinalIgnoreCase))+ if (string.Equals(normalizedName, "PLANE", StringComparison.Ordinal)){- var planeResult = Step242SubsetDecoder.ReadPlaneSurface(document, surfaceEntity);+ var planeResult = Step242SubsetDecoder.ReadPlaneSurface(document, surfaceToDecode);if (!planeResult.IsSuccess){return KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>.Failure(planeResult.Diagnostics);@@ -504,7 +524,7 @@ public static class Step242Importer{return OrientationFailure<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>("ADVANCED_FACE same_sense not supported for this face",- SourceFor(surfaceEntity.Id, "Importer.Orientation.AdvancedFaceSense"));+ SourceFor(surfaceToDecode.Id, "Importer.Orientation.AdvancedFaceSense"));}faceSurface = new PlaneSurface(faceSurface.Origin, reversedNormal, faceSurface.UAxis);@@ -513,9 +533,9 @@ public static class Step242Importerreturn KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>.Success((geometryId, SurfaceGeometry.FromPlane(faceSurface)));}- if (string.Equals(surfaceEntity.Name, "CYLINDRICAL_SURFACE", StringComparison.OrdinalIgnoreCase))+ if (string.Equals(normalizedName, "CYLINDRICAL_SURFACE", StringComparison.Ordinal)){- var cylinderResult = Step242SubsetDecoder.ReadCylindricalSurface(document, surfaceEntity);+ var cylinderResult = Step242SubsetDecoder.ReadCylindricalSurface(document, surfaceToDecode);if (!cylinderResult.IsSuccess){return KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>.Failure(cylinderResult.Diagnostics);@@ -524,9 +544,9 @@ public static class Step242Importerreturn KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>.Success((geometryId, SurfaceGeometry.FromCylinder(cylinderResult.Value)));}- if (string.Equals(surfaceEntity.Name, "SPHERICAL_SURFACE", StringComparison.OrdinalIgnoreCase))+ if (string.Equals(normalizedName, "SPHERICAL_SURFACE", StringComparison.Ordinal)){- var sphereResult = Step242SubsetDecoder.ReadSphericalSurface(document, surfaceEntity);+ var sphereResult = Step242SubsetDecoder.ReadSphericalSurface(document, surfaceToDecode);if (!sphereResult.IsSuccess){return KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>.Failure(sphereResult.Diagnostics);@@ -535,9 +555,9 @@ public static class Step242Importerreturn KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>.Success((geometryId, SurfaceGeometry.FromSphere(sphereResult.Value)));}- if (string.Equals(surfaceEntity.Name, "CONICAL_SURFACE", StringComparison.OrdinalIgnoreCase))+ if (string.Equals(normalizedName, "CONICAL_SURFACE", StringComparison.Ordinal)){- var coneResult = Step242SubsetDecoder.ReadConicalSurface(document, surfaceEntity);+ var coneResult = Step242SubsetDecoder.ReadConicalSurface(document, surfaceToDecode);if (!coneResult.IsSuccess){return KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>.Failure(coneResult.Diagnostics);@@ -546,7 +566,43 @@ public static class Step242Importerreturn KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>.Success((geometryId, SurfaceGeometry.FromCone(coneResult.Value)));}- return FailureSurfaceBinding($"ADVANCED_FACE surface '{surfaceEntity.Name}' is unsupported.", SourceFor(surfaceEntity.Id, "Importer.EntityFamily"));+ return FailureSurfaceBinding($"ADVANCED_FACE surface '{surfaceName}' is unsupported.", SourceFor(surfaceToDecode.Id, "Importer.EntityFamily"));+ }++ private static Step242ParsedEntity BuildInlineSurfaceEntity(int faceEntityId, string surfaceName, IReadOnlyList<Step242Value>? inlineArguments)+ {+ if (inlineArguments is null)+ {+ throw new InvalidOperationException("Inline surface constructor arguments are required for non-reference ADVANCED_FACE surface values.");+ }++ var normalizedArguments = NormalizeInlineSurfaceArguments(surfaceName, inlineArguments);+ return new Step242ParsedEntity(+ faceEntityId,+ new Step242SimpleEntityInstance(new Step242EntityConstructor(surfaceName, normalizedArguments)));+ }++ private static IReadOnlyList<Step242Value> NormalizeInlineSurfaceArguments(string surfaceName, IReadOnlyList<Step242Value> inlineArguments)+ {+ if (string.Equals(surfaceName, "PLANE", StringComparison.Ordinal) && inlineArguments.Count == 1+ || string.Equals(surfaceName, "CYLINDRICAL_SURFACE", StringComparison.Ordinal) && inlineArguments.Count == 2+ || string.Equals(surfaceName, "SPHERICAL_SURFACE", StringComparison.Ordinal) && inlineArguments.Count == 2+ || string.Equals(surfaceName, "CONICAL_SURFACE", StringComparison.Ordinal) && inlineArguments.Count == 3)+ {+ var normalizedArguments = new List<Step242Value>(inlineArguments.Count + 1)+ {+ Step242OmittedValue.Instance+ };++ for (var i = 0; i < inlineArguments.Count; i++)+ {+ normalizedArguments.Add(inlineArguments[i]);+ }++ return normalizedArguments;+ }++ return inlineArguments;}private static KernelResult<ParameterInterval> ComputeCircleTrim(Circle3Curve circle, Point3D startPoint, Point3D endPoint)diff --git a/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.cs b/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.csindex ccdb154f..2a080d73 100644--- a/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.cs+++ b/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.cs@@ -8,6 +8,28 @@ namespace Aetheris.Kernel.Core.Step242;internal static class Step242SubsetDecoder{+ internal readonly record struct EntityReferenceOrInlineConstructor+ {+ private EntityReferenceOrInlineConstructor(int? referenceId, string? inlineName, IReadOnlyList<Step242Value>? inlineArguments)+ {+ ReferenceId = referenceId;+ InlineName = inlineName;+ InlineArguments = inlineArguments;+ }++ public int? ReferenceId { get; }++ public string? InlineName { get; }++ public IReadOnlyList<Step242Value>? InlineArguments { get; }++ public bool IsReference => ReferenceId.HasValue;++ public static EntityReferenceOrInlineConstructor FromReference(int targetId) => new(targetId, null, null);++ public static EntityReferenceOrInlineConstructor FromInlineConstructor(string name, IReadOnlyList<Step242Value> arguments) => new(null, name, arguments);+ }+public static Step242EntityConstructor? TryGetConstructor(Step242EntityInstance entityValue, string name){if (entityValue is Step242SimpleEntityInstance simple)@@ -48,6 +70,29 @@ internal static class Step242SubsetDecoderreturn KernelResult<Step242EntityReference>.Success(reference);}+ public static KernelResult<EntityReferenceOrInlineConstructor> ReadEntityRefOrInlineConstructor(Step242ParsedEntity entity, int argumentIndex, string context)+ {+ if (argumentIndex < 0 || argumentIndex >= entity.Arguments.Count)+ {+ return Failure<EntityReferenceOrInlineConstructor>($"{context}: missing argument at index {argumentIndex}.", $"Entity:{entity.Id}");+ }++ var value = entity.Arguments[argumentIndex];+ if (value is Step242EntityReference reference)+ {+ return KernelResult<EntityReferenceOrInlineConstructor>.Success(EntityReferenceOrInlineConstructor.FromReference(reference.TargetId));+ }++ if (value is Step242TypedValue typed)+ {+ return KernelResult<EntityReferenceOrInlineConstructor>.Success(EntityReferenceOrInlineConstructor.FromInlineConstructor(typed.Name, typed.Arguments));+ }++ return Failure<EntityReferenceOrInlineConstructor>(+ $"{context}: expected entity reference or inline entity constructor.",+ "Importer.StepSyntax.InlineEntity");+ }+public static KernelResult<IReadOnlyList<Step242EntityReference>> ReadReferenceList(Step242ParsedEntity entity, int argumentIndex, string context){if (argumentIndex < 0 || argumentIndex >= entity.Arguments.Count)diff --git a/docs/support-matrix-step242-v0.md b/docs/support-matrix-step242-v0.mdindex 06ba04e1..a2022e95 100644--- a/docs/support-matrix-step242-v0.md+++ b/docs/support-matrix-step242-v0.md@@ -10,6 +10,7 @@ Aetheris STEP242 v0 is intentionally narrow and deterministic.- Exporter line-edge consistency: for exported `EDGE_CURVE` instances backed by `LINE`, both referenced vertex points are guaranteed to lie on the exported line geometry within export tolerance.- STEP Part 21 complex entity-instance assignments are accepted for parser/decoder context use (for example `#5=(GEOMETRIC_REPRESENTATION_CONTEXT(...)...REPRESENTATION_CONTEXT(...));`).- STEP Part 21 typed parameter values are supported in value position with deterministic normalization (`IDENT(...)` parsed as uppercase identifier + argument list), including common nested wrappers such as `LENGTH_MEASURE(...)` and `LENGTH_MEASURE_WITH_UNIT(LENGTH_MEASURE(...),#...)`.+- `ADVANCED_FACE.surface` accepts either a `#entity` reference or a limited inline surface constructor (`PLANE`, `CYLINDRICAL_SURFACE`, `CONICAL_SURFACE`, `SPHERICAL_SURFACE`) when geometry arguments are otherwise in subset.## Supported entity families (Tier1)diff --git a/testdata/step242/manifests/nist.v0.report.json b/testdata/step242/manifests/nist.v0.report.jsonindex 8b42865e..216e09e4 100644--- a/testdata/step242/manifests/nist.v0.report.json+++ b/testdata/step242/manifests/nist.v0.report.json@@ -7,7 +7,7 @@"firstFailureLayer": "importer-topology","firstDiagnostic": {"code": "NotImplemented",- "source": "Entity:764",+ "source": "Importer.StepSyntax.InlineEntity","messagePrefix": "ADVANCED_FACE surface"},"diagnosticCount": 1,@@ -31,7 +31,7 @@"firstFailureLayer": "importer-topology","firstDiagnostic": {"code": "NotImplemented",- "source": "Entity:2513",+ "source": "Importer.StepSyntax.InlineEntity","messagePrefix": "ADVANCED_FACE surface"},"diagnosticCount": 1,@@ -55,7 +55,7 @@"firstFailureLayer": "importer-topology","firstDiagnostic": {"code": "NotImplemented",- "source": "Entity:1331",+ "source": "Importer.StepSyntax.InlineEntity","messagePrefix": "ADVANCED_FACE surface"},"diagnosticCount": 1,@@ -223,7 +223,7 @@"firstFailureLayer": "importer-topology","firstDiagnostic": {"code": "NotImplemented",- "source": "Entity:82",+ "source": "Importer.StepSyntax.InlineEntity","messagePrefix": "ADVANCED_FACE surface"},"diagnosticCount": 1,@@ -367,7 +367,7 @@"firstFailureLayer": "importer-topology","firstDiagnostic": {"code": "NotImplemented",- "source": "Entity:1096",+ "source": "Importer.StepSyntax.InlineEntity","messagePrefix": "ADVANCED_FACE surface"},"diagnosticCount": 1,diff --git a/testdata/step242/syntax-robustness/advanced-face-inline-plane.step b/testdata/step242/syntax-robustness/advanced-face-inline-plane.stepnew file mode 100644index 00000000..c8d52be9--- /dev/null+++ b/testdata/step242/syntax-robustness/advanced-face-inline-plane.step@@ -0,0 +1,21 @@+ISO-10303-21;+HEADER;+ENDSEC;+DATA;+#1=MANIFOLD_SOLID_BREP('solid',#2);+#2=CLOSED_SHELL($,(#3));+#3=ADVANCED_FACE((#4),PLANE($,#30),.T.);+#4=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));+#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-ref-plane.step b/testdata/step242/syntax-robustness/advanced-face-ref-plane.stepnew file mode 100644index 00000000..1a6cdee1--- /dev/null+++ b/testdata/step242/syntax-robustness/advanced-face-ref-plane.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;