레이아웃 설치

This commit is contained in:
yjnoh 2025-03-14 18:35:13 +09:00
parent f9766a7d21
commit ae2171c633
3 changed files with 214 additions and 167 deletions

View File

@ -25,9 +25,7 @@ export default function BasicSetting({ id, pos = { x: 50, y: 230 } }) {
const { getMessage } = useMessage() const { getMessage } = useMessage()
const { closePopup } = usePopup() const { closePopup } = usePopup()
const [tabNum, setTabNum] = useState(1) const [tabNum, setTabNum] = useState(1)
const canvasSetting = useRecoilValue(canvasSettingState)
const orientationRef = useRef(null) const orientationRef = useRef(null)
const { initEvent } = useEvent()
const [isManualModuleSetup, setIsManualModuleSetup] = useRecoilState(isManualModuleSetupState) const [isManualModuleSetup, setIsManualModuleSetup] = useRecoilState(isManualModuleSetupState)
const [isManualModuleLayoutSetup, setIsManualModuleLayoutSetup] = useRecoilState(isManualModuleLayoutSetupState) const [isManualModuleLayoutSetup, setIsManualModuleLayoutSetup] = useRecoilState(isManualModuleLayoutSetupState)
@ -40,12 +38,9 @@ export default function BasicSetting({ id, pos = { x: 50, y: 230 } }) {
const [isClosePopup, setIsClosePopup] = useState({ close: false, id: 0 }) const [isClosePopup, setIsClosePopup] = useState({ close: false, id: 0 })
const [checkedModules, setCheckedModules] = useRecoilState(checkedModuleState) const [checkedModules, setCheckedModules] = useRecoilState(checkedModuleState)
const [manualSetupMode, setManualSetupMode] = useState('manualSetup') const [manualSetupMode, setManualSetupMode] = useState('')
const [layoutSetup, setLayoutSetup] = useState({ const [layoutSetup, setLayoutSetup] = useState([{}])
col: 1,
row: 1,
})
// const { initEvent } = useContext(EventContext) // const { initEvent } = useContext(EventContext)
const { manualModuleSetup, autoModuleSetup, manualFlatroofModuleSetup, autoFlatroofModuleSetup, manualModuleLayoutSetup } = const { manualModuleSetup, autoModuleSetup, manualFlatroofModuleSetup, autoFlatroofModuleSetup, manualModuleLayoutSetup } =
@ -98,12 +93,10 @@ export default function BasicSetting({ id, pos = { x: 50, y: 230 } }) {
const placementRef = { const placementRef = {
isChidori: useRef('false'), isChidori: useRef('false'),
setupLocation: useRef('eaves'), setupLocation: useRef('eaves'),
layoutSetup: useRef({
col: 1,
row: 1,
}),
} }
const layoutSetupRef = useRef([])
const placementFlatRef = { const placementFlatRef = {
setupLocation: useRef('south'), setupLocation: useRef('south'),
} }
@ -114,6 +107,7 @@ export default function BasicSetting({ id, pos = { x: 50, y: 230 } }) {
} }
const handleManualModuleLayoutSetup = () => { const handleManualModuleLayoutSetup = () => {
console.log('asdfasdkljfhaskjdhfakjsdhkfjh')
setManualSetupMode(`manualLayoutSetup_${!isManualModuleLayoutSetup}`) setManualSetupMode(`manualLayoutSetup_${!isManualModuleLayoutSetup}`)
setIsManualModuleLayoutSetup(!isManualModuleLayoutSetup) setIsManualModuleLayoutSetup(!isManualModuleLayoutSetup)
} }
@ -140,16 +134,21 @@ export default function BasicSetting({ id, pos = { x: 50, y: 230 } }) {
if (isManualModuleSetup) { if (isManualModuleSetup) {
setIsManualModuleSetup(false) setIsManualModuleSetup(false)
} }
if (isManualModuleLayoutSetup) {
setIsManualModuleLayoutSetup(false)
}
} }
setIsClosePopup({ close: true, id: id }) setIsClosePopup({ close: true, id: id })
} }
useEffect(() => { useEffect(() => {
console.log('asdfasdf', manualSetupMode)
if (basicSetting.roofSizeSet !== '3') { if (basicSetting.roofSizeSet !== '3') {
if (manualSetupMode.indexOf('manualSetup') > -1) { if (manualSetupMode.indexOf('manualSetup') > -1) {
manualModuleSetup(placementRef) manualModuleSetup(placementRef)
} else if (manualSetupMode.indexOf('manualLayoutSetup') > -1) { } else if (manualSetupMode.indexOf('manualLayoutSetup') > -1) {
manualModuleLayoutSetup(placementRef) manualModuleLayoutSetup(layoutSetupRef)
} }
} else { } else {
manualFlatroofModuleSetup(placementFlatRef) manualFlatroofModuleSetup(placementFlatRef)
@ -161,7 +160,7 @@ export default function BasicSetting({ id, pos = { x: 50, y: 230 } }) {
useEffect(() => { useEffect(() => {
if (isManualModuleLayoutSetup) { if (isManualModuleLayoutSetup) {
manualModuleLayoutSetup(placementRef) manualModuleLayoutSetup(layoutSetupRef)
} }
}, [layoutSetup]) }, [layoutSetup])
@ -183,7 +182,15 @@ export default function BasicSetting({ id, pos = { x: 50, y: 230 } }) {
{tabNum === 1 && <Orientation ref={orientationRef} tabNum={tabNum} setTabNum={setTabNum} />} {tabNum === 1 && <Orientation ref={orientationRef} tabNum={tabNum} setTabNum={setTabNum} />}
{/*배치면 초기설정 - 입력방법: 복시도 입력 || 실측값 입력*/} {/*배치면 초기설정 - 입력방법: 복시도 입력 || 실측값 입력*/}
{basicSetting.roofSizeSet && basicSetting.roofSizeSet != '3' && tabNum === 2 && <Module setTabNum={setTabNum} />} {basicSetting.roofSizeSet && basicSetting.roofSizeSet != '3' && tabNum === 2 && <Module setTabNum={setTabNum} />}
{basicSetting.roofSizeSet && basicSetting.roofSizeSet != '3' && tabNum === 3 && <Placement setTabNum={setTabNum} ref={placementRef} />} {basicSetting.roofSizeSet && basicSetting.roofSizeSet != '3' && tabNum === 3 && (
<Placement
setTabNum={setTabNum}
ref={placementRef}
layoutSetupRef={layoutSetupRef}
layoutSetup={layoutSetup}
setLayoutSetup={setLayoutSetup}
/>
)}
{/*배치면 초기설정 - 입력방법: 육지붕*/} {/*배치면 초기설정 - 입력방법: 육지붕*/}
{basicSetting.roofSizeSet && basicSetting.roofSizeSet == '3' && tabNum === 2 && <PitchModule setTabNum={setTabNum} />} {basicSetting.roofSizeSet && basicSetting.roofSizeSet == '3' && tabNum === 2 && <PitchModule setTabNum={setTabNum} />}

View File

@ -1,7 +1,7 @@
import { forwardRef, useEffect, useState } from 'react' import { forwardRef, useEffect, useState } from 'react'
import { useMessage } from '@/hooks/useMessage' import { useMessage } from '@/hooks/useMessage'
import { useModuleBasicSetting } from '@/hooks/module/useModuleBasicSetting' import { useModuleBasicSetting } from '@/hooks/module/useModuleBasicSetting'
import { checkedModuleState, currentCanvasPlanState, isManualModuleSetupState } from '@/store/canvasAtom' import { checkedModuleState, currentCanvasPlanState, isManualModuleLayoutSetupState, isManualModuleSetupState } from '@/store/canvasAtom'
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil' import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil'
import { moduleSelectionDataState, selectedModuleState } from '@/store/selectedModuleOptions' import { moduleSelectionDataState, selectedModuleState } from '@/store/selectedModuleOptions'
import { isObjectNotEmpty } from '@/util/common-utils' import { isObjectNotEmpty } from '@/util/common-utils'
@ -23,7 +23,9 @@ const Placement = forwardRef((props, refs) => {
const [isMultiModule, setIsMultiModule] = useState(false) const [isMultiModule, setIsMultiModule] = useState(false)
const [isManualModuleSetup, setIsManualModuleSetup] = useRecoilState(isManualModuleSetupState) //
const setIsManualModuleSetup = useSetRecoilState(isManualModuleSetupState)
const setIsManualModuleLayoutSetup = useSetRecoilState(isManualModuleLayoutSetupState)
// //
useEffect(() => { useEffect(() => {
@ -38,6 +40,7 @@ const Placement = forwardRef((props, refs) => {
return () => { return () => {
setIsManualModuleSetup(false) setIsManualModuleSetup(false)
setIsManualModuleLayoutSetup(false)
} }
}, []) }, [])
@ -56,6 +59,8 @@ const Placement = forwardRef((props, refs) => {
}) })
setSelectedItems(initCheckedModule) setSelectedItems(initCheckedModule)
setSelectedModules(moduleSelectionData.module) setSelectedModules(moduleSelectionData.module)
props.setLayoutSetup(moduleSelectionData.module.itemList.map((item) => ({ moduleId: item.itemId, col: 0, row: 0 })))
props.layoutSetupRef.current = moduleSelectionData.module.itemList.map((item) => ({ moduleId: item.itemId, col: 0, row: 0 }))
} }
// //
@ -111,9 +116,11 @@ const Placement = forwardRef((props, refs) => {
setSelectedItems({ ...selectedItems, [e.target.name]: e.target.checked }) setSelectedItems({ ...selectedItems, [e.target.name]: e.target.checked })
} }
const handleLayoutSetup = (e) => { const handleLayoutSetup = (e, itemId, index) => {
props.setLayoutSetup({ ...props.layoutSetup, [e.target.name]: Number(e.target.value) }) const newLayoutSetup = [...props.layoutSetup]
refs.layoutSetup.current = { ...props.layoutSetup, [e.target.name]: Number(e.target.value) } newLayoutSetup[index] = { ...newLayoutSetup[index], moduleId: itemId, [e.target.name]: Number(e.target.value) }
props.setLayoutSetup(newLayoutSetup)
props.layoutSetupRef.current[index] = { ...props.layoutSetupRef.current[index], moduleId: itemId, [e.target.name]: Number(e.target.value) }
} }
return ( return (
@ -162,6 +169,24 @@ const Placement = forwardRef((props, refs) => {
</div> </div>
</td> </td>
<td className="al-r">{item.wpOut}</td> <td className="al-r">{item.wpOut}</td>
<label htmlFor="ra06"></label>
<input
type="text"
className="input-origin block mr10"
name="col"
value={props.layoutSetup[index]?.col ?? 1}
defaultValue={1}
onChange={(e) => handleLayoutSetup(e, item.itemId, index)}
/>{' '}
×<label htmlFor="ra07"></label>
<input
type="text"
className="input-origin block"
name="row"
value={props.layoutSetup[index]?.row ?? 1}
defaultValue={1}
onChange={(e) => handleLayoutSetup(e, item.itemId, index)}
/>
</tr> </tr>
))} ))}
</tbody> </tbody>
@ -238,33 +263,6 @@ const Placement = forwardRef((props, refs) => {
</div> </div>
</div> </div>
</div> </div>
<div className="self-table-item">
<div className="self-item-th">레이아웃 입력</div>
<div className="self-item-td">
<div className="pop-form-radio">
<div className="d-check-radio pop">
<label htmlFor="ra06"></label>
<input
type="text"
className="input-origin block mr10"
name="col"
value={props.layoutSetup.col}
defaultValue={1}
onChange={handleLayoutSetup}
/>{' '}
×<label htmlFor="ra07"></label>
<input
type="text"
className="input-origin block"
name="row"
value={props.layoutSetup.row}
defaultValue={1}
onChange={handleLayoutSetup}
/>
</div>
</div>
</div>
</div>
</div> </div>
<div className="self-table-flx"> <div className="self-table-flx">
{/* <div className="d-check-box pop"> {/* <div className="d-check-box pop">

View File

@ -560,7 +560,7 @@ export function useModuleBasicSetting(tabNum) {
/** /**
* 스냅기능 * 스냅기능
*/ */
let snapDistance = flowDirection === 'south' || flowDirection === 'north' ? 70 : 40 let snapDistance = flowDirection === 'south' || flowDirection === 'north' ? 10 : 10
let trestleSnapDistance = 15 let trestleSnapDistance = 15
let intvHor = let intvHor =
@ -817,7 +817,7 @@ export function useModuleBasicSetting(tabNum) {
} }
} }
const manualModuleLayoutSetup = (placementRef) => { const manualModuleLayoutSetup = (layoutSetupRef) => {
if (isManualModuleSetup) { if (isManualModuleSetup) {
setIsManualModuleSetup(false) setIsManualModuleSetup(false)
} }
@ -831,8 +831,12 @@ export function useModuleBasicSetting(tabNum) {
return return
} }
if (checkedModule.length > 1) { const hasZeroLength = checkedModule.some((item) =>
swalFire({ text: getMessage('module.place.select.one.module') }) layoutSetupRef.current.some((layoutItem) => item.itemId === layoutItem.moduleId && (layoutItem.row === 0 || layoutItem.col === 0)),
)
if (hasZeroLength) {
swalFire({ text: getMessage('모듈의 열, 행을 입력해 주세요.') })
setIsManualModuleLayoutSetup(!isManualModuleLayoutSetup) setIsManualModuleLayoutSetup(!isManualModuleLayoutSetup)
return return
} }
@ -876,8 +880,8 @@ export function useModuleBasicSetting(tabNum) {
} }
if (moduleSetupSurfaces.length !== 0) { if (moduleSetupSurfaces.length !== 0) {
const col = placementRef.layoutSetup.current.col // const col = layoutSetupRef.current[0].col
const row = placementRef.layoutSetup.current.row // const row = layoutSetupRef.current[0].row
let tempModule let tempModule
let manualDrawModules = [] let manualDrawModules = []
@ -924,48 +928,48 @@ export function useModuleBasicSetting(tabNum) {
? moduleSetupSurfaces[i].trestleDetail.moduleIntvlVer / 10 ? moduleSetupSurfaces[i].trestleDetail.moduleIntvlVer / 10
: moduleSetupSurfaces[i].trestleDetail.moduleIntvlHor / 10 : moduleSetupSurfaces[i].trestleDetail.moduleIntvlHor / 10
let calcHalfWidth = (Number((width * col).toFixed(1)) + Number((intvHor * (col - 1)).toFixed(1))) / 2 // let calcHalfWidth = (Number((width * col).toFixed(1)) + Number((intvHor * (col - 1)).toFixed(1))) / 2
let calcHalfHeight = (Number((height * row).toFixed(1)) + Number((intvVer * (row - 1)).toFixed(1))) / 2 // let calcHalfHeight = (Number((height * row).toFixed(1)) + Number((intvVer * (row - 1)).toFixed(1))) / 2
//아래래 //아래래
let points = [ // let points = [
{
x: Number(mousePoint.x.toFixed(1)) - calcHalfWidth,
y: Number(mousePoint.y.toFixed(1)) - calcHalfHeight,
},
{
x: Number(mousePoint.x.toFixed(1)) - calcHalfWidth,
y: Number(mousePoint.y.toFixed(1)) + calcHalfHeight,
},
{
x: Number(mousePoint.x.toFixed(1)) + calcHalfWidth,
y: Number(mousePoint.y.toFixed(1)) + calcHalfHeight,
},
{
x: Number(mousePoint.x.toFixed(1)) + calcHalfWidth,
y: Number(mousePoint.y.toFixed(1)) - calcHalfHeight,
},
]
// const points = [
// { // {
// x: Number(mousePoint.x.toFixed(1)) + Number((width / 2).toFixed(1)), // x: Number(mousePoint.x.toFixed(1)) - calcHalfWidth,
// y: Number(mousePoint.y.toFixed(1)) - Number((height / 2).toFixed(1)), // y: Number(mousePoint.y.toFixed(1)) - calcHalfHeight,
// }, // },
// { // {
// x: Number(mousePoint.x.toFixed(1)) + Number((width / 2).toFixed(1)), // x: Number(mousePoint.x.toFixed(1)) - calcHalfWidth,
// y: Number(mousePoint.y.toFixed(1)) + Number((height / 2).toFixed(1)), // y: Number(mousePoint.y.toFixed(1)) + calcHalfHeight,
// }, // },
// { // {
// x: Number(mousePoint.x.toFixed(1)) - Number((width / 2).toFixed(1)), // x: Number(mousePoint.x.toFixed(1)) + calcHalfWidth,
// y: Number(mousePoint.y.toFixed(1)) - Number((height / 2).toFixed(1)), // y: Number(mousePoint.y.toFixed(1)) + calcHalfHeight,
// }, // },
// { // {
// x: Number(mousePoint.x.toFixed(1)) - Number((width / 2).toFixed(1)), // x: Number(mousePoint.x.toFixed(1)) + calcHalfWidth,
// y: Number(mousePoint.y.toFixed(1)) + Number((height / 2).toFixed(1)), // y: Number(mousePoint.y.toFixed(1)) - calcHalfHeight,
// }, // },
// ] // ]
const points = [
{
x: Number(mousePoint.x.toFixed(1)) + Number((width / 2).toFixed(1)),
y: Number(mousePoint.y.toFixed(1)) - Number((height / 2).toFixed(1)),
},
{
x: Number(mousePoint.x.toFixed(1)) + Number((width / 2).toFixed(1)),
y: Number(mousePoint.y.toFixed(1)) + Number((height / 2).toFixed(1)),
},
{
x: Number(mousePoint.x.toFixed(1)) - Number((width / 2).toFixed(1)),
y: Number(mousePoint.y.toFixed(1)) - Number((height / 2).toFixed(1)),
},
{
x: Number(mousePoint.x.toFixed(1)) - Number((width / 2).toFixed(1)),
y: Number(mousePoint.y.toFixed(1)) + Number((height / 2).toFixed(1)),
},
]
const turfPoints = coordToTurfPolygon(points) const turfPoints = coordToTurfPolygon(points)
if (turf.booleanWithin(turfPoints, turfPolygon)) { if (turf.booleanWithin(turfPoints, turfPolygon)) {
@ -979,14 +983,14 @@ export function useModuleBasicSetting(tabNum) {
stroke: 'black', stroke: 'black',
strokeWidth: 1, strokeWidth: 1,
strokeDashArray: [10, 5], strokeDashArray: [10, 5],
// width: Number(width.toFixed(1)), //작은버전 width: Number(width.toFixed(1)), //작은버전
// height: Number(height.toFixed(1)), //작은버전 height: Number(height.toFixed(1)), //작은버전
// left: Number(mousePoint.x.toFixed(1) - Number((width / 2).toFixed(1))), //작은버전 left: Number(mousePoint.x.toFixed(1) - Number((width / 2).toFixed(1))), //작은버전
// top: Number(mousePoint.y.toFixed(1) - Number((height / 2).toFixed(1))), //작은버전 top: Number(mousePoint.y.toFixed(1) - Number((height / 2).toFixed(1))), //작은버전
width: Number((width * col).toFixed(1)) + Number((intvHor * (col - 1)).toFixed(1)), //큰버전 // width: Number((width * col).toFixed(1)) + Number((intvHor * (col - 1)).toFixed(1)), //큰버전
height: Number((height * row).toFixed(1)) + Number((intvVer * (row - 1)).toFixed(1)), //큰버전 // height: Number((height * row).toFixed(1)) + Number((intvVer * (row - 1)).toFixed(1)), //큰버전
left: Number(mousePoint.x.toFixed(1)) - calcHalfWidth.toFixed(1), //큰버전 // left: Number(mousePoint.x.toFixed(1)) - calcHalfWidth.toFixed(1), //큰버전
top: Number(mousePoint.y.toFixed(1)) - calcHalfHeight.toFixed(1), //큰버전 // top: Number(mousePoint.y.toFixed(1)) - calcHalfHeight.toFixed(1), //큰버전
selectable: false, selectable: false,
lockMovementX: true, lockMovementX: true,
lockMovementY: true, lockMovementY: true,
@ -1027,60 +1031,60 @@ export function useModuleBasicSetting(tabNum) {
/** /**
* 미리 깔아놓은 셀이 있을때 셀에 흡착됨 * 미리 깔아놓은 셀이 있을때 셀에 흡착됨
*/ */
// if (manualDrawModules) { if (manualDrawModules) {
// manualDrawModules.forEach((cell) => { manualDrawModules.forEach((cell) => {
// const holdCellLeft = cell.left const holdCellLeft = cell.left
// const holdCellTop = cell.top const holdCellTop = cell.top
// const holdCellRight = holdCellLeft + Number(cell.width.toFixed(1)) const holdCellRight = holdCellLeft + Number(cell.width.toFixed(1))
// const holdCellBottom = holdCellTop + Number(cell.height.toFixed(1)) const holdCellBottom = holdCellTop + Number(cell.height.toFixed(1))
// const holdCellCenterX = holdCellLeft + Number((cell.width / 2).toFixed(1)) const holdCellCenterX = holdCellLeft + Number((cell.width / 2).toFixed(1))
// const holdCellCenterY = holdCellTop + Number((cell.height / 2).toFixed(1)) const holdCellCenterY = holdCellTop + Number((cell.height / 2).toFixed(1))
// //설치된 셀에 좌측에 스냅 //설치된 셀에 좌측에 스냅
// if (Math.abs(smallRight - holdCellLeft) < snapDistance) { if (Math.abs(smallRight - holdCellLeft) < snapDistance) {
// tempModule.left = holdCellLeft - width - intvHor tempModule.left = holdCellLeft - width - intvHor
// } }
// //설치된 셀에 우측에 스냅 //설치된 셀에 우측에 스냅
// if (Math.abs(smallLeft - holdCellRight) < snapDistance) { if (Math.abs(smallLeft - holdCellRight) < snapDistance) {
// tempModule.left = holdCellRight + intvHor tempModule.left = holdCellRight + intvHor
// } }
// //설치된 셀에 위쪽에 스냅 //설치된 셀에 위쪽에 스냅
// if (Math.abs(smallBottom - holdCellTop) < snapDistance) { if (Math.abs(smallBottom - holdCellTop) < snapDistance) {
// tempModule.top = holdCellTop - height - intvVer tempModule.top = holdCellTop - height - intvVer
// } }
// //설치된 셀에 밑쪽에 스냅 //설치된 셀에 밑쪽에 스냅
// if (Math.abs(smallTop - holdCellBottom) < snapDistance) { if (Math.abs(smallTop - holdCellBottom) < snapDistance) {
// tempModule.top = holdCellBottom + intvVer tempModule.top = holdCellBottom + intvVer
// } }
// //가운데 -> 가운데 //가운데 -> 가운데
// if (Math.abs(smallCenterX - holdCellCenterX) < snapDistance) { if (Math.abs(smallCenterX - holdCellCenterX) < snapDistance) {
// tempModule.left = holdCellCenterX - Number((width / 2).toFixed(1)) tempModule.left = holdCellCenterX - Number((width / 2).toFixed(1))
// } }
// //왼쪽 -> 가운데 //왼쪽 -> 가운데
// if (Math.abs(smallLeft - holdCellCenterX) < snapDistance) { if (Math.abs(smallLeft - holdCellCenterX) < snapDistance) {
// tempModule.left = holdCellCenterX tempModule.left = holdCellCenterX
// } }
// // 오른쪽 -> 가운데 // 오른쪽 -> 가운데
// if (Math.abs(smallRight - holdCellCenterX) < snapDistance) { if (Math.abs(smallRight - holdCellCenterX) < snapDistance) {
// tempModule.left = holdCellCenterX - width tempModule.left = holdCellCenterX - width
// } }
// //세로 가운데 -> 가운데 //세로 가운데 -> 가운데
// if (Math.abs(smallCenterY - holdCellCenterY) < snapDistance) { if (Math.abs(smallCenterY - holdCellCenterY) < snapDistance) {
// tempModule.top = holdCellCenterY - Number((height / 2).toFixed(1)) tempModule.top = holdCellCenterY - Number((height / 2).toFixed(1))
// } }
// // //위쪽 -> 가운데 // //위쪽 -> 가운데
// // if (Math.abs(smallTop - holdCellCenterY) < cellSnapDistance) { // if (Math.abs(smallTop - holdCellCenterY) < cellSnapDistance) {
// // tempModule.top = holdCellCenterY // tempModule.top = holdCellCenterY
// // } // }
// // //아랫쪽 -> 가운데 // //아랫쪽 -> 가운데
// // if (Math.abs(smallBottom - holdCellCenterY) < cellSnapDistance) { // if (Math.abs(smallBottom - holdCellCenterY) < cellSnapDistance) {
// // tempModule.top = holdCellCenterY - height // tempModule.top = holdCellCenterY - height
// // } // }
// }) })
// } }
// 위쪽 변에 스냅 // 위쪽 변에 스냅
if (Math.abs(smallTop - trestleTop) < trestleSnapDistance) { if (Math.abs(smallTop - trestleTop) < trestleSnapDistance) {
@ -1152,37 +1156,66 @@ export function useModuleBasicSetting(tabNum) {
if (!inside) return if (!inside) return
if (tempModule) { if (tempModule) {
let startX, startY let startX, startY
let installedLastHeightCoord = 0 //마지막으로 설치된 모듈의 좌표
console.log(tempModule)
//그려진 가이드 라인의 포인트를 기준으로 시작점을 만든다 //그려진 가이드 라인의 포인트를 기준으로 시작점을 만든다
if (flowDirection === 'south') { if (flowDirection === 'south') {
startX = toFixedWithoutRounding(tempModule.left, 1) startX = toFixedWithoutRounding(tempModule.left, 1)
startY = toFixedWithoutRounding(tempModule.top + tempModule.height, 1) startY = toFixedWithoutRounding(tempModule.top + tempModule.height, 1)
for (let i = 0; i < placementRef.layoutSetup.current.row; i++) { console.log('checkedModule', checkedModule)
let tempY = startY - i * height
let tempHeightMargin = i === 0 ? 0 : i * intvVer
for (let j = 0; j < placementRef.layoutSetup.current.col; j++) {
let tempX = startX + j * width
let tempWidthMargin = j === 0 ? 0 : j * intvHor
let rectPoints = [ checkedModule.forEach((module, index) => {
{ x: tempX + tempWidthMargin, y: tempY - height - tempHeightMargin }, moduleOptions.fill = module.color
{ x: tempX + tempWidthMargin, y: tempY - tempHeightMargin }, const moduleWidth = Number(module.longAxis) / 10
{ x: tempX + width + tempWidthMargin, y: tempY - tempHeightMargin }, const moduleHeight = Number(module.shortAxis) / 10
{ x: tempX + width + tempWidthMargin, y: tempY - height - tempHeightMargin },
]
// console.log('🚀 ~ addCanvasMouseEventListener ~ rectPoints:', rectPoints)
tempModule.set({ points: rectPoints }) let tmpWidth = flowDirection === 'south' || flowDirection === 'north' ? moduleWidth : moduleHeight
const tempTurfModule = polygonToTurfPolygon(tempModule) let tmpHeight = flowDirection === 'south' || flowDirection === 'north' ? moduleHeight : moduleWidth
tempModule.setCoords() //좌표 재정렬
if (turf.booleanContains(turfPolygon, tempTurfModule) || turf.booleanWithin(tempTurfModule, turfPolygon)) { width =
//마우스 클릭시 set으로 해당 위치에 셀을 넣음 canvasSetting.roofSizeSet == '1'
const isOverlap = manualDrawModules.some((module) => turf.booleanOverlap(tempTurfModule, polygonToTurfPolygon(module))) //겹치는지 확인 ? calculateVisibleModuleHeight(tmpWidth, tmpHeight, getDegreeByChon(moduleSetupSurfaces[i].roofMaterial.pitch), flowDirection)
if (!isOverlap) { .width
: tmpWidth
height =
canvasSetting.roofSizeSet == '1'
? calculateVisibleModuleHeight(tmpWidth, tmpHeight, getDegreeByChon(moduleSetupSurfaces[i].roofMaterial.pitch), flowDirection)
.height
: tmpHeight
const col = layoutSetupRef.current.filter((item) => item.moduleId === module.itemId)[0].col
const row = layoutSetupRef.current.filter((item) => item.moduleId === module.itemId)[0].row
for (let i = 0; i < row; i++) {
let tempY = startY - i * height
if (index > 0) {
//두번째 모듈일때 마지막 설치 지점
tempY = index > 0 && i === 0 ? installedLastHeightCoord - intvVer : installedLastHeightCoord
}
let tempHeightMargin = i === 0 ? 0 : i * intvVer
for (let j = 0; j < col; j++) {
let tempX = startX + j * width
let tempWidthMargin = j === 0 ? 0 : j * intvHor
let rectPoints = [
{ x: tempX + tempWidthMargin, y: tempY - height - tempHeightMargin },
{ x: tempX + tempWidthMargin, y: tempY - tempHeightMargin },
{ x: tempX + width + tempWidthMargin, y: tempY - tempHeightMargin },
{ x: tempX + width + tempWidthMargin, y: tempY - height - tempHeightMargin },
]
// console.log('🚀 ~ addCanvasMouseEventListener ~ rectPoints:', rectPoints)
tempModule.set({ points: rectPoints })
const tempTurfModule = polygonToTurfPolygon(tempModule)
tempModule.setCoords() //좌표 재정렬
if (turf.booleanContains(turfPolygon, tempTurfModule) || turf.booleanWithin(tempTurfModule, turfPolygon)) {
//마우스 클릭시 set으로 해당 위치에 셀을 넣음
const isOverlap = manualDrawModules.some((module) => turf.booleanOverlap(tempTurfModule, polygonToTurfPolygon(module))) //겹치는지 확인
// if (!isOverlap) {
canvas?.remove(tempModule) canvas?.remove(tempModule)
//안겹치면 넣는다 //안겹치면 넣는다
@ -1191,7 +1224,7 @@ export function useModuleBasicSetting(tabNum) {
let manualModule = new QPolygon(tempModule.points, { let manualModule = new QPolygon(tempModule.points, {
...moduleOptions, ...moduleOptions,
moduleInfo: checkedModule[0], moduleInfo: module,
// left: toFixedWithoutRounding(tempX + tempWidthMargin, 1), // left: toFixedWithoutRounding(tempX + tempWidthMargin, 1),
// top: toFixedWithoutRounding(tempY - height - tempHeightMargin, 1), // top: toFixedWithoutRounding(tempY - height - tempHeightMargin, 1),
width: toFixedWithoutRounding(width, 1), width: toFixedWithoutRounding(width, 1),
@ -1205,15 +1238,24 @@ export function useModuleBasicSetting(tabNum) {
canvas?.add(manualModule) canvas?.add(manualModule)
manualDrawModules.push(manualModule) manualDrawModules.push(manualModule)
setModuleStatisticsData() setModuleStatisticsData()
installedLastHeightCoord = tempY - height - tempHeightMargin
} else {
manualModule.set({ fill: 'transparent', stroke: 'red', strokeWidth: 1 })
canvas?.add(manualModule)
canvas.renderAll()
} }
// getModuleStatistics() // getModuleStatistics()
} else { // } else {
swalFire({ text: getMessage('module.place.overlab') }) // swalFire({ text: getMessage('module.place.overlab') })
return // return
// tempModule.set({ fill: 'transparent', stroke: 'red', strokeWidth: 1 })
// canvas?.add(tempModule)
// canvas.renderAll()
// }
} }
} }
} }
} })
} else if (flowDirection === 'north') { } else if (flowDirection === 'north') {
startX = tempModule.points[3].x startX = tempModule.points[3].x
startY = tempModule.points[3].y startY = tempModule.points[3].y