Files
Pier_v1/Code/검토수정/스크립트/c1_lap_sanoe_footing.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

178 lines
7.8 KiB
Python

#! python3
# Pilot: 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_수정4_20261026.3dm")
DST = os.path.join(BASE, "검토_산외교P1", "산외교P1 G5_수정5_20261027.3dm")
OUT = r"C:\Users\User\AppData\Local\PierApp\jobs\c1_work\c1_lap_sanoe_footing.json"
SPEC = {"B2": ("IV", 1000.0), "B5": ("IV", 1000.0), "B8": ("V", 570.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
def pieces_II(c, C, tol):
bb = c.GetBoundingBox(True)
x = (bb.Min.X + bb.Max.X) / 2.0
y0, y1, zb, zt = bb.Min.Y, bb.Max.Y, bb.Min.Z, bb.Max.Z
R = first_arc_radius(c)
lid = fillet_poly([(x, y0, zt - C), (x, y0, zt), (x, y1, zt), (x, y1, zt - C)], R, tol)
bot = fillet_poly([(x, y0, zt), (x, y0, zb), (x, y1, zb), (x, y1, zt)], R, tol)
return [("뚜껑", lid), ("바닥", bot)]
def pieces_band(c, J, tol):
bb = c.GetBoundingBox(True)
xc = (bb.Min.X + bb.Max.X) / 2.0
x0, x1, y0, y1, z = bb.Min.X, bb.Max.X, bb.Min.Y, bb.Max.Y, bb.Min.Z
R = first_arc_radius(c)
h = J / 2.0
left = fillet_poly([(xc + h, y1, z), (x0, y1, z), (x0, y0, z), (xc + h, y0, z)], R, tol)
right = fillet_poly([(xc - h, y1, z), (x1, y1, z), (x1, y0, z), (xc - h, y0, z)], R, tol)
return [("좌", left), ("우", right)]
def pieces_VIII(c, J):
# main straight run = longest segment; split with J overlap at its middle
best, bl = None, 0.0
for i in range(c.SegmentCount):
s = c.SegmentCurve(i)
if s.IsLinear() and s.GetLength() > bl:
best, bl = i, s.GetLength()
s = c.SegmentCurve(best)
p0, p1 = s.PointAtStart, s.PointAtEnd
mid = (p0 + p1) / 2.0
u = p1 - p0
u.Unitize()
a = mid - u * (J / 2.0)
b = mid + u * (J / 2.0)
ta = c.ClosestPoint(a)[1]
tb = c.ClosestPoint(b)[1]
first = c.Trim(c.Domain.Min, tb) # left hook ... up to b (extends J/2 past the middle)
second = c.Trim(ta, c.Domain.Max) # from a (J/2 before the middle) ... right hook
return [("좌", first), ("우", second)]
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 or not isinstance(c, rg.PolyCurve):
stat[m + "_unexpected"] += 1
continue
try:
if shape == "II":
pcs = pieces_II(c, J, tol)
elif shape in ("III", "XII", "V"):
pcs = pieces_band(c, J, tol)
else:
pcs = pieces_VIII(c, J) # IV: two L pieces overlapping J at the middle of the long straight bottom run
except Exception:
stat[m + "_split_error"] += 1
continue
if any(p[1] is None for p in pcs):
stat[m + "_piece_none"] += 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) != 2:
stat[m + "_pipe_fail"] += 1
continue
cid, bid = o.Id, nb[0].Id
ca = a.Duplicate()
ba = nb[0].Attributes.Duplicate()
(n1, c1), (n2, c2) = pcs
ok1 = doc.Objects.Replace(cid, c1) and doc.Objects.Replace(bid, pipes[0])
if not ok1:
stat[m + "_replace_failed"] += 1
continue
ca2, ba2 = a.Duplicate(), nb[0].Attributes.Duplicate()
for at, nm, base in ((ca2, n2, a.Name), (ba2, n2, nb[0].Attributes.Name)):
at.Name = base + "-" + nm
doc.Objects.AddCurve(c2, ca2)
doc.Objects.AddBrep(pipes[1], ba2)
for oid, nm, base in ((cid, n1, a.Name), (bid, n1, nb[0].Attributes.Name)):
ro = doc.Objects.FindId(oid)
at = ro.Attributes.Duplicate()
at.Name = base + "-" + n1
at.SetUserString("lap_fix", "shape %s: two pieces (%s/%s) lapped J=%.0f (%s)" % (shape, n1, n2, J, DATE_TXT))
doc.Objects.ModifyAttributes(ro, at, True)
i = info[m]
i["pieces"] += 2
i["len_old"].append(c.GetLength())
i["len_new"].append(c1.GetLength() + c2.GetLength())
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 "") + "footing bars B2,B5 (IV, J1000) and B8 (V, J570) rebuilt with lap J")
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)