Files
Aislo/B07_DesignDetail/openwebcad/src/commands/commands.insert.ts
T
eomsangdonandClaude Opus 5 3fccf8278b feat(B07): 그린 것을 블록으로 저장해 다시 놓고, 사진 넣기를 되살린다
조사표 4·7절 검토 결과를 반영한다.

- 블록 라이브러리: 선택한 객체를 이름 붙여 저장(BLOCK)하고 팔레트에서 골라
  클릭 한 번으로 놓는다(INSERT). 정의-참조 링크 없는 클론 방식이라 새 엔티티
  타입 없이 기존 직렬화·groupId를 그대로 쓴다. 기준점은 선택 영역 중심.
  라이브러리는 도면과 분리해 브라우저에 두고, 유실 대비로 파일 내보내기·
  가져오기를 붙였다.
- 사진 넣기: IMAGEATTACH가 파일 선택창을 띄우지 않아 도구가 FILE_SELECTED를
  영원히 기다리고 있었다. 도구형 명령도 run()을 함께 부르게 하고 파일 선택을
  붙여 되살렸다.
- 조사표 4·7절의 반영 등급·반영 열을 실제 코드에 맞춰 정정하고, 반영하지
  않기로 한 항목의 사유를 절마다 남겼다. 7절은 신규 구현 없음.

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

62 lines
2.1 KiB
TypeScript

/** 삽입 탭 명령 (조사표 4절 중 구현분) */
import { toast } from 'react-toastify';
import { saveBlockFromEntities } from '../blocks/block-library';
import { setBlockLibraryVisible } from '../components/ui-state';
import { importImageFromFile } from '../helpers/import-export-handlers/import-image-from-file';
import { pickFile } from '../helpers/pick-file';
import { getActiveToolActor, getSelectedEntities } from '../state';
import { Tool } from '../tools';
import { imageImportToolStateMachine } from '../tools/image-import-tool';
import { ActorEvent, type FileSelectedEvent } from '../tools/tool.types';
import type { CadCommand } from './command.types';
export const INSERT_COMMANDS: CadCommand[] = [
{
id: 'IMAGEATTACH',
label: '이미지 부착',
aliases: ['IAT'],
glyph: '🖼',
hint: '래스터 이미지를 도면에 배치한다',
tool: Tool.IMAGE_IMPORT,
machine: imageImportToolStateMachine,
// 도구가 FILE_SELECTED를 기다리므로 파일 선택창을 띄워 이미지를 넣어 준다
run: () => {
pickFile('image/*', async (file) => {
const image = await importImageFromFile(file);
const event: FileSelectedEvent = { type: ActorEvent.FILE_SELECTED, image };
getActiveToolActor()?.send(event);
});
return '이미지 파일 선택';
},
},
{
id: 'BLOCK',
label: '블록 작성',
aliases: ['B'],
glyph: '🧩',
hint: '선택한 객체를 이름 붙여 블록 라이브러리에 저장한다',
needsSelection: true,
run: () => {
const entities = getSelectedEntities();
const name = window.prompt('블록 이름', '')?.trim();
if (!name) return '블록 작성 취소';
void saveBlockFromEntities(name, entities).then(() => {
toast.success(`블록 '${name}' 저장 (객체 ${entities.length}개)`);
setBlockLibraryVisible(true);
});
return `블록 '${name}' 저장`;
},
},
{
id: 'INSERT',
label: '블록 삽입',
aliases: ['I'],
glyph: '📥',
hint: '라이브러리에 저장한 블록을 도면에 놓는다',
run: () => {
setBlockLibraryVisible(true);
return '블록 라이브러리';
},
},
];