Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Add Firmament V2 semantic PMI STEP emission
Yuechen Lic0c4d8979b65
diff --git a/Aetheris.CLI.Tests/FirmamentFixtureCorpusTests.cs b/Aetheris.CLI.Tests/FirmamentFixtureCorpusTests.csindex 730af3e4..f5ebfcd3 100644--- a/Aetheris.CLI.Tests/FirmamentFixtureCorpusTests.cs+++ b/Aetheris.CLI.Tests/FirmamentFixtureCorpusTests.cs@@ -180,7 +180,7 @@ public sealed class FirmamentFixtureCorpusTestsvar fixture = LoadMetadata(path);Assert.Equal("FirmamentV2", fixture["syntax-version"]);Assert.Equal("SemanticRefs", fixture["category"]);- if (fixture["implementation"] != "parser-backed" || fixture["validity"] == "invalid") Assert.True(fixture.ContainsKey("expected-diagnostic"), path);+ if (fixture["implementation"] != "parser-backed" || fixture["validity"] == "invalid") if (fixture["implementation"] != "parser-backed") Assert.True(fixture.ContainsKey("expected-diagnostic"), path);}}@@ -361,13 +361,13 @@ public sealed class FirmamentFixtureCorpusTestspublic void FirmamentV2PMI_MetadataRecognized(){var fixtures = DiscoverV2Fixtures().Where(p => p.Contains("/PMI/", StringComparison.Ordinal)).ToArray();- Assert.Equal(3, fixtures.Length);+ Assert.Equal(5, fixtures.Length);foreach (var path in fixtures){var fixture = LoadMetadata(path);Assert.Equal("FirmamentV2", fixture["syntax-version"]);Assert.Equal("PMI", fixture["category"]);- Assert.True(fixture.ContainsKey("expected-diagnostic"), path);+ if (fixture["implementation"] != "parser-backed") Assert.True(fixture.ContainsKey("expected-diagnostic"), path);}}diff --git a/Aetheris.CLI.Tests/FirmamentV2SemanticPmiStepPipelineTests.cs b/Aetheris.CLI.Tests/FirmamentV2SemanticPmiStepPipelineTests.csnew file mode 100644index 00000000..5b9d1f9f--- /dev/null+++ b/Aetheris.CLI.Tests/FirmamentV2SemanticPmiStepPipelineTests.cs@@ -0,0 +1,59 @@+using System.Text.RegularExpressions;+using Aetheris.Kernel.Core.Step242;++namespace Aetheris.CLI.Tests;++public sealed class FirmamentV2SemanticPmiStepPipelineTests+{+ public static TheoryData<string, string, string, double> Cases => new()+ {+ { "pmi-v2-hole-diameter-callout-emits-in-step", "SHAPE_DIMENSION_REPRESENTATION('diameter:base.mount'", "PROPERTY_DEFINITION('diameter:base.mount'", 480d - Math.PI * 1d * 1d * 6d },+ { "pmi-v2-datum-plane-emits-in-step", "SHAPE_ASPECT('firmament-datum:A'", "PROPERTY_DEFINITION('datum:A:base'", 480d }+ };++ [Theory]+ [MemberData(nameof(Cases))]+ public void STEP_V2_X7_semantic_pmi_step_verified_builds_emits_reimports_and_matches_volume(string fixtureId, string primaryEvidence, string secondaryEvidence, double expectedVolume)+ {+ var fixturePath = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, $"../../../../fixtures/FirmamentV2/PMI/valid/{fixtureId}.valid.firmfixture"));+ var outDir = Path.Combine(Path.GetTempPath(), "aetheris-step-v2-x7", Guid.NewGuid().ToString("N"));+ Directory.CreateDirectory(outDir);+ var stepPath = Path.Combine(outDir, fixtureId + ".step");++ var stdout = new StringWriter();+ var stderr = new StringWriter();+ var exit = Aetheris.CLI.CliRunner.Run(["build", fixturePath, "--out", stepPath, "--json"], stdout, stderr);++ Assert.True(exit == 0, stderr.ToString());+ Assert.True(File.Exists(stepPath), fixtureId + " reaches real build command");++ var fixtureText = File.ReadAllText(fixturePath);+ Assert.Contains("expected-stage: step-verified", fixtureText, StringComparison.Ordinal);+ Assert.Contains("current-stage: step-verified", fixtureText, StringComparison.Ordinal);+ Assert.Contains("roundtrip-required: true", fixtureText, StringComparison.Ordinal);+ Assert.Contains("semantic-pmi-required: true", fixtureText, StringComparison.Ordinal);+ Assert.Contains("graphical-pmi-required: false", fixtureText, StringComparison.Ordinal);+ Assert.Contains("build-command: aetheris build", fixtureText, StringComparison.Ordinal);++ var stepText = File.ReadAllText(stepPath);+ Assert.True(CountStepEntities(stepText, "ADVANCED_FACE") > 0, fixtureId + " emits real STEP advanced faces");+ Assert.True(CountStepEntities(stepText, "VERTEX_POINT") > 0, fixtureId + " emits STEP vertex topology marker");+ Assert.Contains(primaryEvidence, stepText, StringComparison.Ordinal);+ Assert.Contains(secondaryEvidence, stepText, StringComparison.Ordinal);+ Assert.DoesNotContain("DRAUGHTING_CALLOUT", stepText, StringComparison.Ordinal);+ Assert.DoesNotContain("ANNOTATION_PLANE", stepText, StringComparison.Ordinal);++ var import = Step242Importer.ImportBody(stepText);+ Assert.True(import.IsSuccess, string.Join(Environment.NewLine, import.Diagnostics.Select(d => d.Message)));+ Assert.True(import.Value.Topology.Faces.Count() > 0);+ Assert.True(import.Value.Topology.Vertices.Count() > 0);++ var volume = StepAnalyzer.AnalyzeVolume(stepPath);+ Assert.True(volume.Success, fixtureId + " volume analysis succeeds");+ Assert.True(volume.Exact, fixtureId + " volume should use exact analysis.");+ Assert.InRange(Math.Abs(volume.Volume - expectedVolume), 0d, 1e-8);+ }++ private static int CountStepEntities(string stepText, string entityName) =>+ Regex.Matches(stepText, "=\\s*" + Regex.Escape(entityName) + "\\s*\\(", RegexOptions.CultureInvariant).Count;+}diff --git a/Aetheris.CLI/AirTrace.cs b/Aetheris.CLI/AirTrace.csindex 663a07d3..aed9cada 100644--- a/Aetheris.CLI/AirTrace.cs+++ b/Aetheris.CLI/AirTrace.cs@@ -133,7 +133,7 @@ internal static class AirTraceReportBuilderif (isFirmamentV2 && string.Equals(fixture.ExpectedStage, "step-verified", StringComparison.Ordinal)){var featureArea = fixture.Metadata.GetValueOrDefault("feature-area");- var stepVerified = string.Equals(featureArea, "semantic-hole", StringComparison.Ordinal) || string.Equals(featureArea, "semantic-reference", StringComparison.Ordinal) || string.Equals(featureArea, "multi-feature-composition", StringComparison.Ordinal)+ var stepVerified = string.Equals(featureArea, "semantic-hole", StringComparison.Ordinal) || string.Equals(featureArea, "semantic-reference", StringComparison.Ordinal) || string.Equals(featureArea, "multi-feature-composition", StringComparison.Ordinal) || string.Equals(featureArea, "semantic-pmi", StringComparison.Ordinal)? TryVerifyV2SemanticHoleStepFixture(fixture): TryVerifyV2BoxStepFixture(fixture);if (stepVerified.Succeeded)@@ -295,6 +295,8 @@ internal static class AirTraceReportBuilder"feature-v2-shaft-hole-blind-step-verified" => 480d - Math.PI * 3d,"feature-v2-counterbore-step-verified" => 480d - ((Math.PI * 6d) + (Math.PI * 3d)),"feature-v2-countersink-step-verified" => 480d - ((Math.PI * 6d) + (Math.PI * 7d / 3d) - Math.PI),+ "pmi-v2-hole-diameter-callout-emits-in-step" => 480d - Math.PI * 6d,+ "pmi-v2-datum-plane-emits-in-step" => 480d,_ => double.NaN};@@ -304,6 +306,24 @@ internal static class AirTraceReportBuilderreturn (false, Stable(diagnostics).ToArray());}+ if (string.Equals(fixture.Metadata.GetValueOrDefault("feature-area"), "semantic-pmi", StringComparison.Ordinal))+ {+ var hasPmiEvidence = fixture.CaseName switch+ {+ "pmi-v2-hole-diameter-callout-emits-in-step" => stepText.Contains("SHAPE_DIMENSION_REPRESENTATION('diameter:base.mount'", StringComparison.Ordinal),+ "pmi-v2-datum-plane-emits-in-step" => stepText.Contains("PROPERTY_DEFINITION('datum:A:base'", StringComparison.Ordinal),+ _ => false+ };+ if (!hasPmiEvidence)+ {+ diagnostics.Add("step-v2-x7-semantic-pmi-evidence-missing");+ return (false, Stable(diagnostics).ToArray());+ }++ diagnostics.Add("step-v2-x7-semantic-pmi-evidence-verified");+ diagnostics.Add("step-v2-x7-graphical-pmi-not-required");+ }+diagnostics.Add("step-v2-x2-real-ap242-emitted");diagnostics.Add("step-v2-x2-step-roundtrip-succeeded");diagnostics.Add("step-v2-x2-topology-evidence-verified");diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentV2ParserTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentV2ParserTests.csindex 7c3c688b..06f73c59 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentV2ParserTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentV2ParserTests.cs@@ -817,6 +817,49 @@ model AliasFailure {}}++ [Fact]+ public void FirmamentV2Parser_SemanticPmi_ParsesHoleDiameterAndDatumPlane()+ {+ var hole = FirmamentV2Parser.Parse(Source("PMI/valid/pmi-v2-hole-diameter-callout-emits-in-step.valid.firmfixture"));+ Assert.True(hole.IsSuccess, string.Join(", ", hole.Diagnostics));+ var holePmi = Assert.Single(hole.Document!.Pmi!);+ Assert.Equal(FirmamentV2PmiKind.HoleDiameter, holePmi.Kind);+ Assert.Equal("mountDiameter", holePmi.Name);+ Assert.Equal("mount", holePmi.Target);+ Assert.Equal(2d, holePmi.Value);++ var datum = FirmamentV2Parser.Parse(Source("PMI/valid/pmi-v2-datum-plane-emits-in-step.valid.firmfixture"));+ Assert.True(datum.IsSuccess, string.Join(", ", datum.Diagnostics));+ var datumPmi = Assert.Single(datum.Document!.Pmi!);+ Assert.Equal(FirmamentV2PmiKind.DatumPlane, datumPmi.Kind);+ Assert.Equal("A", datumPmi.Name);+ Assert.Equal("top", datumPmi.Target);+ }++ [Fact]+ public void FirmamentV2Parser_SemanticPmi_InvalidTargetAndDiameterAreDeterministicDiagnostics()+ {+ var unknown = FirmamentV2Parser.Parse("""+model BadPmiTarget {+ units mm+ solid base: Box { size: [10, 8, 6] }+ pmi { diameter bad { target: missing value: 2mm } }+}+""");+ Assert.Contains(FirmamentV2Parser.PmiTargetUnresolved, unknown.Diagnostics);++ var invalidDiameter = FirmamentV2Parser.Parse("""+model BadPmiDiameter {+ units mm+ solid base: Box { size: [10, 8, 6] }+ modify base { hole<shaft> mount { on: face(+Z) center: [0, 0] diameter: 2 end: throughAll } }+ pmi { diameter bad { target: mount value: 2deg } }+}+""");+ Assert.Contains(FirmamentV2Parser.PmiDiameterInvalid, invalidDiameter.Diagnostics);+ }+private static string Source(string relative){var path = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "../../../../fixtures/FirmamentV2", relative));diff --git a/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.cs b/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.csindex 3243c978..07bf5c8d 100644--- a/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.cs+++ b/Aetheris.Kernel.Firmament/FirmamentBuildAndExport.cs@@ -70,7 +70,8 @@ public static class FirmamentBuildAndExportreturn KernelResult<FirmamentStepExportResult>.Failure(execution.Diagnostics);}- var step = Step242Exporter.ExportBody(executedPrimitive.Body);+ var semanticPmi = BuildV2SemanticPmi(v2Parse.Document, [], executedPrimitive.FeatureId);+ var step = Step242Exporter.ExportBody(executedPrimitive.Body, semanticPmi);if (!step.IsSuccess){return KernelResult<FirmamentStepExportResult>.Failure(step.Diagnostics);@@ -83,7 +84,7 @@ public static class FirmamentBuildAndExportexecutedPrimitive.OpIndex,"primitive",v2Parse.Document.Solid.RecordType.ToLowerInvariant(),- DatumInspection: [],+ DatumInspection: v2Parse.Document.Pmi?.Where(p => p.Kind == FirmamentV2PmiKind.DatumPlane).Select(p => new FirmamentPmiInspectionDatum(p.Name, "planar", p.Target)).ToArray() ?? [],DimensionInspection: []));}@@ -140,7 +141,8 @@ public static class FirmamentBuildAndExport}}- var step = Step242Exporter.ExportBody(body);+ var semanticPmi = BuildV2SemanticPmi(document, semanticHoles, modifyTargets[0]);+ var step = Step242Exporter.ExportBody(body, semanticPmi);if (!step.IsSuccess){return KernelResult<FirmamentStepExportResult>.Failure(step.Diagnostics);@@ -153,10 +155,58 @@ public static class FirmamentBuildAndExport0,semanticHoles.Count == 1 ? nameof(AirHoleSimpleShaftMaterializer) : nameof(AirHoleCompositeMaterializer),semanticHoles.Count == 1 ? feature.Stack.Kind.ToString() : "CompositeSimpleShaft",- DatumInspection: [],- DimensionInspection: []));+ DatumInspection: document.Pmi?.Where(p => p.Kind == FirmamentV2PmiKind.DatumPlane).Select(p => new FirmamentPmiInspectionDatum(p.Name, "planar", p.Target)).ToArray() ?? [],+ DimensionInspection: document.Pmi?.Where(p => p.Kind == FirmamentV2PmiKind.HoleDiameter).Select(p => new FirmamentPmiInspectionDimension("Diameter", p.Target, null, p.Value ?? 0d, "explicit-v2-semantic-pmi", null)).ToArray() ?? []));}+ private static IReadOnlyList<Step242SemanticPmi> BuildV2SemanticPmi(FirmamentV2Document document, IReadOnlyList<Core.Air.AirHoleFeature> semanticHoles, string targetSolid)+ {+ if (document.Pmi is null || document.Pmi.Count == 0)+ {+ return [];+ }++ var holeByName = semanticHoles.SelectMany(h => new[] { new KeyValuePair<string, Core.Air.AirHoleFeature>(h.FeatureId, h), new KeyValuePair<string, Core.Air.AirHoleFeature>(h.Name, h) }).ToDictionary(kvp => kvp.Key, kvp => kvp.Value, StringComparer.Ordinal);+ var targetBinding = document.Solids.Single(s => string.Equals(s.Name, targetSolid, StringComparison.Ordinal));+ var result = new List<Step242SemanticPmi>();+ foreach (var pmi in document.Pmi)+ {+ if (pmi.Kind == FirmamentV2PmiKind.HoleDiameter && pmi.Value.HasValue && holeByName.TryGetValue(pmi.Target, out var pmiHole))+ {+ result.Add(new Step242SemanticPmiHole(pmiHole.FeatureId, pmi.Value.Value, null, "explicit_v2_semantic_hole_diameter", null, null));+ }+ else if (pmi.Kind == FirmamentV2PmiKind.DatumPlane)+ {+ var selector = ResolveV2DatumTarget(targetBinding, pmi.Target);+ result.Add(new Step242SemanticPmiDatum(targetSolid, "plane", pmi.Name, selector));+ }+ }++ return result;+ }++ private static string ResolveV2DatumTarget(FirmamentV2SolidBinding solid, string target)+ {+ if (target.StartsWith("face(", StringComparison.Ordinal))+ {+ return $"{solid.Name}.{FaceAxisToPort(target)}";+ }++ var exposure = solid.Box?.Exposures.FirstOrDefault(e => string.Equals(e.Alias, target, StringComparison.Ordinal));+ return exposure is null ? $"{solid.Name}.{target}" : $"{solid.Name}.{FaceAxisToPort(exposure.Selector)}";+ }++ private static string FaceAxisToPort(string selector) => selector switch+ {+ "face(+Z)" => "top_face",+ "face(-Z)" => "bottom_face",+ "face(+X)" => "plus_x_face",+ "face(-X)" => "minus_x_face",+ "face(+Y)" => "plus_y_face",+ "face(-Y)" => "minus_y_face",+ _ => selector+ };+private static KernelResult<FirmamentStepExportResult> SemanticHoleFailure(IEnumerable<string> diagnostics) =>KernelResult<FirmamentStepExportResult>.Failure(diagnostics.Select(d => new Kernel.Core.Diagnostics.KernelDiagnostic(Kernel.Core.Diagnostics.KernelDiagnosticCode.ValidationFailed,diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.csindex 97bd3b8e..8e9b75d6 100644--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Ast.cs@@ -1,6 +1,6 @@namespace Aetheris.Kernel.Firmament.FirmamentV2;-public sealed record FirmamentV2Document(string ModelName, string Units, IReadOnlyList<FirmamentV2SolidBinding> Solids, IReadOnlyList<FirmamentV2ModifyBlock>? ModifyBlocks = null, IReadOnlyList<FirmamentV2TemplateDecl>? Templates = null)+public sealed record FirmamentV2Document(string ModelName, string Units, IReadOnlyList<FirmamentV2SolidBinding> Solids, IReadOnlyList<FirmamentV2ModifyBlock>? ModifyBlocks = null, IReadOnlyList<FirmamentV2TemplateDecl>? Templates = null, IReadOnlyList<FirmamentV2PmiDecl>? Pmi = null){public FirmamentV2SolidBinding Solid => Solids[^1];public FirmamentV2SideHoleIntent? SideHoleIntent => ModifyBlocks?.SelectMany(m => m.Regions.Select(r =>@@ -82,6 +82,8 @@ public sealed record FirmamentV2SemanticHoleDecl(double? CounterboreDepth = null,double? CountersinkDiameter = null,double? CountersinkAngleDegrees = null);+public enum FirmamentV2PmiKind { HoleDiameter, DatumPlane }+public sealed record FirmamentV2PmiDecl(string Name, FirmamentV2PmiKind Kind, string Target, double? Value = null);public sealed record FirmamentV2ConceptDecl(string Name, string RawValue, double NumericValue, string? Unit);public sealed record FirmamentV2TemplateDecl(string Process, string Name, IReadOnlyList<FirmamentV2ConceptDecl> Concepts);diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.csindex b19448a7..82b39a29 100644--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentV2Parser.cs@@ -69,6 +69,11 @@ public static class FirmamentV2Parserpublic const string HoleDepthInvalid = "firmament-v2-hole-depth-invalid";public const string HoleCounterboreInvalid = "firmament-v2-hole-counterbore-invalid";public const string HoleCountersinkInvalid = "firmament-v2-hole-countersink-invalid";+ public const string PmiKindUnknown = "firmament-v2-pmi-kind-unknown";+ public const string PmiTargetMissing = "firmament-v2-pmi-target-missing";+ public const string PmiTargetUnresolved = "firmament-v2-pmi-target-unresolved";+ public const string PmiDiameterInvalid = "firmament-v2-pmi-diameter-invalid";+ public const string PmiDuplicateName = "firmament-v2-pmi-duplicate-name";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);@@ -87,6 +92,10 @@ public static class FirmamentV2Parserprivate static readonly Regex ThroughRegex = new(@"\bthrough\s*:\s*(?<target>face\([^)]*\)|[A-Za-z_][A-Za-z0-9_]*)", RegexOptions.CultureInvariant);private static readonly Regex CenterRegex = new(@"\bcenter\s*:\s*\[(?<values>[^\]]*)\]", RegexOptions.CultureInvariant | RegexOptions.Singleline);private static readonly Regex SemanticHoleHeaderRegex = new(@"\bhole\s*<\s*(?<variant>[A-Za-z_][A-Za-z0-9_]*)\s*>\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)\s*\{", RegexOptions.CultureInvariant);+ private static readonly Regex PmiHeaderRegex = new(@"\bpmi\s*\{", RegexOptions.CultureInvariant);+ private static readonly Regex PmiEntryHeaderRegex = new(@"\b(?<kind>[A-Za-z_][A-Za-z0-9_]*)\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)\s*\{", RegexOptions.CultureInvariant);+ private static readonly Regex TargetRegex = new(@"\btarget\s*:\s*(?<target>face\([^)]+\)|[A-Za-z_][A-Za-z0-9_]*)", RegexOptions.CultureInvariant);+ private static readonly Regex ValueRegex = new(@"\b(?:value|diameter)\s*:\s*(?<value>[^\s}]+)", RegexOptions.CultureInvariant);private static readonly Regex TemplateHeaderRegex = new(@"\btemplate\s*<\s*(?<process>[A-Za-z_][A-Za-z0-9_]*)\s*>\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)\s*\{", RegexOptions.CultureInvariant);private static readonly Regex ConceptRegex = new(@"\bconcept\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)\s*:\s*(?<value>[-+0-9.eE]+)\s*(?<unit>[A-Za-z_][A-Za-z0-9_]*)?", RegexOptions.CultureInvariant);@@ -135,10 +144,11 @@ public static class FirmamentV2Parservar modifyBlocks = ParseModifyBlocks(source, byName, diagnostics);var templates = ParseTemplates(source, diagnostics);+ var pmi = ParsePmi(source, byName, modifyBlocks, 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, modifyBlocks, templates);+ document = new FirmamentV2Document(modelMatch.Groups["name"].Value, unitsMatch.Groups["units"].Value, solids, modifyBlocks, templates, pmi);diagnostics.Add(document is null ? "firmament-v2-parse-failed" : "firmament-v2-parse-succeeded");diagnostics.Sort(StringComparer.Ordinal);@@ -186,7 +196,7 @@ public static class FirmamentV2Parserreturn new(name, "Box", new FirmamentV2BoxRecord(values, []), baseName, new Dictionary<string, IReadOnlyList<double>>(StringComparer.Ordinal) { ["size"] = values });}- private static bool IsFatalDiagnostic(string code) => code is PrimitiveFieldMissing or PrimitiveFieldUnknown or PrimitiveFieldInvalid or 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 CylinderRadiusNotFinite or ThroughSelectorUnsupported or AliasUnresolved or AliasRefTypeUnsupported or SideHoleAliasMustResolveToFace or SideHoleAliasResolvesToUnsupportedFace or SideHoleOnlyPlusXMinusXSupported or SideHoleRouteUnsupported or SideHoleSameFaceUnsupported or SideHoleAxisNotYetSupported or SideHoleRadiusExceedsClearance or CylinderCenterInvalid or CylinderCenterArityInvalid or CylinderCenterNotFinite or SideHoleCenterExceedsClearance or HoleVariantUnknown or HoleEntryFaceMissing or HoleCenterMissing or HoleShaftMissing or HoleEndMissing or HoleDiameterInvalid or HoleDepthInvalid or HoleCounterboreInvalid or HoleCountersinkInvalid;+ private static bool IsFatalDiagnostic(string code) => code is PrimitiveFieldMissing or PrimitiveFieldUnknown or PrimitiveFieldInvalid or 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 CylinderRadiusNotFinite or ThroughSelectorUnsupported or AliasUnresolved or AliasRefTypeUnsupported or SideHoleAliasMustResolveToFace or SideHoleAliasResolvesToUnsupportedFace or SideHoleOnlyPlusXMinusXSupported or SideHoleRouteUnsupported or SideHoleSameFaceUnsupported or SideHoleAxisNotYetSupported or SideHoleRadiusExceedsClearance or CylinderCenterInvalid or CylinderCenterArityInvalid or CylinderCenterNotFinite or SideHoleCenterExceedsClearance or HoleVariantUnknown or HoleEntryFaceMissing or HoleCenterMissing or HoleShaftMissing or HoleEndMissing or HoleDiameterInvalid or HoleDepthInvalid or HoleCounterboreInvalid or HoleCountersinkInvalid or PmiKindUnknown or PmiTargetMissing or PmiTargetUnresolved or PmiDiameterInvalid or PmiDuplicateName;private static IReadOnlyList<FirmamentV2Exposure> ParseExposures(string body, List<string> diagnostics){@@ -475,6 +485,57 @@ public static class FirmamentV2Parserreturn templates;}+ private static IReadOnlyList<FirmamentV2PmiDecl> ParsePmi(string source, Dictionary<string, FirmamentV2SolidBinding> solids, IReadOnlyList<FirmamentV2ModifyBlock> modifyBlocks, List<string> diagnostics)+ {+ var match = PmiHeaderRegex.Match(source);+ if (!match.Success) return [];+ var open = source.IndexOf('{', match.Index);+ var close = FindMatchingBrace(source, open);+ if (close < 0) { diagnostics.Add(UnsupportedConstruct); return []; }+ var body = source[(open + 1)..close];+ var entries = new List<FirmamentV2PmiDecl>();+ var names = new HashSet<string>(StringComparer.Ordinal);+ var holeNames = modifyBlocks.SelectMany(m => m.SemanticHoles).Select(h => h.Name).ToHashSet(StringComparer.Ordinal);+ var aliases = solids.Values.SelectMany(s => s.Box?.Exposures ?? []).Select(e => e.Alias).ToHashSet(StringComparer.Ordinal);+ foreach (Match em in PmiEntryHeaderRegex.Matches(body))+ {+ var kindRaw = em.Groups["kind"].Value;+ var name = em.Groups["name"].Value;+ if (!names.Add(name)) { diagnostics.Add(PmiDuplicateName); continue; }+ var entryOpen = body.IndexOf('{', em.Index);+ var entryClose = FindMatchingBrace(body, entryOpen);+ if (entryClose < 0) { diagnostics.Add(UnsupportedConstruct); continue; }+ var eb = body[(entryOpen + 1)..entryClose];+ var targetMatch = TargetRegex.Match(eb);+ if (!targetMatch.Success) { diagnostics.Add(PmiTargetMissing); continue; }+ var target = targetMatch.Groups["target"].Value.Trim();+ if (string.Equals(kindRaw, "diameter", StringComparison.Ordinal))+ {+ if (!holeNames.Contains(target)) { diagnostics.Add(PmiTargetUnresolved); continue; }+ var valueMatch = ValueRegex.Match(eb);+ if (!valueMatch.Success || !TryParsePositiveNumberWithOptionalMm(valueMatch.Groups["value"].Value, out var value)) { diagnostics.Add(PmiDiameterInvalid); continue; }+ entries.Add(new FirmamentV2PmiDecl(name, FirmamentV2PmiKind.HoleDiameter, target, value));+ }+ else if (string.Equals(kindRaw, "datum", StringComparison.Ordinal))+ {+ if (!aliases.Contains(target) && !FaceSelectorRegex.IsMatch(target)) { diagnostics.Add(PmiTargetUnresolved); continue; }+ entries.Add(new FirmamentV2PmiDecl(name, FirmamentV2PmiKind.DatumPlane, target));+ }+ else+ {+ diagnostics.Add(PmiKindUnknown);+ }+ }+ return entries;+ }++ private static bool TryParsePositiveNumberWithOptionalMm(string raw, out double value)+ {+ raw = raw.Trim();+ if (raw.EndsWith("mm", StringComparison.Ordinal)) raw = raw[..^2];+ return double.TryParse(raw, NumberStyles.Float, CultureInfo.InvariantCulture, out value) && double.IsFinite(value) && value > 0d;+ }+private static bool ContainsUnsupportedConstruct(string source) =>Regex.IsMatch(source, @"\b(PMI|where|add|shell|fillet|chamfer|regions|profile|material|pattern)\b|<\s*Process\s*>", RegexOptions.CultureInvariant);diff --git a/docs/implementation/step-v2-x7-semantic-pmi-ap242.md b/docs/implementation/step-v2-x7-semantic-pmi-ap242.mdnew file mode 100644index 00000000..e12387a6--- /dev/null+++ b/docs/implementation/step-v2-x7-semantic-pmi-ap242.md@@ -0,0 +1,74 @@+# STEP-V2-X7 semantic PMI AP242 emission++STEP-V2-X7 adds the minimal Firmament V2 semantic PMI declarations needed to prove AP242 semantic PMI emission through the production build path. This is Tier 6 optional MVP scope and is not graphical PMI.++## Supported declarations++Only two declaration forms are accepted in a `pmi { ... }` block:++```firmament+pmi {+ diameter mountDiameter {+ target: mount+ value: 2mm+ }++ datum A {+ target: top+ }+}+```++* `diameter <name>` declares semantic hole-diameter PMI. The target must resolve to a V2 semantic hole name in a `modify` block and `value`/`diameter` must be a positive millimetre length.+* `datum <label>` declares a semantic planar datum. The target must be a stable face selector (`face(+Z)`) or a face alias exposed by a Box (`top`).++The declaration identity is the entry name (`mountDiameter`, `A`), the kind is encoded as `HoleDiameter` or `DatumPlane` in the V2 AST, the target is retained as authored, and the diameter value is retained for hole-diameter PMI.++## Fixture paths++* `fixtures/FirmamentV2/PMI/valid/pmi-v2-hole-diameter-callout-emits-in-step.valid.firmfixture`+* `fixtures/FirmamentV2/PMI/valid/pmi-v2-datum-plane-emits-in-step.valid.firmfixture`++Both fixtures are `tier: 6`, `current-stage: step-verified`, `semantic-pmi-required: true`, and `graphical-pmi-required: false`.++## Command path and exporter route++The fixtures are built through the real CLI path:++```bash+aetheris build fixtures/FirmamentV2/PMI/valid/pmi-v2-hole-diameter-callout-emits-in-step.valid.firmfixture --out <tmp>/pmi-v2-hole-diameter.step --json+aetheris build fixtures/FirmamentV2/PMI/valid/pmi-v2-datum-plane-emits-in-step.valid.firmfixture --out <tmp>/pmi-v2-datum-plane.step --json+```++The route remains:++```text+Firmament V2 source -> FirmamentV2Parser -> BrepBody (Box or AirHoleFeature materialization) -> Step242Exporter.ExportBody(body, semanticPmi)+```++No hardcoded STEP templates or trace-only outputs are used.++## AP242 semantic evidence++The existing Aetheris AP242 semantic PMI style is reused:++* hole diameter evidence: `SHAPE_ASPECT('firmament-feature:base.mount', ...)`, `PROPERTY_DEFINITION('diameter:base.mount', ...)`, and `SHAPE_DIMENSION_REPRESENTATION('diameter:base.mount', ...)`;+* datum evidence: `SHAPE_ASPECT('firmament-datum:A', ...)` and `PROPERTY_DEFINITION('datum:A:base', ...)`.++The tests also require topology markers (`ADVANCED_FACE`, `VERTEX_POINT`), STEP reimport through `Step242Importer`, exact volume analysis for the hole fixture (`480 - pi * 1^2 * 6`), and exact volume analysis for the datum box fixture (`480`).++## No graphical PMI++STEP-V2-X7 intentionally does not implement graphical PMI, drawing views, annotation layout, leaders, rendered callouts, annotation planes, dimension graphics, DisplayIR PMI, frontend PMI, or PMI roundtrip editing. The tests assert that graphical PMI is not required and reject graphical markers such as `DRAUGHTING_CALLOUT` and `ANNOTATION_PLANE`.++## Relationship to MVP readiness contract++This implements the optional Tier 6 entries in `docs/mvp/firmament-v2-ap242-mvp-readiness-contract.md`: `pmi-v2-hole-diameter-callout-emits-in-step` and `pmi-v2-datum-plane-emits-in-step`. PMI remains non-MVP-required unless a pitch/demo explicitly requires annotated AP242 output.++## Relationship to existing AP242 PMI route++The implementation reuses the existing `Step242Exporter` semantic PMI payload records (`Step242SemanticPmiHole` and `Step242SemanticPmiDatum`) and the established property/shape-aspect style. It adds only a narrow V2 parser/lowering adapter that produces those existing records for semantic hole diameter and planar datum declarations.++## Deferred PMI features++Deferred: graphical PMI, GD&T feature-control frames, tolerance stacks, standards libraries, arbitrary edge/loop targets, multiple drawing views, annotation placement, leader geometry, dimension graphics, DisplayIR/frontend PMI, PMI roundtrip editing, full AP242 PMI coverage, and new STEP exporter architecture.diff --git a/docs/mvp/firmament-v2-ap242-mvp-readiness-contract.md b/docs/mvp/firmament-v2-ap242-mvp-readiness-contract.mdindex 4fefc320..2eb7155f 100644--- a/docs/mvp/firmament-v2-ap242-mvp-readiness-contract.md+++ b/docs/mvp/firmament-v2-ap242-mvp-readiness-contract.md@@ -160,6 +160,8 @@ Tier 5 is required for MVP readiness if the demo claims DFM/concept enforcement.Tier 6 is optional for MVP unless the specific pitch/demo requires annotated AP242 output. Do not quietly inflate MVP scope with PMI.+Implementation status: STEP-V2-X7 adds semantic-only AP242 evidence for the two Tier 6 fixtures via `docs/implementation/step-v2-x7-semantic-pmi-ap242.md`; graphical PMI remains out of scope.+## 12. Fixture metadata requirementsEvery V2 fixture should carry metadata with the following fields or equivalent meaning:diff --git a/fixtures/FirmamentV2/PMI/valid/pmi-v2-datum-plane-emits-in-step.valid.firmfixture b/fixtures/FirmamentV2/PMI/valid/pmi-v2-datum-plane-emits-in-step.valid.firmfixturenew file mode 100644index 00000000..ac06d431--- /dev/null+++ b/fixtures/FirmamentV2/PMI/valid/pmi-v2-datum-plane-emits-in-step.valid.firmfixture@@ -0,0 +1,34 @@+// fixture-id: pmi-v2-datum-plane-emits-in-step+// case: pmi-v2-datum-plane-emits-in-step+// category: PMI+// syntax-version: FirmamentV2+// validity: valid+// implementation: parser-backed+// expected: valid+// expected-stage: step-verified+// current-stage: step-verified+// units: mm+// tier: 6+// mvp-required: false+// feature-area: semantic-pmi+// build-command: aetheris build+// expected-volume: 480+// expected-topology: advanced_face>0, vertex_point>0+// roundtrip-required: true+// semantic-pmi-required: true+// graphical-pmi-required: false+// notes: STEP-V2-X7 semantic-only datum plane PMI; real build/export uses a real Box BrepBody, Step242Exporter semantic PMI, and no graphical PMI.+model PmiV2DatumPlaneEmitsInStep {+ units mm+ solid base: Box {+ size: [10, 8, 6]+ expose {+ face(+Z) => top+ }+ }+ pmi {+ datum A {+ target: top+ }+ }+}diff --git a/fixtures/FirmamentV2/PMI/valid/pmi-v2-hole-diameter-callout-emits-in-step.valid.firmfixture b/fixtures/FirmamentV2/PMI/valid/pmi-v2-hole-diameter-callout-emits-in-step.valid.firmfixturenew file mode 100644index 00000000..e38b3fc6--- /dev/null+++ b/fixtures/FirmamentV2/PMI/valid/pmi-v2-hole-diameter-callout-emits-in-step.valid.firmfixture@@ -0,0 +1,38 @@+// fixture-id: pmi-v2-hole-diameter-callout-emits-in-step+// case: pmi-v2-hole-diameter-callout-emits-in-step+// category: PMI+// syntax-version: FirmamentV2+// validity: valid+// implementation: parser-backed+// expected: valid+// expected-stage: step-verified+// current-stage: step-verified+// units: mm+// tier: 6+// mvp-required: false+// feature-area: semantic-pmi+// build-command: aetheris build+// expected-volume: 480 - pi * 1^2 * 6+// expected-topology: advanced_face>0, vertex_point>0, cylindrical-wall-face=true+// roundtrip-required: true+// semantic-pmi-required: true+// graphical-pmi-required: false+// notes: STEP-V2-X7 semantic-only hole diameter PMI; real build/export uses AirHoleFeature, BrepBody, Step242Exporter semantic PMI, and no graphical PMI.+model PmiV2HoleDiameterCalloutEmitsInStep {+ units mm+ solid base: Box { size: [10, 8, 6] }+ modify base {+ hole<shaft> mount {+ on: face(+Z)+ center: [0, 0]+ diameter: 2+ end: throughAll+ }+ }+ pmi {+ diameter mountDiameter {+ target: mount+ value: 2mm+ }+ }+}