feat(CAD): 331-3 선 중 닫기(C) · 명령취소(U) · 한 번 스냅 이름 · 한글 안내문
- 선 — 이어 그리기 첫 점 · 구간 기억 · C = 둘째 선부터 첫 점으로 닫고 끝 · U = 마지막 한 구간만 취소 - 점 단계 글 — 선택지 글자(meta.options)만 도구로 · 나머지는 명령 이름 그대로 · 한글 받개는 점 단계에서 안 잡음 - 새 input-snap-override — END · MID · CEN · INT · PER · NEA · NON 다음 한 점만 · F3 꺼져도 · 맞는 점 없으면 클릭 버림 · Esc 풂 · 커서 옆 안내 - 원본 도구 안내문 한글(선 · 원 · 사각형 · 이동 · 복사 · 회전 · 배열 · 정렬 · 지우개 · 그림 · 폴리선 합치기 · 선택) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013QyNXY2TUKXCFMwAca2APG
This commit is contained in:
@@ -9,12 +9,33 @@ import { getActiveToolActor } from '../state.ts';
|
||||
export const isImeKey = (evt: KeyboardEvent): boolean =>
|
||||
evt.isComposing || evt.keyCode === 229 || evt.key === 'Process';
|
||||
|
||||
/** 활성 도구의 지금 단계 설정(평평한 단계만) */
|
||||
const activeStateConfig = () => {
|
||||
const snapshot = getActiveToolActor()?.getSnapshot();
|
||||
return snapshot?.machine?.states?.[snapshot?.value]?.config;
|
||||
};
|
||||
|
||||
/** 활성 도구의 지금 단계가 TEXT_INPUT 을 받는가 */
|
||||
export function activeToolAcceptsText(): boolean {
|
||||
const snapshot = getActiveToolActor()?.getSnapshot();
|
||||
return !!snapshot?.machine?.states?.[snapshot?.value]?.config?.on?.TEXT_INPUT;
|
||||
return !!activeStateConfig()?.on?.TEXT_INPUT;
|
||||
}
|
||||
|
||||
/** 지금 단계가 점(`x,y`)을 받는가 — 한 번 스냅 이름 · 선택지 판정 */
|
||||
export function activeToolWantsPoint(): boolean {
|
||||
return !!activeStateConfig()?.on?.ABSOLUTE_POINT_INPUT;
|
||||
}
|
||||
|
||||
/** 지금 단계가 이 글을 받는가 — 점 단계는 선택지 글자(meta.options · 선 C · U)만 · 나머지는 명령 이름으로 */
|
||||
export function activeToolTakesText(text: string): boolean {
|
||||
if (!activeToolAcceptsText()) return false;
|
||||
if (!activeToolWantsPoint()) return true;
|
||||
const options = (activeStateConfig()?.meta as { options?: string[] } | undefined)?.options;
|
||||
return !!options?.includes(text);
|
||||
}
|
||||
|
||||
/** 한글 받개에 초점을 줄 단계 — 글은 받되 점 단계 선택지(영문 C · U)는 아님 */
|
||||
export const activeToolWantsIme = (): boolean => activeToolAcceptsText() && !activeToolWantsPoint();
|
||||
|
||||
/** 지금 단계가 자유 글(TEXT · MTEXT · 표 칸 · 이름 …)을 받는가 — Space 가 띄어쓰기(아니면 Enter) */
|
||||
export function activeToolWantsFreeText(): boolean {
|
||||
const meta = getActiveToolActor()?.getSnapshot()?.getMeta?.() as
|
||||
|
||||
@@ -17,6 +17,7 @@ import { getClosestSnapPointWithinRadius } from '../helpers/get-closest-snap-poi
|
||||
import { pickRadius } from '../helpers/pick-radius.ts';
|
||||
import {
|
||||
getActiveToolActor,
|
||||
getAngleGuideOriginPoint,
|
||||
getAngleStep,
|
||||
getCanvas,
|
||||
getPickableEntities,
|
||||
@@ -46,8 +47,10 @@ import { Tool } from '../tools.ts';
|
||||
import { SelectState, selectToolStateMachine } from '../tools/select-tool.ts';
|
||||
import { ActorEvent, type MouseClickEvent, type TextInputEvent } from '../tools/tool.types.ts';
|
||||
import {
|
||||
activeToolAcceptsText,
|
||||
activeToolTakesText,
|
||||
activeToolWantsFreeText,
|
||||
activeToolWantsIme,
|
||||
activeToolWantsPoint,
|
||||
ImeSink,
|
||||
isImeKey,
|
||||
isPlainSpace,
|
||||
@@ -58,6 +61,13 @@ import { wheelZoom } from './input-wheel.ts';
|
||||
import { attachTouch } from './input-touch.ts';
|
||||
import { ANGLE_LOCK_REGEXP, parsePointText, type PointTextEvent } from './input-patterns.ts';
|
||||
import { angleLockHint, setAngleLock } from './input-angle-lock.ts';
|
||||
import {
|
||||
getSnapOverride,
|
||||
isSnapName,
|
||||
setSnapOverride,
|
||||
snapOverrideHint,
|
||||
snapOverridePoint,
|
||||
} from './input-snap-override.ts';
|
||||
|
||||
/** 이만큼 넘게 끌면 클릭이 아니라 드래그로 본다 (화면 픽셀) */
|
||||
const DRAG_SELECT_MIN_PX = 4;
|
||||
@@ -112,7 +122,7 @@ export class InputController {
|
||||
}
|
||||
|
||||
public draw(drawController: ScreenCanvasDrawController) {
|
||||
this.ime.sync(activeToolAcceptsText());
|
||||
this.ime.sync(activeToolWantsIme());
|
||||
const toolInstruction = getLastStateInstructions();
|
||||
const texts: string[] = [];
|
||||
if (toolInstruction) {
|
||||
@@ -122,8 +132,7 @@ export class InputController {
|
||||
const roundedY = round(drawController.getWorldMouseLocation().y, 2);
|
||||
texts.push(`${roundedX},${roundedY}`);
|
||||
}
|
||||
const lockHint = angleLockHint();
|
||||
if (lockHint) texts.push(lockHint);
|
||||
texts.push(...compact([angleLockHint(), snapOverrideHint()]));
|
||||
// 입력 중인 문자로 시작하는 명령 후보. 예: C => CIRCLE (C), COPY (CO)
|
||||
texts.push(...this.getCommandSuggestions());
|
||||
// 입력 글(조합 중인 한글도 함께)
|
||||
@@ -173,7 +182,7 @@ export class InputController {
|
||||
return;
|
||||
}
|
||||
this.sendMouseClick(evt);
|
||||
this.ime.sync(activeToolAcceptsText()); // 클릭으로 문자 단계에 들면 바로 한글 받개로
|
||||
this.ime.sync(activeToolWantsIme()); // 클릭으로 문자 단계에 들면 바로 한글 받개로
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +209,12 @@ export class InputController {
|
||||
const worldMouseLocationTemp = screenCanvasDrawController.targetToWorld(
|
||||
this.getCanvasPoint(evt)
|
||||
);
|
||||
const worldMouseLocation = closestSnapPoint ? closestSnapPoint.point : worldMouseLocationTemp;
|
||||
let worldMouseLocation = closestSnapPoint ? closestSnapPoint.point : worldMouseLocationTemp;
|
||||
if (getSnapOverride()) {
|
||||
const snapped = snapOverridePoint(worldMouseLocationTemp, getAngleGuideOriginPoint());
|
||||
if (!snapped) return; // 맞는 점 없음 — 다시 누르기를 기다림
|
||||
worldMouseLocation = snapped;
|
||||
}
|
||||
|
||||
this.sendPointEvent({
|
||||
type: ActorEvent.MOUSE_CLICK,
|
||||
@@ -408,12 +422,12 @@ export class InputController {
|
||||
} else if (evt.key === 'Enter') {
|
||||
// User wants to submit the input or submit the action
|
||||
this.handleEnterKey(true);
|
||||
this.ime.sync(activeToolAcceptsText());
|
||||
this.ime.sync(activeToolWantsIme());
|
||||
} else if (evt.key === ' ' && !activeToolWantsFreeText()) {
|
||||
// Space = Enter(오토캐드) · 글 단계는 아래 띄어쓰기 · 수정키 · 길게 눌러 반복은 무시
|
||||
if (isPlainSpace(evt)) {
|
||||
this.handleEnterKey(true);
|
||||
this.ime.sync(activeToolAcceptsText());
|
||||
this.ime.sync(activeToolWantsIme());
|
||||
}
|
||||
} else if (evt.key === 'ArrowDown') {
|
||||
// Move the screen down
|
||||
@@ -438,6 +452,7 @@ export class InputController {
|
||||
|
||||
public handleEscapeKey() {
|
||||
setAngleLock(null);
|
||||
setSnapOverride(null);
|
||||
if (getSelectedEntities().length > 0) {
|
||||
// Deselect entities
|
||||
setSelectedEntityIds([]);
|
||||
@@ -463,7 +478,6 @@ export class InputController {
|
||||
/** @param repeatIfIdle 키보드 Enter · Space — 빈 입력 + 선택 도구 대기면 마지막 명령 반복(우클릭은 확정만) */
|
||||
public handleEnterKey(repeatIfIdle = false) {
|
||||
// submit the text as input to the active tool and clear the input field
|
||||
const activeToolCanHandleTextInput = activeToolAcceptsText();
|
||||
|
||||
if (this.text === '') {
|
||||
console.log('ENTER: ', {
|
||||
@@ -496,8 +510,12 @@ export class InputController {
|
||||
// 거리 `100` · `x,y` · `@x,y` · `@d<a` · `d<a`
|
||||
this.sendPointEvent(this.pointEventFromText() as PointTextEvent);
|
||||
this.text = '';
|
||||
} else if (activeToolCanHandleTextInput) {
|
||||
// 지금 단계의 선택지(배열 L/R · 숫자 단계 글)
|
||||
} else if (isSnapName(this.text) && activeToolWantsPoint()) {
|
||||
// 한 번 스냅 END · MID · … — 다음 한 점만
|
||||
setSnapOverride(this.text);
|
||||
this.text = '';
|
||||
} else if (activeToolTakesText(this.text)) {
|
||||
// 지금 단계의 선택지(선 C · U · 배열 L/R · 숫자 단계 글)
|
||||
this.sendText();
|
||||
} else if (resolveCommandInput(this.text)) {
|
||||
// 명령 이름 또는 AutoCAD 별칭을 입력했다. 예: L, LINE, REC
|
||||
@@ -531,10 +549,11 @@ export class InputController {
|
||||
);
|
||||
}
|
||||
|
||||
/** 점 하나를 도구에 보냄 — 각도 고정은 이 한 점으로 끝 */
|
||||
/** 점 하나를 도구에 보냄 — 각도 고정 · 한 번 스냅은 이 한 점으로 끝 */
|
||||
private sendPointEvent(event: PointTextEvent | MouseClickEvent) {
|
||||
getActiveToolActor()?.send(event);
|
||||
setAngleLock(null);
|
||||
setSnapOverride(null);
|
||||
}
|
||||
|
||||
public handleUndo(evt: KeyboardEvent) {
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* 한 번 스냅 — 점 단계에서 END · MID · CEN · INT · PER · NEA · NON 을 치면 다음 한 점만 그 스냅(오토캐드).
|
||||
* F3(객체 스냅) 꺼져 있어도 먹음. 커서 둘레에 맞는 점이 없으면 클릭을 버리고 기다림 · Esc 로 풂.
|
||||
*/
|
||||
import type { Point } from '@flatten-js/core';
|
||||
import { SNAP_POINT_DISTANCE } from '../App.consts.ts';
|
||||
import { SnapPointType } from '../App.types.ts';
|
||||
import { findClosestEntity } from '../helpers/find-closest-entity.ts';
|
||||
import { getIntersectionPoints } from '../helpers/get-intersection-points.ts';
|
||||
import { queryEntitiesNearPoint } from '../helpers/spatial-index.ts';
|
||||
import { getLayerById, getScreenCanvasDrawController } from '../state.ts';
|
||||
|
||||
const SNAP_LABELS = {
|
||||
END: '끝점',
|
||||
MID: '중간점',
|
||||
CEN: '중심',
|
||||
INT: '교차점',
|
||||
PER: '수직',
|
||||
NEA: '근처점',
|
||||
NON: '스냅 없음',
|
||||
} as const;
|
||||
type SnapName = keyof typeof SNAP_LABELS;
|
||||
|
||||
const SNAP_TYPES: Partial<Record<SnapName, SnapPointType>> = {
|
||||
END: SnapPointType.LineEndPoint,
|
||||
MID: SnapPointType.LineMidPoint,
|
||||
CEN: SnapPointType.CircleCenter,
|
||||
};
|
||||
|
||||
let override: SnapName | null = null;
|
||||
|
||||
export const getSnapOverride = (): SnapName | null => override;
|
||||
export const setSnapOverride = (name: SnapName | null) => {
|
||||
override = name;
|
||||
};
|
||||
export const isSnapName = (text: string): text is SnapName => text in SNAP_LABELS;
|
||||
|
||||
/** 커서 옆 안내 줄 */
|
||||
export const snapOverrideHint = (): string | null =>
|
||||
override ? `${SNAP_LABELS[override]}(${override}) 한 번 — 점 지정` : null;
|
||||
|
||||
const closest = (points: Point[], mouse: Point, radius: number): Point | null => {
|
||||
let best: Point | null = null;
|
||||
let bestDistance = radius;
|
||||
for (const point of points) {
|
||||
const distance = Math.hypot(point.x - mouse.x, point.y - mouse.y);
|
||||
if (distance <= bestDistance) {
|
||||
best = point;
|
||||
bestDistance = distance;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
};
|
||||
|
||||
/** 한 번 스냅이 고른 점 · 맞는 점 없으면 null. base = 앞 점(PER 기준) */
|
||||
export function snapOverridePoint(mouse: Point, base: Point | null): Point | null {
|
||||
if (override === 'NON') return mouse;
|
||||
// ponytail: 일반 스냅(15px)의 두 배 둘레 — 오토캐드 조준 상자 크기 설정이 필요하면 설정 모달로
|
||||
const radius = (SNAP_POINT_DISTANCE * 2) / getScreenCanvasDrawController().getScreenScale();
|
||||
const entities = queryEntitiesNearPoint(mouse.x, mouse.y, radius).filter(
|
||||
(entity) => !getLayerById(entity.layerId)?.isLocked
|
||||
);
|
||||
const type = override ? SNAP_TYPES[override] : undefined;
|
||||
if (type) {
|
||||
const points = entities.flatMap((entity) =>
|
||||
entity
|
||||
.getSnapPoints()
|
||||
.filter((snap) => snap.type === type)
|
||||
.map((snap) => snap.point)
|
||||
);
|
||||
return closest(points, mouse, radius);
|
||||
}
|
||||
if (override === 'INT') return closest(getIntersectionPoints(entities), mouse, radius);
|
||||
const near = findClosestEntity(mouse, entities);
|
||||
if (!near.entity || near.distance > radius) return null;
|
||||
if (override === 'NEA') return near.segment.start;
|
||||
// PER — 앞 점에서 커서 아래 객체로 내린 발(선분이면 수선의 발)
|
||||
if (!base) return null;
|
||||
return near.entity.distanceTo(base)?.[1].start ?? null;
|
||||
}
|
||||
Reference in New Issue
Block a user