모듈 자동기능 작업진행중

This commit is contained in:
yjnoh 2024-11-28 17:45:33 +09:00
parent d01756c029
commit 05f187fda4

View File

@ -54,8 +54,7 @@ export function useModuleBasicSetting() {
})
setupSurface.setViewLengthText(false)
canvas.add(setupSurface)
canvas.add(setupSurface) //모듈설치면 만들기
if (setupSurface.flowDirection === 'south' || setupSurface.flowDirection === 'north') {
setFlowModuleLine(bottomTopFlowLine(setupSurface))
@ -392,11 +391,10 @@ export function useModuleBasicSetting() {
//자동 모듈 설치(그리드 방식)
const autoModuleSetup = (placementRef) => {
const isChidori = placementRef.isChidori.current
const isChidori = placementRef.isChidori.current === 'true' ? true : false
const setupLocation = placementRef.setupLocation.current
const isMaxSetup = placementRef.isMaxSetup.current
initEvent()
const moduleSetupSurfaces = moduleSetupSurface //선택 설치면
const notSelectedTrestlePolygons = canvas
@ -438,7 +436,7 @@ export function useModuleBasicSetting() {
fill: '#BFFD9F',
stroke: 'black',
strokeWidth: 0.1,
selectable: true, // 선택 가능하게 설정
selectable: false, // 선택 가능하게 설정
lockMovementX: false, // X 축 이동 잠금
lockMovementY: false, // Y 축 이동 잠금
lockRotation: false, // 회전 잠금
@ -537,9 +535,11 @@ export function useModuleBasicSetting() {
const maxRightEndPoint = surfaceMaxLines.right.x1 //최 우측
const maxTopEndPoint = surfaceMaxLines.top.y1 //최 상단
const maxBottomEndPoint = surfaceMaxLines.bottom.y1 //최 하단
let leftMargin, bottomMargin, square
let leftMargin, bottomMargin, square, chidoriLength
//처마면 배치
if (setupLocation === 'eaves') {
// 흐름방향이 남쪽일때
if (moduleSetupSurface.flowDirection === 'south') {
let startPoint = flowModuleLine.find((obj) => obj.target === 'bottom')
let totalLeftEndPoint = maxLeftEndPoint - startPoint.x1
@ -550,16 +550,59 @@ export function useModuleBasicSetting() {
let startColPoint = Math.abs(width * Math.ceil(diffLeftEndPoint) - startPoint.x1)
for (let j = 0; j < diffTopEndPoint; j++) {
bottomMargin = 1
bottomMargin = j === 0 ? 1 : 0
for (let i = 0; i <= totalWidth; i++) {
leftMargin = i === 0 ? 0 : 1 //숫자가 0이면 0, 1이면 1로 바꾸기
leftMargin = i === 0 ? 1 : 0 //숫자가 0이면 0, 1이면 1로 바꾸기
chidoriLength = 0
if (isChidori) {
chidoriLength = j % 2 === 0 ? 0 : width / 2
}
square = [
[startColPoint + width * i + leftMargin, startPoint.y1 - height * j - bottomMargin],
[startColPoint + width * i + width - leftMargin, startPoint.y1 - height * j - bottomMargin],
[startColPoint + width * i + width - leftMargin, startPoint.y1 - height * j - height - bottomMargin],
[startColPoint + width * i + leftMargin, startPoint.y1 - height * j - height - bottomMargin],
[startColPoint + width * i + leftMargin, startPoint.y1 - height * j - bottomMargin],
[startColPoint + width * i - chidoriLength, startPoint.y1 - height * j - bottomMargin],
[startColPoint + width * i + width - chidoriLength, startPoint.y1 - height * j - bottomMargin],
[startColPoint + width * i + width - chidoriLength, startPoint.y1 - height * j - height - bottomMargin],
[startColPoint + width * i - chidoriLength, startPoint.y1 - height * j - height - bottomMargin],
[startColPoint + width * i - chidoriLength, startPoint.y1 - height * j - bottomMargin],
]
let squarePolygon = turf.polygon([square])
let turfCoordnates = squarePolygon.geometry.coordinates[0].slice(0, -1)
let points = turfCoordnates.map((coord) => ({ x: coord[0], y: coord[1] }))
// if (disjointFromTrestle && isDisjoint) {
let tempModule = new QPolygon(points, { ...moduleOptions, turfPoints: squarePolygon })
canvas?.add(tempModule)
moduleSetupArray.push(tempModule)
}
}
}
if (moduleSetupSurface.flowDirection === 'west') {
let startPoint = flowModuleLine.find((obj) => obj.target === 'left')
let totalTopEndPoint = Math.abs(maxTopEndPoint - startPoint.y1) //전체 높이에서 현재 높이를 뺌
let diffTopEndPoint = Math.abs(totalTopEndPoint / height)
let totalHeight = Math.ceil(Math.abs(maxBottomEndPoint - maxTopEndPoint) / height)
let totalWidth = Math.abs(startPoint.x1 - maxRightEndPoint) / width
let startRowPoint = startPoint.y1 - height * Math.ceil(diffTopEndPoint)
for (let j = 0; j < totalHeight; j++) {
bottomMargin = j === 0 ? 1 : 0
for (let i = 0; i <= totalWidth; i++) {
leftMargin = 1
chidoriLength = 0
if (isChidori) {
chidoriLength = i % 2 === 0 ? 0 : height / 2
}
square = [
[startPoint.x1 + width * i + leftMargin, startRowPoint + height * j + bottomMargin - chidoriLength],
[startPoint.x1 + width * i + width + leftMargin, startRowPoint + height * j + bottomMargin - chidoriLength],
[startPoint.x1 + width * i + width + leftMargin, startRowPoint + height * j + height + bottomMargin - chidoriLength],
[startPoint.x1 + width * i + leftMargin, startRowPoint + height * j + height + bottomMargin - chidoriLength],
[startPoint.x1 + width * i + leftMargin, startRowPoint + height * j + bottomMargin - chidoriLength],
]
let squarePolygon = turf.polygon([square])
let turfCoordnates = squarePolygon.geometry.coordinates[0].slice(0, -1)
let points = turfCoordnates.map((coord) => ({ x: coord[0], y: coord[1] }))
@ -583,17 +626,61 @@ export function useModuleBasicSetting() {
let startColPoint = Math.abs(width * Math.ceil(diffLeftEndPoint) - startPoint.x1)
for (let j = 0; j < diffBottomEndPoint; j++) {
bottomMargin = 1
for (let i = 0; i < diffRightEndPoint; i++) {
leftMargin = i === 0 ? 0 : 1
chidoriLength = 0
if (isChidori) {
chidoriLength = j % 2 === 0 ? 0 : width / 2
}
square = [
[startColPoint + width * i + chidoriLength, startPoint.y1 + height * j],
[startColPoint + width * i + chidoriLength, startPoint.y1 + height * j + height],
[startColPoint + width * i + width + chidoriLength, startPoint.y1 + height * j + height],
[startColPoint + width * i + width + chidoriLength, startPoint.y1 + height * j],
[startColPoint + width * i + chidoriLength, startPoint.y1 + height * j],
]
let squarePolygon = turf.polygon([square])
let turfCoordnates = squarePolygon.geometry.coordinates[0].slice(0, -1)
let points = turfCoordnates.map((coord) => ({ x: coord[0], y: coord[1] }))
// if (disjointFromTrestle && isDisjoint) {
let tempModule = new QPolygon(points, { ...moduleOptions, turfPoints: squarePolygon })
canvas?.add(tempModule)
moduleSetupArray.push(tempModule)
}
}
}
if (moduleSetupSurface.flowDirection === 'west') {
let startPoint = flowModuleLine.find((obj) => obj.target === 'right')
//계산하기 편하게 그냥 y1을 작은수로 만든다
let correctPoint =
startPoint.y1 > startPoint.y2
? { x1: startPoint.x2, x2: startPoint.x1, y1: startPoint.y2, y2: startPoint.y1 }
: { x1: startPoint.x1, x2: startPoint.x2, y1: startPoint.y1, y2: startPoint.y2 }
let totalTopEndPoint = Math.abs(maxTopEndPoint - startPoint.y1) //전체 높이에서 현재 높이를 뺌
let diffTopEndPoint = Math.abs(totalTopEndPoint / height)
let totalHeight = Math.ceil(Math.abs(maxBottomEndPoint - maxTopEndPoint) / height)
let totalWidth = Math.abs(startPoint.x1 - maxLeftEndPoint) / width
let startRowPoint = startPoint.y1 - height * Math.ceil(diffTopEndPoint)
for (let j = 0; j < totalHeight; j++) {
bottomMargin = j === 0 ? 1 : 0
for (let i = 0; i <= totalWidth; i++) {
leftMargin = 1
chidoriLength = 0
if (isChidori) {
chidoriLength = i % 2 === 0 ? 0 : height / 2
}
square = [
[startColPoint + width * i - leftMargin, startPoint.y1 + height * j + bottomMargin],
[startColPoint + width * i - leftMargin, startPoint.y1 + height * j + height + bottomMargin],
[startColPoint + width * i + width - leftMargin, startPoint.y1 + height * j + height + bottomMargin],
[startColPoint + width * i + width - leftMargin, startPoint.y1 + height * j + bottomMargin],
[startColPoint + width * i - leftMargin, startPoint.y1 + height * j + bottomMargin],
[startPoint.x1 - width * i - leftMargin, startRowPoint + height * j - bottomMargin + chidoriLength],
[startPoint.x1 - width * i - width - leftMargin, startRowPoint + height * j - bottomMargin + chidoriLength],
[startPoint.x1 - width * i - width - leftMargin, startRowPoint + height * j + height - bottomMargin + chidoriLength],
[startPoint.x1 - width * i - leftMargin, startRowPoint + height * j + height - bottomMargin + chidoriLength],
[startPoint.x1 - width * i - leftMargin, startRowPoint + height * j - bottomMargin + chidoriLength],
]
let squarePolygon = turf.polygon([square])
let turfCoordnates = squarePolygon.geometry.coordinates[0].slice(0, -1)
let points = turfCoordnates.map((coord) => ({ x: coord[0], y: coord[1] }))
@ -613,17 +700,17 @@ export function useModuleBasicSetting() {
let isDisjoint = checkModuleDisjointObjects(module.turfPoints, containsBatchObjects)
if (!(disjointFromTrestle && isDisjoint)) {
canvas?.remove(module)
// canvas?.remove(module)
module.set({ fill: 'rgba(255,190,41, 0.4)', stroke: 'black', strokeWidth: 1 })
return false
} else {
return module
}
})
moduleSetupSurface.set({ modules: setupedModules })
setModuleIsSetup(moduleSetupArray)
})
setModuleIsSetup(moduleSetupArray)
// console.log(calculateForApi(moduleSetupArray))
}
@ -826,12 +913,6 @@ export function useModuleBasicSetting() {
const h = beta * Math.sin((angle1 * Math.PI) / 180) // 높이
const sign = Math.sign(coords[0].y - coords[1].y) // 진행방향
const top = coords[1].y + sign * h // 변경되는 높이 좌표 값
// const line3 = new QLine([coords[1].x, coords[1].y, coords[1].x, top], {
// stroke: 'blue',
// strokeWidth: 1,
// selectable: true,
// })
// // canvas?.add(line3)
const pointX1 = coords[0].x + ((coords[0].y - top) / (coords[0].y - coords[1].y)) * (coords[1].x - coords[0].x)
const pointY1 = top
@ -845,8 +926,31 @@ export function useModuleBasicSetting() {
})
canvas?.add(finalLine)
canvas?.renderAll()
let rtnObj
if (alpha === 0 || beta === 0 || h === 0 || sign === 0) {
//꼭지점이 없고 평평할때 ex) 네모
let standardLine
if (center.index === 0) {
standardLine = surface.lines.reduce((acc, line, index) => {
if (line.y1 < acc.y1 || (line.y1 === acc.y1 && line.x1 < acc.x1)) {
return { x1: line.x1, y1: line.y1, index: index }
}
return acc
})
} else {
standardLine = surface.lines.reduce((acc, line, index) => {
if (line.y1 > acc.y1) {
return { x1: line.x1, y1: line.y1, index: index }
}
return acc
})
}
rtnObj = { target: idx === 0 ? 'bottom' : 'top', x1: standardLine.x1, y1: pointY1, x2: standardLine.x1 + charlie, y2: pointY2 }
} else {
rtnObj = { target: idx === 0 ? 'bottom' : 'top', x1: pointX1, y1: pointY1, x2: pointX2, y2: pointY2 }
}
const rtnObj = { target: idx === 0 ? 'bottom' : 'top', x1: pointX1, y1: pointY1, x2: pointX2, y2: pointY2 }
rtnObjArray.push(rtnObj)
++idx
})
@ -943,6 +1047,7 @@ export function useModuleBasicSetting() {
rtnObjArray.push(rtnObj)
++idx
})
return rtnObjArray
}
const findSetupSurfaceMaxLines = (surface) => {