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,29 @@
/**
* 명령 정의 — 리본 버튼·명령행 입력·단축키가 모두 이 한 곳을 읽는다.
* AutoCAD 명령 이름(id)과 기본 별칭(aliases)을 그대로 쓴다.
*/
import type { Tool } from '../tools';
// biome-ignore lint/suspicious/noExplicitAny: xstate 머신 타입 인자가 14개라 그대로 받는다
export type AnyToolMachine = any;
export interface CadCommand {
/** AutoCAD 명령 이름 (대문자). 명령행에서 그대로 입력한다 */
id: string;
/** 리본·툴팁에 쓰는 한글 이름 */
label: string;
/** AutoCAD 기본 별칭 (대문자) */
aliases?: string[];
/** 리본 버튼 글리프 */
glyph: string;
/** 툴팁 보조 설명 */
hint?: string;
/** 도구형 명령이 활성화할 도구 */
tool?: Tool;
/** 도구형 명령의 xstate 머신 */
machine?: AnyToolMachine;
/** 즉시 실행 명령. 반환 문자열은 명령행 기록에 남는다 (없으면 라벨을 쓴다) */
run?: () => string | undefined;
/** 선택 객체가 있어야 동작하는 즉시 실행 명령 */
needsSelection?: boolean;
}
@@ -0,0 +1,299 @@
/** 주석 탭 명령 (조사표 5절 전 항목) */
import { toast } from 'react-toastify';
import type { CadCommand } from './command.types';
import { setActiveRibbonTab } from '../components/ui-state';
import { Tool } from '../tools';
import {
centerLineToolStateMachine,
centerMarkToolStateMachine,
dimAngularToolStateMachine,
dimArcToolStateMachine,
dimDiameterToolStateMachine,
dimOrdinateToolStateMachine,
dimRadiusToolStateMachine,
dimSpaceToolStateMachine,
} from '../tools/annotate/dimension-radial-tools';
import {
dimAlignedToolStateMachine,
dimAutoToolStateMachine,
dimBaselineToolStateMachine,
dimContinueToolStateMachine,
dimLinearToolStateMachine,
qDimToolStateMachine,
} from '../tools/annotate/dimension-tools';
import {
annotationScaleToolStateMachine,
dimStyleToolStateMachine,
mleaderAlignToolStateMachine,
mleaderStyleToolStateMachine,
mleaderToolStateMachine,
revCloudToolStateMachine,
tableStyleToolStateMachine,
tableToolStateMachine,
updateDimensions,
} from '../tools/annotate/leader-table-tools';
import {
findToolStateMachine,
mtextToolStateMachine,
textEditToolStateMachine,
textToolStateMachine,
} from '../tools/annotate/text-tools';
export const TEXT_COMMANDS: CadCommand[] = [
{
id: 'MTEXT',
label: '여러 줄 문자',
aliases: ['T', 'MT'],
glyph: '¶',
hint: '여러 줄 문자를 작성한다 (줄바꿈은 \\P)',
tool: Tool.MTEXT,
machine: mtextToolStateMachine,
},
{
id: 'TEXT',
label: '단일 행 문자',
aliases: ['DT'],
glyph: 'A',
hint: '한 줄짜리 문자를 작성한다',
tool: Tool.TEXT,
machine: textToolStateMachine,
},
{
id: 'STYLE',
label: '문자 스타일',
aliases: ['ST'],
glyph: '🅰',
hint: '리본 문자 패널에서 글꼴·크기·색을 지정한다',
run: () => {
setActiveRibbonTab('annotate');
toast.info('주석 탭 문자 패널에서 글꼴과 크기를 지정하십시오.');
return '문자 스타일';
},
},
{
id: 'TEXTEDIT',
label: '문자 편집',
aliases: ['TEDIT'],
glyph: '✎',
hint: '기존 문자의 내용을 고친다',
tool: Tool.TEXTEDIT,
machine: textEditToolStateMachine,
},
{
id: 'FIND',
label: '찾기·대치',
glyph: '🔍',
hint: '도면 문자를 찾고 바꾼다',
tool: Tool.FIND,
machine: findToolStateMachine,
},
];
export const DIMENSION_COMMANDS: CadCommand[] = [
{
id: 'DIM',
label: '치수',
glyph: '⟺',
hint: '선택 객체에 맞는 치수를 자동으로 넣는다',
tool: Tool.DIM,
machine: dimAutoToolStateMachine,
},
{
id: 'DIMLINEAR',
label: '선형 치수',
aliases: ['DLI'],
glyph: '↔',
hint: '수평 또는 수직 거리를 기입한다',
tool: Tool.DIMLINEAR,
machine: dimLinearToolStateMachine,
},
{
id: 'DIMALIGNED',
label: '정렬 치수',
aliases: ['DAL'],
glyph: '⤢',
hint: '두 점과 평행한 실제 길이를 기입한다',
tool: Tool.DIMALIGNED,
machine: dimAlignedToolStateMachine,
},
{
id: 'DIMANGULAR',
label: '각도 치수',
aliases: ['DAN'],
glyph: '∠',
hint: '세 점이 이루는 각도를 기입한다',
tool: Tool.DIMANGULAR,
machine: dimAngularToolStateMachine,
},
{
id: 'DIMARC',
label: '호 길이 치수',
aliases: ['DAR'],
glyph: '⌒',
hint: '호의 곡선 길이를 기입한다',
tool: Tool.DIMARC,
machine: dimArcToolStateMachine,
},
{
id: 'DIMRADIUS',
label: '반지름 치수',
aliases: ['DRA'],
glyph: 'R',
hint: '원·호의 반지름을 기입한다',
tool: Tool.DIMRADIUS,
machine: dimRadiusToolStateMachine,
},
{
id: 'DIMDIAMETER',
label: '지름 치수',
aliases: ['DDI'],
glyph: 'Ø',
hint: '원·호의 지름을 기입한다',
tool: Tool.DIMDIAMETER,
machine: dimDiameterToolStateMachine,
},
{
id: 'DIMORDINATE',
label: '세로좌표 치수',
aliases: ['DOR'],
glyph: '⌐',
hint: '기준 원점에 대한 X 또는 Y 좌표를 기입한다',
tool: Tool.DIMORDINATE,
machine: dimOrdinateToolStateMachine,
},
{
id: 'DIMBASELINE',
label: '기준선 치수',
aliases: ['DBA'],
glyph: '⊞',
hint: '직전 치수의 시작점을 기준으로 이어 기입한다',
tool: Tool.DIMBASELINE,
machine: dimBaselineToolStateMachine,
},
{
id: 'DIMCONTINUE',
label: '연속 치수',
aliases: ['DCO'],
glyph: '⋯',
hint: '직전 치수의 끝점에서 이어 기입한다',
tool: Tool.DIMCONTINUE,
machine: dimContinueToolStateMachine,
},
{
id: 'QDIM',
label: '빠른 치수',
glyph: '⚡',
hint: '선택 객체에 치수를 한 번에 넣는다',
tool: Tool.QDIM,
machine: qDimToolStateMachine,
},
{
id: 'CENTERMARK',
label: '중심 표식',
glyph: '✛',
hint: '원·호 중심에 표식을 넣는다',
tool: Tool.CENTERMARK,
machine: centerMarkToolStateMachine,
},
{
id: 'CENTERLINE',
label: '중심선',
glyph: '┈',
hint: '두 선 사이에 중심선을 넣는다',
tool: Tool.CENTERLINE,
machine: centerLineToolStateMachine,
},
{
id: 'DIMSTYLE',
label: '치수 스타일',
aliases: ['D'],
glyph: '⚙',
hint: '치수 문자 높이·화살표 크기·소수 자릿수를 정한다',
tool: Tool.DIMSTYLE,
machine: dimStyleToolStateMachine,
},
{
id: 'DIMUPDATE',
label: '치수 업데이트',
glyph: '⟳',
hint: '바꾼 치수 스타일을 기존 치수에 반영한다',
run: updateDimensions,
},
{
id: 'DIMSPACE',
label: '치수 간격',
glyph: '⇕',
hint: '평행한 치수선의 간격을 고르게 맞춘다',
tool: Tool.DIMSPACE,
machine: dimSpaceToolStateMachine,
},
];
export const LEADER_COMMANDS: CadCommand[] = [
{
id: 'MLEADER',
label: '다중 지시선',
aliases: ['MLD'],
glyph: '➤',
hint: '화살표와 문자를 잇는 지시선을 작성한다',
tool: Tool.MLEADER,
machine: mleaderToolStateMachine,
},
{
id: 'MLEADERSTYLE',
label: '지시선 스타일',
aliases: ['MLS'],
glyph: '⚙',
hint: '지시선 문자 높이와 화살표 크기를 정한다',
tool: Tool.MLEADERSTYLE,
machine: mleaderStyleToolStateMachine,
},
{
id: 'MLEADERALIGN',
label: '지시선 정렬',
glyph: '≡',
hint: '선택한 지시선 문자의 위치를 맞춘다',
tool: Tool.MLEADERALIGN,
machine: mleaderAlignToolStateMachine,
},
];
export const TABLE_COMMANDS: CadCommand[] = [
{
id: 'TABLE',
label: '테이블',
aliases: ['TB'],
glyph: '▦',
hint: '행·열 격자를 도면에 배치한다',
tool: Tool.TABLE,
machine: tableToolStateMachine,
},
{
id: 'TABLESTYLE',
label: '테이블 스타일',
aliases: ['TS'],
glyph: '⚙',
hint: '표의 열 너비와 행 높이를 정한다',
tool: Tool.TABLESTYLE,
machine: tableStyleToolStateMachine,
},
];
export const MARKUP_COMMANDS: CadCommand[] = [
{
id: 'REVCLOUD',
label: '구름형 리비전',
glyph: '☁',
hint: '검토 범위를 구름형 선으로 표시한다',
tool: Tool.REVCLOUD,
machine: revCloudToolStateMachine,
},
{
id: 'ANNOSCALE',
label: '주석 축척',
glyph: '⚖',
hint: '치수·문자·화살표 크기에 곱할 축척을 정한다',
tool: Tool.ANNOSCALE,
machine: annotationScaleToolStateMachine,
},
];
@@ -0,0 +1,221 @@
/** 홈 탭 — 그리기 패널 명령 (조사표 1절 전 항목) */
import type { CadCommand } from './command.types';
import { Tool } from '../tools';
import { circleToolStateMachine } from '../tools/circle-tool';
import {
arcToolStateMachine,
donutToolStateMachine,
ellipseToolStateMachine,
plineToolStateMachine,
pointToolStateMachine,
polygonToolStateMachine,
splineToolStateMachine,
} from '../tools/draw/basic-draw-tools';
import {
mlineToolStateMachine,
mlstyleToolStateMachine,
rayToolStateMachine,
wipeoutToolStateMachine,
xlineToolStateMachine,
} from '../tools/draw/construction-tools';
import {
divideToolStateMachine,
measureLengthToolStateMachine,
} from '../tools/draw/divide-tools';
import {
boundaryToolStateMachine,
gradientToolStateMachine,
hatchToolStateMachine,
regionToolStateMachine,
} from '../tools/draw/fill-tools';
import { lineToolStateMachine } from '../tools/line-tool';
import { rectangleToolStateMachine } from '../tools/rectangle-tool';
export const DRAW_COMMANDS: CadCommand[] = [
{
id: 'LINE',
label: '선',
aliases: ['L'],
glyph: '╱',
hint: '두 점 사이에 직선 세그먼트를 작성한다',
tool: Tool.LINE,
machine: lineToolStateMachine,
},
{
id: 'PLINE',
label: '폴리선',
aliases: ['PL'],
glyph: '⌁',
hint: '연결된 선을 하나의 객체로 작성한다',
tool: Tool.PLINE,
machine: plineToolStateMachine,
},
{
id: 'CIRCLE',
label: '원',
aliases: ['C'],
glyph: '○',
hint: '중심과 반지름으로 원을 작성한다',
tool: Tool.CIRCLE,
machine: circleToolStateMachine,
},
{
id: 'ARC',
label: '호',
aliases: ['A'],
glyph: '◜',
hint: '시작점·통과점·끝점 세 점으로 호를 작성한다',
tool: Tool.ARC,
machine: arcToolStateMachine,
},
{
id: 'RECTANG',
label: '직사각형',
aliases: ['REC'],
glyph: '▭',
hint: '두 대각점으로 직사각형을 작성한다',
tool: Tool.RECTANGLE,
machine: rectangleToolStateMachine,
},
{
id: 'POLYGON',
label: '다각형',
aliases: ['POL'],
glyph: '⬠',
hint: '지정한 변 수의 정다각형을 작성한다',
tool: Tool.POLYGON,
machine: polygonToolStateMachine,
},
{
id: 'ELLIPSE',
label: '타원',
aliases: ['EL'],
glyph: '⬭',
hint: '중심과 두 축으로 타원을 작성한다',
tool: Tool.ELLIPSE,
machine: ellipseToolStateMachine,
},
{
id: 'SPLINE',
label: '스플라인',
aliases: ['SPL'],
glyph: '∿',
hint: '지정한 점을 지나는 부드러운 곡선을 작성한다',
tool: Tool.SPLINE,
machine: splineToolStateMachine,
},
{
id: 'MLINE',
label: '다중선',
aliases: ['ML'],
glyph: '⋕',
hint: '평행한 여러 선을 한 번에 작성한다',
tool: Tool.MLINE,
machine: mlineToolStateMachine,
},
{
id: 'MLSTYLE',
label: '다중선 스타일',
glyph: '⚙',
hint: '다중선의 요소 수와 간격을 정한다',
tool: Tool.MLSTYLE,
machine: mlstyleToolStateMachine,
},
{
id: 'XLINE',
label: '구성선',
aliases: ['XL'],
glyph: '⟷',
hint: '양방향으로 길게 뻗는 기준선을 작성한다',
tool: Tool.XLINE,
machine: xlineToolStateMachine,
},
{
id: 'RAY',
label: '광선',
glyph: '⟶',
hint: '한 방향으로 길게 뻗는 기준선을 작성한다',
tool: Tool.RAY,
machine: rayToolStateMachine,
},
{
id: 'POINT',
label: '점',
aliases: ['PO'],
glyph: '·',
hint: '점 객체를 작성한다',
tool: Tool.POINT,
machine: pointToolStateMachine,
},
{
id: 'DONUT',
label: '도넛',
aliases: ['DO'],
glyph: '◎',
hint: '내부·외부 지름으로 링을 작성한다',
tool: Tool.DONUT,
machine: donutToolStateMachine,
},
{
id: 'DIVIDE',
label: '등분',
aliases: ['DIV'],
glyph: '⋯',
hint: '객체를 자르지 않고 같은 간격의 점을 배치한다',
tool: Tool.DIVIDE,
machine: divideToolStateMachine,
},
{
id: 'MEASURE',
label: '길이분할',
aliases: ['ME'],
glyph: '⋮',
hint: '지정 거리마다 점을 배치한다',
tool: Tool.MEASURE_LENGTH,
machine: measureLengthToolStateMachine,
},
{
id: 'HATCH',
label: '해치',
aliases: ['H', 'BH'],
glyph: '▨',
hint: '닫힌 경계를 패턴으로 채운다',
tool: Tool.HATCH,
machine: hatchToolStateMachine,
},
{
id: 'GRADIENT',
label: '그라데이션',
aliases: ['GD'],
glyph: '◪',
hint: '닫힌 경계를 색 변화로 채운다',
tool: Tool.GRADIENT,
machine: gradientToolStateMachine,
},
{
id: 'BOUNDARY',
label: '경계',
aliases: ['BO'],
glyph: '⬡',
hint: '선택 객체에서 닫힌 폴리선 경계를 만든다',
tool: Tool.BOUNDARY,
machine: boundaryToolStateMachine,
},
{
id: 'REGION',
label: '영역',
aliases: ['REG'],
glyph: '⬢',
hint: '닫힌 객체를 영역(닫힌 폴리선)으로 만든다',
tool: Tool.REGION,
machine: regionToolStateMachine,
},
{
id: 'WIPEOUT',
label: '와이프아웃',
glyph: '▩',
hint: '뒤쪽 객체를 가리는 마스크를 작성한다',
tool: Tool.WIPEOUT,
machine: wipeoutToolStateMachine,
},
];
@@ -0,0 +1,70 @@
/** 빠른 실행 도구막대 · 출력 탭 명령 (파일 수명주기) */
import { toast } from 'react-toastify';
import type { CadCommand } from './command.types';
import { exportEntitiesToJsonFile } from '../helpers/import-export-handlers/export-entities-to-json';
import { exportEntitiesToLocalStorage } from '../helpers/import-export-handlers/export-entities-to-local-storage';
import { exportEntitiesToPngFile } from '../helpers/import-export-handlers/export-entities-to-png';
import { exportEntitiesToSvgFile } from '../helpers/import-export-handlers/export-entities-to-svg';
import { redo, undo } from '../state';
export const FILE_COMMANDS: CadCommand[] = [
{
id: 'QSAVE',
label: '저장',
aliases: ['SAVE'],
glyph: '💾',
hint: '현재 도면을 브라우저에 저장한다',
run: () => {
void exportEntitiesToLocalStorage().then(() => toast.success('도면을 저장했습니다.'));
return '도면 저장';
},
},
{
id: 'EXPORT',
label: 'JSON 내보내기',
aliases: ['EXP'],
glyph: '⭳',
hint: '도면을 JSON 파일로 내보낸다',
run: () => {
void exportEntitiesToJsonFile();
return 'JSON 내보내기';
},
},
{
id: 'EXPORTSVG',
label: 'SVG 내보내기',
glyph: '🖼',
run: () => {
exportEntitiesToSvgFile();
return 'SVG 내보내기';
},
},
{
id: 'EXPORTPNG',
label: 'PNG 내보내기',
glyph: '🏞',
run: () => {
void exportEntitiesToPngFile();
return 'PNG 내보내기';
},
},
{
id: 'UNDO',
label: '실행 취소',
aliases: ['U'],
glyph: '↶',
run: () => {
undo();
return '실행 취소';
},
},
{
id: 'REDO',
label: '다시 실행',
glyph: '↷',
run: () => {
redo();
return '다시 실행';
},
},
];
@@ -0,0 +1,16 @@
/** 삽입 탭 명령 (조사표 4절 중 구현분) */
import type { CadCommand } from './command.types';
import { Tool } from '../tools';
import { imageImportToolStateMachine } from '../tools/image-import-tool';
export const INSERT_COMMANDS: CadCommand[] = [
{
id: 'IMAGEATTACH',
label: '이미지 부착',
aliases: ['IAT'],
glyph: '🖼',
hint: '래스터 이미지를 도면에 배치한다',
tool: Tool.IMAGE_IMPORT,
machine: imageImportToolStateMachine,
},
];
@@ -0,0 +1,166 @@
/** 홈 탭 — 도면층 패널 명령 (조사표 3절) */
import type { CadCommand } from './command.types';
import { Tool } from '../tools';
import {
layerCurrentToolStateMachine,
layerDeleteToolStateMachine,
layerFreezeToolStateMachine,
layerIsolateToolStateMachine,
layerLockToolStateMachine,
layerMatchToolStateMachine,
layerMergeToolStateMachine,
layerOffToolStateMachine,
layerStateRestoreToolStateMachine,
layerStateSaveToolStateMachine,
layerToCurrentToolStateMachine,
layerUnlockToolStateMachine,
openLayerManager,
restorePreviousLayers,
thawAllLayers,
turnAllLayersOn,
unisolateLayers,
walkLayers,
} from '../tools/utility/layer-tools';
export const LAYER_COMMANDS: CadCommand[] = [
{
id: 'LAYER',
label: '도면층 특성',
aliases: ['LA'],
glyph: '▤',
hint: '도면층을 만들고 이름·표시·잠금을 관리한다',
run: openLayerManager,
},
{
id: 'LAYCURSET',
label: '현재 도면층 설정',
glyph: '◉',
hint: '선택한 객체의 도면층을 현재 도면층으로 지정한다',
tool: Tool.LAYER_CURRENT,
machine: layerCurrentToolStateMachine,
},
{
id: 'LAYOFF',
label: '도면층 끄기',
glyph: '◐',
hint: '선택 객체가 속한 도면층을 숨긴다',
tool: Tool.LAYOFF,
machine: layerOffToolStateMachine,
},
{
id: 'LAYON',
label: '모두 켜기',
glyph: '◉',
hint: '모든 도면층을 표시한다',
run: turnAllLayersOn,
},
{
id: 'LAYFRZ',
label: '동결',
glyph: '❄',
hint: '도면층을 표시·재생성 대상에서 뺀다',
tool: Tool.LAYFRZ,
machine: layerFreezeToolStateMachine,
},
{
id: 'LAYTHW',
label: '동결 해제',
glyph: '☀',
hint: '모든 도면층의 동결을 푼다',
run: thawAllLayers,
},
{
id: 'LAYLCK',
label: '잠금',
glyph: '🔒',
hint: '도면층 객체를 편집할 수 없게 한다',
tool: Tool.LAYLCK,
machine: layerLockToolStateMachine,
},
{
id: 'LAYULK',
label: '잠금 해제',
glyph: '🔓',
hint: '도면층 잠금을 푼다',
tool: Tool.LAYULK,
machine: layerUnlockToolStateMachine,
},
{
id: 'LAYISO',
label: '분리',
glyph: '◫',
hint: '선택 객체의 도면층만 남기고 나머지를 숨긴다',
tool: Tool.LAYISO,
machine: layerIsolateToolStateMachine,
},
{
id: 'LAYUNISO',
label: '분리 해제',
glyph: '◻',
hint: '도면층 분리 이전 상태로 되돌린다',
run: unisolateLayers,
},
{
id: 'LAYERP',
label: '이전 상태',
glyph: '↺',
hint: '직전 도면층 설정으로 되돌린다',
run: restorePreviousLayers,
},
{
id: 'LAYERSTATE',
label: '도면층 상태 저장',
aliases: ['LAS'],
glyph: '💾',
hint: '현재 도면층 설정을 이름으로 저장한다',
tool: Tool.LAYERSTATE,
machine: layerStateSaveToolStateMachine,
},
{
id: 'LAYERSTATERESTORE',
label: '도면층 상태 복원',
glyph: '⭯',
hint: '저장한 도면층 설정을 되돌린다',
tool: Tool.LAYERSTATE_RESTORE,
machine: layerStateRestoreToolStateMachine,
},
{
id: 'LAYMCH',
label: '도면층 일치',
glyph: '⇄',
hint: '선택 객체를 대상 객체의 도면층으로 옮긴다',
tool: Tool.LAYMCH,
machine: layerMatchToolStateMachine,
},
{
id: 'LAYCUR',
label: '현재 도면층으로',
glyph: '⇥',
hint: '선택 객체를 현재 도면층으로 옮긴다',
tool: Tool.LAYCUR,
machine: layerToCurrentToolStateMachine,
},
{
id: 'LAYMRG',
label: '도면층 병합',
glyph: '⊎',
hint: '한 도면층의 객체를 다른 도면층으로 옮기고 원래 도면층을 지운다',
tool: Tool.LAYMRG,
machine: layerMergeToolStateMachine,
},
{
id: 'LAYDEL',
label: '도면층 삭제',
glyph: '🗑',
hint: '선택한 도면층과 그 객체를 삭제한다',
tool: Tool.LAYDEL,
machine: layerDeleteToolStateMachine,
},
{
id: 'LAYWALK',
label: '도면층 탐색',
glyph: '👣',
hint: '부를 때마다 다음 도면층만 표시한다',
run: walkLayers,
},
];
@@ -0,0 +1,340 @@
/** 홈 탭 — 수정 패널 명령 (조사표 2절 전 항목) */
import type { CadCommand } from './command.types';
import { Tool } from '../tools';
import { alignBottomToolStateMachine } from '../tools/align-bottom-tool';
import { alignCenterHorizontalToolStateMachine } from '../tools/align-center-horizontal-tool';
import { alignLeftToolStateMachine } from '../tools/align-left-tool';
import { alignCenterVerticalToolStateMachine } from '../tools/align-middle-vertical-tool';
import { alignRightToolStateMachine } from '../tools/align-right-tool';
import { alignTopToolStateMachine } from '../tools/align-top-tool';
import { arrayToolStateMachine } from '../tools/array-tool';
import { copyToolStateMachine } from '../tools/copy-tool';
import { eraserToolStateMachine } from '../tools/eraser-tool';
import {
blendToolStateMachine,
breakAtPointToolStateMachine,
breakToolStateMachine,
chamferToolStateMachine,
filletToolStateMachine,
} from '../tools/modify/corner-tools';
import {
drawOrderBackToolStateMachine,
drawOrderFrontToolStateMachine,
hatchEditToolStateMachine,
matchPropToolStateMachine,
overkillToolStateMachine,
reverseToolStateMachine,
setByLayerToolStateMachine,
} from '../tools/modify/property-tools';
import {
eraseToolStateMachine,
explodeToolStateMachine,
extendToolStateMachine,
joinToolStateMachine,
} from '../tools/modify/structure-tools';
import {
alignToolStateMachine,
lengthenToolStateMachine,
mirrorToolStateMachine,
offsetToolStateMachine,
stretchToolStateMachine,
} from '../tools/modify/transform-tools';
import { moveToolStateMachine } from '../tools/move-tool';
import { peditToolStateMachine } from '../tools/pedit-tool';
import { rotateToolStateMachine } from '../tools/rotate-tool';
import { scaleToolStateMachine } from '../tools/scale-tool';
export const MODIFY_COMMANDS: CadCommand[] = [
{
id: 'MOVE',
label: '이동',
aliases: ['M'],
glyph: '✥',
hint: '선택 객체를 기준점에서 새 위치로 이동한다',
tool: Tool.MOVE,
machine: moveToolStateMachine,
},
{
id: 'COPY',
label: '복사',
aliases: ['CO', 'CP'],
glyph: '⧉',
hint: '선택 객체를 하나 이상의 위치에 복제한다',
tool: Tool.COPY,
machine: copyToolStateMachine,
},
{
id: 'ROTATE',
label: '회전',
aliases: ['RO'],
glyph: '↻',
hint: '기준점을 중심으로 객체를 회전한다',
tool: Tool.ROTATE,
machine: rotateToolStateMachine,
},
{
id: 'SCALE',
label: '축척',
aliases: ['SC'],
glyph: '⤢',
hint: '기준점과 비율로 크기를 변경한다',
tool: Tool.SCALE,
machine: scaleToolStateMachine,
},
{
id: 'ALIGN',
label: '정렬',
aliases: ['AL'],
glyph: '⇲',
hint: '원본점·대상점 두 쌍으로 객체를 이동·회전한다',
tool: Tool.ALIGN,
machine: alignToolStateMachine,
},
{
id: 'MIRROR',
label: '대칭',
aliases: ['MI'],
glyph: '⇋',
hint: '대칭축을 기준으로 객체를 반사 복사한다',
tool: Tool.MIRROR,
machine: mirrorToolStateMachine,
},
{
id: 'OFFSET',
label: '간격띄우기',
aliases: ['O'],
glyph: '⇶',
hint: '평행선·동심원을 지정 거리만큼 띄워 만든다',
tool: Tool.OFFSET,
machine: offsetToolStateMachine,
},
{
id: 'ARRAY',
label: '배열',
aliases: ['AR'],
glyph: '⋮⋮',
hint: '직사각형 패턴으로 객체를 반복 배치한다',
tool: Tool.ARRAY,
machine: arrayToolStateMachine,
},
{
id: 'TRIM',
label: '자르기',
aliases: ['TR'],
glyph: '⌦',
hint: '교차점 사이의 필요 없는 부분을 잘라낸다',
tool: Tool.ERASER,
machine: eraserToolStateMachine,
},
{
id: 'EXTEND',
label: '연장',
aliases: ['EX'],
glyph: '⇥',
hint: '선의 끝을 지정한 경계까지 늘린다',
tool: Tool.EXTEND,
machine: extendToolStateMachine,
},
{
id: 'STRETCH',
label: '신축',
aliases: ['S'],
glyph: '↔',
hint: '기준점에 가까운 끝점을 끌어 늘린다',
tool: Tool.STRETCH,
machine: stretchToolStateMachine,
},
{
id: 'FILLET',
label: '모깎기',
aliases: ['F'],
glyph: '◟',
hint: '두 선을 지정 반지름의 호로 연결한다',
tool: Tool.FILLET,
machine: filletToolStateMachine,
},
{
id: 'CHAMFER',
label: '모따기',
aliases: ['CHA'],
glyph: '◺',
hint: '두 선을 직선 모따기로 연결한다',
tool: Tool.CHAMFER,
machine: chamferToolStateMachine,
},
{
id: 'BLEND',
label: '곡선 혼합',
glyph: '∿',
hint: '두 곡선의 끝을 부드러운 곡선으로 잇는다',
tool: Tool.BLEND,
machine: blendToolStateMachine,
},
{
id: 'BREAK',
label: '끊기',
aliases: ['BR'],
glyph: '⊣⊢',
hint: '두 점 사이를 제거해 객체를 끊는다',
tool: Tool.BREAK,
machine: breakToolStateMachine,
},
{
id: 'BREAKATPOINT',
label: '점에서 끊기',
glyph: '⊥',
hint: '지정한 점에서 객체를 둘로 나눈다',
tool: Tool.BREAK_AT_POINT,
machine: breakAtPointToolStateMachine,
},
{
id: 'JOIN',
label: '결합',
aliases: ['J'],
glyph: '⋈',
hint: '끝이 맞는 객체를 하나의 폴리선으로 결합한다',
tool: Tool.JOIN,
machine: joinToolStateMachine,
},
{
id: 'EXPLODE',
label: '분해',
aliases: ['X'],
glyph: '✳',
hint: '폴리선·사각형·해치를 구성요소로 분해한다',
tool: Tool.EXPLODE,
machine: explodeToolStateMachine,
},
{
id: 'ERASE',
label: '지우기',
aliases: ['E'],
glyph: '⌫',
hint: '선택한 객체를 삭제한다',
tool: Tool.ERASE,
machine: eraseToolStateMachine,
},
{
id: 'LENGTHEN',
label: '길이조정',
aliases: ['LEN'],
glyph: '↦',
hint: '선의 길이를 증분만큼 늘리거나 줄인다',
tool: Tool.LENGTHEN,
machine: lengthenToolStateMachine,
},
{
id: 'PEDIT',
label: '폴리선 편집',
aliases: ['PE'],
glyph: '⌁',
hint: '연결된 선을 폴리선으로 묶거나 편집한다',
tool: Tool.PEDIT,
machine: peditToolStateMachine,
},
{
id: 'HATCHEDIT',
label: '해치 편집',
aliases: ['HE'],
glyph: '▨',
hint: '기존 해치의 패턴을 바꾼다',
tool: Tool.HATCHEDIT,
machine: hatchEditToolStateMachine,
},
{
id: 'DRAWORDER',
label: '맨 앞으로',
aliases: ['DR'],
glyph: '⤒',
hint: '선택 객체를 가장 위에 그린다',
tool: Tool.DRAWORDER_FRONT,
machine: drawOrderFrontToolStateMachine,
},
{
id: 'DRAWORDERBACK',
label: '맨 뒤로',
glyph: '⤓',
hint: '선택 객체를 가장 아래에 그린다',
tool: Tool.DRAWORDER_BACK,
machine: drawOrderBackToolStateMachine,
},
{
id: 'MATCHPROP',
label: '특성 일치',
aliases: ['MA'],
glyph: '🖌',
hint: '원본 객체의 색·굵기·선종류를 대상에 복사한다',
tool: Tool.MATCHPROP,
machine: matchPropToolStateMachine,
},
{
id: 'OVERKILL',
label: '중복 객체 삭제',
glyph: '⧉',
hint: '같은 자리에 겹친 중복 객체를 지운다',
tool: Tool.OVERKILL,
machine: overkillToolStateMachine,
},
{
id: 'REVERSE',
label: '방향 반전',
glyph: '⇄',
hint: '선·폴리선의 시작점과 끝점을 뒤집는다',
tool: Tool.REVERSE,
machine: reverseToolStateMachine,
},
{
id: 'SETBYLAYER',
label: 'ByLayer로',
glyph: '▤',
hint: '선택 객체의 특성을 도면층 값으로 되돌린다',
tool: Tool.SETBYLAYER,
machine: setByLayerToolStateMachine,
},
];
/** 원본 openwebcad의 정렬 도구 — AutoCAD 리본에는 없지만 기존 기능이라 유지한다 */
export const ALIGN_COMMANDS: CadCommand[] = [
{
id: 'ALIGNLEFT',
label: '왼쪽',
glyph: '⇤',
tool: Tool.ALIGN_LEFT,
machine: alignLeftToolStateMachine,
},
{
id: 'ALIGNCENTERH',
label: '가로 중앙',
glyph: '↔',
tool: Tool.ALIGN_CENTER_HORIZONTAL,
machine: alignCenterHorizontalToolStateMachine,
},
{
id: 'ALIGNRIGHT',
label: '오른쪽',
glyph: '⇥',
tool: Tool.ALIGN_RIGHT,
machine: alignRightToolStateMachine,
},
{
id: 'ALIGNTOP',
label: '위',
glyph: '⤒',
tool: Tool.ALIGN_TOP,
machine: alignTopToolStateMachine,
},
{
id: 'ALIGNCENTERV',
label: '세로 중앙',
glyph: '↕',
tool: Tool.ALIGN_CENTER_VERTICAL,
machine: alignCenterVerticalToolStateMachine,
},
{
id: 'ALIGNBOTTOM',
label: '아래',
glyph: '⤓',
tool: Tool.ALIGN_BOTTOM,
machine: alignBottomToolStateMachine,
},
];
@@ -0,0 +1,270 @@
/** 홈 탭 — 특성·그룹·유틸리티·클립보드 명령 (조사표 3절) */
import type { CadCommand } from './command.types';
import { Tool } from '../tools';
import {
copyBaseToolStateMachine,
copySelectionToClipboard,
cutSelectionToClipboard,
pasteAsGroup,
pasteAtOriginalCoordinates,
pasteToolStateMachine,
} from '../tools/utility/clipboard-tools';
import {
angleToolStateMachine,
areaToolStateMachine,
distanceToolStateMachine,
idPointToolStateMachine,
listSelectedEntities,
measureGeomToolStateMachine,
quickCalcToolStateMachine,
radiusToolStateMachine,
} from '../tools/utility/inquiry-tools';
import {
colorToolStateMachine,
lineTypeToolStateMachine,
lineWeightToolStateMachine,
openPropertiesPalette,
toggleQuickProperties,
transparencyToolStateMachine,
} from '../tools/utility/property-tools';
import {
groupToolStateMachine,
hideObjectsToolStateMachine,
isolateObjectsToolStateMachine,
qSelectToolStateMachine,
selectSimilarToolStateMachine,
ungroupToolStateMachine,
unhideAllObjects,
} from '../tools/utility/selection-tools';
export const PROPERTY_COMMANDS: CadCommand[] = [
{
id: 'COLOR',
label: '색상',
aliases: ['COL'],
glyph: '🎨',
hint: '선택 객체의 색을 지정한다',
tool: Tool.COLOR,
machine: colorToolStateMachine,
},
{
id: 'LINETYPE',
label: '선종류',
aliases: ['LT'],
glyph: '┄',
hint: '실선·파선·1점쇄선·점선을 지정한다',
tool: Tool.LINETYPE,
machine: lineTypeToolStateMachine,
},
{
id: 'LWEIGHT',
label: '선가중치',
aliases: ['LW'],
glyph: '▬',
hint: '선 굵기를 지정한다',
tool: Tool.LWEIGHT,
machine: lineWeightToolStateMachine,
},
{
id: 'PROPERTIES',
label: '특성',
aliases: ['CH', 'MO', 'PR'],
glyph: '☰',
hint: '선택 객체의 특성을 보고 고친다',
run: openPropertiesPalette,
},
{
id: 'QUICKPROPERTIES',
label: '빠른 특성',
aliases: ['QP'],
glyph: '⌗',
hint: '선택 객체의 주요 특성만 화면에 띄운다',
run: toggleQuickProperties,
},
{
id: 'TRANSPARENCY',
label: '투명도',
glyph: '◍',
hint: '선택 객체의 투명도를 지정한다',
tool: Tool.TRANSPARENCY,
machine: transparencyToolStateMachine,
},
];
export const GROUP_COMMANDS: CadCommand[] = [
{
id: 'GROUP',
label: '그룹',
aliases: ['G'],
glyph: '⧉',
hint: '여러 객체를 함께 선택되는 그룹으로 묶는다',
tool: Tool.GROUP,
machine: groupToolStateMachine,
},
{
id: 'UNGROUP',
label: '그룹 해제',
glyph: '⧅',
hint: '그룹 묶음을 푼다',
tool: Tool.UNGROUP,
machine: ungroupToolStateMachine,
},
];
export const INQUIRY_COMMANDS: CadCommand[] = [
{
id: 'DIST',
label: '거리',
aliases: ['DI'],
glyph: '↔',
hint: '두 점 사이의 거리와 각도를 잰다',
tool: Tool.DIST,
machine: distanceToolStateMachine,
},
{
id: 'RADIUS',
label: '반지름',
glyph: '◜',
hint: '원 또는 호의 반지름을 잰다',
tool: Tool.RADIUS_INQUIRY,
machine: radiusToolStateMachine,
},
{
id: 'ANGLE',
label: '각도',
glyph: '∠',
hint: '세 점이 이루는 각도를 잰다',
tool: Tool.ANGLE_INQUIRY,
machine: angleToolStateMachine,
},
{
id: 'AREA',
label: '면적',
aliases: ['AA'],
glyph: '▦',
hint: '닫힌 경계의 면적과 둘레를 계산한다',
tool: Tool.AREA,
machine: areaToolStateMachine,
},
{
id: 'MEASUREGEOM',
label: '빠른 측정',
aliases: ['MEA'],
glyph: '📏',
hint: '거리·반지름·각도·면적 중 하나를 골라 잰다',
tool: Tool.MEASUREGEOM,
machine: measureGeomToolStateMachine,
},
{
id: 'ID',
label: '점 좌표',
glyph: '⌖',
hint: '지정한 점의 좌표를 표시한다',
tool: Tool.ID_POINT,
machine: idPointToolStateMachine,
},
{
id: 'LIST',
label: '리스트',
aliases: ['LI'],
glyph: '≣',
hint: '선택 객체의 종류·길이·크기를 표시한다',
run: listSelectedEntities,
},
{
id: 'QSELECT',
label: '빠른 선택',
glyph: '⋔',
hint: '객체 유형으로 선택 집합을 만든다',
tool: Tool.QSELECT,
machine: qSelectToolStateMachine,
},
{
id: 'QUICKCALC',
label: '계산기',
aliases: ['QC'],
glyph: '🖩',
hint: '수식을 계산한다',
tool: Tool.QUICKCALC,
machine: quickCalcToolStateMachine,
},
{
id: 'SELECTSIMILAR',
label: '유사 선택',
glyph: '⁝⁝',
hint: '같은 종류·색·도면층 객체를 모두 선택한다',
tool: Tool.SELECTSIMILAR,
machine: selectSimilarToolStateMachine,
},
{
id: 'ISOLATEOBJECTS',
label: '객체 분리',
glyph: '◧',
hint: '선택 객체만 남기고 나머지를 숨긴다',
tool: Tool.ISOLATEOBJECTS,
machine: isolateObjectsToolStateMachine,
},
{
id: 'HIDEOBJECTS',
label: '객체 숨기기',
glyph: '◌',
hint: '선택 객체를 일시적으로 숨긴다',
tool: Tool.HIDEOBJECTS,
machine: hideObjectsToolStateMachine,
},
{
id: 'UNISOLATEOBJECTS',
label: '객체 분리 종료',
aliases: ['UNHIDE', 'UNISOLATE'],
glyph: '◉',
hint: '숨긴 객체를 다시 표시한다',
run: unhideAllObjects,
},
];
export const CLIPBOARD_COMMANDS: CadCommand[] = [
{
id: 'COPYCLIP',
label: '복사',
glyph: '⎘',
hint: '선택 객체를 클립보드로 복사한다',
run: copySelectionToClipboard,
},
{
id: 'CUTCLIP',
label: '잘라내기',
glyph: '✂',
hint: '선택 객체를 클립보드로 옮긴다',
run: cutSelectionToClipboard,
},
{
id: 'PASTECLIP',
label: '붙여넣기',
glyph: '📋',
hint: '클립보드 객체를 지정 위치에 붙여넣는다',
tool: Tool.PASTECLIP,
machine: pasteToolStateMachine,
},
{
id: 'COPYBASE',
label: '기준점 복사',
glyph: '⌖',
hint: '기준점을 지정해 복사한다',
tool: Tool.COPYBASE,
machine: copyBaseToolStateMachine,
},
{
id: 'PASTEORIG',
label: '원래 좌표로 붙여넣기',
glyph: '⇱',
hint: '복사한 좌표 그대로 붙여넣는다',
run: pasteAtOriginalCoordinates,
},
{
id: 'PASTEBLOCK',
label: '그룹으로 붙여넣기',
glyph: '❐',
hint: '붙여넣으면서 하나의 그룹으로 묶는다',
run: pasteAsGroup,
},
];
@@ -0,0 +1,71 @@
/** 뷰 탭 — 탐색·재생성 명령 (조사표 7절 중 구현분) */
import { toast } from 'react-toastify';
import type { CadCommand } from './command.types';
import { bumpSceneVersion } from '../helpers/scene-version';
import { getScreenCanvasDrawController, setEntities, getEntities } from '../state';
import { Tool } from '../tools';
import { selectToolStateMachine } from '../tools/select-tool';
const zoomBy = (factor: number): string => {
const controller = getScreenCanvasDrawController();
controller.setScreenScale(Math.max(0.01, controller.getScreenScale() * factor));
return `줌 ${Math.round(controller.getScreenScale() * 100)}%`;
};
export const VIEW_COMMANDS: CadCommand[] = [
{
id: 'SELECT',
label: '선택',
aliases: ['SE'],
glyph: '↖',
hint: '객체를 클릭하거나 선택 사각형으로 고른다',
tool: Tool.SELECT,
machine: selectToolStateMachine,
},
{
id: 'ZOOM',
label: '범위 줌',
aliases: ['Z'],
glyph: '⛶',
hint: '도면 전체가 보이도록 화면을 맞춘다',
run: () => {
getScreenCanvasDrawController().zoomToFitScreen();
return '도면 전체 보기';
},
},
{
id: 'ZOOMIN',
label: '확대',
glyph: '+',
run: () => zoomBy(1.25),
},
{
id: 'ZOOMOUT',
label: '축소',
glyph: '-',
run: () => zoomBy(0.8),
},
{
id: 'REGEN',
label: '재생성',
aliases: ['RE'],
glyph: '⟳',
hint: '화면 캐시를 버리고 객체를 다시 그린다',
run: () => {
bumpSceneVersion();
setEntities([...getEntities()], false);
return '화면 재생성';
},
},
{
id: 'PAN',
label: '초점이동',
aliases: ['P'],
glyph: '✋',
hint: '휠 버튼을 누른 채 끌면 화면이 움직인다',
run: () => {
toast.info('휠 버튼을 누른 채 끌면 화면이 이동합니다.');
return '초점이동 안내';
},
},
];
@@ -0,0 +1,40 @@
/**
* 치수·지시선·표 스타일 설정 (DIMSTYLE·MLEADERSTYLE·TABLESTYLE·주석 축척).
* 기본값은 App.consts의 상수를 그대로 쓰고, 명령이 바꾸면 그 뒤로 반영된다.
*/
import {
ARROW_HEAD_LENGTH,
MEASUREMENT_DECIMAL_PLACES,
MEASUREMENT_FONT_SIZE,
} from '../App.consts';
let dimTextHeight = MEASUREMENT_FONT_SIZE;
let dimArrowSize = ARROW_HEAD_LENGTH;
let dimDecimals = MEASUREMENT_DECIMAL_PLACES;
/** 주석 축척 — 치수·문자·화살표 크기에 곱한다 */
let annotationScale = 1;
let tableColumnWidth = 40;
let tableRowHeight = 10;
export const getDimTextHeight = () => dimTextHeight * annotationScale;
export const getDimArrowSize = () => dimArrowSize * annotationScale;
export const getDimDecimals = () => dimDecimals;
export const getAnnotationScale = () => annotationScale;
export const getTableColumnWidth = () => tableColumnWidth;
export const getTableRowHeight = () => tableRowHeight;
export function setDimStyle(textHeight: number, arrowSize: number, decimals: number): void {
if (textHeight > 0) dimTextHeight = textHeight;
if (arrowSize > 0) dimArrowSize = arrowSize;
if (decimals >= 0) dimDecimals = Math.min(6, Math.round(decimals));
}
export function setAnnotationScale(scale: number): void {
if (scale > 0) annotationScale = scale;
}
export function setTableStyle(columnWidth: number, rowHeight: number): void {
if (columnWidth > 0) tableColumnWidth = columnWidth;
if (rowHeight > 0) tableRowHeight = rowHeight;
}
@@ -0,0 +1,36 @@
/**
* 그리기 명령의 설정값 — AutoCAD의 MLSTYLE·HATCH 대화상자에 해당하는 상태.
* 명령이 물어보는 값 중 "매번 묻지 않는 것"만 여기에 둔다.
*/
import type { HatchStyle } from '../entities/HatchEntity';
let mlineElements = 2;
let mlineSpacing = 1;
let hatchStyle: HatchStyle = 'pattern';
/** null이면 경계 크기에 맞춰 자동 계산한다 */
let hatchSpacing: number | null = null;
let hatchAngle = Math.PI / 4;
export const getMlineElements = () => mlineElements;
export const getMlineSpacing = () => mlineSpacing;
export const setMlineStyle = (elements: number, spacing: number) => {
mlineElements = Math.max(2, Math.round(elements));
mlineSpacing = Math.abs(spacing) || 1;
};
export const getHatchStyle = () => hatchStyle;
export const getHatchSpacing = () => hatchSpacing;
export const getHatchAngle = () => hatchAngle;
export const setHatchStyle = (style: HatchStyle) => {
hatchStyle = style;
};
export const setHatchSpacing = (spacing: number | null) => {
hatchSpacing = spacing;
};
export const setHatchAngle = (angleRad: number) => {
hatchAngle = angleRad;
};
/** 경계 크기에 맞춘 기본 해치 간격 — 도면 축척이 달라도 눈에 보이게 한다 */
export const autoHatchSpacing = (width: number, height: number): number =>
Math.max(Math.hypot(width, height) / 30, 1e-6);
@@ -0,0 +1,95 @@
/**
* 명령 레지스트리 — 리본·명령행·단축키가 읽는 단일 소스.
* 새 명령은 commands.*.ts에 한 줄 추가하면 세 곳에 동시에 나타난다.
*/
import type { AnyToolMachine, CadCommand } from './command.types';
import type { Tool } from '../tools';
import {
DIMENSION_COMMANDS,
LEADER_COMMANDS,
MARKUP_COMMANDS,
TABLE_COMMANDS,
TEXT_COMMANDS,
} from './commands.annotate';
import { DRAW_COMMANDS } from './commands.draw';
import { FILE_COMMANDS } from './commands.file';
import { INSERT_COMMANDS } from './commands.insert';
import { LAYER_COMMANDS } from './commands.layer';
import {
CLIPBOARD_COMMANDS,
GROUP_COMMANDS,
INQUIRY_COMMANDS,
PROPERTY_COMMANDS,
} from './commands.utility';
import { ALIGN_COMMANDS, MODIFY_COMMANDS } from './commands.modify';
import { VIEW_COMMANDS } from './commands.view';
const ALL_COMMANDS: CadCommand[] = [
...DRAW_COMMANDS,
...MODIFY_COMMANDS,
...ALIGN_COMMANDS,
...TEXT_COMMANDS,
...DIMENSION_COMMANDS,
...LEADER_COMMANDS,
...TABLE_COMMANDS,
...MARKUP_COMMANDS,
...LAYER_COMMANDS,
...PROPERTY_COMMANDS,
...GROUP_COMMANDS,
...INQUIRY_COMMANDS,
...CLIPBOARD_COMMANDS,
...INSERT_COMMANDS,
...VIEW_COMMANDS,
...FILE_COMMANDS,
];
const COMMANDS_BY_ID = new Map<string, CadCommand>(
ALL_COMMANDS.map((command) => [command.id, command])
);
const COMMANDS_BY_ALIAS = new Map<string, CadCommand>();
for (const command of ALL_COMMANDS) {
for (const alias of command.aliases ?? []) {
if (!COMMANDS_BY_ALIAS.has(alias)) {
COMMANDS_BY_ALIAS.set(alias, command);
}
}
}
export const getAllCommands = (): CadCommand[] => ALL_COMMANDS;
export const getCommandById = (id: string): CadCommand | undefined => COMMANDS_BY_ID.get(id);
/** 활성 도구로 어떤 명령이 실행 중인지 되짚는다 (리본 강조·상태 표시용) */
export const getCommandByTool = (tool: Tool | null): CadCommand | undefined =>
tool ? ALL_COMMANDS.find((command) => command.tool === tool) : undefined;
/** 도구형 명령의 xstate 머신 표 — 도구 활성화 경로가 이 표만 본다 */
export const TOOL_STATE_MACHINES = Object.fromEntries(
ALL_COMMANDS.filter((command) => command.tool && command.machine).map((command) => [
command.tool,
command.machine,
])
) as Record<Tool, AnyToolMachine>;
/** 명령행 입력 해석 — 정확한 이름·별칭이 먼저, 없으면 접두사 후보의 첫 항목 */
export function resolveCommandInput(input: string): CadCommand | undefined {
const text = input.trim().toUpperCase();
if (!text) return undefined;
return COMMANDS_BY_ID.get(text) ?? COMMANDS_BY_ALIAS.get(text) ?? matchCommandPrefixes(text)[0];
}
/** 접두사가 같은 명령 후보 (커서 옆 자동완성 목록에 쓴다) */
export function matchCommandPrefixes(input: string): CadCommand[] {
const text = input.trim().toUpperCase();
if (!text) return [];
const byAlias = ALL_COMMANDS.filter((command) =>
(command.aliases ?? []).some((alias) => alias.startsWith(text))
);
const byId = ALL_COMMANDS.filter((command) => command.id.startsWith(text));
return [...new Set([...byAlias, ...byId])];
}
/** 명령행 자동완성에 보여줄 문자열 (예: "LINE (L) 선") */
export const describeCommand = (command: CadCommand): string =>
`${command.id}${command.aliases?.length ? ` (${command.aliases[0]})` : ''} ${command.label}`;
@@ -0,0 +1,61 @@
/** 명령 실행기 — 리본 버튼·명령행·단축키가 모두 이 경로로 들어온다. */
import { toast } from 'react-toastify';
import { Actor } from 'xstate';
import type { CadCommand } from './command.types';
import { getCommandById, resolveCommandInput } from './registry';
import { HtmlEvent } from '../App.types';
import { getSelectedEntities, setActiveToolActor } from '../state';
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);
}
window.dispatchEvent(new CustomEvent(HtmlEvent.UPDATE_STATE));
}
/** 명령 한 건 실행. 도구형이면 도구를 활성화하고, 즉시형이면 run()을 부른다. */
export function runCommand(command: CadCommand): string {
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));
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;
}