Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Add resolved placement facts to native geometry replay log
Yuechen Lic867e1aab4f2
diff --git a/Aetheris.Kernel.Firmament.Tests/NativeGeometryStateTests.cs b/Aetheris.Kernel.Firmament.Tests/NativeGeometryStateTests.csindex d467d957..e3e44eda 100644--- a/Aetheris.Kernel.Firmament.Tests/NativeGeometryStateTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/NativeGeometryStateTests.cs@@ -1,8 +1,9 @@+using Aetheris.Kernel.Core.Math;using Aetheris.Kernel.Firmament.Execution;namespace Aetheris.Kernel.Firmament.Tests;-public sealed class NativeGeometryStateTests+public sealed partial class NativeGeometryStateTests{[Fact]public void NativeGeometryState_BoxBasic_IsBRepActive()@@ -128,4 +129,53 @@ public sealed class NativeGeometryStateTestsAssert.True(differential.CirEstimatedVolume > 0d);}-}\ No newline at end of file+ [Fact]+ public void ReplayPlacement_None_IsResolvedZero()+ {+ var result = FirmamentCorpusHarness.Compile(FirmamentCorpusHarness.ReadFixtureText("testdata/firmament/examples/box_basic.firmament"));+ var op = result.Compilation.Value.PrimitiveExecutionResult!.NativeGeometryState.ReplayLog.Operations.Single(o => o.FeatureId == "base");++ Assert.Equal(NativeGeometryPlacementKind.None, op.ResolvedPlacement.Kind);+ Assert.Equal(Vector3D.Zero, op.ResolvedPlacement.Translation);+ Assert.True(op.ResolvedPlacement.IsResolved);+ }++ [Fact]+ public void ReplayPlacement_Offset_CapturesTranslation()+ {+ var result = FirmamentCorpusHarness.Compile(FirmamentCorpusHarness.ReadFixtureText("testdata/firmament/examples/boolean_add_basic.firmament"));+ var op = result.Compilation.Value.PrimitiveExecutionResult!.NativeGeometryState.ReplayLog.Operations.Single(o => o.FeatureId == "shifted");++ Assert.Equal(NativeGeometryPlacementKind.Offset, op.ResolvedPlacement.Kind);+ Assert.Equal(new Vector3D(3d, 0d, 0d), op.ResolvedPlacement.Offset);+ Assert.Equal(new Vector3D(3d, 0d, 0d), op.ResolvedPlacement.Translation);+ Assert.True(op.ResolvedPlacement.IsResolved);+ }++ [Fact]+ public void ReplayPlacement_OnFace_CapturesAnchorAndTranslation()+ {+ var result = FirmamentCorpusHarness.Compile(FirmamentCorpusHarness.ReadFixtureText("testdata/firmament/examples/p1_blind_hole_on_face_semantic.firmament"));+ var op = result.Compilation.Value.PrimitiveExecutionResult!.NativeGeometryState.ReplayLog.Operations.Single(o => o.FeatureId == "blind_hole_tool");++ Assert.Equal(NativeGeometryPlacementKind.OnFace, op.ResolvedPlacement.Kind);+ Assert.Equal("base", op.ResolvedPlacement.AnchorFeatureId);+ Assert.Equal("top_face", op.ResolvedPlacement.AnchorPort);+ Assert.True(op.ResolvedPlacement.Translation.Z > 0d);+ Assert.True(op.ResolvedPlacement.IsResolved);+ }++ [Fact]+ public void ReplayPlacement_Unsupported_DoesNotFailProduction()+ {+ var result = FirmamentCorpusHarness.Compile(FirmamentCorpusHarness.ReadFixtureText("testdata/firmament/examples/p1_flange_radial_hole_semantic.firmament"));+ Assert.True(result.Compilation.IsSuccess);++ var op = result.Compilation.Value.PrimitiveExecutionResult!.NativeGeometryState.ReplayLog.Operations.Single(o => o.FeatureId == "radial_hole_tool");+ Assert.Equal(NativeGeometryPlacementKind.AroundAxis, op.ResolvedPlacement.Kind);+ Assert.False(op.ResolvedPlacement.IsResolved);+ Assert.False(string.IsNullOrWhiteSpace(op.ResolvedPlacement.Diagnostic));+ }+}++diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.csindex c14a4dd2..7c135d94 100644--- a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs@@ -30,6 +30,7 @@ internal static class FirmamentPrimitiveExecutorvar publishedBodiesByFeatureId = new Dictionary<string, BrepBody>(StringComparer.Ordinal);var booleanExecutionBodiesByFeatureId = new Dictionary<string, BrepBody>(StringComparer.Ordinal);var featureGraphStates = new Dictionary<string, FirmamentSafeSubtractFeatureGraphState>(StringComparer.Ordinal);+ var resolvedPlacementByOpIndex = new Dictionary<int, NativeGeometryResolvedPlacement>();var tolerance = ToleranceContext.Default;@@ -42,6 +43,7 @@ internal static class FirmamentPrimitiveExecutor}executedPrimitives.Add(new FirmamentExecutedPrimitive(primitive.OpIndex, primitive.FeatureId, primitive.Kind, bodyResult.Value.Published));+ resolvedPlacementByOpIndex[primitive.OpIndex] = BuildResolvedPlacement(primitive.Placement, bodyResult.Value.PlacementTranslation);publishedBodiesByFeatureId[primitive.FeatureId] = bodyResult.Value.Published;booleanExecutionBodiesByFeatureId[primitive.FeatureId] = bodyResult.Value.LegacyForBoolean;featureGraphStates[primitive.FeatureId] = primitive.Kind switch@@ -76,6 +78,7 @@ internal static class FirmamentPrimitiveExecutorpublishedBodiesByFeatureId[boolean.FeatureId] = draftedBody;booleanExecutionBodiesByFeatureId[boolean.FeatureId] = draftedBody;featureGraphStates[boolean.FeatureId] = FirmamentSafeSubtractFeatureGraphState.Other;+ resolvedPlacementByOpIndex[boolean.OpIndex] = BuildResolvedPlacement(boolean.Placement, Vector3D.Zero);continue;}@@ -96,6 +99,7 @@ internal static class FirmamentPrimitiveExecutorpublishedBodiesByFeatureId[boolean.FeatureId] = chamferedBody;booleanExecutionBodiesByFeatureId[boolean.FeatureId] = chamferedBody;featureGraphStates[boolean.FeatureId] = FirmamentSafeSubtractFeatureGraphState.Other;+ resolvedPlacementByOpIndex[boolean.OpIndex] = BuildResolvedPlacement(boolean.Placement, Vector3D.Zero);continue;}@@ -116,6 +120,7 @@ internal static class FirmamentPrimitiveExecutorpublishedBodiesByFeatureId[boolean.FeatureId] = filletedBody;booleanExecutionBodiesByFeatureId[boolean.FeatureId] = filletedBody;featureGraphStates[boolean.FeatureId] = FirmamentSafeSubtractFeatureGraphState.Other;+ resolvedPlacementByOpIndex[boolean.OpIndex] = BuildResolvedPlacement(boolean.Placement, Vector3D.Zero);continue;}@@ -167,6 +172,7 @@ internal static class FirmamentPrimitiveExecutorpatternGraphValidation.Value.ResultState,patternBooleanBody,tolerance);+ resolvedPlacementByOpIndex[boolean.OpIndex] = BuildResolvedPlacement(boolean.Placement, patternPlacementResult.Value);continue;}@@ -212,6 +218,7 @@ internal static class FirmamentPrimitiveExecutorreturn KernelResult<FirmamentPrimitiveExecutionResult>.Failure(placementResult.Diagnostics);}+ deferredPlacementTranslation = placementResult.Value;var translatedToolBody = TranslateBody(ApplyDefaultToolLocalFrame(boolean.Tool, toolResult.Value), placementResult.Value);toolBodyUsedForBoolean = translatedToolBody;booleanResult = ExecuteBoolean(boolean.Kind, publishedBaseBody, translatedToolBody);@@ -234,6 +241,7 @@ internal static class FirmamentPrimitiveExecutorreturn KernelResult<FirmamentPrimitiveExecutionResult>.Failure(placementResult.Diagnostics);}+ deferredPlacementTranslation = placementResult.Value;var translatedToolBody = PlaceSemanticToolBody(boolean, toolResult.Value, placementResult.Value);toolBodyUsedForBoolean = translatedToolBody;booleanResult = ExecuteBoolean(boolean.Kind, baseBody, translatedToolBody);@@ -275,9 +283,10 @@ internal static class FirmamentPrimitiveExecutorfeatureGraphValidation.Value.ResultState,placedBooleanBody,tolerance);+ resolvedPlacementByOpIndex[boolean.OpIndex] = BuildResolvedPlacement(boolean.Placement, deferredPlacementTranslation);}- var replayLog = BuildReplayLog(loweringPlan);+ var replayLog = BuildReplayLog(loweringPlan, resolvedPlacementByOpIndex);BrepBody? materializedBody = null;if (executedBooleans.Count > 0){@@ -359,7 +368,7 @@ internal static class FirmamentPrimitiveExecutorSource: "firmament");- private static NativeGeometryReplayLog BuildReplayLog(FirmamentPrimitiveLoweringPlan loweringPlan)+ private static NativeGeometryReplayLog BuildReplayLog(FirmamentPrimitiveLoweringPlan loweringPlan, IReadOnlyDictionary<int, NativeGeometryResolvedPlacement> resolvedPlacementByOpIndex){var replayOps = new List<NativeGeometryReplayOperation>(loweringPlan.Primitives.Count + loweringPlan.Booleans.Count);@@ -373,6 +382,7 @@ internal static class FirmamentPrimitiveExecutornull,null,SummarizePlacement(p.Placement),+ ResolveReplayPlacement(p.OpIndex, p.Placement, resolvedPlacementByOpIndex),null)));replayOps.AddRange(loweringPlan.Booleans@@ -385,6 +395,7 @@ internal static class FirmamentPrimitiveExecutorb.Tool.OpName,b.Tool.RawFields.TryGetValue("id", out var toolId) ? toolId : null,SummarizePlacement(b.Placement),+ ResolveReplayPlacement(b.OpIndex, b.Placement, resolvedPlacementByOpIndex),b.Tool.RawValue)));return new NativeGeometryReplayLog(replayOps.OrderBy(o => o.OpIndex).ToArray());@@ -410,6 +421,57 @@ internal static class FirmamentPrimitiveExecutorreturn $"on={anchor};offset={offset};semantic={placement.UsesSemanticAnchor}";}++ private static NativeGeometryResolvedPlacement ResolveReplayPlacement(+ int opIndex,+ FirmamentLoweredPlacement? placement,+ IReadOnlyDictionary<int, NativeGeometryResolvedPlacement> resolvedPlacementByOpIndex)+ {+ if (resolvedPlacementByOpIndex.TryGetValue(opIndex, out var resolved))+ {+ return resolved;+ }++ return BuildResolvedPlacement(placement, Vector3D.Zero);+ }++ private static NativeGeometryResolvedPlacement BuildResolvedPlacement(FirmamentLoweredPlacement? placement, Vector3D translation)+ {+ if (placement is null)+ {+ return new NativeGeometryResolvedPlacement(NativeGeometryPlacementKind.None, null, null, Vector3D.Zero, Vector3D.Zero, true, null);+ }++ var offset = placement.Offset.Count == 3+ ? new Vector3D(placement.Offset[0], placement.Offset[1], placement.Offset[2])+ : Vector3D.Zero;++ if (!string.IsNullOrWhiteSpace(placement.AroundAxis))+ {+ return new NativeGeometryResolvedPlacement(NativeGeometryPlacementKind.AroundAxis, null, null, offset, translation, false, "Around-axis placement replay facts are deferred in CIR-F2.5.");+ }++ if (placement.On is FirmamentLoweredPlacementSelectorAnchor selectorAnchor)+ {+ var i = selectorAnchor.Selector.IndexOf('.', StringComparison.Ordinal);+ if (i <= 0 || i >= selectorAnchor.Selector.Length - 1)+ {+ return new NativeGeometryResolvedPlacement(NativeGeometryPlacementKind.Unsupported, null, null, offset, translation, false, $"Unsupported placement selector '{selectorAnchor.Selector}' for replay facts.");+ }++ return new NativeGeometryResolvedPlacement(+ NativeGeometryPlacementKind.OnFace,+ selectorAnchor.Selector[..i],+ selectorAnchor.Selector[(i + 1)..],+ offset,+ translation,+ true,+ null);+ }++ return new NativeGeometryResolvedPlacement(NativeGeometryPlacementKind.Offset, null, null, offset, translation, true, null);+ }+private static bool IsPatternGeneratedFeature(string featureId)=> featureId.Contains("__lin", StringComparison.Ordinal)|| featureId.Contains("__cir", StringComparison.Ordinal)@@ -460,7 +522,7 @@ internal static class FirmamentPrimitiveExecutor}var publishedBody = TranslateBody(defaultFrameBody, placementResult.Value);- return KernelResult<FirmamentExecutedPrimitiveBodies>.Success(new FirmamentExecutedPrimitiveBodies(publishedBody, legacyResult.Value));+ return KernelResult<FirmamentExecutedPrimitiveBodies>.Success(new FirmamentExecutedPrimitiveBodies(publishedBody, legacyResult.Value, placementResult.Value));}private static BrepBody ApplyDefaultLocalFrame(FirmamentLoweredPrimitive primitive, BrepBody body)@@ -1202,7 +1264,7 @@ internal static class FirmamentPrimitiveExecutor}}-internal sealed record FirmamentExecutedPrimitiveBodies(BrepBody Published, BrepBody LegacyForBoolean);+internal sealed record FirmamentExecutedPrimitiveBodies(BrepBody Published, BrepBody LegacyForBoolean, Vector3D PlacementTranslation);internal static class FirmamentPrimitiveToolParsing{diff --git a/Aetheris.Kernel.Firmament/Execution/NativeGeometryState.cs b/Aetheris.Kernel.Firmament/Execution/NativeGeometryState.csindex 9ff9f1b5..9d6dede9 100644--- a/Aetheris.Kernel.Firmament/Execution/NativeGeometryState.cs+++ b/Aetheris.Kernel.Firmament/Execution/NativeGeometryState.cs@@ -36,6 +36,24 @@ public sealed record NativeGeometryTransitionEvent(public sealed record NativeGeometryReplayLog(IReadOnlyList<NativeGeometryReplayOperation> Operations);+public enum NativeGeometryPlacementKind+{+ None,+ Offset,+ OnFace,+ AroundAxis,+ Unsupported+}++public readonly record struct NativeGeometryResolvedPlacement(+ NativeGeometryPlacementKind Kind,+ string? AnchorFeatureId,+ string? AnchorPort,+ Vector3D Offset,+ Vector3D Translation,+ bool IsResolved,+ string? Diagnostic);+public sealed record NativeGeometryReplayOperation(int OpIndex,string FeatureId,@@ -44,6 +62,7 @@ public sealed record NativeGeometryReplayOperation(string? ToolKind,string? ToolId,string? PlacementSummary,+ NativeGeometryResolvedPlacement ResolvedPlacement,string? MetadataReference);public enum CirMirrorStatusdiff --git a/docs/cir-f25-resolved-placement-replay.md b/docs/cir-f25-resolved-placement-replay.mdnew file mode 100644index 00000000..46d6f186--- /dev/null+++ b/docs/cir-f25-resolved-placement-replay.md@@ -0,0 +1,42 @@+# CIR-F2.5: resolved placement facts in NativeGeometry replay log++CIR-F1 replay operations only carried `PlacementSummary` text. That was readable but not deterministic enough for fall-forward replay because future replay would have to re-resolve placement from selector text and context.++CIR-F2.5 adds structured placement facts captured from the production execution pass and stored on each `NativeGeometryReplayOperation`.++## Structured facts recorded++Each replay operation now includes:++- placement kind (`None`, `Offset`, `OnFace`, `AroundAxis`, `Unsupported`)+- authored anchor feature/port when selector-shaped+- authored offset vector+- resolved final translation vector from production placement resolution+- resolved/unresolved flag+- unresolved diagnostic message++`PlacementSummary` is intentionally retained for human-readable debugging.++## Supported in CIR-F2.5++- no placement: resolved zero translation+- `place.offset`: resolved offset + translation+- `place.on_face`: authored selector anchor + offset + resolved translation++## Deferred/unsupported in CIR-F2.5++- `place.around_axis` replay facts are recorded as unresolved (`Kind=AroundAxis`, `IsResolved=false`) with explicit diagnostics.+- This is intentional scaffolding; production behavior remains unchanged and successful models still succeed.++## F3 consumption guidance++CIR-F3 fall-forward should consume `ResolvedPlacement` as the authoritative replay placement input where `IsResolved=true`, and should not re-derive placement from summary strings.++## Behavior statement++This milestone is behavior-preserving:++- no runtime transition to `CirOnly`+- no CIR-to-BRep materialization enablement+- no placement semantic expansion+- no selector/topology naming expansion (SEM-A0 preserved)