Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Fix inline surface diagnostic helper type inference

Yuechen Li02f3f8e443da
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs
index 5c68c4da..8b2ae01d 100644
--- a/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs
@@ -144,6 +144,23 @@ public sealed class Step242ImporterTests
Assert.Single(import.Value.Topology.Faces);
}
+ [Fact]
+ public void Step242_AdvancedFace_Surface_RejectsInlineNonPlaneSurface()
+ {
+ var text = LoadFixture("testdata/step242/syntax-robustness/advanced-face-inline-non-plane.step");
+
+ var parseResult = Step242SubsetParser.Parse(text);
+ Assert.True(parseResult.IsSuccess);
+
+ var import = Step242Importer.ImportBody(text);
+
+ Assert.False(import.IsSuccess);
+ var diagnostic = Assert.Single(import.Diagnostics);
+ Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);
+ Assert.Equal("Importer.StepSyntax.InlineEntity", diagnostic.Source);
+ Assert.Equal("ADVANCED_FACE surface: inline constructor 'CYLINDRICAL_SURFACE' is unsupported in M47a (only PLANE is allowed).", diagnostic.Message);
+ }
+
private static string LoadFixture(string relativePath)
{
var path = Path.Combine(Step242CorpusManifestRunner.RepoRoot(), relativePath.Replace('/', Path.DirectorySeparatorChar));
diff --git a/Aetheris.Kernel.Core/Step242/Step242Importer.cs b/Aetheris.Kernel.Core/Step242/Step242Importer.cs
index 2553b7bc..3e831cb8 100644
--- a/Aetheris.Kernel.Core/Step242/Step242Importer.cs
+++ b/Aetheris.Kernel.Core/Step242/Step242Importer.cs
@@ -506,7 +506,15 @@ public static class Step242Importer
int faceEntityId)
{
var normalizedName = surfaceName.ToUpperInvariant();
- var surfaceToDecode = surfaceEntity ?? BuildInlineSurfaceEntity(faceEntityId, normalizedName, inlineSurfaceArguments);
+ var surfaceToDecodeResult = surfaceEntity is null
+ ? BuildInlineSurfaceEntity(faceEntityId, normalizedName, inlineSurfaceArguments)
+ : KernelResult<Step242ParsedEntity>.Success(surfaceEntity);
+ if (!surfaceToDecodeResult.IsSuccess)
+ {
+ return KernelResult<(SurfaceGeometryId SurfaceGeometryId, SurfaceGeometry SurfaceGeometry)>.Failure(surfaceToDecodeResult.Diagnostics);
+ }
+
+ var surfaceToDecode = surfaceToDecodeResult.Value;
var geometryId = new SurfaceGeometryId(nextSurfaceGeometryId);
if (string.Equals(normalizedName, "PLANE", StringComparison.Ordinal))
@@ -569,42 +577,71 @@ public static class Step242Importer
return FailureSurfaceBinding($"ADVANCED_FACE surface '{surfaceName}' is unsupported.", SourceFor(surfaceToDecode.Id, "Importer.EntityFamily"));
}
- private static Step242ParsedEntity BuildInlineSurfaceEntity(int faceEntityId, string surfaceName, IReadOnlyList<Step242Value>? inlineArguments)
+ private static KernelResult<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.");
+ return FailureInlineSurface<Step242ParsedEntity>("ADVANCED_FACE surface: inline constructor arguments are required.", SourceFor(faceEntityId, "Importer.StepSyntax.InlineEntity"));
+ }
+
+ if (!string.Equals(surfaceName, "PLANE", StringComparison.Ordinal))
+ {
+ return FailureInlineSurface<Step242ParsedEntity>($"ADVANCED_FACE surface: inline constructor '{surfaceName}' is unsupported in M47a (only PLANE is allowed).", SourceFor(faceEntityId, "Importer.StepSyntax.InlineEntity"));
+ }
+
+ var normalizedArgumentsResult = NormalizeInlineSurfaceArguments(surfaceName, inlineArguments, faceEntityId);
+ if (!normalizedArgumentsResult.IsSuccess)
+ {
+ return KernelResult<Step242ParsedEntity>.Failure(normalizedArgumentsResult.Diagnostics);
}
- var normalizedArguments = NormalizeInlineSurfaceArguments(surfaceName, inlineArguments);
- return new Step242ParsedEntity(
+ return KernelResult<Step242ParsedEntity>.Success(new Step242ParsedEntity(
faceEntityId,
- new Step242SimpleEntityInstance(new Step242EntityConstructor(surfaceName, normalizedArguments)));
+ new Step242SimpleEntityInstance(new Step242EntityConstructor(surfaceName, normalizedArgumentsResult.Value))));
}
- private static IReadOnlyList<Step242Value> NormalizeInlineSurfaceArguments(string surfaceName, IReadOnlyList<Step242Value> inlineArguments)
+ private static KernelResult<IReadOnlyList<Step242Value>> NormalizeInlineSurfaceArguments(string surfaceName, IReadOnlyList<Step242Value> inlineArguments, int faceEntityId)
{
- 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)
+ if (string.Equals(surfaceName, "PLANE", StringComparison.Ordinal))
{
- var normalizedArguments = new List<Step242Value>(inlineArguments.Count + 1)
+ if (inlineArguments.Count == 1)
{
- Step242OmittedValue.Instance
- };
+ if (inlineArguments[0] is not Step242EntityReference)
+ {
+ return FailureInlineSurface<IReadOnlyList<Step242Value>>("ADVANCED_FACE surface: inline PLANE constructor expects PLANE(#axis2_placement_3d).", SourceFor(faceEntityId, "Importer.StepSyntax.InlineEntity"));
+ }
+
+ return KernelResult<IReadOnlyList<Step242Value>>.Success([
+ Step242OmittedValue.Instance,
+ inlineArguments[0]
+ ]);
+ }
- for (var i = 0; i < inlineArguments.Count; i++)
+ if (inlineArguments.Count == 2)
{
- normalizedArguments.Add(inlineArguments[i]);
+ if (inlineArguments[0] is not Step242OmittedValue || inlineArguments[1] is not Step242EntityReference)
+ {
+ return FailureInlineSurface<IReadOnlyList<Step242Value>>("ADVANCED_FACE surface: inline PLANE constructor expects PLANE(#axis2_placement_3d).", SourceFor(faceEntityId, "Importer.StepSyntax.InlineEntity"));
+ }
+
+ return KernelResult<IReadOnlyList<Step242Value>>.Success(inlineArguments);
}
- return normalizedArguments;
+ return FailureInlineSurface<IReadOnlyList<Step242Value>>("ADVANCED_FACE surface: inline PLANE constructor expects PLANE(#axis2_placement_3d).", SourceFor(faceEntityId, "Importer.StepSyntax.InlineEntity"));
}
- return inlineArguments;
+ return KernelResult<IReadOnlyList<Step242Value>>.Success(inlineArguments);
}
+ private static KernelResult<T> FailureInlineSurface<T>(string message, string source)
+ => KernelResult<T>.Failure([
+ new KernelDiagnostic(
+ KernelDiagnosticCode.NotImplemented,
+ KernelDiagnosticSeverity.Error,
+ message,
+ source)
+ ]);
+
private static KernelResult<ParameterInterval> ComputeCircleTrim(Circle3Curve circle, Point3D startPoint, Point3D endPoint)
{
const double tolerance = 1e-6d;
diff --git a/docs/support-matrix-step242-v0.md b/docs/support-matrix-step242-v0.md
index a2022e95..7b68dc95 100644
--- a/docs/support-matrix-step242-v0.md
+++ b/docs/support-matrix-step242-v0.md
@@ -10,7 +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.
+- `ADVANCED_FACE.surface` accepts either a `#entity` reference or a limited inline surface constructor (`PLANE(...)` only in M47a).
## Supported entity families (Tier1)
@@ -33,6 +33,7 @@ Aetheris STEP242 v0 is intentionally narrow and deterministic.
- Toroidal and other exotic analytic surface support.
- Any modeling/editor feature expansion in the Viewer tab.
- Typed wrapper decoding is intentionally limited in v0: primitive readers currently unwrap single-argument typed values; wrappers with unexpected arity fail deterministically via `Importer.StepSyntax.TypedValue`.
+- Inline surface constructors are intentionally limited in v0: only `ADVANCED_FACE.surface = PLANE(...)` is accepted in M47a; other inline surface constructors fail deterministically via `Importer.StepSyntax.InlineEntity`.
## Corpus and CI gate
diff --git a/testdata/step242/syntax-robustness/advanced-face-inline-non-plane.step b/testdata/step242/syntax-robustness/advanced-face-inline-non-plane.step
new file mode 100644
index 00000000..a5db0f91
--- /dev/null
+++ b/testdata/step242/syntax-robustness/advanced-face-inline-non-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),CYLINDRICAL_SURFACE(#30,1.0),.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;