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' 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() useEffect(() => { return () => { canvas?.discardActiveObject() } }, []) const [compasDeg, setCompasDeg] = useState(target.surfaceCompass ?? null) const [flowDirection, setFlowDirection] = useState(target.direction) const { closePopup } = usePopup() const orientations = [ { name: `${getMessage('commons.none')}`, value: 0 }, { name: `${getMessage('commons.south')}`, value: 360 }, { name: `${getMessage('commons.south')}${getMessage('commons.east')}`, value: 315 }, { name: `${getMessage('commons.south')}${getMessage('commons.west')}`, value: 45 }, { name: `${getMessage('commons.east')}`, value: 270 }, { name: `${getMessage('commons.west')}`, value: 90 }, { name: `${getMessage('commons.north')}${getMessage('commons.east')}`, value: 225 }, { 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, }) drawDirectionArrow(roof) canvas?.renderAll() 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 (

{getMessage('modal.shape.flow.direction.setting')}

{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) }} />
{ 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 + 1 }).map((dot, index) => (
{ setType(FLOW_DIRECTION_TYPE.TWENTY_FOUR_AZIMUTH) setCompasDeg(15 * (12 + index)) }} >
))} {Array.from({ length: 180 / 15 - 1 }).map((dot, index) => (
{ setType(FLOW_DIRECTION_TYPE.TWENTY_FOUR_AZIMUTH) setCompasDeg(15 * (index + 1)) }} >
))}
) }