diff --git a/src/hooks/option/useCanvasSetting.js b/src/hooks/option/useCanvasSetting.js index 072a2987..d6cc0e2b 100644 --- a/src/hooks/option/useCanvasSetting.js +++ b/src/hooks/option/useCanvasSetting.js @@ -179,7 +179,7 @@ export function useCanvasSetting(executeEffect = true) { layout: ['ROOF_ID_SLATE', 'ROOF_ID_SINGLE'].includes(item.roofMatlCd) ? ROOF_MATERIAL_LAYOUT.STAIRS : ROOF_MATERIAL_LAYOUT.PARALLEL, hajebichi: item.roofPchBase && parseInt(item.roofPchBase), pitch: item.inclBase ? parseInt(item.inclBase) : 4, - angle: getDegreeByChon(item.inclBase ? parseInt(item.inclBase): 4) //item.angle ? parseInt(item.angle) : 21.8, + angle: getDegreeByChon(item.inclBase ? parseInt(item.inclBase) : 4), //item.angle ? parseInt(item.angle) : 21.8, })) setRoofMaterials(roofLists) return roofLists @@ -231,8 +231,9 @@ export function useCanvasSetting(executeEffect = true) { setPolygonLinesActualSize(roof) }) changeCorridorDimensionText() + canvas.renderAll() } - }, [corridorDimension]) + }, [corridorDimension, canvasSetting]) useEffect(() => { if (!executeEffect) { diff --git a/src/hooks/useLine.js b/src/hooks/useLine.js index 3e1d72e6..0d678afa 100644 --- a/src/hooks/useLine.js +++ b/src/hooks/useLine.js @@ -168,6 +168,9 @@ export const useLine = () => { * @param pitch */ const setActualSize = (line, direction, pitch = globalPitch) => { + if (line.attributes.isCalculated) { + return + } const { x1, y1, x2, y2 } = line const isHorizontal = y1 === y2 @@ -209,7 +212,11 @@ export const useLine = () => { } } - line.attributes = { ...line.attributes, actualSize: Number(line.attributes.actualSize.toFixed(0)) } + line.attributes = { + ...line.attributes, + actualSize: Number(line.attributes.actualSize.toFixed(0)), + isCalculated: true, + } } return { diff --git a/src/hooks/usePolygon.js b/src/hooks/usePolygon.js index b862047a..cca65475 100644 --- a/src/hooks/usePolygon.js +++ b/src/hooks/usePolygon.js @@ -973,7 +973,6 @@ export const usePolygon = () => { }) canvas.renderAll() - /*polygonLines.forEach((line) => { line.set({ strokeWidth: 10 }) canvas.add(line) @@ -1043,16 +1042,25 @@ export const usePolygon = () => { name: 'newLine', }) + // 두 라인 중 큰 길이로 통일 + const length1 = Math.round(Math.hypot(newLine1.x1 - newLine1.x2, newLine1.y1 - newLine1.y2)) * 10 + const length2 = Math.round(Math.hypot(newLine2.x1 - newLine2.x2, newLine2.y1 - newLine2.y2)) * 10 + const maxLength = Math.max(length1, length2) + const unifiedPlaneSize = line.attributes.planeSize ?? maxLength + const unifiedActualSize = line.attributes.actualSize ?? maxLength + newLine1.attributes = { ...line.attributes, - planeSize: Math.round(Math.hypot(newLine1.x1 - newLine1.x2, newLine1.y1 - newLine1.y2)) * 10, - actualSize: Math.round(Math.hypot(newLine1.x1 - newLine1.x2, newLine1.y1 - newLine1.y2)) * 10, + planeSize: unifiedPlaneSize, + actualSize: unifiedActualSize, } + newLine1.length = maxLength newLine2.attributes = { ...line.attributes, - planeSize: Math.round(Math.hypot(newLine2.x1 - newLine2.x2, newLine2.y1 - newLine2.y2)) * 10, - actualSize: Math.round(Math.hypot(newLine2.x1 - newLine2.x2, newLine2.y1 - newLine2.y2)) * 10, + planeSize: unifiedPlaneSize, + actualSize: unifiedActualSize, } + newLine2.length = maxLength newLines.push(newLine1, newLine2) divideLines.splice(i, 1) // 기존 line 제거 @@ -1071,11 +1079,13 @@ export const usePolygon = () => { name: 'newLine', }) + const calcLength = Math.round(Math.hypot(newLine.x1 - newLine.x2, newLine.y1 - newLine.y2)) * 10 newLine.attributes = { ...line.attributes, - planeSize: Math.round(Math.hypot(newLine.x1 - newLine.x2, newLine.y1 - newLine.y2)) * 10, - actualSize: Math.round(Math.hypot(newLine.x1 - newLine.x2, newLine.y1 - newLine.y2)) * 10, + planeSize: line.attributes.planeSize ?? calcLength, + actualSize: line.attributes.actualSize ?? calcLength, } + newLine.length = line.attributes.planeSize ?? calcLength newLines.push(newLine) currentPoint = minDistancePoint @@ -1089,11 +1099,13 @@ export const usePolygon = () => { attributes: line.attributes, name: 'newLine', }) + const lastCalcLength = Math.round(Math.hypot(newLine.x1 - newLine.x2, newLine.y1 - newLine.y2)) * 10 newLine.attributes = { ...line.attributes, - planeSize: Math.round(Math.hypot(newLine.x1 - newLine.x2, newLine.y1 - newLine.y2)) * 10, - actualSize: Math.round(Math.hypot(newLine.x1 - newLine.x2, newLine.y1 - newLine.y2)) * 10, + planeSize: line.attributes.planeSize ?? lastCalcLength, + actualSize: line.attributes.actualSize ?? lastCalcLength, } + newLine.length = line.attributes.planeSize ?? lastCalcLength newLines.push(newLine) divideLines.splice(i, 1) // 기존 line 제거 @@ -1946,23 +1958,33 @@ export const usePolygon = () => { const line2 = allRoofLines[j] const diff = Math.abs(line1.length - line2.length) if (diff > 0 && diff <= 2) { - const minLength = Math.min(line1.length, line2.length) - line1.setLengthByValue(minLength * 10) - line2.setLengthByValue(minLength * 10) + const maxLength = Math.max(line1.length, line2.length) + line1.setLengthByValue(maxLength * 10) + line2.setLengthByValue(maxLength * 10) + // attributes도 통일 + const maxPlaneSize = Math.max(line1.attributes.planeSize || 0, line2.attributes.planeSize || 0) + const maxActualSize = Math.max(line1.attributes.actualSize || 0, line2.attributes.actualSize || 0) + line1.attributes.planeSize = maxPlaneSize + line1.attributes.actualSize = maxActualSize + line2.attributes.planeSize = maxPlaneSize + line2.attributes.actualSize = maxActualSize } } } polygon.lines.forEach((line, index) => { + if (line.attributes.isCalculated) { + return + } //text 와 planSize 및 actualSize가 안맞는 문제 - const nextText = polygon?.texts?.[index]?.text + /*const nextText = polygon?.texts?.[index]?.text const nextPlaneSize = Number(nextText) - if (nextText != null && nextText !== '' && Number.isFinite(nextPlaneSize) ) { - if(line.attributes.actualSize !== nextPlaneSize && line.attributes.planeSize !== nextPlaneSize) { + if (nextText != null && nextText !== '' && Number.isFinite(nextPlaneSize)) { + if (line.attributes.actualSize !== nextPlaneSize && line.attributes.planeSize !== nextPlaneSize) { line.attributes.planeSize = nextPlaneSize } + }*/ - } setActualSize(line, polygon.direction, +polygon.roofMaterial?.pitch) })