From 5b245a001c521259869f4502b3f7d9a0aaf9fa4b Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Mon, 22 Jun 2026 21:00:20 +0000 Subject: [PATCH] feat: enhance CADCanvas to support block creation from selected elements --- frontend/src/components/CADCanvas.jsx | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/frontend/src/components/CADCanvas.jsx b/frontend/src/components/CADCanvas.jsx index 905e435..17620e8 100644 --- a/frontend/src/components/CADCanvas.jsx +++ b/frontend/src/components/CADCanvas.jsx @@ -43,6 +43,37 @@ const CADCanvas = forwardRef(({ activeTool, setActiveTool, onCanvasReady }, ref) if (shape) fabricRef.current.add(shape); }); fabricRef.current.renderAll(); + }, + // Get selected elements for block creation + getSelectedElements: () => { + if (!fabricRef.current) return []; + const activeObject = fabricRef.current.getActiveObject(); + if (!activeObject) return []; + + // If it's a group, return all objects in the group + if (activeObject.type === 'group') { + return activeObject.getObjects().map(obj => ({ + id: obj.id || Date.now() + Math.random(), + type: obj.type, + ...obj.toObject(['id', 'type', 'left', 'top', 'width', 'height', 'radius', 'x1', 'y1', 'x2', 'y2', 'points', 'fill', 'stroke', 'strokeWidth']) + })); + } + + // If it's a single object, return it + return [{ + id: activeObject.id || Date.now() + Math.random(), + type: activeObject.type, + ...activeObject.toObject(['id', 'type', 'left', 'top', 'width', 'height', 'radius', 'x1', 'y1', 'x2', 'y2', 'points', 'fill', 'stroke', 'strokeWidth']) + }]; + }, + // Generate SVG data for selected elements + generateSvgData: () => { + if (!fabricRef.current) return ''; + const activeObject = fabricRef.current.getActiveObject(); + if (!activeObject) return ''; + + // Clone the object to avoid modifying the original + return activeObject.toSVG(); } }));