feat: rich product metadata extraction from STEP files
Extract volume, surface area, part count, assembly hierarchy, and complexity from STEP files via OCC B-rep analysis. Backend: - extract_rich_metadata() in step_processor.py: computes per-part volume (BRepGProp), surface area, triangle/vertex count, assembly depth, instance count, complexity score, largest part identification - cad_metadata JSONB column on Product model (DB migration) - Auto-populated during STEP processing (non-fatal, 10s timeout) - Also stored in cad_files.mesh_attributes["rich_metadata"] - Batch re-extract endpoint: POST /admin/settings/reextract-rich-metadata AI Agent: - search_products returns part_count, volume_cm3, complexity, largest_part - query_database tool description documents cad_metadata schema Frontend: - ProductDetail page: CAD Metadata section with stat cards (parts, volume, surface area, complexity, triangles, assembly depth) - Admin System Tools: "Re-extract Rich Metadata" button for backfill Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -179,6 +179,14 @@ export default function AdminPage() {
|
||||
onError: (e: any) => toast.error(e.response?.data?.detail || 'Failed'),
|
||||
})
|
||||
|
||||
const reextractRichMetadataMut = useMutation({
|
||||
mutationFn: () => api.post('/admin/settings/reextract-rich-metadata'),
|
||||
onSuccess: (res) => {
|
||||
toast.success(res.data.message || 'Rich metadata re-extraction queued')
|
||||
},
|
||||
onError: (e: any) => toast.error(e.response?.data?.detail || 'Failed'),
|
||||
})
|
||||
|
||||
const cleanupOrphanedCadMut = useMutation({
|
||||
mutationFn: () => api.post('/admin/settings/cleanup-orphaned-cad-files'),
|
||||
onSuccess: (res) => {
|
||||
@@ -1228,6 +1236,21 @@ export default function AdminPage() {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card p-5">
|
||||
<h3 className="text-sm font-semibold text-content mb-1">Re-extract Rich Metadata</h3>
|
||||
<p className="text-xs text-content-muted mb-3">Re-compute volume, surface area, complexity for all products with STEP files.</p>
|
||||
<div className="space-y-2">
|
||||
<button
|
||||
onClick={() => reextractRichMetadataMut.mutate()}
|
||||
disabled={reextractRichMetadataMut.isPending}
|
||||
className="btn-secondary text-sm w-full justify-start"
|
||||
>
|
||||
<RefreshCw size={14} className={reextractRichMetadataMut.isPending ? 'animate-spin' : ''} />
|
||||
{reextractRichMetadataMut.isPending ? 'Queueing...' : 'Re-extract Rich Metadata'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -626,6 +626,54 @@ export default function ProductDetailPage() {
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
{product.cad_metadata && (() => {
|
||||
const meta = product.cad_metadata as any
|
||||
return (
|
||||
<div className="col-span-2 mt-2 pt-3 border-t border-border-light">
|
||||
<label className="block text-xs text-content-muted mb-2 flex items-center gap-1">
|
||||
<Box size={11} /> CAD Metadata
|
||||
</label>
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
{meta.part_count != null && (
|
||||
<div className="text-center p-2 rounded-lg" style={{ backgroundColor: 'var(--color-bg-muted)' }}>
|
||||
<p className="text-lg font-semibold text-content">{meta.part_count}</p>
|
||||
<p className="text-xs text-content-muted">Parts</p>
|
||||
</div>
|
||||
)}
|
||||
{meta.total_volume_cm3 != null && (
|
||||
<div className="text-center p-2 rounded-lg" style={{ backgroundColor: 'var(--color-bg-muted)' }}>
|
||||
<p className="text-lg font-semibold text-content">{Number(meta.total_volume_cm3).toFixed(1)}</p>
|
||||
<p className="text-xs text-content-muted">Volume (cm³)</p>
|
||||
</div>
|
||||
)}
|
||||
{meta.total_surface_area_cm2 != null && (
|
||||
<div className="text-center p-2 rounded-lg" style={{ backgroundColor: 'var(--color-bg-muted)' }}>
|
||||
<p className="text-lg font-semibold text-content">{Number(meta.total_surface_area_cm2).toFixed(1)}</p>
|
||||
<p className="text-xs text-content-muted">Surface (cm²)</p>
|
||||
</div>
|
||||
)}
|
||||
{meta.complexity_score != null && (
|
||||
<div className="text-center p-2 rounded-lg" style={{ backgroundColor: 'var(--color-bg-muted)' }}>
|
||||
<p className="text-lg font-semibold text-content">{Number(meta.complexity_score).toFixed(2)}</p>
|
||||
<p className="text-xs text-content-muted">Complexity</p>
|
||||
</div>
|
||||
)}
|
||||
{meta.total_triangle_count != null && (
|
||||
<div className="text-center p-2 rounded-lg" style={{ backgroundColor: 'var(--color-bg-muted)' }}>
|
||||
<p className="text-lg font-semibold text-content">{Number(meta.total_triangle_count).toLocaleString()}</p>
|
||||
<p className="text-xs text-content-muted">Triangles</p>
|
||||
</div>
|
||||
)}
|
||||
{meta.assembly_depth != null && (
|
||||
<div className="text-center p-2 rounded-lg" style={{ backgroundColor: 'var(--color-bg-muted)' }}>
|
||||
<p className="text-lg font-semibold text-content">{meta.assembly_depth}</p>
|
||||
<p className="text-xs text-content-muted">Assembly Depth</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})()}
|
||||
</div>
|
||||
|
||||
{editMode && isPrivileged && (
|
||||
|
||||
Reference in New Issue
Block a user