Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Mark drawing coordinate zeros and table limits
Yuechen Li193bb65974ae
diff --git a/Aetheris.Kernel.Firmament.Tests/DrawingDimensionPlanningTests.cs b/Aetheris.Kernel.Firmament.Tests/DrawingDimensionPlanningTests.csindex 4663da40..b7402805 100644--- a/Aetheris.Kernel.Firmament.Tests/DrawingDimensionPlanningTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/DrawingDimensionPlanningTests.cs@@ -21,6 +21,7 @@ public sealed class DrawingDimensionPlanningTestsAssert.Contains(page.Annotations, a => a.Identity == "dimension:Height" && a.EngineeringDisplay == "70 ±0.1");Assert.Contains(page.Annotations, a => a.Identity == "dimension:Thickness" && a.EngineeringDisplay == "8 ±0.1");var table = Assert.Single(page.Tables); Assert.Equal(DrawingTableKind.HoleCoordinates, table.Kind);+ Assert.Equal(new[] { "HOLE", "X ±0.1", "Y ±0.1", "TYPE" }, table.Columns);Assert.Equal(10, table.Rows.Count);Assert.Contains(table.Rows, r => r.SequenceEqual(new[] { "H1", "14", "17", "D1" }));Assert.Contains(table.Rows, r => r.SequenceEqual(new[] { "H10", "86", "53", "D1" }));@@ -30,6 +31,22 @@ public sealed class DrawingDimensionPlanningTestsAssert.Equal(10, front.Primitives.Count(p => p.Kind == DrawingPrimitiveKind.Hidden));var datum = page.Annotations.Single(a => a.Kind == DrawingAnnotationKind.Datum);Assert.Equal("FRONT", datum.AssignedView); Assert.Equal(front.GeometryBounds.Y, datum.ProjectedAnchor.Y, 8);+ var top = page.Views.Single(v => v.Identity == "TOP");+ var xZero = Assert.Single(page.Annotations, a => a.Identity == "coordinate:X0");+ var yZero = Assert.Single(page.Annotations, a => a.Identity == "coordinate:Y0");+ var origin = Assert.Single(page.Annotations, a => a.Identity == "coordinate:origin");+ Assert.Equal("X0", xZero.EngineeringDisplay); Assert.Equal("Y0", yZero.EngineeringDisplay);+ Assert.Equal(top.GeometryBounds.X, xZero.ProjectedAnchor.X, 8);+ Assert.Equal(top.GeometryBounds.Bottom, yZero.ProjectedAnchor.Y, 8);+ Assert.Equal(top.GeometryBounds.X, origin.ProjectedAnchor.X, 8);+ Assert.Equal(top.GeometryBounds.Bottom, origin.ProjectedAnchor.Y, 8);+ Assert.Equal("(0,0)", origin.EngineeringDisplay);+ foreach (var reference in new[] { xZero, yZero, origin })+ {+ Assert.Equal("TOP", reference.AssignedView);+ Assert.Equal(reference.ProjectedAnchor, reference.SelectedCandidate.Leader[0]);+ Assert.NotEmpty(reference.Strokes);+ }Assert.Equal(0, drawing.LayoutEvidence.TextTextCollisionsAfter + drawing.LayoutEvidence.TextModelCollisionsAfter + drawing.LayoutEvidence.TextLeaderCollisionsAfter);using var presentation = DocumentFormat.OpenXml.Packaging.PresentationDocument.Open(result.Artifacts.PptxPath, false);Assert.Empty(new DocumentFormat.OpenXml.Validation.OpenXmlValidator().Validate(presentation));@@ -48,6 +65,18 @@ public sealed class DrawingDimensionPlanningTestsAssert.Contains(result.Artifacts.Drawing.Pages.Single().Tables.Single().Rows, r => r.SequenceEqual(new[] { "H1", "15.875", "17.75", "D1" }));}+ [Fact]+ public void TableLimitsFollowTheExplicitToleranceWithoutChangingNominalCoordinates()+ {+ using var scratch = new Scratch();+ var result = FirmamentDrawingCompiler.Generate(Fixture(), scratch.Path, null, new(false, .025, "6061-T6 aluminium", .5));+ Assert.True(result.IsSuccess, string.Join("\n", result.Diagnostics));+ var table = Assert.Single(result.Artifacts!.Drawing.Pages.Single().Tables);+ Assert.Equal(new[] { "HOLE", "X ±0.025", "Y ±0.025", "TYPE" }, table.Columns);+ Assert.Contains(table.Rows, row => row.SequenceEqual(new[] { "H1", "14", "17", "D1" }));+ Assert.Contains(result.Artifacts.Drawing.Pages.Single().Notes, note => note == "TABLE X/Y LIMITS APPLY INDEPENDENTLY TO EACH AXIS.");+ }+[Theory][InlineData("Model Egg { units: mm Sphere Stock { radius: 10mm } }", false)][InlineData("Model Blind { units: mm Box Stock { size: [40mm, 30mm, 8mm] } Modify Stock { Hole<Shaft> Bore { on: +Z; center: Point2(0mm, 0mm); diameter: 4mm; end: Blind 3mm } } }", true)]@@ -73,6 +102,7 @@ public sealed class DrawingDimensionPlanningTestsAssert.True(evidence.NominalGeometryComplete); Assert.False(evidence.DimensionalTolerancesComplete);Assert.False(evidence.MaterialSpecified); Assert.Null(evidence.LinearToleranceMillimetres); Assert.Null(evidence.AngularToleranceDegrees);Assert.Equal(3, evidence.MissingRequirements.Count);+ Assert.Equal(new[] { "HOLE", "X (TOL?)", "Y (TOL?)", "TYPE" }, result.Artifacts.Drawing.Pages[0].Tables.Single().Columns);Assert.Contains(result.Artifacts.Drawing.Pages[0].Notes, n => n.Contains("NOT FOR MANUFACTURE", StringComparison.Ordinal));}diff --git a/Aetheris.Kernel.Firmament.Tests/DrawingGenerationTests.cs b/Aetheris.Kernel.Firmament.Tests/DrawingGenerationTests.csindex cd110d09..7ab549a7 100644--- a/Aetheris.Kernel.Firmament.Tests/DrawingGenerationTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/DrawingGenerationTests.cs@@ -84,7 +84,8 @@ public sealed class DrawingGenerationTestsAssert.True(result.IsSuccess, string.Join("\n", result.Diagnostics));Assert.True(result.Artifacts!.Drawing.DefinitionEvidence!.NominalGeometryComplete);Assert.False(result.Artifacts.Drawing.DefinitionEvidence.DimensionalTolerancesComplete);- Assert.Contains(result.Artifacts.Drawing.Pages[0].Notes, n => n.Contains("TOLERANCES UNSPECIFIED", StringComparison.Ordinal));+ Assert.Contains(result.Artifacts.Drawing.DefinitionEvidence.MissingRequirements, n => n.Contains("tolerances are unspecified", StringComparison.Ordinal));+ Assert.Contains(result.Artifacts.Drawing.Pages[0].Notes, n => n.Contains("NOT FOR MANUFACTURE", StringComparison.Ordinal));}[Fact]diff --git a/Aetheris.Kernel.Firmament/Drawing/DrawingDimensionPlanning.cs b/Aetheris.Kernel.Firmament/Drawing/DrawingDimensionPlanning.csindex 778be7f0..631baaaa 100644--- a/Aetheris.Kernel.Firmament/Drawing/DrawingDimensionPlanning.cs+++ b/Aetheris.Kernel.Firmament/Drawing/DrawingDimensionPlanning.cs@@ -69,13 +69,14 @@ public static partial class FirmamentDrawingCompilervar metadata = new DrawingMetadataIr(name + " - dimensioned plate", name, null, null, options.Material,name + "Drawing", "CompletePlateDimensions", Author: signoff?.Drawn.Name, Date: signoff?.Drawn.Date,Description: "Exact nominal dimensions; manufacturing release and process capability require engineering review") { Signoff = signoff };- var notes = new List<string> { "DIMENSIONS IN mm. DO NOT SCALE DRAWING.", "X FROM LEFT FINISHED EDGE; Y FROM BOTTOM FINISHED EDGE.",- options.LinearToleranceMillimetres is { } tol ? $"STOCK SIZES AND X/Y COORDINATES: ±{Number(tol)} mm." : "STOCK / COORDINATE TOLERANCES UNSPECIFIED - NOT FOR MANUFACTURE.",- options.AngularToleranceDegrees is { } a ? $"UNLESS SPECIFIED: ANGLES ±{Number(a)}°." : "ANGULAR TOLERANCE UNSPECIFIED - NOT FOR MANUFACTURE.",+ var notes = new List<string> { "DIMENSIONS IN mm. DO NOT SCALE DRAWING.", "X0: LEFT FINISHED EDGE; Y0: BOTTOM FINISHED EDGE.",+ "TABLE X/Y FROM X0/Y0; (0,0) AT THEIR INTERSECTION.",+ options.LinearToleranceMillimetres.HasValue ? "TABLE X/Y LIMITS APPLY INDEPENDENTLY TO EACH AXIS." : "STOCK / X/Y LIMITS UNSPECIFIED - NOT FOR MANUFACTURE.",+ options.AngularToleranceDegrees is { } a ? $"UNLESS SPECIFIED: ANGLES ±{Number(a)}°." : "ANGLE LIMITS UNSPECIFIED - NOT FOR MANUFACTURE.","X/Y AT TOP FACE; HOLE AXES NOMINALLY NORMAL; THRU.",- "NOMINAL GEOMETRY COMPLETE. PROCESS CAPABILITY NOT VERIFIED." };+ "NOMINAL GEOMETRY COMPLETE; PROCESS CAPABILITY UNVERIFIED." };if (string.IsNullOrWhiteSpace(options.Material)) notes.Add("MATERIAL UNSPECIFIED - NOT FOR MANUFACTURE.");- if (groups.Any(g => g.Plus is null || g.Minus is null)) notes.Add("HOLE SIZE TOLERANCES UNSPECIFIED - NOT FOR MANUFACTURE.");+ if (groups.Any(g => g.Plus is null || g.Minus is null)) notes.Add("HOLE SIZE LIMITS UNSPECIFIED - NOT FOR MANUFACTURE.");var chunks = holes.Count == 0 ? new[] { Array.Empty<DrawingDefinedHoleIr>() } : holes.Chunk(12).ToArray();var pages = new List<DrawingPageIr>();var scale = StandardScale(Math.Min(Math.Min(105 / plate.Width, 75 / plate.Height), 12 / plate.Thickness));@@ -89,6 +90,17 @@ public static partial class FirmamentDrawingCompilerannotations.Add(Measure("Width", "TOP", Linear(plate.Width), new(b.X, b.Y), new(b.Right, b.Y), b.Y - 9, true));annotations.Add(Measure("Height", "TOP", Linear(plate.Height), new(b.Right, b.Y), new(b.Right, b.Bottom), b.Right + 8, false));annotations.Add(Measure("Thickness", "FRONT", Linear(plate.Thickness), new(f.Right, f.Y), new(f.Right, f.Bottom), f.Right + 8, false));+ // Drawing coordinate references, not additional source/GD&T datums. The exact+ // stock planes establish zero; the source's datum PMI remains unchanged.+ var xZero = Project(top, new(plate.Origin.X, plate.Origin.Y + plate.Height * .45, plate.Origin.Z + plate.Thickness));+ var yZero = Project(top, new(plate.Origin.X + plate.Width * .6, plate.Origin.Y, plate.Origin.Z + plate.Thickness));+ var origin = Project(top, new(plate.Origin.X, plate.Origin.Y, plate.Origin.Z + plate.Thickness));+ annotations.Add(DefinedLabel("coordinate:X0", "TOP", "X0", new(b.X - 19, xZero.Y - 3),+ [xZero, new(b.X - 9, xZero.Y)], xZero, $"Drawing X=0 reference: finished stock plane X={plate.Origin.X:R}; not additional AP242 PMI."));+ annotations.Add(DefinedLabel("coordinate:Y0", "TOP", "Y0", new(yZero.X - 3, b.Bottom + 3),+ [yZero, new(yZero.X, b.Bottom + 3)], yZero, $"Drawing Y=0 reference: finished stock plane Y={plate.Origin.Y:R}; not additional AP242 PMI."));+ annotations.Add(DefinedLabel("coordinate:origin", "TOP", "(0,0)", new(b.X - 19, b.Bottom + 3),+ [origin, new(b.X - 4, b.Bottom + 6)], origin, $"Top-face coordinate origin: ({plate.Origin.X:R}, {plate.Origin.Y:R}, {plate.Origin.Z + plate.Thickness:R}) mm."));var primitives = top.Primitives.ToList();foreach (var hole in holes){@@ -143,11 +155,12 @@ public static partial class FirmamentDrawingCompiler{var number = index + 1;var zones = Zones(297, 210);- IReadOnlyList<DrawingTableIr> tables = chunk.Length == 0 ? [] : [new("HOLE COORDINATES (mm)", ["HOLE", "X", "Y", "TYPE"],+ var coordinateLimit = options.LinearToleranceMillimetres is { } tolerance ? " ±" + Number(tolerance) : " (TOL?)";+ IReadOnlyList<DrawingTableIr> tables = chunk.Length == 0 ? [] : [new("HOLE COORDINATES (mm)", ["HOLE", "X" + coordinateLimit, "Y" + coordinateLimit, "TYPE"],chunk.Select(h => (IReadOnlyList<string>)new[] { h.Identity, Number(h.X), Number(h.Y), h.Group }).ToArray(), name,"Exact cylinder axes relative to finished stock planes; no sampled or chained dimensions.", DrawingTableKind.HoleCoordinates,new(190, 30, 95, 7 * (chunk.Length + 1)), new(number, "B5"))];- if (tables.SelectMany(t => t.Rows).SelectMany(r => r).Any(value => DrawingInterFont.Load().MeasureMillimetres(value, 2.8) > 95d / 4 - 2))+ if (tables.SelectMany(t => t.Rows.Prepend(t.Columns)).SelectMany(r => r).Any(value => DrawingInterFont.Load().MeasureMillimetres(value, 2.8) > 95d / 4 - 2))return Failure("drawing-layout-impossible: A hole-schedule value exceeds its measured cell width. Use an authored wider schedule; values were not truncated.");var fields = new Dictionary<string, string> { ["Units"] = "mm", ["Scale"] = "×" + Number(scale), ["Sheet"] = $"{number}/{chunks.Length}",["Status"] = missing.Count == 0 ? "DIMENSIONED - REVIEW" : "INCOMPLETE REQUIREMENTS" };diff --git a/docs/development/DRAWING-DEFINITION-QUALIFICATION.md b/docs/development/DRAWING-DEFINITION-QUALIFICATION.mdindex 1c75351d..33a8ebb5 100644--- a/docs/development/DRAWING-DEFINITION-QUALIFICATION.md+++ b/docs/development/DRAWING-DEFINITION-QUALIFICATION.md@@ -178,3 +178,47 @@ This is not a general manufacturing-release or process-capability certification.Qualified shop execution, stock form/finish, functional fit, inspection uncertaintyand engineering signoff remain distinct from the successful drawing-definitiongate. The implementation and public documentation preserve that distinction.++## Coordinate zero and table limits follow-up (2026-10-19)++The review correctly identified that naming reference edges in a note did not make+their zeros immediately visible, and burying coordinate limits in general notes+made the hole schedule harder to use. The shared dimension planner now projects+X0 and Y0 leaders onto the exact left/bottom finished stock planes and marks their+intersection `(0,0)` on the top face. These are drawing coordinate references;+source datum A and AP242 PMI remain unchanged.++Both table headers carry explicit independent bilateral limits (`X ±0.1`,+`Y ±0.1` mm for the example). These define Cartesian entry-center intervals, not+a circular GD&T position zone. `--linear-tolerance` remains the explicit authoring+input; unspecified limits print `TOL?`. Header widths are checked alongside row+values. Notes were shortened to retain missing-requirement warnings within the+reserved area, including the case where diameter limits are absent too.++Evidence is under `artifacts/local/drawing-coordinate-datums/`. Fifty focused+drawing tests and seven CLI drawing tests pass. Coverage checks both zero leaders+and the origin against the projected stock, the existing datum A, missing limits,+and a nondefault ±0.025 mm input without changing nominal coordinates. Both PDFs+were rendered and visually inspected; the regular and asymmetric variants have+zero text/model, text/text or text/stroke collisions. Native PPTX validation passes.++The independent PDF reader now obtains each axis limit from its table header and+requires the zero labels in the view region separately from the explanatory notes.+Eight missing-data mutations reject for each PDF, including each zero reference,+the origin and each axis tolerance. Both frozen PDF-only reconstructions compile+and match the reference topology, bounds, exact cylinder centers/radii and analytic+volume. PDF/SVG/PPTX bytes match between part and STEP input. Original STEP content+through the geometric entities is byte-identical to the pre-refactor baseline.++The follow-up full solution regression passes 5,661 tests across 20 test assemblies,+with zero failures/skips; FrictionLab still discovers no tests. The prescribed+Core fast lane passes 1,087 tests. Logs are `full.log` and `fast.log` in the follow-up+evidence directory. The final build completes with zero errors.++FrontendX4 passes 32/32 (`corpus.log`), without recording new geometry baselines.+The final code-quality pass confirms that the references, limits and provenance+belong to the existing shared dimension planner; no renderer-specific inference,+new drawing schema or body modification was introduced. `git diff --check` passes,+and no dotnet, testhost, aetheris, MSBuild or VBCSCompiler hosts remain at closeout.+This follow-up is **Success** for the requested coordinate-reference refinement;+manufacturing approval and process capability remain unqualified.diff --git a/docs/public/drawings.md b/docs/public/drawings.mdindex 7f3e8a93..e9be7c69 100644--- a/docs/public/drawings.md+++ b/docs/public/drawings.md@@ -31,6 +31,9 @@ A qualified plate receives:view. These values come from stock planes, not sampled display bounds.- Hole center marks and IDs, a coordinate schedule from the left and bottomfinished edges, entry-face/orientation information, and explicit THRU extents.+ Visible X0 and Y0 leaders identify those zero edges; `(0,0)` marks their+ intersection on the top face. The table's X and Y headers each state their+ bilateral tolerance, for example `X ±0.1` and `Y ±0.1` (mm).- Grouped diameter/limit callouts only when size, limits and extent agree.Original PMI names, targets and face identities remain in provenance.- A datum indication on the actual associated plane in a useful view. Coordinate@@ -51,6 +54,13 @@ coordinate limits. `--angular-tolerance <degrees>` specifies the general angularallowance. `--material <name>` supplies the material for the drawing. These arenot defaults and never override existing diameter PMI.+Each table coordinate is measured from its marked zero edge with its own ± limit;+the two limits define independent Cartesian intervals, not a circular GD&T position+zone. X0/Y0 are drawing coordinate references, distinct from authored datum PMI+such as A. They do not silently add B/C datum requirements to the source or AP242.+An unspecified coordinate tolerance prints `TOL?` in each header and remains an+incomplete requirement.+Without these inputs, nominal dimensions are still complete for a recognized part,but the sheet prominently identifies missing requirements and is not formanufacture. Missing hole diameter tolerances remain missing as well. JSON reportsdiff --git a/fixtures/Regression/DrawingGeneration/reconstruct_from_pdf.py b/fixtures/Regression/DrawingGeneration/reconstruct_from_pdf.pyindex 590dab07..e64eedb7 100644--- a/fixtures/Regression/DrawingGeneration/reconstruct_from_pdf.py+++ b/fixtures/Regression/DrawingGeneration/reconstruct_from_pdf.py@@ -18,6 +18,7 @@ import subprocessfrom pypdf import PdfReaderNUMBER = r"(?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?"+COORDINATE_LABELS = {'x_zero': r'(?<!\w)X0(?!\w)', 'y_zero': r'(?<!\w)Y0(?!\w)', 'origin': r'\(0,0\)'}def read_definition(text: str) -> dict:@@ -27,8 +28,14 @@ def read_definition(text: str) -> dict:width, height, thickness = [float(pair[0]) for pair in sizes]if min(width, height, thickness) <= 0:raise ValueError('Stock dimensions must be positive.')- if 'X FROM LEFT FINISHED EDGE; Y FROM BOTTOM FINISHED EDGE.' not in text:+ if 'X0: LEFT FINISHED EDGE; Y0: BOTTOM FINISHED EDGE.' not in text:raise ValueError('The coordinate reference edges are missing.')+ # PDF extraction may concatenate distant labels on the same baseline. Require+ # the labels in the view annotation region, independently of their later notes.+ annotation_text = text.partition('HOLE COORDINATES (mm)')[0]+ if 'TABLE X/Y FROM X0/Y0; (0,0) AT THEIR INTERSECTION.' not in text or any(+ not re.search(pattern, annotation_text) for pattern in COORDINATE_LABELS.values()):+ raise ValueError('The visible coordinate zero references or origin are missing.')if 'X/Y AT TOP FACE; HOLE AXES NOMINALLY NORMAL; THRU.' not in text:raise ValueError('Hole entry plane, orientation or extent is missing.')groups = {}@@ -46,15 +53,21 @@ def read_definition(text: str) -> dict:for identity, specification in groups.items():if sum(h['group'] == identity for h in holes) != specification['count']:raise ValueError('The hole table does not account for the specified quantity.')- coordinates = re.search(rf'STOCK SIZES AND X/Y COORDINATES: ±({NUMBER}) mm\.', text)+ # Table headers carry the actual Cartesian limits; a general note alone is insufficient.+ coordinates = re.findall(rf'HOLE\s+X ±({NUMBER})\s+Y ±({NUMBER})\s+TYPE', text)angles = re.search(rf'UNLESS SPECIFIED: ANGLES ±({NUMBER})°\.', text)- if not coordinates or not angles:+ if not coordinates or len(set(coordinates)) != 1 or not angles:raise ValueError('General dimensional acceptance requirements are missing.')- values = [width, height, thickness] + [float(v) for pair in sizes for v in pair] + [h[k] for h in holes for k in ('x', 'y', 'diameter', 'plus', 'minus')]- if not all(math.isfinite(v) for v in values):- raise ValueError('Nonfinite dimension.')+ x_tolerance, y_tolerance = map(float, coordinates[0])+ if x_tolerance != y_tolerance:+ raise ValueError('This bounded drawing convention requires equal X and Y limits.')+ values = [width, height, thickness, x_tolerance, y_tolerance] + [float(v) for pair in sizes for v in pair] + [h[k] for h in holes for k in ('x', 'y', 'diameter', 'plus', 'minus')]+ if not all(math.isfinite(v) for v in values) or min(x_tolerance, y_tolerance) <= 0:+ raise ValueError('Nonfinite dimension or nonpositive coordinate tolerance.')return {'width': width, 'height': height, 'thickness': thickness, 'stockTolerances': [float(pair[1]) for pair in sizes],- 'coordinateTolerance': float(coordinates[1]), 'angularToleranceDegrees': float(angles[1]), 'groups': groups, 'holes': holes}+ 'coordinateTolerance': x_tolerance, 'xTolerance': x_tolerance, 'yTolerance': y_tolerance,+ 'coordinateOrigin': 'Intersection of X0 (left finished edge) and Y0 (bottom finished edge) at the top face',+ 'angularToleranceDegrees': float(angles[1]), 'groups': groups, 'holes': holes}def reconstruct(definition: dict) -> str:@@ -78,12 +91,16 @@ def main():args = parser.parse_args()text = '\n'.join(page.extract_text() for page in PdfReader(args.pdf).pages)definition = read_definition(text)+ annotation_text, table_title, remainder = text.partition('HOLE COORDINATES (mm)')# Missing stock sizes, centers, extent and location tolerance must fail reconstruction.mutations = {'missing_stock_size': re.sub(rf'(?m)^{NUMBER}\s+±{NUMBER}\s*$', '', text, count=1),'missing_hole_row': re.sub(rf'(?m)^[A-Za-z_]\w* {NUMBER} {NUMBER} D\d+\s*$', '', text, count=1),'missing_extent': text.replace(' THRU', ''),- 'missing_coordinate_tolerance': text.replace('STOCK SIZES AND X/Y COORDINATES:', 'REFERENCE COORDINATES:'),+ 'missing_x_tolerance': re.sub(rf'X ±{NUMBER}', 'X', text),+ 'missing_y_tolerance': re.sub(rf'Y ±{NUMBER}', 'Y', text),+ **{f'missing_{name}': re.sub(pattern, '', annotation_text) + table_title + remainder+ for name, pattern in COORDINATE_LABELS.items()},}for name, mutant in mutations.items():try: