모듈 열.단 삭제기능 구현
This commit is contained in:
parent
f56e5ca4b0
commit
f08e1fd4ff
@ -1,11 +1,12 @@
|
|||||||
import { BATCH_TYPE, POLYGON_TYPE } from '@/common/common'
|
import { BATCH_TYPE, POLYGON_TYPE } from '@/common/common'
|
||||||
import { canvasState } from '@/store/canvasAtom'
|
import { canvasState } from '@/store/canvasAtom'
|
||||||
import { isOverlap, polygonToTurfPolygon } from '@/util/canvas-util'
|
import { isOverlap, polygonToTurfPolygon, rectToPolygon } from '@/util/canvas-util'
|
||||||
import { useRecoilValue } from 'recoil'
|
import { useRecoilValue } from 'recoil'
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
import * as turf from '@turf/turf'
|
import * as turf from '@turf/turf'
|
||||||
import { useSwal } from '../useSwal'
|
import { useSwal } from '../useSwal'
|
||||||
import { QPolygon } from '@/components/fabric/QPolygon'
|
import { QPolygon } from '@/components/fabric/QPolygon'
|
||||||
|
import { useModuleBasicSetting } from './useModuleBasicSetting'
|
||||||
|
|
||||||
export const MODULE_REMOVE_TYPE = {
|
export const MODULE_REMOVE_TYPE = {
|
||||||
LEFT: 'left',
|
LEFT: 'left',
|
||||||
@ -20,6 +21,7 @@ export const MODULE_REMOVE_TYPE = {
|
|||||||
export function useModule() {
|
export function useModule() {
|
||||||
const canvas = useRecoilValue(canvasState)
|
const canvas = useRecoilValue(canvasState)
|
||||||
const { swalFire } = useSwal()
|
const { swalFire } = useSwal()
|
||||||
|
const { checkModuleDisjointObjects } = useModuleBasicSetting()
|
||||||
|
|
||||||
const moduleMove = (length, direction) => {
|
const moduleMove = (length, direction) => {
|
||||||
const checkModuleDisjointSurface = (squarePolygon, turfModuleSetupSurface) => {
|
const checkModuleDisjointSurface = (squarePolygon, turfModuleSetupSurface) => {
|
||||||
@ -38,6 +40,8 @@ export function useModule() {
|
|||||||
.filter((obj) => obj.name === POLYGON_TYPE.MODULE_SETUP_SURFACE && obj.id === selectedModules[0].surfaceId)[0]
|
.filter((obj) => obj.name === POLYGON_TYPE.MODULE_SETUP_SURFACE && obj.id === selectedModules[0].surfaceId)[0]
|
||||||
const isOverlapArray = []
|
const isOverlapArray = []
|
||||||
const isInSurfaceArray = []
|
const isInSurfaceArray = []
|
||||||
|
const isOverlapObjects = []
|
||||||
|
const objects = getObjects()
|
||||||
|
|
||||||
if (selectedModules) {
|
if (selectedModules) {
|
||||||
canvas.remove(...selectedModules)
|
canvas.remove(...selectedModules)
|
||||||
@ -73,16 +77,28 @@ export function useModule() {
|
|||||||
//나갔는지 확인하는 로직
|
//나갔는지 확인하는 로직
|
||||||
const isInSurface = turf.booleanContains(turfModuleSetupSurface, turfModule) || turf.booleanWithin(turfModule, turfModuleSetupSurface)
|
const isInSurface = turf.booleanContains(turfModuleSetupSurface, turfModule) || turf.booleanWithin(turfModule, turfModuleSetupSurface)
|
||||||
isInSurfaceArray.push(isInSurface)
|
isInSurfaceArray.push(isInSurface)
|
||||||
|
isOverlapObjects.push(!checkModuleDisjointObjects(polygonToTurfPolygon(module, true), objects))
|
||||||
})
|
})
|
||||||
|
|
||||||
const isNotOverlap = isOverlapArray.some((isOverlap) => isOverlap) // true면 겹침
|
const isNotOverlap = isOverlapArray.some((isOverlap) => isOverlap) // true면 겹침
|
||||||
const isNotOutSurface = isInSurfaceArray.every((isOutSurface) => isOutSurface) //false면 밖으로 나감
|
const isNotOutSurface = isInSurfaceArray.every((isOutSurface) => isOutSurface) //false면 밖으로 나감
|
||||||
|
|
||||||
//안겹치고 안나갔으면 이동시킨다 아니면 원래 위치로 돌려놓는다
|
//안겹치고 안나갔으면 이동시킨다 아니면 원래 위치로 돌려놓는다
|
||||||
if (isNotOverlap || !isNotOutSurface) {
|
if (isNotOverlap || !isNotOutSurface || isOverlapObjects.some((isOverlap) => isOverlap)) {
|
||||||
selectedModules.forEach((module) => {
|
swalFire({
|
||||||
module.set({ ...module, left: module.originCoords.left, top: module.originCoords.top })
|
title: isNotOverlap
|
||||||
module.setCoords()
|
? '겹치는 모듈이 있습니다.'
|
||||||
|
: isOverlapObjects.some((isOverlap) => isOverlap)
|
||||||
|
? '모듈이 오브젝트와 겹칩니다.'
|
||||||
|
: '영역 밖',
|
||||||
|
icon: 'error',
|
||||||
|
type: 'confirm',
|
||||||
|
confirmFn: () => {
|
||||||
|
selectedModules.forEach((module) => {
|
||||||
|
module.set({ ...module, left: module.originCoords.left, top: module.originCoords.top })
|
||||||
|
module.setCoords()
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,11 +111,12 @@ export function useModule() {
|
|||||||
if (canvas.getActiveObjects().length === 0) return
|
if (canvas.getActiveObjects().length === 0) return
|
||||||
const activeModuleIds = canvas.getActiveObjects().map((obj) => obj.id)
|
const activeModuleIds = canvas.getActiveObjects().map((obj) => obj.id)
|
||||||
const modules = canvas.getObjects().filter((obj) => activeModuleIds.includes(obj.id))
|
const modules = canvas.getObjects().filter((obj) => activeModuleIds.includes(obj.id))
|
||||||
|
const objects = getObjects()
|
||||||
const otherModules = canvas.getObjects().filter((obj) => obj.surfaceId === modules[0].surfaceId && obj.name === POLYGON_TYPE.MODULE)
|
const otherModules = canvas.getObjects().filter((obj) => obj.surfaceId === modules[0].surfaceId && obj.name === POLYGON_TYPE.MODULE)
|
||||||
const moduleSetupSurface = canvas
|
const moduleSetupSurface = canvas
|
||||||
.getObjects()
|
.getObjects()
|
||||||
.filter((obj) => obj.name === POLYGON_TYPE.MODULE_SETUP_SURFACE && obj.id === modules[0].surfaceId)[0]
|
.filter((obj) => obj.name === POLYGON_TYPE.MODULE_SETUP_SURFACE && obj.id === modules[0].surfaceId)[0]
|
||||||
|
let [isOverlapOtherModules, isOverlapObjects, isOutsideSurface] = [[], [], []]
|
||||||
canvas.discardActiveObject() //선택해제
|
canvas.discardActiveObject() //선택해제
|
||||||
modules.forEach((module) => {
|
modules.forEach((module) => {
|
||||||
const { top, left } = getPosotion(module, direction, length, true)
|
const { top, left } = getPosotion(module, direction, length, true)
|
||||||
@ -109,20 +126,28 @@ export function useModule() {
|
|||||||
rect.setCoords()
|
rect.setCoords()
|
||||||
canvas.renderAll()
|
canvas.renderAll()
|
||||||
|
|
||||||
// const isOverlapOtherModules = otherModules.some((otherModule) => rect.intersectsWithObject(otherModule))
|
isOverlapOtherModules.push(
|
||||||
const isOverlapOtherModules = otherModules.some(
|
otherModules.some(
|
||||||
(otherModule) =>
|
(otherModule) =>
|
||||||
turf.booleanOverlap(polygonToTurfPolygon(rect, true), polygonToTurfPolygon(otherModule, true)) ||
|
turf.booleanOverlap(polygonToTurfPolygon(rect, true), polygonToTurfPolygon(otherModule, true)) ||
|
||||||
turf.booleanWithin(polygonToTurfPolygon(rect, true), polygonToTurfPolygon(otherModule, true)),
|
turf.booleanWithin(polygonToTurfPolygon(rect, true), polygonToTurfPolygon(otherModule, true)),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
const isOutsideSurface =
|
isOverlapObjects.push(!checkModuleDisjointObjects(polygonToTurfPolygon(rect, true), objects))
|
||||||
!turf.booleanContains(polygonToTurfPolygon(moduleSetupSurface, true), polygonToTurfPolygon(rect, true)) ||
|
|
||||||
!turf.booleanWithin(polygonToTurfPolygon(rect, true), polygonToTurfPolygon(moduleSetupSurface, true))
|
|
||||||
|
|
||||||
if (isOverlapOtherModules || isOutsideSurface) {
|
isOutsideSurface.push(
|
||||||
|
!turf.booleanContains(polygonToTurfPolygon(moduleSetupSurface, true), polygonToTurfPolygon(rect, true)) ||
|
||||||
|
!turf.booleanWithin(polygonToTurfPolygon(rect, true), polygonToTurfPolygon(moduleSetupSurface, true)),
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
isOverlapOtherModules.some((isOverlap) => isOverlap) ||
|
||||||
|
isOutsideSurface.some((isOutside) => isOutside) ||
|
||||||
|
isOverlapObjects.some((isOverlap) => isOverlap)
|
||||||
|
) {
|
||||||
swalFire({
|
swalFire({
|
||||||
title: isOverlapOtherModules ? '겹치는 모듈이 있습니다.' : '영역 밖',
|
title: isOverlapOtherModules ? '겹치는 모듈이 있습니다.' : isOutsideSurface ? '모듈이 오브젝트와 겹칩니다.' : '영역 밖',
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
confirmFn: () => {
|
confirmFn: () => {
|
||||||
@ -133,6 +158,7 @@ export function useModule() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const moduleMultiMove = (type, length, direction) => {
|
const moduleMultiMove = (type, length, direction) => {
|
||||||
if (canvas.getActiveObjects().length === 0) return
|
if (canvas.getActiveObjects().length === 0) return
|
||||||
if (canvas.getActiveObjects().length > 1) {
|
if (canvas.getActiveObjects().length > 1) {
|
||||||
@ -148,6 +174,8 @@ export function useModule() {
|
|||||||
const modules = type === 'row' ? getRowModules(activeModule) : getColumnModules(activeModule)
|
const modules = type === 'row' ? getRowModules(activeModule) : getColumnModules(activeModule)
|
||||||
const otherModules = getOtherModules(modules)
|
const otherModules = getOtherModules(modules)
|
||||||
const objects = getObjects()
|
const objects = getObjects()
|
||||||
|
console.log('🚀 ~ moduleMultiMove ~ objects:', objects)
|
||||||
|
|
||||||
const moduleSetupSurface = canvas
|
const moduleSetupSurface = canvas
|
||||||
.getObjects()
|
.getObjects()
|
||||||
.filter((obj) => obj.name === POLYGON_TYPE.MODULE_SETUP_SURFACE && obj.id === activeModule.surfaceId)[0]
|
.filter((obj) => obj.name === POLYGON_TYPE.MODULE_SETUP_SURFACE && obj.id === activeModule.surfaceId)[0]
|
||||||
@ -175,13 +203,7 @@ export function useModule() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (objects.length > 0) {
|
if (objects.length > 0) {
|
||||||
isOverlapObjects.push(
|
isOverlapObjects.push(!checkModuleDisjointObjects(polygonToTurfPolygon(module, true), objects))
|
||||||
objects.some(
|
|
||||||
(object) =>
|
|
||||||
turf.booleanOverlap(polygonToTurfPolygon(module, true), polygonToTurfPolygon(object, true)) ||
|
|
||||||
turf.booleanWithin(polygonToTurfPolygon(module, true), polygonToTurfPolygon(object, true)),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isOutsideSurface.push(
|
isOutsideSurface.push(
|
||||||
@ -196,7 +218,11 @@ export function useModule() {
|
|||||||
isOutsideSurface.some((isOutside) => isOutside)
|
isOutsideSurface.some((isOutside) => isOutside)
|
||||||
) {
|
) {
|
||||||
swalFire({
|
swalFire({
|
||||||
title: isOverlapOtherModules.some((isOverlap) => isOverlap) ? '겹치는 모듈이 있습니다.' : '영역 밖',
|
title: isOverlapOtherModules.some((isOverlap) => isOverlap)
|
||||||
|
? '겹치는 모듈이 있습니다.'
|
||||||
|
: isOverlapObjects.some((isOverlap) => isOverlap)
|
||||||
|
? '모듈이 오브젝트와 겹칩니다.'
|
||||||
|
: '영역 밖',
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
confirmFn: () => {
|
confirmFn: () => {
|
||||||
@ -232,9 +258,9 @@ export function useModule() {
|
|||||||
let [isOverlapOtherModules, isOverlapObjects, isOutsideSurface] = [[], [], []]
|
let [isOverlapOtherModules, isOverlapObjects, isOutsideSurface] = [[], [], []]
|
||||||
|
|
||||||
modules.forEach((module) => {
|
modules.forEach((module) => {
|
||||||
const { top, left } = getPosotion(module, direction, length, true)
|
const { top, left } = getPosotion(module, direction, length, false)
|
||||||
const moduleOptions = { ...module, left, top, id: uuidv4() }
|
const moduleOptions = { ...module, left, top, id: uuidv4() }
|
||||||
const rect = new QPolygon(module.points, moduleOptions)
|
const rect = new QPolygon(module.getCurrentPoints(), moduleOptions)
|
||||||
canvas.add(rect)
|
canvas.add(rect)
|
||||||
copyRects.push(rect)
|
copyRects.push(rect)
|
||||||
module.setCoords()
|
module.setCoords()
|
||||||
@ -250,13 +276,7 @@ export function useModule() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (objects.length > 0) {
|
if (objects.length > 0) {
|
||||||
isOverlapObjects.push(
|
isOverlapObjects.push(!checkModuleDisjointObjects(polygonToTurfPolygon(module, true), objects))
|
||||||
objects.some(
|
|
||||||
(object) =>
|
|
||||||
turf.booleanOverlap(polygonToTurfPolygon(module, true), polygonToTurfPolygon(object, true)) ||
|
|
||||||
turf.booleanWithin(polygonToTurfPolygon(module, true), polygonToTurfPolygon(object, true)),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isOutsideSurface.push(
|
isOutsideSurface.push(
|
||||||
@ -271,7 +291,11 @@ export function useModule() {
|
|||||||
isOutsideSurface.some((isOutside) => isOutside)
|
isOutsideSurface.some((isOutside) => isOutside)
|
||||||
) {
|
) {
|
||||||
swalFire({
|
swalFire({
|
||||||
title: isOverlapOtherModules.some((isOverlap) => isOverlap) ? '겹치는 모듈이 있습니다.' : '영역 밖',
|
title: isOverlapOtherModules.some((isOverlap) => isOverlap)
|
||||||
|
? '겹치는 모듈이 있습니다.'
|
||||||
|
: isOverlapObjects.some((isOverlap) => isOverlap)
|
||||||
|
? '모듈이 오브젝트와 겹칩니다.'
|
||||||
|
: '영역 밖',
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
confirmFn: () => {
|
confirmFn: () => {
|
||||||
@ -284,35 +308,11 @@ export function useModule() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getIsOverlapOtherModules = (module, otherModules) => {
|
|
||||||
return otherModules.some(
|
|
||||||
(otherModule) =>
|
|
||||||
turf.booleanOverlap(polygonToTurfPolygon(module, true), polygonToTurfPolygon(otherModule, true)) ||
|
|
||||||
turf.booleanWithin(polygonToTurfPolygon(module, true), polygonToTurfPolygon(otherModule, true)),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const getIsOverlapObjects = (module, objects) => {
|
|
||||||
return objects.some(
|
|
||||||
(object) =>
|
|
||||||
turf.booleanOverlap(polygonToTurfPolygon(module, true), polygonToTurfPolygon(object, true)) ||
|
|
||||||
turf.booleanWithin(polygonToTurfPolygon(module, true), polygonToTurfPolygon(object, true)),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const getIsOutsideSurface = (module, moduleSetupSurface) => {
|
|
||||||
return (
|
|
||||||
!turf.booleanContains(polygonToTurfPolygon(moduleSetupSurface, true), polygonToTurfPolygon(module, true)) ||
|
|
||||||
!turf.booleanWithin(polygonToTurfPolygon(module, true), polygonToTurfPolygon(moduleSetupSurface, true))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const moduleColumnRemove = (type) => {
|
const moduleColumnRemove = (type) => {
|
||||||
const activeModule = canvas.getObjects().filter((obj) => canvas.getActiveObjects()[0].id === obj.id)[0]
|
const activeModule = canvas.getObjects().filter((obj) => canvas.getActiveObjects()[0].id === obj.id)[0]
|
||||||
const columnModules = getColumnModules(activeModule)
|
const columnModules = getColumnModules(activeModule)
|
||||||
const otherModules = getOtherModules(columnModules)
|
const otherModules = getOtherModules(columnModules)
|
||||||
const objects = getObjects()
|
const objects = getObjects()
|
||||||
console.log('🚀 ~ moduleColumnRemove ~ objects:', objects)
|
|
||||||
let targetModules = []
|
let targetModules = []
|
||||||
const rightModules = otherModules.filter((module) => activeModule.left < module.left).sort((a, b) => a.left - b.left)
|
const rightModules = otherModules.filter((module) => activeModule.left < module.left).sort((a, b) => a.left - b.left)
|
||||||
const leftModules = otherModules.filter((module) => activeModule.left > module.left).sort((a, b) => b.left - a.left)
|
const leftModules = otherModules.filter((module) => activeModule.left > module.left).sort((a, b) => b.left - a.left)
|
||||||
@ -321,19 +321,11 @@ export function useModule() {
|
|||||||
.getObjects()
|
.getObjects()
|
||||||
.filter((obj) => obj.name === POLYGON_TYPE.MODULE_SETUP_SURFACE && obj.id === activeModule.surfaceId)[0]
|
.filter((obj) => obj.name === POLYGON_TYPE.MODULE_SETUP_SURFACE && obj.id === activeModule.surfaceId)[0]
|
||||||
let [isOverlapOtherModules, isOverlapObjects, isOutsideSurface] = [[], [], []]
|
let [isOverlapOtherModules, isOverlapObjects, isOutsideSurface] = [[], [], []]
|
||||||
console.log(
|
|
||||||
'🚀 ~ moduleColumnRemove ~ isOverlapOtherModules, isOverlapObjects, isOutsideSurface:',
|
|
||||||
isOverlapOtherModules,
|
|
||||||
isOverlapObjects,
|
|
||||||
isOutsideSurface,
|
|
||||||
)
|
|
||||||
|
|
||||||
canvas.discardActiveObject()
|
canvas.discardActiveObject()
|
||||||
canvas.remove(...columnModules)
|
canvas.remove(...columnModules)
|
||||||
canvas.renderAll()
|
canvas.renderAll()
|
||||||
|
|
||||||
if (type === MODULE_REMOVE_TYPE.LEFT) {
|
if (type === MODULE_REMOVE_TYPE.LEFT) {
|
||||||
console.log('🚀 ~ moduleColumnRemove ~ rightModules:', rightModules)
|
|
||||||
rightModules.forEach((module) => {
|
rightModules.forEach((module) => {
|
||||||
module.originPos = {
|
module.originPos = {
|
||||||
left: module.left,
|
left: module.left,
|
||||||
@ -344,7 +336,7 @@ export function useModule() {
|
|||||||
module.setCoords()
|
module.setCoords()
|
||||||
canvas.renderAll()
|
canvas.renderAll()
|
||||||
isOverlapOtherModules.push(getIsOverlapOtherModules(module, leftModules))
|
isOverlapOtherModules.push(getIsOverlapOtherModules(module, leftModules))
|
||||||
isOverlapObjects.push(getIsOverlapObjects(module, objects))
|
isOverlapObjects.push(!checkModuleDisjointObjects(polygonToTurfPolygon(module, true), objects))
|
||||||
isOutsideSurface.push(getIsOutsideSurface(module, moduleSetupSurface))
|
isOutsideSurface.push(getIsOutsideSurface(module, moduleSetupSurface))
|
||||||
})
|
})
|
||||||
targetModules = rightModules
|
targetModules = rightModules
|
||||||
@ -359,7 +351,7 @@ export function useModule() {
|
|||||||
module.setCoords()
|
module.setCoords()
|
||||||
canvas.renderAll()
|
canvas.renderAll()
|
||||||
isOverlapOtherModules.push(getIsOverlapOtherModules(module, rightModules))
|
isOverlapOtherModules.push(getIsOverlapOtherModules(module, rightModules))
|
||||||
isOverlapObjects.push(getIsOverlapObjects(module, objects))
|
isOverlapObjects.push(!checkModuleDisjointObjects(polygonToTurfPolygon(module, true), objects))
|
||||||
isOutsideSurface.push(getIsOutsideSurface(module, moduleSetupSurface))
|
isOutsideSurface.push(getIsOutsideSurface(module, moduleSetupSurface))
|
||||||
})
|
})
|
||||||
targetModules = leftModules
|
targetModules = leftModules
|
||||||
@ -394,19 +386,12 @@ export function useModule() {
|
|||||||
sideModules.filter((m) => m.id !== module.id),
|
sideModules.filter((m) => m.id !== module.id),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
isOverlapObjects.push(getIsOverlapObjects(module, objects))
|
isOverlapObjects.push(!checkModuleDisjointObjects(polygonToTurfPolygon(module, true), objects))
|
||||||
isOutsideSurface.push(getIsOutsideSurface(module, moduleSetupSurface))
|
isOutsideSurface.push(getIsOutsideSurface(module, moduleSetupSurface))
|
||||||
})
|
})
|
||||||
|
|
||||||
targetModules = sideModules
|
targetModules = sideModules
|
||||||
}
|
}
|
||||||
console.log('🚀 ~ sideModules.forEach ~ objects:', objects)
|
|
||||||
console.log(
|
|
||||||
'🚀 ~ moduleColumnRemove ~ isOverlapOtherModules, isOverlapObjects, isOutsideSurface:',
|
|
||||||
isOverlapOtherModules,
|
|
||||||
isOverlapObjects,
|
|
||||||
isOutsideSurface,
|
|
||||||
)
|
|
||||||
if (
|
if (
|
||||||
(isOverlapOtherModules.some((isOverlap) => isOverlap) ||
|
(isOverlapOtherModules.some((isOverlap) => isOverlap) ||
|
||||||
isOverlapObjects.some((isOverlap) => isOverlap) ||
|
isOverlapObjects.some((isOverlap) => isOverlap) ||
|
||||||
@ -414,9 +399,10 @@ export function useModule() {
|
|||||||
type !== MODULE_REMOVE_TYPE.NONE
|
type !== MODULE_REMOVE_TYPE.NONE
|
||||||
) {
|
) {
|
||||||
swalFire({
|
swalFire({
|
||||||
title:
|
title: isOverlapOtherModules.some((isOverlap) => isOverlap)
|
||||||
isOverlapOtherModules.some((isOverlap) => isOverlap) || isOverlapObjects.some((isOverlap) => isOverlap)
|
? '겹치는 모듈이 있습니다.'
|
||||||
? '겹치는 모듈이 있습니다.'
|
: isOverlapObjects.some((isOverlap) => isOverlap)
|
||||||
|
? '모듈이 오브젝트와 겹칩니다.'
|
||||||
: '영역 밖',
|
: '영역 밖',
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
@ -426,10 +412,10 @@ export function useModule() {
|
|||||||
module.set({ top: module.originPos.top, left: module.originPos.left })
|
module.set({ top: module.originPos.top, left: module.originPos.left })
|
||||||
module.setCoords()
|
module.setCoords()
|
||||||
})
|
})
|
||||||
canvas.renderAll()
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
canvas.renderAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
const moduleRowRemove = (type) => {
|
const moduleRowRemove = (type) => {
|
||||||
@ -461,7 +447,7 @@ export function useModule() {
|
|||||||
module.setCoords()
|
module.setCoords()
|
||||||
canvas.renderAll()
|
canvas.renderAll()
|
||||||
isOverlapOtherModules.push(getIsOverlapOtherModules(module, topModules))
|
isOverlapOtherModules.push(getIsOverlapOtherModules(module, topModules))
|
||||||
isOverlapObjects.push(getIsOverlapObjects(module, objects))
|
isOverlapObjects.push(!checkModuleDisjointObjects(polygonToTurfPolygon(module, true), objects))
|
||||||
isOutsideSurface.push(getIsOutsideSurface(module, moduleSetupSurface))
|
isOutsideSurface.push(getIsOutsideSurface(module, moduleSetupSurface))
|
||||||
})
|
})
|
||||||
targetModules = bottomModules
|
targetModules = bottomModules
|
||||||
@ -476,7 +462,7 @@ export function useModule() {
|
|||||||
module.setCoords()
|
module.setCoords()
|
||||||
canvas.renderAll()
|
canvas.renderAll()
|
||||||
isOverlapOtherModules.push(getIsOverlapOtherModules(module, bottomModules))
|
isOverlapOtherModules.push(getIsOverlapOtherModules(module, bottomModules))
|
||||||
isOverlapObjects.push(getIsOverlapObjects(module, objects))
|
isOverlapObjects.push(!checkModuleDisjointObjects(polygonToTurfPolygon(module, true), objects))
|
||||||
isOutsideSurface.push(getIsOutsideSurface(module, moduleSetupSurface))
|
isOutsideSurface.push(getIsOutsideSurface(module, moduleSetupSurface))
|
||||||
})
|
})
|
||||||
targetModules = topModules
|
targetModules = topModules
|
||||||
@ -512,7 +498,7 @@ export function useModule() {
|
|||||||
sideModules.filter((m) => m.id !== module.id),
|
sideModules.filter((m) => m.id !== module.id),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
isOverlapObjects.push(getIsOverlapObjects(module, objects))
|
isOverlapObjects.push(!checkModuleDisjointObjects(polygonToTurfPolygon(module, true), objects))
|
||||||
isOutsideSurface.push(getIsOutsideSurface(module, moduleSetupSurface))
|
isOutsideSurface.push(getIsOutsideSurface(module, moduleSetupSurface))
|
||||||
})
|
})
|
||||||
targetModules = sideModules
|
targetModules = sideModules
|
||||||
@ -525,9 +511,10 @@ export function useModule() {
|
|||||||
type !== MODULE_REMOVE_TYPE.NONE
|
type !== MODULE_REMOVE_TYPE.NONE
|
||||||
) {
|
) {
|
||||||
swalFire({
|
swalFire({
|
||||||
title:
|
title: isOverlapOtherModules.some((isOverlap) => isOverlap)
|
||||||
isOverlapOtherModules.some((isOverlap) => isOverlap) || isOverlapObjects.some((isOverlap) => isOverlap)
|
? '겹치는 모듈이 있습니다.'
|
||||||
? '겹치는 모듈이 있습니다.'
|
: isOverlapObjects.some((isOverlap) => isOverlap)
|
||||||
|
? '모듈이 오브젝트와 겹칩니다.'
|
||||||
: '영역 밖',
|
: '영역 밖',
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
@ -537,10 +524,10 @@ export function useModule() {
|
|||||||
module.set({ top: module.originPos.top, left: module.originPos.left })
|
module.set({ top: module.originPos.top, left: module.originPos.left })
|
||||||
module.setCoords()
|
module.setCoords()
|
||||||
})
|
})
|
||||||
canvas.renderAll()
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
canvas.renderAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
const getRowModules = (target) => {
|
const getRowModules = (target) => {
|
||||||
@ -559,7 +546,7 @@ export function useModule() {
|
|||||||
top = Number(target.top) - Number(length)
|
top = Number(target.top) - Number(length)
|
||||||
top = hasMargin ? top - Number(target.height) : top
|
top = hasMargin ? top - Number(target.height) : top
|
||||||
} else if (direction === 'down') {
|
} else if (direction === 'down') {
|
||||||
top = Number(target.top) + Number(target.height) + Number(length)
|
top = Number(target.top) + Number(length)
|
||||||
top = hasMargin ? top + Number(target.height) : top
|
top = hasMargin ? top + Number(target.height) : top
|
||||||
} else if (direction === 'left') {
|
} else if (direction === 'left') {
|
||||||
left = Number(target.left) - Number(length)
|
left = Number(target.left) - Number(length)
|
||||||
@ -584,6 +571,29 @@ export function useModule() {
|
|||||||
.filter((obj) => [BATCH_TYPE.OPENING, BATCH_TYPE.TRIANGLE_DORMER, BATCH_TYPE.PENTAGON_DORMER, BATCH_TYPE.SHADOW].includes(obj.name))
|
.filter((obj) => [BATCH_TYPE.OPENING, BATCH_TYPE.TRIANGLE_DORMER, BATCH_TYPE.PENTAGON_DORMER, BATCH_TYPE.SHADOW].includes(obj.name))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getIsOverlapOtherModules = (module, otherModules) => {
|
||||||
|
return otherModules.some(
|
||||||
|
(otherModule) =>
|
||||||
|
turf.booleanOverlap(polygonToTurfPolygon(module, true), polygonToTurfPolygon(otherModule, true)) ||
|
||||||
|
turf.booleanWithin(polygonToTurfPolygon(module, true), polygonToTurfPolygon(otherModule, true)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const getIsOverlapObjects = (module, objects) => {
|
||||||
|
return !objects.some(
|
||||||
|
(object) =>
|
||||||
|
turf.booleanOverlap(polygonToTurfPolygon(module, true), polygonToTurfPolygon(object, true)) ||
|
||||||
|
turf.booleanWithin(polygonToTurfPolygon(module, true), polygonToTurfPolygon(object, true)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const getIsOutsideSurface = (module, moduleSetupSurface) => {
|
||||||
|
return (
|
||||||
|
!turf.booleanContains(polygonToTurfPolygon(moduleSetupSurface, true), polygonToTurfPolygon(module, true)) ||
|
||||||
|
!turf.booleanWithin(polygonToTurfPolygon(module, true), polygonToTurfPolygon(moduleSetupSurface, true))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
moduleMove,
|
moduleMove,
|
||||||
moduleMultiMove,
|
moduleMultiMove,
|
||||||
|
|||||||
@ -429,7 +429,8 @@ export function useModuleBasicSetting() {
|
|||||||
dormerTurfPolygon = batchObjectGroupToTurfPolygon(object)
|
dormerTurfPolygon = batchObjectGroupToTurfPolygon(object)
|
||||||
} else {
|
} else {
|
||||||
//개구, 그림자
|
//개구, 그림자
|
||||||
dormerTurfPolygon = polygonToTurfPolygon(rectToPolygon(object))
|
object.set({ points: rectToPolygon(object) })
|
||||||
|
dormerTurfPolygon = polygonToTurfPolygon(object)
|
||||||
}
|
}
|
||||||
|
|
||||||
const intersection = turf.intersect(turf.featureCollection([dormerTurfPolygon, tempTurfModule])) //겹치는지 확인
|
const intersection = turf.intersect(turf.featureCollection([dormerTurfPolygon, tempTurfModule])) //겹치는지 확인
|
||||||
@ -566,35 +567,35 @@ export function useModuleBasicSetting() {
|
|||||||
return containsBatchObjects
|
return containsBatchObjects
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 도머나 개구가 모듈에 걸치는지 확인하는 로직
|
// * 도머나 개구가 모듈에 걸치는지 확인하는 로직
|
||||||
* @param {*} squarePolygon
|
// * @param {*} squarePolygon
|
||||||
* @param {*} containsBatchObjects
|
// * @param {*} containsBatchObjects
|
||||||
* @returns
|
// * @returns
|
||||||
*/
|
// */
|
||||||
const checkModuleDisjointObjects = (squarePolygon, containsBatchObjects) => {
|
// const checkModuleDisjointObjects = (squarePolygon, containsBatchObjects) => {
|
||||||
let isDisjoint = false
|
// let isDisjoint = false
|
||||||
|
//
|
||||||
if (containsBatchObjects.length > 0) {
|
// if (containsBatchObjects.length > 0) {
|
||||||
let convertBatchObject
|
// let convertBatchObject
|
||||||
//도머가 있으면 적용되는 로직
|
// //도머가 있으면 적용되는 로직
|
||||||
isDisjoint = containsBatchObjects.every((batchObject) => {
|
// isDisjoint = containsBatchObjects.every((batchObject) => {
|
||||||
if (batchObject.type === 'group') {
|
// if (batchObject.type === 'group') {
|
||||||
convertBatchObject = batchObjectGroupToTurfPolygon(batchObject)
|
// convertBatchObject = batchObjectGroupToTurfPolygon(batchObject)
|
||||||
} else {
|
// } else {
|
||||||
convertBatchObject = polygonToTurfPolygon(batchObject)
|
// convertBatchObject = polygonToTurfPolygon(batchObject)
|
||||||
}
|
// }
|
||||||
/**
|
// /**
|
||||||
* 도머가 여러개일수있으므로 겹치는게 있다면...
|
// * 도머가 여러개일수있으므로 겹치는게 있다면...
|
||||||
* 안겹치는지 확인하는 로직이라 안겹치면 true를 반환
|
// * 안겹치는지 확인하는 로직이라 안겹치면 true를 반환
|
||||||
*/
|
// */
|
||||||
return turf.booleanDisjoint(squarePolygon, convertBatchObject)
|
// return turf.booleanDisjoint(squarePolygon, convertBatchObject)
|
||||||
})
|
// })
|
||||||
} else {
|
// } else {
|
||||||
isDisjoint = true
|
// isDisjoint = true
|
||||||
}
|
// }
|
||||||
return isDisjoint
|
// return isDisjoint
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 배치면 안에 있는지 확인
|
* 배치면 안에 있는지 확인
|
||||||
@ -1997,36 +1998,6 @@ export function useModuleBasicSetting() {
|
|||||||
return containsBatchObjects
|
return containsBatchObjects
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 도머나 개구가 모듈에 걸치는지 확인하는 로직
|
|
||||||
* @param {*} squarePolygon
|
|
||||||
* @param {*} containsBatchObjects
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
const checkModuleDisjointObjects = (squarePolygon, containsBatchObjects) => {
|
|
||||||
let isDisjoint = false
|
|
||||||
|
|
||||||
if (containsBatchObjects.length > 0) {
|
|
||||||
let convertBatchObject
|
|
||||||
//도머가 있으면 적용되는 로직
|
|
||||||
isDisjoint = containsBatchObjects.every((batchObject) => {
|
|
||||||
if (batchObject.type === 'group') {
|
|
||||||
convertBatchObject = batchObjectGroupToTurfPolygon(batchObject)
|
|
||||||
} else {
|
|
||||||
convertBatchObject = polygonToTurfPolygon(batchObject)
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 도머가 여러개일수있으므로 겹치는게 있다면...
|
|
||||||
* 안겹치는지 확인하는 로직이라 안겹치면 true를 반환
|
|
||||||
*/
|
|
||||||
return turf.booleanDisjoint(squarePolygon, convertBatchObject)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
isDisjoint = true
|
|
||||||
}
|
|
||||||
return isDisjoint
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 배치면 안에 있는지 확인
|
* 배치면 안에 있는지 확인
|
||||||
* @param {*} squarePolygon
|
* @param {*} squarePolygon
|
||||||
@ -2287,6 +2258,39 @@ export function useModuleBasicSetting() {
|
|||||||
//드래그 하기위해 기능 활성화
|
//드래그 하기위해 기능 활성화
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 도머나 개구가 모듈에 걸치는지 확인하는 로직
|
||||||
|
* @param {*} squarePolygon
|
||||||
|
* @param {*} containsBatchObjects
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const checkModuleDisjointObjects = (squarePolygon, containsBatchObjects) => {
|
||||||
|
let isDisjoint = false
|
||||||
|
|
||||||
|
if (containsBatchObjects.length > 0) {
|
||||||
|
let convertBatchObject
|
||||||
|
//도머가 있으면 적용되는 로직
|
||||||
|
isDisjoint = containsBatchObjects.every((batchObject) => {
|
||||||
|
if (batchObject.type === 'group') {
|
||||||
|
convertBatchObject = batchObjectGroupToTurfPolygon(batchObject)
|
||||||
|
} else {
|
||||||
|
if (!batchObject.points) {
|
||||||
|
batchObject.set({ points: rectToPolygon(batchObject) })
|
||||||
|
}
|
||||||
|
convertBatchObject = polygonToTurfPolygon(batchObject)
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 도머가 여러개일수있으므로 겹치는게 있다면...
|
||||||
|
* 안겹치는지 확인하는 로직이라 안겹치면 true를 반환
|
||||||
|
*/
|
||||||
|
return turf.booleanDisjoint(squarePolygon, convertBatchObject)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
isDisjoint = true
|
||||||
|
}
|
||||||
|
return isDisjoint
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
makeModuleInstArea,
|
makeModuleInstArea,
|
||||||
manualModuleSetup,
|
manualModuleSetup,
|
||||||
@ -2294,5 +2298,6 @@ export function useModuleBasicSetting() {
|
|||||||
restoreModuleInstArea,
|
restoreModuleInstArea,
|
||||||
manualFlatroofModuleSetup,
|
manualFlatroofModuleSetup,
|
||||||
autoFlatroofModuleSetup,
|
autoFlatroofModuleSetup,
|
||||||
|
checkModuleDisjointObjects,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user