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,209 @@
/** 지시선·표·구름형·스타일 설정 (조사표 5절 지시선·표·표식·주석 축척) */
import { Point } from '@flatten-js/core';
import { toast } from 'react-toastify';
import {
getAnnotationScale,
getDimTextHeight,
getTableColumnWidth,
getTableRowHeight,
setAnnotationScale,
setDimStyle,
setTableStyle,
} from '../../commands/dim-settings';
import type { Entity } from '../../entities/Entity';
import { EntityName } from '../../entities/Entity';
import type { TextEntity } from '../../entities/TextEntity';
import { revisionCloudPoints } from '../../helpers/geometry/shape-points';
import { addEntities, getEntities, setEntities, setSelectedEntityIds } from '../../state';
import { Tool } from '../../tools';
import { lineEntity, polyLineEntity } from '../factories/entity-factory';
import { createSequenceTool } from '../factories/sequence-tool';
import { annotationText, arrowHead, worldFactor } from './annotation.helpers';
export const mleaderToolStateMachine = createSequenceTool({
tool: Tool.MLEADER,
steps: [
{ kind: 'point', instructions: '지시선 화살표 위치를 지정하십시오.' },
{ kind: 'point', instructions: '지시선 꺾임점을 지정하십시오.' },
{ kind: 'text', instructions: '지시선 문자를 입력하십시오.' },
],
preview: (input) => {
const points = input.points();
if (points.length !== 1) return [];
return [lineEntity(points[0], input.cursor), arrowHead(points[0], input.cursor)];
},
commit: (input) => {
const [tip, knee] = input.points();
const textHeight = getDimTextHeight() / worldFactor();
// 꺾임점에서 문자 쪽으로 짧은 가로선을 하나 더 뽑는다 (AutoCAD 지시선 모양)
const landingLength = textHeight * 2;
const toRight = knee.x >= tip.x;
const landingEnd = new Point(knee.x + (toRight ? landingLength : -landingLength), knee.y);
const label = annotationText(input.text(2), new Point(landingEnd.x, landingEnd.y + textHeight * 0.4));
const groupId = crypto.randomUUID();
const parts: Entity[] = [
lineEntity(tip, knee),
lineEntity(knee, landingEnd),
arrowHead(tip, knee),
label,
];
for (const part of parts) part.groupId = groupId;
addEntities(parts, true);
},
});
export const mleaderStyleToolStateMachine = createSequenceTool({
tool: Tool.MLEADERSTYLE,
helpers: false,
steps: [
{ kind: 'number', instructions: '지시선 문자 높이를 입력하십시오 <16>.', defaultValue: 16 },
{ kind: 'number', instructions: '화살표 크기를 입력하십시오 <20>.', defaultValue: 20 },
],
commit: (input) => {
setDimStyle(input.number(0), input.number(1), -1);
toast.success(`지시선 스타일: 문자 ${input.number(0)} · 화살표 ${input.number(1)}`);
},
});
/** 지시선 정렬 — 선택한 지시선 문자의 X 위치를 첫 문자에 맞춘다 */
export const mleaderAlignToolStateMachine = createSequenceTool({
tool: Tool.MLEADERALIGN,
helpers: false,
steps: [{ kind: 'selection', instructions: '정렬할 지시선 문자를 선택한 뒤 ENTER.' }],
commit: (input) => {
const texts = input
.entities(0)
.filter((entity) => entity.getType() === EntityName.Text) as TextEntity[];
if (texts.length < 2) {
toast.warn('지시선 문자를 두 개 이상 선택하십시오.');
return;
}
const targetX = texts[0].getBoundingBox().xmin;
for (const text of texts.slice(1)) {
text.move(targetX - text.getBoundingBox().xmin, 0);
}
setEntities([...getEntities()], true);
setSelectedEntityIds([]);
toast.success(`${texts.length}개 지시선 문자를 정렬했습니다.`);
},
});
export const dimStyleToolStateMachine = createSequenceTool({
tool: Tool.DIMSTYLE,
helpers: false,
steps: [
{ kind: 'number', instructions: '치수 문자 높이를 입력하십시오 <16>.', defaultValue: 16 },
{ kind: 'number', instructions: '화살표 크기를 입력하십시오 <20>.', defaultValue: 20 },
{ kind: 'number', instructions: '소수 자릿수를 입력하십시오 <2>.', defaultValue: 2 },
],
commit: (input) => {
setDimStyle(input.number(0), input.number(1), input.number(2));
setEntities([...getEntities()], false);
toast.success('치수 스타일을 바꿨습니다.');
},
});
/** 치수 업데이트 — 스타일을 바꾼 뒤 화면을 다시 그린다 */
export function updateDimensions(): string {
setEntities([...getEntities()], false);
toast.success('치수를 현재 스타일로 갱신했습니다.');
return '치수 업데이트';
}
export const annotationScaleToolStateMachine = createSequenceTool({
tool: Tool.ANNOSCALE,
helpers: false,
steps: [{ kind: 'number', instructions: '주석 축척 배율을 입력하십시오 <1>.', defaultValue: 1 }],
commit: (input) => {
setAnnotationScale(input.number(0));
setEntities([...getEntities()], false);
toast.success(`주석 축척 ${getAnnotationScale()}배`);
},
});
export const tableStyleToolStateMachine = createSequenceTool({
tool: Tool.TABLESTYLE,
helpers: false,
steps: [
{ kind: 'number', instructions: '열 너비를 입력하십시오 <40>.', defaultValue: 40 },
{ kind: 'number', instructions: '행 높이를 입력하십시오 <10>.', defaultValue: 10 },
],
commit: (input) => {
setTableStyle(input.number(0), input.number(1));
toast.success(`표 스타일: 열 ${input.number(0)} · 행 ${input.number(1)}`);
},
});
export const tableToolStateMachine = createSequenceTool({
tool: Tool.TABLE,
steps: [
{ kind: 'number', instructions: '열 수를 입력하십시오 <3>.', defaultValue: 3 },
{ kind: 'number', instructions: '행 수를 입력하십시오 <3>.', defaultValue: 3 },
{ kind: 'point', instructions: '표의 좌측 상단 삽입점을 지정하십시오.' },
],
commit: (input) => {
const columns = Math.max(1, Math.round(input.number(0)));
const rows = Math.max(1, Math.round(input.number(1)));
const origin = input.point(2);
const width = getTableColumnWidth();
const height = getTableRowHeight();
const groupId = crypto.randomUUID();
const parts: Entity[] = [];
for (let column = 0; column <= columns; column++) {
parts.push(
lineEntity(
new Point(origin.x + column * width, origin.y),
new Point(origin.x + column * width, origin.y - rows * height)
)
);
}
for (let row = 0; row <= rows; row++) {
parts.push(
lineEntity(
new Point(origin.x, origin.y - row * height),
new Point(origin.x + columns * width, origin.y - row * height)
)
);
}
for (const part of parts) part.groupId = groupId;
addEntities(parts, true);
toast.info('표를 만들었습니다. 칸 내용은 문자(TEXT) 명령으로 채우십시오.');
},
});
export const revCloudToolStateMachine = createSequenceTool({
tool: Tool.REVCLOUD,
steps: [
{ kind: 'point', instructions: '구름형 경로의 첫 점을 지정하십시오.' },
{ kind: 'point', instructions: '다음 점을 지정하십시오. ENTER로 닫습니다.' },
],
repeatLastStep: true,
preview: (input) => {
const preview = polyLineEntity([...input.points(), input.cursor]);
return preview ? [preview] : [];
},
commit: (input) => {
const points = input.points();
if (points.length < 2) return;
const closed = [...points, points[0].clone()];
const box = closed.reduce(
(size, point) => ({
minX: Math.min(size.minX, point.x),
minY: Math.min(size.minY, point.y),
maxX: Math.max(size.maxX, point.x),
maxY: Math.max(size.maxY, point.y),
}),
{
minX: Number.POSITIVE_INFINITY,
minY: Number.POSITIVE_INFINITY,
maxX: Number.NEGATIVE_INFINITY,
maxY: Number.NEGATIVE_INFINITY,
}
);
// 스캘럽 크기는 구름 크기에 비례시켜 어떤 축척에서도 비슷하게 보이게 한다
const arcRadius = Math.max(Math.hypot(box.maxX - box.minX, box.maxY - box.minY) / 40, 1e-6);
const cloud = polyLineEntity(revisionCloudPoints(closed, arcRadius));
if (cloud) addEntities([cloud], true);
},
});