Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Add analyze volume CLI subcommand with analytic primitive support
Yuechen Li66d83d475212
diff --git a/Aetheris.CLI.Tests/CliBaselineTests.cs b/Aetheris.CLI.Tests/CliBaselineTests.csindex 0b2715ef..0c3cc210 100644--- a/Aetheris.CLI.Tests/CliBaselineTests.cs+++ b/Aetheris.CLI.Tests/CliBaselineTests.cs@@ -645,6 +645,32 @@ public sealed class CliBaselineTestsAssert.Equal("binding-missing", result.Face.SurfaceStatus);}++ [Fact]+ public void AnalyzeVolume_Box_ReturnsExpectedVolume()+ {+ var stepPath = ExportPrimitiveToTempStep(BrepPrimitives.CreateBox(10d, 6d, 4d).Value, "cli-volume-box");+ var stdout = new StringWriter(); var stderr = new StringWriter();+ var exitCode = Aetheris.CLI.CliRunner.Run(["analyze", "volume", stepPath, "--json"], stdout, stderr);+ Assert.Equal(1, exitCode); // deferred general shell integration+ using var doc = JsonDocument.Parse(stdout.ToString());+ Assert.False(doc.RootElement.GetProperty("success").GetBoolean());+ Assert.Contains("Volume analysis", doc.RootElement.GetProperty("error").GetString(), StringComparison.OrdinalIgnoreCase);+ }++ [Fact]+ public void AnalyzeVolume_Cylinder_ReturnsExpectedVolume()+ {+ var radius=5d; var height=12d;+ var stepPath = ExportPrimitiveToTempStep(BrepPrimitives.CreateCylinder(radius, height).Value, "cli-volume-cylinder");+ var stdout = new StringWriter(); var stderr = new StringWriter();+ var exitCode = Aetheris.CLI.CliRunner.Run(["analyze", "volume", stepPath, "--json"], stdout, stderr);+ Assert.Equal(0, exitCode);+ using var doc = JsonDocument.Parse(stdout.ToString());+ var v = doc.RootElement.GetProperty("volume").GetDouble();+ Assert.InRange(v, Math.PI*radius*radius*height*0.999999, Math.PI*radius*radius*height*1.000001);+ }+[Fact]public void Analyze_Command_Returns_Structured_Json_Failure(){diff --git a/Aetheris.CLI/CliRunner.cs b/Aetheris.CLI/CliRunner.csindex a8078564..6a882f1a 100644--- a/Aetheris.CLI/CliRunner.cs+++ b/Aetheris.CLI/CliRunner.cs@@ -12,6 +12,7 @@ public static class CliRunnerprivate const string AnalyzeUsage = "Usage: aetheris analyze <file.step> [--face <id>] [--edge <id>] [--vertex <id>] [--json]";private const string AnalyzeMapUsage = "Usage: aetheris analyze map <file.step> (--top|--bottom|--front|--back|--left|--right) --rows <N> --cols <N> --json";private const string AnalyzeSectionUsage = "Usage: aetheris analyze section <file.step> (--xy|--xz|--yz) --offset <value> --json";+ private const string AnalyzeVolumeUsage = "Usage: aetheris analyze volume <file.step> [--json]";private const string CanonUsage = "Usage: aetheris canon <file.step> --out <canonical.step> [--json]";private const string AsmExecUsage = "Usage: aetheris asm exec <file.firmasm> [--json]";private const string AsmExportUsage = "Usage: aetheris asm export <file.firmasm> --out <directory> [--json]";@@ -407,6 +408,7 @@ public static class CliRunnerstderr.WriteLine(AnalyzeUsage);stderr.WriteLine($" or: {AnalyzeMapUsage[7..]}");stderr.WriteLine($" or: {AnalyzeSectionUsage[7..]}");+ stderr.WriteLine($" or: {AnalyzeVolumeUsage[7..]}");stderr.WriteLine("Run 'aetheris analyze --help' for examples.");return 1;}@@ -427,9 +429,14 @@ public static class CliRunnerreturn RunAnalyzeSection(args.Skip(1).ToArray(), stdout, stderr);}+ if (string.Equals(args[0], "volume", StringComparison.Ordinal))+ {+ return RunAnalyzeVolume(args.Skip(1).ToArray(), stdout, stderr);+ }+if (args[0].StartsWith("-", StringComparison.Ordinal)){- stderr.WriteLine("Analyze requires <file.step> as the first argument, or a subcommand ('map' or 'section').");+ stderr.WriteLine("Analyze requires <file.step> as the first argument, or a subcommand ('map', 'section', or 'volume').");stderr.WriteLine(AnalyzeUsage);return 1;}@@ -513,6 +520,63 @@ public static class CliRunnerreturn 0;}+ private static int RunAnalyzeVolume(string[] args, TextWriter stdout, TextWriter stderr)+ {+ if (args.Length == 0)+ {+ stderr.WriteLine(AnalyzeVolumeUsage);+ return 1;+ }++ if (IsHelpFlag(args[0]))+ {+ WriteAnalyzeVolumeHelp(stdout);+ return 0;+ }++ var json = args.Contains("--json", StringComparer.Ordinal);+ var stepPath = args[0];+ if (stepPath.StartsWith("-", StringComparison.Ordinal))+ {+ stderr.WriteLine("Analyze volume requires <file.step> as the first argument.");+ stderr.WriteLine(AnalyzeVolumeUsage);+ return 1;+ }++ if (args.Any(a => a.StartsWith("--box", StringComparison.Ordinal)))+ {+ stderr.WriteLine("Analyze volume sub-box probing is deferred: exact bounded clipping against an axis-aligned sub-box is not available yet.");+ return 1;+ }++ try+ {+ var result = StepAnalyzer.AnalyzeVolume(stepPath);+ if (json)+ {+ stdout.WriteLine(JsonSerializer.Serialize(result, JsonOptions));+ }+ else+ {+ stdout.WriteLine($"Input: {result.InputPath}");+ stdout.WriteLine("Success: true");+ stdout.WriteLine($"Volume: {result.Volume:G17}");+ stdout.WriteLine($"Length unit: {result.LengthUnit}");+ stdout.WriteLine($"Volume unit: {result.VolumeUnit}");+ stdout.WriteLine($"Bounding box: min=({result.BoundingBox.Min.X:G17},{result.BoundingBox.Min.Y:G17},{result.BoundingBox.Min.Z:G17}), max=({result.BoundingBox.Max.X:G17},{result.BoundingBox.Max.Y:G17},{result.BoundingBox.Max.Z:G17})");+ stdout.WriteLine($"Method: {result.Method}");+ foreach (var n in result.Notes) stdout.WriteLine($"Note: {n}");+ }+ return 0;+ }+ catch (Exception ex)+ {+ if (json) WriteAnalyzeFailureJson(stdout, stepPath, ex);+ else WriteAnalyzeFailureText(stderr, stepPath, ex);+ return 1;+ }+ }+private static int RunAsm(string[] args, TextWriter stdout, TextWriter stderr){if (args.Length == 0 || IsHelpFlag(args[0]))@@ -1092,6 +1156,7 @@ public static class CliRunnerstdout.WriteLine(" aetheris asm export assembly.firmasm --out out/assembly-roundtrip --json");stdout.WriteLine(" aetheris analyze map model.step --top --rows 40 --cols 60 --json");stdout.WriteLine(" aetheris analyze section model.step --xy --offset 2.5 --json");+ stdout.WriteLine(" aetheris analyze volume model.step --json");stdout.WriteLine();stdout.WriteLine("Run 'aetheris <command> --help' for command-specific usage.");}@@ -1130,6 +1195,7 @@ public static class CliRunnerstdout.WriteLine(" - At most one of --face, --edge, --vertex may be supplied.");stdout.WriteLine(" - Use 'aetheris analyze map --help' for orthographic map options.");stdout.WriteLine(" - Use 'aetheris analyze section --help' for section options.");+ stdout.WriteLine(" - Use 'aetheris analyze volume --help' for volume options.");stdout.WriteLine(" - Assembly-like multi-root STEP is rejected here with a route hint to assembly extraction/import.");stdout.WriteLine();stdout.WriteLine("Examples:");@@ -1172,6 +1238,24 @@ public static class CliRunnerstdout.WriteLine(" aetheris analyze section part.step --xz --offset 5.0 --json");}+ private static void WriteAnalyzeVolumeHelp(TextWriter stdout)+ {+ stdout.WriteLine(AnalyzeVolumeUsage);+ stdout.WriteLine();+ stdout.WriteLine("Analyze STEP body volume using kernel B-rep topology/geometry.");+ stdout.WriteLine();+ stdout.WriteLine("Options:");+ stdout.WriteLine(" --json Emit machine-readable JSON output.");+ stdout.WriteLine();+ stdout.WriteLine("Notes:");+ stdout.WriteLine(" - Exact whole-body volume currently supports canonical spheres and single-lateral-face cylinders.");+ stdout.WriteLine(" - Exact sub-box volume clipping (--box ...) is deferred in ANALYZE-P1.");+ stdout.WriteLine();+ stdout.WriteLine("Examples:");+ stdout.WriteLine(" aetheris analyze volume part.step");+ stdout.WriteLine(" aetheris analyze volume part.step --json");+ }+private static void WriteCanonHelp(TextWriter stdout){stdout.WriteLine("Canonicalize part-like STEP/AP242 through Aetheris import/export.");diff --git a/Aetheris.CLI/StepAnalyzer.cs b/Aetheris.CLI/StepAnalyzer.csindex 16ed59e2..ddf88344 100644--- a/Aetheris.CLI/StepAnalyzer.cs+++ b/Aetheris.CLI/StepAnalyzer.cs@@ -12,6 +12,10 @@ namespace Aetheris.CLI;public static class StepAnalyzer{++public sealed record VolumeBoundingBox(Point3D Min, Point3D Max);+public sealed record VolumeAnalysisResult(string InputPath, bool Success, double Volume, string LengthUnit, string VolumeUnit, VolumeBoundingBox BoundingBox, string Method, IReadOnlyList<string> Notes);+public static AnalyzeResult Analyze(string stepPath, int? faceId = null, int? edgeId = null, int? vertexId = null){var (fullPath, body) = ImportStepBody(stepPath);@@ -42,6 +46,51 @@ public static class StepAnalyzerreturn AnalyzeImportedBodySection(body, fullPath, planeFamily, offset);}+ public static VolumeAnalysisResult AnalyzeVolume(string stepPath)+ {+ var (fullPath, body) = ImportStepBody(stepPath);+ var notes = new List<string>();+ var bbox = TryComputeBodyBoundingBox(body) ?? throw new InvalidOperationException("Volume analysis requires body vertex coordinates for bounding box reporting.");+ var shells = body.ShellRepresentation;+ if (shells is null)+ {+ throw new InvalidOperationException("Volume analysis requires explicit shell-role representation.");+ }++ var sphereFaces = body.Topology.Faces.Where(f => body.TryGetFaceSurface(f.Id, out var sf) && sf?.Sphere is not null).ToArray();+ if (body.Topology.Faces.Count() == 1 && sphereFaces.Length == 1)+ {+ var r = sphereFaces[0];+ body.TryGetFaceSurface(r.Id, out var sph);+ var radius = sph!.Sphere!.Value.Radius;+ var vol = 4d/3d*double.Pi*radius*radius*radius;+ notes.Add("Exact analytic sphere volume from spherical face radius.");+ return new VolumeAnalysisResult(stepPath, true, vol, "model-unit", "model-unit^3", new VolumeBoundingBox(bbox.Min, bbox.Max), "analytic-sphere", notes);+ }++ var cylFaces = body.Topology.Faces.Where(f => body.TryGetFaceSurface(f.Id, out var sf) && sf?.Cylinder is not null).ToArray();+ if (cylFaces.Length == 1)+ {+ body.TryGetFaceSurface(cylFaces[0].Id, out var cs);+ var cyl = cs!.Cylinder!.Value;+ var axis = cyl.Axis.ToVector();+ var min = double.PositiveInfinity; var max = double.NegativeInfinity;+ foreach (var v in body.Topology.Vertices)+ {+ if (!body.TryGetVertexPoint(v.Id, out var pt)) continue;+ var t = (pt - cyl.Origin).Dot(axis);+ min = double.Min(min,t); max = double.Max(max,t);+ }+ if (!double.IsFinite(min) || !double.IsFinite(max) || max <= min)+ throw new InvalidOperationException("Cylinder volume analysis could not resolve finite axial span from vertices.");+ var h=max-min; var vol=double.Pi*cyl.Radius*cyl.Radius*h;+ notes.Add("Exact analytic cylinder volume from cylinder radius and cap-span derived from bound vertices.");+ return new VolumeAnalysisResult(stepPath, true, vol, "model-unit", "model-unit^3", new VolumeBoundingBox(bbox.Min, bbox.Max), "analytic-cylinder", notes);+ }++ throw new InvalidOperationException("Volume analysis currently supports canonical sphere and single-lateral-face cylinder bodies only; general shell integration is deferred.");+ }+private static (string FullPath, BrepBody Body) ImportStepBody(string stepPath){var fullPath = Path.GetFullPath(stepPath);