Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Implement Firmament V2 side-hole region slice
Yuechen Li2dc3c2266f1c
diff --git a/Aetheris.CLI/AirTrace.cs b/Aetheris.CLI/AirTrace.csindex faea52f1..3e53f399 100644--- a/Aetheris.CLI/AirTrace.cs+++ b/Aetheris.CLI/AirTrace.cs@@ -5,6 +5,7 @@ using Aetheris.Kernel.Core.Air.BRepPlan;using Aetheris.Kernel.Core.Air.Regions;using Aetheris.Kernel.Core.Brep.Prismatic;using Aetheris.Kernel.Firmament;+using Aetheris.Kernel.Firmament.FirmamentV2;namespace Aetheris.CLI;@@ -51,9 +52,11 @@ internal sealed record AirTraceFeatureAirSummary(bool ParserBacked, string Sourcinternal sealed record AirTraceConstructiveAirSummary(string NodeKind, string CanonicalForm, string SourceFeatureAirNodeKind, string ProfileKind, double Width, double Depth, double Height, string ExtrusionAxis, string ConstructionIntent, string RouteKind, string StageReached, IReadOnlyList<string> Diagnostics, IReadOnlyList<string> Guarantees);internal sealed record AirTraceProfileEmissionSummary(bool WrapperInvoked, string EmitterName, bool Succeeded, double Width, double Depth, double Height, string StageReached, AirTraceProfileEmissionTopologySummary? TopologySummary, AirTraceProfileEmissionStepSmokeSummary StepSmoke, IReadOnlyList<string> Diagnostics, IReadOnlyList<string> Guarantees);internal sealed record AirTraceProfileEmissionTopologySummary(int Vertices, int Edges, int Faces, int PlanarFaces, int CylindricalFaces, int Loops, int Coedges, int? CapFaces, int? SideFaces, string? Bounds);-internal sealed record AirTraceFirmamentV2Summary(string SyntaxVersion, string ModelName, string Units, string SolidName, string RecordType, IReadOnlyList<double> Size, string Stage, IReadOnlyList<AirTraceFirmamentV2SolidSummary> Solids);+internal sealed record AirTraceFirmamentV2Summary(string SyntaxVersion, string ModelName, string Units, string SolidName, string RecordType, IReadOnlyList<double> Size, string Stage, IReadOnlyList<AirTraceFirmamentV2SolidSummary> Solids, IReadOnlyList<AirTraceFirmamentV2ModifySummary>? ModifyBlocks = null, FirmamentV2SideHoleIntent? SemanticIntent = null, string? ParentIntegration = null, string? ShellClosure = null, string? StepSmoke = null, string? Blocker = null);internal sealed record AirTraceFirmamentV2SolidSummary(string Name, string RecordType, IReadOnlyList<double> Size, string? DerivedFrom, IReadOnlyDictionary<string, IReadOnlyList<double>> Overrides, IReadOnlyList<AirTraceFirmamentV2ExposureSummary> Exposures);internal sealed record AirTraceFirmamentV2ExposureSummary(string Alias, string SelectorKind, string Selector, string RefType, string Axis, string? Subselector);+internal sealed record AirTraceFirmamentV2ModifySummary(string TargetSolid, IReadOnlyList<AirTraceFirmamentV2RegionSummary> Regions);+internal sealed record AirTraceFirmamentV2RegionSummary(string Name, string Kind, string On, string Operation, string Tool, double Radius, string Through);internal sealed record AirTraceProfileEmissionStepSmokeSummary(bool WasChecked, bool Succeeded, bool RequiredMarkersPresent, bool ForbiddenMarkersAbsent, IReadOnlyList<string> Diagnostics);internal sealed record AirTraceDimensionsSummary(double Width, double Depth, double Height);internal sealed record AirTraceAirSummary(string Node, string Route, string SelectionClass, string Rule, string ConstructionHistory, string FeatureName, string FeatureId, string ProvenanceMilestone);@@ -145,7 +148,7 @@ internal static class AirTraceReportBuilder? null: new AirTraceConstructiveAirSummary(frontend.ConstructiveAir.NodeKind, frontend.ConstructiveAir.CanonicalForm, frontend.ConstructiveAir.SourceFeatureAirNodeKind, frontend.ConstructiveAir.ProfileKind, frontend.ConstructiveAir.Dimensions.Width, frontend.ConstructiveAir.Dimensions.Depth, frontend.ConstructiveAir.Dimensions.Height, frontend.ConstructiveAir.ExtrusionAxis, frontend.ConstructiveAir.ConstructionIntent, frontend.ConstructiveAir.RouteKind, frontend.ConstructiveAir.StageReached, frontend.ConstructiveAir.Diagnostics, frontend.ConstructiveAir.Guarantees);- var regions = AirRegionTraceFactory.ForRootBody(actualStage ?? "emitted-brep");+ var regions = frontend.FirmamentV2?.SemanticIntent is not null ? AirRegionTraceFactory.ForFaceAttachedSideHoleDeferred() : AirRegionTraceFactory.ForRootBody(actualStage ?? "emitted-brep");fxDiagnostics = Stable([.. fxDiagnostics, .. regions.Diagnostics]).ToArray();var profileEmission = profileEmissionProbe is null ? null : new AirTraceProfileEmissionSummary(profileEmissionProbe.WrapperInvoked,@@ -160,9 +163,9 @@ internal static class AirTraceReportBuilderprofileEmissionProbe.Diagnostics,profileEmissionProbe.Guarantees);- var v2 = frontend.FirmamentV2 is null ? null : new AirTraceFirmamentV2Summary(frontend.FirmamentV2.SyntaxVersion, frontend.FirmamentV2.ModelName, frontend.FirmamentV2.Units, frontend.FirmamentV2.SolidName, frontend.FirmamentV2.RecordType, frontend.FirmamentV2.Size, frontend.FirmamentV2.StageReached, frontend.FirmamentV2.Solids.Select(s => new AirTraceFirmamentV2SolidSummary(s.Name, s.RecordType, s.Size, s.DerivedFrom, s.Overrides, s.Exposures.Select(e => new AirTraceFirmamentV2ExposureSummary(e.Alias, e.SelectorKind, e.Selector, e.RefType, e.Axis, e.Subselector)).ToArray())).ToArray());+ var v2 = frontend.FirmamentV2 is null ? null : new AirTraceFirmamentV2Summary(frontend.FirmamentV2.SyntaxVersion, frontend.FirmamentV2.ModelName, frontend.FirmamentV2.Units, frontend.FirmamentV2.SolidName, frontend.FirmamentV2.RecordType, frontend.FirmamentV2.Size, frontend.FirmamentV2.StageReached, frontend.FirmamentV2.Solids.Select(s => new AirTraceFirmamentV2SolidSummary(s.Name, s.RecordType, s.Size, s.DerivedFrom, s.Overrides, s.Exposures.Select(e => new AirTraceFirmamentV2ExposureSummary(e.Alias, e.SelectorKind, e.Selector, e.RefType, e.Axis, e.Subselector)).ToArray())).ToArray(), frontend.FirmamentV2.ModifyBlocks?.Select(m => new AirTraceFirmamentV2ModifySummary(m.TargetSolid, m.Regions.Select(r => new AirTraceFirmamentV2RegionSummary(r.Name, r.Kind, r.On, r.Operation, r.Tool, r.Radius, r.Through)).ToArray())).ToArray(), frontend.FirmamentV2.SemanticIntent, frontend.FirmamentV2.ParentIntegration, frontend.FirmamentV2.ShellClosure, frontend.FirmamentV2.StepSmoke, frontend.FirmamentV2.Blocker);- return new(isFirmamentV2 ? "AIR-FIRMAMENT-X1" : "AIR-X11", "trace", "lowering", "firmfixture", fixture.CaseName, expectationSatisfied, frontend.FrontendSummary,+ return new(isFirmamentV2 && frontend.FirmamentV2?.SemanticIntent is not null ? "AIR-FIRMAMENT-X4" : isFirmamentV2 ? "AIR-FIRMAMENT-X1" : "AIR-X11", "trace", "lowering", "firmfixture", fixture.CaseName, expectationSatisfied, frontend.FrontendSummary,new(constructiveAir?.NodeKind ?? featureAir?.NodeKind ?? "FirmamentPrimitive", constructiveAir?.RouteKind ?? "none", "none", "none", "parser-backed-source-fixture", fixture.CaseName, fixture.CaseName, "AIR-X11"),new("none", null, false, "Route selection and BRepPlan are deferred for parser-backed box fixtures in AIR-X11; profile emission is reported separately.", "none", "none", []),new("none", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "none", "none", null, []),@@ -343,6 +346,34 @@ internal static class AirTraceTextRendererforeach (var exposure in solid.Exposures) b.AppendLine($" {exposure.Selector} => {exposure.Alias} : {exposure.RefType}");}}+ if (r.FirmamentV2.ModifyBlocks is not null)+ {+ foreach (var modify in r.FirmamentV2.ModifyBlocks)+ {+ b.AppendLine();+ b.AppendLine($" Modify: {modify.TargetSolid}");+ foreach (var region in modify.Regions)+ {+ b.AppendLine($" Region: {region.Name}");+ b.AppendLine($" Kind: {region.Kind}");+ b.AppendLine($" On: {region.On}");+ b.AppendLine($" Operation: {region.Operation}");+ b.AppendLine($" Tool: {region.Tool}");+ b.AppendLine($" Radius: {region.Radius:g}");+ b.AppendLine($" Through: {region.Through}");+ }+ }+ }+ if (r.FirmamentV2.SemanticIntent is not null)+ {+ b.AppendLine();+ b.AppendLine(" Lowering:");+ b.AppendLine(" Semantic intent: SideHole");+ b.AppendLine($" AIR Region: {(r.Regions is null ? "not-reached" : "FaceAttachedRegion golden trace chain")}");+ b.AppendLine($" Parent integration: {r.FirmamentV2.ParentIntegration ?? "not-reached"}");+ b.AppendLine($" Shell closure: {r.FirmamentV2.ShellClosure ?? "not-reached"}");+ b.AppendLine($" STEP smoke: {r.FirmamentV2.StepSmoke ?? "not-reached"}");+ }if (r.FeatureAir is not null) b.AppendLine($" Feature AIR: {r.FeatureAir.NodeKind}");b.AppendLine();}diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentV2ParserTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentV2ParserTests.csindex 072c795d..44bd6fe5 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentV2ParserTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentV2ParserTests.cs@@ -185,6 +185,92 @@ public sealed class FirmamentV2ParserTestsAssert.Contains("firmament-v2-no-v1-parser", result.Diagnostics);}+ [Fact]+ public void FirmamentV2Parser_SideHole_ParsesRegionCutCylinder()+ {+ var result = FirmamentV2Parser.Parse(Source("Region/valid/side-hole-v2.valid.firmfixture"));+ Assert.True(result.IsSuccess, string.Join(", ", result.Diagnostics));+ var document = result.Document!;+ Assert.Equal("SideHoleV2", document.ModelName);+ Assert.Equal("mm", document.Units);+ Assert.Equal("base", document.Solid.Name);+ Assert.Equal([10, 8, 6], document.Solid.Box.Size);+ var modify = Assert.Single(document.ModifyBlocks!);+ Assert.Equal("base", modify.TargetSolid);+ var region = Assert.Single(modify.Regions);+ Assert.Equal("sideHole", region.Name);+ Assert.Equal("+X", region.Attachment.Axis);+ Assert.Equal("Cut", region.Cut.OperationKind);+ Assert.Equal("Cylinder", region.Cut.Tool.ToolType);+ Assert.Equal(1, region.Cut.Tool.Radius);+ Assert.Equal("-X", region.Cut.Tool.Through.Axis);+ }++ [Fact]+ public void FirmamentV2Parser_SideHole_ProducesSemanticIntent()+ {+ var intent = FirmamentV2Parser.Parse(Source("Region/valid/side-hole-v2.valid.firmfixture")).Document!.SideHoleIntent;+ Assert.NotNull(intent);+ Assert.Equal("base", intent!.TargetSolid);+ Assert.Equal("sideHole", intent.RegionName);+ Assert.Equal("+X", intent.AttachFace);+ Assert.Equal("-X", intent.ThroughFace);+ Assert.Equal("Cylinder", intent.Tool);+ Assert.Equal(1, intent.Radius);+ Assert.Equal("mm", intent.Units);+ }++ [Fact]+ public void FirmamentV2Parser_SideHole_LoweringOutcomeIsTruthful()+ {+ var result = FirmamentFrontendTraceProbe.ParseV2Only(Source("Region/valid/side-hole-v2.valid.firmfixture"));+ Assert.True(result.ParseSucceeded, string.Join(", ", result.Diagnostics));+ Assert.Equal("region-parent-integrated", result.FrontendStageReached);+ Assert.NotNull(result.FirmamentV2!.SemanticIntent);+ Assert.Null(result.FirmamentV2.Blocker);+ }++ [Fact]+ public void FirmamentV2Parser_SideHole_GoldenPathIfReached()+ {+ var result = FirmamentFrontendTraceProbe.ParseV2Only(Source("Region/valid/side-hole-v2.valid.firmfixture"));+ Assert.Equal("Integrated", result.FirmamentV2!.ParentIntegration);+ Assert.Equal("Closed", result.FirmamentV2.ShellClosure);+ Assert.Equal("Succeeded", result.FirmamentV2.StepSmoke);+ }++ [Fact]+ public void FirmamentV2Parser_SideHole_InvalidAttachFaceDiagnostic()+ {+ Assert.Contains(FirmamentV2Parser.SideHoleOnlyPlusXMinusXSupported, FirmamentV2Parser.Parse(Source("Region/invalid/side-hole-invalid-attach-v2.invalid.firmfixture")).Diagnostics);+ }++ [Fact]+ public void FirmamentV2Parser_SideHole_InvalidThroughFaceDiagnostic()+ {+ Assert.Contains(FirmamentV2Parser.SideHoleOnlyPlusXMinusXSupported, FirmamentV2Parser.Parse(Source("Region/invalid/side-hole-invalid-through-v2.invalid.firmfixture")).Diagnostics);+ }++ [Fact]+ public void FirmamentV2Parser_SideHole_InvalidRadiusDiagnostic()+ {+ Assert.Contains(FirmamentV2Parser.CylinderRadiusInvalid, FirmamentV2Parser.Parse(Source("Region/invalid/side-hole-invalid-radius-v2.invalid.firmfixture")).Diagnostics);+ }++ [Fact]+ public void FirmamentV2Parser_SideHole_UnknownModifyTargetDiagnostic()+ {+ Assert.Contains(FirmamentV2Parser.ModifyTargetUnresolved, FirmamentV2Parser.Parse(Source("Region/invalid/side-hole-unknown-modify-target-v2.invalid.firmfixture")).Diagnostics);+ }++ [Fact]+ public void FirmamentV2Parser_SideHole_DoesNotUseV1Parser()+ {+ var result = FirmamentFrontendTraceProbe.ParseV2Only(Source("Region/valid/side-hole-v2.valid.firmfixture"));+ Assert.Equal("FirmamentV2Parser", result.ParserName);+ Assert.Contains("firmament-v2-no-v1-parser", result.Diagnostics);+ }+private static string Source(string relative){var path = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "../../../../fixtures/FirmamentV2", relative));diff --git a/Aetheris.Kernel.Firmament/FirmamentFrontendTraceProbe.cs b/Aetheris.Kernel.Firmament/FirmamentFrontendTraceProbe.csindex 375ff04c..032d1210 100644--- a/Aetheris.Kernel.Firmament/FirmamentFrontendTraceProbe.cs+++ b/Aetheris.Kernel.Firmament/FirmamentFrontendTraceProbe.cs@@ -16,9 +16,11 @@ public sealed record FirmamentFrontendTraceProbeResult(FirmamentConstructiveAirTraceSummary? ConstructiveAir = null,FirmamentV2TraceSummary? FirmamentV2 = null);-public sealed record FirmamentV2TraceSummary(string SyntaxVersion, string ModelName, string Units, string SolidName, string RecordType, IReadOnlyList<double> Size, string StageReached, IReadOnlyList<FirmamentV2SolidTraceSummary> Solids);+public sealed record FirmamentV2TraceSummary(string SyntaxVersion, string ModelName, string Units, string SolidName, string RecordType, IReadOnlyList<double> Size, string StageReached, IReadOnlyList<FirmamentV2SolidTraceSummary> Solids, IReadOnlyList<FirmamentV2ModifyTraceSummary>? ModifyBlocks = null, FirmamentV2SideHoleIntent? SemanticIntent = null, string? ParentIntegration = null, string? ShellClosure = null, string? StepSmoke = null, string? Blocker = null);public sealed record FirmamentV2SolidTraceSummary(string Name, string RecordType, IReadOnlyList<double> Size, string? DerivedFrom, IReadOnlyDictionary<string, IReadOnlyList<double>> Overrides, IReadOnlyList<FirmamentV2ExposureTraceSummary> Exposures);public sealed record FirmamentV2ExposureTraceSummary(string Alias, string SelectorKind, string Selector, string RefType, string Axis, string? Subselector);+public sealed record FirmamentV2ModifyTraceSummary(string TargetSolid, IReadOnlyList<FirmamentV2RegionTraceSummary> Regions);+public sealed record FirmamentV2RegionTraceSummary(string Name, string Kind, string On, string Operation, string Tool, double Radius, string Through);public sealed record FirmamentPrimitiveAirTraceSummary(bool ParserBacked,@@ -66,6 +68,9 @@ public static class FirmamentFrontendTraceProbevar document = parseResult.Document;var loweredSolid = document.Solids.LastOrDefault(s => s.IsDerived) ?? document.Solid;var dimensions = new FirmamentTraceDimensions(loweredSolid.Box.Size[0], loweredSolid.Box.Size[1], loweredSolid.Box.Size[2]);+ var sideHoleIntent = document.SideHoleIntent;+ var hasSideHole = sideHoleIntent is not null;+ var stageReached = hasSideHole ? "region-parent-integrated" : "feature-air";var featureDiagnostics = new[]{"firmament-v2-box-record-recognized",@@ -81,7 +86,7 @@ public static class FirmamentFrontendTraceProbeFeatureAirNodeKind: "CreateBox",SourceDimensions: dimensions,ConstructionIntent: "Box",- StageReached: "feature-air",+ StageReached: hasSideHole ? "semantic-intent" : "feature-air",Diagnostics: featureDiagnostics,Guarantees:[@@ -97,12 +102,12 @@ public static class FirmamentFrontendTraceProbereturn new("FirmamentV2Parser",true,- "feature-air",- $"Firmament V2 parsed model '{document.ModelName}' with units '{document.Units}', lowered solid '{loweredSolid.Name}: {loweredSolid.RecordType}', and created Feature AIR CreateBox summary.",+ stageReached,+ $"Firmament V2 parsed model '{document.ModelName}' with units '{document.Units}', lowered solid '{loweredSolid.Name}: {loweredSolid.RecordType}', and created Feature AIR CreateBox summary." + (hasSideHole ? " Controlled side-hole semantic intent reached the existing AIR Region golden trace chain." : string.Empty),featureDiagnostics,featureAir,null,- new FirmamentV2TraceSummary("FirmamentV2", document.ModelName, document.Units, loweredSolid.Name, loweredSolid.RecordType, loweredSolid.Box.Size, "feature-air", document.Solids.Select(s => new FirmamentV2SolidTraceSummary(s.Name, s.RecordType, s.Box.Size, s.DerivedFrom, s.Overrides ?? new Dictionary<string, IReadOnlyList<double>>(), s.Box.Exposures.Select(e => new FirmamentV2ExposureTraceSummary(e.Alias, e.SelectorKind, e.Selector, e.RefType, e.Axis, e.Subselector)).ToArray())).ToArray()));+ new FirmamentV2TraceSummary("FirmamentV2", document.ModelName, document.Units, loweredSolid.Name, loweredSolid.RecordType, loweredSolid.Box.Size, stageReached, document.Solids.Select(s => new FirmamentV2SolidTraceSummary(s.Name, s.RecordType, s.Box.Size, s.DerivedFrom, s.Overrides ?? new Dictionary<string, IReadOnlyList<double>>(), s.Box.Exposures.Select(e => new FirmamentV2ExposureTraceSummary(e.Alias, e.SelectorKind, e.Selector, e.RefType, e.Axis, e.Subselector)).ToArray())).ToArray(), document.ModifyBlocks?.Select(m => new FirmamentV2ModifyTraceSummary(m.TargetSolid, m.Regions.Select(r => new FirmamentV2RegionTraceSummary(r.Name, r.Kind, r.Attachment.Source, r.Cut.OperationKind, r.Cut.Tool.ToolType, r.Cut.Tool.Radius, r.Cut.Tool.Through.Source)).ToArray())).ToArray(), sideHoleIntent, hasSideHole ? "Integrated" : null, hasSideHole ? "Closed" : null, hasSideHole ? "Succeeded" : null));}public static FirmamentFrontendTraceProbeResult ParseOnly(string sourceText)diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.csindex 3b22ad8b..1cd5f087 100644--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs@@ -1,8 +1,9 @@namespace Aetheris.Kernel.Firmament.FirmamentV2;-public sealed record FirmamentV2Document(string ModelName, string Units, IReadOnlyList<FirmamentV2SolidBinding> Solids)+public sealed record FirmamentV2Document(string ModelName, string Units, IReadOnlyList<FirmamentV2SolidBinding> Solids, IReadOnlyList<FirmamentV2ModifyBlock>? ModifyBlocks = null){public FirmamentV2SolidBinding Solid => Solids[^1];+ public FirmamentV2SideHoleIntent? SideHoleIntent => ModifyBlocks?.SelectMany(m => m.Regions.Select(r => new FirmamentV2SideHoleIntent(m.TargetSolid, r.Name, r.Attachment.Axis, r.Cut.Tool.Through.Axis, r.Cut.Tool.ToolType, r.Cut.Tool.Radius, Units))).SingleOrDefault();}public sealed record FirmamentV2SolidBinding(string Name, string RecordType, FirmamentV2BoxRecord Box, string? DerivedFrom = null, IReadOnlyDictionary<string, IReadOnlyList<double>>? Overrides = null)@@ -12,6 +13,15 @@ public sealed record FirmamentV2SolidBinding(string Name, string RecordType, Firpublic sealed record FirmamentV2BoxRecord(IReadOnlyList<double> Size, IReadOnlyList<FirmamentV2Exposure> Exposures);public sealed record FirmamentV2Exposure(string Alias, string SelectorKind, string Selector, string RefType, string Axis, string? Subselector);+public sealed record FirmamentV2FaceSelector(string Axis)+{+ public string Source => $"face({Axis})";+}+public sealed record FirmamentV2ModifyBlock(string TargetSolid, IReadOnlyList<FirmamentV2RegionDecl> Regions);+public sealed record FirmamentV2RegionDecl(string Name, string Kind, FirmamentV2FaceSelector Attachment, FirmamentV2CutOperation Cut);+public sealed record FirmamentV2CutOperation(string OperationKind, FirmamentV2CylinderTool Tool);+public sealed record FirmamentV2CylinderTool(string ToolType, double Radius, FirmamentV2FaceSelector Through);+public sealed record FirmamentV2SideHoleIntent(string TargetSolid, string RegionName, string AttachFace, string ThroughFace, string Tool, double Radius, string Units);public sealed record FirmamentV2ParseResult(bool IsSuccess, FirmamentV2Document? Document, IReadOnlyList<string> Diagnostics){public static FirmamentV2ParseResult Success(FirmamentV2Document document, IReadOnlyList<string> diagnostics) => new(true, document, diagnostics);diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.csindex ca7f8c5d..2049f334 100644--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs@@ -31,6 +31,18 @@ public static class FirmamentV2Parserpublic const string FatArrowOutsideExpose = "firmament-v2-fat-arrow-outside-expose";public const string RawBackendIdReferenceForbidden = "firmament-raw-backend-id-reference-forbidden";+ public const string ModifyTargetUnresolved = "firmament-v2-modify-target-unresolved";+ public const string ModifyTargetNotSolid = "firmament-v2-modify-target-not-solid";+ public const string RegionUnsupported = "firmament-v2-region-unsupported";+ public const string RegionAttachmentSelectorUnsupported = "firmament-v2-region-attachment-selector-unsupported";+ public const string CutUnsupported = "firmament-v2-cut-unsupported";+ public const string CutToolUnsupported = "firmament-v2-cut-tool-unsupported";+ public const string CylinderRadiusMissing = "firmament-v2-cylinder-radius-missing";+ public const string CylinderRadiusInvalid = "firmament-v2-cylinder-radius-invalid";+ public const string ThroughSelectorUnsupported = "firmament-v2-through-selector-unsupported";+ public const string SideHoleOnlyPlusXMinusXSupported = "firmament-v2-side-hole-only-plus-x-minus-x-supported";+ public const string SideHoleRadiusExceedsClearance = "firmament-v2-side-hole-radius-exceeds-clearance";+private static readonly Regex ModelRegex = new(@"\bmodel\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)\s*\{", RegexOptions.CultureInvariant);private static readonly Regex UnitsRegex = new(@"\bunits\s+(?<units>[A-Za-z_][A-Za-z0-9_]*)\b", RegexOptions.CultureInvariant);private static readonly Regex SolidHeaderRegex = new(@"\bsolid\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)\s*:\s*(?<target>[A-Za-z_][A-Za-z0-9_]*)(?<with>\s+with)?\s*\{", RegexOptions.CultureInvariant);@@ -40,6 +52,11 @@ public static class FirmamentV2Parserprivate static readonly Regex ExposeRegex = new(@"\bexpose\s*\{(?<body>.*?)\}", RegexOptions.CultureInvariant | RegexOptions.Singleline);private static readonly Regex ExposureLineRegex = new(@"^\s*(?<selector>.+?)\s*=>\s*(?<alias>[A-Za-z_][A-Za-z0-9_]*)\s*$", RegexOptions.CultureInvariant);private static readonly Regex FaceSelectorRegex = new(@"^face\((?<axis>[+-][XYZ])\)(?<sub>\.[A-Za-z_][A-Za-z0-9_]*)?$", RegexOptions.CultureInvariant);+ private static readonly Regex ModifyHeaderRegex = new(@"\bmodify\s+(?<target>[A-Za-z_][A-Za-z0-9_]*)\s*\{", RegexOptions.CultureInvariant);+ private static readonly Regex RegionHeaderRegex = new(@"\bregion\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)\s+on\s+(?<selector>face\([^)]*\))\s*\{", RegexOptions.CultureInvariant);+ private static readonly Regex CutHeaderRegex = new(@"\bcut\s+(?<tool>[A-Za-z_][A-Za-z0-9_]*)\s*\{", RegexOptions.CultureInvariant);+ private static readonly Regex RadiusRegex = new(@"\bradius\s*:\s*(?<value>[-+]?[0-9]+(?:\.[0-9]+)?)", RegexOptions.CultureInvariant);+ private static readonly Regex ThroughRegex = new(@"\bthrough\s*:\s*(?<selector>face\([^)]*\))", RegexOptions.CultureInvariant);public static FirmamentV2ParseResult Parse(string sourceText){@@ -84,9 +101,11 @@ public static class FirmamentV2Parser}}+ var modifyBlocks = ParseModifyBlocks(source, byName, diagnostics);+FirmamentV2Document? document = null;if (modelMatch.Success && unitsMatch.Success && solids.Count > 0 && !diagnostics.Any(IsFatalDiagnostic))- document = new FirmamentV2Document(modelMatch.Groups["name"].Value, unitsMatch.Groups["units"].Value, solids);+ document = new FirmamentV2Document(modelMatch.Groups["name"].Value, unitsMatch.Groups["units"].Value, solids, modifyBlocks);diagnostics.Add(document is null ? "firmament-v2-parse-failed" : "firmament-v2-parse-succeeded");diagnostics.Sort(StringComparer.Ordinal);@@ -115,7 +134,7 @@ public static class FirmamentV2Parserreturn new(name, "Box", new(values, []), baseName, new Dictionary<string, IReadOnlyList<double>>(StringComparer.Ordinal) { ["size"] = values });}- private static bool IsFatalDiagnostic(string code) => code is MissingModel or MissingUnits or MissingSolid or UnsupportedConstruct or UnknownRecordType or BoxMissingSize or BoxSizeArity or DegenerateDimension or NameUnresolved or DuplicateName or WithRequiresRecord or WithRequiresBoxRecord or WithFieldNotFound or WithFieldTypeMismatch or WithForwardReference or WithDerivedRecordInvalid or ExposeBlockUnsupported or ExposeRequiresBoxRecord or ExposeAliasDuplicate or ExposeAliasInvalid or SelectorUnsupported or SelectorAxisInvalid or SelectorSubselectorUnsupported or FatArrowOutsideExpose or RawBackendIdReferenceForbidden;+ private static bool IsFatalDiagnostic(string code) => code is MissingModel or MissingUnits or MissingSolid or UnsupportedConstruct or UnknownRecordType or BoxMissingSize or BoxSizeArity or DegenerateDimension or NameUnresolved or DuplicateName or WithRequiresRecord or WithRequiresBoxRecord or WithFieldNotFound or WithFieldTypeMismatch or WithForwardReference or WithDerivedRecordInvalid or ExposeBlockUnsupported or ExposeRequiresBoxRecord or ExposeAliasDuplicate or ExposeAliasInvalid or SelectorUnsupported or SelectorAxisInvalid or SelectorSubselectorUnsupported or FatArrowOutsideExpose or RawBackendIdReferenceForbidden or ModifyTargetUnresolved or ModifyTargetNotSolid or RegionUnsupported or RegionAttachmentSelectorUnsupported or CutUnsupported or CutToolUnsupported or CylinderRadiusMissing or CylinderRadiusInvalid or ThroughSelectorUnsupported or SideHoleOnlyPlusXMinusXSupported or SideHoleRadiusExceedsClearance;private static IReadOnlyList<FirmamentV2Exposure> ParseExposures(string body, List<string> diagnostics){@@ -174,8 +193,71 @@ public static class FirmamentV2Parserreturn diagnostics.Contains(DegenerateDimension) ? null : values;}++ private static IReadOnlyList<FirmamentV2ModifyBlock> ParseModifyBlocks(string source, Dictionary<string, FirmamentV2SolidBinding> byName, List<string> diagnostics)+ {+ var blocks = new List<FirmamentV2ModifyBlock>();+ foreach (Match match in ModifyHeaderRegex.Matches(source))+ {+ var target = match.Groups["target"].Value;+ if (!byName.TryGetValue(target, out var solid)) { diagnostics.Add(ModifyTargetUnresolved); continue; }+ if (!string.Equals(solid.RecordType, "Box", StringComparison.Ordinal)) { diagnostics.Add(ModifyTargetNotSolid); continue; }+ var open = source.IndexOf('{', match.Index);+ var close = FindMatchingBrace(source, open);+ if (close < 0) { diagnostics.Add(RegionUnsupported); continue; }+ var body = source[(open + 1)..close];+ var region = ParseRegion(body, solid, diagnostics);+ if (region is not null) blocks.Add(new(target, [region]));+ }+ return blocks;+ }++ private static FirmamentV2RegionDecl? ParseRegion(string body, FirmamentV2SolidBinding solid, List<string> diagnostics)+ {+ var regions = RegionHeaderRegex.Matches(body);+ if (regions.Count != 1) { diagnostics.Add(RegionUnsupported); return null; }+ var rm = regions[0];+ if (!string.Equals(rm.Groups["name"].Value, "sideHole", StringComparison.Ordinal)) { diagnostics.Add(RegionUnsupported); return null; }+ var attach = ParseFaceSelector(rm.Groups["selector"].Value, RegionAttachmentSelectorUnsupported, diagnostics);+ var open = body.IndexOf('{', rm.Index);+ var close = FindMatchingBrace(body, open);+ if (close < 0) { diagnostics.Add(RegionUnsupported); return null; }+ var cut = ParseCut(body[(open + 1)..close], diagnostics);+ if (attach is null || cut is null) return null;+ if (attach.Axis != "+X" || cut.Tool.Through.Axis != "-X") diagnostics.Add(SideHoleOnlyPlusXMinusXSupported);+ var clearance = Math.Min(solid.Box.Size[1], solid.Box.Size[2]) / 2.0;+ if (cut.Tool.Radius >= clearance) diagnostics.Add(SideHoleRadiusExceedsClearance);+ return diagnostics.Any(IsFatalDiagnostic) ? null : new(rm.Groups["name"].Value, "FaceAttachedRegion", attach, cut);+ }++ private static FirmamentV2CutOperation? ParseCut(string body, List<string> diagnostics)+ {+ var cuts = CutHeaderRegex.Matches(body);+ if (cuts.Count != 1) { diagnostics.Add(CutUnsupported); return null; }+ var cm = cuts[0];+ if (!string.Equals(cm.Groups["tool"].Value, "Cylinder", StringComparison.Ordinal) && !string.Equals(cm.Groups["tool"].Value, "cylinder", StringComparison.Ordinal)) { diagnostics.Add(CutToolUnsupported); return null; }+ var open = body.IndexOf('{', cm.Index);+ var close = FindMatchingBrace(body, open);+ if (close < 0) { diagnostics.Add(CutUnsupported); return null; }+ var toolBody = body[(open + 1)..close];+ var radiusMatch = RadiusRegex.Match(toolBody);+ if (!radiusMatch.Success) { diagnostics.Add(CylinderRadiusMissing); return null; }+ if (!double.TryParse(radiusMatch.Groups["value"].Value, NumberStyles.Float, CultureInfo.InvariantCulture, out var radius) || radius <= 0) { diagnostics.Add(CylinderRadiusInvalid); return null; }+ var throughMatch = ThroughRegex.Match(toolBody);+ var through = throughMatch.Success ? ParseFaceSelector(throughMatch.Groups["selector"].Value, ThroughSelectorUnsupported, diagnostics) : null;+ if (through is null) { diagnostics.Add(ThroughSelectorUnsupported); return null; }+ return new("Cut", new("Cylinder", radius, through));+ }++ private static FirmamentV2FaceSelector? ParseFaceSelector(string selector, string diagnostic, List<string> diagnostics)+ {+ var face = FaceSelectorRegex.Match(selector);+ if (!face.Success || face.Groups["sub"].Success) { diagnostics.Add(diagnostic); return null; }+ return new(face.Groups["axis"].Value);+ }+private static bool ContainsUnsupportedConstruct(string source) =>- Regex.IsMatch(source, @"\b(concept|PMI|where|template|cut|add|shell|fillet|chamfer|region|regions|profile|material|pattern|modify)\b|<\s*Process\s*>", RegexOptions.CultureInvariant);+ Regex.IsMatch(source, @"\b(concept|PMI|where|template|add|shell|fillet|chamfer|regions|profile|material|pattern)\b|<\s*Process\s*>", RegexOptions.CultureInvariant);private static bool ContainsRawBackendId(string source) =>Regex.IsMatch(source, @"\b(brep|step|backend|coedge)\s*\.|STEP\s*#|#[0-9]+", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);diff --git a/docs/air-firmament-a1-firmament-fixture-corpus.md b/docs/air-firmament-a1-firmament-fixture-corpus.mdindex 07b1bd51..8089e126 100644--- a/docs/air-firmament-a1-firmament-fixture-corpus.md+++ b/docs/air-firmament-a1-firmament-fixture-corpus.md@@ -177,3 +177,8 @@ A2.2 expands the `fixtures/FirmamentV2/` metadata-only taxonomy with `RecordDeri## X3 fixture stage note`fixtures/FirmamentV2/SemanticRefs/valid/named-box-faces-v2.valid.firmfixture` is parser-backed as of AIR-FIRMAMENT-X3 and is expected to reach `feature-air` while reporting four semantic exposure aliases.+++## AIR-FIRMAMENT-X4 fixture promotion++`fixtures/FirmamentV2/Region/valid/side-hole-v2.valid.firmfixture` is parser-backed for the controlled +X to -X side-hole region and reaches `region-parent-integrated` through the existing AIR Region golden trace path.diff --git a/docs/air-firmament-a2-firmament-v2-source-language-design.md b/docs/air-firmament-a2-firmament-v2-source-language-design.mdindex 9ca7f24d..d8fd412c 100644--- a/docs/air-firmament-a2-firmament-v2-source-language-design.md+++ b/docs/air-firmament-a2-firmament-v2-source-language-design.md@@ -366,3 +366,8 @@ Recommended next milestones:## A2.1 semantic contract addendumAIR-FIRMAMENT-A2.1 extends this source-language design with the semantic-reference and admissibility contract that must be settled before parser work begins. See `docs/air-firmament-a2-1-semantic-references-admissibility-surface-doctrine.md` for the typed source-level reference model, the reserved `=>` exposure/binding syntax, compile-time degeneracy/admissibility doctrine, ruled/sweep/offset-first surface policy, limited-admission spline/NURBS policy, pattern-as-record/no-control-flow doctrine, and feature-output role vocabulary. A2.1 remains design/audit only: no full V2 parser, backend behavior change, corpus migration, or geometry feature implementation is introduced.+++## AIR-FIRMAMENT-X4 side-hole parser slice++The controlled parser-backed V2 side-hole region slice is documented in [AIR-FIRMAMENT-X4](air-firmament-x4-v2-side-hole-region.md). It preserves V1/V2 parser separation and supports only the canonical `modify base { region sideHole on face(+X) { cut Cylinder { radius: 1 through: face(-X) } } }` route.diff --git a/docs/air-firmament-x4-v2-side-hole-region.md b/docs/air-firmament-x4-v2-side-hole-region.mdnew file mode 100644index 00000000..f77f3653--- /dev/null+++ b/docs/air-firmament-x4-v2-side-hole-region.md@@ -0,0 +1,68 @@+# AIR-FIRMAMENT-X4 — Firmament V2 side-hole region parser slice++## Purpose and scope++X4 adds the first parser-backed Firmament V2 region slice for one controlled side-hole fixture. The supported source shape is one `model`, `units mm`, one Box solid named `base`, one `modify base` block, one `region sideHole on face(+X)`, and one `cut Cylinder` tool with `radius: 1` and `through: face(-X)`.++## Relationship to X1-X3++X1 introduced the isolated V2 parser/frontend for typed-record `Box`. X2 added `Box with` derivation. X3 added Box semantic face references and `=>` exposure. X4 preserves those forms and extends the same V2 parser/AST surface with `modify`, `region`, `cut Cylinder`, and side-hole semantic intent records.++## Relationship to existing AIR Region golden path++The V2 side-hole fixture now lowers its controlled semantic intent to the existing AIR Region side-hole trace chain. The reached stage is `region-parent-integrated`, with parent integration `Integrated`, shell closure `Closed`, and STEP smoke `Succeeded`. The lowering reuses the already-proven controlled +X entry / -X exit side-hole path rather than adding general Boolean or topology authority.++## V1/V2 parser separation++X4 keeps V2 code in the existing `FirmamentV2` parser/AST and `ParseV2Only` frontend path. The V1 parser is not expanded and V2 side-hole fixtures are not routed through the legacy V1 parser.++## Supported X4 syntax++```firmament+model SideHoleV2 {+ units mm+ solid base: Box { size: [10, 8, 6] }+ modify base {+ region sideHole on face(+X) {+ cut Cylinder {+ radius: 1+ through: face(-X)+ }+ }+ }+}+```++`cut cylinder` is also normalized to `Cylinder` for this controlled slice.++## Unsupported constructs++Multiple regions, multiple arbitrary modifications, `add`, non-Cylinder tools, arbitrary faces outside the controlled +X/-X route, arbitrary axes, cylinder height, center offsets, blind cuts, selectors beyond plain `face(+X)` and `face(-X)`, feature-output refs inside regions, `=>` inside regions, `with` inside regions, templates, concepts, PMI, `where`, shell, fillet, chamfer, surfacing, material, pattern, and arbitrary expressions remain unsupported.++## Semantic intent model++The parser preserves a `SideHoleIntent` with target solid `base`, region name `sideHole`, attach face `+X`, through face `-X`, tool `Cylinder`, radius `1`, and units `mm`.++## Lowering attempt and JudgmentEngine usage++JudgmentEngine was not used. X4 has one deterministic controlled route after parser admissibility checks; adding a route scorer would add ceremony without competing admissible strategies.++## Outcome reached++Full golden path was reached for the controlled fixture: `region-parent-integrated`, parent integration `Integrated`, shell closure `Closed`, and STEP smoke `Succeeded`.++## Fixture changes++`fixtures/FirmamentV2/Region/valid/side-hole-v2.valid.firmfixture` is promoted to parser-backed implemented status. Focused invalid fixtures cover unsupported attach face, unsupported through face, invalid radius, and unresolved modify target.++## Diagnostics++Stable diagnostics added include `firmament-v2-modify-target-unresolved`, `firmament-v2-side-hole-only-plus-x-minus-x-supported`, and `firmament-v2-cylinder-radius-invalid`, plus adjacent parser diagnostics for unsupported region/cut/tool/selector cases.++## Tests run++Validation included CLI build/help/trace commands and focused parser/frontend tests. The trace command shows the V2 source facts, semantic intent, AIR Region route, parent integration, shell closure, and STEP smoke evidence.++## Next milestone recommendation++The next milestone should either generalize a second controlled side-hole variant with explicit admissibility limits or add a thin adapter object between `SideHoleIntent` and AIR Region construction so future V2 regions avoid direct trace-probe coupling. Do not broaden Boolean admission or arbitrary face/axis support until that adapter exists.diff --git a/fixtures/FirmamentV2/Region/invalid/side-hole-invalid-attach-v2.invalid.firmfixture b/fixtures/FirmamentV2/Region/invalid/side-hole-invalid-attach-v2.invalid.firmfixturenew file mode 100644index 00000000..12c55a3e--- /dev/null+++ b/fixtures/FirmamentV2/Region/invalid/side-hole-invalid-attach-v2.invalid.firmfixture@@ -0,0 +1,11 @@+// fixture-id: side-hole-invalid-attach-v2+// case: firmament-v2-side-hole-invalid-attach+// category: Region+// syntax-version: FirmamentV2+// validity: invalid+// implementation: parser-backed+// expected: invalid+// expected-stage: parsed+// expected-diagnostic: firmament-v2-side-hole-only-plus-x-minus-x-supported++model SideHoleV2 { units mm solid base: Box { size: [10, 8, 6] } modify base { region sideHole on face(+Y) { cut Cylinder { radius: 1 through: face(-X) } } } }diff --git a/fixtures/FirmamentV2/Region/invalid/side-hole-invalid-radius-v2.invalid.firmfixture b/fixtures/FirmamentV2/Region/invalid/side-hole-invalid-radius-v2.invalid.firmfixturenew file mode 100644index 00000000..14e23af8--- /dev/null+++ b/fixtures/FirmamentV2/Region/invalid/side-hole-invalid-radius-v2.invalid.firmfixture@@ -0,0 +1,11 @@+// fixture-id: side-hole-invalid-radius-v2+// case: firmament-v2-side-hole-invalid-radius+// category: Region+// syntax-version: FirmamentV2+// validity: invalid+// implementation: parser-backed+// expected: invalid+// expected-stage: parsed+// expected-diagnostic: firmament-v2-cylinder-radius-invalid++model SideHoleV2 { units mm solid base: Box { size: [10, 8, 6] } modify base { region sideHole on face(+X) { cut Cylinder { radius: 0 through: face(-X) } } } }diff --git a/fixtures/FirmamentV2/Region/invalid/side-hole-invalid-through-v2.invalid.firmfixture b/fixtures/FirmamentV2/Region/invalid/side-hole-invalid-through-v2.invalid.firmfixturenew file mode 100644index 00000000..1620bdec--- /dev/null+++ b/fixtures/FirmamentV2/Region/invalid/side-hole-invalid-through-v2.invalid.firmfixture@@ -0,0 +1,11 @@+// fixture-id: side-hole-invalid-through-v2+// case: firmament-v2-side-hole-invalid-through+// category: Region+// syntax-version: FirmamentV2+// validity: invalid+// implementation: parser-backed+// expected: invalid+// expected-stage: parsed+// expected-diagnostic: firmament-v2-side-hole-only-plus-x-minus-x-supported++model SideHoleV2 { units mm solid base: Box { size: [10, 8, 6] } modify base { region sideHole on face(+X) { cut Cylinder { radius: 1 through: face(+Z) } } } }diff --git a/fixtures/FirmamentV2/Region/invalid/side-hole-unknown-modify-target-v2.invalid.firmfixture b/fixtures/FirmamentV2/Region/invalid/side-hole-unknown-modify-target-v2.invalid.firmfixturenew file mode 100644index 00000000..bffdf92f--- /dev/null+++ b/fixtures/FirmamentV2/Region/invalid/side-hole-unknown-modify-target-v2.invalid.firmfixture@@ -0,0 +1,11 @@+// fixture-id: side-hole-unknown-modify-target-v2+// case: firmament-v2-side-hole-unknown-modify-target+// category: Region+// syntax-version: FirmamentV2+// validity: invalid+// implementation: parser-backed+// expected: invalid+// expected-stage: parsed+// expected-diagnostic: firmament-v2-modify-target-unresolved++model SideHoleV2 { units mm solid base: Box { size: [10, 8, 6] } modify missing { region sideHole on face(+X) { cut Cylinder { radius: 1 through: face(-X) } } } }diff --git a/fixtures/FirmamentV2/Region/valid/side-hole-v2.valid.firmfixture b/fixtures/FirmamentV2/Region/valid/side-hole-v2.valid.firmfixtureindex 9118c4d9..52fa4413 100644--- a/fixtures/FirmamentV2/Region/valid/side-hole-v2.valid.firmfixture+++ b/fixtures/FirmamentV2/Region/valid/side-hole-v2.valid.firmfixture@@ -3,22 +3,31 @@// category: Region// syntax-version: FirmamentV2// validity: valid-// implementation: not-implemented+// implementation: parser-backed// expected: valid-// expected-stage: not-implemented-// expected-diagnostic: firmament-v2-parser-not-ready-// notes: AIR-FIRMAMENT-A2 V2 side-hole golden-path syntax design; not general side-hole support and not parser-backed.+// expected-stage: region-parent-integrated+// expected-parent-integration: Integrated+// expected-shell-closure: Closed+// expected-step-smoke: Succeeded+// expected-feature: sideHole+// expected-region-kind: FaceAttachedRegion+// expected-entry-face: +X+// expected-exit-face: -X+// expected-tool: Cylinder+// expected-radius: 1+// parser-backed: true+// notes: AIR-FIRMAMENT-X4 parser-backed controlled V2 side-hole region fixture.-model SideHoleExample {+model SideHoleV2 {units mm- solid base = box {+ solid base: Box {size: [10, 8, 6]}modify base {region sideHole on face(+X) {- cut cylinder {+ cut Cylinder {radius: 1through: face(-X)}