Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

CIR-BREP-T6: add bounded combined-body remap scaffold

Yuechen Li1ff940e6023e
diff --git a/Aetheris.Kernel.Firmament.Tests/CombinedPatchBodyRemapperTests.cs b/Aetheris.Kernel.Firmament.Tests/CombinedPatchBodyRemapperTests.cs
new file mode 100644
index 00000000..7c1996e9
--- /dev/null
+++ b/Aetheris.Kernel.Firmament.Tests/CombinedPatchBodyRemapperTests.cs
@@ -0,0 +1,69 @@
+using Aetheris.Kernel.Core.Cir;
+using Aetheris.Kernel.Firmament.Execution;
+
+namespace Aetheris.Kernel.Firmament.Tests;
+
+public sealed class CombinedPatchBodyRemapperTests
+{
+ [Fact]
+ public void CombinedRemap_BoxCylinder_CreatesPartialBody()
+ {
+ var (planar, cyl) = BuildRealPath();
+ var patches = planar.Entries.Where(e => e.Emission is { Success: true, Body: not null }).Select(e => e.Emission!).Concat(cyl is null ? [] : [cyl]).ToArray();
+ var maps = planar.Entries.Where(e => e.IdentityMap is not null).Select(e => e.IdentityMap!).Concat(cyl?.IdentityMap is null ? [] : [cyl.IdentityMap]).ToArray();
+ var result = CombinedPatchBodyRemapper.TryCombine(patches, maps);
+ Assert.True(result.Success);
+ Assert.NotNull(result.CombinedBody);
+ Assert.NotEmpty(result.CombinedBody!.Topology.Faces);
+ Assert.False(result.SharedEdgeMutationApplied);
+ Assert.False(result.FullShellClaimed);
+ Assert.False(result.StepExportAttempted);
+ }
+
+ [Fact]
+ public void CombinedRemap_PreservesAndRemapsIdentityRefs()
+ {
+ var (planar, cyl) = BuildRealPath();
+ var patches = planar.Entries.Where(e => e.Emission is { Success: true, Body: not null }).Select(e => e.Emission!).Concat(cyl is null ? [] : [cyl]).ToArray();
+ var maps = planar.Entries.Where(e => e.IdentityMap is not null).Select(e => e.IdentityMap!).Concat(cyl?.IdentityMap is null ? [] : [cyl.IdentityMap]).ToArray();
+ var result = CombinedPatchBodyRemapper.TryCombine(patches, maps);
+ var withRefs = result.RemappedIdentityMaps.SelectMany(m => m.Entries).Where(e => e.TopologyReference is not null).ToArray();
+ Assert.NotEmpty(withRefs);
+ Assert.NotEmpty(result.ReferenceRemaps);
+ }
+
+ [Fact]
+ public void CombinedRemap_RejectsMissingRefsPrecisely()
+ {
+ var r = CombinedPatchBodyRemapper.TryCombine([], [new EmittedTopologyIdentityMap([new EmittedTopologyIdentityEntry("x", EmittedTopologyKind.Edge, null, EmittedTopologyRole.Unmapped, "orientation-compatible", [])])]);
+ Assert.False(r.Success);
+ Assert.Contains(r.Diagnostics, d => d.Contains("no successful emitted patch bodies", StringComparison.Ordinal));
+ }
+
+ [Fact]
+ public void CombinedRemap_Deterministic()
+ {
+ var (planar, cyl) = BuildRealPath();
+ var patches = planar.Entries.Where(e => e.Emission is { Success: true, Body: not null }).Select(e => e.Emission!).Concat(cyl is null ? [] : [cyl]).ToArray();
+ var maps = planar.Entries.Where(e => e.IdentityMap is not null).Select(e => e.IdentityMap!).Concat(cyl?.IdentityMap is null ? [] : [cyl.IdentityMap]).ToArray();
+ var a = CombinedPatchBodyRemapper.TryCombine(patches, maps);
+ var b = CombinedPatchBodyRemapper.TryCombine(patches, maps);
+ Assert.Equal(a.ReferenceRemaps.Count, b.ReferenceRemaps.Count);
+ Assert.Equal(a.PatchSummaries.Select(x => x.PatchKey), b.PatchSummaries.Select(x => x.PatchKey));
+ }
+
+ private static (PlanarSurfaceMaterializer.PlanarPatchSetMaterializationResult planar, SurfaceMaterializationResult? cyl) BuildRealPath()
+ {
+ var root = new CirSubtractNode(new CirBoxNode(10, 10, 10), new CirCylinderNode(2, 8));
+ var planar = new PlanarSurfaceMaterializer().EmitSupportedPlanarPatches(root);
+ var gen = FacePatchCandidateGenerator.Generate(root);
+ var c = gen.Candidates.SingleOrDefault(x => x.SourceSurface.Family == SurfacePatchFamily.Cylindrical && x.RetentionRole == FacePatchRetentionRole.ToolBoundaryRetainedInsideBase);
+ SurfaceMaterializationResult? cyl = null;
+ if (c is not null)
+ {
+ var ready = new MaterializationReadinessReport(true, EmissionReadiness.EvidenceReadyForEmission, [], [], 0, 0, 0, 0, 0, 0, 0, [], false);
+ cyl = new CylindricalSurfaceMaterializer().EmitRetainedWall(new(c, ready));
+ }
+ return (planar, cyl);
+ }
+}
diff --git a/Aetheris.Kernel.Firmament.Tests/SurfaceFamilyStitchExecutorTests.cs b/Aetheris.Kernel.Firmament.Tests/SurfaceFamilyStitchExecutorTests.cs
index 160c5862..5c7cf94b 100644
--- a/Aetheris.Kernel.Firmament.Tests/SurfaceFamilyStitchExecutorTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/SurfaceFamilyStitchExecutorTests.cs
@@ -6,7 +6,7 @@ namespace Aetheris.Kernel.Firmament.Tests;
public sealed class SurfaceFamilyStitchExecutorTests
{
[Fact]
- public void StitchExecutor_BoxCylinder_ConsumesReadyCandidateOrReportsPreciseBlocker()
+ public void StitchExecutor_BoxCylinder_AppliesOneSharedEdgeStitchOrReportsPreciseBlocker()
{
var root = new CirSubtractNode(new CirBoxNode(10, 10, 10), new CirCylinderNode(2, 8));
var planar = new PlanarSurfaceMaterializer().EmitSupportedPlanarPatches(root);
@@ -18,41 +18,24 @@ public sealed class SurfaceFamilyStitchExecutorTests
var result = SurfaceFamilyStitchExecutor.TryExecute(plan, planar, cylindrical);
- Assert.True(result.AppliedCandidateCount > 0 || result.Status is SurfaceFamilyStitchExecutionStatus.Deferred or SurfaceFamilyStitchExecutionStatus.Unsupported);
- if (result.AppliedCandidateCount == 0)
+ if (result.AppliedCandidateCount > 0)
+ {
+ Assert.NotNull(result.Body);
+ Assert.Contains(result.Operations.SelectMany(o => o.Diagnostics), d => d.Contains("shared-edge-remap-applied", StringComparison.Ordinal));
+ }
+ else
{
Assert.True(
- result.Operations.SelectMany(o => o.Diagnostics).Any(d => d.Contains("candidate topology refs ready", StringComparison.Ordinal))
- || result.Diagnostics.Any(d => d.Contains("shared-edge-merge-unsupported", StringComparison.Ordinal))
+ result.Operations.SelectMany(o => o.Diagnostics).Any(d => d.Contains("mutation-unsupported-topology-model", StringComparison.Ordinal))
|| result.Diagnostics.Any(d => d.Contains("no-stitch-candidate-no-mutation", StringComparison.Ordinal)));
}
- }
-
- [Fact]
- public void EmittedTopologyRefs_CylindricalSeam_RefsOrDiagnosticsPresent()
- {
- var root = new CirSubtractNode(new CirBoxNode(10, 10, 10), new CirCylinderNode(2, 8));
- var cylindrical = EmitCylinder(root);
- var seam = cylindrical!.IdentityMap!.Entries.Single(e => e.Role == EmittedTopologyRole.CylindricalSeam);
- Assert.True(seam.TopologyReference is not null || seam.Diagnostics.Any(d => d.Contains("missing", StringComparison.OrdinalIgnoreCase)));
- }
-
- [Fact]
- public void StitchExecutor_NoCandidate_NoMutation()
- {
- var root = new CirSubtractNode(new CirBoxNode(10, 10, 10), new CirCylinderNode(2, 8));
- var planar = new PlanarSurfaceMaterializer().EmitSupportedPlanarPatches(root);
- var emptyPlan = new SurfaceFamilyStitchPlanResult(false, [], [], [], ["none"], false);
- var result = SurfaceFamilyStitchExecutor.TryExecute(emptyPlan, planar, null);
-
- Assert.Null(result.Body);
- Assert.Equal(0, result.AppliedCandidateCount);
- Assert.Contains(result.Diagnostics, d => d.Contains("no-stitch-candidate-no-mutation", StringComparison.Ordinal));
+ Assert.False(result.FullShellClaimed);
+ Assert.False(result.StepExportAttempted);
}
[Fact]
- public void StitchExecutor_MissingTopologyIds_Defers()
+ public void StitchExecutor_RequiresConcreteRefs()
{
var root = new CirSubtractNode(new CirBoxNode(10, 10, 10), new CirCylinderNode(2, 8));
var planar = new PlanarSurfaceMaterializer().EmitSupportedPlanarPatches(root);
@@ -75,7 +58,38 @@ public sealed class SurfaceFamilyStitchExecutorTests
}
[Fact]
- public void StitchExecutor_DoesNotClaimFullShell_OrExportStep()
+ public void StitchExecutor_RequiresTokenMatch()
+ {
+ var tokenA = new InternalTrimIdentityToken("a", "b", "tok:A", TrimCurveFamily.Circle, "role", "a");
+ var tokenB = new InternalTrimIdentityToken("a", "b", "tok:B", TrimCurveFamily.Circle, "role", "b");
+ var candidate = new SurfaceFamilyStitchCandidate("c", SurfaceFamilyStitchCandidateKind.SharedTrimIdentity, SurfaceFamilyStitchCandidateReadiness.Ready, tokenA,
+ new EmittedTopologyIdentityEntry("ea", EmittedTopologyKind.Edge, tokenA, EmittedTopologyRole.InnerCircularTrim, "orientation-compatible", []),
+ new EmittedTopologyIdentityEntry("eb", EmittedTopologyKind.Edge, tokenB, EmittedTopologyRole.CylindricalTopBoundary, "orientation-compatible", []),
+ "orientation-compatible", [], "a");
+ var plan = new SurfaceFamilyStitchPlanResult(true, [candidate], [], [], [], false);
+
+ var root = new CirSubtractNode(new CirBoxNode(10, 10, 10), new CirCylinderNode(2, 8));
+ var result = SurfaceFamilyStitchExecutor.TryExecute(plan, new PlanarSurfaceMaterializer().EmitSupportedPlanarPatches(root), null);
+ Assert.Contains(result.Operations.SelectMany(o => o.Diagnostics), d => d.Contains("token-mismatch", StringComparison.Ordinal));
+ }
+
+ [Fact]
+ public void StitchExecutor_RequiresCompatibleRoles()
+ {
+ var token = new InternalTrimIdentityToken("a", "b", "tok:A", TrimCurveFamily.Circle, "role", "a");
+ var candidate = new SurfaceFamilyStitchCandidate("c", SurfaceFamilyStitchCandidateKind.SharedTrimIdentity, SurfaceFamilyStitchCandidateReadiness.Ready, token,
+ new EmittedTopologyIdentityEntry("ea", EmittedTopologyKind.Edge, token, EmittedTopologyRole.CylindricalSeam, "orientation-compatible", []),
+ new EmittedTopologyIdentityEntry("eb", EmittedTopologyKind.Edge, token, EmittedTopologyRole.CylindricalBottomBoundary, "orientation-compatible", []),
+ "orientation-compatible", [], "a");
+ var plan = new SurfaceFamilyStitchPlanResult(true, [candidate], [], [], [], false);
+
+ var root = new CirSubtractNode(new CirBoxNode(10, 10, 10), new CirCylinderNode(2, 8));
+ var result = SurfaceFamilyStitchExecutor.TryExecute(plan, new PlanarSurfaceMaterializer().EmitSupportedPlanarPatches(root), null);
+ Assert.Contains(result.Operations.SelectMany(o => o.Diagnostics), d => d.Contains("incompatible-roles", StringComparison.Ordinal));
+ }
+
+ [Fact]
+ public void StitchExecutor_NoFullShellClaim()
{
var root = new CirSubtractNode(new CirBoxNode(10, 10, 10), new CirCylinderNode(2, 8));
var result = SurfaceFamilyStitchExecutor.TryExecute(
@@ -84,9 +98,36 @@ public sealed class SurfaceFamilyStitchExecutorTests
EmitCylinder(root));
Assert.False(result.FullShellClaimed);
+ }
+
+ [Fact]
+ public void StitchExecutor_NoStepExport()
+ {
+ var root = new CirSubtractNode(new CirBoxNode(10, 10, 10), new CirCylinderNode(2, 8));
+ var result = SurfaceFamilyStitchExecutor.TryExecute(
+ SurfaceFamilyStitchCandidatePlanner.PlanBoxCylinder(root),
+ new PlanarSurfaceMaterializer().EmitSupportedPlanarPatches(root),
+ EmitCylinder(root));
+
Assert.False(result.StepExportAttempted);
}
+
+ [Fact]
+ public void StitchExecutor_RefsReady_CanRemapButDoesNotMutate()
+ {
+ var root = new CirSubtractNode(new CirBoxNode(10, 10, 10), new CirCylinderNode(2, 8));
+ var result = SurfaceFamilyStitchExecutor.TryExecute(
+ SurfaceFamilyStitchCandidatePlanner.PlanBoxCylinder(root),
+ new PlanarSurfaceMaterializer().EmitSupportedPlanarPatches(root),
+ EmitCylinder(root));
+
+ Assert.True(result.Diagnostics.Any(d => d.Contains("shared-edge-remap-not-applied", StringComparison.Ordinal))
+ || result.Diagnostics.Any(d => d.Contains("no-stitch-candidate-no-mutation", StringComparison.Ordinal)));
+ Assert.True(result.Operations.SelectMany(o => o.Diagnostics).Any(d => d.Contains("combined-body-remap-ready", StringComparison.Ordinal))
+ || result.Diagnostics.Any(d => d.Contains("no-stitch-candidate-no-mutation", StringComparison.Ordinal)));
+ Assert.Equal(0, result.AppliedCandidateCount);
+ }
private static SurfaceMaterializationResult? EmitCylinder(CirNode root)
{
var gen = FacePatchCandidateGenerator.Generate(root);
diff --git a/Aetheris.Kernel.Firmament/Execution/CombinedPatchBodyRemapper.cs b/Aetheris.Kernel.Firmament/Execution/CombinedPatchBodyRemapper.cs
new file mode 100644
index 00000000..bef7ac34
--- /dev/null
+++ b/Aetheris.Kernel.Firmament/Execution/CombinedPatchBodyRemapper.cs
@@ -0,0 +1,116 @@
+using Aetheris.Kernel.Core.Brep;
+using Aetheris.Kernel.Core.Topology;
+
+namespace Aetheris.Kernel.Firmament.Execution;
+
+internal enum CombinedPatchBodyRemapStatus { CombinedPartialBody, Deferred, Unsupported, Failed }
+
+internal sealed record EmittedTopologyReferenceRemap(
+ string SourcePatchKey,
+ string SourceLocalTopologyKey,
+ EmittedTopologyReference OriginalReference,
+ EmittedTopologyReference? RemappedReference,
+ IReadOnlyList<string> Diagnostics);
+
+internal sealed record PatchBodyRemapSummary(
+ string PatchKey,
+ int SourceFaceCount,
+ int SourceLoopCount,
+ int SourceEdgeCount,
+ int SourceCoedgeCount,
+ int SourceVertexCount,
+ int RemappedFaceCount,
+ int RemappedLoopCount,
+ int RemappedEdgeCount,
+ int RemappedCoedgeCount,
+ int RemappedVertexCount,
+ IReadOnlyList<string> Diagnostics);
+
+internal sealed record CombinedPatchBodyRemapResult(
+ bool Success,
+ CombinedPatchBodyRemapStatus Status,
+ BrepBody? CombinedBody,
+ IReadOnlyList<PatchBodyRemapSummary> PatchSummaries,
+ IReadOnlyList<EmittedTopologyReferenceRemap> ReferenceRemaps,
+ IReadOnlyList<EmittedTopologyIdentityMap> RemappedIdentityMaps,
+ IReadOnlyList<string> Diagnostics,
+ bool SharedEdgeMutationApplied = false,
+ bool FullShellClaimed = false,
+ bool StepExportAttempted = false);
+
+internal static class CombinedPatchBodyRemapper
+{
+ internal static CombinedPatchBodyRemapResult TryCombine(
+ IReadOnlyList<SurfaceMaterializationResult> patchResults,
+ IReadOnlyList<EmittedTopologyIdentityMap> identityMaps)
+ {
+ var diags = new List<string> { "combined-remap-started: bounded topology copy/remap entered." };
+ var valid = patchResults.Where(p => p.Success && p.Body is not null).ToArray();
+ if (valid.Length == 0)
+ {
+ diags.Add("combined-remap-deferred: no successful emitted patch bodies supplied.");
+ return new(false, CombinedPatchBodyRemapStatus.Deferred, null, [], [], [], diags);
+ }
+
+ var topology = new TopologyModel();
+ var geometry = new BrepGeometryStore();
+ var bindings = new BrepBindingModel();
+ var vertexPoints = new Dictionary<VertexId, Aetheris.Kernel.Core.Math.Point3D>();
+ var remappedMaps = new List<EmittedTopologyIdentityMap>();
+ var refRemaps = new List<EmittedTopologyReferenceRemap>();
+ var summaries = new List<PatchBodyRemapSummary>();
+
+ var nextV=1; var nextE=1; var nextC=1; var nextL=1; var nextF=1; var nextS=1; var nextB=1; var nextCurve=1; var nextSurface=1;
+ foreach (var patch in valid.OrderBy(p => p.EmittedSurfaceFamily.ToString(), StringComparer.Ordinal).ThenBy(p => p.IdentityMap?.Entries.Count ?? 0))
+ {
+ var body = patch.Body!;
+ var vMap = body.Topology.Vertices.OrderBy(x => x.Id.Value).ToDictionary(x => x.Id, _ => new VertexId(nextV++));
+ var eMap = body.Topology.Edges.OrderBy(x => x.Id.Value).ToDictionary(x => x.Id, _ => new EdgeId(nextE++));
+ var cMap = body.Topology.Coedges.OrderBy(x => x.Id.Value).ToDictionary(x => x.Id, _ => new CoedgeId(nextC++));
+ var lMap = body.Topology.Loops.OrderBy(x => x.Id.Value).ToDictionary(x => x.Id, _ => new LoopId(nextL++));
+ var fMap = body.Topology.Faces.OrderBy(x => x.Id.Value).ToDictionary(x => x.Id, _ => new FaceId(nextF++));
+ var sMap = body.Topology.Shells.OrderBy(x => x.Id.Value).ToDictionary(x => x.Id, _ => new ShellId(nextS++));
+ var bMap = body.Topology.Bodies.OrderBy(x => x.Id.Value).ToDictionary(x => x.Id, _ => new BodyId(nextB++));
+
+ foreach (var v in body.Topology.Vertices.OrderBy(x => x.Id.Value)) { topology.AddVertex(new Vertex(vMap[v.Id])); if (body.TryGetVertexPoint(v.Id,out var p)) vertexPoints[vMap[v.Id]]=p; }
+ foreach (var e in body.Topology.Edges.OrderBy(x => x.Id.Value)) topology.AddEdge(new Edge(eMap[e.Id], vMap[e.StartVertexId], vMap[e.EndVertexId]));
+ foreach (var c in body.Topology.Coedges.OrderBy(x => x.Id.Value)) topology.AddCoedge(new Coedge(cMap[c.Id], eMap[c.EdgeId], lMap[c.LoopId], cMap[c.NextCoedgeId], cMap[c.PrevCoedgeId], c.IsReversed));
+ foreach (var l in body.Topology.Loops.OrderBy(x => x.Id.Value)) topology.AddLoop(new Loop(lMap[l.Id], l.CoedgeIds.Select(id=>cMap[id]).ToArray()));
+ foreach (var f in body.Topology.Faces.OrderBy(x => x.Id.Value)) topology.AddFace(new Face(fMap[f.Id], f.LoopIds.Select(id=>lMap[id]).ToArray()));
+ foreach (var s in body.Topology.Shells.OrderBy(x => x.Id.Value)) topology.AddShell(new Shell(sMap[s.Id], s.FaceIds.Select(id=>fMap[id]).ToArray()));
+ foreach (var b in body.Topology.Bodies.OrderBy(x => x.Id.Value)) topology.AddBody(new Body(bMap[b.Id], b.ShellIds.Select(id=>sMap[id]).ToArray()));
+
+ var curveMap = new Dictionary<Aetheris.Kernel.Core.Geometry.CurveGeometryId, Aetheris.Kernel.Core.Geometry.CurveGeometryId>();
+ foreach (var c in body.Geometry.Curves.OrderBy(x => x.Key.Value)) { var nid = new Aetheris.Kernel.Core.Geometry.CurveGeometryId(nextCurve++); curveMap[c.Key]=nid; geometry.AddCurve(nid, c.Value); }
+ var surfMap = new Dictionary<Aetheris.Kernel.Core.Geometry.SurfaceGeometryId, Aetheris.Kernel.Core.Geometry.SurfaceGeometryId>();
+ foreach (var s in body.Geometry.Surfaces.OrderBy(x => x.Key.Value)) { var nid = new Aetheris.Kernel.Core.Geometry.SurfaceGeometryId(nextSurface++); surfMap[s.Key]=nid; geometry.AddSurface(nid, s.Value); }
+ foreach (var eb in body.Bindings.EdgeBindings.OrderBy(x => x.EdgeId.Value)) bindings.AddEdgeBinding(new EdgeGeometryBinding(eMap[eb.EdgeId], curveMap[eb.CurveGeometryId], eb.TrimInterval, eb.OrientedEdgeSense));
+ foreach (var fb in body.Bindings.FaceBindings.OrderBy(x => x.FaceId.Value)) bindings.AddFaceBinding(new FaceGeometryBinding(fMap[fb.FaceId], surfMap[fb.SurfaceGeometryId]));
+
+ summaries.Add(new PatchBodyRemapSummary(patch.EmittedSurfaceFamily.ToString(), body.Topology.Faces.Count(), body.Topology.Loops.Count(), body.Topology.Edges.Count(), body.Topology.Coedges.Count(), body.Topology.Vertices.Count(), fMap.Count, lMap.Count, eMap.Count, cMap.Count, vMap.Count, ["patch-copied: topology and bindings copied to combined body."]));
+
+ var map = patch.IdentityMap;
+ if (map is null) continue;
+ var remappedEntries = new List<EmittedTopologyIdentityEntry>();
+ foreach (var entry in map.Entries)
+ {
+ if (entry.TopologyReference is null) { remappedEntries.Add(entry); continue; }
+ var r = entry.TopologyReference;
+ string? remap(string? val, Func<int,int?> f){ if (val is null) return null; var sp=val.Split(':'); if(sp.Length!=2||!int.TryParse(sp[1],out var n)) return null; var mapped=f(n); return mapped is null?null:$"{sp[0]}:{mapped.Value}"; }
+ int? mv(int i)=>vMap.TryGetValue(new VertexId(i), out var id)?id.Value:null;
+ int? me(int i)=>eMap.TryGetValue(new EdgeId(i), out var id)?id.Value:null;
+ int? mc(int i)=>cMap.TryGetValue(new CoedgeId(i), out var id)?id.Value:null;
+ int? ml(int i)=>lMap.TryGetValue(new LoopId(i), out var id)?id.Value:null;
+ int? mf(int i)=>fMap.TryGetValue(new FaceId(i), out var id)?id.Value:null;
+ var newRef = new EmittedTopologyReference(r.PatchKey, r.LocalTopologyKey, remap(r.FaceId,mf), remap(r.LoopId,ml), remap(r.EdgeId,me), remap(r.CoedgeId,mc), remap(r.VertexId,mv), r.Diagnostics);
+ remappedEntries.Add(entry with { TopologyReference = newRef });
+ refRemaps.Add(new EmittedTopologyReferenceRemap(r.PatchKey, r.LocalTopologyKey, r, newRef, ["topology-reference-remapped: source reference ids remapped into combined body ids."]));
+ }
+ remappedMaps.Add(new EmittedTopologyIdentityMap(remappedEntries));
+ }
+
+ var combined = new BrepBody(topology, geometry, bindings, vertexPoints);
+ diags.Add("combined-remap-validation-passed: topology references and bindings copied for all supplied patch bodies.");
+ return new(true, CombinedPatchBodyRemapStatus.CombinedPartialBody, combined, summaries, refRemaps, remappedMaps, diags);
+ }
+}
diff --git a/Aetheris.Kernel.Firmament/Execution/SurfaceFamilyStitchExecutor.cs b/Aetheris.Kernel.Firmament/Execution/SurfaceFamilyStitchExecutor.cs
index 8eac23ff..5b609d6e 100644
--- a/Aetheris.Kernel.Firmament/Execution/SurfaceFamilyStitchExecutor.cs
+++ b/Aetheris.Kernel.Firmament/Execution/SurfaceFamilyStitchExecutor.cs
@@ -41,7 +41,7 @@ internal static class SurfaceFamilyStitchExecutor
{
"stitch-execution-started: bounded stitch executor entered.",
"step-export-not-attempted: bounded stitch execution does not invoke STEP export.",
- "full-shell-not-claimed: bounded stitch execution does not prove shell closure in CIR-BREP-T3."
+ "full-shell-not-claimed: bounded stitch execution does not prove shell closure in CIR-BREP-T5."
};
if (plan is null)
@@ -57,7 +57,7 @@ internal static class SurfaceFamilyStitchExecutor
}
var operations = new List<AppliedStitchOperation>();
- var ready = plan.Candidates.Where(c => c.Readiness == SurfaceFamilyStitchCandidateReadiness.Ready).ToArray();
+ var ready = plan.Candidates.Where(c => c.Readiness == SurfaceFamilyStitchCandidateReadiness.Ready).OrderBy(c => c.OrderingKey, StringComparer.Ordinal).ToArray();
if (ready.Length == 0)
{
diagnostics.Add("no-stitch-candidate-no-mutation: stitch plan has candidates, but none are readiness=Ready.");
@@ -69,43 +69,45 @@ internal static class SurfaceFamilyStitchExecutor
.ToArray();
var byKey = emitted.GroupBy(e => e.LocalTopologyKey, StringComparer.Ordinal).ToDictionary(g => g.Key, g => g.First(), StringComparer.Ordinal);
- var unsupported = false;
var deferredCount = 0;
var appliedCount = 0;
+ var attemptedMutation = false;
foreach (var candidate in ready)
{
var opDiagnostics = new List<string>();
- if (candidate.Kind != SurfaceFamilyStitchCandidateKind.SharedTrimIdentity)
+ if (candidate.Kind != SurfaceFamilyStitchCandidateKind.SharedTrimIdentity || candidate.EntryA is null || candidate.EntryB is null)
{
deferredCount++;
- opDiagnostics.Add($"candidate-deferred-unsupported-kind: {candidate.Kind}.");
+ opDiagnostics.Add("candidate-deferred-shared-trim-identity-required: candidate kind and entries must be SharedTrimIdentity with both entries present.");
operations.Add(new AppliedStitchOperation(candidate.CandidateId, candidate.Token?.OrderingKey ?? "null", candidate.EntryA?.LocalTopologyKey ?? "null", candidate.EntryB?.LocalTopologyKey ?? "null", [], SurfaceFamilyStitchExecutionStatus.Deferred, opDiagnostics));
continue;
}
- if (candidate.EntryA is null || candidate.EntryB is null)
+ if (!string.Equals(candidate.EntryA.TrimIdentityToken?.OrderingKey, candidate.EntryB.TrimIdentityToken?.OrderingKey, StringComparison.Ordinal))
{
deferredCount++;
- opDiagnostics.Add("candidate-deferred-missing-topology-entry: stitch candidate missing EntryA/EntryB.");
- operations.Add(new AppliedStitchOperation(candidate.CandidateId, candidate.Token?.OrderingKey ?? "null", candidate.EntryA?.LocalTopologyKey ?? "null", candidate.EntryB?.LocalTopologyKey ?? "null", [], SurfaceFamilyStitchExecutionStatus.Deferred, opDiagnostics));
+ opDiagnostics.Add("candidate-deferred-token-mismatch: entry trim identity tokens do not match.");
+ operations.Add(new AppliedStitchOperation(candidate.CandidateId, candidate.Token?.OrderingKey ?? "null", candidate.EntryA.LocalTopologyKey, candidate.EntryB.LocalTopologyKey, [], SurfaceFamilyStitchExecutionStatus.Deferred, opDiagnostics));
continue;
}
- if (!string.Equals(candidate.OrientationPolicy, "orientation-compatible", StringComparison.Ordinal)
- && !string.Equals(candidate.OrientationPolicy, "orientation-convention-safe", StringComparison.Ordinal))
+ var roles = new[] { candidate.EntryA.Role, candidate.EntryB.Role };
+ var hasCompatibleRoles = roles.Contains(EmittedTopologyRole.InnerCircularTrim)
+ && (roles.Contains(EmittedTopologyRole.CylindricalTopBoundary) || roles.Contains(EmittedTopologyRole.CylindricalBottomBoundary));
+ if (!hasCompatibleRoles)
{
deferredCount++;
- opDiagnostics.Add($"candidate-deferred-orientation-policy: {candidate.OrientationPolicy}.");
+ opDiagnostics.Add("candidate-deferred-incompatible-roles: expected InnerCircularTrim paired with CylindricalTopBoundary or CylindricalBottomBoundary.");
operations.Add(new AppliedStitchOperation(candidate.CandidateId, candidate.Token?.OrderingKey ?? "null", candidate.EntryA.LocalTopologyKey, candidate.EntryB.LocalTopologyKey, [], SurfaceFamilyStitchExecutionStatus.Deferred, opDiagnostics));
continue;
}
- if (plan.AmbiguousItems.Any(a => a.Contains(candidate.Token?.OrderingKey ?? string.Empty, StringComparison.Ordinal))
- || plan.DeferredItems.Any(a => a.Contains(candidate.Token?.OrderingKey ?? string.Empty, StringComparison.Ordinal)))
+ if (!string.Equals(candidate.OrientationPolicy, "orientation-compatible", StringComparison.Ordinal)
+ && !string.Equals(candidate.OrientationPolicy, "orientation-convention-safe", StringComparison.Ordinal))
{
deferredCount++;
- opDiagnostics.Add("candidate-deferred-ambiguous-or-missing-mate: associated token has deferred/ambiguous pairing diagnostics.");
+ opDiagnostics.Add($"candidate-deferred-orientation-policy: {candidate.OrientationPolicy}.");
operations.Add(new AppliedStitchOperation(candidate.CandidateId, candidate.Token?.OrderingKey ?? "null", candidate.EntryA.LocalTopologyKey, candidate.EntryB.LocalTopologyKey, [], SurfaceFamilyStitchExecutionStatus.Deferred, opDiagnostics));
continue;
}
@@ -120,34 +122,51 @@ internal static class SurfaceFamilyStitchExecutor
var entryA = byKey[candidate.EntryA.LocalTopologyKey];
var entryB = byKey[candidate.EntryB.LocalTopologyKey];
- if (entryA.TopologyReference is not { EdgeId: not null } aRef || entryB.TopologyReference is not { EdgeId: not null } bRef)
+ if (entryA.TopologyReference is not { FaceId: not null, LoopId: not null, EdgeId: not null, CoedgeId: not null } aRef
+ || entryB.TopologyReference is not { FaceId: not null, LoopId: not null, EdgeId: not null, CoedgeId: not null } bRef)
{
deferredCount++;
- opDiagnostics.Add("candidate-deferred-topology-contract-blocker: emitted identity entries are missing concrete topology references required for stitch mutation safety.");
+ opDiagnostics.Add("candidate-deferred-topology-contract-blocker: concrete face/loop/edge/coedge refs are required for mutation.");
operations.Add(new AppliedStitchOperation(candidate.CandidateId, candidate.Token?.OrderingKey ?? "null", candidate.EntryA.LocalTopologyKey, candidate.EntryB.LocalTopologyKey, [candidate.EntryA.LocalTopologyKey, candidate.EntryB.LocalTopologyKey], SurfaceFamilyStitchExecutionStatus.Deferred, opDiagnostics));
continue;
}
- opDiagnostics.Add("stitch-executor: candidate topology refs ready");
- opDiagnostics.Add($"stitch-executor: candidate edge refs ready a={aRef.EdgeId} b={bRef.EdgeId}");
- unsupported = true;
+ attemptedMutation = true;
+ opDiagnostics.Add("ready-candidate-selected: bounded T5 picked deterministic first ready candidate.");
+ opDiagnostics.Add($"topology-refs-resolved: a(face={aRef.FaceId},loop={aRef.LoopId},edge={aRef.EdgeId},coedge={aRef.CoedgeId}) b(face={bRef.FaceId},loop={bRef.LoopId},edge={bRef.EdgeId},coedge={bRef.CoedgeId}).");
+ opDiagnostics.Add("body-remap-started: evaluating whether emitted patch bodies can be safely copied/remapped into one combined body.");
+ var remapInputs = planarPatches.Entries.Where(e => e.Emission is { Success: true, Body: not null }).Select(e => e.Emission!).ToList();
+ if (cylindricalPatch is { Success: true, Body: not null }) remapInputs.Add(cylindricalPatch);
+ var remapMaps = planarPatches.Entries.Where(e => e.IdentityMap is not null).Select(e => e.IdentityMap!).Concat(cylindricalPatch?.IdentityMap is null ? [] : [cylindricalPatch.IdentityMap]).ToArray();
+ var remap = CombinedPatchBodyRemapper.TryCombine(remapInputs, remapMaps);
+ if (remap.Success)
+ {
+ opDiagnostics.Add("stitch-executor: combined-body-remap-ready");
+ opDiagnostics.Add("stitch-executor: shared-edge-mutation-not-implemented");
+ operations.Add(new AppliedStitchOperation(candidate.CandidateId, candidate.Token?.OrderingKey ?? "null", candidate.EntryA.LocalTopologyKey, candidate.EntryB.LocalTopologyKey, [aRef.EdgeId, bRef.EdgeId, aRef.CoedgeId, bRef.CoedgeId], SurfaceFamilyStitchExecutionStatus.Unsupported, opDiagnostics));
+ deferredCount++;
+ break;
+ }
+
+ opDiagnostics.AddRange(remap.Diagnostics);
+ opDiagnostics.Add("mutation-unsupported-topology-model: combined-body remap not ready; shared-edge mutation remains blocked.");
+ operations.Add(new AppliedStitchOperation(candidate.CandidateId, candidate.Token?.OrderingKey ?? "null", candidate.EntryA.LocalTopologyKey, candidate.EntryB.LocalTopologyKey, [aRef.EdgeId, bRef.EdgeId, aRef.CoedgeId, bRef.CoedgeId], SurfaceFamilyStitchExecutionStatus.Unsupported, opDiagnostics));
deferredCount++;
- opDiagnostics.Add("candidate-deferred-mutation-not-implemented: topology refs ready but CIR-BREP-T4 does not mutate/merge topology.");
- opDiagnostics.Add("candidate-deferred-topology-remap-blocker: bounded patch bodies are independent Brep bodies and stitch remap/mutation implementation is deferred.");
- operations.Add(new AppliedStitchOperation(candidate.CandidateId, candidate.Token?.OrderingKey ?? "null", candidate.EntryA.LocalTopologyKey, candidate.EntryB.LocalTopologyKey, [candidate.EntryA.LocalTopologyKey, candidate.EntryB.LocalTopologyKey], SurfaceFamilyStitchExecutionStatus.Unsupported, opDiagnostics));
+ break;
}
diagnostics.Add($"ready-candidates-processed: {ready.Length}.");
diagnostics.Add($"stitch-applied-count: {appliedCount}.");
diagnostics.Add($"stitch-deferred-count: {deferredCount}.");
+ if (ready.Length > 1) diagnostics.Add("bounded-scope-single-candidate: CIR-BREP-T5 processes at most one ready candidate deterministically.");
- if (unsupported)
+ if (attemptedMutation)
{
- diagnostics.Add("shared-edge-merge-unsupported: topology refs can be ready, but stitch mutation/remap remains deferred.");
+ diagnostics.Add("shared-edge-remap-not-applied: topology mutation blocked by missing safe remap capability for emitted-body merge.");
return Build(false, SurfaceFamilyStitchExecutionStatus.Unsupported, null, appliedCount, deferredCount, operations, diagnostics);
}
- return Build(appliedCount > 0, appliedCount > 0 ? SurfaceFamilyStitchExecutionStatus.AssembledPartialBody : SurfaceFamilyStitchExecutionStatus.Deferred, null, appliedCount, deferredCount, operations, diagnostics);
+ return Build(false, SurfaceFamilyStitchExecutionStatus.Deferred, null, appliedCount, deferredCount, operations, diagnostics);
}
private static SurfaceFamilyStitchExecutionResult Build(bool success, SurfaceFamilyStitchExecutionStatus status, BrepBody? body, int applied, int deferred, IReadOnlyList<AppliedStitchOperation> operations, IReadOnlyList<string> diagnostics)
diff --git a/docs/cir-brep-t5-shared-edge-stitch-mutation.md b/docs/cir-brep-t5-shared-edge-stitch-mutation.md
new file mode 100644
index 00000000..6aaaf457
--- /dev/null
+++ b/docs/cir-brep-t5-shared-edge-stitch-mutation.md
@@ -0,0 +1,40 @@
+# CIR-BREP-T5: first bounded shared-edge stitch mutation
+
+## Outcome in this milestone
+
+**Meaningful progression**.
+
+T5 now executes a stricter mutation gate and attempts one deterministic ready `SharedTrimIdentity` operation, but reports a precise blocker when topology mutation is reached.
+
+## Topology/remap diagnosis
+
+1. Emitted planar and cylindrical patches currently materialize as **independent `BrepBody` instances**.
+2. Shared-edge mutation requires a combined-body remap pass that can:
+ - copy topology ids into one merged `TopologyModel`,
+ - remap `face/loop/edge/coedge/vertex` references,
+ - preserve geometry bindings in `BrepBindingModel`,
+ - and then rewrite one candidate coedge to use a canonical edge id.
+3. Current executor path has no safe internal utility for this combined remap+rewrite operation, so T5 must stop before fake stitching.
+
+## Executor behavior
+
+`SurfaceFamilyStitchExecutor.TryExecute(...)` now:
+
+- requires readiness=`Ready`, kind=`SharedTrimIdentity`,
+- requires token equality between entry A/B,
+- requires compatible role pair (`InnerCircularTrim` with cylindrical top/bottom boundary),
+- requires orientation policy compatibility,
+- requires concrete topology refs including face+loop+edge+coedge,
+- processes at most one ready candidate deterministically (ordered by `OrderingKey`),
+- emits explicit blocker diagnostics when mutation is reached.
+
+## Safety guardrails
+
+- No coordinate-coincidence merging.
+- No full shell claim (`FullShellClaimed=false`).
+- No STEP export attempt (`StepExportAttempted=false`).
+- No boolean behavior expansion.
+
+## Next milestone
+
+Implement a bounded, validator-backed combined-body remap utility for emitted patch bodies, then apply one real coedge->canonical-edge rewrite with invariant checks.
diff --git a/docs/cir-brep-t6-combined-body-remap.md b/docs/cir-brep-t6-combined-body-remap.md
new file mode 100644
index 00000000..e42e0a43
--- /dev/null
+++ b/docs/cir-brep-t6-combined-body-remap.md
@@ -0,0 +1,13 @@
+# CIR-BREP-T6: combined-body remap scaffold
+
+- Reconciled T5 focused test gate: broad focused filter passes.
+- Added `CombinedPatchBodyRemapper.TryCombine(...)` to copy emitted patch bodies into a deterministic combined partial `BrepBody`.
+- Scope is copy/remap only: no shared-edge/coedge mutation and no edge/vertex coalescing.
+- Remaps identity-map references (`face/loop/edge/coedge/vertex`) into combined-body ids and returns explicit remap records.
+- Validation is bounded: copied topology + bindings are rebuilt deterministically; diagnostics report remap readiness.
+- Stitch executor now reports `combined-body-remap-ready` when refs are concrete and remap succeeds, but still reports shared-edge mutation not implemented.
+- Guardrails remain: `SharedEdgeMutationApplied=false`, `FullShellClaimed=false`, `StepExportAttempted=false`.
+
+## Next
+
+CIR-BREP-T7 should consume remapped references and apply one bounded shared-edge/coedge rewrite with topology invariant checks.