import WithDraggable from '@/components/common/draggable/WithDraggable' import { useEffect, useState } from 'react' import QSelectBox from '@/components/common/select/QSelectBox' import { useRecoilValue } from 'recoil' import { contextPopupPositionState } from '@/store/popupAtom' import { useMessage } from '@/hooks/useMessage' import { usePopup } from '@/hooks/usePopup' import { canvasState } from '@/store/canvasAtom' import { usePolygon } from '@/hooks/usePolygon' import { useSurfaceShapeBatch } from '@/hooks/surface/useSurfaceShapeBatch' import { useRoofFn } from '@/hooks/common/useRoofFn' const FLOW_DIRECTION_TYPE = { EIGHT_AZIMUTH: 'eightAzimuth', TWENTY_FOUR_AZIMUTH: 'twentyFourAzimuth', } export default function FlowDirectionSetting(props) { const contextPopupPosition = useRecoilValue(contextPopupPositionState) const { id, pos = contextPopupPosition, target } = props const canvas = useRecoilValue(canvasState) const { getMessage } = useMessage() const { setSurfaceShapePattern } = useRoofFn() const { changeSurfaceLineType } = useSurfaceShapeBatch({}) useEffect(() => { return () => { canvas?.discardActiveObject() } }, []) const [compasDeg, setCompasDeg] = useState(target.surfaceCompass ?? null) const [flowDirection, setFlowDirection] = useState(target.direction) const { closePopup } = usePopup() useEffect(() => { let newCompassDeg = 0 if ([-15, 0, 15].includes(compasDeg)) { newCompassDeg = 0 } else if ([30, 45, 60].includes(compasDeg)) { newCompassDeg = 45 } else if ([75, 90, 105].includes(compasDeg)) { newCompassDeg = 90 } else if ([120, 135, 150].includes(compasDeg)) { newCompassDeg = 135 } else if ([165, 180, -165].includes(compasDeg)) { newCompassDeg = 180 } else if ([-120, -135, -150].includes(compasDeg)) { newCompassDeg = -135 } else if ([-105, -90, -75].includes(compasDeg)) { newCompassDeg = -90 } else if ([-60, -45, -30].includes(compasDeg)) { newCompassDeg = -45 } else { newCompassDeg = '' } const newOrientation = orientations.find((item) => item.value === newCompassDeg) setSelectedOrientation(newOrientation) }, [compasDeg]) const orientations = [ { name: `${getMessage('commons.none')}`, value: '' }, { name: `${getMessage('commons.south')}`, value: 0 }, { name: `${getMessage('commons.south')}${getMessage('commons.east')}`, value: 45 }, { name: `${getMessage('commons.south')}${getMessage('commons.west')}`, value: -45 }, { name: `${getMessage('commons.east')}`, value: 90 }, { name: `${getMessage('commons.west')}`, value: -90 }, { name: `${getMessage('commons.north')}${getMessage('commons.east')}`, value: 135 }, { name: `${getMessage('commons.north')}${getMessage('commons.west')}`, value: -135 }, { name: `${getMessage('commons.north')}`, value: 180 }, ] const { drawDirectionArrow } = usePolygon() const [type, setType] = useState(target.surfaceCompassType ?? FLOW_DIRECTION_TYPE.EIGHT_AZIMUTH) const changeSurfaceFlowDirection = (roof, direction, orientation) => { roof.set({ direction: direction, surfaceCompass: orientation, surfaceCompassType: type, }) setSurfaceShapePattern(roof, null, null, roof.roofMaterial) drawDirectionArrow(roof) canvas?.renderAll() changeSurfaceLineType(roof) closePopup(id) } const [selectedOrientation, setSelectedOrientation] = useState( target.surfaceCompassType !== null && target.surfaceCompassType === FLOW_DIRECTION_TYPE.EIGHT_AZIMUTH ? orientations.find((item) => item.value === target.surfaceCompass) : orientations[0], ) return ( closePopup(id)} />
{getMessage('modal.flow.direction.setting')}
{getMessage('modal.flow.direction.setting.info')}
{getMessage('commons.north')} {getMessage('commons.east')} {getMessage('commons.south')} {getMessage('commons.west')}
{getMessage('modal.module.basic.setting.orientation.setting')}
{getMessage('modal.shape.flow.direction.setting.orientation.setting.info')}
{ setCompasDeg(0) setType(FLOW_DIRECTION_TYPE.EIGHT_AZIMUTH) }} />
{ if (e.value === '') { setCompasDeg(null) setSelectedOrientation(e) return } setType(FLOW_DIRECTION_TYPE.EIGHT_AZIMUTH) setSelectedOrientation(e) setCompasDeg(e.value) }} showKey={'name'} targetKey={'value'} sourceKey={'value'} />
{ setType(FLOW_DIRECTION_TYPE.TWENTY_FOUR_AZIMUTH) }} />
{Array.from({ length: 180 / 15 }).map((dot, index) => (
{ if (index === 0) { setCompasDeg(180) return } setType(FLOW_DIRECTION_TYPE.TWENTY_FOUR_AZIMUTH) setCompasDeg(-15 * index + 180) }} >
))} {Array.from({ length: 180 / 15 }).map((dot, index) => (
{ setType(FLOW_DIRECTION_TYPE.TWENTY_FOUR_AZIMUTH) setCompasDeg(15 * index * -1) }} >
))}
) }