Files
Aislo/B07_DesignDetail/openwebcad/src/commands/run-command.ts
T
eomsangdonandClaude Opus 5.5 83e246deb4 feat(CAD): 337-1 가-1 옵션 틀 — 물음 꼴 · 친 글 사다리 한 곳 · 명령 끝 → 쉼 · 순서 엔진 v2 · 키보드 흠
- 새 src/commands/prompt.ts — PromptSpec · renderPrompt(키워드 물음은 「또는」 없음) · matchOption(initget 줄임) · 세션 기억 · OPT · SELECT_OBJECTS
- 새 inputController/prompt-input.ts — routeTyped 사다리(점 · 옵션 묻는 중 명령 이름 거절 · 식 · 단위 거절 · 투명 ') · 알림 줄 · 덧물음 · cancelActiveCommand · undoCommand
- 새 tools/factories/end-command.ts — final(END) 갈고리 → 같은 틱 선택 도구 · state.ts 갈고리 · LASTPOINT
- sequence-tool v2 — ROUTE · id · prompt · when · next · options · keyword · loopFrom · escCommits · pickfirst · 확정 뒤 기본 끝 · Esc 늘 끝
- 흠 — N1 ②③ · N5 · N6 · N11 · N18(앞글자 실행 없앰) · H1(Ctrl · Alt 글자 안 쌓음 · Ctrl+C · X · Shift+C · Shift+V · 1) · 우클릭 = 쉴 때 반복 · SE 뺌 · ED 더함
- 시험 — cad-drive 도우미 · prompt-frame · prompt-contract · 옛 시험 손질(keyboard-chain · ime-sink · command-catalog · input-prefs-cad · eraser 녹화)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QfHKQs7J3hQELKMWQMUJEy
2026-10-15 23:55:58 +09:00

76 lines
3.1 KiB
TypeScript

/** 명령 실행기 — 리본 버튼·명령행·단축키가 모두 이 경로로 들어온다. */
import { toast } from 'react-toastify';
import { Actor } from 'xstate';
import { HtmlEvent } from '../App.types';
import { releaseOnePoint } from '../inputController/input-angle-lock';
import { cancelActiveCommand } from '../inputController/prompt-input';
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;
/** 기록 줄에 한 줄(명령 · 거절 · 알림) */
export function logLine(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})`);
logLine(`${command.id}: 확정 도면 — 실행하지 않음`);
return '';
}
if (command.needsSelection && getSelectedEntities().length === 0) {
toast.info(`${command.label}: 객체를 먼저 선택하십시오.`);
logLine(`${command.id}: 선택 없음`);
return '';
}
lastCommandId = command.id;
releaseOnePoint(); // 앞 명령의 각도 고정 · 동적 입력 잠금은 새 명령에 넘기지 않음
if (command.machine) {
cancelActiveCommand(); // 앞 명령을 끊고 켬(오토캐드 ^C^C) · 즉시형은 도구를 둠
setActiveToolActor(new Actor(command.machine));
// 도구를 켠 뒤 준비 동작이 필요한 명령(파일 선택 등)은 run()도 함께 부른다
command.run?.();
logLine(`${command.id} ${command.label}`);
return command.id;
}
const result = command.run?.();
logLine(`${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;
}