diff --git a/B07_DesignDetail/openwebcad/src/inputController/ime-sink.ts b/B07_DesignDetail/openwebcad/src/inputController/ime-sink.ts index 327220356..ae60c87a3 100644 --- a/B07_DesignDetail/openwebcad/src/inputController/ime-sink.ts +++ b/B07_DesignDetail/openwebcad/src/inputController/ime-sink.ts @@ -9,12 +9,33 @@ import { getActiveToolActor } from '../state.ts'; export const isImeKey = (evt: KeyboardEvent): boolean => evt.isComposing || evt.keyCode === 229 || evt.key === 'Process'; +/** 활성 도구의 지금 단계 설정(평평한 단계만) */ +const activeStateConfig = () => { + const snapshot = getActiveToolActor()?.getSnapshot(); + return snapshot?.machine?.states?.[snapshot?.value]?.config; +}; + /** 활성 도구의 지금 단계가 TEXT_INPUT 을 받는가 */ export function activeToolAcceptsText(): boolean { - const snapshot = getActiveToolActor()?.getSnapshot(); - return !!snapshot?.machine?.states?.[snapshot?.value]?.config?.on?.TEXT_INPUT; + return !!activeStateConfig()?.on?.TEXT_INPUT; } +/** 지금 단계가 점(`x,y`)을 받는가 — 한 번 스냅 이름 · 선택지 판정 */ +export function activeToolWantsPoint(): boolean { + return !!activeStateConfig()?.on?.ABSOLUTE_POINT_INPUT; +} + +/** 지금 단계가 이 글을 받는가 — 점 단계는 선택지 글자(meta.options · 선 C · U)만 · 나머지는 명령 이름으로 */ +export function activeToolTakesText(text: string): boolean { + if (!activeToolAcceptsText()) return false; + if (!activeToolWantsPoint()) return true; + const options = (activeStateConfig()?.meta as { options?: string[] } | undefined)?.options; + return !!options?.includes(text); +} + +/** 한글 받개에 초점을 줄 단계 — 글은 받되 점 단계 선택지(영문 C · U)는 아님 */ +export const activeToolWantsIme = (): boolean => activeToolAcceptsText() && !activeToolWantsPoint(); + /** 지금 단계가 자유 글(TEXT · MTEXT · 표 칸 · 이름 …)을 받는가 — Space 가 띄어쓰기(아니면 Enter) */ export function activeToolWantsFreeText(): boolean { const meta = getActiveToolActor()?.getSnapshot()?.getMeta?.() as diff --git a/B07_DesignDetail/openwebcad/src/inputController/input-controller.ts b/B07_DesignDetail/openwebcad/src/inputController/input-controller.ts index 768d6fec9..5c257cfc6 100644 --- a/B07_DesignDetail/openwebcad/src/inputController/input-controller.ts +++ b/B07_DesignDetail/openwebcad/src/inputController/input-controller.ts @@ -17,6 +17,7 @@ import { getClosestSnapPointWithinRadius } from '../helpers/get-closest-snap-poi import { pickRadius } from '../helpers/pick-radius.ts'; import { getActiveToolActor, + getAngleGuideOriginPoint, getAngleStep, getCanvas, getPickableEntities, @@ -46,8 +47,10 @@ import { Tool } from '../tools.ts'; import { SelectState, selectToolStateMachine } from '../tools/select-tool.ts'; import { ActorEvent, type MouseClickEvent, type TextInputEvent } from '../tools/tool.types.ts'; import { - activeToolAcceptsText, + activeToolTakesText, activeToolWantsFreeText, + activeToolWantsIme, + activeToolWantsPoint, ImeSink, isImeKey, isPlainSpace, @@ -58,6 +61,13 @@ import { wheelZoom } from './input-wheel.ts'; import { attachTouch } from './input-touch.ts'; import { ANGLE_LOCK_REGEXP, parsePointText, type PointTextEvent } from './input-patterns.ts'; import { angleLockHint, setAngleLock } from './input-angle-lock.ts'; +import { + getSnapOverride, + isSnapName, + setSnapOverride, + snapOverrideHint, + snapOverridePoint, +} from './input-snap-override.ts'; /** 이만큼 넘게 끌면 클릭이 아니라 드래그로 본다 (화면 픽셀) */ const DRAG_SELECT_MIN_PX = 4; @@ -112,7 +122,7 @@ export class InputController { } public draw(drawController: ScreenCanvasDrawController) { - this.ime.sync(activeToolAcceptsText()); + this.ime.sync(activeToolWantsIme()); const toolInstruction = getLastStateInstructions(); const texts: string[] = []; if (toolInstruction) { @@ -122,8 +132,7 @@ export class InputController { const roundedY = round(drawController.getWorldMouseLocation().y, 2); texts.push(`${roundedX},${roundedY}`); } - const lockHint = angleLockHint(); - if (lockHint) texts.push(lockHint); + texts.push(...compact([angleLockHint(), snapOverrideHint()])); // 입력 중인 문자로 시작하는 명령 후보. 예: C => CIRCLE (C), COPY (CO) texts.push(...this.getCommandSuggestions()); // 입력 글(조합 중인 한글도 함께) @@ -173,7 +182,7 @@ export class InputController { return; } this.sendMouseClick(evt); - this.ime.sync(activeToolAcceptsText()); // 클릭으로 문자 단계에 들면 바로 한글 받개로 + this.ime.sync(activeToolWantsIme()); // 클릭으로 문자 단계에 들면 바로 한글 받개로 } } @@ -200,7 +209,12 @@ export class InputController { const worldMouseLocationTemp = screenCanvasDrawController.targetToWorld( this.getCanvasPoint(evt) ); - const worldMouseLocation = closestSnapPoint ? closestSnapPoint.point : worldMouseLocationTemp; + let worldMouseLocation = closestSnapPoint ? closestSnapPoint.point : worldMouseLocationTemp; + if (getSnapOverride()) { + const snapped = snapOverridePoint(worldMouseLocationTemp, getAngleGuideOriginPoint()); + if (!snapped) return; // 맞는 점 없음 — 다시 누르기를 기다림 + worldMouseLocation = snapped; + } this.sendPointEvent({ type: ActorEvent.MOUSE_CLICK, @@ -408,12 +422,12 @@ export class InputController { } else if (evt.key === 'Enter') { // User wants to submit the input or submit the action this.handleEnterKey(true); - this.ime.sync(activeToolAcceptsText()); + this.ime.sync(activeToolWantsIme()); } else if (evt.key === ' ' && !activeToolWantsFreeText()) { // Space = Enter(오토캐드) · 글 단계는 아래 띄어쓰기 · 수정키 · 길게 눌러 반복은 무시 if (isPlainSpace(evt)) { this.handleEnterKey(true); - this.ime.sync(activeToolAcceptsText()); + this.ime.sync(activeToolWantsIme()); } } else if (evt.key === 'ArrowDown') { // Move the screen down @@ -438,6 +452,7 @@ export class InputController { public handleEscapeKey() { setAngleLock(null); + setSnapOverride(null); if (getSelectedEntities().length > 0) { // Deselect entities setSelectedEntityIds([]); @@ -463,7 +478,6 @@ export class InputController { /** @param repeatIfIdle 키보드 Enter · Space — 빈 입력 + 선택 도구 대기면 마지막 명령 반복(우클릭은 확정만) */ public handleEnterKey(repeatIfIdle = false) { // submit the text as input to the active tool and clear the input field - const activeToolCanHandleTextInput = activeToolAcceptsText(); if (this.text === '') { console.log('ENTER: ', { @@ -496,8 +510,12 @@ export class InputController { // 거리 `100` · `x,y` · `@x,y` · `@d> = { + END: SnapPointType.LineEndPoint, + MID: SnapPointType.LineMidPoint, + CEN: SnapPointType.CircleCenter, +}; + +let override: SnapName | null = null; + +export const getSnapOverride = (): SnapName | null => override; +export const setSnapOverride = (name: SnapName | null) => { + override = name; +}; +export const isSnapName = (text: string): text is SnapName => text in SNAP_LABELS; + +/** 커서 옆 안내 줄 */ +export const snapOverrideHint = (): string | null => + override ? `${SNAP_LABELS[override]}(${override}) 한 번 — 점 지정` : null; + +const closest = (points: Point[], mouse: Point, radius: number): Point | null => { + let best: Point | null = null; + let bestDistance = radius; + for (const point of points) { + const distance = Math.hypot(point.x - mouse.x, point.y - mouse.y); + if (distance <= bestDistance) { + best = point; + bestDistance = distance; + } + } + return best; +}; + +/** 한 번 스냅이 고른 점 · 맞는 점 없으면 null. base = 앞 점(PER 기준) */ +export function snapOverridePoint(mouse: Point, base: Point | null): Point | null { + if (override === 'NON') return mouse; + // ponytail: 일반 스냅(15px)의 두 배 둘레 — 오토캐드 조준 상자 크기 설정이 필요하면 설정 모달로 + const radius = (SNAP_POINT_DISTANCE * 2) / getScreenCanvasDrawController().getScreenScale(); + const entities = queryEntitiesNearPoint(mouse.x, mouse.y, radius).filter( + (entity) => !getLayerById(entity.layerId)?.isLocked + ); + const type = override ? SNAP_TYPES[override] : undefined; + if (type) { + const points = entities.flatMap((entity) => + entity + .getSnapPoints() + .filter((snap) => snap.type === type) + .map((snap) => snap.point) + ); + return closest(points, mouse, radius); + } + if (override === 'INT') return closest(getIntersectionPoints(entities), mouse, radius); + const near = findClosestEntity(mouse, entities); + if (!near.entity || near.distance > radius) return null; + if (override === 'NEA') return near.segment.start; + // PER — 앞 점에서 커서 아래 객체로 내린 발(선분이면 수선의 발) + if (!base) return null; + return near.entity.distanceTo(base)?.[1].start ?? null; +} diff --git a/B07_DesignDetail/openwebcad/src/tools/align-tool.helpers.ts b/B07_DesignDetail/openwebcad/src/tools/align-tool.helpers.ts index 0f1c2c495..fac184b20 100644 --- a/B07_DesignDetail/openwebcad/src/tools/align-tool.helpers.ts +++ b/B07_DesignDetail/openwebcad/src/tools/align-tool.helpers.ts @@ -57,7 +57,7 @@ export function GET_ALIGN_TOOL_STATE(type: Tool): MachineContext { [AlignState.WAITING_FOR_SELECTION]: { description: 'Select what you want to align', meta: { - instructions: 'Select what you want to align, then ENTER', + instructions: '정렬할 객체 선택 뒤 Enter', }, invoke: { id: 'selectToolInsideTheAlignTool', diff --git a/B07_DesignDetail/openwebcad/src/tools/array-tool.ts b/B07_DesignDetail/openwebcad/src/tools/array-tool.ts index 2fd83edff..be817e7d2 100644 --- a/B07_DesignDetail/openwebcad/src/tools/array-tool.ts +++ b/B07_DesignDetail/openwebcad/src/tools/array-tool.ts @@ -91,7 +91,7 @@ export const arrayToolStateMachine = createMachine( [ArrayState.WAITING_FOR_SELECTION]: { description: 'Select what you want to copy', meta: { - instructions: 'Select what you want to copy, then ENTER', + instructions: '배열할 객체 선택 뒤 Enter', }, invoke: { id: 'selectToolInsideTheCopyTool', @@ -145,7 +145,7 @@ export const arrayToolStateMachine = createMachine( ], }, [ArrayState.ASK_COPY_MODE]: { - meta: { instructions: 'Choose copy mode: Linear (L) or Radial (R), ENTER for Linear' }, + meta: { instructions: '배열 방식 [직선(L)/원형(R)] <직선>:' }, on: { TEXT_INPUT: { actions: assign(({ event }) => { @@ -168,7 +168,7 @@ export const arrayToolStateMachine = createMachine( }, }, [ArrayState.ASK_NUMBER_OF_COPIES]: { - meta: { instructions: 'Enter number of copies' }, + meta: { instructions: '복사 개수 입력:' }, on: { NUMBER_INPUT: [ { @@ -196,7 +196,7 @@ export const arrayToolStateMachine = createMachine( }, }, [ArrayState.LINEAR_WAITING_FOR_START_POINT]: { - meta: { instructions: 'Click to define the start of the distance vector' }, + meta: { instructions: '간격 시작점 지정:' }, on: { ABSOLUTE_POINT_INPUT: { actions: assign(({ event }) => ({ @@ -216,7 +216,7 @@ export const arrayToolStateMachine = createMachine( }, }, [ArrayState.LINEAR_WAITING_FOR_END_POINT]: { - meta: { instructions: 'Click to define the end of the distance vector' }, + meta: { instructions: '간격 끝점 지정:' }, on: { RELATIVE_POINT_INPUT: { actions: assign(({ event, context }) => ({ @@ -245,7 +245,7 @@ export const arrayToolStateMachine = createMachine( }, }, [ArrayState.RADIAL_WAITING_FOR_PIVOT_POINT]: { - meta: { instructions: 'Click to set pivot point' }, + meta: { instructions: '회전 중심점 지정:' }, on: { ABSOLUTE_POINT_INPUT: { actions: assign(({ event }) => ({ @@ -265,7 +265,7 @@ export const arrayToolStateMachine = createMachine( }, }, [ArrayState.RADIAL_WAITING_FOR_ANGLE]: { - meta: { instructions: 'Enter angle per step (in degrees)' }, + meta: { instructions: '한 칸 각도(도) 입력:' }, on: { NUMBER_INPUT: { target: ArrayState.EXECUTE_COPY, diff --git a/B07_DesignDetail/openwebcad/src/tools/circle-tool.ts b/B07_DesignDetail/openwebcad/src/tools/circle-tool.ts index cbd81db8f..8f992f6c9 100644 --- a/B07_DesignDetail/openwebcad/src/tools/circle-tool.ts +++ b/B07_DesignDetail/openwebcad/src/tools/circle-tool.ts @@ -60,7 +60,7 @@ export const circleToolStateMachine = createMachine( [CircleState.WAITING_FOR_CENTER_POINT]: { description: 'Select the center point of the circle tool', meta: { - instructions: 'Select the center point of the circle', + instructions: '중심점 지정 (x,y):', }, on: { MOUSE_CLICK: { @@ -79,7 +79,7 @@ export const circleToolStateMachine = createMachine( [CircleState.WAITING_FOR_POINT_ON_CIRCLE]: { description: 'Select a point on the circle', meta: { - instructions: 'Select the point on the circle', + instructions: '원 위의 점 지정 또는 반지름 입력:', }, on: { DRAW: { diff --git a/B07_DesignDetail/openwebcad/src/tools/copy-tool.ts b/B07_DesignDetail/openwebcad/src/tools/copy-tool.ts index 25b7d8542..2a24a8503 100644 --- a/B07_DesignDetail/openwebcad/src/tools/copy-tool.ts +++ b/B07_DesignDetail/openwebcad/src/tools/copy-tool.ts @@ -97,7 +97,7 @@ export const copyToolStateMachine = createMachine( [CopyState.WAITING_FOR_SELECTION]: { description: 'Select what you want to copy', meta: { - instructions: 'Select what you want to copy, then ENTER', + instructions: '복사할 객체 선택 뒤 Enter', }, invoke: { id: 'selectToolInsideTheCopyTool', @@ -136,9 +136,9 @@ export const copyToolStateMachine = createMachine( }, }, [CopyState.WAITING_FOR_START_COPY_POINT]: { - description: 'Select the start of the copy line', + description: '기준점 지정 (x,y):', meta: { - instructions: 'Select the start of the copy line', + instructions: '기준점 지정 (x,y):', }, always: { actions: CopyAction.ENABLE_HELPERS, @@ -159,9 +159,9 @@ export const copyToolStateMachine = createMachine( }, }, [CopyState.WAITING_FOR_END_COPY_POINT]: { - description: 'Select the end of the copy line', + description: '둘째 점 지정 (길이 · <각도 · @x,y):', meta: { - instructions: 'Select the end of the copy line', + instructions: '둘째 점 지정 (길이 · <각도 · @x,y):', }, on: { DRAW: { diff --git a/B07_DesignDetail/openwebcad/src/tools/eraser-tool.ts b/B07_DesignDetail/openwebcad/src/tools/eraser-tool.ts index 5aedd0898..933a54d2e 100644 --- a/B07_DesignDetail/openwebcad/src/tools/eraser-tool.ts +++ b/B07_DesignDetail/openwebcad/src/tools/eraser-tool.ts @@ -60,9 +60,9 @@ export const eraserToolStateMachine = createMachine( }, }, [EraserState.WAITING_FOR_FIRST_CLICK]: { - description: 'Select a line segment to delete', + description: '지울 선 선택', meta: { - instructions: 'Select a line segment to delete', + instructions: '지울 선 선택', }, on: { // TODO implement a DRAW action to draw the segment that will be erased in dotted line diff --git a/B07_DesignDetail/openwebcad/src/tools/image-import-tool.ts b/B07_DesignDetail/openwebcad/src/tools/image-import-tool.ts index 81f9b313b..ab3070427 100644 --- a/B07_DesignDetail/openwebcad/src/tools/image-import-tool.ts +++ b/B07_DesignDetail/openwebcad/src/tools/image-import-tool.ts @@ -70,9 +70,9 @@ export const imageImportToolStateMachine = createMachine( }, }, [ImageImportState.WAIT_FOR_IMAGE_DATA]: { - description: 'Select an image file to import', + description: '가져올 그림 파일 선택', meta: { - instructions: 'Select an image file to import', + instructions: '가져올 그림 파일 선택', }, on: { [ActorEvent.FILE_SELECTED]: { @@ -85,9 +85,9 @@ export const imageImportToolStateMachine = createMachine( }, }, [ImageImportState.WAITING_FOR_START_POINT]: { - description: 'Select the start point of the imageImport', + description: '그림 첫 모서리 지정:', meta: { - instructions: 'Select the start point of the imageImport', + instructions: '그림 첫 모서리 지정:', }, on: { MOUSE_CLICK: { @@ -101,9 +101,9 @@ export const imageImportToolStateMachine = createMachine( }, }, [ImageImportState.WAITING_FOR_END_POINT]: { - description: 'Select the end point of the imageImport', + description: '그림 맞은 모서리 지정:', meta: { - instructions: 'Select the end point of the imageImport', + instructions: '그림 맞은 모서리 지정:', }, on: { DRAW: { diff --git a/B07_DesignDetail/openwebcad/src/tools/line-tool.ts b/B07_DesignDetail/openwebcad/src/tools/line-tool.ts index 4ea1cb27a..2f02d7f85 100644 --- a/B07_DesignDetail/openwebcad/src/tools/line-tool.ts +++ b/B07_DesignDetail/openwebcad/src/tools/line-tool.ts @@ -2,6 +2,7 @@ import type { Point } from '@flatten-js/core'; import { LineEntity } from '../entities/LineEntity'; import { addEntities, + deleteEntities, getActiveLayerId, getActiveLineColor, getActiveLineDash, @@ -14,12 +15,22 @@ import { } from '../state'; import { Tool } from '../tools'; import { Actor, assign, createMachine } from 'xstate'; -import type { DrawEvent, PointInputEvent, StateEvent, ToolContext } from './tool.types'; +import type { + DrawEvent, + PointInputEvent, + StateEvent, + TextInputEvent, + ToolContext, +} from './tool.types'; import { selectToolStateMachine } from './select-tool.ts'; import { getPointFromEvent } from '../helpers/get-point-from-event.ts'; export interface LineContext extends ToolContext { startPoint: Point | null; + /** 이번 이어 그리기의 첫 점 — 닫기(C) */ + firstPoint: Point | null; + /** 이번 이어 그리기에서 그린 구간 — 명령취소(U) */ + segments: LineEntity[]; } export enum LineState { @@ -33,6 +44,8 @@ export enum LineAction { RECORD_START_POINT = 'RECORD_START_POINT', DRAW_TEMP_LINE = 'DRAW_TEMP_LINE', DRAW_FINAL_LINE = 'DRAW_FINAL_LINE', + CLOSE_LINE = 'CLOSE_LINE', + UNDO_SEGMENT = 'UNDO_SEGMENT', SWITCH_TO_SELECT_TOOL = 'SWITCH_TO_SELECT_TOOL', } @@ -44,6 +57,8 @@ export const lineToolStateMachine = createMachine( }, context: { startPoint: null, + firstPoint: null, + segments: [], type: Tool.LINE, }, initial: LineState.INIT, @@ -58,7 +73,7 @@ export const lineToolStateMachine = createMachine( [LineState.WAITING_FOR_START_POINT]: { description: 'Select the start point of the line', meta: { - instructions: 'Select the start point of the line', + instructions: '첫 점 지정 (x,y):', }, on: { MOUSE_CLICK: { @@ -77,7 +92,8 @@ export const lineToolStateMachine = createMachine( [LineState.WAITING_FOR_END_POINT]: { description: 'Select the end point of the line', meta: { - instructions: 'Select the end point of the line', + instructions: '다음 점 지정 또는 [닫기(C)/명령취소(U)]:', + options: ['C', 'U'], }, on: { DRAW: { @@ -99,6 +115,21 @@ export const lineToolStateMachine = createMachine( actions: LineAction.DRAW_FINAL_LINE, target: LineState.WAITING_FOR_END_POINT, }, + TEXT_INPUT: [ + { + // 닫기 — 둘째 선부터 · 첫 점으로 잇고 끝 + guard: ({ context, event }) => + (event as TextInputEvent).value === 'C' && context.segments.length >= 2, + actions: LineAction.CLOSE_LINE, + target: LineState.INIT, + }, + { + // 명령취소 — 마지막 구간만 + guard: ({ context, event }) => + (event as TextInputEvent).value === 'U' && context.segments.length > 0, + actions: LineAction.UNDO_SEGMENT, + }, + ], ESC: { target: LineState.INIT, }, @@ -118,6 +149,8 @@ export const lineToolStateMachine = createMachine( setAngleGuideOriginPoint(null); return { startPoint: null, + firstPoint: null, + segments: [], }; }), [LineAction.RECORD_START_POINT]: assign(({ event }) => { @@ -125,6 +158,8 @@ export const lineToolStateMachine = createMachine( setAngleGuideOriginPoint(startPoint); return { startPoint, + firstPoint: startPoint, + segments: [], }; }), [LineAction.DRAW_TEMP_LINE]: ({ context, event }) => { @@ -159,8 +194,28 @@ export const lineToolStateMachine = createMachine( setAngleGuideOriginPoint(endPoint); return { startPoint: endPoint, + segments: [...context.segments, activeLine], }; }), + [LineAction.CLOSE_LINE]: ({ context }) => { + const closing = new LineEntity( + getActiveLayerId(), + context.startPoint as Point, + context.firstPoint as Point + ); + closing.lineColor = getActiveLineColor(); + closing.lineWidth = getActiveLineWidth(); + closing.lineDash = getActiveLineDash(); + addEntities([closing], true); + }, + [LineAction.UNDO_SEGMENT]: assign(({ context }) => { + const last = context.segments[context.segments.length - 1]; + deleteEntities([last], true); + const startPoint = last.getStartPoint(); + setGhostHelperEntities([new LineEntity(getActiveLayerId(), startPoint, startPoint)]); + setAngleGuideOriginPoint(startPoint); + return { startPoint, segments: context.segments.slice(0, -1) }; + }), [LineAction.SWITCH_TO_SELECT_TOOL]: () => { setActiveToolActor(new Actor(selectToolStateMachine)); }, diff --git a/B07_DesignDetail/openwebcad/src/tools/move-tool.ts b/B07_DesignDetail/openwebcad/src/tools/move-tool.ts index a2fe3cbfd..3517c1ce4 100644 --- a/B07_DesignDetail/openwebcad/src/tools/move-tool.ts +++ b/B07_DesignDetail/openwebcad/src/tools/move-tool.ts @@ -98,7 +98,7 @@ export const moveToolStateMachine = createMachine( [MoveState.WAITING_FOR_SELECTION]: { description: 'Select what you want to move', meta: { - instructions: 'Select what you want to move, then ENTER', + instructions: '이동할 객체 선택 뒤 Enter', }, invoke: { id: 'selectToolInsideTheMoveTool', @@ -137,9 +137,9 @@ export const moveToolStateMachine = createMachine( }, }, [MoveState.WAITING_FOR_START_MOVE_POINT]: { - description: 'Select the start of the move line', + description: '기준점 지정 (x,y):', meta: { - instructions: 'Select the start of the move line', + instructions: '기준점 지정 (x,y):', }, always: { actions: MoveAction.ENABLE_HELPERS, @@ -160,9 +160,9 @@ export const moveToolStateMachine = createMachine( }, }, [MoveState.WAITING_FOR_END_MOVE_POINT]: { - description: 'Select the end of the move line', + description: '둘째 점 지정 (길이 · <각도 · @x,y):', meta: { - instructions: 'Select the end of the move line', + instructions: '둘째 점 지정 (길이 · <각도 · @x,y):', }, on: { DRAW: { diff --git a/B07_DesignDetail/openwebcad/src/tools/pedit-tool.ts b/B07_DesignDetail/openwebcad/src/tools/pedit-tool.ts index d00c3874f..83c7f330b 100644 --- a/B07_DesignDetail/openwebcad/src/tools/pedit-tool.ts +++ b/B07_DesignDetail/openwebcad/src/tools/pedit-tool.ts @@ -75,7 +75,7 @@ export const peditToolStateMachine = createMachine( [PeditState.WAITING_FOR_SELECTION]: { description: 'Select the entities that you want to combine into a polyline', meta: { - instructions: 'Select what you want to combine into a polyline, then ENTER', + instructions: '폴리선으로 합칠 객체 선택 뒤 Enter', }, invoke: { id: 'selectToolInsideThePeditTool', diff --git a/B07_DesignDetail/openwebcad/src/tools/rectangle-tool.ts b/B07_DesignDetail/openwebcad/src/tools/rectangle-tool.ts index aa375f5d6..afee826d8 100644 --- a/B07_DesignDetail/openwebcad/src/tools/rectangle-tool.ts +++ b/B07_DesignDetail/openwebcad/src/tools/rectangle-tool.ts @@ -53,9 +53,9 @@ export const rectangleToolStateMachine = createMachine( }, }, [RectangleState.WAITING_FOR_START_POINT]: { - description: 'Select the start point of the rectangle', + description: '첫 모서리 지정 (x,y):', meta: { - instructions: 'Select the start point of the rectangle', + instructions: '첫 모서리 지정 (x,y):', }, on: { MOUSE_CLICK: { @@ -69,9 +69,9 @@ export const rectangleToolStateMachine = createMachine( }, }, [RectangleState.WAITING_FOR_END_POINT]: { - description: 'Select the end point of the rectangle', + description: '맞은 모서리 지정 (@x,y):', meta: { - instructions: 'Select the end point of the rectangle', + instructions: '맞은 모서리 지정 (@x,y):', }, on: { DRAW: { diff --git a/B07_DesignDetail/openwebcad/src/tools/rotate-tool.ts b/B07_DesignDetail/openwebcad/src/tools/rotate-tool.ts index c2930e017..619c7e63e 100644 --- a/B07_DesignDetail/openwebcad/src/tools/rotate-tool.ts +++ b/B07_DesignDetail/openwebcad/src/tools/rotate-tool.ts @@ -105,7 +105,7 @@ export const rotateToolStateMachine = createMachine( [RotateState.WAITING_FOR_SELECTION]: { description: 'Select what you want to rotate', meta: { - instructions: 'Select what you want to rotate, then ENTER', + instructions: '회전할 객체 선택 뒤 Enter', }, invoke: { id: 'selectToolInsideTheRotateTool', @@ -144,9 +144,9 @@ export const rotateToolStateMachine = createMachine( }, }, [RotateState.WAITING_FOR_ROTATION_ORIGIN]: { - description: 'Select the origin of the rotate operation', + description: '기준점 지정 (x,y):', meta: { - instructions: 'Select the origin of the rotate operation', + instructions: '기준점 지정 (x,y):', }, always: { actions: RotateAction.ENABLE_HELPERS, @@ -167,9 +167,9 @@ export const rotateToolStateMachine = createMachine( }, }, [RotateState.WAITING_FOR_ANGLE_START_POINT]: { - description: 'Select the end of the base rotate line', + description: '회전 각도 입력 또는 기준선 끝점 지정:', meta: { - instructions: 'Select the end of the base rotate line', + instructions: '회전 각도 입력 또는 기준선 끝점 지정:', }, on: { MOUSE_CLICK: { @@ -195,9 +195,9 @@ export const rotateToolStateMachine = createMachine( }, }, [RotateState.WAITING_FOR_ANGLE_END_POINT]: { - description: 'Select the end of the rotate line', + description: '회전 방향 점 지정:', meta: { - instructions: 'Select the end of the rotate line', + instructions: '회전 방향 점 지정:', }, on: { DRAW: { diff --git a/B07_DesignDetail/openwebcad/src/tools/select-tool.ts b/B07_DesignDetail/openwebcad/src/tools/select-tool.ts index 55a339266..62aa98e41 100644 --- a/B07_DesignDetail/openwebcad/src/tools/select-tool.ts +++ b/B07_DesignDetail/openwebcad/src/tools/select-tool.ts @@ -57,7 +57,7 @@ export const selectToolStateMachine = createMachine( [SelectState.WAITING_FOR_FIRST_SELECT_POINT]: { description: 'Select a line or select the first point of a selection rectangle', meta: { - instructions: 'Select a line or start drawing a selection rectangle', + instructions: '객체 선택 또는 선택 상자 시작', }, on: { MOUSE_CLICK: { @@ -79,7 +79,7 @@ export const selectToolStateMachine = createMachine( [SelectState.CHECK_SELECTION]: { description: 'Checking to select one line or start drawing a selection rectangle', meta: { - instructions: 'Select one line or start drawing a selection rectangle', + instructions: '객체 하나 선택 또는 선택 상자 시작', }, always: [ { @@ -95,9 +95,9 @@ export const selectToolStateMachine = createMachine( ], }, [SelectState.WAITING_FOR_SECOND_SELECT_POINT]: { - description: 'Select the second point of a selection rectangle', + description: '선택 상자 맞은 모서리 지정', meta: { - instructions: 'Select the second point of a selection rectangle', + instructions: '선택 상자 맞은 모서리 지정', }, on: { DRAW: { diff --git a/resources/tester/cad/keyboard-chain.test.ts b/resources/tester/cad/keyboard-chain.test.ts index af5d1a5d6..a10e808fc 100644 --- a/resources/tester/cad/keyboard-chain.test.ts +++ b/resources/tester/cad/keyboard-chain.test.ts @@ -13,9 +13,11 @@ vi.mock("react-toastify", () => ({ import { toast } from "react-toastify"; import { InputController } from "../../../B07_DesignDetail/openwebcad/src/inputController/input-controller"; import { getAngleLock } from "../../../B07_DesignDetail/openwebcad/src/inputController/input-angle-lock"; +import { getSnapOverride } from "../../../B07_DesignDetail/openwebcad/src/inputController/input-snap-override"; import { getActiveToolActor, getEntities, + getLastStateInstructions, setEntities, setSelectedEntityIds, } from "../../../B07_DesignDetail/openwebcad/src/state"; @@ -197,3 +199,83 @@ describe("331-2 이동 · 복사 · 회전 키보드 값", () => { expect(toast.error).not.toHaveBeenCalled(); }); }); + +describe("331-3 선 중 C · U · 한 번 스냅 · 한글 안내", () => { + const drawOpen = () => { + type(controller, "l"); + type(controller, "0,0"); + type(controller, "10,0"); + type(controller, "10,10"); + }; + + it("C = 첫 점으로 닫고 끝 · 안내 「[닫기(C)/명령취소(U)]」", () => { + drawOpen(); + expect(getLastStateInstructions()).toBe("다음 점 지정 또는 [닫기(C)/명령취소(U)]:"); + type(controller, "c"); + const drawn = lines(); + expect(drawn).toHaveLength(3); + expectXy(drawn[2].start, 10, 10); + expectXy(drawn[2].end, 0, 0); + expect(getActiveToolActor()?.getSnapshot()?.value).toBe("WAITING_FOR_START_POINT"); + expect(getLastStateInstructions()).toBe("첫 점 지정 (x,y):"); + }); + + it("C 는 둘째 선부터 — 한 구간이면 무시", () => { + type(controller, "l"); + type(controller, "0,0"); + type(controller, "10,0"); + type(controller, "c"); + expect(lines()).toHaveLength(1); + expect(getActiveToolActor()?.getSnapshot()?.value).toBe("WAITING_FOR_END_POINT"); + }); + + it("U = 마지막 한 구간만 취소 · 그 시작점에서 이어 그림", () => { + drawOpen(); + type(controller, "u"); + expect(lines()).toHaveLength(1); + type(controller, "20,0"); + const drawn = lines(); + expect(drawn).toHaveLength(2); + expectXy(drawn[1].start, 10, 0); + expectXy(drawn[1].end, 20, 0); + }); + + it("선 중 다른 명령 이름은 그대로 명령", () => { + drawOpen(); + type(controller, "circle"); + expect(getActiveToolActor()?.getSnapshot()?.context.type).toBe("CIRCLE"); + }); + + it("END 한 번 — 둘레 안 끝점으로 · 한 점 뒤 풂", () => { + type(controller, "l"); + type(controller, "0,0"); + type(controller, "100,0"); + key(controller, "Escape"); + type(controller, "end"); + expect(getSnapOverride()).toBe("END"); + clickAt(controller, 80, 20); // 끝점 (100, 0) 에서 28 — 일반 스냅(15)은 못 닿음 + expect(getSnapOverride()).toBeNull(); + type(controller, "@0,10"); + const drawn = lines(); + expect(drawn).toHaveLength(2); + expectXy(drawn[1].start, 100, 0); + expectXy(drawn[1].end, 100, 10); + }); + + it("END 둘레에 끝점 없으면 클릭 버림 · Esc 로 풂", () => { + type(controller, "l"); + type(controller, "end"); + clickAt(controller, 500, 500); + expect(getActiveToolActor()?.getSnapshot()?.value).toBe("WAITING_FOR_START_POINT"); + expect(getSnapOverride()).toBe("END"); + key(controller, "Escape"); + expect(getSnapOverride()).toBeNull(); + }); + + it("점 단계가 아니면 END 는 스냅 아님", () => { + key(controller, "Escape"); + key(controller, "Escape"); + type(controller, "end"); + expect(getSnapOverride()).toBeNull(); + }); +});