Merge branch 'dev' into feature/test-jy
This commit is contained in:
commit
1cdd5432f5
@ -1,8 +1,15 @@
|
|||||||
import { fabric } from 'fabric'
|
import { fabric } from 'fabric'
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
import { QLine } from '@/components/fabric/QLine'
|
import { QLine } from '@/components/fabric/QLine'
|
||||||
import { distanceBetweenPoints, findTopTwoIndexesByDistance, getDirectionByPoint, sortedPointLessEightPoint, sortedPoints } from '@/util/canvas-util'
|
import {
|
||||||
import { calculateAngle, drawRidgeRoof, drawShedRoof, inPolygon, toGeoJSON } from '@/util/qpolygon-utils'
|
distanceBetweenPoints,
|
||||||
|
findTopTwoIndexesByDistance,
|
||||||
|
getAllRelatedObjects,
|
||||||
|
getDirectionByPoint,
|
||||||
|
sortedPointLessEightPoint,
|
||||||
|
sortedPoints,
|
||||||
|
} from '@/util/canvas-util'
|
||||||
|
import { calculateAngle, drawRidgeRoof, inPolygon, toGeoJSON } from '@/util/qpolygon-utils'
|
||||||
import * as turf from '@turf/turf'
|
import * as turf from '@turf/turf'
|
||||||
import { LINE_TYPE } from '@/common/common'
|
import { LINE_TYPE } from '@/common/common'
|
||||||
|
|
||||||
@ -131,7 +138,7 @@ export const QPolygon = fabric.util.createClass(fabric.Polygon, {
|
|||||||
})
|
})
|
||||||
|
|
||||||
this.on('removed', () => {
|
this.on('removed', () => {
|
||||||
const children = this.canvas.getObjects().filter((obj) => obj.parentId === this.id)
|
const children = getAllRelatedObjects(this.id, this.canvas)
|
||||||
children.forEach((child) => {
|
children.forEach((child) => {
|
||||||
this.canvas.remove(child)
|
this.canvas.remove(child)
|
||||||
})
|
})
|
||||||
@ -169,6 +176,7 @@ export const QPolygon = fabric.util.createClass(fabric.Polygon, {
|
|||||||
offset: 0,
|
offset: 0,
|
||||||
},
|
},
|
||||||
parent: this,
|
parent: this,
|
||||||
|
parentId: this.id,
|
||||||
direction: getDirectionByPoint(point, nextPoint),
|
direction: getDirectionByPoint(point, nextPoint),
|
||||||
idx: i + 1,
|
idx: i + 1,
|
||||||
})
|
})
|
||||||
|
|||||||
@ -925,3 +925,32 @@ export function checkLineOrientation(line) {
|
|||||||
return 'diagonal' // 대각선
|
return 'diagonal' // 대각선
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 최상위 parentId를 통해 모든 하위 객체를 찾는 함수
|
||||||
|
export const getAllRelatedObjects = (id, canvas) => {
|
||||||
|
const result = []
|
||||||
|
const map = new Map()
|
||||||
|
|
||||||
|
// Create a map of objects by their id
|
||||||
|
canvas.getObjects().forEach((obj) => {
|
||||||
|
map.set(obj.id, obj)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Helper function to recursively find all related objects
|
||||||
|
function findRelatedObjects(id) {
|
||||||
|
const obj = map.get(id)
|
||||||
|
if (obj) {
|
||||||
|
result.push(obj)
|
||||||
|
canvas.getObjects().forEach((o) => {
|
||||||
|
if (o.parentId === id) {
|
||||||
|
findRelatedObjects(o.id)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start the search with the given parentId
|
||||||
|
findRelatedObjects(id)
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user