Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

F2: bounded cylinder-root safe subtract re-entry for center bore

Yuechen Li160b4bc53c31
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
index 08f25a98..f85121a8 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
@@ -285,6 +285,41 @@ public sealed class BrepBooleanTests
&& surface?.Kind == SurfaceGeometryKind.Cylinder);
}
+ [Fact]
+ public void Subtract_CylinderRootCenterBore_Exports_And_RoundTrips_Deterministically()
+ {
+ var root = BrepPrimitives.CreateCylinder(40d, 12d).Value;
+ var bore = BrepPrimitives.CreateCylinder(12d, 24d).Value;
+
+ var first = BrepBoolean.Subtract(root, bore);
+ var second = BrepBoolean.Subtract(root, bore);
+
+ Assert.True(first.IsSuccess);
+ Assert.True(second.IsSuccess);
+ Assert.True(BrepBindingValidator.Validate(first.Value, true).IsSuccess);
+
+ var firstExport = Step242Exporter.ExportBody(first.Value);
+ var secondExport = Step242Exporter.ExportBody(second.Value);
+ Assert.True(firstExport.IsSuccess);
+ Assert.True(secondExport.IsSuccess);
+ Assert.Equal(firstExport.Value, secondExport.Value);
+ Assert.Contains("BREP_WITH_VOIDS", firstExport.Value, StringComparison.Ordinal);
+ Assert.Equal(6, first.Value.Topology.Faces.Count());
+ }
+
+ [Fact]
+ public void Subtract_CylinderRootOffsetHole_IsRejectedLoudly()
+ {
+ var root = BrepPrimitives.CreateCylinder(40d, 12d).Value;
+ var offsetHole = TransformBody(BrepPrimitives.CreateCylinder(4d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(25d, 0d, 0d)));
+
+ var result = BrepBoolean.Subtract(root, offsetHole);
+
+ Assert.False(result.IsSuccess);
+ var diagnostic = Assert.Single(result.Diagnostics);
+ Assert.Contains("only coaxial center bores are supported", diagnostic.Message, StringComparison.Ordinal);
+ }
+
[Fact]
public void Subtract_BoxCylinderRotatedAxis_SucceedsWithinBoundedSubset()
{
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs
index 4737ba74..9f9ef412 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs
@@ -173,6 +173,13 @@ public static class BrepBoolean
return new BooleanCaseClassification(BooleanExecutionClass.PlanarOnly, leftSafeComposition, leftBox, rightBox, null, null);
}
+ if (operation == BooleanOperation.Subtract && !leftRecognized && !leftSafeCompositionRecognized
+ && BrepBooleanSafeComposition.TryRecognize(leftBody, resolvedTolerance, out var recognizedRootComposition, out _))
+ {
+ leftSafeCompositionRecognized = true;
+ leftSafeComposition = recognizedRootComposition;
+ }
+
if (operation == BooleanOperation.Subtract && (leftRecognized || leftSafeCompositionRecognized) && rightAnalyticRecognized)
{
return new BooleanCaseClassification(
@@ -192,7 +199,7 @@ public static class BrepBoolean
leftRecognized ? leftBox : leftSafeComposition!.OuterBox,
rightRecognized ? rightBox : null,
rightAnalyticRecognized ? analyticSurface : null,
- $"Boolean {operation}: sequential safe composition only supports subtracting supported cylinder/cone analytic holes from the current composed box shell.");
+ $"Boolean {operation}: sequential safe composition only supports subtracting supported analytic holes from the current bounded safe root family.");
}
return new BooleanCaseClassification(
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs
index bf25897e..24cd8c30 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs
@@ -5,6 +5,7 @@ using Aetheris.Kernel.Core.Math;
using Aetheris.Kernel.Core.Numerics;
using Aetheris.Kernel.Core.Results;
using Aetheris.Kernel.Core.Topology;
+using Aetheris.Kernel.Core.Brep.Features;
namespace Aetheris.Kernel.Core.Brep.Boolean;
@@ -25,6 +26,11 @@ public static class BrepBooleanBoxCylinderHoleBuilder
{
ArgumentNullException.ThrowIfNull(composition);
_ = tolerance;
+ if (composition.RootDescriptor.Kind == SafeBooleanRootKind.Cylinder)
+ {
+ return CreateBoundedCylinderRootCenterBoreBody(composition, tolerance);
+ }
+
if (composition.Holes.Count == 1
&& composition.Holes[0].Surface.Kind == AnalyticSurfaceKind.Sphere
&& composition.Holes[0].Surface.Sphere is RecognizedSphere sphere)
@@ -48,6 +54,67 @@ public static class BrepBooleanBoxCylinderHoleBuilder
return CreateComposedThroughHoleBody(composition);
}
+ private static KernelResult<BrepBody> CreateBoundedCylinderRootCenterBoreBody(SafeBooleanComposition composition, ToleranceContext tolerance)
+ {
+ if (composition.RootDescriptor.Cylinder is not RecognizedCylinder rootCylinder
+ || composition.Holes.Count != 1
+ || composition.Holes[0].Surface.Kind != AnalyticSurfaceKind.Cylinder
+ || composition.Holes[0].Surface.Cylinder is not RecognizedCylinder boreCylinder)
+ {
+ return KernelResult<BrepBody>.Failure([
+ new BooleanDiagnostic(
+ BooleanDiagnosticCode.NotFullySpanning,
+ BrepBooleanCylinderRecognition.CreateBooleanMessage(
+ BooleanOperation.Subtract.ToString(),
+ null,
+ "cylinder-root safe rebuild in F2 requires exactly one recognized through center-bore cylinder."),
+ "BrepBoolean.AnalyticHole.CylinderRootUnsupportedComposition").ToKernelDiagnostic(),
+ ]);
+ }
+
+ var rootCenter = new Point3D(
+ (rootCylinder.MinCenter.X + rootCylinder.MaxCenter.X) * 0.5d,
+ (rootCylinder.MinCenter.Y + rootCylinder.MaxCenter.Y) * 0.5d,
+ (rootCylinder.MinCenter.Z + rootCylinder.MaxCenter.Z) * 0.5d);
+ var boreCenter = new Point3D(
+ (boreCylinder.MinCenter.X + boreCylinder.MaxCenter.X) * 0.5d,
+ (boreCylinder.MinCenter.Y + boreCylinder.MaxCenter.Y) * 0.5d,
+ (boreCylinder.MinCenter.Z + boreCylinder.MaxCenter.Z) * 0.5d);
+
+ if (!ToleranceMath.AlmostEqual(rootCenter.X, boreCenter.X, tolerance)
+ || !ToleranceMath.AlmostEqual(rootCenter.Y, boreCenter.Y, tolerance))
+ {
+ return KernelResult<BrepBody>.Failure([
+ new BooleanDiagnostic(
+ BooleanDiagnosticCode.RadiusExceedsBoundary,
+ BrepBooleanCylinderRecognition.CreateBooleanMessage(
+ BooleanOperation.Subtract.ToString(),
+ null,
+ "cylinder-root safe rebuild in F2 only supports coaxial center bores."),
+ "BrepBoolean.AnalyticHole.CylinderRootUnsupportedComposition").ToKernelDiagnostic(),
+ ]);
+ }
+
+ var outer = BrepPrimitives.CreateCylinder(rootCylinder.Radius, rootCylinder.Height);
+ if (!outer.IsSuccess)
+ {
+ return KernelResult<BrepBody>.Failure(outer.Diagnostics);
+ }
+
+ var inner = BrepPrimitives.CreateCylinder(boreCylinder.Radius, rootCylinder.Height);
+ if (!inner.IsSuccess)
+ {
+ return KernelResult<BrepBody>.Failure(inner.Diagnostics);
+ }
+
+ var merged = MergeOuterAndInnerShell(outer.Value, inner.Value);
+ var bodyWithComposition = TranslateMergedBody(merged, rootCenter, composition);
+ var validation = BrepBindingValidator.Validate(bodyWithComposition, requireAllEdgeAndFaceBindings: true);
+ return validation.IsSuccess
+ ? KernelResult<BrepBody>.Success(bodyWithComposition, validation.Diagnostics)
+ : KernelResult<BrepBody>.Failure(validation.Diagnostics);
+ }
+
private static KernelResult<BrepBody> CreateComposedContainedSphereCavityBody(AxisAlignedBoxExtents outerBox, in RecognizedSphere sphere)
{
var outer = BrepBooleanBoxRecognition.CreateBoxFromExtents(outerBox);
@@ -578,6 +645,47 @@ public static class BrepBooleanBoxCylinderHoleBuilder
return (z - cone.AxisOrigin.Z) / axisZ;
}
+ private static BrepBody TranslateMergedBody(BrepBody body, Point3D center, SafeBooleanComposition composition)
+ {
+ var translation = new Vector3D(center.X, center.Y, center.Z);
+ if (translation == Vector3D.Zero)
+ {
+ return new BrepBody(body.Topology, body.Geometry, body.Bindings, vertexPoints: null, composition, body.ShellRepresentation);
+ }
+
+ var translatedGeometry = new BrepGeometryStore();
+ foreach (var curveEntry in body.Geometry.Curves)
+ {
+ translatedGeometry.AddCurve(curveEntry.Key, curveEntry.Value.Kind switch
+ {
+ CurveGeometryKind.Line3 => CurveGeometry.FromLine(new Line3Curve(curveEntry.Value.Line3!.Value.Origin + translation, curveEntry.Value.Line3.Value.Direction)),
+ CurveGeometryKind.Circle3 => CurveGeometry.FromCircle(new Circle3Curve(curveEntry.Value.Circle3!.Value.Center + translation, curveEntry.Value.Circle3.Value.Normal, curveEntry.Value.Circle3.Value.Radius, curveEntry.Value.Circle3.Value.XAxis)),
+ _ => curveEntry.Value
+ });
+ }
+
+ foreach (var surfaceEntry in body.Geometry.Surfaces)
+ {
+ translatedGeometry.AddSurface(surfaceEntry.Key, surfaceEntry.Value.Kind switch
+ {
+ SurfaceGeometryKind.Plane => SurfaceGeometry.FromPlane(new PlaneSurface(surfaceEntry.Value.Plane!.Value.Origin + translation, surfaceEntry.Value.Plane.Value.Normal, surfaceEntry.Value.Plane.Value.UAxis)),
+ SurfaceGeometryKind.Cylinder => SurfaceGeometry.FromCylinder(new CylinderSurface(surfaceEntry.Value.Cylinder!.Value.Origin + translation, surfaceEntry.Value.Cylinder.Value.Axis, surfaceEntry.Value.Cylinder.Value.Radius, surfaceEntry.Value.Cylinder.Value.XAxis)),
+ _ => surfaceEntry.Value
+ });
+ }
+
+ var vertexPoints = new Dictionary<VertexId, Point3D>();
+ foreach (var vertex in body.Topology.Vertices)
+ {
+ if (body.TryGetVertexPoint(vertex.Id, out var point))
+ {
+ vertexPoints[vertex.Id] = point + translation;
+ }
+ }
+
+ return new BrepBody(body.Topology, translatedGeometry, body.Bindings, vertexPoints, composition, body.ShellRepresentation);
+ }
+
private static LoopId AddLoop(TopologyBuilder builder, IReadOnlyList<EdgeUse> edgeUses)
{
var loopId = builder.AllocateLoopId();
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs
index c8d7bc94..108fde57 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs
@@ -6,8 +6,11 @@ namespace Aetheris.Kernel.Core.Brep.Boolean;
public sealed record SafeBooleanComposition(
AxisAlignedBoxExtents OuterBox,
- IReadOnlyList<SupportedBooleanHole> Holes)
+ IReadOnlyList<SupportedBooleanHole> Holes,
+ SafeBooleanRootDescriptor? Root = null)
{
+ public SafeBooleanRootDescriptor RootDescriptor => Root ?? SafeBooleanRootDescriptor.FromBox(OuterBox);
+
public SafeBooleanComposition Translate(Vector3D translation)
{
var translatedOuter = new AxisAlignedBoxExtents(
@@ -20,7 +23,60 @@ public sealed record SafeBooleanComposition(
return new SafeBooleanComposition(
translatedOuter,
- Holes.Select(hole => hole.Translate(translation)).ToArray());
+ Holes.Select(hole => hole.Translate(translation)).ToArray(),
+ RootDescriptor.Translate(translation));
+ }
+}
+
+public enum SafeBooleanRootKind
+{
+ Box,
+ Cylinder,
+}
+
+public readonly record struct SafeBooleanRootDescriptor(
+ SafeBooleanRootKind Kind,
+ AxisAlignedBoxExtents Box,
+ RecognizedCylinder? Cylinder = null)
+{
+ public static SafeBooleanRootDescriptor FromBox(AxisAlignedBoxExtents box)
+ => new(SafeBooleanRootKind.Box, box);
+
+ public static SafeBooleanRootDescriptor FromCylinder(in RecognizedCylinder cylinder)
+ {
+ var minCenter = cylinder.MinCenter;
+ var maxCenter = cylinder.MaxCenter;
+ var minX = System.Math.Min(minCenter.X, maxCenter.X) - cylinder.Radius;
+ var maxX = System.Math.Max(minCenter.X, maxCenter.X) + cylinder.Radius;
+ var minY = System.Math.Min(minCenter.Y, maxCenter.Y) - cylinder.Radius;
+ var maxY = System.Math.Max(minCenter.Y, maxCenter.Y) + cylinder.Radius;
+ var minZ = System.Math.Min(minCenter.Z, maxCenter.Z);
+ var maxZ = System.Math.Max(minCenter.Z, maxCenter.Z);
+ return new SafeBooleanRootDescriptor(
+ SafeBooleanRootKind.Cylinder,
+ new AxisAlignedBoxExtents(minX, maxX, minY, maxY, minZ, maxZ),
+ cylinder);
+ }
+
+ public SafeBooleanRootDescriptor Translate(Vector3D translation)
+ {
+ var translatedBox = new AxisAlignedBoxExtents(
+ Box.MinX + translation.X,
+ Box.MaxX + translation.X,
+ Box.MinY + translation.Y,
+ Box.MaxY + translation.Y,
+ Box.MinZ + translation.Z,
+ Box.MaxZ + translation.Z);
+
+ if (Kind == SafeBooleanRootKind.Cylinder && Cylinder is RecognizedCylinder cylinder)
+ {
+ return new SafeBooleanRootDescriptor(
+ Kind,
+ translatedBox,
+ cylinder with { AxisOrigin = cylinder.AxisOrigin + translation });
+ }
+
+ return new SafeBooleanRootDescriptor(Kind, translatedBox);
}
}
@@ -75,7 +131,15 @@ public static class BrepBooleanSafeComposition
if (BrepBooleanBoxRecognition.TryRecognizeAxisAlignedBox(body, tolerance, out var box, out reason))
{
- composition = new SafeBooleanComposition(box, []);
+ composition = new SafeBooleanComposition(box, [], SafeBooleanRootDescriptor.FromBox(box));
+ return true;
+ }
+
+ if (BrepBooleanCylinderRecognition.TryRecognizeCylinder(body, tolerance, out var cylinder, out reason)
+ && BrepBooleanCylinderRecognition.ValidateAxisAlignedZ(cylinder, tolerance))
+ {
+ var root = SafeBooleanRootDescriptor.FromCylinder(cylinder);
+ composition = new SafeBooleanComposition(root.Box, [], root);
return true;
}
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs
index 40024d31..7170f9d2 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs
@@ -16,6 +16,19 @@ public static class BrepBooleanSafeCompositionGraphValidator
{
updatedComposition = composition;
diagnostic = null;
+ var root = composition.RootDescriptor;
+
+ if (root.Kind == SafeBooleanRootKind.Cylinder)
+ {
+ return TryValidateCylinderRootSubtract(
+ composition,
+ root,
+ surface,
+ tolerance,
+ out updatedComposition,
+ out diagnostic,
+ nextFeatureId);
+ }
if (!TryCreateSupportedHole(composition.OuterBox, surface, tolerance, composition.Holes.Count > 0, out var nextHole, out diagnostic, nextFeatureId))
{
@@ -80,6 +93,121 @@ public static class BrepBooleanSafeCompositionGraphValidator
return true;
}
+ private static bool TryValidateCylinderRootSubtract(
+ SafeBooleanComposition composition,
+ SafeBooleanRootDescriptor root,
+ AnalyticSurface surface,
+ ToleranceContext tolerance,
+ out SafeBooleanComposition updatedComposition,
+ out BooleanDiagnostic? diagnostic,
+ string? nextFeatureId)
+ {
+ updatedComposition = composition;
+ diagnostic = null;
+
+ if (composition.Holes.Count > 0)
+ {
+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(
+ BooleanOperation.Subtract.ToString(),
+ nextFeatureId,
+ "supports only a single center-bore subtract on the bounded cylinder-root safe family in F2; follow-on cylinder-root subtract composition is deferred.");
+ return false;
+ }
+
+ if (surface.Kind != AnalyticSurfaceKind.Cylinder || surface.Cylinder is not RecognizedCylinder toolCylinder)
+ {
+ diagnostic = BrepBooleanCylinderRecognition.CreateUnsupportedAnalyticSurfaceKindDiagnostic(
+ BooleanOperation.Subtract.ToString(),
+ surface.Kind,
+ nextFeatureId);
+ return false;
+ }
+
+ if (root.Cylinder is not RecognizedCylinder rootCylinder)
+ {
+ diagnostic = BrepBooleanCylinderRecognition.CreateAxisNotAlignedDiagnostic(
+ BooleanOperation.Subtract.ToString(),
+ nextFeatureId,
+ "cannot resolve recognized cylinder-root descriptor.");
+ return false;
+ }
+
+ if (!BrepBooleanCylinderRecognition.ValidateAxisAlignedZ(rootCylinder, tolerance)
+ || !BrepBooleanCylinderRecognition.ValidateAxisAlignedZ(toolCylinder, tolerance))
+ {
+ diagnostic = BrepBooleanCylinderRecognition.CreateAxisNotAlignedDiagnostic(
+ BooleanOperation.Subtract.ToString(),
+ nextFeatureId,
+ "bounded cylinder-root safe subtract supports only world-Z aligned root and center-bore cylinders.");
+ return false;
+ }
+
+ var rootCenter = new Point3D(
+ (rootCylinder.MinCenter.X + rootCylinder.MaxCenter.X) * 0.5d,
+ (rootCylinder.MinCenter.Y + rootCylinder.MaxCenter.Y) * 0.5d,
+ (rootCylinder.MinCenter.Z + rootCylinder.MaxCenter.Z) * 0.5d);
+ var toolCenter = new Point3D(
+ (toolCylinder.MinCenter.X + toolCylinder.MaxCenter.X) * 0.5d,
+ (toolCylinder.MinCenter.Y + toolCylinder.MaxCenter.Y) * 0.5d,
+ (toolCylinder.MinCenter.Z + toolCylinder.MaxCenter.Z) * 0.5d);
+
+ if (!ToleranceMath.AlmostEqual(rootCenter.X, toolCenter.X, tolerance)
+ || !ToleranceMath.AlmostEqual(rootCenter.Y, toolCenter.Y, tolerance))
+ {
+ diagnostic = BrepBooleanCylinderRecognition.CreateRadiusExceedsBoundaryDiagnostic(
+ BooleanOperation.Subtract.ToString(),
+ nextFeatureId,
+ "is outside the bounded cylinder-root safe subtract family; only coaxial center bores are supported.");
+ return false;
+ }
+
+ if (toolCylinder.Radius >= (rootCylinder.Radius - tolerance.Linear))
+ {
+ diagnostic = BrepBooleanCylinderRecognition.CreateRadiusExceedsBoundaryDiagnostic(
+ BooleanOperation.Subtract.ToString(),
+ nextFeatureId,
+ "must remain strictly smaller than the flange root radius in the bounded cylinder-root safe subtract family.");
+ return false;
+ }
+
+ var rootMinZ = System.Math.Min(rootCylinder.MinCenter.Z, rootCylinder.MaxCenter.Z);
+ var rootMaxZ = System.Math.Max(rootCylinder.MinCenter.Z, rootCylinder.MaxCenter.Z);
+ var toolMinZ = System.Math.Min(toolCylinder.MinCenter.Z, toolCylinder.MaxCenter.Z);
+ var toolMaxZ = System.Math.Max(toolCylinder.MinCenter.Z, toolCylinder.MaxCenter.Z);
+ var spansRoot = toolMinZ <= (rootMinZ + tolerance.Linear) && toolMaxZ >= (rootMaxZ - tolerance.Linear);
+ if (!spansRoot)
+ {
+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(
+ BooleanOperation.Subtract.ToString(),
+ nextFeatureId,
+ "is outside the bounded cylinder-root safe subtract family; only through center bores that span both planar caps are supported.");
+ return false;
+ }
+
+ updatedComposition = composition with
+ {
+ Holes =
+ [
+ new SupportedBooleanHole(
+ nextFeatureId,
+ surface,
+ rootCenter.X,
+ rootCenter.Y,
+ new Point3D(rootCenter.X, rootCenter.Y, rootMinZ),
+ new Point3D(rootCenter.X, rootCenter.Y, rootMaxZ),
+ toolCylinder.Axis,
+ Direction3D.Create(new Vector3D(1d, 0d, 0d)),
+ toolCylinder.Radius,
+ toolCylinder.Radius,
+ SupportedBooleanHoleSpanKind.Through,
+ rootMinZ,
+ rootMaxZ)
+ ],
+ };
+
+ return true;
+ }
+
private static bool TryCreateSupportedHole(
AxisAlignedBoxExtents outerBox,
AnalyticSurface surface,
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
index 9a1d5552..6d507ff9 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
@@ -197,6 +197,18 @@ public sealed class FirmamentBuildAndExportTests
"add");
}
+ [Fact]
+ public void Run_F2FlangeCenterBoreExample_Writes_Default_Export_Artifact()
+ {
+ AssertExampleBuildAndExport(
+ "testdata/firmament/examples/f2_flange_center_bore.firmament",
+ "f2_flange_center_bore.step",
+ "center_bore",
+ 1,
+ "boolean",
+ "subtract");
+ }
+
[Fact]
public void Run_UnsupportedBoxWithCylinderHoleFixture_Fails_And_Does_Not_Write_Fallback_Export()
{
@@ -221,6 +233,7 @@ public sealed class FirmamentBuildAndExportTests
[InlineData("testdata/firmament/fixtures/m13a-unsupported-composed-subtract-sphere.firmament", "m13a-unsupported-composed-subtract-sphere.step", "cavity", "subtract")]
[InlineData("testdata/firmament/fixtures/m13a-unsupported-composed-subtract-box.firmament", "m13a-unsupported-composed-subtract-box.step", "notch", "subtract")]
[InlineData("testdata/firmament/fixtures/m13b-invalid-composed-reenter-safe-family.firmament", "m13b-invalid-composed-reenter-safe-family.step", "hole", "subtract")]
+ [InlineData("testdata/firmament/fixtures/m13c-unsupported-cylinder-root-follow-on-hole.firmament", "m13c-unsupported-cylinder-root-follow-on-hole.step", "bolt_hole", "subtract")]
public void Run_Unsupported_MixedPrimitive_Fixtures_Fail_And_Do_Not_Write_Fallback_Export(
string sourcePath,
string expectedFileName,
diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
index 563c0994..86e9034e 100644
--- a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
@@ -36,9 +36,12 @@ internal static class FirmamentPrimitiveExecutor
executedPrimitives.Add(new FirmamentExecutedPrimitive(primitive.OpIndex, primitive.FeatureId, primitive.Kind, bodyResult.Value.Published));
publishedBodiesByFeatureId[primitive.FeatureId] = bodyResult.Value.Published;
booleanExecutionBodiesByFeatureId[primitive.FeatureId] = bodyResult.Value.LegacyForBoolean;
- featureGraphStates[primitive.FeatureId] = primitive.Kind == FirmamentLoweredPrimitiveKind.Box
- ? FirmamentSafeSubtractFeatureGraphState.BoxRoot
- : FirmamentSafeSubtractFeatureGraphState.Other;
+ featureGraphStates[primitive.FeatureId] = primitive.Kind switch
+ {
+ FirmamentLoweredPrimitiveKind.Box => FirmamentSafeSubtractFeatureGraphState.BoxRoot,
+ FirmamentLoweredPrimitiveKind.Cylinder => FirmamentSafeSubtractFeatureGraphState.CylinderRoot,
+ _ => FirmamentSafeSubtractFeatureGraphState.Other
+ };
}
foreach (var boolean in loweringPlan.Booleans.OrderBy(b => b.OpIndex))
diff --git a/Aetheris.Kernel.Firmament/Validation/FirmamentSafeSubtractFeatureGraphValidator.cs b/Aetheris.Kernel.Firmament/Validation/FirmamentSafeSubtractFeatureGraphValidator.cs
index 9ed91c2d..22b3560b 100644
--- a/Aetheris.Kernel.Firmament/Validation/FirmamentSafeSubtractFeatureGraphValidator.cs
+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentSafeSubtractFeatureGraphValidator.cs
@@ -47,7 +47,7 @@ internal static class FirmamentSafeSubtractFeatureGraphValidator
return ValidateSupportedSafeSubtract(boolean, executionBodiesByFeatureId, tolerance);
}
- if (sourceState == FirmamentSafeSubtractFeatureGraphState.BoxRoot)
+ if (sourceState is FirmamentSafeSubtractFeatureGraphState.BoxRoot or FirmamentSafeSubtractFeatureGraphState.CylinderRoot)
{
if (boolean.Kind == FirmamentLoweredBooleanKind.Subtract && usesSupportedSafeHoleTool)
{
@@ -64,7 +64,7 @@ internal static class FirmamentSafeSubtractFeatureGraphValidator
{
return Failure(
KernelDiagnosticCode.ValidationFailed,
- $"Boolean feature '{boolean.FeatureId}' (subtract) cannot re-enter the safe subtract family from '{boolean.PrimaryReferenceFeatureId}'. Safe-hole composition may start only from a box root or continue from a previously validated safe subtract result.",
+ $"Boolean feature '{boolean.FeatureId}' (subtract) cannot re-enter the safe subtract family from '{boolean.PrimaryReferenceFeatureId}'. Safe-hole composition may start only from a bounded box/cylinder root or continue from a previously validated safe subtract result.",
"firmament.feature-graph.invalid-composition-order");
}
@@ -89,7 +89,7 @@ internal static class FirmamentSafeSubtractFeatureGraphValidator
{
return Failure(
KernelDiagnosticCode.ValidationFailed,
- $"Boolean feature '{boolean.FeatureId}' (subtract) cannot use '{boolean.PrimaryReferenceFeatureId}' as a safe subtract input because that earlier result is not a recognized base box or previously validated safe-hole composition.",
+ $"Boolean feature '{boolean.FeatureId}' (subtract) cannot use '{boolean.PrimaryReferenceFeatureId}' as a safe subtract input because that earlier result is not a recognized bounded box/cylinder root or previously validated safe-hole composition.",
"firmament.feature-graph.invalid-composition-order");
}
@@ -146,6 +146,7 @@ internal sealed record FirmamentSafeSubtractFeatureGraphValidation(
internal enum FirmamentSafeSubtractFeatureGraphState
{
BoxRoot,
+ CylinderRoot,
SafeSubtractComposition,
Other
}
diff --git a/testdata/firmament/examples/f2_flange_center_bore.firmament b/testdata/firmament/examples/f2_flange_center_bore.firmament
new file mode 100644
index 00000000..c745f877
--- /dev/null
+++ b/testdata/firmament/examples/f2_flange_center_bore.firmament
@@ -0,0 +1,22 @@
+firmament:
+ version: 1
+
+model:
+ name: f2_flange_center_bore
+ units: mm
+
+ops[2]:
+ -
+ op: cylinder
+ id: flange
+ radius: 40
+ height: 12
+
+ -
+ op: subtract
+ id: center_bore
+ from: flange
+ with:
+ op: cylinder
+ radius: 12
+ height: 24
diff --git a/testdata/firmament/exports/f2_flange_center_bore.step b/testdata/firmament/exports/f2_flange_center_bore.step
new file mode 100644
index 00000000..1d32c562
--- /dev/null
+++ b/testdata/firmament/exports/f2_flange_center_bore.step
@@ -0,0 +1,141 @@
+ISO-10303-21;
+HEADER;
+FILE_DESCRIPTION(('Aetheris AP242 subset export'),'2;1');
+FILE_NAME('aetheris_export.step','1970-01-01T00:00:00',('Aetheris'),('Aetheris'),'Aetheris.Kernel','Aetheris.Kernel','');
+FILE_SCHEMA(('AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF'));
+ENDSEC;
+DATA;
+#1=CARTESIAN_POINT($,(0,0,-6));
+#2=DIRECTION($,(0,0,1));
+#3=DIRECTION($,(1,0,0));
+#4=AXIS2_PLACEMENT_3D($,#1,#2,#3);
+#5=CYLINDRICAL_SURFACE($,#4,40);
+#6=CARTESIAN_POINT($,(40,0,-6));
+#7=VERTEX_POINT($,#6);
+#8=CARTESIAN_POINT($,(40,0,6));
+#9=VERTEX_POINT($,#8);
+#10=CARTESIAN_POINT($,(40,0,-6));
+#11=DIRECTION($,(0,0,1));
+#12=VECTOR($,#11,1);
+#13=LINE($,#10,#12);
+#14=EDGE_CURVE($,#7,#9,#13,.T.);
+#15=ORIENTED_EDGE($,$,$,#14,.T.);
+#16=CARTESIAN_POINT($,(40,0,6));
+#17=VERTEX_POINT($,#16);
+#18=CARTESIAN_POINT($,(0,0,6));
+#19=DIRECTION($,(0,0,1));
+#20=DIRECTION($,(1,0,0));
+#21=AXIS2_PLACEMENT_3D($,#18,#19,#20);
+#22=CIRCLE($,#21,40);
+#23=EDGE_CURVE($,#17,#17,#22,.T.);
+#24=ORIENTED_EDGE($,$,$,#23,.T.);
+#25=ORIENTED_EDGE($,$,$,#14,.F.);
+#26=CARTESIAN_POINT($,(40,0,-6));
+#27=VERTEX_POINT($,#26);
+#28=CARTESIAN_POINT($,(0,0,-6));
+#29=DIRECTION($,(0,0,1));
+#30=DIRECTION($,(1,0,0));
+#31=AXIS2_PLACEMENT_3D($,#28,#29,#30);
+#32=CIRCLE($,#31,40);
+#33=EDGE_CURVE($,#27,#27,#32,.T.);
+#34=ORIENTED_EDGE($,$,$,#33,.F.);
+#35=EDGE_LOOP($,(#15,#24,#25,#34));
+#36=FACE_OUTER_BOUND('',#35,.T.);
+#37=ADVANCED_FACE('',(#36),#5,.T.);
+#38=CARTESIAN_POINT($,(0,0,6));
+#39=DIRECTION($,(0,0,1));
+#40=DIRECTION($,(1,0,0));
+#41=AXIS2_PLACEMENT_3D($,#38,#39,#40);
+#42=PLANE($,#41);
+#43=ORIENTED_EDGE($,$,$,#23,.F.);
+#44=EDGE_LOOP($,(#43));
+#45=FACE_OUTER_BOUND('',#44,.T.);
+#46=ADVANCED_FACE('',(#45),#42,.T.);
+#47=CARTESIAN_POINT($,(0,0,-6));
+#48=DIRECTION($,(0,0,-1));
+#49=DIRECTION($,(0,1,0));
+#50=AXIS2_PLACEMENT_3D($,#47,#48,#49);
+#51=PLANE($,#50);
+#52=ORIENTED_EDGE($,$,$,#33,.T.);
+#53=EDGE_LOOP($,(#52));
+#54=FACE_OUTER_BOUND('',#53,.T.);
+#55=ADVANCED_FACE('',(#54),#51,.T.);
+#56=CLOSED_SHELL($,(#37,#46,#55));
+#57=CARTESIAN_POINT($,(0,0,-6));
+#58=DIRECTION($,(0,0,1));
+#59=DIRECTION($,(1,0,0));
+#60=AXIS2_PLACEMENT_3D($,#57,#58,#59);
+#61=CYLINDRICAL_SURFACE($,#60,12);
+#62=CARTESIAN_POINT($,(12,0,-6));
+#63=VERTEX_POINT($,#62);
+#64=CARTESIAN_POINT($,(12,0,6));
+#65=VERTEX_POINT($,#64);
+#66=CARTESIAN_POINT($,(12,0,-6));
+#67=DIRECTION($,(0,0,1));
+#68=VECTOR($,#67,1);
+#69=LINE($,#66,#68);
+#70=EDGE_CURVE($,#63,#65,#69,.T.);
+#71=ORIENTED_EDGE($,$,$,#70,.T.);
+#72=CARTESIAN_POINT($,(12,0,6));
+#73=VERTEX_POINT($,#72);
+#74=CARTESIAN_POINT($,(0,0,6));
+#75=DIRECTION($,(0,0,1));
+#76=DIRECTION($,(1,0,0));
+#77=AXIS2_PLACEMENT_3D($,#74,#75,#76);
+#78=CIRCLE($,#77,12);
+#79=EDGE_CURVE($,#73,#73,#78,.T.);
+#80=ORIENTED_EDGE($,$,$,#79,.T.);
+#81=ORIENTED_EDGE($,$,$,#70,.F.);
+#82=CARTESIAN_POINT($,(12,0,-6));
+#83=VERTEX_POINT($,#82);
+#84=CARTESIAN_POINT($,(0,0,-6));
+#85=DIRECTION($,(0,0,1));
+#86=DIRECTION($,(1,0,0));
+#87=AXIS2_PLACEMENT_3D($,#84,#85,#86);
+#88=CIRCLE($,#87,12);
+#89=EDGE_CURVE($,#83,#83,#88,.T.);
+#90=ORIENTED_EDGE($,$,$,#89,.F.);
+#91=EDGE_LOOP($,(#71,#80,#81,#90));
+#92=FACE_OUTER_BOUND('',#91,.T.);
+#93=ADVANCED_FACE('',(#92),#61,.T.);
+#94=CARTESIAN_POINT($,(0,0,6));
+#95=DIRECTION($,(0,0,1));
+#96=DIRECTION($,(1,0,0));
+#97=AXIS2_PLACEMENT_3D($,#94,#95,#96);
+#98=PLANE($,#97);
+#99=ORIENTED_EDGE($,$,$,#79,.F.);
+#100=EDGE_LOOP($,(#99));
+#101=FACE_OUTER_BOUND('',#100,.T.);
+#102=ADVANCED_FACE('',(#101),#98,.T.);
+#103=CARTESIAN_POINT($,(0,0,-6));
+#104=DIRECTION($,(0,0,-1));
+#105=DIRECTION($,(0,1,0));
+#106=AXIS2_PLACEMENT_3D($,#103,#104,#105);
+#107=PLANE($,#106);
+#108=ORIENTED_EDGE($,$,$,#89,.T.);
+#109=EDGE_LOOP($,(#108));
+#110=FACE_OUTER_BOUND('',#109,.T.);
+#111=ADVANCED_FACE('',(#110),#107,.T.);
+#112=CLOSED_SHELL($,(#93,#102,#111));
+#113=ORIENTED_CLOSED_SHELL($,#112,.F.);
+#114=BREP_WITH_VOIDS('AetherisBody',#56,(#113));
+#115=APPLICATION_CONTEXT('mechanical design');
+#116=PRODUCT_CONTEXT('',#115,'mechanical');
+#117=PRODUCT('AETHERIS','AetherisBody','',(#116));
+#118=PRODUCT_DEFINITION_FORMATION('','',#117);
+#119=PRODUCT_DEFINITION_CONTEXT('design',#115,'design');
+#120=PRODUCT_DEFINITION('','',#118,#119);
+#121=PRODUCT_DEFINITION_SHAPE('','',#120);
+#122=(LENGTH_UNIT()NAMED_UNIT(*)SI_UNIT(.MILLI.,.METRE.));
+#123=(NAMED_UNIT(*)PLANE_ANGLE_UNIT()SI_UNIT($,.RADIAN.));
+#124=(NAMED_UNIT(*)SI_UNIT($,.STERADIAN.)SOLID_ANGLE_UNIT());
+#125=(GEOMETRIC_REPRESENTATION_CONTEXT(3)GLOBAL_UNIT_ASSIGNED_CONTEXT((#122,#123,#124))REPRESENTATION_CONTEXT('3','3D'));
+#126=SHAPE_ASPECT('firmament-feature:center_bore','supported cylinder through-hole feature',#121,.FALSE.);
+#127=PROPERTY_DEFINITION('diameter:center_bore','auto-derived semantic PMI diameter',#126);
+#128=MEASURE_REPRESENTATION_ITEM('diameter',24,#122);
+#129=SHAPE_DIMENSION_REPRESENTATION('diameter:center_bore',(#128),#125);
+#130=PROPERTY_DEFINITION_REPRESENTATION(#127,#129);
+#131=SHAPE_REPRESENTATION('AetherisBody',(#114),#125);
+#132=SHAPE_DEFINITION_REPRESENTATION(#121,#131);
+ENDSEC;
+END-ISO-10303-21;
diff --git a/testdata/firmament/fixtures/m13c-unsupported-cylinder-root-follow-on-hole.firmament b/testdata/firmament/fixtures/m13c-unsupported-cylinder-root-follow-on-hole.firmament
new file mode 100644
index 00000000..091832e7
--- /dev/null
+++ b/testdata/firmament/fixtures/m13c-unsupported-cylinder-root-follow-on-hole.firmament
@@ -0,0 +1,37 @@
+firmament:
+ version: 1
+
+model:
+ name: m13c_unsupported_cylinder_root_follow_on_hole
+ units: mm
+
+ops[3]:
+ -
+ op: cylinder
+ id: flange
+ radius: 40
+ height: 12
+
+ -
+ op: subtract
+ id: center_bore
+ from: flange
+ with:
+ op: cylinder
+ radius: 12
+ height: 24
+
+ -
+ op: subtract
+ id: bolt_hole
+ from: center_bore
+ with:
+ op: cylinder
+ radius: 4
+ height: 24
+ place:
+ on: origin
+ offset[3]:
+ 25
+ 0
+ 0