Files
Aislo/B07_DesignDetail/openwebcad/src/commands/run-command.ts
T
eomsangdonandClaude Opus 5.5 5a1490ddaa fix(527-1): B07 확정 표시 걷음 — 정보칸 「확정/잠정」 배지 · CAD 보기 전용 알림 옛 「확정한 도면 · [수정]」 글 · 저장 실패 글 「확정」 → 「저장」
- [>] 「도면 저장」 단계는 요구 281 · 520-3 그대로(고친 도면만 서버 저장 → 단계 완료 → 이동)
- 서버 끝점 · manifest confirmed 키 = 안쪽 이름이라 그대로(브레인 정함)
- 평면도 설정 모달 배지는 sub5(524) 몫

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 14:28:28 +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;
}