"""Ramp-A P1 shape reading (G1 + G5 positions) from D1 by handle -> 판독/g1_values.json. Datums (D1 front view): pier CL x = 86041.7, z(mm) = drawing y + 534115.2 (EL 32.752 at pile bottom y -501363.2, EL 59.952 / 60.267 at coping top y -474163.2 / -473848.2). Plan view: CL x = 86041.7, coping CL y = -465444.9. Model axes: X along the coping (교축직각), Y across (교축), origin = pier centre, Z = EL x 1000. """ import json import math from pathlib import Path from dxftools import doc D = doc("D1") X0, ZOFF = 86041.7, 534115.2 PX0, PY0 = 86041.7, -465444.9 def ent(h): return D.entitydb[h] def z(y): return round(y + ZOFF, 1) def line(h): e = ent(h) return (e.dxf.start.x, e.dxf.start.y), (e.dxf.end.x, e.dxf.end.y) out = {} # front view (a, b) = line("857"); (c, d) = line("7D1") out["coping"] = { "top_left": {"x0": round(line("856")[0][0] - X0, 1), "x1": 0.0, "z": z(line("856")[0][1]), "src": "D1 856"}, "top_right": {"x0": 0.0, "x1": round(line("854")[1][0] - X0, 1), "z": z(line("854")[0][1]), "src": "D1 854"}, "end_left_front": {"bottom": [round(a[0] - X0, 1), z(a[1])], "top": [round(b[0] - X0, 1), z(b[1])], "src": "D1 857"}, "end_right_front": {"bottom": [round(c[0] - X0, 1), z(c[1])], "top": [round(d[0] - X0, 1), z(d[1])], "src": "D1 7D1"}, } for h, k in (("501", "soffit_left"), ("4FF", "soffit_right")): e = ent(h) cx, cz, r = e.dxf.center.x - X0, z(e.dxf.center.y), e.dxf.radius pts = [(round(cx + r * math.cos(math.radians(t)), 1), round(cz + r * math.sin(math.radians(t)), 1)) for t in (e.dxf.start_angle, e.dxf.end_angle)] out["coping"][k] = {"centre": [round(cx, 1), cz], "radius": r, "ends": pts, "src": f"D1 ARC {h}"} (p, q) = line("55A") out["coping"]["column_top_z"] = z(p[1]) # side view (CL x 105105.6) SX0 = 105105.6 (s0, s1) = line("504") out["coping"]["side"] = {"half_width_top": round(SX0 - ent("520").dxf.start.x, 1), "taper": {"from": [round(s1[0] - SX0, 1), z(s1[1])], "to": [round(s0[0] - SX0, 1), z(s0[1])]}, "src": "D1 측면도 520/521 (2,200), 503/504 (2,200 -> 2,000)"} # plan view ends: polyline 51A / 519 with bulge for h, k in (("51A", "plan_end_left"), ("519", "plan_end_right")): pts = ent(h).get_points("xyb") x_top, x_bot, bulge = pts[0][0] - PX0, pts[1][0] - PX0, pts[1][2] chord = abs(pts[2][1] - pts[1][1]) sag = abs(bulge) * chord / 2 out["coping"][k] = {"top_edge_x": round(x_top, 1), "corner_bottom_x": round(x_bot, 1), "half_width": round(chord / 2, 1), "sagitta": round(sag, 1), "radius": round((chord ** 2 / 4 + sag ** 2) / (2 * sag), 1), "src": f"D1 평면 {h} bulge {bulge:.3f}"} # column / pile (front) out["column"] = {"d": round(line("610")[0][0] - line("60F")[0][0], 1), "z0": z(line("60F")[0][1]), "z1": z(line("60F")[1][1]), "src": "D1 60F/610"} out["pile_upper"] = {"d": round(line("87F")[0][0] - line("881")[0][0], 1), "z0": z(line("880")[0][1]), "z1": z(line("881")[1][1]), "src": "D1 880-87F / 882-881, 89F"} out["pile_lower"] = {"d": round(line("875")[0][0] - line("873")[0][0], 1), "z0": z(line("873")[1][1]), "z1": z(line("873")[0][1]), "src": "D1 873/875, 87E"} out["ground_z"] = z(line("89E")[0][1]) # plan: pedestals and pads (corner polylines / lines), rotation from the long (along Y) edge def rect(pts, src): cx = sum(p[0] for p in pts) / 4 - PX0 cy = sum(p[1] for p in pts) / 4 - PY0 e = [(pts[(i + 1) % 4][0] - pts[i][0], pts[(i + 1) % 4][1] - pts[i][1]) for i in range(4)] L = [math.hypot(*v) for v in e] along = max(range(4), key=lambda i: abs(e[i][1])) # edge most parallel to plan Y vx, vy = e[along] if e[along][1] > 0 else (-e[along][0], -e[along][1]) rot = math.degrees(math.atan2(vx, vy)) # + = clockwise from +Y (bearings.py convention) return {"centre": [round(cx, 1), round(cy, 1)], "along": round(L[along], 1), "across": round(L[(along + 1) % 4], 1), "rotation_deg": round(rot, 3), "src": src} out["plan"] = {} for no, ped, pads in ((1, ("49D", "49E", "49F", "4A0"), ("486", "487", "488")), (2, ("4A5", "4A6", "4A7", "4A8"), ("489", "48A", "48B"))): pts = [line(h)[0] for h in ped] out["plan"][no] = {"pedestal": rect(pts, "D1 평면 " + "/".join(ped)), "pads": [rect([p[:2] for p in ent(h).get_points("xy")], f"D1 평면 {h}") for h in pads]} p = Path(__file__).resolve().parent / "판독" / "g1_values.json" p.write_text(json.dumps(out, ensure_ascii=False, indent=1), encoding="utf-8") print(json.dumps(out, ensure_ascii=False, indent=1))