Files
Pier_v1/Code/검토수정/스크립트/c1_hook_okseong.py
T
ahnyongjooandClaude Sonnet 5.5 964a841de1 chore(rebar): Pier_T_rebar 작업 폴더 초기 구성 및 외부 의존 파일 통합
- Code\rebar_pipeline, review_pipeline, pier-program을 정션에서 실제 폴더로 전환
- Code\rhino_mcp 및 CLAUDE_rhino배경.md 추가, .mcp.json은 PYTHONPATH로 새 위치 사용
- pier-program 내부 .git 제거(이력은 backup\pier-program_20261028.bundle에 보관)
- worktree 가이드 반영(CLAUDE.local.md, HANDOFF.md)
- D:\Rhino-MCP 경로 참조를 새 위치로 치환

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-28 11:20:18 +09:00

176 lines
7.3 KiB
Python

#! python3
# Okseong pentagon stirrups C9/C11/C13 lap c=630 (수정7 -> 수정8). Based on: Sanoe coping shear bars rebuilt with lap J (drawing shapes II / III / XII / VIII), as in the Daehoji method
# II (C7-C9) : lid (top bar + both legs C=660 down) + bottom (bottom bar + both legs full height up) [vertical stirrup, plane x=const]
# III (C10) : left U + right U overlapping J=660 at the middle of the top and bottom edges [horizontal band, plane z=const]
# XII (C12) : same as III with corner R400
# VIII(C13) : two hooked pieces overlapping J=660 in the middle of the straight run
# Source: 산외교P1 G5_수정2_20261026.3dm -> 산외교P1 G5_수정4_20261026.3dm (수정3 was cancelled)
import sys, os, json, math, collections, traceback
sys.path.insert(0, r"C:\Users\User\AppData\Local\PierApp\jobs\c1_work")
import c1_core
import Rhino
import Rhino.Geometry as rg
from Rhino.Geometry import Point3d, PolylineCurve, Curve, Brep, PipeCapMode
from c1_core import BASE, required_rc
DATE_TXT = "2026-10-27"
SRC = os.path.join(BASE, "검토_옥성교P1", "옥성교P1_G5_수정8_20261027.3dm")
DST = os.path.join(BASE, "검토_옥성교P1", "옥성교P1_G5_수정9_20261027.3dm")
OUT = r"C:\Users\User\AppData\Local\PierApp\jobs\c1_work\c1_hook_okseong.json"
SPEC = {"C15": ("hook", 0.0), "C17": ("hook", 550.0)}
res = {}
def robust_pipe(curve, d, tol):
for fit, atol in ((True, tol), (False, tol), (True, 0.01), (True, 0.1)):
rr = Brep.CreatePipe(curve, d / 2.0, False, PipeCapMode.Flat, fit, atol, Rhino.RhinoMath.ToRadians(1.0))
if rr and len(rr) == 1 and rr[0].IsSolid:
vol = rg.VolumeMassProperties.Compute(rr[0]).Volume
if abs(vol / (math.pi * (d / 2.0) ** 2 * curve.GetLength()) - 1.0) <= 0.005:
return rr[0]
return None
def fillet_poly(pts, R, tol):
pc = PolylineCurve([Point3d(*p) for p in pts])
f = Curve.CreateFilletCornersCurve(pc, R, tol, Rhino.RhinoMath.ToRadians(1.0))
return f if f is not None else None
def first_arc_radius(c):
for i in range(c.SegmentCount):
ok, arc = c.SegmentCurve(i).TryGetArc()
if ok and not c.SegmentCurve(i).IsLinear():
return arc.Radius
return None
R_H, ARC_LEN, TAIL = 80.0, 188.0, 140.0
def hook_at(p_end, d, n):
# d = bar direction pointing out of the bar at this end, n = in-plane direction toward the section centre
th = ARC_LEN / R_H
cen = p_end + n * R_H
p2 = cen + (n * (-R_H * math.cos(th)) + d * (R_H * math.sin(th)))
t = n * math.sin(th) + d * math.cos(th)
p3 = p2 + t * TAIL
arc = rg.Arc(p_end, d, p2)
return arc, rg.Line(p2, p3)
def make_pieces(c, J, lap):
p0, p1 = c.PointAtStart, c.PointAtEnd
u = p1 - p0
u.Unitize()
sgn = 1.0 if (p0.Y + p1.Y) >= 0 else -1.0
n = rg.Vector3d(0, -sgn, 0)
arcs, tls = hook_at(p0, -u, n)
arce, tle = hook_at(p1, u, n)
def build(parts):
pc = rg.PolyCurve()
for g in parts:
if isinstance(g, rg.Arc):
pc.Append(g)
else:
pc.Append(g)
return pc
def seg_start():
return [rg.Line(tls.To, tls.From), None]
# start hook as arc reversed: tail end -> arc end -> bar start
sa = rg.ArcCurve(arcs)
sa.Reverse()
sl = rg.Line(tls.To, tls.From)
if not lap:
return [("", build([sl, sa, rg.Line(p0, p1), arce, tle]))]
mid = (p0 + p1) / 2.0
h = J / 2.0
left = build([sl, sa, rg.Line(p0, mid + u * h)])
right = build([rg.Line(mid - u * h, p1), arce, tle])
return [("좌", left), ("우", right)]
try:
doc = Rhino.RhinoDoc.OpenHeadless(SRC)
tol = doc.ModelAbsoluteTolerance
st = Rhino.DocObjects.ObjectEnumeratorSettings()
st.HiddenObjects = True; st.LockedObjects = True; st.NormalObjects = True
lay = {l.Index: l.FullPath for l in doc.Layers}
res["objects_before"] = doc.Objects.Count
breps = collections.defaultdict(list)
curves = []
for o in doc.Objects.GetObjectList(st):
g = o.Geometry
L = lay.get(o.Attributes.LayerIndex, "")
if isinstance(g, Brep) and "철근" in L:
breps[o.Attributes.Name].append(o)
elif isinstance(g, Curve) and "중심선" in L and o.Attributes.GetUserString("mark") in SPEC:
curves.append(o)
stat = collections.Counter()
info = collections.defaultdict(lambda: {"len_old": [], "len_new": [], "pieces": 0})
for o in curves:
a = o.Attributes
m = a.GetUserString("mark")
shape, J = SPEC[m]
req, d = required_rc(a.GetUserString("dia"))
nb = breps.get(a.Name.replace("-RC-", "-R-"), [])
c = o.Geometry
if len(nb) != 1:
stat[m + "_unexpected"] += 1
continue
try:
pcs = make_pieces(c, J, J > 0)
except Exception:
res["tb"] = traceback.format_exc()
stat[m + "_split_error"] += 1
continue
pipes = []
for nm, pc in pcs:
pp = robust_pipe(pc, d, tol)
if pp is None:
break
pipes.append(pp)
if len(pipes) != len(pcs):
stat[m + "_pipe_fail"] += 1
continue
cid, bid = o.Id, nb[0].Id
bname = nb[0].Attributes.Name
ok1 = doc.Objects.Replace(cid, pcs[0][1]) and doc.Objects.Replace(bid, pipes[0])
if not ok1:
stat[m + "_replace_failed"] += 1
continue
if len(pcs) == 2:
ca2, ba2 = a.Duplicate(), nb[0].Attributes.Duplicate()
ca2.Name = a.Name + "-" + pcs[1][0]
ba2.Name = bname + "-" + pcs[1][0]
doc.Objects.AddCurve(pcs[1][1], ca2)
doc.Objects.AddBrep(pipes[1], ba2)
for oid, base, nm in ((cid, a.Name, pcs[0][0]), (bid, bname, pcs[0][0])):
ro = doc.Objects.FindId(oid)
at = ro.Attributes.Duplicate()
if nm:
at.Name = base + "-" + nm
at.SetUserString("hook_fix", "both ends hooked r80 arc188 (134.65deg) tail140, toward section centre in plane z=const (%s)" % DATE_TXT)
doc.Objects.ModifyAttributes(ro, at, True)
i2 = info[m]
i2["pieces"] += len(pcs)
i2["len_old"].append(c.GetLength())
i2["len_new"].append(sum(q[1].GetLength() for q in pcs))
stat[m + "_done"] += 1
res["stat"] = dict(stat)
res["info"] = {m: {"bars": len(v["len_old"]), "avg_len_old": round(sum(v["len_old"]) / max(1, len(v["len_old"])), 1),
"avg_len_new_sum_of_pieces": round(sum(v["len_new"]) / max(1, len(v["len_new"])), 1)} for m, v in info.items()}
doc.Strings.SetString("수정일", DATE_TXT)
prev = doc.Strings.GetValue("수정내용") or ""
doc.Strings.SetString("수정내용", (prev + " | " if prev else "") + "coping ties C15,C17 rebuilt with end hooks (r80, arc188, tail140), C17 two pieces lapped j550")
res["objects_after"] = doc.Objects.Count
res["saved"] = bool(doc.WriteFile(DST, Rhino.FileIO.FileWriteOptions()))
res["out"] = DST
doc.Dispose()
except Exception:
res["error"] = traceback.format_exc()
res["done"] = True
json.dump(res, open(OUT, "w", encoding="utf-8"), ensure_ascii=False, indent=1)