/* 178-3 사면안정 흙막이 · 옹벽 「추가 단」 헬퍼 — 화면 TS 를 그 자리에서 트랜스파일해 Node 로 돌림. * ① 명세 상자 저장 왕복(readState → writeOptions) ② 구조물 정본 → 벽 제원(`wallSpecsFrom`) → 횡단 형상 * (`computeRevetmentLayout`) 단 수 · 단마다 형태 · 높이. 입력 측점 = 73-4 픽스처(helper_79 와 같은 180 측점). * 결과 = 표준출력 JSON 한 벌 · 짝 = `test_178_3_slope_tiers.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"); // 구조물 표(322-1) const ROOT = path.join(__dirname, "..", ".."); const STUBS = { "@ui/ui_template_toast": { showToast: () => undefined } }; const { loadTs } = makeLoader({ root: ROOT, interop: true, requireFor: (full) => (request) => { if (CATALOG.isCatalogRequest(request)) return CATALOG; if (STUBS[request]) return STUBS[request]; const alias = { "@util/": "common_util", "@ui/": "ui_template", "@config/": "config" }; for (const [prefix, dir] of Object.entries(alias)) if (request.startsWith(prefix)) return loadTs(resolve(path.join(ROOT, dir, request.slice(prefix.length)))); return loadTs(resolve(path.join(path.dirname(full), request))); }, }); const resolve = (base) => [base, `${base}.ts`, path.join(base, "index.ts")].find( (p) => fs.existsSync(p) && fs.statSync(p).isFile(), ) ?? `${base}.ts`; const design = (f) => path.join(ROOT, "A00_Common", "design", f); const spec = loadTs(design("logic/design_structure_spec.ts")); const { ADDON_SPECS } = loadTs(design("logic/design_structure_slope_tier.ts")); const { STRUCTURE_SPECS } = loadTs(design("logic/design_structure_pipe.ts")); const { wallSpecsFrom } = loadTs(path.join(ROOT, "common_util", "common_util_structure_walls.ts")); const { computeRevetmentLayout } = loadTs( path.join(ROOT, "B06_Section", "logic", "B06_Section_Cross_Revetment_Geom.ts"), ); const r3 = (v) => Math.round(v * 1000) / 1000; const out = {}; // ① 저장 왕복 — 상자 둘(흙막이) · 하나(옹벽) · 빈 상자(값 없이 추가만) const soil = ADDON_SPECS.soil_guard; const wall = ADDON_SPECS.retaining_wall; const soilOptions = { form: "돌쌓기(찰)", height_m: 2, tier_1_form: "콘크리트", tier_1_height: 2, tier_2_form: "돌망태", tier_2_height: 1.2, }; const soilState = spec.readState(soil, soilOptions); out.roundTrip = { items: Object.fromEntries( Object.entries(ADDON_SPECS).map(([k, s]) => [k, s.containers[0].items.map((i) => i.id)]), ), soilState: soilState.tier, soilBack: spec.writeOptions(soil, soilState), wallBack: spec.writeOptions(wall, { tier: [{ height: "1.8" }] }), emptyBox: spec.writeOptions(soil, { tier: [{}] }), notMainSpecs: Object.keys(ADDON_SPECS).filter((k) => k in STRUCTURE_SPECS), }; // ② 형상 — 정본 → 벽 제원 → 횡단 단 const fixture = JSON.parse( fs.readFileSync(path.join(__dirname, "fixtures", "b06_73_4_body_guard_sections.json"), "utf8"), ); const base = fixture.cross_sections.find((s) => Math.abs(s.chainage_m - 180) < 0.6); const names = new Map([ ["soil_guard", "흙막이"], ["retaining_wall", "옹벽"], ]); function shape(typeId, options) { const [wallSpec] = wallSpecsFrom( [{ structure_id: "t", type_id: typeId, chainage_m: 180, start_m: 170, end_m: 190, options }], names, ); const section = JSON.parse(JSON.stringify(base)); section.revetment = { ...wallSpec, side: "우" }; const layout = computeRevetmentLayout(section, null); return { tiers: wallSpec.tiers, extras: wallSpec.extras, requested: layout?.requestedTiers ?? null, walls: (layout?.walls ?? []).map((w) => ({ form: w.form, pure: r3(w.height + 0.5) })), }; } out.soil2 = shape("soil_guard", soilOptions); out.wall1 = shape("retaining_wall", { height_m: 2.5, tier_1_height: 1.8 }); out.emptyBox = shape("soil_guard", { form: "돌망태", height_m: 2, tier_1_form: "" }); out.legacy = shape("soil_guard", { form: "돌망태", height_m: 2, tiers: 2 }); out.none = shape("retaining_wall", { height_m: 2.5 }); process.stdout.write(JSON.stringify(out));