Files
Aislo/B07_DesignDetail/openwebcad/src/commands/run-command.ts
T
eomsangdonandClaude Opus 5 793e1aad37 fix(B07): 표제란 값 공급 통로 + CAD 회귀 6건 해소
표제란(도각) 값 공급
- `use_title_fields()` 문맥 변수 신설 — 회사 도각 폴더와 같은 방식이라 작도 엔진
  6개의 서명을 고치지 않음. `frame_entities` 가 문맥값 위에 호출부 값(도면명)을 얹음.
- 라우터가 도면 한 건을 그리기 전에 DB 값을 세움: 공사명·위치(projects),
  용역회사(companies), 설계자(users). 못 채운 자리는 빈칸 — 도각 원본의 남의 값이
  도면으로 나가지 않음.
- 미공급 항목과 사유를 `_title_block_fields` 주석에 명시: 시행청·과업책임자·
  분야별책임자는 DB 칸 부재(B02 마이그레이션 대기), 축척·사업량·연도기번은 임의 수치
  금지, 설계일자는 채울 시점 정의 미결.

CAD 회귀 6건 (87건 중 81 passed → 87 passed)
- `window` 부재 5건: `notifyWindow()` 한 곳으로 모으고 `window` 없는 Node 시험에서는
  통지를 건너뜀. `triggerReactUpdate` 가 이미 같은 이유로 시험을 건너뛰던 것과 같은 결.
- `find-closest-entity`: 목의 호가 90°까지만 돌아 클릭점에서 147px 떨어져 있었음 —
  시험 의도(호가 가장 가깝다)대로 3/4바퀴로 되돌림.
- 선색 기대값 4건: 앱 기본 선색이 흰 종이 배경에 맞춰 검정으로 바뀐 뒤 상류 기대값
  `#fff` 가 남아 있었음 — `getActiveLineColor()` 대조로 교체.
- 좌표 NaN: 없어진 `TOOLBAR_WIDTH` 를 시험 보조가 아직 참조 — 입력 컨트롤러가 캔버스
  bounding rect 를 쓰도록 바뀐 현행에 맞춤.
- 호 각도 비교: 같은 각의 음수·2π 표기 차이라 [0, 2π) 정규화 후 대조.

검증: `npx vitest run` 87 passed / 0 failed, `npm run check-types`·`npm run build` 통과,
`pytest tmp/tests/ -q` 131 passed / 0 failed(신규 `test_b07_title_block_fields.py` 4건 포함).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 08:00:39 +09:00

71 lines
2.7 KiB
TypeScript

/** 명령 실행기 — 리본 버튼·명령행·단축키가 모두 이 경로로 들어온다. */
import { toast } from 'react-toastify';
import { Actor } from 'xstate';
import { HtmlEvent } from '../App.types';
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;
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;
}