- 노선 저장 전 · 뒤 정본 관을 받아 초안을 얹음(rebasePipeDraft) — 옛 자리 그대로인 관 = 서버가 옮긴 자리 · 옵션 고침은 그대로 · 사용자가 옮긴 · 새로 놓은 관 그대로 · 지운 관 없음 · 서버가 새로 놓은 교차 관 붙음 - 관 초안이 없거나 노선 저장이 없으면 전과 같음 - 따라감 미리보기 — 좌표 없는 초안 관 중 안 옮긴 것은 정본 좌표로(서버 노선 저장과 같은 측점) - 시험 test_349_0u_save_rebase(실제 design_save · 서버 따라감 = project_pipe_points) · test_349_0u_follow_draft_xy 서버 대조 · design_store_save 가짜 보탬 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TteK8mfYZetk5P3bEZkyVZ
234 lines
8.4 KiB
JavaScript
234 lines
8.4 KiB
JavaScript
/* PLAN 349-0u sub7 헬퍼 — 세션 관 · 구조물 초안에 좌표가 없어도(배수유역도 · 구조물 목록이 정본 PUT 꼴로 씀)
|
|
* 앞쪽 꺾임점을 끌면 follow 가 새 측점을 가게에 바로 · 되돌리기 = 초안 값 · 다시하기 = 다시 밂 · 조작 하나 =
|
|
* 묶음 한 번. 나머지 틀 = `helper_349_0d_follow_store.cjs` 그대로. 짝 = `test_349_0u_follow_draft_xy.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,
|
|
};
|
|
|
|
// 흙 배분 서버 — 늦게 답함 · 끊기면 버림
|
|
globalThis.fetch = (url, init) =>
|
|
new Promise((resolve, reject) => {
|
|
const timer = setTimeout(
|
|
() => resolve({ ok: true, json: async () => ({ haul_plan: { blocks: [], url } }) }),
|
|
20,
|
|
);
|
|
init.signal.addEventListener("abort", () => {
|
|
clearTimeout(timer);
|
|
reject(new Error("aborted"));
|
|
});
|
|
});
|
|
|
|
const STUBS = {};
|
|
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));
|
|
|
|
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: job.curves,
|
|
min_radius_m: job.minRadius,
|
|
station_snap: job.stationSnap,
|
|
}),
|
|
};
|
|
STUBS["B05_Profile_Api_Structures"] = {
|
|
fetchStructures: async () => ({ structures: job.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 pageMod = load("A00_Common", "design", "design_pipeline_page.ts");
|
|
const storeMod = load("A00_Common", "design", "design_store.ts");
|
|
const alignment = load("B05_Profile", "logic", "B05_Profile_UI_Profile_Alignment.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 quiet() {
|
|
let seen = -1;
|
|
for (let i = 0; i < 400; i += 1) {
|
|
await tick(15);
|
|
const last = runs()[runs().length - 1];
|
|
const count = runs().length;
|
|
if (count === seen && (!last || last.outcome !== "running")) return;
|
|
seen = count;
|
|
}
|
|
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: job.stationSnap,
|
|
});
|
|
const shift = (index, dx, dy) =>
|
|
job.nodes.map((node, i) => (i === index ? [node[0] + dx, node[1] + dy] : node));
|
|
const chainagesOf = (stations) => (stations ?? []).map((s) => s.chainageM);
|
|
|
|
const P = "proj-3490u";
|
|
const ids = (list) => (list ?? []).map((item) => [item.id ?? item.structure_id, item.chainage_m]);
|
|
const lengthOf = (line) =>
|
|
(line ?? []).reduce(
|
|
(sum, p, i) => (i ? sum + Math.hypot(p[0] - line[i - 1][0], p[1] - line[i - 1][1]) : 0),
|
|
0,
|
|
);
|
|
|
|
async function run() {
|
|
window.localStorage.setItem("frd_current_project_id", P);
|
|
const savedAlignment = job.detail.longitudinal.profile_alignment;
|
|
const savedBase = alignment.toAlignmentBase(savedAlignment);
|
|
const followed = [];
|
|
const link = {
|
|
pipelineSource: () => ({
|
|
base: savedBase,
|
|
edits: savedAlignment.edits,
|
|
detail: job.detail,
|
|
routeId: 7,
|
|
}),
|
|
adoptPipeline: (base, edits, draft) =>
|
|
pageMod.pipelineGrade(P, draft ? edits : savedAlignment.edits),
|
|
redraw: () => undefined,
|
|
side: null,
|
|
};
|
|
const store = storeMod.useDesignStore(P, null);
|
|
// 세션 초안 = 정본 PUT 꼴(좌표 뺌) — 배수유역도 · 구조물 목록이 열 때 · 고칠 때 씀
|
|
const draftPipes = job.pipes.map(({ x: _x, y: _y, ...pipe }) => pipe);
|
|
const draftStructures = job.structures.map(({ x: _x, y: _y, ...item }) => item);
|
|
store.set("pipes", draftPipes);
|
|
store.set("structures", draftStructures);
|
|
const bridge = pageMod.routeDraftBridge(P, link, {
|
|
stationIntervalM: job.interval,
|
|
onFacilitiesFollowed: (far) => followed.push(far),
|
|
});
|
|
pageMod.pipelineEarthwork(P, { conversion: job.conversion });
|
|
await quiet();
|
|
const pipe = pageMod.pagePipeline(P);
|
|
const savedLength = lengthOf(pipe.output("route")?.line);
|
|
const open = {
|
|
pipes: ids(store.get("pipes")),
|
|
structures: ids(store.get("structures")),
|
|
followed: [...followed],
|
|
};
|
|
const snapshot = {};
|
|
for (let i = 0; i < window.sessionStorage.length; i += 1) {
|
|
const key = window.sessionStorage.key(i);
|
|
snapshot[key] = window.sessionStorage.getItem(key);
|
|
}
|
|
const step = async (edit) => {
|
|
const mark = runs().length;
|
|
const before = followed.length;
|
|
bridge.edited(edit);
|
|
await quiet();
|
|
return {
|
|
runs: runs()
|
|
.slice(mark)
|
|
.map((r) => r.sources),
|
|
pipes: ids(store.get("pipes")),
|
|
structures: ids(store.get("structures")),
|
|
length: lengthOf(pipe.output("route")?.line),
|
|
followed: followed.slice(before),
|
|
blocked: pipe.blockedWrites,
|
|
};
|
|
};
|
|
// 앞쪽(시작 쪽) 꺾임점을 크게 끌어 놓음 — 그 뒤 관 · 구조물은 길이가 는 만큼 뒤로
|
|
const dragged = draftOf(shift(1, job.dx, job.dy));
|
|
const drag = await step(dragged);
|
|
drag.line = pipe.output("route")?.line; // 서버 따라감 대조(파이썬)
|
|
// 되돌리기 — 사진첩이 세션을 되쓴 뒤 초안 없음
|
|
for (const key of Object.keys(snapshot)) window.sessionStorage.setItem(key, snapshot[key]);
|
|
for (let i = window.sessionStorage.length - 1; i >= 0; i -= 1) {
|
|
const key = window.sessionStorage.key(i);
|
|
if (!(key in snapshot)) window.sessionStorage.removeItem(key);
|
|
}
|
|
const undo = await step(null);
|
|
const redo = await step(dragged);
|
|
const undo2 = await step(null);
|
|
pageMod.disposePagePipeline(P);
|
|
return {
|
|
savedLength,
|
|
open,
|
|
drag,
|
|
undo,
|
|
redo,
|
|
undo2,
|
|
draftPipes: ids(draftPipes),
|
|
draftStructures: ids(draftStructures),
|
|
};
|
|
}
|
|
|
|
run()
|
|
.then((out) => {
|
|
process.stdout.write(JSON.stringify(out));
|
|
process.exit(0);
|
|
})
|
|
.catch((error) => {
|
|
process.stderr.write(String(error && error.stack ? error.stack : error));
|
|
process.exit(1);
|
|
});
|