import { useState, useRef } from 'react'; import { useConnectionStore } from '../../store/connectionStore'; interface Position { x: number; y: number; } interface DraggableElements { [key: string]: Position; } export const ConnectionDiagram = () => { const { support, beam, angle, bolts, connectionType } = useConnectionStore(); const [draggedElement, setDraggedElement] = useState(null); const [elementPositions, setElementPositions] = useState({}); const [isLocked, setIsLocked] = useState(true); const svgRef = useRef(null); // Scaling const scale = 10; const boltSpacing = bolts.spacing * scale; const angleThickness = angle.thickness * scale; const edgeDistV = angle.edgeDistanceVertical * scale; const edgeDistH = angle.edgeDistanceHorizontal * scale; const beamGap = beam.gapFromSupport * scale; const angleLeg = angle.legOnSupport * scale; const boltRows = bolts.numberOfRows; const boltGroupHeight = (boltRows - 1) * boltSpacing; const totalConnectionHeight = edgeDistV * 2 + boltGroupHeight; const startY = 60; // Engineering Style Colors const colors = { support: '#40E0D0', // Turquoise/Cyan beam: '#00FF7F', // SpringGreen angle: '#FFFF00', // Yellow plate: '#FFA500', // Orange for single-plate tee: '#87CEEB', // SkyBlue for Tee bolt: '#FF0000', // Red line: '#000000' }; // Drag Logic const handleMouseDown = (elementId: string) => { if (!isLocked) setDraggedElement(elementId); }; const handleMouseMove = (e: React.MouseEvent) => { if (draggedElement && svgRef.current && !isLocked) { const svg = svgRef.current; const pt = svg.createSVGPoint(); pt.x = e.clientX; pt.y = e.clientY; const svgP = pt.matrixTransform(svg.getScreenCTM()?.inverse()); setElementPositions(prev => ({ ...prev, [draggedElement]: { x: svgP.x, y: svgP.y } })); } }; const handleMouseUp = () => setDraggedElement(null); const getPos = (id: string, def: Position) => elementPositions[id] || def; // Helper: Draggable Text const DraggableText = ({ id, x, y, children, fontSize = "11", fontWeight = "normal", textDecoration = "none" }: any) => { const pos = getPos(id, { x, y }); return ( { e.stopPropagation(); handleMouseDown(id); }} > {children} ); }; // Helper: Dimension Line const DimLine = ({ id, x1, y1, x2, y2, text, textPos, arrows = 'both' }: any) => { const p1 = getPos(`${id}-p1`, { x: x1, y: y1 }); const p2 = getPos(`${id}-p2`, { x: x2, y: y2 }); const tp = getPos(`${id}-text`, textPos); return ( { e.stopPropagation(); handleMouseDown(`${id}-text`); }}> {text} ); }; const renderFrontConnection = () => { switch (connectionType) { case 'double-angle': return ( ); case 'single-plate': return ; case 'tee': return ( ); case 'single-angle': default: return ; } }; return (
{!isLocked && Drag dimensions and labels to customize}
{/* --- FRONT VIEW --- */} FRONT VIEW {/* Support Column */} {/* Updated Default Position to Bottom (y=280) */} Support {support.designation} {/* Beam (Translucent) */} CL {beam.designation} {/* Connection */} {renderFrontConnection()} {/* Bolts */} {Array.from({ length: boltRows }).map((_, i) => ( ))} {/* Dimensions */} {Array.from({ length: boltRows - 1 }).map((_, i) => ( ))} {/* --- SIDE VIEW --- */} SIDE VIEW {/* Support Side */} {/* Updated Default Position to Left Outside (x=10) */} Support {support.designation} {/* Connection Side */} {/* Beam Side */} {/* Bolts Side */} {Array.from({ length: boltRows }).map((_, i) => ( ))} {/* Dimensions */} {/* --- TOP VIEW --- */}
TOP VIEW {/* Support Top */} Support {support.designation} {/* Angles/Plate Top */} {connectionType === 'double-angle' ? ( <> ) : ( )} {/* Beam Top */} {/* Dimensions */}
); };