자재 개수에 따른 높이 조절

This commit is contained in:
dohyeons 2025-11-24 16:52:22 +09:00
parent b6eb66d9cb
commit 90b7c2b0f0
1 changed files with 42 additions and 3 deletions

View File

@ -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; if (!draggedTool) return;
const defaults = getToolDefaults(draggedTool); const defaults = getToolDefaults(draggedTool);
// Area는 바닥(y=0.05)에, 다른 객체는 중앙 정렬 // 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 데이터에서 드래그한 경우 해당 정보 사용 // 외부 DB 데이터에서 드래그한 경우 해당 정보 사용
let objectName = defaults.name || "새 객체"; let objectName = defaults.name || "새 객체";
@ -696,12 +696,51 @@ export default function DigitalTwinEditor({ layoutId, layoutName, onBack }: Digi
externalKey = draggedLocationData.LOCAKEY; 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 = { const newObject: PlacedObject = {
id: nextObjectId, id: nextObjectId,
type: draggedTool, type: draggedTool,
name: objectName, name: objectName,
position: { x, y: yPosition, z }, position: { x, y: yPosition, z },
size: defaults.size || { x: 5, y: 5, z: 5 }, size: objectSize,
color: defaults.color || "#9ca3af", color: defaults.color || "#9ca3af",
areaKey, areaKey,
locaKey, locaKey,