/** * PEDIT — 고른 선 · 호를 폴리선 하나로 묶음. 고르기 물음 = 오토캐드 「객체 선택:」(337 라 · 설계 2-14 ④) · * 고른 것 있으면 바로 · 빈 고르기 Enter · Esc = 끝 · 묶은 뒤 끝(쉬는 상태). */ import { toast } from 'react-toastify'; import { createMachine } from 'xstate'; import { PolyLineEntity } from '../entities/PolyLineEntity.ts'; import { getActiveLayerId, getNotSelectedEntities, getSelectedEntities, setEntities, } from '../state'; import { Tool } from '../tools'; import { END_STATE, type StateEvent, type ToolContext } from './tool.types'; import { endState, selectionState, startState } from './transform.helpers'; export interface PeditContext extends ToolContext {} export enum PeditState { INIT = 'INIT', WAITING_FOR_SELECTION = 'WAITING_FOR_SELECTION', CONVERT_SELECTION_TO_POLYLINE = 'CONVERT_SELECTION_TO_POLYLINE', } const convert = () => { const newPolyLine = new PolyLineEntity(getActiveLayerId(), getSelectedEntities()); setEntities([...getNotSelectedEntities(), newPolyLine], true); toast.success(`Created polyline with ${newPolyLine.numberOfSegments()} segments`); }; // biome-ignore lint/suspicious/noExplicitAny: 공용 상태 조각(여러 도구 공통)을 섞어 만든다 const states: Record = { [PeditState.INIT]: startState(PeditState.CONVERT_SELECTION_TO_POLYLINE), [PeditState.WAITING_FOR_SELECTION]: selectionState(PeditState.CONVERT_SELECTION_TO_POLYLINE), [PeditState.CONVERT_SELECTION_TO_POLYLINE]: { always: { actions: convert, target: END_STATE }, }, [END_STATE]: endState, }; /** 고른 객체를 폴리선 하나로 */ export const peditToolStateMachine = createMachine({ types: {} as { context: PeditContext & { originals: unknown[] }; events: StateEvent }, context: { originals: [], type: Tool.PEDIT }, initial: PeditState.INIT, states, });