/* 451 헬퍼 — B06 에서 노선 초안 버림 바로 뒤 cross 입력(횡단 보기)이 와도 되돌림까지(B05 와 같게). 진짜 TS * (`design_pipeline_page` · 단계 파일 전부)를 Node 로 · 서버 창구만 가짜(틀 = `helper_365_page_pipeline.cjs`). * 입력 argv[2] JSON · argv[3] 격자 이진 · 결과 = 표준출력 JSON. 짝 = `test_451_drop_cross.py`. */ const fs = require("fs"); const path = require("path"); const { makeLoader } = require("./helper_ts_stub_loader.cjs"); 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 = {}; const { load, loadTs } = makeLoader({ root: ROOT, requireFor: (full) => (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); }, }); // 상세 가게 칸(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-451"; window.localStorage.setItem("frd_current_project_id", P); const savedBase = await savedBaseOf(); const shop = store.useDesignStore(P, null); const restores = []; const adopts = []; const bridge = pageMod.routeDraftBridge( P, { pipelineSource: () => ({ base: savedBase, edits: alignment.emptyEdits(), detail: (slots().keepSavedDetail(P, 7, job.detail), job.detail), routeId: 7, }), adoptPipeline: (_base, _edits, draft) => adopts.push(draft ? "draft" : "saved"), redraw: () => undefined, }, { stationIntervalM: job.interval, holdDraft: (routeId, saved) => ( slots().keepHeldDetail(P, routeId, saved), // 초안 전 상세 칸(472-5 · 가게 hold 와 같음) async (stations) => { restores.push({ at: adopts.length, stations: stations.length }); return "saved"; } ), }, ); pageMod.pipelineEarthwork(P, { conversion: job.conversion }); await settle(runs().length + 1); const savedStations = (shop.get("stations") ?? []).map((s) => s.chainageM); bridge.edited(draftOf(shift(1, 8, -6))); await settle(runs().length + 1); await tick(20); const draftStations = (shop.get("stations") ?? []).map((s) => s.chainageM); // 버림 바로 뒤 cross 입력 — 횡단 보기가 세션 고침을 묶음에 넘김(B06) const mark = runs().length; adopts.length = 0; bridge.edited(null); await tick(2); // 버림 차례가 돌기 시작한 뒤 const wider = { ...job.standard, road_width_m: (job.standard.road_width_m ?? 3) + 0.5 }; STUBS["B06_Section_UI_Standard_Panel"].effectiveStandardCross = () => wider; // 표준 고침 = 새 cross 입력 pageMod.pipelineCross(P); for (let i = 0; i < 400 && !restores.length; i += 1) await tick(5); await pageMod.pagePipeline(P).settled(); await tick(30); const after = runs().slice(mark); const out = { moved: JSON.stringify(savedStations) !== JSON.stringify(draftStations), runs: after.map((r) => [r.sources.join("+"), r.outcome, r.restoreWhy ?? ""]), restores: [...restores], adopts: [...adopts], stationsPublished: JSON.stringify((shop.get("stations") ?? []).map((s) => s.chainageM)) !== JSON.stringify(draftStations), routeDraft: shop.get("routeDraft"), }; // 버림이 안 밀린 길(B05) — 그대로 한 번 bridge.edited(draftOf(shift(1, 8, -6))); await settle(runs().length + 1); const mark2 = runs().length; restores.length = 0; bridge.edited(null); for (let i = 0; i < 400 && !restores.length; i += 1) await tick(5); await pageMod.pagePipeline(P).settled(); out.plain = { runs: runs() .slice(mark2) .map((r) => [r.sources.join("+"), r.outcome, r.restoreWhy ?? ""]), restores: restores.length, }; // 버림 뒤 새 초안이 밀어냄 — 되돌림 없음(초안이 이김) const mark3 = runs().length; restores.length = 0; bridge.edited(null); bridge.edited(draftOf(shift(1, 8, -6))); await settle(runs().length + 1); await pageMod.pagePipeline(P).settled(); await tick(30); out.redraft = { runs: runs() .slice(mark3) .map((r) => [r.sources.join("+"), r.outcome, r.restoreWhy ?? ""]), restores: restores.length, draft: shop.get("routeDraft") !== null, }; pageMod.disposePagePipeline(P); return out; } 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); });