원인(브라우저 차례 엿보기): 관 옆 노선 교점 끌기 = 노선 초안(관은 follow 로 따라감) · ↶ 가 ① 버림 차례(조용 · 초안 전 상세 되돌림)와 되돌리기 훅의 관 먹이기 차례 둘로 갈림(버림이 밀림) ② 버림 시작~되돌림 사이 종단도가 초안 때 갈아끼운 저장 상세 · 초안 종단과 섞어 그림 ③ 되돌린 뒤 시설 줄이 한 박자 늦어 「낡음」 다시 셈이 옛 관 자리 계획선으로 셈(관 측점 면적 한 틀 틀림) ④ 되돌림 · 갈아끼움이 읽기 길의 얹기(조정창 · 관 옵션)를 빼고 면적부터 셈 - 되돌리기 훅: 버림 동안 관 · 구조물 안 먹임(버림 차례가 follow 로 초안 전 값까지) - 버림 시작부터 종단도 그리기 멈춤(holdDraw) · 되돌림 바로 뒤 저장 기준 맞춤 · 묶음이 조용해지면 한 번 그림 - 종단도가 저장 상세를 받을 때 노선 초안이 이미 없으면 그 자리에서 저장 기준 · 저장 노선 셈 편집 = 그 노선 것(routeAlignment) - 버림 동안 저장 노선 낡음 다시 셈(recross) 안 띄움(pipelineHolding) - 상세 가게 얹기 꼬리 한 벌(withAdjustsAndAreas) — 읽기 · 갈아끼움 · 되돌림 - 시험 test_472_5c_drop_once(옛 코드 빨강) · 위키 규칙 한 줄 · 줄 번호 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
285 lines
11 KiB
JavaScript
285 lines
11 KiB
JavaScript
/* 472-5 덧 헬퍼 — 노선 초안(관이 따라 옮겨짐) ↶ = 차례 하나 · 값 하나. 진짜 TS(`design_pipeline_page` · 단계
|
|
* 파일 전부)를 Node 로 · 서버 창구만 가짜(틀 = `helper_451_drop_cross.cjs`). 되돌리기 = 사진첩처럼 세션을 바로
|
|
* 되쓰고(가게 알림 없음) 훅을 부름(노선 편집기 → 관 · 구조물 먹이기 차례 그대로).
|
|
* 입력 argv[2] JSON · argv[3] 격자 이진 · 결과 = 표준출력 JSON. 짝 = `test_472_5c_drop_once.py`. */
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
|
|
const CATALOG = require("./helper_322_catalog_module.cjs");
|
|
|
|
const ROOT = path.join(__dirname, "..", "..");
|
|
const job = JSON.parse(fs.readFileSync(process.argv[2], "utf8"));
|
|
|
|
function memoryStorage() {
|
|
const map = new Map();
|
|
return {
|
|
getItem: (key) => (map.has(key) ? map.get(key) : null),
|
|
setItem: (key, value) => map.set(key, String(value)),
|
|
removeItem: (key) => map.delete(key),
|
|
key: (index) => [...map.keys()][index] ?? null,
|
|
get length() {
|
|
return map.size;
|
|
},
|
|
};
|
|
}
|
|
globalThis.window = {
|
|
sessionStorage: memoryStorage(),
|
|
localStorage: memoryStorage(),
|
|
setTimeout,
|
|
clearTimeout,
|
|
};
|
|
|
|
// 흙 배분 서버 — 늦게 답함 · 끊기면 버림
|
|
const haul = { calls: 0, aborted: 0, answered: 0 };
|
|
globalThis.fetch = (url, init) =>
|
|
new Promise((resolve, reject) => {
|
|
haul.calls += 1;
|
|
const timer = setTimeout(() => {
|
|
haul.answered += 1;
|
|
resolve({ ok: true, json: async () => ({ haul_plan: { blocks: [], url } }) });
|
|
}, job.haulDelayMs);
|
|
init.signal.addEventListener("abort", () => {
|
|
clearTimeout(timer);
|
|
haul.aborted += 1;
|
|
reject(new Error("aborted"));
|
|
});
|
|
});
|
|
|
|
const STUBS = {};
|
|
// 되돌리기 훅 — 사진첩(`_Profile_History`) 대신 모아 두고 시험이 부름
|
|
const hooks = [];
|
|
STUBS["B05_Profile_UI_Profile_History"] = new Proxy(
|
|
{
|
|
onPageHistory: (entry) => (hooks.push(entry), () => undefined),
|
|
pageReplaying: () => false,
|
|
},
|
|
{ get: (target, key) => (key in target ? target[key] : () => undefined) },
|
|
);
|
|
const cache = new Map();
|
|
function loadTs(full) {
|
|
if (cache.has(full)) return cache.get(full);
|
|
const js = ts.transpileModule(fs.readFileSync(full, "utf8"), {
|
|
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
|
}).outputText;
|
|
const box = { exports: {} };
|
|
cache.set(full, box.exports);
|
|
const localRequire = (request) => {
|
|
if (CATALOG.isCatalogRequest(request)) return CATALOG;
|
|
const key = Object.keys(STUBS).find((name) => request.endsWith(name));
|
|
if (key) return STUBS[key];
|
|
if (request.startsWith("@config/")) return { API_BASE_URL: "http://fake" };
|
|
if (request.startsWith("@util/"))
|
|
return loadTs(path.join(ROOT, "common_util", `${request.slice(6)}.ts`));
|
|
if (request.startsWith(".")) return loadTs(path.join(path.dirname(full), `${request}.ts`));
|
|
return require(request);
|
|
};
|
|
new Function("exports", "module", "require", js)(box.exports, box, localRequire);
|
|
return box.exports;
|
|
}
|
|
const load = (...parts) => loadTs(path.join(ROOT, ...parts));
|
|
// 상세 가게 칸(472-5) — 실제는 상세 가게가 받을 때 채움 · 여기선 종단도가 내주는 저장 상세 그대로
|
|
const slots = () => load("B06_Section", "B06_Section_Section_Canon.ts");
|
|
|
|
const sampler = load("common_util", "common_util_surface_sampler.ts");
|
|
const bytes = fs.readFileSync(process.argv[3]);
|
|
const grid = sampler.parseDtmGrid(
|
|
bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.length),
|
|
);
|
|
const local = { grid, design: "las" };
|
|
|
|
STUBS["B05_Profile_Api_Replan"] = {
|
|
analysisTerrain: () => "las",
|
|
fetchRoutePlan: async () => ({
|
|
planned: job.line,
|
|
curves: [],
|
|
min_radius_m: job.minRadius,
|
|
station_snap: false,
|
|
}),
|
|
};
|
|
STUBS["B05_Profile_Api_Structures"] = {
|
|
fetchStructures: async () => ({ structures: [] }),
|
|
fetchStructureTypes: async () => job.types,
|
|
};
|
|
STUBS["B05_Profile_Api_TerrainGrid"] = {
|
|
loadDesignTerrainGrid: async () => local,
|
|
groundStageDeps: () => ({ grid: () => local, remote: async () => [] }),
|
|
};
|
|
STUBS["B04_PreProcess_Api_Fetch"] = {
|
|
fetchDetailPipePoints: async () => ({
|
|
pipe_points: job.pipes.map((pipe) => ({ ...pipe, lonlat: [0, 0] })),
|
|
}),
|
|
};
|
|
STUBS["B06_Section_UI_Standard_Panel"] = {
|
|
effectiveStandardCross: () => job.standard,
|
|
readRockBoundaryDefault: () => -0.5,
|
|
};
|
|
|
|
const pipeMod = load("A00_Common", "design", "logic", "design_pipeline.ts");
|
|
const pageMod = load("A00_Common", "design", "design_pipeline_page.ts");
|
|
const stationsMod = load("A00_Common", "design", "logic", "design_pipeline_stations.ts");
|
|
const routeGround = load("B05_Profile", "logic", "B05_Profile_Pipeline_RouteGround.ts");
|
|
const grade = load("B05_Profile", "logic", "B05_Profile_Pipeline_Grade.ts");
|
|
const gradeGround = load("B05_Profile", "logic", "B05_Profile_Grade_Ground.ts");
|
|
const detailMod = load("B05_Profile", "logic", "B05_Profile_Pipeline_Detail.ts");
|
|
const alignment = load("B05_Profile", "logic", "B05_Profile_UI_Profile_Alignment.ts");
|
|
const editMod = load("B05_Profile", "B05_Profile_UI_Profile_Edit.ts");
|
|
const page = load("A00_Common", "b_page_state.ts");
|
|
|
|
const tick = (ms = 0) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
const runs = () => globalThis.__aisloPipeline?.runs ?? [];
|
|
async function settle(count) {
|
|
for (let i = 0; i < 400; i += 1) {
|
|
const last = runs()[runs().length - 1];
|
|
if (runs().length >= count && last && last.outcome !== "running") return last;
|
|
await tick(5);
|
|
}
|
|
throw new Error("묶음이 끝나지 않음");
|
|
}
|
|
const n = job.nodes.length;
|
|
const draftOf = (nodes) => ({
|
|
nodes,
|
|
curveOn: Array(n).fill(true),
|
|
curveRadius: Array(n).fill(null),
|
|
curveLock: Array(n).fill(null),
|
|
curveArc: Array(n).fill(null),
|
|
stationSnap: false,
|
|
});
|
|
const shift = (index, dx, dy) =>
|
|
job.nodes.map((node, i) => (i === index ? [node[0] + dx, node[1] + dy] : node));
|
|
|
|
/** 저장 기준 — 저장 노선 지반 첫 계획선(관 측점 포함 · 서버 정책 그대로). */
|
|
async function savedBaseOf() {
|
|
const seed = pipeMod.createDesignPipeline({
|
|
stages: {
|
|
route: routeGround.createRouteStage({
|
|
minRadiusM: () => job.minRadius,
|
|
savedLine: () => ({ line: job.line, curves: [] }),
|
|
}),
|
|
stations: stationsMod.createStationsStage({
|
|
intervalM: job.interval,
|
|
types: () => job.types,
|
|
}),
|
|
ground: routeGround.createGroundStage({ grid: () => local, remote: async () => [] }),
|
|
},
|
|
});
|
|
await seed.start({ route: null, alignment: null, cross: null, pipes: job.pipes, structures: [] });
|
|
const ground = seed.output("ground");
|
|
seed.dispose();
|
|
const samples = ground.longitudinal.chainageM.map((c, i) => ({
|
|
chainage_m: c,
|
|
elevation_m: ground.longitudinal.z[i],
|
|
}));
|
|
const profile = gradeGround.groundProfile(samples);
|
|
return {
|
|
policy: job.policy,
|
|
onlyExplicitCurves: false,
|
|
basePvi: gradeGround.groundFollowingBasePvi({
|
|
samples,
|
|
stations: ground.stations.map((s) => s.chainageM),
|
|
policy: job.policy,
|
|
}),
|
|
chainage: profile.chainage,
|
|
ground: profile.ground,
|
|
stations: ground.stations.map((s) => ({
|
|
station_id: grade.stationIdOf(s.chainageM),
|
|
chainage_m: s.chainageM,
|
|
})),
|
|
};
|
|
}
|
|
|
|
const store = load("A00_Common", "design", "design_store.ts");
|
|
// B05 오른쪽 횡단 판(365-3) — 그림 조각만 가짜 · 값 고르기는 진짜
|
|
STUBS["b_svg_zoom_pan"] = { attachSvgZoomPan: () => undefined };
|
|
STUBS["B05_Profile_UI_RouteEdit_Cross_Draw"] = { CROSS_PLOT_PAD: {}, summarizeCross: () => "" };
|
|
STUBS["B05_Profile_UI_RouteEdit_Chrome"] = { sidePanelsOf: new WeakMap() }; // 판 양식(382-1) — 화면 밖
|
|
// B06 카드 그림(393-2) — 화면 밖 · 판 값 고르기는 진짜
|
|
STUBS["B05_Profile_UI_RouteEdit_Cross_Card"] = {
|
|
routeCrossSource: () => null,
|
|
routeCrossCard: () => null,
|
|
};
|
|
const pane = load("B05_Profile", "B05_Profile_UI_RouteEdit_Cross.ts");
|
|
const r3 = (value) => (typeof value === "number" ? Math.round(value * 1000) / 1000 : null);
|
|
|
|
/** 묶음 새 노선 상세(카드가 그리는 것) — 측점 · 계획고 · 절 · 성토 면적. */
|
|
function shownRows(P) {
|
|
const shown = pageMod.pipelineDetail(P);
|
|
return (
|
|
shown &&
|
|
shown.cross_sections.map((s) => [
|
|
r3(s.chainage_m),
|
|
r3(s.design?.design_elevation_m),
|
|
r3(s.design?.cut_area_m2),
|
|
r3(s.design?.fill_area_m2),
|
|
])
|
|
);
|
|
}
|
|
|
|
async function run() {
|
|
const P = "proj-4725c";
|
|
window.localStorage.setItem("frd_current_project_id", P);
|
|
const savedBase = await savedBaseOf();
|
|
const shop = store.useDesignStore(P, null);
|
|
const restores = [];
|
|
const bridge = pageMod.routeDraftBridge(
|
|
P,
|
|
{
|
|
pipelineSource: () => ({
|
|
base: savedBase,
|
|
edits: alignment.emptyEdits(),
|
|
detail: (slots().keepSavedDetail(P, 7, job.detail), job.detail),
|
|
routeId: 7,
|
|
}),
|
|
adoptPipeline: () => undefined,
|
|
redraw: () => undefined,
|
|
},
|
|
{
|
|
stationIntervalM: job.interval,
|
|
holdDraft: (routeId, saved) => (
|
|
slots().keepHeldDetail(P, routeId, saved),
|
|
async (stations) => {
|
|
restores.push(stations.length);
|
|
return "saved";
|
|
}
|
|
),
|
|
},
|
|
);
|
|
pageMod.pipelineEarthwork(P, { conversion: job.conversion });
|
|
await settle(runs().length + 1);
|
|
const pipe = pageMod.pagePipeline(P);
|
|
const at = (list) => (list ?? []).map((p) => Math.round(p.chainage_m * 100) / 100);
|
|
const opened = { pipes: at(pipe.input("pipes")), store: shop.get("pipes") };
|
|
// 노선 교점 끌기 — 관이 따라 옮겨짐(follow 가 가게 관을 씀)
|
|
bridge.edited(draftOf(shift(1, 8, -6)));
|
|
await settle(runs().length + 1);
|
|
await tick(20);
|
|
const drafted = { pipes: at(shop.get("pipes")), input: at(pipe.input("pipes")) };
|
|
// ↶ — 사진첩: 세션을 그 걸음 값으로 바로 되씀(가게 알림 없음) → 훅(노선 편집기 버림 → 관 먹이기)
|
|
const mark = runs().length;
|
|
page.writeState("pipes", opened.store, P);
|
|
page.writeState("route-draft", null, P);
|
|
bridge.edited(null);
|
|
hooks.forEach((entry) => entry.restore?.("undo"));
|
|
for (let i = 0; i < 400 && !restores.length; i += 1) await tick(5);
|
|
await pipe.settled();
|
|
await tick(30);
|
|
await pipe.settled();
|
|
const after = runs().slice(mark);
|
|
console.log(
|
|
JSON.stringify({
|
|
moved: JSON.stringify(drafted.pipes) !== JSON.stringify(opened.pipes),
|
|
runs: after.map((r) => [r.sources.join("+"), r.outcome, r.restoreWhy ?? ""]),
|
|
restores: restores.length,
|
|
pipes: { opened: opened.pipes, after: at(pipe.input("pipes")), store: shop.get("pipes") },
|
|
routeDraft: shop.get("routeDraft"),
|
|
}),
|
|
);
|
|
pageMod.disposePagePipeline(P);
|
|
}
|
|
|
|
run()
|
|
.then(() => process.exit(0))
|
|
.catch((error) => {
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|