diff --git a/src/components/floor-plan/modal/circuitTrestle/CircuitTrestleSetting.jsx b/src/components/floor-plan/modal/circuitTrestle/CircuitTrestleSetting.jsx index adeb0300..842fa83c 100644 --- a/src/components/floor-plan/modal/circuitTrestle/CircuitTrestleSetting.jsx +++ b/src/components/floor-plan/modal/circuitTrestle/CircuitTrestleSetting.jsx @@ -337,7 +337,6 @@ export default function CircuitTrestleSetting({ id }) { const result = await apply() removeNotAllocationModules() - apply() } const removeNotAllocationModules = () => { diff --git a/src/hooks/module/useTrestle.js b/src/hooks/module/useTrestle.js index 083c24c3..6704adb3 100644 --- a/src/hooks/module/useTrestle.js +++ b/src/hooks/module/useTrestle.js @@ -41,6 +41,7 @@ export const useTrestle = () => { return } + const plvrYn = construction.plvrYn let moduleRowsTotCnt = 0 let isEaveBar = construction.setupCover let isSnowGuard = construction.setupSnowCover @@ -102,6 +103,14 @@ export const useTrestle = () => { leftExposedHalfTopModules.length > 0 || rightExposedHalfTopPoints.length > 0 + console.log('isChidory', isChidory) + + if (plvrYn === 'N' && isChidory) { + alert('치조불가공법입니다.') + clear() + throw new Error('치조불가공법입니다.') + } + surface.set({ isChidory: isChidory }) canvas @@ -210,6 +219,10 @@ export const useTrestle = () => { let findLeft = true let findRight = true + let leftFindModuleList = [module] + let rightFindModuleList = [module] + let centerFindModuleList = [module] + //우선 절반을 나눈 뒤 왼쪽부터 찾는다. while (hasNextModule) { //바로 위에 있는지 확인한다. @@ -218,6 +231,7 @@ export const useTrestle = () => { if (nextModule) { // 바로 위 모듈을 찾는다. leftRows++ + leftFindModuleList.push(nextModule) x = nextModule.x y = nextModule.y } else { @@ -233,6 +247,7 @@ export const useTrestle = () => { if (nextModule) { // 바로 위 모듈을 찾는다. leftRows++ + leftFindModuleList.push(nextModule) x = nextModule.x y = nextModule.y } else { @@ -253,6 +268,7 @@ export const useTrestle = () => { if (nextModule) { // 바로 위 모듈을 찾는다. rightRows++ + rightFindModuleList.push(nextModule) x = nextModule.x y = nextModule.y } else { @@ -268,6 +284,7 @@ export const useTrestle = () => { if (nextModule) { // 바로 위 모듈을 찾는다. rightRows++ + rightFindModuleList.push(nextModule) x = nextModule.x y = nextModule.y } else { @@ -287,6 +304,7 @@ export const useTrestle = () => { if (nextModule) { // 바로 위 모듈을 찾는다. + centerFindModuleList.push(nextModule) centerRows++ x = nextModule.x y = nextModule.y @@ -295,19 +313,77 @@ export const useTrestle = () => { } } + const leftModuleInfos = leftFindModuleList.map((module) => { + return { + moduleTpCd: module.moduleInfo.moduleTpCd, + } + }) + + const rightModuleInfos = rightFindModuleList.map((module) => { + return { + moduleTpCd: module.moduleInfo.moduleTpCd, + } + }) + + const centerModuleInfos = centerFindModuleList.map((module) => { + return { + moduleTpCd: module.moduleInfo.moduleTpCd, + } + }) + + const leftRowsInfo = moduleTransformData(leftModuleInfos) + const rightRowsInfo = moduleTransformData(rightModuleInfos) + const centerRowsInfo = moduleTransformData(centerModuleInfos) + // 모듈의 왼쪽 부터 그릴 랙 정보를 가져온다. const leftRacks = rackInfos.find((rack) => { - return rack.value.moduleRows === leftRows + if (leftRowsInfo.rowsInfo.length === 1) { + return ( + rack.value.moduleTpCd === leftRowsInfo.moduleTotalTp && + rack.value.moduleRows === leftRowsInfo.rowsInfo.reduce((acc, row) => acc + row.count, 0) + ) + } else { + return ( + rack.value.moduleTpCd === leftRowsInfo.moduleTotalTp && + rack.value.moduleRows === leftRowsInfo.rowsInfo.reduce((acc, row) => acc + row.count, 0) && + rack.value.moduleTpRows1 === leftRowsInfo.rowsInfo[0].count && + rack.value.moduleTpRows2 === leftRowsInfo.rowsInfo[1].count + ) + } })?.value.racks // 모듈의 오른쪽 부터 그릴 랙 정보를 가져온다. const rightRacks = rackInfos.find((rack) => { - return rack.value.moduleRows === rightRows + if (rightRowsInfo.rowsInfo.length === 1) { + return ( + rack.value.moduleTpCd === rightRowsInfo.moduleTotalTp && + rack.value.moduleRows === rightRowsInfo.rowsInfo.reduce((acc, row) => acc + row.count, 0) + ) + } else { + return ( + rack.value.moduleTpCd === rightRowsInfo.moduleTotalTp && + rack.value.moduleRows === rightRowsInfo.rowsInfo.reduce((acc, row) => acc + row.count, 0) && + rack.value.moduleTpRows1 === rightRowsInfo.rowsInfo[0].count && + rack.value.moduleTpRows2 === rightRowsInfo.rowsInfo[1].count + ) + } })?.value.racks // 해당 rack으로 그려준다. const centerRacks = rackInfos.find((rack) => { - return rack.value.moduleRows === centerRows + if (centerRowsInfo.rowsInfo.length === 1) { + return ( + rack.value.moduleTpCd === centerRowsInfo.moduleTotalTp && + rack.value.moduleRows === centerRowsInfo.rowsInfo.reduce((acc, row) => acc + row.count, 0) + ) + } else { + return ( + rack.value.moduleTpCd === centerRowsInfo.moduleTotalTp && + rack.value.moduleRows === centerRowsInfo.rowsInfo.reduce((acc, row) => acc + row.count, 0) && + rack.value.moduleTpRows1 === centerRowsInfo.rowsInfo[0].count && + rack.value.moduleTpRows2 === centerRowsInfo.rowsInfo[1].count + ) + } })?.value.racks mostRowsModule = Math.max(leftRows, rightRows, centerRows, mostRowsModule) @@ -336,6 +412,7 @@ export const useTrestle = () => { let leftRows = 1 let hasNextModule = true let findLeft = true + let findModuleList = [module] //우선 절반을 나눈 뒤 왼쪽부터 찾는다. while (hasNextModule) { @@ -345,6 +422,7 @@ export const useTrestle = () => { if (nextModule) { // 바로 위 모듈을 찾는다. leftRows++ + findModuleList.push(nextModule) x = nextModule.x y = nextModule.y } else { @@ -371,6 +449,7 @@ export const useTrestle = () => { if (nextModule) { // 바로 위 모듈을 찾는다. leftRows++ + findModuleList.push(nextModule) x = nextModule.x y = nextModule.y } else { @@ -379,10 +458,30 @@ export const useTrestle = () => { } } + const leftModuleInfos = findModuleList.map((module) => { + return { + moduleTpCd: module.moduleInfo.moduleTpCd, + } + }) + const leftRowsInfo = moduleTransformData(leftModuleInfos) + // 모듈의 왼쪽 부터 그릴 랙 정보를 가져온다. const leftRacks = rackInfos.find((rack) => { - return rack.value.moduleRows === leftRows + if (leftRowsInfo.rowsInfo.length === 1) { + return ( + rack.value.moduleTpCd === leftRowsInfo.moduleTotalTp && + rack.value.moduleRows === leftRowsInfo.rowsInfo.reduce((acc, row) => acc + row.count, 0) + ) + } else { + return ( + rack.value.moduleTpCd === leftRowsInfo.moduleTotalTp && + rack.value.moduleRows === leftRowsInfo.rowsInfo.reduce((acc, row) => acc + row.count, 0) && + rack.value.moduleTpRows1 === leftRowsInfo.rowsInfo[0].count && + rack.value.moduleTpRows2 === leftRowsInfo.rowsInfo[1].count + ) + } })?.value.racks + mostRowsModule = Math.max(leftRows, mostRowsModule) if (rackYn === 'Y') { drawRacks(leftRacks, rackQty, rackIntvlPct, module, direction, 'L', rackYn) @@ -400,6 +499,7 @@ export const useTrestle = () => { let rightRows = 1 let hasNextModule = true let findRight = true + let findModuleList = [module] // 오른쪽 찾는다. while (hasNextModule) { @@ -409,6 +509,7 @@ export const useTrestle = () => { if (nextModule) { // 바로 위 모듈을 찾는다. rightRows++ + findModuleList.push(nextModule) x = nextModule.x y = nextModule.y } else { @@ -424,6 +525,7 @@ export const useTrestle = () => { if (nextModule) { // 바로 위 모듈을 찾는다. rightRows++ + findModuleList.push(nextModule) x = nextModule.x y = nextModule.y } else { @@ -432,11 +534,30 @@ export const useTrestle = () => { } } + const rightRowsInfos = findModuleList.map((module) => { + return { + moduleTpCd: module.moduleInfo.moduleTpCd, + } + }) + + const rightRowsInfo = moduleTransformData(rightRowsInfos) + // 모듈의 오른쪽 부터 그릴 랙 정보를 가져온다. const rightRacks = rackInfos.find((rack) => { - return rack.value.moduleRows === rightRows + if (rightRowsInfo.rowsInfo.length === 1) { + return ( + rack.value.moduleTpCd === rightRowsInfo.moduleTotalTp && + rack.value.moduleRows === rightRowsInfo.rowsInfo.reduce((acc, row) => acc + row.count, 0) + ) + } else { + return ( + rack.value.moduleTpCd === rightRowsInfo.moduleTotalTp && + rack.value.moduleRows === rightRowsInfo.rowsInfo.reduce((acc, row) => acc + row.count, 0) && + rack.value.moduleTpRows1 === rightRowsInfo.rowsInfo[0].count && + rack.value.moduleTpRows2 === rightRowsInfo.rowsInfo[1].count + ) + } })?.value.racks - mostRowsModule = Math.max(rightRows, mostRowsModule) // 해당 rack으로 그려준다. if (rackYn === 'Y') { @@ -462,10 +583,25 @@ export const useTrestle = () => { return setEstimateData() } catch (e) { + console.log(e) return false } } + //module Rack 정보를 얻기위한 데이터 가공 + function moduleTransformData(arr) { + let counts = {} + + arr.forEach((item) => { + counts[item.moduleTpCd] = (counts[item.moduleTpCd] || 0) + 1 + }) + + let moduleTotalTp = Object.keys(counts).join('') + let rowsInfo = Object.entries(counts).map(([moduleTpCd, count]) => ({ moduleTpCd, count })) + + return { moduleTotalTp, rowsInfo } + } + // itemList 조회 후 estimateParam에 저장 const setEstimateData = async () => { const surfaces = canvas.getObjects().filter((obj) => obj.name === POLYGON_TYPE.MODULE_SETUP_SURFACE) @@ -565,9 +701,11 @@ export const useTrestle = () => { } const findNextModule = (currentPoint, centerPoints, direction) => { - let { x, y, width, height, horizontal, vertical } = { ...currentPoint } - width = width + horizontal - height = height + vertical + let { x, y, horizontal, vertical } = { ...currentPoint } + let { widthArr, heightArr } = centerPoints[0] + + let width = widthArr.reduce((acc, num) => acc + num, 0) / widthArr.length + horizontal + let height = heightArr.reduce((acc, num) => acc + num, 0) / heightArr.length + vertical let maxX = 2 + horizontal * 3 let maxY = 2 + vertical * 3 @@ -596,7 +734,11 @@ export const useTrestle = () => { } const findNextLeftModule = (currentPoint, centerPoints, direction) => { - let { x, y, width, height, horizontal, vertical } = { ...currentPoint } + let { x, y, horizontal, vertical } = { ...currentPoint } + let { widthArr, heightArr } = centerPoints[0] + + let width = widthArr.reduce((acc, num) => acc + num, 0) / widthArr.length + horizontal + let height = heightArr.reduce((acc, num) => acc + num, 0) / heightArr.length + vertical let result let topLeftPoint @@ -631,9 +773,11 @@ export const useTrestle = () => { return result } const findNextRightModule = (currentPoint, centerPoints, direction) => { - let { x, y, width, height, horizontal, vertical } = { ...currentPoint } - width = width + horizontal - height = height + vertical + let { x, y, horizontal, vertical } = { ...currentPoint } + let { widthArr, heightArr } = centerPoints[0] + + let width = widthArr.reduce((acc, num) => acc + num, 0) / widthArr.length + horizontal + let height = heightArr.reduce((acc, num) => acc + num, 0) / heightArr.length + vertical let result let topRightPoint @@ -665,6 +809,9 @@ export const useTrestle = () => { } const drawRacks = (rackInfos, rackQty, rackIntvlPct, module, direction, l, rackYn) => { + if (!rackInfos) { + return + } const { width, height, left, top, lastX, lastY, surfaceId } = module const surface = canvas.getObjects().find((obj) => obj.id === surfaceId) const roof = canvas.getObjects().find((obj) => obj.id === surface.parentId) @@ -762,7 +909,7 @@ export const useTrestle = () => { name: 'smartRack', stroke: 'red', strokeWidth: 4, - selectable: false, + selectable: true, shadow: { color: 'black', // Outline color blur: 10, @@ -774,17 +921,18 @@ export const useTrestle = () => { surfaceId: surface.id, supFitQty, supFitIntvlPct, - rackLen, + rackLen: rackLength, rackRowsCd, seq, smartRackId, rackId: itemId, direction: 'top', }) + startPointY -= rackLength + 8 canvas.add(rack) canvas.renderAll() } else if (setRackTpCd === 'INTVL') { - startPointY -= rackLength + 8 + startPointY -= rackLength } }) } else { @@ -844,13 +992,14 @@ export const useTrestle = () => { surfaceId: surface.id, supFitQty, supFitIntvlPct, - rackLen, + rackLen: rackLength, rackRowsCd, seq, smartRackId, rackId: itemId, direction: 'left', }) + startPointX -= rackLength + 8 canvas.add(rack) canvas.renderAll() } else if (setRackTpCd === 'INTVL') { @@ -873,7 +1022,7 @@ export const useTrestle = () => { selectable: false, supFitQty, supFitIntvlPct, - rackLen, + rackLen: rackLength, rackYn, rackRowsCd, rackId: itemId, @@ -913,17 +1062,18 @@ export const useTrestle = () => { surfaceId: surface.id, supFitQty, supFitIntvlPct, - rackLen, + rackLen: rackLength, rackRowsCd, seq, smartRackId, rackId: itemId, direction: 'right', }) + startPointX += rackLength + 8 canvas.add(rack) canvas.renderAll() } else if (setRackTpCd === 'INTVL') { - startPointX += rackLength + 8 + startPointX += rackLength } }) } else { @@ -989,8 +1139,9 @@ export const useTrestle = () => { }) canvas.add(rack) canvas.renderAll() - } else if (setRackTpCd === 'INTVL') { startPointY += rackLength + 8 + } else if (setRackTpCd === 'INTVL') { + startPointY += rackLength } }) } else { @@ -1043,17 +1194,16 @@ export const useTrestle = () => { canvas.renderAll() racks.forEach((rack) => { - const { x1, y1, x2, y2, direction, supFitQty, supFitIntvlPct, rackLen } = rack + const { x1, y1, x2, y2, direction, supFitQty, supFitIntvlPct, rackLen, name } = rack const bracketLength = 10 if (direction === 'top') { const result = getBracketPoints(supFitQty, supFitIntvlPct) - result.forEach((percent) => { const bracket = new fabric.Rect({ left: x2 - bracketLength / 3, - top: y2 + (rackLen / 10) * percent, + top: name === 'smartRack' ? y2 + rackLen * percent : y2 + (rackLen / 10) * percent, fill: 'green', name: 'bracket', parentId: rack.parentId, @@ -1071,7 +1221,7 @@ export const useTrestle = () => { result.forEach((percent) => { const bracket = new fabric.Rect({ - left: x2 + (rackLen / 10) * percent, + left: name === 'smartRack' ? x2 + rackLen * percent : x2 + (rackLen / 10) * percent, top: y2 - bracketLength / 3, fill: 'green', name: 'bracket', @@ -1090,7 +1240,7 @@ export const useTrestle = () => { result.forEach((percent) => { const bracket = new fabric.Rect({ - left: x2 - (rackLen / 10) * percent, + left: name === 'smartRack' ? x2 - rackLen * percent : x2 - (rackLen / 10) * percent, top: y2 - bracketLength / 3, fill: 'green', parentId: rack.parentId, @@ -1110,7 +1260,7 @@ export const useTrestle = () => { result.forEach((percent) => { const bracket = new fabric.Rect({ left: x2 - bracketLength / 3, - top: y2 - (rackLen / 10) * percent, + top: name === 'smartRack' ? y2 - rackLen * percent : y2 - (rackLen / 10) * percent, fill: 'green', name: 'bracket', parentId: rack.parentId, @@ -1337,8 +1487,49 @@ export const useTrestle = () => { return points.slice(0, 2) } - const calculateForApi = (moduleSurface) => { + const getCenterPoints = (moduleSurface) => { const centerPoints = [] + let widthArr = [] + let heightArr = [] + const modules = moduleSurface.modules + modules.forEach((module, index) => { + module.tempIndex = index + const { x, y } = module.getCenterPoint() + const { width, height } = { ...module } + widthArr.push(width) + heightArr.push(height) + centerPoints.push({ x, y, width: Math.floor(width), height: Math.floor(height), index, moduleInfo: module.moduleInfo }) + }) + + //widthArr 중복 제거 1이상 차이가 나지 않으면 같은 너비로 간주 + widthArr = removeCloseValues(Array.from(new Set(widthArr))) + heightArr = removeCloseValues(Array.from(new Set(heightArr))) + + centerPoints.forEach((centerPoint, index) => { + centerPoint.widthArr = [...widthArr] + + centerPoint.heightArr = [...heightArr] + }) + + function removeCloseValues(arr, threshold = 1) { + arr.sort((a, b) => a - b) // 배열을 정렬 + + let result = [] + + for (let i = 0; i < arr.length; i++) { + if (i === 0 || Math.abs(arr[i] - arr[i - 1]) >= threshold) { + result.push(arr[i]) + } + } + + return result + } + + return centerPoints + } + + const calculateForApi = (moduleSurface) => { + const centerPoints = getCenterPoints(moduleSurface) const direction = moduleSurface.direction const modules = moduleSurface.modules @@ -1350,12 +1541,6 @@ export const useTrestle = () => { const maxX = 2 + horizontal * 3 const maxY = 2 + vertical * 3 - modules.forEach((module, index) => { - module.tempIndex = index - const { x, y } = module.getCenterPoint() - const { width, height } = { ...module } - centerPoints.push({ x, y, width: Math.floor(width), height: Math.floor(height), index }) - }) if (centerPoints.length === 0) return @@ -1382,7 +1567,7 @@ export const useTrestle = () => { let rightExposedHalfTopPoints = [] centerPoints.forEach((centerPoint, index) => { - let { x, y, width, height } = { ...centerPoint } + let { x, y, width, height, widthArr, heightArr } = { ...centerPoint } // centerPoints중에 현재 centerPoint와 x값이 같고, y값이 y-height값과 같은 centerPoint가 있는지 확인 let bottomCell let bottomLeftPoint @@ -1392,28 +1577,29 @@ export const useTrestle = () => { switch (direction) { case 'south': - width = width + horizontal - height = height + vertical + //widthArr의 값을 전부 더한 후 widthArr의 길이로 나누어 평균값을 구한다. + width = widthArr.reduce((acc, num) => acc + num, 0) / widthArr.length + horizontal + height = heightArr.reduce((acc, num) => acc + num, 0) / heightArr.length + vertical bottomCell = centerPoints.filter((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y + height)) < maxY) bottomLeftPoint = { x: x - width / 2, y: y + height } bottomRightPoint = { x: x + width / 2, y: y + height } break case 'north': - width = width + horizontal - height = height + vertical + width = widthArr.reduce((acc, num) => acc + num, 0) / widthArr.length + horizontal + height = heightArr.reduce((acc, num) => acc + num, 0) / heightArr.length + vertical bottomCell = centerPoints.filter((centerPoint) => Math.abs(centerPoint.x - x) < maxX && Math.abs(centerPoint.y - (y - height)) < maxY) bottomLeftPoint = { x: x + width / 2, y: y - height } bottomRightPoint = { x: x - width / 2, y: y - height } break case 'east': bottomCell = centerPoints.filter((centerPoint) => Math.abs(centerPoint.x - (x + width)) < maxX && Math.abs(centerPoint.y - y) < maxY) - width = width + horizontal + width = widthArr.reduce((acc, num) => acc + num, 0) / widthArr.length + horizontal bottomLeftPoint = { x: x + width, y: y + height / 2 } bottomRightPoint = { x: x + width, y: y - height / 2 } break case 'west': bottomCell = centerPoints.filter((centerPoint) => Math.abs(centerPoint.x - (x - width)) < maxX && Math.abs(centerPoint.y - y) < maxY) - width = width + horizontal + width = widthArr.reduce((acc, num) => acc + num, 0) / widthArr.length + horizontal bottomLeftPoint = { x: x - width, y: y - height / 2 } bottomRightPoint = { x: x - width, y: y + height / 2 } break @@ -1870,16 +2056,16 @@ export const useTrestle = () => { const { direction, modules } = surface let { rackYn, cvrPlvrYn, moduleIntvlHor, moduleIntvlVer, rackQty, lessSupFitQty } = surface.trestleDetail - const centerPoints = modules.map((module) => { - return module.getCenterPoint() - }) + const centerPoints = getCenterPoints(surface) const horizontal = ['south', 'north'].includes(direction) ? moduleIntvlHor : moduleIntvlVer const vertical = ['south', 'north'].includes(direction) ? moduleIntvlVer : moduleIntvlHor const maxX = 2 + horizontal * 3 const maxY = 2 + vertical * 3 - let { width, height } = { ...module } + let { widthArr, heightArr } = centerPoints[0] + let width = widthArr.reduce((acc, num) => acc + num, 0) / widthArr.length + let height = heightArr.reduce((acc, num) => acc + num, 0) / heightArr.length let { x, y } = { ...module.getCenterPoint() } let halfBottomLeftPoint