Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Add canonical STEP 242 download action in frontend

Yuechen Li9ceb93f840bc
diff --git a/aetheris.client/src/App.tsx b/aetheris.client/src/App.tsx
index 4551928c..7e3656c7 100644
--- a/aetheris.client/src/App.tsx
+++ b/aetheris.client/src/App.tsx
@@ -197,12 +197,15 @@ function App() {
}, [activeBodyId, documentId, runAction]);
+ const activeOccurrence = useMemo(
+ () => occurrences.find((item) => item.occurrenceId === activeBodyId) ?? null,
+ [activeBodyId, occurrences]);
+
const handleExportActiveStep = useCallback(async () => {
if (!documentId || !activeBodyId) {
return;
}
- const activeOccurrence = occurrences.find((item) => item.occurrenceId === activeBodyId);
if (!activeOccurrence) {
setStatus('error');
setStatusMessage('Active occurrence metadata is unavailable for STEP export.');
@@ -215,7 +218,30 @@ function App() {
setStepExportText(exported.stepText);
setStepCanonicalHash(exported.canonicalHash);
});
- }, [activeBodyId, documentId, occurrences, runAction]);
+ }, [activeBodyId, activeOccurrence, documentId, runAction]);
+
+ const handleDownloadCanonicalStep = useCallback(async () => {
+ if (!documentId || !activeOccurrence) {
+ return;
+ }
+
+ await runAction('Download canonical STEP 242', async () => {
+ const exported = await exportDefinitionStep(documentId, activeOccurrence.definitionId);
+ const blob = new Blob([exported.stepText], { type: 'application/step; charset=utf-8' });
+ const objectUrl = URL.createObjectURL(blob);
+
+ try {
+ const anchor = document.createElement('a');
+ anchor.href = objectUrl;
+ anchor.download = `aetheris-${activeOccurrence.definitionId}.step`;
+ document.body.appendChild(anchor);
+ anchor.click();
+ document.body.removeChild(anchor);
+ } finally {
+ URL.revokeObjectURL(objectUrl);
+ }
+ });
+ }, [activeOccurrence, documentId, runAction]);
const handleImportStep = useCallback(async () => {
if (!documentId || !stepImportFile) {
@@ -472,6 +498,9 @@ function App() {
<button type="button" onClick={() => void handleExportActiveStep()} disabled={!activeBodyId || status === 'loading'}>
Export Active (STEP)
</button>
+ <button type="button" onClick={() => void handleDownloadCanonicalStep()} disabled={!documentId || !activeOccurrence || status === 'loading'}>
+ Download Canonical 242
+ </button>
<label className="textarea-label">
Exported STEP
<textarea value={stepExportText} readOnly placeholder="Exported STEP text will appear here." rows={7} />
diff --git a/aetheris.client/src/__tests__/App.test.tsx b/aetheris.client/src/__tests__/App.test.tsx
index 6ef71c5b..53529c27 100644
--- a/aetheris.client/src/__tests__/App.test.tsx
+++ b/aetheris.client/src/__tests__/App.test.tsx
@@ -38,6 +38,14 @@ vi.mock('../viewer/ViewerViewport', () => ({
function setupDocumentApiMocks(): void {
apiMocks.createDocument.mockResolvedValue({ documentId: 'doc-1', name: 'Test', volatile: true });
+ apiMocks.createBox.mockResolvedValue({
+ documentId: 'doc-1',
+ bodyId: 'occ-2',
+ definitionId: 'def-2',
+ faceCount: 6,
+ edgeCount: 12,
+ vertexCount: 8,
+ });
apiMocks.getDocumentSummary.mockResolvedValue({
documentId: 'doc-1',
name: 'Test',
@@ -111,6 +119,56 @@ describe('App STEP file upload flow', () => {
await screen.findByText('hash-123');
});
+ it('downloads backend STEP text with deterministic filename without mutating hash state', async () => {
+ const createObjectUrlSpy = vi.spyOn(URL, 'createObjectURL').mockReturnValue('blob:download');
+ const revokeObjectUrlSpy = vi.spyOn(URL, 'revokeObjectURL').mockImplementation(() => undefined);
+ const anchorClickSpy = vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => undefined);
+ const appendSpy = vi.spyOn(document.body, 'appendChild');
+
+ apiMocks.exportDefinitionStep
+ .mockResolvedValueOnce({
+ documentId: 'doc-1',
+ definitionId: 'def-2',
+ stepText: 'ISO-10303-21;HEADER;ENDSEC;',
+ canonicalHash: 'hash-initial',
+ diagnostics: [],
+ })
+ .mockResolvedValueOnce({
+ documentId: 'doc-1',
+ definitionId: 'def-2',
+ stepText: 'ISO-10303-21;DATA;ENDSEC;',
+ canonicalHash: 'hash-after-download',
+ diagnostics: [],
+ });
+
+ render(<App />);
+
+ fireEvent.click(screen.getByRole('button', { name: 'Create Document' }));
+ await screen.findByText(/Create document complete/i);
+ fireEvent.click(screen.getByRole('button', { name: 'Create Box' }));
+ await screen.findByText(/Create box complete/i);
+
+ fireEvent.click(screen.getByRole('button', { name: 'Export Active (STEP)' }));
+ await screen.findByText('hash-initial');
+
+ fireEvent.click(screen.getByRole('button', { name: 'Download Canonical 242' }));
+
+ await waitFor(() => {
+ expect(apiMocks.exportDefinitionStep).toHaveBeenNthCalledWith(2, 'doc-1', 'def-2');
+ });
+
+ const blob = createObjectUrlSpy.mock.calls[0][0] as Blob;
+ expect(await blob.text()).toBe('ISO-10303-21;DATA;ENDSEC;');
+
+ const downloadAnchor = appendSpy.mock.calls.at(-1)?.[0] as HTMLAnchorElement;
+ expect(downloadAnchor.download).toBe('aetheris-def-2.step');
+ expect(anchorClickSpy).toHaveBeenCalledTimes(1);
+ expect(revokeObjectUrlSpy).toHaveBeenCalledWith('blob:download');
+
+ expect(screen.getByText('hash-initial')).toBeTruthy();
+ expect(screen.queryByText('hash-after-download')).toBeNull();
+ });
+
it('preserves ApiError diagnostics from import failure', async () => {
apiMocks.importStep.mockRejectedValue(new ApiError('Malformed STEP payload.', [{
code: 'ValidationFailed',
@@ -133,4 +191,25 @@ describe('App STEP file upload flow', () => {
await screen.findByText('Malformed STEP payload.');
await screen.findByText('[Error] ValidationFailed: Malformed STEP payload.');
});
+
+ it('preserves ApiError diagnostics from canonical download failure', async () => {
+ apiMocks.exportDefinitionStep.mockRejectedValue(new ApiError('Export failed.', [{
+ code: 'StepExportFailed',
+ severity: 'Error',
+ message: 'Export failed.',
+ source: 'step242.export',
+ }]));
+
+ render(<App />);
+
+ fireEvent.click(screen.getByRole('button', { name: 'Create Document' }));
+ await screen.findByText(/Create document complete/i);
+ fireEvent.click(screen.getByRole('button', { name: 'Create Box' }));
+ await screen.findByText(/Create box complete/i);
+
+ fireEvent.click(screen.getByRole('button', { name: 'Download Canonical 242' }));
+
+ await screen.findByText('Export failed.');
+ await screen.findByText('[Error] StepExportFailed: Export failed.');
+ });
});
diff --git a/docs/milestones.md b/docs/milestones.md
index 7fbd1f20..4bfa92e9 100644
--- a/docs/milestones.md
+++ b/docs/milestones.md
@@ -262,3 +262,10 @@
- [x] On successful import, auto-refresh summary, activate imported occurrence, tessellate it, and immediately refresh canonical hash via definition export.
- [x] Add frontend safeguards for empty/oversized files and display diagnostics without silent error swallowing.
- [x] Add frontend tests for file-selection state updates, import payload wiring, canonical-hash refresh trigger, and `ApiError` propagation.
+
+## M29 — Canonical STEP 242 Download (Frontend)
+
+- [x] Add a deterministic `Download Canonical 242` UI action that requests backend export for the active definition and downloads the returned STEP text without client-side mutation.
+- [x] Use deterministic file naming (`aetheris-{definitionId}.step`) with no timestamp/random suffixes.
+- [x] Keep backend canonical hash authoritative and visible in the inspector without extra state mutation during download.
+- [x] Add client tests covering export call wiring, downloaded Blob byte/text parity, deterministic filename behavior, canonical-hash stability, and `ApiError` propagation.