- ZOOM(Z): 「윈도우 구석 지정, 축척 비율 (nX 또는 nXP) 입력 또는 [전체(A)/범위(E)/이전(P)/윈도우(W)] <실시간>:」 덧물음 · E · A = 범위 · P = 앞 화면 · W · 누름 = 두 구석 윈도우 · 2X = 배율 곱 · 빈 Enter = 실시간 안내 · 중심 · 동적 · 축척 · 객체 = 없음 안내 · 'Z 투명 · ⛶ 단추 = 바로 범위 - 약속 더함: SubPrompt.onText(꼴이 정해지지 않은 글 · nX) — routeTyped 가 덧물음에 먼저 물음 · undefined = 사다리 그대로(브레인 알림) - Shift+우클릭: 점 물음에서만 한 번 스냅 메뉴(시작점에서 · 두 점 사이의 중간 · 끝점 · 중간점 · 교차점 · 중심 · 사분점 · 수직 · 노드 · 근처점 · 없음) → 고른 이름을 친 것과 같은 길 · Esc · 바깥 누름 = 메뉴만 닫음(ic/snap-menu.ts) - 고르기 숨은 키워드 ALL · L · P(선택 도구 첫 점 대기 · 쉼 · 명령 안 자식) — 앞 고름에 더함 · 「n개를 찾음, 총 m개」 - 그립 물음 새 꼴 「** 신축 ** 신축점 지정 또는 [종료(X)]:」 · X = 놓음 · 기준점(B) · 복사(C) · 명령 취소(U) 없음 안내 - ↶ ↷ 단추 = undoCommand · redoCommand(끊고 되돌림) · 우클릭 = 명령 중 Enter · 쉴 때 반복(가-1 길 · 시험) - 시험: mouse-acad 마-2 더함(21) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Se7ytqbohmBQnfYpwYFnYf
190 lines
5.3 KiB
TypeScript
190 lines
5.3 KiB
TypeScript
import type { Point } from '@flatten-js/core';
|
|
import {
|
|
getNotSelectedEntities,
|
|
isDrawingReadOnly,
|
|
isViewOnly,
|
|
setEntities,
|
|
setGhostHelperEntities,
|
|
setSelectedEntityIds,
|
|
setShouldDrawHelpers,
|
|
} from '../state';
|
|
import type { DrawEvent, MouseClickEvent, StateEvent, ToolContext } from './tool.types';
|
|
import { Tool } from '../tools';
|
|
import { assign, createMachine } from 'xstate';
|
|
import {
|
|
drawTempSelectionRectangle,
|
|
handleFirstSelectionPoint,
|
|
selectByKeyword,
|
|
selectEntitiesInsideRectangle,
|
|
} from './select-tool.helpers';
|
|
|
|
export interface SelectContext extends ToolContext {
|
|
startPoint: Point | null;
|
|
}
|
|
|
|
export enum SelectState {
|
|
INIT = 'INIT',
|
|
WAITING_FOR_FIRST_SELECT_POINT = 'WAITING_FOR_FIRST_SELECT_POINT',
|
|
CHECK_SELECTION = 'CHECK_SELECTION',
|
|
WAITING_FOR_SECOND_SELECT_POINT = 'WAITING_FOR_SECOND_SELECT_POINT',
|
|
SELECTION_COMPLETED = 'SELECTION_COMPLETED',
|
|
}
|
|
|
|
export enum SelectAction {
|
|
INIT_SELECT_TOOL = 'INIT_SELECT_TOOL',
|
|
HANDLE_FIRST_SELECT_POINT = 'HANDLE_FIRST_SELECT_POINT',
|
|
SELECT_ENTITIES_INSIDE_RECTANGLE = 'SELECT_ENTITIES_INSIDE_RECTANGLE',
|
|
DRAW_TEMP_SELECTION_RECTANGLE = 'DRAW_TEMP_SELECTION_RECTANGLE',
|
|
DELETE_SELECTED_ENTITIES = 'DELETE_SELECTED_ENTITIES',
|
|
}
|
|
|
|
export const selectToolStateMachine = createMachine(
|
|
{
|
|
types: {} as {
|
|
context: SelectContext;
|
|
events: StateEvent;
|
|
},
|
|
context: {
|
|
startPoint: null,
|
|
type: Tool.SELECT,
|
|
},
|
|
initial: SelectState.INIT,
|
|
states: {
|
|
[SelectState.INIT]: {
|
|
description: 'Initializing the select tool',
|
|
always: {
|
|
actions: SelectAction.INIT_SELECT_TOOL,
|
|
target: SelectState.WAITING_FOR_FIRST_SELECT_POINT,
|
|
},
|
|
},
|
|
[SelectState.WAITING_FOR_FIRST_SELECT_POINT]: {
|
|
description: 'Select a line or select the first point of a selection rectangle',
|
|
meta: {
|
|
instructions: '객체 선택 또는 선택 상자 시작',
|
|
},
|
|
on: {
|
|
MOUSE_CLICK: {
|
|
actions: SelectAction.HANDLE_FIRST_SELECT_POINT,
|
|
target: SelectState.CHECK_SELECTION,
|
|
},
|
|
ESC: {
|
|
actions: SelectAction.INIT_SELECT_TOOL,
|
|
},
|
|
ENTER: {
|
|
target: SelectState.SELECTION_COMPLETED,
|
|
},
|
|
DELETE: {
|
|
actions: SelectAction.DELETE_SELECTED_ENTITIES,
|
|
target: SelectState.INIT,
|
|
},
|
|
// 고르기 숨은 키워드(SELECT_OBJECTS) — 전체 · 최종 · 이전
|
|
'OPTION.ALL': { actions: () => selectByKeyword('ALL') },
|
|
'OPTION.LAST': { actions: () => selectByKeyword('LAST') },
|
|
'OPTION.PREVIOUS': { actions: () => selectByKeyword('PREVIOUS') },
|
|
},
|
|
},
|
|
[SelectState.CHECK_SELECTION]: {
|
|
description: 'Checking to select one line or start drawing a selection rectangle',
|
|
meta: {
|
|
instructions: '객체 하나 선택 또는 선택 상자 시작',
|
|
},
|
|
always: [
|
|
{
|
|
// User started drawing a selection rectangle
|
|
guard: ({ context }: { context: SelectContext }) => !!context.startPoint,
|
|
target: SelectState.WAITING_FOR_SECOND_SELECT_POINT,
|
|
},
|
|
{
|
|
// User clicked on an entity
|
|
guard: ({ context }: { context: SelectContext }) => !context.startPoint,
|
|
target: SelectState.WAITING_FOR_FIRST_SELECT_POINT,
|
|
},
|
|
],
|
|
},
|
|
[SelectState.WAITING_FOR_SECOND_SELECT_POINT]: {
|
|
description: '선택 상자 맞은 모서리 지정',
|
|
meta: {
|
|
instructions: '선택 상자 맞은 모서리 지정',
|
|
},
|
|
on: {
|
|
DRAW: {
|
|
actions: SelectAction.DRAW_TEMP_SELECTION_RECTANGLE,
|
|
},
|
|
MOUSE_CLICK: {
|
|
actions: SelectAction.SELECT_ENTITIES_INSIDE_RECTANGLE,
|
|
target: SelectState.WAITING_FOR_FIRST_SELECT_POINT,
|
|
},
|
|
ESC: {
|
|
target: SelectState.INIT,
|
|
},
|
|
},
|
|
},
|
|
[SelectState.SELECTION_COMPLETED]: {
|
|
description: 'Selection completed',
|
|
type: 'final',
|
|
},
|
|
},
|
|
},
|
|
{
|
|
actions: {
|
|
INIT_SELECT_TOOL: () => {
|
|
setShouldDrawHelpers(false);
|
|
setGhostHelperEntities([]);
|
|
},
|
|
HANDLE_FIRST_SELECT_POINT: assign(
|
|
({ context, event }: { context: SelectContext; event: StateEvent }) => {
|
|
return handleFirstSelectionPoint(context, event as MouseClickEvent);
|
|
}
|
|
),
|
|
DRAW_TEMP_SELECTION_RECTANGLE: ({
|
|
context,
|
|
event,
|
|
}: {
|
|
context: SelectContext;
|
|
event: StateEvent;
|
|
}) => {
|
|
if (!context.startPoint) {
|
|
// assert
|
|
throw new Error('[SELECT] Calling drawTempSelectionRectangle without startPoint set');
|
|
}
|
|
drawTempSelectionRectangle(
|
|
context.startPoint as Point,
|
|
(event as DrawEvent).drawController.getWorldMouseLocation()
|
|
);
|
|
},
|
|
SELECT_ENTITIES_INSIDE_RECTANGLE: ({
|
|
context,
|
|
event,
|
|
}: {
|
|
context: SelectContext;
|
|
event: StateEvent;
|
|
}) => {
|
|
if (!context.startPoint) {
|
|
//
|
|
throw new Error('[SELECT] calling SELECT_ENTITIES_INSIDE_RECTANGLE without start point');
|
|
}
|
|
selectEntitiesInsideRectangle(
|
|
context.startPoint,
|
|
(event as MouseClickEvent).worldMouseLocation,
|
|
(event as MouseClickEvent).holdingCtrl,
|
|
(event as MouseClickEvent).holdingShift
|
|
);
|
|
setGhostHelperEntities([]);
|
|
},
|
|
DELETE_SELECTED_ENTITIES: () => {
|
|
if (isViewOnly() || isDrawingReadOnly()) return; // 보기 전용 · 확정 도면은 안 지움(H2)
|
|
setEntities(getNotSelectedEntities(), true);
|
|
setSelectedEntityIds([]);
|
|
setGhostHelperEntities([]);
|
|
},
|
|
RESET_SELECTION: assign(() => {
|
|
setGhostHelperEntities([]);
|
|
setSelectedEntityIds([]);
|
|
return {
|
|
startPoint: null,
|
|
};
|
|
}),
|
|
},
|
|
}
|
|
);
|