모듈 최대배치 작업중
This commit is contained in:
parent
a94b328ae3
commit
47e5b62e9c
@ -12,6 +12,7 @@ import { POLYGON_TYPE, BATCH_TYPE } from '@/common/common'
|
|||||||
import * as turf from '@turf/turf'
|
import * as turf from '@turf/turf'
|
||||||
import { EventContext } from '@/app/floor-plan/EventProvider'
|
import { EventContext } from '@/app/floor-plan/EventProvider'
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
|
import { useMainContentsController } from '../main/useMainContentsController'
|
||||||
|
|
||||||
export function useModuleBasicSetting() {
|
export function useModuleBasicSetting() {
|
||||||
const canvas = useRecoilValue(canvasState)
|
const canvas = useRecoilValue(canvasState)
|
||||||
@ -400,7 +401,7 @@ export function useModuleBasicSetting() {
|
|||||||
const autoModuleSetup = (placementRef) => {
|
const autoModuleSetup = (placementRef) => {
|
||||||
const isChidori = placementRef.isChidori.current === 'true' ? true : false
|
const isChidori = placementRef.isChidori.current === 'true' ? true : false
|
||||||
const setupLocation = placementRef.setupLocation.current
|
const setupLocation = placementRef.setupLocation.current
|
||||||
const isMaxSetup = placementRef.isMaxSetup.current
|
const isMaxSetup = placementRef.isMaxSetup.current === 'true' ? true : false
|
||||||
|
|
||||||
const moduleSetupSurfaces = moduleSetupSurface //선택 설치면
|
const moduleSetupSurfaces = moduleSetupSurface //선택 설치면
|
||||||
|
|
||||||
@ -539,29 +540,34 @@ export function useModuleBasicSetting() {
|
|||||||
let diffLeftEndPoint = Math.abs(totalLeftEndPoint / width)
|
let diffLeftEndPoint = Math.abs(totalLeftEndPoint / width)
|
||||||
let diffTopEndPoint = Math.abs(totalTopEndPoint / height)
|
let diffTopEndPoint = Math.abs(totalTopEndPoint / height)
|
||||||
let startColPoint = Math.abs(width * Math.ceil(diffLeftEndPoint) - startPoint.x1)
|
let startColPoint = Math.abs(width * Math.ceil(diffLeftEndPoint) - startPoint.x1)
|
||||||
|
let tempMaxWidth = isMaxSetup ? width / 2 : width //최대배치인지 확인하려고 넣음
|
||||||
|
if (isMaxSetup) totalWidth = totalWidth * 2 //최대배치시 2배로 늘려서 반씩 검사하기위함
|
||||||
|
|
||||||
for (let j = 0; j < diffTopEndPoint; j++) {
|
for (let j = 0; j < diffTopEndPoint; j++) {
|
||||||
bottomMargin = j === 0 ? 1 : 0
|
bottomMargin = j === 0 ? 1 : 0
|
||||||
for (let i = 0; i <= totalWidth; i++) {
|
for (let i = 0; i <= totalWidth; i++) {
|
||||||
leftMargin = i === 0 ? 1 : 0 //숫자가 0이면 0, 1이면 1로 바꾸기
|
leftMargin = i === 0 ? 1.1 : 0 //숫자가 0이면 0, 1이면 1로 바꾸기
|
||||||
chidoriLength = 0
|
chidoriLength = 0
|
||||||
if (isChidori) {
|
if (isChidori) {
|
||||||
chidoriLength = j % 2 === 0 ? 0 : width / 2
|
chidoriLength = j % 2 === 0 ? 0 : width / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let squarePolygon
|
||||||
|
let turfCoordnates
|
||||||
|
let points
|
||||||
|
|
||||||
square = [
|
square = [
|
||||||
[startColPoint + width * i - chidoriLength, startPoint.y1 - height * j - bottomMargin],
|
[startColPoint + tempMaxWidth * i - chidoriLength, startPoint.y1 - height * j - bottomMargin],
|
||||||
[startColPoint + width * i + width - chidoriLength, startPoint.y1 - height * j - bottomMargin],
|
[startColPoint + tempMaxWidth * i + width - chidoriLength, startPoint.y1 - height * j - bottomMargin],
|
||||||
[startColPoint + width * i + width - chidoriLength, startPoint.y1 - height * j - height - bottomMargin],
|
[startColPoint + tempMaxWidth * i + width - chidoriLength, startPoint.y1 - height * j - height - bottomMargin],
|
||||||
[startColPoint + width * i - chidoriLength, startPoint.y1 - height * j - height - bottomMargin],
|
[startColPoint + tempMaxWidth * i - chidoriLength, startPoint.y1 - height * j - height - bottomMargin],
|
||||||
[startColPoint + width * i - chidoriLength, startPoint.y1 - height * j - bottomMargin],
|
[startColPoint + tempMaxWidth * i - chidoriLength, startPoint.y1 - height * j - bottomMargin],
|
||||||
]
|
]
|
||||||
|
|
||||||
let squarePolygon = turf.polygon([square])
|
squarePolygon = turf.polygon([square])
|
||||||
let turfCoordnates = squarePolygon.geometry.coordinates[0].slice(0, -1)
|
turfCoordnates = squarePolygon.geometry.coordinates[0].slice(0, -1)
|
||||||
let points = turfCoordnates.map((coord) => ({ x: coord[0], y: coord[1] }))
|
points = turfCoordnates.map((coord) => ({ x: coord[0], y: coord[1] }))
|
||||||
|
|
||||||
// if (disjointFromTrestle && isDisjoint) {
|
|
||||||
let tempModule = new QPolygon(points, { ...moduleOptions, turfPoints: squarePolygon })
|
let tempModule = new QPolygon(points, { ...moduleOptions, turfPoints: squarePolygon })
|
||||||
canvas?.add(tempModule)
|
canvas?.add(tempModule)
|
||||||
moduleSetupArray.push(tempModule)
|
moduleSetupArray.push(tempModule)
|
||||||
@ -581,25 +587,26 @@ export function useModuleBasicSetting() {
|
|||||||
let totalWidth = Math.abs(startPoint.x1 - maxRightEndPoint) / width
|
let totalWidth = Math.abs(startPoint.x1 - maxRightEndPoint) / width
|
||||||
let startRowPoint = startPoint.y1 - height * Math.ceil(diffTopEndPoint)
|
let startRowPoint = startPoint.y1 - height * Math.ceil(diffTopEndPoint)
|
||||||
|
|
||||||
for (let j = 0; j < totalHeight; j++) {
|
let tempMaxHeight = isMaxSetup ? height / 2 : height //최대배치인지 확인하려고 넣음
|
||||||
bottomMargin = j === 0 ? 1 : 0
|
if (isMaxSetup) totalHeight = totalHeight * 2 //최대배치시 2배로 늘려서 반씩 검사
|
||||||
for (let i = 0; i <= totalWidth; i++) {
|
|
||||||
leftMargin = 1
|
for (let i = 0; i <= totalWidth; i++) {
|
||||||
|
bottomMargin = i === 0 ? 1 : 0.1
|
||||||
|
for (let j = 0; j < totalHeight; j++) {
|
||||||
|
leftMargin = i === 0 ? 0 : 0.5 * i
|
||||||
chidoriLength = 0
|
chidoriLength = 0
|
||||||
if (isChidori) {
|
if (isChidori) {
|
||||||
chidoriLength = i % 2 === 0 ? 0 : height / 2
|
chidoriLength = j % 2 === 0 ? 0 : height / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
square = [
|
square = [
|
||||||
[startPoint.x1 + width * i + leftMargin, startRowPoint + height * j + bottomMargin - chidoriLength],
|
[startPoint.x1 + width * i + leftMargin, startRowPoint + tempMaxHeight * j + bottomMargin - chidoriLength],
|
||||||
[startPoint.x1 + width * i + width + leftMargin, startRowPoint + height * j + bottomMargin - chidoriLength],
|
[startPoint.x1 + width * i + width + leftMargin, startRowPoint + tempMaxHeight * j + bottomMargin - chidoriLength],
|
||||||
[startPoint.x1 + width * i + width + leftMargin, startRowPoint + height * j + height + bottomMargin - chidoriLength],
|
[startPoint.x1 + width * i + width + leftMargin, startRowPoint + tempMaxHeight * j + height + bottomMargin - chidoriLength],
|
||||||
[startPoint.x1 + width * i + leftMargin, startRowPoint + height * j + height + bottomMargin - chidoriLength],
|
[startPoint.x1 + width * i + leftMargin, startRowPoint + tempMaxHeight * j + height + bottomMargin - chidoriLength],
|
||||||
[startPoint.x1 + width * i + leftMargin, startRowPoint + height * j + bottomMargin - chidoriLength],
|
[startPoint.x1 + width * i + leftMargin, startRowPoint + tempMaxHeight * j + bottomMargin - chidoriLength],
|
||||||
]
|
]
|
||||||
|
|
||||||
console.log('square', square)
|
|
||||||
|
|
||||||
let squarePolygon = turf.polygon([square])
|
let squarePolygon = turf.polygon([square])
|
||||||
let turfCoordnates = squarePolygon.geometry.coordinates[0].slice(0, -1)
|
let turfCoordnates = squarePolygon.geometry.coordinates[0].slice(0, -1)
|
||||||
let points = turfCoordnates.map((coord) => ({ x: coord[0], y: coord[1] }))
|
let points = turfCoordnates.map((coord) => ({ x: coord[0], y: coord[1] }))
|
||||||
@ -622,9 +629,11 @@ export function useModuleBasicSetting() {
|
|||||||
let totalRightEndPoint = maxLeftEndPoint - maxRightEndPoint
|
let totalRightEndPoint = maxLeftEndPoint - maxRightEndPoint
|
||||||
let totalBottomEndPoint = maxBottomEndPoint - startPoint.y1
|
let totalBottomEndPoint = maxBottomEndPoint - startPoint.y1
|
||||||
let diffLeftEndPoint = Math.abs(totalLeftEndPoint / width)
|
let diffLeftEndPoint = Math.abs(totalLeftEndPoint / width)
|
||||||
let diffRightEndPoint = Math.abs(totalRightEndPoint / width)
|
let diffRightEndPoint = Math.ceil(Math.abs(totalRightEndPoint / width))
|
||||||
let diffBottomEndPoint = Math.abs(totalBottomEndPoint / height)
|
let diffBottomEndPoint = Math.ceil(Math.abs(totalBottomEndPoint / height))
|
||||||
let startColPoint = Math.abs(width * Math.ceil(diffLeftEndPoint) - startPoint.x1)
|
let startColPoint = Math.abs(width * Math.ceil(diffLeftEndPoint) - startPoint.x1)
|
||||||
|
let tempMaxWidth = isMaxSetup ? width / 2 : width //최대배치인지 확인하려고 넣음
|
||||||
|
if (isMaxSetup) diffRightEndPoint = diffRightEndPoint * 2 //최대배치시 2배로 늘려서 반씩 검사하기위함
|
||||||
|
|
||||||
for (let j = 0; j < diffBottomEndPoint; j++) {
|
for (let j = 0; j < diffBottomEndPoint; j++) {
|
||||||
for (let i = 0; i < diffRightEndPoint; i++) {
|
for (let i = 0; i < diffRightEndPoint; i++) {
|
||||||
@ -633,11 +642,11 @@ export function useModuleBasicSetting() {
|
|||||||
chidoriLength = j % 2 === 0 ? 0 : width / 2
|
chidoriLength = j % 2 === 0 ? 0 : width / 2
|
||||||
}
|
}
|
||||||
square = [
|
square = [
|
||||||
[startColPoint + width * i + chidoriLength, startPoint.y1 + height * j + 1],
|
[startColPoint + tempMaxWidth * i + chidoriLength, startPoint.y1 + height * j + 1],
|
||||||
[startColPoint + width * i + chidoriLength, startPoint.y1 + height * j + height + 1],
|
[startColPoint + tempMaxWidth * i + chidoriLength, startPoint.y1 + height * j + height + 1],
|
||||||
[startColPoint + width * i + width + chidoriLength, startPoint.y1 + height * j + height + 1],
|
[startColPoint + tempMaxWidth * i + width + chidoriLength, startPoint.y1 + height * j + height + 1],
|
||||||
[startColPoint + width * i + width + chidoriLength, startPoint.y1 + height * j + 1],
|
[startColPoint + tempMaxWidth * i + width + chidoriLength, startPoint.y1 + height * j + 1],
|
||||||
[startColPoint + width * i + chidoriLength, startPoint.y1 + height * j + 1],
|
[startColPoint + tempMaxWidth * i + chidoriLength, startPoint.y1 + height * j + 1],
|
||||||
]
|
]
|
||||||
|
|
||||||
let squarePolygon = turf.polygon([square])
|
let squarePolygon = turf.polygon([square])
|
||||||
@ -662,23 +671,26 @@ export function useModuleBasicSetting() {
|
|||||||
let diffTopEndPoint = Math.abs(totalTopEndPoint / height)
|
let diffTopEndPoint = Math.abs(totalTopEndPoint / height)
|
||||||
let totalHeight = Math.ceil(Math.abs(maxBottomEndPoint - maxTopEndPoint) / height)
|
let totalHeight = Math.ceil(Math.abs(maxBottomEndPoint - maxTopEndPoint) / height)
|
||||||
let totalWidth = Math.abs(startPoint.x1 - maxLeftEndPoint) / width
|
let totalWidth = Math.abs(startPoint.x1 - maxLeftEndPoint) / width
|
||||||
let startRowPoint = startPoint.y1 - height * Math.ceil(diffTopEndPoint)
|
let startRowPoint = startPoint.y1 - height * Math.ceil(diffTopEndPoint) - 3 // -3으로 위치살짝 보정
|
||||||
|
|
||||||
for (let j = 0; j < totalHeight; j++) {
|
let tempMaxHeight = isMaxSetup ? height / 2 : height //최대배치인지 확인하려고 넣음
|
||||||
bottomMargin = j === 0 ? 1 : 0
|
if (isMaxSetup) totalHeight = totalHeight * 2 //최대배치시 2배로 늘려서 반씩 검사
|
||||||
for (let i = 0; i <= totalWidth; i++) {
|
|
||||||
leftMargin = 1
|
for (let i = 0; i <= totalWidth; i++) {
|
||||||
|
for (let j = 0; j < totalHeight; j++) {
|
||||||
|
bottomMargin = j === 0 ? 0.5 : 0.5 * j
|
||||||
|
leftMargin = i === 0 ? 0 : 0.5 * i
|
||||||
chidoriLength = 0
|
chidoriLength = 0
|
||||||
if (isChidori) {
|
if (isChidori) {
|
||||||
chidoriLength = i % 2 === 0 ? 0 : height / 2
|
chidoriLength = i % 2 === 0 ? 0 : height / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
square = [
|
square = [
|
||||||
[startPoint.x1 - width * i - leftMargin, startRowPoint + height * j + bottomMargin + chidoriLength],
|
[startPoint.x1 - width * i - leftMargin, startRowPoint + tempMaxHeight * j + bottomMargin + chidoriLength],
|
||||||
[startPoint.x1 - width * i - width - leftMargin, startRowPoint + height * j + bottomMargin + chidoriLength],
|
[startPoint.x1 - width * i - width - leftMargin, startRowPoint + tempMaxHeight * j + bottomMargin + chidoriLength],
|
||||||
[startPoint.x1 - width * i - width - leftMargin, startRowPoint + height * j + height + bottomMargin + chidoriLength],
|
[startPoint.x1 - width * i - width - leftMargin, startRowPoint + tempMaxHeight * j + height + bottomMargin + chidoriLength],
|
||||||
[startPoint.x1 - width * i - leftMargin, startRowPoint + height * j + height + bottomMargin + chidoriLength],
|
[startPoint.x1 - width * i - leftMargin, startRowPoint + tempMaxHeight * j + height + bottomMargin + chidoriLength],
|
||||||
[startPoint.x1 - width * i - leftMargin, startRowPoint + height * j + bottomMargin + chidoriLength],
|
[startPoint.x1 - width * i - leftMargin, startRowPoint + tempMaxHeight * j + bottomMargin + chidoriLength],
|
||||||
]
|
]
|
||||||
|
|
||||||
let squarePolygon = turf.polygon([square])
|
let squarePolygon = turf.polygon([square])
|
||||||
@ -743,10 +755,9 @@ export function useModuleBasicSetting() {
|
|||||||
if (moduleSetupSurface.flowDirection === 'north') {
|
if (moduleSetupSurface.flowDirection === 'north') {
|
||||||
downFlowSetupModule(surfaceMaxLines, width, height, moduleSetupArray, moduleSetupSurface.flowLines)
|
downFlowSetupModule(surfaceMaxLines, width, height, moduleSetupArray, moduleSetupSurface.flowLines)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const setupedModules = moduleSetupArray.filter((module) => {
|
const setupedModules = moduleSetupArray.filter((module, index) => {
|
||||||
let disjointFromTrestle = checkModuleDisjointSurface(module.turfPoints, turfModuleSetupSurface)
|
let disjointFromTrestle = checkModuleDisjointSurface(module.turfPoints, turfModuleSetupSurface)
|
||||||
let isDisjoint = checkModuleDisjointObjects(module.turfPoints, containsBatchObjects)
|
let isDisjoint = checkModuleDisjointObjects(module.turfPoints, containsBatchObjects)
|
||||||
|
|
||||||
@ -758,11 +769,29 @@ export function useModuleBasicSetting() {
|
|||||||
return module
|
return module
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log('setupedModules.length', setupedModules.length)
|
||||||
|
//나간애들 제외하고 설치된 애들로 겹친애들 삭제 하기
|
||||||
|
setupedModules.forEach((module, index) => {
|
||||||
|
if (isMaxSetup && index > 0) {
|
||||||
|
const isOverlap = turf.booleanOverlap(polygonToTurfPolygon(setupedModules[index - 1]), polygonToTurfPolygon(module))
|
||||||
|
console.log(isOverlap)
|
||||||
|
//겹치는지 확인
|
||||||
|
if (isOverlap) {
|
||||||
|
//겹쳐있으면 삭제
|
||||||
|
// canvas?.remove(module)
|
||||||
|
// module.set({ fill: 'rgba(72, 161, 250, 0.4)', stroke: 'black', strokeWidth: 0.1 })
|
||||||
|
canvas.renderAll()
|
||||||
|
setupedModules.splice(index, 1)
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
moduleSetupSurface.set({ modules: setupedModules })
|
moduleSetupSurface.set({ modules: setupedModules })
|
||||||
setModuleIsSetup(moduleSetupArray)
|
setModuleIsSetup(moduleSetupArray)
|
||||||
})
|
})
|
||||||
|
|
||||||
// console.log(calculateForApi(moduleSetupArray))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const calculateForApi = (moduleSetupArray) => {
|
const calculateForApi = (moduleSetupArray) => {
|
||||||
@ -1129,7 +1158,7 @@ export function useModuleBasicSetting() {
|
|||||||
y2: standardLine.y1 + charlie,
|
y2: standardLine.y1 + charlie,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rtnObj = { target: idx === 0 ? 'left' : 'right', x1: pointX1, y1: pointY1, x2: pointX2, y2: pointY2 }
|
rtnObj = { target: index === 0 ? 'left' : 'right', x1: pointX1, y1: pointY1, x2: pointX2, y2: pointY2 }
|
||||||
}
|
}
|
||||||
rtnObjArray.push(rtnObj)
|
rtnObjArray.push(rtnObj)
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user