- B07_wf4_DesignDetail(8파일+openwebcad) -> B08_DesignDetail로 git mv (이력 보존) - B08_wf5_Quantity -> B07_Quantity (구 수량 백업 zip 보관 폴더) - 파생 문자열 일괄 전환: /b07-cad -> /b08-cad 정적 서빙, CAD 레이어 b07-* -> b08-*, postMessage aislo:b07:* -> aislo:b08:*, 패키지명 aislo-b08-cad, CSS .b08-*, 라우트 키/슬러그(B08_DESIGN_DETAIL/b08-design-detail, B07_QUANTITY/b07-quantity) - 상세설계 워크플로우 stage 4 -> 5 (확정/무효화 전이 3곳), 확정 완료 시 B09로 이동 - WORKFLOW_STEP_ROUTES 순서 재배열: index4=수량(B07), index5=상세설계(B08) - [임시] B08 이동 테스트 버튼 제거, openwebcad dist 재빌드 - 주석 의미 정렬: 수량 인계 주석 B08->B07, 도면 참조 B07->B08 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
173 lines
5.4 KiB
TypeScript
173 lines
5.4 KiB
TypeScript
import { Point } from '@flatten-js/core';
|
|
import React from 'react';
|
|
import ReactDOM from 'react-dom/client';
|
|
import { Actor, type MachineSnapshot } from 'xstate';
|
|
import { HIGHLIGHT_ENTITY_DISTANCE, SNAP_POINT_DISTANCE } from './App.consts';
|
|
import App from './App.tsx';
|
|
import { ScreenCanvasDrawController } from './drawControllers/screenCanvas.drawController';
|
|
import { draw } from './helpers/draw';
|
|
import { findClosestEntity } from './helpers/find-closest-entity';
|
|
import { scenePerf } from './helpers/scene-cache';
|
|
import { queryEntitiesNearPoint } from './helpers/spatial-index';
|
|
import { getNewLayer } from './helpers/get-new-layer.ts';
|
|
import { trackHoveredSnapPoint } from './helpers/track-hovered-snap-points';
|
|
import { InputController } from './inputController/input-controller.ts';
|
|
import { registerAisloDrawingBridge } from './integration/aislo-drawing-bridge.ts';
|
|
import {
|
|
getActiveToolActor,
|
|
getCanvas,
|
|
getHoveredSnapPoints,
|
|
getLastDrawTimestamp,
|
|
getScreenCanvasDrawController,
|
|
getSnapPoint,
|
|
setActiveLayerId,
|
|
setActiveToolActor,
|
|
setCanvas,
|
|
setEntities,
|
|
setHighlightedEntityIds,
|
|
setHoveredSnapPoints,
|
|
setInputController,
|
|
setLastDrawTimestamp,
|
|
setLayers,
|
|
setScreenCanvasDrawController,
|
|
} from './state';
|
|
import { Tool } from './tools';
|
|
import { TOOL_STATE_MACHINES } from './tools/tool.consts';
|
|
import { ActorEvent, type DrawEvent } from './tools/tool.types';
|
|
|
|
ReactDOM.createRoot(document.getElementById('root') as HTMLDivElement).render(
|
|
<React.StrictMode>
|
|
<App />
|
|
</React.StrictMode>
|
|
);
|
|
|
|
// Hover highlight throttle: the closest-entity scan is O(entities) so it runs
|
|
// at most every HOVER_THROTTLE_MS and only when the mouse actually moved.
|
|
const HOVER_THROTTLE_MS = 30;
|
|
let lastHoverCheckAt = 0;
|
|
let lastHoverMouseX = Number.NaN;
|
|
let lastHoverMouseY = Number.NaN;
|
|
|
|
function startDrawLoop(
|
|
screenCanvasDrawController: ScreenCanvasDrawController,
|
|
timestamp: DOMHighResTimeStamp
|
|
) {
|
|
const lastDrawTimestamp = getLastDrawTimestamp();
|
|
|
|
const elapsedTime = timestamp - lastDrawTimestamp;
|
|
setLastDrawTimestamp(timestamp);
|
|
scenePerf.avgFrameMs = scenePerf.avgFrameMs * 0.9 + elapsedTime * 0.1;
|
|
|
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
const activeToolSnapshot: MachineSnapshot<any, any, any, any, any, any, any, any> | undefined =
|
|
getActiveToolActor()?.getSnapshot();
|
|
if (
|
|
activeToolSnapshot?.status === 'active' &&
|
|
activeToolSnapshot?.can({ type: ActorEvent.DRAW })
|
|
) {
|
|
getActiveToolActor()?.send({
|
|
type: ActorEvent.DRAW,
|
|
drawController: screenCanvasDrawController,
|
|
} as DrawEvent);
|
|
}
|
|
|
|
/**
|
|
* Highlight the entity closest to the mouse when the select tool is active
|
|
*/
|
|
if (getActiveToolActor()?.getSnapshot()?.context?.type === Tool.SELECT) {
|
|
const screenCanvasDrawController = getScreenCanvasDrawController();
|
|
if (!screenCanvasDrawController) {
|
|
throw new Error('getScreenCanvasDrawController() returned null');
|
|
}
|
|
const mouseLocation = screenCanvasDrawController.getScreenMouseLocation();
|
|
const mouseMoved = mouseLocation.x !== lastHoverMouseX || mouseLocation.y !== lastHoverMouseY;
|
|
if (mouseMoved && timestamp - lastHoverCheckAt >= HOVER_THROTTLE_MS) {
|
|
lastHoverCheckAt = timestamp;
|
|
lastHoverMouseX = mouseLocation.x;
|
|
lastHoverMouseY = mouseLocation.y;
|
|
const worldMouseLocation = screenCanvasDrawController.getWorldMouseLocation();
|
|
const { distance, entity: closestEntity } = findClosestEntity(
|
|
worldMouseLocation,
|
|
// 공간 인덱스로 후보를 좁혀 O(전체) 스캔 제거
|
|
queryEntitiesNearPoint(
|
|
worldMouseLocation.x,
|
|
worldMouseLocation.y,
|
|
HIGHLIGHT_ENTITY_DISTANCE
|
|
)
|
|
);
|
|
|
|
if (distance < HIGHLIGHT_ENTITY_DISTANCE) {
|
|
setHighlightedEntityIds([closestEntity.id]);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Track hovered snap points
|
|
*/
|
|
trackHoveredSnapPoint(
|
|
getSnapPoint(),
|
|
getHoveredSnapPoints(),
|
|
setHoveredSnapPoints,
|
|
SNAP_POINT_DISTANCE / screenCanvasDrawController.getScreenScale(),
|
|
elapsedTime
|
|
);
|
|
|
|
/**
|
|
* Draw everything on the canvas
|
|
*/
|
|
draw(screenCanvasDrawController);
|
|
|
|
requestAnimationFrame((newTimestamp: DOMHighResTimeStamp) => {
|
|
startDrawLoop(screenCanvasDrawController, newTimestamp);
|
|
});
|
|
}
|
|
|
|
function handleWindowResize() {
|
|
const canvas = getCanvas();
|
|
if (canvas) {
|
|
const bounds = canvas.getBoundingClientRect();
|
|
const width = Math.max(1, Math.round(bounds.width));
|
|
const height = Math.max(1, Math.round(bounds.height));
|
|
canvas.width = width;
|
|
canvas.height = height;
|
|
getScreenCanvasDrawController().setCanvasSize(new Point(width, height));
|
|
}
|
|
}
|
|
|
|
function initApplication() {
|
|
const canvas = document.getElementsByTagName('canvas')[0] as HTMLCanvasElement | null;
|
|
if (canvas) {
|
|
setCanvas(canvas);
|
|
|
|
const context = canvas.getContext('2d');
|
|
if (!context) return;
|
|
|
|
setEntities([], true); // Creates the first undo entry
|
|
|
|
const layers = [getNewLayer()];
|
|
setLayers(layers);
|
|
setActiveLayerId(layers[0].id);
|
|
registerAisloDrawingBridge();
|
|
const screenCanvasDrawController = new ScreenCanvasDrawController(context);
|
|
setScreenCanvasDrawController(screenCanvasDrawController);
|
|
|
|
window.addEventListener('resize', handleWindowResize);
|
|
new ResizeObserver(handleWindowResize).observe(canvas);
|
|
const inputController = new InputController();
|
|
setInputController(inputController);
|
|
|
|
handleWindowResize();
|
|
|
|
startDrawLoop(screenCanvasDrawController, 0);
|
|
|
|
const lineToolActor = new Actor(TOOL_STATE_MACHINES[Tool.LINE]);
|
|
lineToolActor.start();
|
|
setActiveToolActor(lineToolActor);
|
|
}
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
initApplication();
|
|
});
|