From 90b7c2b0f0fc2f4dfa7fb9807fdf94c3e98dd860 Mon Sep 17 00:00:00 2001 From: dohyeons Date: Mon, 24 Nov 2025 16:52:22 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9E=90=EC=9E=AC=20=EA=B0=9C=EC=88=98?= =?UTF-8?q?=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EB=86=92=EC=9D=B4=20=EC=A1=B0?= =?UTF-8?q?=EC=A0=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../widgets/yard-3d/DigitalTwinEditor.tsx | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/frontend/components/admin/dashboard/widgets/yard-3d/DigitalTwinEditor.tsx b/frontend/components/admin/dashboard/widgets/yard-3d/DigitalTwinEditor.tsx index 88e844d3..3a8975c8 100644 --- a/frontend/components/admin/dashboard/widgets/yard-3d/DigitalTwinEditor.tsx +++ b/frontend/components/admin/dashboard/widgets/yard-3d/DigitalTwinEditor.tsx @@ -656,13 +656,13 @@ export default function DigitalTwinEditor({ layoutId, layoutName, onBack }: Digi }; // 캔버스에 드롭 - const handleCanvasDrop = (x: number, z: number) => { + const handleCanvasDrop = async (x: number, z: number) => { if (!draggedTool) return; const defaults = getToolDefaults(draggedTool); // Area는 바닥(y=0.05)에, 다른 객체는 중앙 정렬 - const yPosition = draggedTool === "area" ? 0.05 : (defaults.size?.y || 1) / 2; + let yPosition = draggedTool === "area" ? 0.05 : (defaults.size?.y || 1) / 2; // 외부 DB 데이터에서 드래그한 경우 해당 정보 사용 let objectName = defaults.name || "새 객체"; @@ -696,12 +696,51 @@ export default function DigitalTwinEditor({ layoutId, layoutName, onBack }: Digi externalKey = draggedLocationData.LOCAKEY; } + // 기본 크기 설정 + let objectSize = defaults.size || { x: 5, y: 5, z: 5 }; + + // Location 배치 시 자재 개수에 따라 높이 자동 설정 + if ( + (draggedTool === "location-bed" || + draggedTool === "location-stp" || + draggedTool === "location-temp" || + draggedTool === "location-dest") && + locaKey && + selectedDbConnection && + hierarchyConfig?.material + ) { + try { + // 해당 Location의 자재 개수 조회 + const countsResponse = await getMaterialCounts(selectedDbConnection, hierarchyConfig.material.tableName, [ + locaKey, + ]); + + if (countsResponse.success && countsResponse.data && countsResponse.data.length > 0) { + const materialCount = countsResponse.data[0].count; + + // 자재 개수에 비례해서 높이(Y축) 설정 (최소 5, 최대 30) + // 자재 1개 = 높이 5, 자재 10개 = 높이 15, 자재 50개 = 높이 30 + const calculatedHeight = Math.min(30, Math.max(5, 5 + materialCount * 0.5)); + + objectSize = { + ...objectSize, + y: calculatedHeight, // Y축이 높이! + }; + + // 높이가 높아진 만큼 Y 위치도 올려서 바닥을 뚫지 않게 조정 + yPosition = calculatedHeight / 2; + } + } catch (error) { + console.error("자재 개수 조회 실패, 기본 높이 사용:", error); + } + } + const newObject: PlacedObject = { id: nextObjectId, type: draggedTool, name: objectName, position: { x, y: yPosition, z }, - size: defaults.size || { x: 5, y: 5, z: 5 }, + size: objectSize, color: defaults.color || "#9ca3af", areaKey, locaKey,