Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

M25: add lightweight definition/occurrence document model

Yuechen Li17a4aedb428a
diff --git a/Aetheris.Server.Tests/DocumentSessionTests.cs b/Aetheris.Server.Tests/DocumentSessionTests.cs
new file mode 100644
index 00000000..bb570423
--- /dev/null
+++ b/Aetheris.Server.Tests/DocumentSessionTests.cs
@@ -0,0 +1,53 @@
+using Aetheris.Kernel.Core.Brep;
+using Aetheris.Kernel.Core.Math;
+using Aetheris.Server.Documents;
+
+namespace Aetheris.Server.Tests;
+
+public sealed class DocumentSessionTests
+{
+ [Fact]
+ public void AddBody_CreatesDefinitionAndInitialOccurrence()
+ {
+ var session = new DocumentSession(Guid.NewGuid());
+ var body = BrepPrimitives.CreateBox(1, 1, 1).Value;
+
+ var created = session.AddBody(body);
+
+ Assert.Single(session.SnapshotDefinitions());
+ Assert.Single(session.SnapshotOccurrences());
+ Assert.True(session.TryGetOccurrence(created.OccurrenceId, out var occurrence));
+ Assert.Equal(created.DefinitionId, occurrence.DefinitionId);
+ }
+
+ [Fact]
+ public void CreateOccurrenceFromOccurrence_ReusesDefinition()
+ {
+ var session = new DocumentSession(Guid.NewGuid());
+ var body = BrepPrimitives.CreateBox(1, 1, 1).Value;
+ var created = session.AddBody(body);
+
+ var success = session.TryCreateOccurrenceFromOccurrence(created.OccurrenceId, out var second);
+
+ Assert.True(success);
+ Assert.NotEqual(created.OccurrenceId, second.OccurrenceId);
+ Assert.Equal(created.DefinitionId, second.DefinitionId);
+ }
+
+ [Fact]
+ public void TranslateOccurrence_DoesNotMoveSiblingOccurrence()
+ {
+ var session = new DocumentSession(Guid.NewGuid());
+ var body = BrepPrimitives.CreateBox(1, 1, 1).Value;
+ var created = session.AddBody(body);
+ session.TryCreateOccurrenceFromOccurrence(created.OccurrenceId, out var sibling);
+
+ var moved = session.ApplyBodyTranslation(created.OccurrenceId, new Vector3D(5, 0, 0), out var movedTransform);
+ var hasSiblingTransform = session.TryGetBodyTransform(sibling.OccurrenceId, out var siblingTransform);
+
+ Assert.True(moved);
+ Assert.True(hasSiblingTransform);
+ Assert.Equal(5d, movedTransform.Apply(new Point3D(0, 0, 0)).X);
+ Assert.Equal(0d, siblingTransform.Apply(new Point3D(0, 0, 0)).X);
+ }
+}
diff --git a/Aetheris.Server.Tests/KernelApiIntegrationTests.cs b/Aetheris.Server.Tests/KernelApiIntegrationTests.cs
index 00a658d1..54a7e7ab 100644
--- a/Aetheris.Server.Tests/KernelApiIntegrationTests.cs
+++ b/Aetheris.Server.Tests/KernelApiIntegrationTests.cs
@@ -283,6 +283,85 @@ public sealed class KernelApiIntegrationTests : IClassFixture<WebApplicationFact
Assert.Contains(payload.Diagnostics, d => d.Source == "operations.extrude");
}
+
+ [Fact]
+ public async Task DocumentSummary_ReportsOccurrenceAndDefinitionIds()
+ {
+ var document = await CreateDocumentAsync("/api/v1/documents");
+ var box = await CreateBoxAsync("/api/v1/documents", document.Data!.DocumentId, 2, 2, 2);
+
+ var summaryResponse = await _client.GetAsync($"/api/v1/documents/{document.Data.DocumentId}");
+ summaryResponse.EnsureSuccessStatusCode();
+ var summary = await summaryResponse.Content.ReadFromJsonAsync<ApiResponseDto<DocumentSummaryResponseDto>>();
+
+ Assert.NotNull(summary);
+ Assert.True(summary!.Success);
+ Assert.Single(summary.Data!.BodyIds);
+ Assert.Single(summary.Data.Occurrences);
+ Assert.Equal(1, summary.Data.DefinitionCount);
+ Assert.Equal(box.Data!.BodyId, summary.Data.Occurrences[0].OccurrenceId);
+ Assert.Equal(box.Data.DefinitionId, summary.Data.Occurrences[0].DefinitionId);
+ }
+
+ [Fact]
+ public async Task CreateOccurrence_ReusesDefinitionAndSupportsIndependentPlacement()
+ {
+ var document = await CreateDocumentAsync("/api/v1/documents");
+ var box = await CreateBoxAsync("/api/v1/documents", document.Data!.DocumentId, 2, 2, 2);
+
+ var duplicateResponse = await _client.PostAsJsonAsync(
+ $"/api/v1/documents/{document.Data.DocumentId}/occurrences",
+ new CreateOccurrenceRequestDto(box.Data!.BodyId, DefinitionId: null, Name: "copy"));
+ duplicateResponse.EnsureSuccessStatusCode();
+
+ var duplicate = await duplicateResponse.Content.ReadFromJsonAsync<ApiResponseDto<OccurrenceCreatedResponseDto>>();
+ Assert.NotNull(duplicate);
+ Assert.True(duplicate!.Success);
+ Assert.Equal(box.Data.DefinitionId, duplicate.Data!.DefinitionId);
+
+ var transformResponse = await _client.PostAsJsonAsync(
+ $"/api/v1/documents/{document.Data.DocumentId}/bodies/{duplicate.Data.BodyId}/transform",
+ new TranslateBodyRequestDto(new Vector3Dto(10, 0, 0)));
+ transformResponse.EnsureSuccessStatusCode();
+
+ var originalTessellation = await _client.PostAsJsonAsync(
+ $"/api/v1/documents/{document.Data.DocumentId}/bodies/{box.Data.BodyId}/tessellate",
+ new TessellateRequestDto(null));
+ var duplicateTessellation = await _client.PostAsJsonAsync(
+ $"/api/v1/documents/{document.Data.DocumentId}/bodies/{duplicate.Data.BodyId}/tessellate",
+ new TessellateRequestDto(null));
+
+ var original = await originalTessellation.Content.ReadFromJsonAsync<ApiResponseDto<TessellationResponseDto>>();
+ var copied = await duplicateTessellation.Content.ReadFromJsonAsync<ApiResponseDto<TessellationResponseDto>>();
+
+ Assert.NotNull(original);
+ Assert.NotNull(copied);
+ var originalMaxX = original!.Data!.FacePatches.SelectMany(static patch => patch.Positions).Max(static p => p.X);
+ var copiedMaxX = copied!.Data!.FacePatches.SelectMany(static patch => patch.Positions).Max(static p => p.X);
+ Assert.True(copiedMaxX > originalMaxX + 8d);
+ }
+
+ [Fact]
+ public async Task PickResponse_ContainsOccurrenceIdentity()
+ {
+ var document = await CreateDocumentAsync("/api/v1/documents");
+ var box = await CreateBoxAsync("/api/v1/documents", document.Data!.DocumentId, 2, 2, 2);
+
+ var pickResponse = await _client.PostAsJsonAsync(
+ $"/api/v1/documents/{document.Data.DocumentId}/bodies/{box.Data!.BodyId}/pick",
+ new PickRequestDto(
+ new Point3Dto(0, 0, 5),
+ new Vector3Dto(0, 0, -1),
+ TessellationOptions: null,
+ PickOptions: new PickOptionsDto(NearestOnly: true, IncludeBackfaces: null, EdgeTolerance: null, SortTieTolerance: null, MaxDistance: null)));
+ pickResponse.EnsureSuccessStatusCode();
+
+ var pick = await pickResponse.Content.ReadFromJsonAsync<ApiResponseDto<PickResponseDto>>();
+ Assert.NotNull(pick);
+ Assert.True(pick!.Success);
+ Assert.Equal(box.Data.BodyId, pick.Data!.Hits[0].OccurrenceId);
+ }
+
private async Task<ApiResponseDto<DocumentCreateResponseDto>> CreateDocumentAsync(string routePrefix)
{
var response = await _client.PostAsJsonAsync(routePrefix, new DocumentCreateRequestDto("test"));
diff --git a/Aetheris.Server/Api/ApiMappings.cs b/Aetheris.Server/Api/ApiMappings.cs
index 238d9818..f14e77d4 100644
--- a/Aetheris.Server/Api/ApiMappings.cs
+++ b/Aetheris.Server/Api/ApiMappings.cs
@@ -66,11 +66,12 @@ public static class ApiMappings
e.Points.Select(point => ToPointDto(transform.Apply(point))).ToArray(),
e.IsClosed)).ToArray());
- public static PickResponseDto ToPickResponse(IReadOnlyList<PickHit> hits)
- => ToPickResponse(hits, Transform3D.Identity);
+ public static PickResponseDto ToPickResponse(IReadOnlyList<PickHit> hits, Guid occurrenceId)
+ => ToPickResponse(hits, Transform3D.Identity, occurrenceId);
- public static PickResponseDto ToPickResponse(IReadOnlyList<PickHit> hits, Transform3D transform)
+ public static PickResponseDto ToPickResponse(IReadOnlyList<PickHit> hits, Transform3D transform, Guid occurrenceId)
=> new(hits.Select(h => new PickHitDto(
+ occurrenceId,
h.T,
ToPointDto(transform.Apply(h.Point)),
h.Normal is null ? null : ToVectorDto(transform.Apply(h.Normal.Value.ToVector())),
diff --git a/Aetheris.Server/Api/KernelEndpoints.cs b/Aetheris.Server/Api/KernelEndpoints.cs
index d8a15136..ff419bea 100644
--- a/Aetheris.Server/Api/KernelEndpoints.cs
+++ b/Aetheris.Server/Api/KernelEndpoints.cs
@@ -32,8 +32,22 @@ public static class KernelEndpoints
return ApiMappings.NotFound($"Document '{documentId}' was not found.", "documents.get");
}
- var bodyIds = document.SnapshotBodies().Keys.OrderBy(id => id).ToArray();
- return ApiMappings.Ok(new DocumentSummaryResponseDto(document.Id, document.Name, bodyIds.Length, bodyIds));
+ var definitions = document.SnapshotDefinitions();
+ var occurrences = document.SnapshotOccurrences().Values.OrderBy(o => o.OccurrenceId).ToArray();
+ var bodyIds = occurrences.Select(o => o.OccurrenceId).ToArray();
+ var occurrenceSummaries = occurrences.Select(o =>
+ {
+ var origin = o.Placement.Apply(new Point3D(0d, 0d, 0d));
+ return new BodyOccurrenceSummaryDto(o.OccurrenceId, o.DefinitionId, o.Name, new Vector3Dto(origin.X, origin.Y, origin.Z));
+ }).ToArray();
+
+ return ApiMappings.Ok(new DocumentSummaryResponseDto(
+ document.Id,
+ document.Name,
+ bodyIds.Length,
+ bodyIds,
+ definitions.Count,
+ occurrenceSummaries));
});
documents.MapPost("/{documentId:guid}/bodies/primitives/box", (Guid documentId, BoxCreateRequestDto request, KernelDocumentStore store) =>
@@ -180,6 +194,27 @@ public static class KernelEndpoints
return ApiMappings.Ok(CreateBodyResponse(document, kernel.Value));
}));
+ documents.MapPost("/{documentId:guid}/occurrences", (Guid documentId, CreateOccurrenceRequestDto request, KernelDocumentStore store) =>
+ WithDocument(store, documentId, document =>
+ {
+ if (request.SourceOccurrenceId is null && request.DefinitionId is null)
+ {
+ return ApiMappings.BadRequestFromMessage("Either SourceOccurrenceId or DefinitionId must be provided.", "documents.occurrences");
+ }
+
+ BodyOccurrence occurrence;
+ var created = request.SourceOccurrenceId is Guid sourceOccurrenceId
+ ? document.TryCreateOccurrenceFromOccurrence(sourceOccurrenceId, out occurrence, request.Name)
+ : document.TryCreateOccurrence(request.DefinitionId!.Value, out occurrence, request.Name);
+
+ if (!created)
+ {
+ return ApiMappings.NotFound("Referenced occurrence or definition was not found.", "documents.occurrences");
+ }
+
+ return ApiMappings.Ok(new OccurrenceCreatedResponseDto(documentId, occurrence.OccurrenceId, occurrence.DefinitionId, occurrence.Name));
+ }));
+
documents.MapPost("/{documentId:guid}/bodies/{bodyId:guid}/transform", (Guid documentId, Guid bodyId, TranslateBodyRequestDto request, KernelDocumentStore store) =>
WithDocument(store, documentId, document =>
{
@@ -193,11 +228,12 @@ public static class KernelEndpoints
return ApiMappings.NotFound($"Body '{bodyId}' was not found.", "documents.body");
}
- return ApiMappings.Ok(new BodyTransformedResponseDto(documentId, bodyId, request.Translation));
+ document.TryGetOccurrence(bodyId, out var occurrence);
+ return ApiMappings.Ok(new BodyTransformedResponseDto(documentId, bodyId, occurrence.DefinitionId, request.Translation));
}));
documents.MapPost("/{documentId:guid}/bodies/{bodyId:guid}/tessellate", (Guid documentId, Guid bodyId, TessellateRequestDto? request, KernelDocumentStore store) =>
- WithDocumentBody(store, documentId, bodyId, (document, body) =>
+ WithDocumentOccurrence(store, documentId, bodyId, (document, body) =>
{
var options = ApiMappings.BuildTessellationOptions(request?.Options);
var kernel = BrepDisplayTessellator.Tessellate(body, options);
@@ -215,7 +251,7 @@ public static class KernelEndpoints
}));
documents.MapPost("/{documentId:guid}/bodies/{bodyId:guid}/pick", (Guid documentId, Guid bodyId, PickRequestDto request, KernelDocumentStore store) =>
- WithDocumentBody(store, documentId, bodyId, (document, body) =>
+ WithDocumentOccurrence(store, documentId, bodyId, (document, body) =>
{
if (request.Direction is null)
{
@@ -246,10 +282,10 @@ public static class KernelEndpoints
if (document.TryGetBodyTransform(bodyId, out transform))
{
- return ApiMappings.Ok(ApiMappings.ToPickResponse(kernel.Value, transform));
+ return ApiMappings.Ok(ApiMappings.ToPickResponse(kernel.Value, transform, bodyId));
}
- return ApiMappings.Ok(ApiMappings.ToPickResponse(kernel.Value));
+ return ApiMappings.Ok(ApiMappings.ToPickResponse(kernel.Value, bodyId));
}));
}
@@ -263,7 +299,7 @@ public static class KernelEndpoints
return operation(document);
}
- private static IResult WithDocumentBody(KernelDocumentStore store, Guid documentId, Guid bodyId, Func<DocumentSession, BrepBody, IResult> operation)
+ private static IResult WithDocumentOccurrence(KernelDocumentStore store, Guid documentId, Guid bodyId, Func<DocumentSession, BrepBody, IResult> operation)
=> WithDocument(store, documentId, document =>
{
if (!document.TryGetBody(bodyId, out var body))
@@ -276,10 +312,11 @@ public static class KernelEndpoints
private static BodyCreatedResponseDto CreateBodyResponse(DocumentSession document, BrepBody body)
{
- var bodyId = document.AddBody(body);
+ var bodyIds = document.AddBody(body);
return new BodyCreatedResponseDto(
document.Id,
- bodyId,
+ bodyIds.OccurrenceId,
+ bodyIds.DefinitionId,
body.Topology.Faces.Count(),
body.Topology.Edges.Count(),
body.Topology.Vertices.Count());
diff --git a/Aetheris.Server/Contracts/ApiContracts.cs b/Aetheris.Server/Contracts/ApiContracts.cs
index 590af2ca..5429b994 100644
--- a/Aetheris.Server/Contracts/ApiContracts.cs
+++ b/Aetheris.Server/Contracts/ApiContracts.cs
@@ -8,9 +8,17 @@ public sealed record DocumentCreateRequestDto(string? Name);
public sealed record DocumentCreateResponseDto(Guid DocumentId, string? Name, bool Volatile);
-public sealed record DocumentSummaryResponseDto(Guid DocumentId, string? Name, int BodyCount, IReadOnlyList<Guid> BodyIds);
+public sealed record BodyOccurrenceSummaryDto(Guid OccurrenceId, Guid DefinitionId, string? Name, Vector3Dto Translation);
-public sealed record BodyCreatedResponseDto(Guid DocumentId, Guid BodyId, int FaceCount, int EdgeCount, int VertexCount);
+public sealed record DocumentSummaryResponseDto(
+ Guid DocumentId,
+ string? Name,
+ int BodyCount,
+ IReadOnlyList<Guid> BodyIds,
+ int DefinitionCount,
+ IReadOnlyList<BodyOccurrenceSummaryDto> Occurrences);
+
+public sealed record BodyCreatedResponseDto(Guid DocumentId, Guid BodyId, Guid DefinitionId, int FaceCount, int EdgeCount, int VertexCount);
public sealed record Point3Dto(double X, double Y, double Z);
@@ -26,7 +34,11 @@ public sealed record SphereCreateRequestDto(double Radius);
public sealed record TranslateBodyRequestDto(Vector3Dto Translation);
-public sealed record BodyTransformedResponseDto(Guid DocumentId, Guid BodyId, Vector3Dto AppliedTranslation);
+public sealed record BodyTransformedResponseDto(Guid DocumentId, Guid BodyId, Guid DefinitionId, Vector3Dto AppliedTranslation);
+
+public sealed record CreateOccurrenceRequestDto(Guid? SourceOccurrenceId, Guid? DefinitionId, string? Name);
+
+public sealed record OccurrenceCreatedResponseDto(Guid DocumentId, Guid BodyId, Guid DefinitionId, string? Name);
public sealed record ExtrudeRequestDto(
IReadOnlyList<ProfilePoint2Dto> Profile,
@@ -61,6 +73,7 @@ public sealed record PickRequestDto(Point3Dto Origin, Vector3Dto Direction, Tess
public sealed record PickResponseDto(IReadOnlyList<PickHitDto> Hits);
public sealed record PickHitDto(
+ Guid OccurrenceId,
double T,
Point3Dto Point,
Vector3Dto? Normal,
diff --git a/Aetheris.Server/Documents/DocumentSession.cs b/Aetheris.Server/Documents/DocumentSession.cs
index e0436e39..4d67f78b 100644
--- a/Aetheris.Server/Documents/DocumentSession.cs
+++ b/Aetheris.Server/Documents/DocumentSession.cs
@@ -5,8 +5,8 @@ namespace Aetheris.Server.Documents;
public sealed class DocumentSession
{
- private readonly Dictionary<Guid, BrepBody> _bodies = new();
- private readonly Dictionary<Guid, Transform3D> _bodyTransforms = new();
+ private readonly Dictionary<Guid, BrepBody> _definitions = new();
+ private readonly Dictionary<Guid, BodyOccurrence> _occurrences = new();
private readonly object _sync = new();
public DocumentSession(Guid id, string? name = null)
@@ -19,54 +19,97 @@ public sealed class DocumentSession
public string? Name { get; }
- public IReadOnlyDictionary<Guid, BrepBody> SnapshotBodies()
+ public IReadOnlyDictionary<Guid, BrepBody> SnapshotDefinitions()
{
lock (_sync)
{
- return _bodies.ToDictionary(static kvp => kvp.Key, static kvp => kvp.Value);
+ return _definitions.ToDictionary(static kvp => kvp.Key, static kvp => kvp.Value);
}
}
- public Guid AddBody(BrepBody body)
+ public IReadOnlyDictionary<Guid, BodyOccurrence> SnapshotOccurrences()
{
- var bodyId = Guid.NewGuid();
lock (_sync)
{
- _bodies[bodyId] = body;
- _bodyTransforms[bodyId] = Transform3D.Identity;
+ return _occurrences.ToDictionary(static kvp => kvp.Key, static kvp => kvp.Value);
}
+ }
- return bodyId;
+ public (Guid OccurrenceId, Guid DefinitionId) AddBody(BrepBody body, string? occurrenceName = null)
+ {
+ lock (_sync)
+ {
+ var definitionId = Guid.NewGuid();
+ var occurrenceId = Guid.NewGuid();
+ _definitions[definitionId] = body;
+ _occurrences[occurrenceId] = new BodyOccurrence(occurrenceId, definitionId, Transform3D.Identity, occurrenceName);
+ return (occurrenceId, definitionId);
+ }
}
- public bool TryGetBody(Guid bodyId, out BrepBody body)
+ public bool TryGetOccurrence(Guid occurrenceId, out BodyOccurrence occurrence)
{
lock (_sync)
{
- return _bodies.TryGetValue(bodyId, out body!);
+ return _occurrences.TryGetValue(occurrenceId, out occurrence);
}
}
- public bool ReplaceBody(Guid bodyId, BrepBody body)
+ public bool TryGetBody(Guid occurrenceId, out BrepBody body)
{
lock (_sync)
{
- if (!_bodies.ContainsKey(bodyId))
+ if (!_occurrences.TryGetValue(occurrenceId, out var occurrence))
{
+ body = null!;
return false;
}
- _bodies[bodyId] = body;
+ return _definitions.TryGetValue(occurrence.DefinitionId, out body!);
+ }
+ }
+
+ public bool TryCreateOccurrence(Guid definitionId, out BodyOccurrence occurrence, string? name = null)
+ {
+ lock (_sync)
+ {
+ if (!_definitions.ContainsKey(definitionId))
+ {
+ occurrence = default;
+ return false;
+ }
+
+ var occurrenceId = Guid.NewGuid();
+ occurrence = new BodyOccurrence(occurrenceId, definitionId, Transform3D.Identity, name);
+ _occurrences[occurrenceId] = occurrence;
return true;
}
}
- public bool TryGetBodyTransform(Guid bodyId, out Transform3D transform)
+ public bool TryCreateOccurrenceFromOccurrence(Guid sourceOccurrenceId, out BodyOccurrence occurrence, string? name = null)
{
lock (_sync)
{
- if (_bodyTransforms.TryGetValue(bodyId, out transform))
+ if (!_occurrences.TryGetValue(sourceOccurrenceId, out var source))
{
+ occurrence = default;
+ return false;
+ }
+
+ var occurrenceId = Guid.NewGuid();
+ occurrence = new BodyOccurrence(occurrenceId, source.DefinitionId, Transform3D.Identity, name);
+ _occurrences[occurrenceId] = occurrence;
+ return true;
+ }
+ }
+
+ public bool TryGetBodyTransform(Guid occurrenceId, out Transform3D transform)
+ {
+ lock (_sync)
+ {
+ if (_occurrences.TryGetValue(occurrenceId, out var occurrence))
+ {
+ transform = occurrence.Placement;
return true;
}
@@ -75,21 +118,22 @@ public sealed class DocumentSession
}
}
- public bool ApplyBodyTranslation(Guid bodyId, Vector3D translation, out Transform3D updatedTransform)
+ public bool ApplyBodyTranslation(Guid occurrenceId, Vector3D translation, out Transform3D updatedTransform)
{
lock (_sync)
{
- if (!_bodies.ContainsKey(bodyId))
+ if (!_occurrences.TryGetValue(occurrenceId, out var occurrence))
{
updatedTransform = Transform3D.Identity;
return false;
}
- var current = _bodyTransforms.GetValueOrDefault(bodyId, Transform3D.Identity);
var delta = Transform3D.CreateTranslation(translation);
- updatedTransform = delta * current;
- _bodyTransforms[bodyId] = updatedTransform;
+ updatedTransform = delta * occurrence.Placement;
+ _occurrences[occurrenceId] = occurrence with { Placement = updatedTransform };
return true;
}
}
}
+
+public readonly record struct BodyOccurrence(Guid OccurrenceId, Guid DefinitionId, Transform3D Placement, string? Name);
diff --git a/aetheris.client/src/App.tsx b/aetheris.client/src/App.tsx
index 66eeb24d..6101bcee 100644
--- a/aetheris.client/src/App.tsx
+++ b/aetheris.client/src/App.tsx
@@ -11,6 +11,7 @@ import {
translateBody,
type BooleanOperation,
type DiagnosticDto,
+ type BodyOccurrenceSummaryDto,
type PickHitDto,
type TessellationResponseDto,
} from './api/aetherisApi';
@@ -29,6 +30,7 @@ const BOOLEAN_OP_TO_API: Record<BooleanOperationUi, BooleanOperation> = {
function App() {
const [documentId, setDocumentId] = useState<string | null>(null);
const [bodyIds, setBodyIds] = useState<string[]>([]);
+ const [occurrences, setOccurrences] = useState<BodyOccurrenceSummaryDto[]>([]);
const [activeBodyId, setActiveBodyId] = useState<string | null>(null);
const [tessellation, setTessellation] = useState<TessellationResponseDto | null>(null);
const [status, setStatus] = useState<RequestStatus>('idle');
@@ -76,6 +78,7 @@ function App() {
const selected = targetBodyId ?? (summary.bodyIds.includes(activeBodyId ?? '') ? activeBodyId : summary.bodyIds[0] ?? null);
setBodyIds(summary.bodyIds);
+ setOccurrences(summary.occurrences ?? []);
setActiveBodyId(selected ?? null);
if (selected) {
@@ -92,6 +95,7 @@ function App() {
setDocumentId(created.documentId);
setBodyIds([]);
setActiveBodyId(null);
+ setOccurrences([]);
setTessellation(null);
setPickStatus('idle');
setPickMessage('Click in the viewport to run nearest-hit pick.');
@@ -163,7 +167,7 @@ function App() {
await translateBody(documentId, activeBodyId, { x, y, z });
await refreshSummaryAndActiveTessellation(activeBodyId);
setPickStatus('idle');
- setPickMessage('Body translated. Click in viewport to refresh nearest hit.');
+ setPickMessage('Occurrence translated. Click in viewport to refresh nearest hit.');
setPickDiagnostics([]);
setPickHits([]);
});
@@ -199,14 +203,14 @@ function App() {
if (!booleanTargetBodyId || !booleanToolBodyId) {
setStatus('error');
- setStatusMessage('Boolean operation requires both target and tool bodies.');
+ setStatusMessage('Boolean operation requires both target and tool occurrences.');
setDiagnostics([]);
return;
}
if (booleanTargetBodyId === booleanToolBodyId) {
setStatus('error');
- setStatusMessage('Boolean target and tool must be different bodies.');
+ setStatusMessage('Boolean target and tool must be different occurrences.');
setDiagnostics([]);
return;
}
@@ -255,7 +259,7 @@ function App() {
setPickHits(pickResponse.hits);
setPickMessage(pickResponse.hits.length === 0
? 'No hit for current click ray.'
- : `Picked ${pickResponse.hits[0].entityKind} (nearest hit on active body).`);
+ : `Picked ${pickResponse.hits[0].entityKind} on occurrence ${pickResponse.hits[0].occurrenceId}.`);
} catch (error) {
const apiError = error instanceof ApiError
? error
@@ -314,19 +318,24 @@ function App() {
<section>
<h3>Body List</h3>
- {bodyIds.length === 0 ? <p>No bodies in document.</p> : (
+ {bodyIds.length === 0 ? <p>No occurrences in document.</p> : (
<ul>
- {bodyIds.map((bodyId) => (
- <li key={bodyId}>
+ {bodyIds.map((bodyId) => {
+ const occurrence = occurrences.find((item) => item.occurrenceId === bodyId);
+ const label = occurrence
+ ? `${bodyId} (def ${occurrence.definitionId.slice(0, 8)}, t=[${occurrence.translation.x.toFixed(2)}, ${occurrence.translation.y.toFixed(2)}, ${occurrence.translation.z.toFixed(2)}])`
+ : bodyId;
+
+ return <li key={bodyId}>
<button
type="button"
className={bodyId === activeBodyId ? 'active-row' : ''}
onClick={() => void handleSelectBody(bodyId)}
disabled={status === 'loading'}>
- {bodyId}
+ {label}
</button>
- </li>
- ))}
+ </li>;
+ })}
</ul>
)}
</section>
@@ -382,8 +391,8 @@ function App() {
<p><strong>Request status:</strong> {status}</p>
<p><strong>Message:</strong> {statusMessage}</p>
<p><strong>Document ID:</strong> {documentId ?? 'None'}</p>
- <p><strong>Active body ID:</strong> {activeBodyId ?? 'None'}</p>
- <p><strong>Body count:</strong> {bodyIds.length}</p>
+ <p><strong>Active occurrence ID:</strong> {activeBodyId ?? 'None'}</p>
+ <p><strong>Occurrence count:</strong> {bodyIds.length}</p>
<p><strong>Face patches:</strong> {tessellation?.facePatches.length ?? 0}</p>
<p><strong>Edge polylines:</strong> {tessellation?.edgePolylines.length ?? 0}</p>
<h3>Pick Diagnostics (active body only)</h3>
diff --git a/aetheris.client/src/__tests__/aetherisApi.test.ts b/aetheris.client/src/__tests__/aetherisApi.test.ts
index 43ff55bc..e4d9ac19 100644
--- a/aetheris.client/src/__tests__/aetherisApi.test.ts
+++ b/aetheris.client/src/__tests__/aetherisApi.test.ts
@@ -45,6 +45,7 @@ describe('pickBody', () => {
success: true,
data: {
hits: [{
+ occurrenceId: 'occ-1',
t: 1.25,
point: { x: 0, y: 0, z: 1 },
normal: { x: 0, y: 0, z: 1 },
@@ -84,6 +85,7 @@ describe('translateBody', () => {
data: {
documentId: 'doc-1',
bodyId: 'body-1',
+ definitionId: 'def-1',
appliedTranslation: { x: 1, y: 2, z: 3 },
},
diagnostics: [],
@@ -108,6 +110,7 @@ describe('executeBoolean', () => {
data: {
documentId: 'doc-1',
bodyId: 'result-body-1',
+ definitionId: 'result-def-1',
faceCount: 6,
edgeCount: 12,
vertexCount: 8,
diff --git a/aetheris.client/src/api/aetherisApi.ts b/aetheris.client/src/api/aetherisApi.ts
index db6139e4..dc4bf40d 100644
--- a/aetheris.client/src/api/aetherisApi.ts
+++ b/aetheris.client/src/api/aetherisApi.ts
@@ -17,16 +17,26 @@ export interface DocumentCreateResponseDto {
volatile: boolean;
}
+export interface BodyOccurrenceSummaryDto {
+ occurrenceId: string;
+ definitionId: string;
+ name: string | null;
+ translation: Vector3Dto;
+}
+
export interface DocumentSummaryResponseDto {
documentId: string;
name: string | null;
bodyCount: number;
bodyIds: string[];
+ definitionCount: number;
+ occurrences: BodyOccurrenceSummaryDto[];
}
export interface BodyCreatedResponseDto {
documentId: string;
bodyId: string;
+ definitionId: string;
faceCount: number;
edgeCount: number;
vertexCount: number;
@@ -35,6 +45,7 @@ export interface BodyCreatedResponseDto {
export interface BodyTransformedResponseDto {
documentId: string;
bodyId: string;
+ definitionId: string;
appliedTranslation: Vector3Dto;
}
@@ -92,6 +103,7 @@ export interface PickRequestDto {
}
export interface PickHitDto {
+ occurrenceId: string;
t: number;
point: Point3Dto;
normal: Vector3Dto | null;
diff --git a/docs/milestones.md b/docs/milestones.md
index 4930b810..db9814bb 100644
--- a/docs/milestones.md
+++ b/docs/milestones.md
@@ -226,3 +226,12 @@
- [x] Confirm deterministic STEP text behavior for the supported subset: M22 canonical export is byte-stable from the first cycle and remains stable across subsequent cycles.
- [x] Add a minimal generated golden/fixture corpus for supported subset and importer failure-path diagnostics (malformed input, unsupported entity, broken reference).
- [x] Keep AP242 support scope intentionally narrow (single-body/single-shell solids with planar faces and line edges); broader entity/schema coverage remains deferred.
+
+## M25 — Assembly/Document Model v1 (Lightweight and AP242-Aligned)
+
+- [x] Split document state into body definitions (shared `BrepBody`) and body occurrences (instance identity + per-occurrence placement).
+- [x] Preserve existing route shapes while reinterpreting `bodyId` as occurrence identity for tessellation/picking/transform and document summary flows.
+- [x] Add lightweight occurrence creation (`POST /api/v1/documents/{documentId}/occurrences`) so multiple occurrences can reference one shared definition.
+- [x] Extend pick/document contracts minimally with occurrence identity and occurrence summaries while preserving M17 envelope behavior.
+- [x] Keep React modeling UI compatible by listing/selecting occurrences and surfacing occurrence definition/translation context.
+- [x] Add focused occurrence semantics + placement regression coverage; defer full assembly constraints, mates/kinematics, and broad AP242 assembly IO.