Files
Aislo/B07_DesignDetail/openwebcad/src/tools/utility/layer-tools.ts
T
eomsangdonandClaude Opus 5.5 17e6500cf6 fix(506-3 B07 · CAD 작은 흠): 저장 길 · 죽은 길 걷음 · CAD 되돌리기 · B09 인쇄 미리보기 · M02 도움말
- 1-A 도면 GET · 저장 PUT 한도 60 s · 저장 중 미리받기 쉼 · 끊긴 저장 = 목록 confirmed 로 판정
- 2 CAD 자동백업 열쇠 = b07:{프로젝트}:{도면} · 도각 편집 = b07-frame:{프로젝트} · [초기화] 같은 열쇠
- 3-1 [초기화] 물음 글 = 프로젝트 도각 그대로 · [도각 편집] → [기본 도각 복원] 안내
- 3-2 풀린 장 저장본 json · 수량표 찌꺼기 걷음(_write_manifest 한 곳)
- 5-1 확정 풀기 · 배치 · 축척 = mark_stage(save)
- 7-3 start_stage 가 DEV_UNLOCK 표식 남김
- 6-a navigateDrawing · onNavigate · hasPrev · hasNext 걷음 · 6-b cad-host-save 토글 걷음 · 4-2 B08 안 쓰는 글 11 걷음
- 6-f 특성 판 색 끌기 = 되돌리기 한 칸(paintNowCommitLater 한 벌) · 6-g LAYMRG 사본 길
- 4-1 B09 [인쇄 미리보기] = 저장 뒤 이동 · 단계 그대로 · 6-e M02 카드 도움말 DWG 한 줄
- 시험 test_506_3_* 둘 · cad/undo-506-3 · test_298_2_b07_buttons 열쇠 맞춤

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 12:48:36 +09:00

267 lines
9.2 KiB
TypeScript

/** 도면층 명령 (조사표 3절 도면층 패널) */
import { toast } from 'react-toastify';
import { restyle } from '../../helpers/selection-style';
import type { Layer } from '../../App.types';
import { openInspector } from '../../components/ui-state';
import type { Entity } from '../../entities/Entity';
import {
popLayerHistory,
pushLayerHistory,
restoreLayerState,
saveLayerState,
} from '../../helpers/layer-history';
import {
deleteEntities,
getActiveLayerId,
getEntities,
getLayers,
setActiveLayerId,
setLayers,
setSelectedEntityIds,
} from '../../state';
import { Tool } from '../../tools';
import { createSequenceTool } from '../factories/sequence-tool';
/** 도면층을 바꾸기 전에 직전 상태를 기록한다 (LAYERP가 되돌린다) */
function updateLayers(mutate: (layers: Layer[]) => Layer[]): void {
const current = getLayers();
pushLayerHistory(current);
setLayers(mutate(current.map((layer) => ({ ...layer }))));
}
const layerNameOf = (layerId: string): string =>
getLayers().find((layer) => layer.id === layerId)?.name ?? layerId;
/** LAYER — 도면층 특성 관리자(좌측 팔레트)를 연다 */
export function openLayerManager(): string {
openInspector('layers');
return '레이어 관리자';
}
export const layerCurrentToolStateMachine = createSequenceTool({
tool: Tool.LAYER_CURRENT,
helpers: false,
steps: [{ kind: 'entity', instructions: '현재 레이어로 지정할 객체를 선택하십시오.' }],
commit: (input) => {
const layerId = input.entity(0).layerId;
setActiveLayerId(layerId);
toast.success(`현재 레이어: ${layerNameOf(layerId)}`);
},
});
export const layerOffToolStateMachine = createSequenceTool({
tool: Tool.LAYOFF,
helpers: false,
steps: [{ kind: 'entity', instructions: '끌 레이어의 객체를 선택하십시오.' }],
commit: (input) => {
const layerId = input.entity(0).layerId;
updateLayers((layers) =>
layers.map((layer) => (layer.id === layerId ? { ...layer, isVisible: false } : layer))
);
toast.info(`레이어 끄기: ${layerNameOf(layerId)}`);
},
});
/** LAYON — 모든 도면층 켜기 */
export function turnAllLayersOn(): string {
updateLayers((layers) => layers.map((layer) => ({ ...layer, isVisible: true })));
toast.success('모든 레이어를 켰습니다.');
return '모든 레이어 켜기';
}
export const layerFreezeToolStateMachine = createSequenceTool({
tool: Tool.LAYFRZ,
helpers: false,
steps: [{ kind: 'entity', instructions: '동결할 레이어의 객체를 선택하십시오.' }],
commit: (input) => {
const layerId = input.entity(0).layerId;
if (layerId === getActiveLayerId()) {
toast.warn('현재 레이어는 동결할 수 없습니다.');
return;
}
updateLayers((layers) =>
layers.map((layer) => (layer.id === layerId ? { ...layer, isFrozen: true } : layer))
);
toast.info(`레이어 동결: ${layerNameOf(layerId)}`);
},
});
/** LAYTHW — 모든 도면층 동결 해제 */
export function thawAllLayers(): string {
updateLayers((layers) => layers.map((layer) => ({ ...layer, isFrozen: false })));
toast.success('모든 레이어를 동결 해제했습니다.');
return '동결 해제';
}
export const layerLockToolStateMachine = createSequenceTool({
tool: Tool.LAYLCK,
helpers: false,
steps: [{ kind: 'entity', instructions: '잠글 레이어의 객체를 선택하십시오.' }],
commit: (input) => {
const layerId = input.entity(0).layerId;
updateLayers((layers) =>
layers.map((layer) => (layer.id === layerId ? { ...layer, isLocked: true } : layer))
);
toast.info(`레이어 잠금: ${layerNameOf(layerId)}`);
},
});
export const layerUnlockToolStateMachine = createSequenceTool({
tool: Tool.LAYULK,
helpers: false,
steps: [{ kind: 'entity', instructions: '잠금 해제할 레이어의 객체를 선택하십시오.' }],
commit: (input) => {
const layerId = input.entity(0).layerId;
updateLayers((layers) =>
layers.map((layer) => (layer.id === layerId ? { ...layer, isLocked: false } : layer))
);
toast.success(`레이어 잠금 해제: ${layerNameOf(layerId)}`);
},
});
export const layerIsolateToolStateMachine = createSequenceTool({
tool: Tool.LAYISO,
helpers: false,
steps: [{ kind: 'entity', instructions: '남길 레이어의 객체를 선택하십시오.' }],
commit: (input) => {
const layerId = input.entity(0).layerId;
updateLayers((layers) =>
layers.map((layer) => ({ ...layer, isVisible: layer.id === layerId }))
);
toast.info(`레이어 분리: ${layerNameOf(layerId)}`);
},
});
/** LAYUNISO — 도면층 분리 해제 */
export function unisolateLayers(): string {
updateLayers((layers) => layers.map((layer) => ({ ...layer, isVisible: true })));
toast.success('레이어 분리를 해제했습니다.');
return '레이어 분리 해제';
}
/** LAYERP — 직전 도면층 상태로 되돌리기 */
export function restorePreviousLayers(): string {
const previous = popLayerHistory();
if (!previous) {
toast.info('되돌릴 레이어 상태가 없습니다.');
return '되돌릴 상태 없음';
}
setLayers(previous);
toast.success('직전 레이어 상태로 되돌렸습니다.');
return '직전 레이어 상태';
}
export const layerStateSaveToolStateMachine = createSequenceTool({
tool: Tool.LAYERSTATE,
helpers: false,
steps: [{ kind: 'text', instructions: '저장할 레이어 상태 이름을 입력하십시오.' }],
commit: (input) => {
saveLayerState(input.text(0), getLayers());
toast.success(`레이어 상태 저장: ${input.text(0)}`);
},
});
export const layerStateRestoreToolStateMachine = createSequenceTool({
tool: Tool.LAYERSTATE_RESTORE,
helpers: false,
steps: [{ kind: 'text', instructions: '복원할 레이어 상태 이름을 입력하십시오.' }],
commit: (input) => {
const restored = restoreLayerState(input.text(0));
if (!restored) {
toast.warn('그 이름으로 저장한 레이어 상태가 없습니다.');
return;
}
pushLayerHistory(getLayers());
setLayers(restored);
toast.success(`레이어 상태 복원: ${input.text(0)}`);
},
});
export const layerMatchToolStateMachine = createSequenceTool({
tool: Tool.LAYMCH,
helpers: false,
steps: [
{ kind: 'selection', instructions: '옮길 객체를 선택한 뒤 ENTER.' },
{ kind: 'entity', instructions: '대상 레이어의 객체를 선택하십시오.' },
],
commit: (input) => {
const layerId = input.entity(1).layerId;
restyle(input.entities(0), (entity) => {
entity.layerId = layerId;
});
setSelectedEntityIds([]);
toast.success(`${input.entities(0).length}개 객체를 ${layerNameOf(layerId)}(으)로 옮겼습니다.`);
},
});
export const layerToCurrentToolStateMachine = createSequenceTool({
tool: Tool.LAYCUR,
helpers: false,
steps: [{ kind: 'selection', instructions: '현재 레이어로 옮길 객체를 선택한 뒤 ENTER.' }],
commit: (input) => {
const layerId = getActiveLayerId();
restyle(input.entities(0), (entity) => {
entity.layerId = layerId;
});
setSelectedEntityIds([]);
toast.success(`${input.entities(0).length}개 객체를 현재 레이어로 옮겼습니다.`);
},
});
export const layerMergeToolStateMachine = createSequenceTool({
tool: Tool.LAYMRG,
helpers: false,
steps: [
{ kind: 'entity', instructions: '병합할(사라질) 레이어의 객체를 선택하십시오.' },
{ kind: 'entity', instructions: '대상 레이어의 객체를 선택하십시오.' },
],
commit: (input) => {
const sourceId = input.entity(0).layerId;
const targetId = input.entity(1).layerId;
if (sourceId === targetId) {
toast.warn('같은 레이어입니다.');
return;
}
// 사본으로 갈아 끼움(제자리 고침 = 되돌리기 칸이 같은 참조 → Ctrl+Z 해도 그대로) · 층 목록 = LAYERP
restyle(
getEntities().filter((entity) => entity.layerId === sourceId),
(entity) => {
entity.layerId = targetId;
}
);
updateLayers((layers) => layers.filter((layer) => layer.id !== sourceId));
if (getActiveLayerId() === sourceId) setActiveLayerId(targetId);
toast.success(`레이어를 ${layerNameOf(targetId)}(으)로 병합했습니다.`);
},
});
export const layerDeleteToolStateMachine = createSequenceTool({
tool: Tool.LAYDEL,
helpers: false,
steps: [{ kind: 'entity', instructions: '삭제할 레이어의 객체를 선택하십시오.' }],
commit: (input) => {
const layerId = input.entity(0).layerId;
if (getLayers().length <= 1) {
toast.warn('마지막 레이어는 삭제할 수 없습니다.');
return;
}
const doomed: Entity[] = getEntities().filter((entity) => entity.layerId === layerId);
deleteEntities(doomed, true);
updateLayers((layers) => layers.filter((layer) => layer.id !== layerId));
if (getActiveLayerId() === layerId) setActiveLayerId(getLayers()[0].id);
toast.success(`레이어와 객체 ${doomed.length}개를 삭제했습니다.`);
},
});
/** LAYWALK — 부를 때마다 다음 도면층 하나만 보여 준다 */
let walkIndex = -1;
export function walkLayers(): string {
const layers = getLayers();
if (!layers.length) return '레이어 없음';
walkIndex = (walkIndex + 1) % layers.length;
const target = layers[walkIndex];
updateLayers((all) => all.map((layer) => ({ ...layer, isVisible: layer.id === target.id })));
toast.info(`레이어 탐색: ${target.name} (${walkIndex + 1}/${layers.length})`);
return `레이어 탐색 ${target.name}`;
}