보조선 작성 수정

This commit is contained in:
hyojun.choi 2024-10-17 17:04:25 +09:00
parent dae4de6825
commit 32f648c559
3 changed files with 50 additions and 38 deletions

View File

@ -27,7 +27,7 @@ export default function QContextMenu(props) {
const handleContextMenu = (e) => { const handleContextMenu = (e) => {
// e.preventDefault() // contextmenu // e.preventDefault() // contextmenu
setContextMenu({ visible: true, x: e.pageX, y: e.pageY }) setContextMenu({ visible: true, x: e.pageX, y: e.pageY })
console.log(111, canvasProps) // console.log(111, canvasProps)
canvasProps?.upperCanvasEl.removeEventListener('contextmenu', handleContextMenu) // canvasProps?.upperCanvasEl.removeEventListener('contextmenu', handleContextMenu) //
} }

View File

@ -538,59 +538,66 @@ export function useAuxiliaryDrawing(setShowAuxiliaryModal) {
// 보조선 절삭 // 보조선 절삭
const cutAuxiliary = (e) => { const cutAuxiliary = (e) => {
const auxiliaryLines = canvas.getObjects().filter((obj) => obj.name === 'auxiliaryLine' && !obj.isFixed) const auxiliaryLines = canvas.getObjects().filter((obj) => obj.name === 'auxiliaryLine')
if (auxiliaryLines.length === 0) { if (auxiliaryLines.length === 0) {
return return
} }
const roofBases = canvas.getObjects().filter((obj) => obj.name === 'roofBase')
const allLines = [...auxiliaryLines]
roofBases.forEach((roofBase) => {
roofBase.lines.forEach((line) => {
allLines.push(line)
})
})
auxiliaryLines.forEach((line1) => { auxiliaryLines.forEach((line1) => {
auxiliaryLines.forEach((line2) => { allLines.forEach((line2) => {
const lines = [line1, line2]
if (line1 === line2) { if (line1 === line2) {
return return
} }
const intersectionPoint = calculateIntersection(line1, line2) const intersectionPoint = calculateIntersection(line1, line2)
if (!intersectionPoint || intersectionPoints.current.some((point) => point.x === intersectionPoint.x && point.y === intersectionPoint.y)) { if (!intersectionPoint) {
return return
} }
roofAdsorptionPoints.current.push(intersectionPoint) roofAdsorptionPoints.current.push(intersectionPoint)
intersectionPoints.current.push(intersectionPoint) intersectionPoints.current.push(intersectionPoint)
lines.forEach((line) => {
const distance1 = distanceBetweenPoints({ x: line.x1, y: line.y1 }, intersectionPoint)
const distance2 = distanceBetweenPoints({ x: line.x2, y: line.y2 }, intersectionPoint)
if (distance1 === 0 || distance2 === 0) { const distance1 = distanceBetweenPoints({ x: line1.x1, y: line1.y1 }, intersectionPoint)
return const distance2 = distanceBetweenPoints({ x: line1.x2, y: line1.y2 }, intersectionPoint)
}
//historyLine에서 기존 line을 제거한다.
lineHistory.current = lineHistory.current.filter((history) => history !== line)
let newLine if (distance1 === 0 || distance2 === 0) {
return
}
//historyLine에서 기존 line을 제거한다.
lineHistory.current = lineHistory.current.filter((history) => history !== line1)
if (distance1 >= distance2) { let newLine
newLine = addLine([line.x1, line.y1, intersectionPoint.x, intersectionPoint.y], {
stroke: 'black', if (distance1 >= distance2) {
strokeWidth: 1, newLine = addLine([line1.x1, line1.y1, intersectionPoint.x, intersectionPoint.y], {
selectable: false, stroke: 'black',
name: 'auxiliaryLine', strokeWidth: 1,
isFixed: true, selectable: false,
intersectionPoint, name: 'auxiliaryLine',
}) isFixed: true,
} else { intersectionPoint,
newLine = addLine([line.x2, line.y2, intersectionPoint.x, intersectionPoint.y], { })
stroke: 'black', } else {
strokeWidth: 1, newLine = addLine([line1.x2, line1.y2, intersectionPoint.x, intersectionPoint.y], {
selectable: false, stroke: 'black',
name: 'auxiliaryLine', strokeWidth: 1,
isFixed: true, selectable: false,
intersectionPoint, name: 'auxiliaryLine',
}) isFixed: true,
} intersectionPoint,
lineHistory.current.push(newLine) })
removeLine(line) }
}) lineHistory.current.push(newLine)
removeLine(line1)
}) })
}) })
addCanvasMouseEventListener('mouse:move', mouseMove) addCanvasMouseEventListener('mouse:move', mouseMove)

View File

@ -36,6 +36,8 @@ export function useRoofShapePassivitySetting(setShowRoofShapePassivitySettingMod
const isFix = useRef(false) const isFix = useRef(false)
const initLines = useRef([]) const initLines = useRef([])
const [isLoading, setIsLoading] = useState(false)
const buttons = [ const buttons = [
{ id: 1, name: getMessage('eaves'), type: TYPES.EAVES }, { id: 1, name: getMessage('eaves'), type: TYPES.EAVES },
{ id: 2, name: getMessage('gable'), type: TYPES.GABLE }, { id: 2, name: getMessage('gable'), type: TYPES.GABLE },
@ -49,10 +51,13 @@ export function useRoofShapePassivitySetting(setShowRoofShapePassivitySettingMod
if (!outerLineFix || outerLines.length === 0) { if (!outerLineFix || outerLines.length === 0) {
swalFire({ text: '외벽선이 없습니다.' }) swalFire({ text: '외벽선이 없습니다.' })
setShowRoofShapePassivitySettingModal(false) setShowRoofShapePassivitySettingModal(false)
return
} }
setIsLoading(true)
}, []) }, [])
useEffect(() => { useEffect(() => {
if (!isLoading) return
addCanvasMouseEventListener('mouse:down', mouseDown) addCanvasMouseEventListener('mouse:down', mouseDown)
const wallLines = canvas.getObjects().filter((obj) => obj.name === 'wallLine') const wallLines = canvas.getObjects().filter((obj) => obj.name === 'wallLine')
@ -75,7 +80,7 @@ export function useRoofShapePassivitySetting(setShowRoofShapePassivitySettingMod
canvas?.discardActiveObject() canvas?.discardActiveObject()
initEvent() initEvent()
} }
}, []) }, [isLoading])
useEffect(() => { useEffect(() => {
const lines = canvas.getObjects().filter((obj) => obj.name === 'outerLine') const lines = canvas.getObjects().filter((obj) => obj.name === 'outerLine')