feat(B07): CAD를 AutoCAD 명령 체계로 재구성한다 (조사표 1·2·3·5절)

저장소 사고로 잃은 4개 커밋(38eb7cd4·b8a11756·281528bf·f60b488d)의 작업물을
하나로 다시 담았다. 내용은 동일하다.

■ 구조
- commands/: 명령 정의(id·AutoCAD 별칭·글리프·도구/즉시실행)를 단일 소스로 두고
  리본·명령행·단축키가 모두 이 레지스트리를 읽는다. tools/tool.consts.ts 폐지.
- ribbon/: 탭→패널→명령 데이터(ribbon.config.ts)와 범용 렌더러 분리.
  AutoCAD 배치(홈·삽입·주석·뷰·출력)와 패널 확장(▾)을 따른다.
- tools/factories/sequence-tool.ts: 점·숫자·문자·객체·선택 단계를 선언하면
  xstate 머신을 만들어 주는 공장. 명령당 170줄 보일러플레이트 제거.
- helpers/geometry/: 3점 호·정다각형·타원·스플라인·구름형·평행이동·해치 스캔선·
  점렬 샘플링 등 상태 없는 순수 함수.
- Toolbar 483줄을 QuickAccessBar/Ribbon/InspectorPanel/StatusBar/CommandLine/
  ViewControls/PropertiesEditor/QuickProperties로 분해.

■ 명령 (조사표 기준)
- 1절 그리기 21건, 2절 수정 27건, 3절 도면층·특성·그룹·유틸리티 39건 전부 반영.
- 5절 주석 34건 중 26건 반영(문자·치수 16종·지시선·표·구름형·주석 축척).
- HatchEntity 추가(solid·pattern·cross·gradient) + JSON 왕복, Layer에 색·선가중치·
  선종류·동결·투명도 필드 추가, 그리기 루프가 동결·숨김·투명도를 반영.

■ 화면 실측에서 고친 결함
- 명령행 포커스 상태에서 ENTER가 도구로 가지 않던 문제
- 명령행 문자 입력이 접두사가 같은 명령으로 실행되던 문제
- 명령이 끝나도 입력을 계속 먹던 문제(점 입력 명령만 반복, 나머지는 선택 도구 복귀)
- 시퀀스 단계 인덱스 오사용 9건 + 단계 값 종류 검사 추가
- 해치 내부를 클릭해도 선택되지 않던 문제

미반영 8건(맞춤법 검사·꺾기 치수·치수 끊기/재연관/검사 치수·기하공차·지시선 수집·
축척 리스트 편집)은 조사표 `반영` 열과 PLAN.md에 사유를 적었다.
This commit is contained in:
2026-08-30 01:34:13 +09:00
parent 60bbe89edb
commit ea9d9685be
88 changed files with 8052 additions and 850 deletions
@@ -0,0 +1,103 @@
/** 문자 명령 — 여러 줄 문자·단일 행 문자·편집·찾기 (조사표 5절 문자 패널) */
import { Point } from '@flatten-js/core';
import { toast } from 'react-toastify';
import { getAnnotationScale } from '../../commands/dim-settings';
import { EntityName } from '../../entities/Entity';
import type { Entity } from '../../entities/Entity';
import type { TextEntity } from '../../entities/TextEntity';
import { addEntities, getActiveTextStyle, getEntities, setEntities } from '../../state';
import { Tool } from '../../tools';
import { textEntity } from '../factories/entity-factory';
import { createSequenceTool } from '../factories/sequence-tool';
/** AutoCAD 여러 줄 문자의 줄바꿈 표기(\P)와 \n을 모두 받는다 */
const splitLines = (text: string): string[] =>
text
.replace(/\\P/gi, '\n')
.split('\n')
.map((line) => line.trim())
.filter((line) => line.length > 0);
function buildTextLines(lines: string[], basePoint: Point): Entity[] {
const lineHeight = getActiveTextStyle().fontSize * getAnnotationScale() * 1.35;
const groupId = lines.length > 1 ? crypto.randomUUID() : undefined;
return lines.map((line, index) => {
const entity = textEntity(line, new Point(basePoint.x, basePoint.y - lineHeight * index), {
textAlign: 'left',
fontSize: getActiveTextStyle().fontSize * getAnnotationScale(),
});
entity.groupId = groupId;
return entity;
});
}
export const textToolStateMachine = createSequenceTool({
tool: Tool.TEXT,
steps: [
{ kind: 'point', instructions: '문자의 시작점을 지정하십시오.' },
{ kind: 'text', instructions: '문자를 입력하십시오.' },
],
commit: (input) => {
const lines = splitLines(input.text(1));
if (!lines.length) return;
addEntities(buildTextLines(lines.slice(0, 1), input.point(0)), true);
},
});
export const mtextToolStateMachine = createSequenceTool({
tool: Tool.MTEXT,
steps: [
{ kind: 'point', instructions: '여러 줄 문자의 첫 코너를 지정하십시오.' },
{ kind: 'text', instructions: '문자를 입력하십시오 (줄바꿈은 \\P).' },
],
commit: (input) => {
const lines = splitLines(input.text(1));
if (!lines.length) return;
addEntities(buildTextLines(lines, input.point(0)), true);
},
});
export const textEditToolStateMachine = createSequenceTool({
tool: Tool.TEXTEDIT,
helpers: false,
steps: [
{ kind: 'entity', instructions: '편집할 문자를 선택하십시오.' },
{ kind: 'text', instructions: '새 문자를 입력하십시오.' },
],
commit: (input) => {
const entity = input.entity(0);
if (entity.getType() !== EntityName.Text) {
toast.warn('문자 객체를 선택하십시오.');
return;
}
(entity as TextEntity).setLabel(input.text(1));
setEntities([...getEntities()], true);
},
});
export const findToolStateMachine = createSequenceTool({
tool: Tool.FIND,
helpers: false,
steps: [
{ kind: 'text', instructions: '찾을 문자열을 입력하십시오.' },
{ kind: 'text', instructions: '바꿀 문자열을 입력하십시오 (그대로 두려면 ENTER).', defaultValue: '' },
],
commit: (input) => {
const needle = input.text(0);
const replacement = input.text(1);
let found = 0;
let replaced = 0;
for (const entity of getEntities()) {
if (entity.getType() !== EntityName.Text) continue;
const text = entity as TextEntity;
if (!text.getLabel().includes(needle)) continue;
found += 1;
if (replacement) {
text.setLabel(text.getLabel().split(needle).join(replacement));
replaced += 1;
}
}
if (replaced) setEntities([...getEntities()], true);
toast.info(replaced ? `${replaced}개 문자를 바꿨습니다.` : `${found}개 문자를 찾았습니다.`);
},
});