73 lines
2.4 KiB
TypeScript
73 lines
2.4 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 { importDrawingFile } from '../integration/dxf-clip-paste';
|
|
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 '블록 라이브러리';
|
|
},
|
|
},
|
|
{
|
|
id: 'IMPORT',
|
|
label: 'DWG 불러오기',
|
|
glyph: '📂',
|
|
hint: 'DWG · DXF 파일을 지금 도면에 원좌표 그대로 더한다(골라진 채 · 되돌리기 한 번에 빠짐)',
|
|
run: () => {
|
|
pickFile('.dwg,.dxf', importDrawingFile);
|
|
return 'DWG · DXF 파일 선택';
|
|
},
|
|
},
|
|
];
|