- 새 input-angle-lock — 다음 한 점만 고정 방향(동쪽 0° 반시계) · 커서 · 클릭은 고정 직선 위로 · 숫자는 그 방향 길이 · 한 점 · Esc · 새 명령이면 풂 · 커서 옆 안내 「각도 30° 고정 — 길이 입력」 - input-patterns — 숫자 음수 · .5 허용 · 각도 고정 꼴 · 점 글 해석 한 곳(parsePointText) - Enter 해석 차례 — 자유 글 단계만 원문 먼저 → 각도 고정 → 점 · 거리 → 단계 선택지 → 명령 이름 - 선 · 시퀀스 미리보기도 고정 방향 · 시퀀스 첫 점의 거리 · 상대 좌표는 무시(도구 멈춤 · 「Error in tool actor」 없앰) - 시험 resources/tester/cad/keyboard-chain.test.ts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013QyNXY2TUKXCFMwAca2APG
73 lines
2.8 KiB
TypeScript
73 lines
2.8 KiB
TypeScript
/** 명령 실행기 — 리본 버튼·명령행·단축키가 모두 이 경로로 들어온다. */
|
|
import { toast } from 'react-toastify';
|
|
import { Actor } from 'xstate';
|
|
import { HtmlEvent } from '../App.types';
|
|
import { setAngleLock } from '../inputController/input-angle-lock';
|
|
import { getSelectedEntities, isDrawingReadOnly, notifyWindow, setActiveToolActor } from '../state';
|
|
import type { CadCommand } from './command.types';
|
|
import { getCommandById, isViewOnlyCommand, resolveCommandInput } from './registry';
|
|
|
|
const COMMAND_HISTORY_LIMIT = 200;
|
|
|
|
let lastCommandId: string | null = null;
|
|
const commandHistory: string[] = [];
|
|
|
|
export const getLastCommandId = (): string | null => lastCommandId;
|
|
export const getCommandHistory = (): string[] => commandHistory;
|
|
|
|
function log(line: string) {
|
|
commandHistory.push(line);
|
|
if (commandHistory.length > COMMAND_HISTORY_LIMIT) {
|
|
commandHistory.splice(0, commandHistory.length - COMMAND_HISTORY_LIMIT);
|
|
}
|
|
notifyWindow(HtmlEvent.UPDATE_STATE);
|
|
}
|
|
|
|
/** 명령 한 건 실행. 도구형이면 도구를 활성화하고, 즉시형이면 run()을 부른다. */
|
|
export function runCommand(command: CadCommand): string {
|
|
// 확정한 도면은 읽기 전용이다 — 보는 명령만 통과시킨다. 리본·명령행·단축키가 모두
|
|
// 이 한 곳을 지나므로 여기서 한 번 막으면 새는 길이 없다 (2026-09-01 사용자 확정).
|
|
if (isDrawingReadOnly() && !isViewOnlyCommand(command)) {
|
|
toast.info(`확정한 도면입니다. 고치려면 [수정]을 먼저 누르세요. (${command.label})`);
|
|
log(`${command.id}: 확정 도면 — 실행하지 않음`);
|
|
return '';
|
|
}
|
|
if (command.needsSelection && getSelectedEntities().length === 0) {
|
|
toast.info(`${command.label}: 객체를 먼저 선택하십시오.`);
|
|
log(`${command.id}: 선택 없음`);
|
|
return '';
|
|
}
|
|
|
|
lastCommandId = command.id;
|
|
setAngleLock(null); // 앞 명령의 각도 고정은 새 명령에 넘기지 않음
|
|
|
|
if (command.machine) {
|
|
setActiveToolActor(new Actor(command.machine));
|
|
// 도구를 켠 뒤 준비 동작이 필요한 명령(파일 선택 등)은 run()도 함께 부른다
|
|
command.run?.();
|
|
log(`${command.id} ${command.label}`);
|
|
return command.id;
|
|
}
|
|
|
|
const result = command.run?.();
|
|
log(`${command.id} ${typeof result === 'string' ? result : command.label}`);
|
|
return typeof result === 'string' ? result : command.id;
|
|
}
|
|
|
|
/** 명령 이름·별칭 문자열로 실행 (명령행 입력) */
|
|
export function runCommandInput(input: string): boolean {
|
|
const command = resolveCommandInput(input);
|
|
if (!command) return false;
|
|
runCommand(command);
|
|
return true;
|
|
}
|
|
|
|
/** 직전 명령 반복 (AutoCAD의 빈 ENTER 동작) */
|
|
export function repeatLastCommand(): boolean {
|
|
if (!lastCommandId) return false;
|
|
const command = getCommandById(lastCommandId);
|
|
if (!command) return false;
|
|
runCommand(command);
|
|
return true;
|
|
}
|