모듈 흡착 범위 변경

This commit is contained in:
yjnoh 2025-02-13 16:10:27 +09:00
parent 77cfa8ea84
commit 3524686dcb

View File

@ -495,7 +495,7 @@ export function useModuleBasicSetting(tabNum) {
/** /**
* 스냅기능 * 스냅기능
*/ */
let snapDistance = 10 let snapDistance = 80
let cellSnapDistance = 20 let cellSnapDistance = 20
let intvHor = let intvHor =
@ -579,54 +579,54 @@ export function useModuleBasicSetting(tabNum) {
}) })
} }
// 위쪽 변에 스냅 // // 위쪽 변에 스냅
if (Math.abs(smallTop - trestleTop) < snapDistance) { // if (Math.abs(smallTop - trestleTop) < snapDistance) {
tempModule.top = trestleTop // tempModule.top = trestleTop
} // }
// 아래쪽 변에 스냅 // // 아래쪽 변에 스냅
if (Math.abs(smallTop + tempModule.height * tempModule.scaleY - (trestleTop + moduleSetupSurfaces[i].height)) < snapDistance) { // if (Math.abs(smallTop + tempModule.height * tempModule.scaleY - (trestleTop + moduleSetupSurfaces[i].height)) < snapDistance) {
tempModule.top = trestleTop + moduleSetupSurfaces[i].height - tempModule.height * tempModule.scaleY // tempModule.top = trestleTop + moduleSetupSurfaces[i].height - tempModule.height * tempModule.scaleY
} // }
// 왼쪽변에 스냅 // // 왼쪽변에 스냅
if (Math.abs(smallLeft - trestleLeft) < snapDistance) { // if (Math.abs(smallLeft - trestleLeft) < snapDistance) {
tempModule.left = trestleLeft // tempModule.left = trestleLeft
} // }
//오른쪽 변에 스냅 // //오른쪽 변에 스냅
if (Math.abs(smallRight - trestleRight) < snapDistance) { // if (Math.abs(smallRight - trestleRight) < snapDistance) {
tempModule.left = trestleRight - tempModule.width * tempModule.scaleX // tempModule.left = trestleRight - tempModule.width * tempModule.scaleX
} // }
if (flowDirection === 'south' || flowDirection === 'north') { // if (flowDirection === 'south' || flowDirection === 'north') {
// 모듈왼쪽이 세로중앙선에 붙게 스냅 // // 모듈왼쪽이 세로중앙선에 붙게 스냅
if (Math.abs(smallLeft - (trestleLeft + moduleSetupSurfaces[i].width / 2)) < snapDistance) { // if (Math.abs(smallLeft - (trestleLeft + moduleSetupSurfaces[i].width / 2)) < snapDistance) {
tempModule.left = trestleLeft + moduleSetupSurfaces[i].width / 2 // tempModule.left = trestleLeft + moduleSetupSurfaces[i].width / 2
} // }
// 모듈이 가운데가 세로중앙선에 붙게 스냅 // // 모듈이 가운데가 세로중앙선에 붙게 스냅
if (Math.abs(smallCenterX - (trestleLeft + moduleSetupSurfaces[i].width / 2)) < snapDistance) { // if (Math.abs(smallCenterX - (trestleLeft + moduleSetupSurfaces[i].width / 2)) < snapDistance) {
tempModule.left = trestleLeft + moduleSetupSurfaces[i].width / 2 - (tempModule.width * tempModule.scaleX) / 2 // tempModule.left = trestleLeft + moduleSetupSurfaces[i].width / 2 - (tempModule.width * tempModule.scaleX) / 2
} // }
// 모듈오른쪽이 세로중앙선에 붙게 스냅 // // 모듈오른쪽이 세로중앙선에 붙게 스냅
if (Math.abs(smallRight - (trestleLeft + moduleSetupSurfaces[i].width / 2)) < snapDistance) { // if (Math.abs(smallRight - (trestleLeft + moduleSetupSurfaces[i].width / 2)) < snapDistance) {
tempModule.left = trestleLeft + moduleSetupSurfaces[i].width / 2 - tempModule.width * tempModule.scaleX // tempModule.left = trestleLeft + moduleSetupSurfaces[i].width / 2 - tempModule.width * tempModule.scaleX
} // }
} else { // } else {
// 모듈이 가로중앙선에 스냅 // // 모듈이 가로중앙선에 스냅
if (Math.abs(smallTop + tempModule.height / 2 - bigCenterY) < snapDistance) { // if (Math.abs(smallTop + tempModule.height / 2 - bigCenterY) < snapDistance) {
tempModule.top = bigCenterY - tempModule.height / 2 // tempModule.top = bigCenterY - tempModule.height / 2
} // }
if (Math.abs(smallTop - (trestleTop + moduleSetupSurfaces[i].height / 2)) < snapDistance) { // if (Math.abs(smallTop - (trestleTop + moduleSetupSurfaces[i].height / 2)) < snapDistance) {
tempModule.top = trestleTop + moduleSetupSurfaces[i].height / 2 // tempModule.top = trestleTop + moduleSetupSurfaces[i].height / 2
} // }
// 모듈 밑면이 가로중앙선에 스냅 // // 모듈 밑면이 가로중앙선에 스냅
if (Math.abs(smallBottom - (trestleTop + moduleSetupSurfaces[i].height / 2)) < snapDistance) { // if (Math.abs(smallBottom - (trestleTop + moduleSetupSurfaces[i].height / 2)) < snapDistance) {
tempModule.top = trestleTop + moduleSetupSurfaces[i].height / 2 - tempModule.height * tempModule.scaleY // tempModule.top = trestleTop + moduleSetupSurfaces[i].height / 2 - tempModule.height * tempModule.scaleY
} // }
} // }
tempModule.setCoords() tempModule.setCoords()
canvas?.renderAll() canvas?.renderAll()
@ -677,9 +677,6 @@ export function useModuleBasicSetting(tabNum) {
if (!isIntersection) return if (!isIntersection) return
tempModule.setCoords() //좌표 재정렬 tempModule.setCoords() //좌표 재정렬
console.log('turf.booleanContains(turfPolygon, tempTurfModule)', turf.booleanContains(turfPolygon, tempTurfModule))
console.log('turf.booleanWithin(tempTurfModule, turfPolygon)', turf.booleanWithin(tempTurfModule, turfPolygon))
if (turf.booleanContains(turfPolygon, tempTurfModule) || turf.booleanWithin(tempTurfModule, turfPolygon)) { if (turf.booleanContains(turfPolygon, tempTurfModule) || turf.booleanWithin(tempTurfModule, turfPolygon)) {
//마우스 클릭시 set으로 해당 위치에 셀을 넣음 //마우스 클릭시 set으로 해당 위치에 셀을 넣음
const isOverlap = manualDrawModules.some((module) => turf.booleanOverlap(tempTurfModule, polygonToTurfPolygon(module))) //겹치는지 확인 const isOverlap = manualDrawModules.some((module) => turf.booleanOverlap(tempTurfModule, polygonToTurfPolygon(module))) //겹치는지 확인
@ -867,6 +864,8 @@ export function useModuleBasicSetting(tabNum) {
let startPoint = flowLines.bottom let startPoint = flowLines.bottom
const moduleArray = [] const moduleArray = []
console.log('flowLines', flowLines)
if (isCenter) { if (isCenter) {
//중앙배치일 경우에는 계산한다 //중앙배치일 경우에는 계산한다
if (flowLines.bottom.type === 'flat' && flowLines.left.type === 'flat' && flowLines.right.type === 'flat') { if (flowLines.bottom.type === 'flat' && flowLines.left.type === 'flat' && flowLines.right.type === 'flat') {
@ -949,9 +948,9 @@ export function useModuleBasicSetting(tabNum) {
} }
} else { } else {
//디버깅용 //디버깅용
// tempModule.set({ fill: 'rgba(255,190,41, 0.4)', stroke: 'black', strokeWidth: 1 }) tempModule.set({ fill: 'rgba(255,190,41, 0.4)', stroke: 'black', strokeWidth: 1 })
// canvas?.add(tempModule) canvas?.add(tempModule)
// canvas.renderAll() canvas.renderAll()
} }
} }
} }
@ -1065,9 +1064,9 @@ export function useModuleBasicSetting(tabNum) {
} }
} else { } else {
//디버깅용 //디버깅용
// tempModule.set({ fill: 'rgba(255,190,41, 0.4)', stroke: 'black', strokeWidth: 1 }) tempModule.set({ fill: 'rgba(255,190,41, 0.4)', stroke: 'black', strokeWidth: 1 })
// canvas?.add(tempModule) canvas?.add(tempModule)
// canvas.renderAll() canvas.renderAll()
} }
} }
} }
@ -1189,9 +1188,9 @@ export function useModuleBasicSetting(tabNum) {
} }
} else { } else {
//디버깅용 //디버깅용
// tempModule.set({ fill: 'rgba(255,190,41, 0.4)', stroke: 'black', strokeWidth: 1 }) tempModule.set({ fill: 'rgba(255,190,41, 0.4)', stroke: 'black', strokeWidth: 1 })
// canvas?.add(tempModule) canvas?.add(tempModule)
// canvas.renderAll() canvas.renderAll()
} }
} }
} }
@ -1517,16 +1516,16 @@ export function useModuleBasicSetting(tabNum) {
const pointX2 = coords[2].x + ((coords[2].y - top) / (coords[2].y - coords[1].y)) * (coords[1].x - coords[2].x) const pointX2 = coords[2].x + ((coords[2].y - top) / (coords[2].y - coords[1].y)) * (coords[1].x - coords[2].x)
const pointY2 = top const pointY2 = top
// const finalLine = new QLine([pointX1, pointY1, pointX2, pointY2], { const finalLine = new QLine([pointX1, pointY1, pointX2, pointY2], {
// stroke: 'red', stroke: 'red',
// strokeWidth: 1, strokeWidth: 1,
// selectable: true, selectable: true,
// }) })
// console.log(`index ${index} : finalLine`, pointX1, pointY1, pointX2, pointY2) // console.log(`index ${index} : finalLine`, pointX1, pointY1, pointX2, pointY2)
// canvas?.add(finalLine) canvas?.add(finalLine)
// canvas?.renderAll() canvas?.renderAll()
let rtnObj let rtnObj
//평평하면 //평평하면
@ -1643,13 +1642,13 @@ export function useModuleBasicSetting(tabNum) {
const pointX2 = top const pointX2 = top
const pointY2 = coords[2].y + ((coords[2].x - top) / (coords[2].x - coords[1].x)) * (coords[1].y - coords[2].y) const pointY2 = coords[2].y + ((coords[2].x - top) / (coords[2].x - coords[1].x)) * (coords[1].y - coords[2].y)
// const finalLine = new QLine([pointX1, pointY1, pointX2, pointY2], { const finalLine = new QLine([pointX1, pointY1, pointX2, pointY2], {
// stroke: 'red', stroke: 'red',
// strokeWidth: 1, strokeWidth: 1,
// selectable: true, selectable: true,
// }) })
// canvas?.add(finalLine) canvas?.add(finalLine)
// canvas?.renderAll() canvas?.renderAll()
let rtnObj let rtnObj
//평평하면 //평평하면