외벽선 작성 작업중
This commit is contained in:
parent
d256acaa56
commit
8834f975a8
@ -6,11 +6,13 @@ import { useMessage } from '@/hooks/useMessage'
|
|||||||
import { post } from '@/lib/Axios'
|
import { post } from '@/lib/Axios'
|
||||||
import { useRecoilState } from 'recoil'
|
import { useRecoilState } from 'recoil'
|
||||||
import { settingModalFirstOptionsState } from '@/store/settingAtom'
|
import { settingModalFirstOptionsState } from '@/store/settingAtom'
|
||||||
|
import { verticalHorizontalModeState } from '@/store/canvasAtom'
|
||||||
|
|
||||||
export default function CanvasMenu(props) {
|
export default function CanvasMenu(props) {
|
||||||
const [objectNo] = useState('test123240912001')
|
const [objectNo] = useState('test123240912001')
|
||||||
const { setShowCanvasSettingModal, showOutlineModal, setShowOutlineModal } = props
|
const { setShowCanvasSettingModal, showOutlineModal, setShowOutlineModal } = props
|
||||||
const [menuNumber, setMenuNumber] = useState(null)
|
const [menuNumber, setMenuNumber] = useState(null)
|
||||||
|
const [verticalHorizontalMode, setVerticalHorizontalMode] = useRecoilState(verticalHorizontalModeState)
|
||||||
const [vertical, setVertical] = useState(true)
|
const [vertical, setVertical] = useState(true)
|
||||||
const [type, setType] = useState('')
|
const [type, setType] = useState('')
|
||||||
const { getMessage } = useMessage()
|
const { getMessage } = useMessage()
|
||||||
@ -135,9 +137,9 @@ export default function CanvasMenu(props) {
|
|||||||
<button className="btn03 "></button>
|
<button className="btn03 "></button>
|
||||||
</div>
|
</div>
|
||||||
{menuNumber !== 4 && (
|
{menuNumber !== 4 && (
|
||||||
<div className={`vertical-horizontal ${vertical ? 'on' : ''}`}>
|
<div className={`vertical-horizontal ${verticalHorizontalMode ? 'on' : ''}`}>
|
||||||
<span>{getMessage('plan.mode.vertical.horizontal')}</span>
|
<span>{getMessage('plan.mode.vertical.horizontal')}</span>
|
||||||
<button onClick={() => setVertical(!vertical)}>{vertical ? 'ON' : 'OFF'}</button>
|
<button onClick={() => setVerticalHorizontalMode(!verticalHorizontalMode)}>{verticalHorizontalMode ? 'ON' : 'OFF'}</button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="select-box">
|
<div className="select-box">
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import WithDraggable from '@/components/common/draggable/withDraggable'
|
|||||||
import { useRecoilState, useRecoilValue } from 'recoil'
|
import { useRecoilState, useRecoilValue } from 'recoil'
|
||||||
import { useMessage } from '@/hooks/useMessage'
|
import { useMessage } from '@/hooks/useMessage'
|
||||||
import { useEvent } from '@/hooks/useEvent'
|
import { useEvent } from '@/hooks/useEvent'
|
||||||
import { canvasState } from '@/store/canvasAtom'
|
import { canvasState, verticalHorizontalModeState } from '@/store/canvasAtom'
|
||||||
import {
|
import {
|
||||||
OUTER_LINE_TYPE,
|
OUTER_LINE_TYPE,
|
||||||
outerLineArrow1State,
|
outerLineArrow1State,
|
||||||
@ -17,12 +17,15 @@ import {
|
|||||||
} from '@/store/outerLineAtom'
|
} from '@/store/outerLineAtom'
|
||||||
import { QLine } from '@/components/fabric/QLine'
|
import { QLine } from '@/components/fabric/QLine'
|
||||||
import { useLine } from '@/hooks/useLine'
|
import { useLine } from '@/hooks/useLine'
|
||||||
|
import { distanceBetweenPoints } from '@/util/canvas-util'
|
||||||
|
|
||||||
export default function OuterLineWall(props) {
|
export default function OuterLineWall(props) {
|
||||||
const { setShowOutlineModal } = props
|
const { setShowOutlineModal } = props
|
||||||
const { getMessage } = useMessage()
|
const { getMessage } = useMessage()
|
||||||
const { addCanvasMouseEventListener, addDocumentEventListener, removeAllDocumentEventListeners } = useEvent()
|
const { addCanvasMouseEventListener, addDocumentEventListener, removeAllMouseEventListeners, removeAllDocumentEventListeners } = useEvent()
|
||||||
const { addLineText, removeLineText } = useLine()
|
const { addLineText, removeLineText } = useLine()
|
||||||
|
const verticalHorizontalMode = useRecoilValue(verticalHorizontalModeState)
|
||||||
|
|
||||||
const length1Ref = useRef(null)
|
const length1Ref = useRef(null)
|
||||||
const length2Ref = useRef(null)
|
const length2Ref = useRef(null)
|
||||||
const [length1, setLength1] = useRecoilState(outerLineLength1State)
|
const [length1, setLength1] = useRecoilState(outerLineLength1State)
|
||||||
@ -37,8 +40,9 @@ export default function OuterLineWall(props) {
|
|||||||
const canvas = useRecoilValue(canvasState)
|
const canvas = useRecoilValue(canvasState)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
removeAllMouseEventListeners()
|
||||||
addCanvasMouseEventListener('mouse:down', mouseDown)
|
addCanvasMouseEventListener('mouse:down', mouseDown)
|
||||||
}, [])
|
}, [verticalHorizontalMode, points])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
arrow1Ref.current = arrow1
|
arrow1Ref.current = arrow1
|
||||||
@ -64,8 +68,44 @@ export default function OuterLineWall(props) {
|
|||||||
|
|
||||||
const mouseDown = (e) => {
|
const mouseDown = (e) => {
|
||||||
const pointer = canvas.getPointer(e.e)
|
const pointer = canvas.getPointer(e.e)
|
||||||
|
if (points.length === 0) {
|
||||||
|
setPoints((prev) => [...prev, pointer])
|
||||||
|
} else {
|
||||||
|
const lastPoint = points[points.length - 1]
|
||||||
|
let newPoint = { x: pointer.x, y: pointer.y }
|
||||||
|
const length = distanceBetweenPoints(lastPoint, newPoint)
|
||||||
|
if (verticalHorizontalMode) {
|
||||||
|
const vector = {
|
||||||
|
x: pointer.x - points[points.length - 1].x,
|
||||||
|
y: pointer.y - points[points.length - 1].y,
|
||||||
|
}
|
||||||
|
const slope = Math.abs(vector.y / vector.x) // 기울기 계산
|
||||||
|
|
||||||
setPoints((prev) => [...prev, pointer])
|
let scaledVector
|
||||||
|
if (slope >= 1) {
|
||||||
|
// 기울기가 1 이상이면 x축 방향으로 그림
|
||||||
|
scaledVector = {
|
||||||
|
x: 0,
|
||||||
|
y: vector.y >= 0 ? Number(length) : -Number(length),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 기울기가 1 미만이면 y축 방향으로 그림
|
||||||
|
scaledVector = {
|
||||||
|
x: vector.x >= 0 ? Number(length) : -Number(length),
|
||||||
|
y: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const verticalLength = scaledVector.y
|
||||||
|
const horizontalLength = scaledVector.x
|
||||||
|
|
||||||
|
newPoint = {
|
||||||
|
x: lastPoint.x + horizontalLength,
|
||||||
|
y: lastPoint.y + verticalLength,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setPoints((prev) => [...prev, newPoint])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -77,6 +117,11 @@ export default function OuterLineWall(props) {
|
|||||||
removeLineText(obj)
|
removeLineText(obj)
|
||||||
})
|
})
|
||||||
canvas?.remove(canvas?.getObjects().find((obj) => obj.name === 'startPoint'))
|
canvas?.remove(canvas?.getObjects().find((obj) => obj.name === 'startPoint'))
|
||||||
|
|
||||||
|
// point가 변경 될때마다 이벤트 리스너를 제거하고 다시 등록
|
||||||
|
removeAllDocumentEventListeners()
|
||||||
|
addDocumentEventListener('keydown', document, keydown[type])
|
||||||
|
|
||||||
if (points.length === 0) {
|
if (points.length === 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -190,6 +235,9 @@ export default function OuterLineWall(props) {
|
|||||||
|
|
||||||
const keydown = {
|
const keydown = {
|
||||||
outerLine: (e) => {
|
outerLine: (e) => {
|
||||||
|
if (points.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const key = e.key
|
const key = e.key
|
||||||
|
|
||||||
if (!length1Ref.current) {
|
if (!length1Ref.current) {
|
||||||
@ -245,11 +293,12 @@ export default function OuterLineWall(props) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
rightAngle: (e) => {
|
rightAngle: (e) => {
|
||||||
|
if (points.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const key = e.key
|
const key = e.key
|
||||||
|
|
||||||
const activeElem = document.activeElement
|
const activeElem = document.activeElement
|
||||||
const length1Num = Number(length1Ref.current.value) / 10
|
|
||||||
const length2Num = Number(length2Ref.current.value) / 10
|
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'Down': // IE/Edge에서 사용되는 값
|
case 'Down': // IE/Edge에서 사용되는 값
|
||||||
|
|||||||
@ -13,11 +13,6 @@ export function useEvent() {
|
|||||||
if (!canvas) {
|
if (!canvas) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Object.keys(canvas.__eventListeners).forEach((key) => {
|
|
||||||
if (key.indexOf('mouse') > -1) {
|
|
||||||
canvas.off(key)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
removeAllMouseEventListeners()
|
removeAllMouseEventListeners()
|
||||||
removeAllDocumentEventListeners()
|
removeAllDocumentEventListeners()
|
||||||
addDefaultEvent()
|
addDefaultEvent()
|
||||||
@ -112,6 +107,7 @@ export function useEvent() {
|
|||||||
return {
|
return {
|
||||||
addDocumentEventListener,
|
addDocumentEventListener,
|
||||||
addCanvasMouseEventListener,
|
addCanvasMouseEventListener,
|
||||||
|
removeAllMouseEventListeners,
|
||||||
removeAllDocumentEventListeners,
|
removeAllDocumentEventListeners,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,20 @@
|
|||||||
import { useRecoilValue } from 'recoil'
|
import { useRecoilValue } from 'recoil'
|
||||||
import { canvasState, fontSizeState } from '@/store/canvasAtom'
|
import { canvasState, fontFamilyState, fontSizeState } from '@/store/canvasAtom'
|
||||||
|
|
||||||
export const useLine = () => {
|
export const useLine = () => {
|
||||||
const canvas = useRecoilValue(canvasState)
|
const canvas = useRecoilValue(canvasState)
|
||||||
const fontSize = useRecoilValue(fontSizeState)
|
const fontSize = useRecoilValue(fontSizeState)
|
||||||
|
const fontFamily = useRecoilValue(fontFamilyState)
|
||||||
|
|
||||||
|
const addLine = (points = [], options) => {
|
||||||
|
const line = new fabric.Line(points, {
|
||||||
|
...options,
|
||||||
|
selectable: options.selectable ?? false,
|
||||||
|
})
|
||||||
|
|
||||||
|
canvas?.add(line)
|
||||||
|
return line
|
||||||
|
}
|
||||||
|
|
||||||
const addLineText = (line) => {
|
const addLineText = (line) => {
|
||||||
removeLineText(line)
|
removeLineText(line)
|
||||||
@ -14,9 +25,11 @@ export const useLine = () => {
|
|||||||
parent: line,
|
parent: line,
|
||||||
name: 'lengthTxt',
|
name: 'lengthTxt',
|
||||||
fontSize: fontSize,
|
fontSize: fontSize,
|
||||||
|
fontFamily: fontFamily,
|
||||||
})
|
})
|
||||||
|
|
||||||
canvas?.add(text)
|
canvas?.add(text)
|
||||||
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeLineText = (line) => {
|
const removeLineText = (line) => {
|
||||||
|
|||||||
@ -1,8 +1,24 @@
|
|||||||
import { canvasState } from '@/store/canvasAtom'
|
import { canvasState, fontFamilyState, fontSizeState } from '@/store/canvasAtom'
|
||||||
import { useRecoilValue } from 'recoil'
|
import { useRecoilValue } from 'recoil'
|
||||||
|
|
||||||
export const usePolygon = () => {
|
export const usePolygon = () => {
|
||||||
const canvas = useRecoilValue(canvasState)
|
const canvas = useRecoilValue(canvasState)
|
||||||
|
const fontSize = useRecoilValue(fontSizeState)
|
||||||
|
const fontFamily = useRecoilValue(fontFamilyState)
|
||||||
|
|
||||||
return {}
|
const addPolygon = (points, options) => {
|
||||||
|
const polygon = new fabric.Polygon(points, {
|
||||||
|
...options,
|
||||||
|
selectable: options.selectable ?? false,
|
||||||
|
})
|
||||||
|
|
||||||
|
canvas?.add(polygon)
|
||||||
|
}
|
||||||
|
|
||||||
|
const addPolygonByLines = (lines) => {}
|
||||||
|
|
||||||
|
return {
|
||||||
|
addPolygon,
|
||||||
|
addPolygonByLines,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,11 @@ export const guideModeLineState = atom({
|
|||||||
default: false,
|
default: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const fontFamilyState = atom({
|
||||||
|
key: 'fontFamilyState',
|
||||||
|
default: 'Noto Sans KR',
|
||||||
|
})
|
||||||
|
|
||||||
export const fontSizeState = atom({
|
export const fontSizeState = atom({
|
||||||
key: 'fontSizeState',
|
key: 'fontSizeState',
|
||||||
default: 16,
|
default: 16,
|
||||||
@ -185,3 +190,9 @@ export const currentMenuState = atom({
|
|||||||
key: 'currentMenu',
|
key: 'currentMenu',
|
||||||
default: MENU.INITIAL_CANVAS_SETTING,
|
default: MENU.INITIAL_CANVAS_SETTING,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 수직 수평 모드
|
||||||
|
export const verticalHorizontalModeState = atom({
|
||||||
|
key: 'verticalHorizontalMode',
|
||||||
|
default: true,
|
||||||
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user