최대배치 작업중
This commit is contained in:
parent
558e33b7b5
commit
5de9242e08
@ -4,19 +4,21 @@ import { rectToPolygon, setSurfaceShapePattern } from '@/util/canvas-util'
|
|||||||
import { roofDisplaySelector } from '@/store/settingAtom'
|
import { roofDisplaySelector } from '@/store/settingAtom'
|
||||||
import offsetPolygon from '@/util/qpolygon-utils'
|
import offsetPolygon from '@/util/qpolygon-utils'
|
||||||
import { QPolygon } from '@/components/fabric/QPolygon'
|
import { QPolygon } from '@/components/fabric/QPolygon'
|
||||||
import { QLine } from '@/components/fabric/QLine'
|
|
||||||
import { moduleSetupSurfaceState, moduleIsSetupState } from '@/store/canvasAtom'
|
import { moduleSetupSurfaceState, moduleIsSetupState } from '@/store/canvasAtom'
|
||||||
import { useEvent } from '@/hooks/useEvent'
|
import { useEvent } from '@/hooks/useEvent'
|
||||||
import { POLYGON_TYPE, BATCH_TYPE } from '@/common/common'
|
import { POLYGON_TYPE, BATCH_TYPE } from '@/common/common'
|
||||||
import * as turf from '@turf/turf'
|
import * as turf from '@turf/turf'
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
|
import { useSwal } from '@/hooks/useSwal'
|
||||||
|
|
||||||
export function useModuleBasicSetting() {
|
export function useModuleBasicSetting() {
|
||||||
const canvas = useRecoilValue(canvasState)
|
const canvas = useRecoilValue(canvasState)
|
||||||
const roofDisplay = useRecoilValue(roofDisplaySelector)
|
const roofDisplay = useRecoilValue(roofDisplaySelector)
|
||||||
const [moduleSetupSurface, setModuleSetupSurface] = useRecoilState(moduleSetupSurfaceState)
|
const [moduleSetupSurface, setModuleSetupSurface] = useRecoilState(moduleSetupSurfaceState)
|
||||||
// const [moduleIsSetup, setModuleIsSetup] = useRecoilState(moduleIsSetupState)
|
const [moduleIsSetup, setModuleIsSetup] = useRecoilState(moduleIsSetupState)
|
||||||
const { addTargetMouseEventListener, addCanvasMouseEventListener, initEvent } = useEvent()
|
const { addTargetMouseEventListener, addCanvasMouseEventListener, initEvent } = useEvent()
|
||||||
|
const { swalFire } = useSwal()
|
||||||
|
|
||||||
// const { addTargetMouseEventListener, addCanvasMouseEventListener, initEvent } = useContext(EventContext)
|
// const { addTargetMouseEventListener, addCanvasMouseEventListener, initEvent } = useContext(EventContext)
|
||||||
let selectedModuleInstSurfaceArray = []
|
let selectedModuleInstSurfaceArray = []
|
||||||
|
|
||||||
@ -440,6 +442,7 @@ export function useModuleBasicSetting() {
|
|||||||
|
|
||||||
//자동 모듈 설치(그리드 방식)
|
//자동 모듈 설치(그리드 방식)
|
||||||
const autoModuleSetup = (placementRef) => {
|
const autoModuleSetup = (placementRef) => {
|
||||||
|
initEvent() //마우스 이벤트 초기화
|
||||||
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 === 'true' ? true : false
|
const isMaxSetup = placementRef.isMaxSetup.current === 'true' ? true : false
|
||||||
@ -472,14 +475,20 @@ export function useModuleBasicSetting() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
moduleSetupSurfaces.forEach((obj) => {
|
// console.log('moduleIsSetup', moduleIsSetup)
|
||||||
if (obj.modules) {
|
|
||||||
obj.modules.forEach((module) => {
|
// if (moduleIsSetup.length > 0) {
|
||||||
canvas?.remove(module)
|
// swalFire({ text: 'alert 아이콘 테스트입니다.', icon: 'error' })
|
||||||
})
|
// }
|
||||||
obj.modules = []
|
|
||||||
}
|
// moduleSetupSurfaces.forEach((obj) => {
|
||||||
})
|
// if (obj.modules) {
|
||||||
|
// obj.modules.forEach((module) => {
|
||||||
|
// canvas?.remove(module)
|
||||||
|
// })
|
||||||
|
// obj.modules = []
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
|
||||||
notSelectedTrestlePolygons.forEach((obj) => {
|
notSelectedTrestlePolygons.forEach((obj) => {
|
||||||
if (obj.modules) {
|
if (obj.modules) {
|
||||||
@ -614,20 +623,20 @@ export function useModuleBasicSetting() {
|
|||||||
if (isMaxSetup) totalWidth = totalWidth * 2 //최대배치시 2배로 늘려서 반씩 검사하기위함
|
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 : 2
|
||||||
for (let i = 0; i <= totalWidth; i++) {
|
for (let i = 0; i <= totalWidth; i++) {
|
||||||
leftMargin = i === 0 ? 1.1 : 0 //숫자가 0이면 0, 1이면 1로 바꾸기
|
leftMargin = i === 0 ? 1 : 2
|
||||||
chidoriLength = 0
|
chidoriLength = 0
|
||||||
if (isChidori) {
|
if (isChidori) {
|
||||||
chidoriLength = j % 2 === 0 ? 0 : width / 2
|
chidoriLength = j % 2 === 0 ? 0 : width / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
square = [
|
square = [
|
||||||
[startColPoint + tempMaxWidth * i - chidoriLength, startPoint.y1 - height * j - bottomMargin],
|
[startColPoint + tempMaxWidth * i - chidoriLength + leftMargin, startPoint.y1 - height * j - bottomMargin],
|
||||||
[startColPoint + tempMaxWidth * i + width - chidoriLength, startPoint.y1 - height * j - bottomMargin],
|
[startColPoint + tempMaxWidth * i + width - chidoriLength + leftMargin, startPoint.y1 - height * j - bottomMargin],
|
||||||
[startColPoint + tempMaxWidth * i + width - chidoriLength, startPoint.y1 - height * j - height - bottomMargin],
|
[startColPoint + tempMaxWidth * i + width - chidoriLength + leftMargin, startPoint.y1 - height * j - height - bottomMargin],
|
||||||
[startColPoint + tempMaxWidth * i - chidoriLength, startPoint.y1 - height * j - height - bottomMargin],
|
[startColPoint + tempMaxWidth * i - chidoriLength + leftMargin, startPoint.y1 - height * j - height - bottomMargin],
|
||||||
[startColPoint + tempMaxWidth * i - chidoriLength, startPoint.y1 - height * j - bottomMargin],
|
[startColPoint + tempMaxWidth * i - chidoriLength + leftMargin, startPoint.y1 - height * j - bottomMargin],
|
||||||
]
|
]
|
||||||
|
|
||||||
let squarePolygon = turf.polygon([square])
|
let squarePolygon = turf.polygon([square])
|
||||||
@ -674,9 +683,9 @@ export function useModuleBasicSetting() {
|
|||||||
if (isMaxSetup) totalHeight = totalHeight * 2 //최대배치시 2배로 늘려서 반씩 검사
|
if (isMaxSetup) totalHeight = totalHeight * 2 //최대배치시 2배로 늘려서 반씩 검사
|
||||||
|
|
||||||
for (let i = 0; i <= totalWidth; i++) {
|
for (let i = 0; i <= totalWidth; i++) {
|
||||||
bottomMargin = i === 0 ? 1 : 0.1
|
bottomMargin = i === 0 ? 1 : 2
|
||||||
for (let j = 0; j < totalHeight; j++) {
|
for (let j = 0; j < totalHeight; j++) {
|
||||||
leftMargin = i === 0 ? 0 : 0.5 * i
|
leftMargin = i === 0 ? 1 : 2
|
||||||
chidoriLength = 0
|
chidoriLength = 0
|
||||||
if (isChidori) {
|
if (isChidori) {
|
||||||
chidoriLength = i % 2 === 0 ? 0 : height / 2
|
chidoriLength = i % 2 === 0 ? 0 : height / 2
|
||||||
@ -746,17 +755,19 @@ export function useModuleBasicSetting() {
|
|||||||
if (isMaxSetup) diffRightEndPoint = diffRightEndPoint * 2 //최대배치시 2배로 늘려서 반씩 검사하기위함
|
if (isMaxSetup) diffRightEndPoint = diffRightEndPoint * 2 //최대배치시 2배로 늘려서 반씩 검사하기위함
|
||||||
|
|
||||||
for (let j = 0; j < diffBottomEndPoint; j++) {
|
for (let j = 0; j < diffBottomEndPoint; j++) {
|
||||||
|
bottomMargin = j === 0 ? 1 : 2
|
||||||
for (let i = 0; i < diffRightEndPoint; i++) {
|
for (let i = 0; i < diffRightEndPoint; i++) {
|
||||||
|
leftMargin = i === 0 ? 1 : 2
|
||||||
chidoriLength = 0
|
chidoriLength = 0
|
||||||
if (isChidori) {
|
if (isChidori) {
|
||||||
chidoriLength = j % 2 === 0 ? 0 : width / 2
|
chidoriLength = j % 2 === 0 ? 0 : width / 2
|
||||||
}
|
}
|
||||||
square = [
|
square = [
|
||||||
[startColPoint + tempMaxWidth * i + chidoriLength, startPoint.y1 + height * j + 1],
|
[startColPoint + tempMaxWidth * i + chidoriLength + leftMargin, startPoint.y1 + height * j + bottomMargin],
|
||||||
[startColPoint + tempMaxWidth * i + chidoriLength, startPoint.y1 + height * j + height + 1],
|
[startColPoint + tempMaxWidth * i + chidoriLength + leftMargin, startPoint.y1 + height * j + height + bottomMargin],
|
||||||
[startColPoint + tempMaxWidth * i + width + chidoriLength, startPoint.y1 + height * j + height + 1],
|
[startColPoint + tempMaxWidth * i + width + chidoriLength + leftMargin, startPoint.y1 + height * j + height + bottomMargin],
|
||||||
[startColPoint + tempMaxWidth * i + width + chidoriLength, startPoint.y1 + height * j + 1],
|
[startColPoint + tempMaxWidth * i + width + chidoriLength + leftMargin, startPoint.y1 + height * j + bottomMargin],
|
||||||
[startColPoint + tempMaxWidth * i + chidoriLength, startPoint.y1 + height * j + 1],
|
[startColPoint + tempMaxWidth * i + chidoriLength + leftMargin, startPoint.y1 + height * j + bottomMargin],
|
||||||
]
|
]
|
||||||
|
|
||||||
let squarePolygon = turf.polygon([square])
|
let squarePolygon = turf.polygon([square])
|
||||||
@ -804,9 +815,9 @@ export function useModuleBasicSetting() {
|
|||||||
if (isMaxSetup) totalHeight = totalHeight * 2 //최대배치시 2배로 늘려서 반씩 검사
|
if (isMaxSetup) totalHeight = totalHeight * 2 //최대배치시 2배로 늘려서 반씩 검사
|
||||||
|
|
||||||
for (let i = 0; i <= totalWidth; i++) {
|
for (let i = 0; i <= totalWidth; i++) {
|
||||||
|
bottomMargin = j === 0 ? 1 : 2
|
||||||
for (let j = 0; j < totalHeight; j++) {
|
for (let j = 0; j < totalHeight; j++) {
|
||||||
bottomMargin = j === 0 ? 0.5 : 0.5 * j
|
leftMargin = i === 0 ? 1 : 2
|
||||||
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
|
||||||
@ -912,11 +923,12 @@ export function useModuleBasicSetting() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
canvas?.renderAll()
|
||||||
|
|
||||||
//나간애들 제외하고 설치된 애들로 겹친애들 삭제 하기
|
//나간애들 제외하고 설치된 애들로 겹친애들 삭제 하기
|
||||||
setupedModules.forEach((module, index) => {
|
setupedModules.forEach((module, index) => {
|
||||||
if (isMaxSetup && index > 0) {
|
if (isMaxSetup && index > 0) {
|
||||||
const isOverlap = turf.booleanOverlap(polygonToTurfPolygon(setupedModules[index - 1]), polygonToTurfPolygon(module))
|
const isOverlap = turf.booleanOverlap(polygonToTurfPolygon(setupedModules[index - 1]), polygonToTurfPolygon(module))
|
||||||
|
|
||||||
//겹치는지 확인
|
//겹치는지 확인
|
||||||
if (isOverlap) {
|
if (isOverlap) {
|
||||||
//겹쳐있으면 삭제
|
//겹쳐있으면 삭제
|
||||||
@ -930,7 +942,13 @@ export function useModuleBasicSetting() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
moduleSetupSurface.set({ modules: setupedModules })
|
moduleSetupSurface.set({ modules: setupedModules })
|
||||||
// setModuleIsSetup(moduleSetupArray)
|
|
||||||
|
// const moduleArray = [...moduleIsSetup]
|
||||||
|
// moduleArray.push({
|
||||||
|
// surfaceId: moduleSetupSurface.surfaceId,
|
||||||
|
// moduleSetupArray: setupedModules,
|
||||||
|
// })
|
||||||
|
// setModuleIsSetup(moduleArray)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user