Files
Aislo/resources/tester/helper_319_kind_swap.cjs
T
eomsangdonandClaude Opus 5.5 bbd6254892 feat(구조물표): 322-1 부품 상자 · 표 읽기 — 목록 · 측점 · 카드 이름 · 형상 고르기 · 3D 몸체 · 알약 띠가 종류 키 · 군 글자 · 자리꼴 · managed_by 대신 구조물 표(catalog) 한 줄을 읽음 · 코드 숨김 목록 걷음 · ★ 넷 + 관 공식 한 벌
- 부품 상자 common_util_structure_parts.json(갈래마다 부품 · 읽는 칸 · 자리꼴 · 정본 · 42종 처음값) · 표 읽기 common_util_structure_catalog.ts / .py 짝(정의 반영 ⊕ 처음값 ⊕ 부품 끔) · 거울 시험 test_322_1_catalog_mirror
- 목록: pickGroups 군 차례 = 구조물군 열쇠 · 페이지 거르기 listPick(B05 both · B06 both + b06) · HIDDEN_PICK_GROUPS · HIDDEN_PICK_TYPES · pickable 걷음(옛 대피 셋 asRoad 그대로)
- 측점: structureStationMarks · pipeStationMarks · is_station_planting_type · resolve_extra_stations = 표 횡단도(anchor · span3 · none)
- 카드 이름: cardTitle / card_title 한 공식(빈칸 = 그 종류 정의 기본값) · 표시 이름이 정의 관종도 앎
- 형상: 벽 = shape wall(형태 = 형상칸.form · 물빼기 = 형상칸.weep) · 포장 = shape pavement(「사용 중」 거르기 없앰) · 맹암거 · 사토 · 관 지점 시설 세트 = shape
- 3D 몸체 = 그림 자료 주인 종류의 표 3D 부품 · 알약 띠 = 표 자리꼴 구간(관 지점 시설은 알약만)
- ★1 노출형 · 개거 횡단도 none · ★2 쇄석 화면에서도 포장층 · ★3 기슭막이 표 자리꼴 interval(정의 파일 그대로) · ★4 코드 숨김 10종 list hidden · ★5 관 빈칸 D800 → 정의 기본 D1000
- 옛 시험: 도움 파일 로더 27개가 표 모듈 공용 한 벌(helper_322_catalog_module) 씀 · 기대값 고침(272_1 · b05_extra_stations · roundtrip · 314 · 52_7 · walls 거울 · wall_drain_pipe)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ji4nuyLVHcxrXWHTdb5nRD
2026-10-14 15:09:45 +09:00

322 lines
12 KiB
JavaScript

/* PLAN 319 단위검증 헬퍼 — 정본이 다른 종류로 바꿈(관 지점 ↔ 구조물 · 맹암거 · 개거) = 옛 것 지우고 같은
* 측점에 새 종류(패널 입력 배선) · 일반 측점 자리(grid) 종류 바꿈 · 지움 = 구조물만 뺀 사본에 새 종류(횡단 초안 맞춤).
* 진짜 TS 를 그 자리에서 트랜스파일해 Node 로 돌림(서버 · 무거운 화면 모듈은 흉내) · 결과 = 표준출력 JSON 한 벌.
* 짝 = `test_319_kind_swap.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"); // 구조물 표(322-1)
const ROOT = path.join(__dirname, "..", "..");
const B05 = (name) => path.join(ROOT, "B05_Profile", `${name}.ts`);
const B06 = (name) => path.join(ROOT, "B06_Section", `${name}.ts`);
const TYPES = JSON.parse(
fs.readFileSync(path.join(ROOT, "resources", "master_template", "구조물정의.json"), "utf8"),
).types;
class FakeStorage {
constructor() {
this.map = new Map();
}
get length() {
return this.map.size;
}
key(index) {
return [...this.map.keys()][index] ?? null;
}
getItem(key) {
return this.map.has(key) ? this.map.get(key) : null;
}
setItem(key, value) {
this.map.set(key, String(value));
}
removeItem(key) {
this.map.delete(key);
}
}
globalThis.window = {
sessionStorage: new FakeStorage(),
localStorage: new FakeStorage(),
addEventListener: () => {},
removeEventListener: () => {},
dispatchEvent: () => true,
requestAnimationFrame: (fn) => fn(),
setTimeout,
clearTimeout,
};
globalThis.sessionStorage = window.sessionStorage;
globalThis.localStorage = window.localStorage;
globalThis.requestAnimationFrame = (fn) => fn();
globalThis.document = { activeElement: null, addEventListener: () => {} };
const anything = () =>
new Proxy({}, { get: (_t, key) => (key === "__esModule" ? false : () => undefined) });
/** `real` 에 든 파일만 진짜로 읽고 그 밖 상대 경로는 흉내 · `stubs` 는 지정자 그대로 갈음. */
function makeLoader(real, stubs = {}) {
const cache = new Map();
const realSet = new Set(real.map((file) => path.resolve(file)));
const load = (file) => {
const full = path.resolve(file);
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 need = (spec) => {
if (CATALOG.isCatalogRequest(spec)) return CATALOG;
if (spec in stubs) return stubs[spec];
let target = null;
if (spec.startsWith("@util/")) target = path.join(ROOT, "common_util", `${spec.slice(6)}.ts`);
else if (spec.startsWith(".")) target = path.join(path.dirname(full), `${spec}.ts`);
if (target && realSet.has(path.resolve(target))) return load(target);
return anything();
};
new Function("exports", "module", "require", js)(box.exports, box, need);
return box.exports;
};
return load;
}
const out = {};
// ── 1. 패널 종류 바꿈(319-2) — 정본 다른 종류 = 지우고 같은 측점 addAt ─────────────
{
const load = makeLoader(
[
B05("B05_Profile_UI_Structures_Panel_Events"),
B05("B05_Profile_Api_Structures"),
B06("B06_Section_Api_Culvert_Options"),
path.join(ROOT, "A00_Common", "b_page_state.ts"),
path.join(ROOT, "A00_Common", "design", "design_selection.ts"),
path.join(ROOT, "common_util", "common_util_summary_item.ts"),
],
{
"./B05_Profile_UI_Structures_Define": { asRoad: (record) => record },
"@ui/ui_template_elements": { showConfirmDialog: async () => true, showToast: () => {} },
"./B06_Section_Section_Drafts": { forgetPreviewAdjusts: () => {} },
},
);
const { bindStructuresEvents } = load(B05("B05_Profile_UI_Structures_Panel_Events"));
const typeMap = new Map(TYPES.map((type) => [type.type_id, type]));
const el = () => ({
value: "",
listeners: {},
addEventListener(t, fn) {
this.listeners[t] = fn;
},
});
const fields = () => ({ station: el(), remainder: el(), wrap: { hidden: false } });
const run = ({ structures = [], pipes = [], editing = null, pipeAt = null, next }) => {
const calls = {
removed: [],
addAt: [],
emit: 0,
live: 0,
reset: 0,
editingSet: [],
pipeSet: [],
};
let editingId = editing;
let selectedPipe = pipeAt;
const ctx = {
groupSelect: el(),
typeSelect: el(),
primary: el(),
removeButton: el(),
resetButton: el(),
positionRow: el(),
memoField: el(),
optionRow: el(),
optionInputs: [],
anchorFields: fields(),
startFields: fields(),
endFields: fields(),
facilityOptions: { root: el(), readOptions: () => ({}) },
groupBoxes: { shapes: () => ({}), get: () => ({}), set: () => {}, setShapes: () => {} },
structures,
projectId: "P",
callbacks: {
onPipeRemove: (at) => calls.removed.push(at),
onListRelease: () => {},
},
pipeFacilities: () => pipes,
types: () => TYPES,
typeMap: () => typeMap,
currentType: () => (next ? typeMap.get(next) : null),
editingId: () => editingId,
setEditingId: (value) => {
editingId = value;
calls.editingSet.push(value);
},
selectedPipeChainage: () => selectedPipe,
setSelectedPipeChainage: (value) => {
selectedPipe = value;
calls.pipeSet.push(value);
},
summary: () => null,
setSummary: () => {},
cancelTempPipe: () => {},
resetForm: () => (calls.reset += 1),
syncTypeOptions: () => {},
syncPlacementFields: () => {},
renderOptionFields: () => {},
syncFacilityForm: () => {},
liveCommit: () => (calls.live += 1),
emit: () => (calls.emit += 1),
addAt: (at, typeId) => calls.addAt.push([at, typeId]),
interval: () => 20,
};
bindStructuresEvents(ctx);
ctx.typeSelect.listeners.change();
return { ...calls, left: structures.map((s) => s.type_id) };
};
const store = window.sessionStorage;
const kindreset = () => JSON.parse(store.getItem("aislo:draft:kindreset:P") ?? "null");
store.setItem(
"aislo:draft:culvertopt:P:1",
JSON.stringify({ "80.00": { a: 1 }, "300.00": { b: 2 } }),
);
out.pipe_to_underdrain = {
...run({ pipes: [{ chainage_m: 80, facility: "pipe" }], pipeAt: 80, next: "cross_underdrain" }),
kindreset: kindreset(),
culvertopt: JSON.parse(store.getItem("aislo:draft:culvertopt:P:1")),
};
// 새로 놓인 맹암거(같은 측점) → 처음 종류(배관)로 되돌림 = 비울 자리 기록이 빠짐(318-4 규칙)
out.underdrain_back_to_pipe = {
...run({
structures: [
{ structure_id: "n1", type_id: "cross_underdrain", placement: "point", chainage_m: 80 },
],
editing: "n1",
next: "pipe",
}),
kindreset: kindreset(),
};
out.open_ditch_to_box = {
...run({
structures: [
{ structure_id: "s1", type_id: "sign", placement: "point", chainage_m: 10 },
{ structure_id: "s9", type_id: "open_ditch", placement: "point", chainage_m: 120 },
],
editing: "s9",
next: "box_culvert",
}),
kindreset: kindreset(),
};
out.pipe_to_box = run({
pipes: [{ chainage_m: 200, facility: "pipe" }],
pipeAt: 200,
next: "box_culvert",
});
out.underdrain_to_open_ditch = run({
structures: [
{ structure_id: "s2", type_id: "cross_underdrain", placement: "point", chainage_m: 60 },
],
editing: "s2",
next: "open_ditch",
});
out.to_blank = run({ pipes: [{ chainage_m: 200, facility: "pipe" }], pipeAt: 200, next: null });
}
// ── 2. 일반 측점 자리(grid) — 종류 바꿈 = 새로 뜬 횡단 · 다 빠짐 = 시설 뺀 사본(319-2) ──────
const state = { draftPipes: null, draftStructures: null, savedPipes: [], savedStructures: [] };
(async () => {
const load = makeLoader(
[
B06("B06_Section_Section_Drafts"),
path.join(ROOT, "common_util", "common_util_culvert_sets.ts"),
path.join(ROOT, "common_util", "common_util_structure_station.ts"),
],
{
"../B04_PreProcess/B04_PreProcess_Api_Fetch": {
fetchDetailPipePoints: async () => ({ pipe_points: state.savedPipes }),
},
"../B05_Profile/B05_Profile_Api_Structures": {
fetchStructures: async () => ({ structures: state.savedStructures }),
fetchStructureTypes: async () => TYPES,
readPendingStructures: () => state.draftStructures,
},
"../B05_Profile/B05_Profile_Api_Pipes_Draft": { readPendingPipes: () => state.draftPipes },
"./B06_Section_Api_Fetch": {
previewStructureSections: async (_p, chainages) =>
chainages.map((at) => ({ chainage_m: at, kind: "irregular", design: { fresh: true } })),
},
},
);
const { withDraftStations, forgetDraftStations } = load(B06("B06_Section_Section_Drafts"));
const D800 = { pipe_kind: "파형강관", pipe_diameter_mm: "800" };
const detailWith = (spec) => ({
cross_sections: [
{ chainage_m: 20, kind: "regular", design: {} },
{ chainage_m: 40, kind: "irregular", grid: true, design: { keep: 1 }, ...spec },
{ chainage_m: 60, kind: "regular", design: {} },
],
});
const at40 = (detail) => {
const section = detail.cross_sections.find((s) => Math.abs(s.chainage_m - 40) < 0.01);
return {
count: detail.cross_sections.length,
keys: Object.keys(section).filter((k) =>
["culvert", "box", "ford", "ford_pavement"].includes(k),
),
structure: section.structure ?? null,
preview: Boolean(section.preview),
fresh: Boolean(section.design?.fresh),
keep: section.design?.keep ?? null,
};
};
const grid = {};
// 저장분 = 격자 40 위 배관
state.savedPipes = [{ chainage_m: 40, facility: "pipe", options: D800 }];
state.savedStructures = [];
let detail = detailWith({ structure: "파형강관 D800", culvert: { chainage_m: 40 } });
state.draftPipes = [];
state.draftStructures = [
{
structure_id: "n1",
type_id: "cross_underdrain",
placement: "point",
chainage_m: 40,
options: {},
},
];
await withDraftStations(detail, "P", 1);
grid.pipe_to_underdrain = at40(detail);
state.draftStructures = [];
await withDraftStations(detail, "P", 1);
grid.pipe_deleted = at40(detail);
state.draftPipes = [{ chainage_m: 40, facility: "pipe", options: D800 }];
state.draftStructures = null;
await withDraftStations(detail, "P", 1);
grid.pipe_back = at40(detail);
state.draftPipes = [{ chainage_m: 40, facility: "box_culvert" }];
await withDraftStations(detail, "P", 1);
grid.pipe_to_box = at40(detail);
// 저장분 = 격자 40 위 맹암거 → 배관
forgetDraftStations("P");
state.savedPipes = [];
state.savedStructures = [
{
structure_id: "s1",
type_id: "cross_underdrain",
placement: "point",
chainage_m: 40,
options: {},
},
];
detail = detailWith({ structure: "맹암거", underdrain: { chainage_m: 40 } });
state.draftPipes = [{ chainage_m: 40, facility: "pipe", options: D800 }];
state.draftStructures = [];
await withDraftStations(detail, "P", 1);
grid.underdrain_to_pipe = at40(detail);
forgetDraftStations("P");
out.grid = grid;
process.stdout.write(JSON.stringify(out));
})().catch((error) => {
process.stderr.write(String(error && error.stack ? error.stack : error));
process.exit(1);
});