Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Enhance STEP dropzone with schema-aware file state

Yuechen Li389b52823664
diff --git a/aetheris.client/src/App.css b/aetheris.client/src/App.css
index 612b3bf3..8cd7a520 100644
--- a/aetheris.client/src/App.css
+++ b/aetheris.client/src/App.css
@@ -388,10 +388,6 @@ strong {
margin: 0;
}
-.tool-section--import label + p {
- margin-top: 2px;
-}
-
.tool-section--import .import-status-box {
margin-top: 4px;
}
@@ -411,8 +407,8 @@ strong {
min-height: 74px;
display: flex;
align-items: center;
- justify-content: center;
- text-align: center;
+ justify-content: flex-start;
+ text-align: left;
cursor: pointer;
padding: 10px 12px;
transition: border-color 120ms ease, background-color 120ms ease;
@@ -433,7 +429,29 @@ strong {
outline: none;
}
-.step-import-validation {
- color: #7f4a4a;
- font-size: 0.78rem;
+.step-dropzone__content {
+ width: 100%;
+ display: flex;
+ flex-direction: column;
+ align-items: flex-start;
+ gap: 3px;
+ text-align: left;
+}
+
+.step-dropzone__primary {
+ margin: 0;
+ font-size: 0.83rem;
+ color: hsl(var(--foreground));
+ font-weight: var(--ui-weight-emphasis);
+ max-width: 100%;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.step-dropzone__meta {
+ margin: 0;
+ font-size: 0.74rem;
+ letter-spacing: 0.02em;
+ color: hsl(var(--muted-foreground));
}
diff --git a/aetheris.client/src/App.tsx b/aetheris.client/src/App.tsx
index 41e34d9d..2321bd8c 100644
--- a/aetheris.client/src/App.tsx
+++ b/aetheris.client/src/App.tsx
@@ -64,9 +64,8 @@ function App() {
const [booleanOperation, setBooleanOperation] = useState<BooleanOperationUi>('Union');
const [stepExportText, setStepExportText] = useState('');
const [stepImportFile, setStepImportFile] = useState<File | null>(null);
+ const [stepDropzoneResetToken, setStepDropzoneResetToken] = useState(0);
const [stepCanonicalHash, setStepCanonicalHash] = useState<string | null>(null);
- const [stepImportSelectionMessage, setStepImportSelectionMessage] = useState('No file selected.');
- const [stepImportValidationMessage, setStepImportValidationMessage] = useState<string | null>(null);
const [copyHashMessage, setCopyHashMessage] = useState('');
const [isImporting, setIsImporting] = useState(false);
const [isRefreshing, setIsRefreshing] = useState(false);
@@ -88,9 +87,8 @@ function App() {
setBooleanOperation('Union');
setStepExportText('');
setStepImportFile(null);
+ setStepDropzoneResetToken((value) => value + 1);
setStepCanonicalHash(null);
- setStepImportSelectionMessage('No file selected.');
- setStepImportValidationMessage(null);
setCopyHashMessage('');
setDiagnostics([]);
setImportStatusMessage('Preparing workspace…');
@@ -373,14 +371,10 @@ function App() {
const handleStepFileAccepted = useCallback((selected: File) => {
setStepImportFile(selected);
- setStepImportSelectionMessage(`Selected file: ${selected.name} (${selected.size} bytes)`);
- setStepImportValidationMessage(null);
}, []);
- const handleStepFileValidationError = useCallback((message: string) => {
+ const handleStepFileValidationError = useCallback((_message: string) => {
setStepImportFile(null);
- setStepImportSelectionMessage('No file selected.');
- setStepImportValidationMessage(message);
}, []);
const handleUseActiveBodyAsTarget = useCallback(() => {
@@ -570,11 +564,10 @@ function App() {
<section className="tool-section tool-section--import">
<h2 className="section-title">Step Import</h2>
<StepImportDropzone
+ resetToken={stepDropzoneResetToken}
onFileAccepted={handleStepFileAccepted}
onValidationError={handleStepFileValidationError}
/>
- {stepImportValidationMessage ? <p className="step-import-validation">{stepImportValidationMessage}</p> : null}
- <p>{stepImportSelectionMessage}</p>
<Button type="button" onClick={() => void handleImportStep()} disabled={!canImportStep}>Import STEP 242</Button>
<div className={`import-status-box import-status-box--${importStatusTone}`}>
<p className="import-status-box__label"><strong>Import Status</strong></p>
diff --git a/aetheris.client/src/__tests__/App.test.tsx b/aetheris.client/src/__tests__/App.test.tsx
index f4a7117a..8a14d25c 100644
--- a/aetheris.client/src/__tests__/App.test.tsx
+++ b/aetheris.client/src/__tests__/App.test.tsx
@@ -115,6 +115,7 @@ describe('App STEP file upload flow', () => {
const fileInput = screen.getByTestId('step-import-file-input') as HTMLInputElement;
const file = new File(['ISO-10303-21;DATA;'], 'part.stp', { type: 'text/plain' });
fireEvent.change(fileInput, { target: { files: [file] } });
+ await screen.findByText('part.stp');
fireEvent.click(screen.getByRole('button', { name: 'Import STEP 242' }));
@@ -126,10 +127,14 @@ describe('App STEP file upload flow', () => {
await screen.findByText('Document: Ready');
const fileInput = screen.getByTestId('step-import-file-input') as HTMLInputElement;
- const file = new File(['ISO-10303-21;'], 'sample.step', { type: 'text/plain' });
+ const file = new File([
+ "ISO-10303-21;\nHEADER;\nFILE_SCHEMA(('AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF'));\nENDSEC;",
+ ], 'sample.step', { type: 'text/plain' });
fireEvent.change(fileInput, { target: { files: [file] } });
- expect(screen.getByText('Selected file: sample.step (13 bytes)')).toBeTruthy();
+ await screen.findByText('sample.step');
+ expect(screen.getByText('Detected schema: AP242')).toBeTruthy();
+ expect(screen.getByText('Compatibility: Supported')).toBeTruthy();
});
@@ -141,8 +146,8 @@ describe('App STEP file upload flow', () => {
const file = new File(['hello'], 'notes.txt', { type: 'text/plain' });
fireEvent.change(fileInput, { target: { files: [file] } });
+ await screen.findByText('File selection needs attention');
expect(screen.getByText('Unsupported file type. Please select a .step or .stp file.')).toBeTruthy();
- expect(screen.getByText('No file selected.')).toBeTruthy();
expect((screen.getByRole('button', { name: 'Import STEP 242' }) as HTMLButtonElement).disabled).toBe(true);
});
@@ -150,7 +155,7 @@ describe('App STEP file upload flow', () => {
render(<App />);
await screen.findByText('Document: Ready');
- const dropzone = screen.getByRole('button', { name: 'Drop STEP file here or click to browse' });
+ const dropzone = screen.getByTestId('step-import-dropzone');
const file = new File(['ISO-10303-21;'], 'dragged.stp', { type: 'text/plain' });
fireEvent.drop(dropzone, {
dataTransfer: {
@@ -158,7 +163,43 @@ describe('App STEP file upload flow', () => {
},
});
- expect(screen.getByText('Selected file: dragged.stp (13 bytes)')).toBeTruthy();
+ await screen.findByText('dragged.stp');
+ });
+
+ it('maps AP214/AP203 schemas to Experimental compatibility', async () => {
+ render(<App />);
+ await screen.findByText('Document: Ready');
+
+ const fileInput = screen.getByTestId('step-import-file-input') as HTMLInputElement;
+ const ap214 = new File([
+ "ISO-10303-21;\nHEADER;\nFILE_SCHEMA(('AUTOMOTIVE_DESIGN_CC2'));\nENDSEC;",
+ ], 'ap214.step', { type: 'text/plain' });
+ fireEvent.change(fileInput, { target: { files: [ap214] } });
+
+ await screen.findByText('Detected schema: AP214');
+ expect(screen.getByText('Compatibility: Experimental')).toBeTruthy();
+
+ const ap203 = new File([
+ "ISO-10303-21;\nHEADER;\nFILE_SCHEMA(('CONFIG_CONTROL_DESIGN'));\nENDSEC;",
+ ], 'ap203.step', { type: 'text/plain' });
+ fireEvent.change(fileInput, { target: { files: [ap203] } });
+
+ await screen.findByText('Detected schema: AP203');
+ expect(screen.getByText('Compatibility: Experimental')).toBeTruthy();
+ });
+
+ it('falls back to unknown schema when FILE_SCHEMA is unrecognized', async () => {
+ render(<App />);
+ await screen.findByText('Document: Ready');
+
+ const fileInput = screen.getByTestId('step-import-file-input') as HTMLInputElement;
+ const unknown = new File([
+ "ISO-10303-21;\nHEADER;\nFILE_SCHEMA(('SOME_CUSTOM_SCHEMA'));\nENDSEC;",
+ ], 'unknown.step', { type: 'text/plain' });
+ fireEvent.change(fileInput, { target: { files: [unknown] } });
+
+ await screen.findByText('Detected schema: Unknown');
+ expect(screen.getByText('Compatibility: Not verified')).toBeTruthy();
});
it('calls importStep with file contents and refreshes canonical hash', async () => {
@@ -183,6 +224,7 @@ describe('App STEP file upload flow', () => {
const fileInput = screen.getByTestId('step-import-file-input') as HTMLInputElement;
const file = new File(['ISO-10303-21;DATA;'], 'part.stp', { type: 'text/plain' });
fireEvent.change(fileInput, { target: { files: [file] } });
+ await screen.findByText('part.stp');
fireEvent.click(screen.getByRole('button', { name: 'Import STEP 242' }));
@@ -258,6 +300,7 @@ describe('App STEP file upload flow', () => {
const fileInput = screen.getByTestId('step-import-file-input') as HTMLInputElement;
const file = new File(['BAD'], 'bad.step', { type: 'text/plain' });
fireEvent.change(fileInput, { target: { files: [file] } });
+ await screen.findByText('bad.step');
fireEvent.click(screen.getByRole('button', { name: 'Import STEP 242' }));
@@ -298,7 +341,7 @@ describe('App STEP file upload flow', () => {
const file = new File(['ISO-10303-21;DATA;'], 'part.stp', { type: 'text/plain' });
fireEvent.change(fileInput, { target: { files: [file] } });
- expect(screen.getByText('Selected file: part.stp (18 bytes)')).toBeTruthy();
+ await screen.findByText('part.stp');
expect((screen.getByRole('button', { name: 'Import STEP 242' }) as HTMLButtonElement).disabled).toBe(true);
resolveCreate({ documentId: 'doc-1', name: 'Test', volatile: true });
@@ -316,11 +359,11 @@ describe('App STEP file upload flow', () => {
const fileInput = screen.getByTestId('step-import-file-input') as HTMLInputElement;
const file = new File(['ISO-10303-21;'], 'sample.step', { type: 'text/plain' });
fireEvent.change(fileInput, { target: { files: [file] } });
- expect(screen.getByText(/Selected file: sample.step \(\d+ bytes\)/)).toBeTruthy();
+ await screen.findByText('sample.step');
fireEvent.click(screen.getByRole('button', { name: 'New Document' }));
- await screen.findByText('No file selected.');
+ await screen.findByText('Drop STEP file here or click to browse');
expect(screen.getByText('Document: Ready')).toBeTruthy();
expect(screen.getByText('Ready. Select a file to import.')).toBeTruthy();
expect(apiMocks.createDocument).toHaveBeenCalledTimes(2);
diff --git a/aetheris.client/src/components/StepImportDropzone.tsx b/aetheris.client/src/components/StepImportDropzone.tsx
index b0aa05d4..16d77ce4 100644
--- a/aetheris.client/src/components/StepImportDropzone.tsx
+++ b/aetheris.client/src/components/StepImportDropzone.tsx
@@ -1,11 +1,29 @@
-import { useCallback, useMemo, useRef, useState, type DragEvent } from 'react';
+import { useCallback, useEffect, useMemo, useRef, useState, type DragEvent } from 'react';
import { z } from 'zod';
+type StepSchemaFamily = 'AP203' | 'AP214' | 'AP242' | 'Unknown';
+type StepCompatibility = 'Supported' | 'Experimental' | 'Not verified';
+
+type StepFileMetadata = {
+ fileName: string;
+ size: number;
+ schemaFamily: StepSchemaFamily;
+ compatibility: StepCompatibility;
+};
+
type StepImportDropzoneProps = {
+ resetToken: number;
onFileAccepted: (file: File) => void;
onValidationError: (message: string) => void;
};
+const stepFileMetadataSchema = z.object({
+ fileName: z.string().min(1),
+ size: z.number().positive(),
+ schemaFamily: z.enum(['AP203', 'AP214', 'AP242', 'Unknown']),
+ compatibility: z.enum(['Supported', 'Experimental', 'Not verified']),
+});
+
const stepFileSelectionSchema = z
.array(z.instanceof(File))
.length(1, 'Please select a single STEP file.')
@@ -36,18 +54,132 @@ function fileListToArray(fileList: FileList | null): File[] {
return fileList ? Array.from(fileList) : [];
}
-export function StepImportDropzone({ onFileAccepted, onValidationError }: StepImportDropzoneProps) {
+function formatFileSize(bytes: number): string {
+ if (bytes < 1024) {
+ return `${bytes} bytes`;
+ }
+
+ const kib = bytes / 1024;
+ if (kib < 1024) {
+ return `${kib.toFixed(1)} KB`;
+ }
+
+ const mib = kib / 1024;
+ return `${mib.toFixed(2)} MB`;
+}
+
+function schemaToCompatibility(schemaFamily: StepSchemaFamily): StepCompatibility {
+ if (schemaFamily === 'AP242') {
+ return 'Supported';
+ }
+
+ if (schemaFamily === 'AP203' || schemaFamily === 'AP214') {
+ return 'Experimental';
+ }
+
+ return 'Not verified';
+}
+
+function normalizeStepSchema(token: string): StepSchemaFamily {
+ const normalized = token.trim().toUpperCase().replace(/[-\s]+/g, '_');
+ const compact = normalized.replace(/_/g, '');
+
+ if (normalized.includes('CONFIG_CONTROL_DESIGN') || compact.includes('AP203')) {
+ return 'AP203';
+ }
+
+ if (normalized.includes('AUTOMOTIVE_DESIGN') || compact.includes('AP214')) {
+ return 'AP214';
+ }
+
+ if (
+ compact.includes('AP242')
+ || normalized.includes('MANAGED_MODEL_BASED_3D_ENGINEERING')
+ || normalized.includes('MODEL_BASED_3D_ENGINEERING')
+ || normalized.includes('APPLIED_MODEL_BASED_3D_ENGINEERING')
+ ) {
+ return 'AP242';
+ }
+
+ return 'Unknown';
+}
+
+function detectStepSchemaFamily(stepHeaderText: string): StepSchemaFamily {
+ const schemaMatch = stepHeaderText.match(/FILE_SCHEMA\s*\(\s*\(([^)]*)\)\s*\)\s*;/i);
+ if (!schemaMatch?.[1]) {
+ return 'Unknown';
+ }
+
+ const schemaTokens = Array.from(schemaMatch[1].matchAll(/'([^']+)'/g), (match) => match[1]);
+ if (schemaTokens.length === 0) {
+ return 'Unknown';
+ }
+
+ for (const token of schemaTokens) {
+ const mapped = normalizeStepSchema(token);
+ if (mapped !== 'Unknown') {
+ return mapped;
+ }
+ }
+
+ return 'Unknown';
+}
+
+async function readStepHeader(file: File): Promise<string> {
+ const headerSliceSize = Math.min(file.size, 64 * 1024);
+ const headerChunk = file.slice(0, headerSliceSize);
+ return headerChunk.text();
+}
+
+export function StepImportDropzone({ resetToken, onFileAccepted, onValidationError }: StepImportDropzoneProps) {
const [isDragActive, setIsDragActive] = useState(false);
+ const [selectionMetadata, setSelectionMetadata] = useState<StepFileMetadata | null>(null);
+ const [selectionError, setSelectionError] = useState<string | null>(null);
const inputRef = useRef<HTMLInputElement | null>(null);
- const handleFiles = useCallback((files: File[]) => {
+ useEffect(() => {
+ setSelectionMetadata(null);
+ setSelectionError(null);
+ }, [resetToken]);
+
+ const handleFiles = useCallback(async (files: File[]) => {
const parsed = stepFileSelectionSchema.safeParse(files);
if (!parsed.success) {
- onValidationError(parsed.error.issues[0]?.message ?? 'Invalid STEP file selection.');
+ const message = parsed.error.issues[0]?.message ?? 'Invalid STEP file selection.';
+ setSelectionMetadata(null);
+ setSelectionError(message);
+ onValidationError(message);
+ return;
+ }
+
+ const file = parsed.data[0];
+
+ let schemaFamily: StepSchemaFamily = 'Unknown';
+ try {
+ const headerText = await readStepHeader(file);
+ schemaFamily = detectStepSchemaFamily(headerText);
+ } catch {
+ schemaFamily = 'Unknown';
+ }
+
+ const metadataResult = stepFileMetadataSchema.safeParse({
+ fileName: file.name,
+ size: file.size,
+ schemaFamily,
+ compatibility: schemaToCompatibility(schemaFamily),
+ });
+
+ if (!metadataResult.success) {
+ const message = metadataResult.error.issues[0]?.message ?? 'Unable to read STEP file metadata.';
+ setSelectionMetadata(null);
+ setSelectionError(message);
+ onValidationError(message);
return;
}
- onFileAccepted(parsed.data[0]);
+ setSelectionError(null);
+ setSelectionMetadata(metadataResult.data);
+ onFileAccepted(file);
}, [onFileAccepted, onValidationError]);
const handleBrowseClick = useCallback(() => {
@@ -68,7 +200,7 @@ export function StepImportDropzone({ onFileAccepted, onValidationError }: StepIm
const handleDrop = useCallback((event: DragEvent<HTMLDivElement>) => {
event.preventDefault();
setIsDragActive(false);
- handleFiles(fileListToArray(event.dataTransfer.files));
+ void handleFiles(fileListToArray(event.dataTransfer.files));
}, [handleFiles]);
const className = useMemo(
@@ -86,7 +218,7 @@ export function StepImportDropzone({ onFileAccepted, onValidationError }: StepIm
aria-label="STEP 242 File"
data-testid="step-import-file-input"
onChange={(event) => {
- handleFiles(fileListToArray(event.target.files));
+ void handleFiles(fileListToArray(event.target.files));
event.currentTarget.value = '';
}}
/>
@@ -102,9 +234,24 @@ export function StepImportDropzone({ onFileAccepted, onValidationError }: StepIm
}
}}
onDragOver={handleDragOver}
+ data-testid="step-import-dropzone"
onDragLeave={handleDragLeave}
onDrop={handleDrop}>
- <p>Drop STEP file here or click to browse</p>
+ {selectionError ? (
+ <div className="step-dropzone__content">
+ <p className="step-dropzone__primary">File selection needs attention</p>
+ <p className="step-dropzone__meta">{selectionError}</p>
+ </div>
+ ) : selectionMetadata ? (
+ <div className="step-dropzone__content">
+ <p className="step-dropzone__primary" title={selectionMetadata.fileName}>{selectionMetadata.fileName}</p>
+ <p className="step-dropzone__meta">Size: {formatFileSize(selectionMetadata.size)}</p>
+ <p className="step-dropzone__meta">Detected schema: {selectionMetadata.schemaFamily}</p>
+ <p className="step-dropzone__meta">Compatibility: {selectionMetadata.compatibility}</p>
+ </div>
+ ) : (
+ <p>Drop STEP file here or click to browse</p>
+ )}
</div>
</>
);