main
John Lauer Publish 0.1.0 b324771 8d ago
"""Original full-length cable display pose. Bending is illustrative, not supplied geometry."""
from pathlib import Path
import sys,json,math,cadquery as cq,hashlib
R=Path(__file__).resolve().parent
from step_geometry import load_step
from glb_shape_helpers import add_shape,write_glb
slug=R.name;raw=load_step(R/(slug+'.step'));body=next(s for s in raw.Solids()if s.BoundingBox().xlen<11 and s.BoundingBox().ylen>2.9)
a=cq.Assembly(name='NTCLE428_illustrative_coiled_display');g={'asset':{'version':'2.0','generator':'Adom original coiled display pose'},'scene':0,'scenes':[{'nodes':[0]}],'nodes':[{'name':'NTCLE428.CoiledDisplay.FullLength','children':[]}],'buffers':[{'byteLength':0}],'accessors':[]};blob=bytearray();items=[('Sensor.Body.MaximumEnvelope',body,(.045,.045,.05))];rows=[]
for n,z in enumerate([.95,2.05],1):
 pts=[cq.Vector(10,0,z),cq.Vector(20,0,z),cq.Vector(30,0,z)]
 T=10.5
 for i in range(1,151):
  t=T*i/150;r=20+2*(t/T)**2;theta=t-math.pi/2
  pts.append(cq.Vector(30+r*math.cos(theta),20+r*math.sin(theta),z))
 curve=cq.Edge.makeSpline(pts,tangents=(cq.Vector(1,0,0),cq.Vector(math.cos(T),math.sin(T),0)))
 length=curve.Length();tail=287-length;assert tail>3,(length,tail)
 direction=curve.tangentAt(1).normalized();end=pts[-1]+direction*tail
 path=cq.Wire.assembleEdges([curve,cq.Edge.makeLine(pts[-1],end)])
 wire=cq.Workplane(cq.Plane(origin=pts[0],normal=(1,0,0))).circle(.425).sweep(path,isFrenet=True).val();tip=cq.Solid.makeCylinder(.15,3,end,direction)
 assert wire.isValid()and tip.isValid();items.extend([(f'Lead.{n}.PVC',wire,(.06,.06,.065)),(f'Lead.{n}.SolderDipped',tip,(.65,.67,.70))]);rows.append({'lead':n,'insulatedExternalCenterlineMm':path.Length(),'exposedMm':3,'equivalentStraightOverallMm':10+path.Length()+3})
for name,shape,color in items:
 a.add(shape,name=name.replace('.','_'),color=cq.Color(*color));add_shape(g,blob,shape,name,color,0,'Illustrative coiled display; full nominal cable length preserved; not a validated installed routing')
a.save(str(R/(slug+'-display.step')));write_glb(R/(slug+'-display.glb'),g,blob)
report={'pose':'Illustrative coiled display, not as-supplied form or qualified harness','leads':rows,'wireToWireIntersectionMm3':items[1][1].intersect(items[3][1]).Volume(),'physicalQualification':False,'sourceStraightStepSha256':hashlib.sha256((R/(slug+'.step')).read_bytes()).hexdigest()};assert report['wireToWireIntersectionMm3']<1e-7
(R/'display-pose-review.json').write_text(json.dumps(report,indent=2)+'\n');print(json.dumps(report))