import sand3d as s3d
def clamp_meter():
root = s3d.at(meter_body(), y=-44.5)
dial = s3d.at(selector_dial(), x=-4, y=18, z=18)
mid = s3d.at(middle_key(), x=36.5, y=4, z=17)
low = s3d.at(lower_key(), x=36.5, y=-12, z=17)
up = s3d.at(upper_key(), x=36.5, y=20, z=17)
button = s3d.at(round_button(), x=18.5, y=-13, z=19)
s3d.joint(&class="tok-comment">#39;joint_knob_01_joint_00class="tok-string">39;, dial, on=s3d.local(root, x=-4, y=62.5, z=25), kind=39;revoluteclass="tok-string">39;, axis=39;+Z39;, range=(-100, 0))
s3d.joint(&class="tok-comment">#39;joint_button_03_joint_00class="tok-string">39;, mid, on=s3d.local(root, x=37, y=48.5, z=20), kind=39;prismaticclass="tok-string">39;, axis=39;+Z39;, range=(0, 0.000001))
s3d.joint(&class="tok-comment">#39;joint_button_02_joint_00class="tok-string">39;, low, on=s3d.local(root, x=37, y=32.5, z=20), kind=39;prismaticclass="tok-string">39;, axis=39;+Z39;, range=(-1, 0))
s3d.joint(&class="tok-comment">#39;joint_button_04_joint_00class="tok-string">39;, up, on=s3d.local(root, x=37, y=64.5, z=20), kind=39;prismaticclass="tok-string">39;, axis=39;+Z39;, range=(0, 0.000001))
s3d.joint(&class="tok-comment">#39;joint_button_01_joint_00class="tok-string">39;, button, on=s3d.local(root, x=18, y=31.5, z=22), kind=39;prismaticclass="tok-string">39;, axis=39;+Z39;, range=(-2, 0))
return s3d.assembly(&class="tok-comment">#39;clamp_meter39;, root, dial, mid, low, up, button)
def meter_body(h=23, cy=44.5, edge=3, start=-59, end=119, bottom=-29, top=37, inset=7, clamp_x=-83, clamp_w=72, clamp_d=64, clamp_h=16, opening_x=-78, opening_w=48, opening_d=34, panel_x=74, panel_d=46, screen_x=58, screen_w=22, screen_d=36, key_x=36.5, dial_x=-4, dial_y=18, dial_d=43, lever_x=-17, lever_w=42, lead_d=1.5):
my = (bottom+top)/2
outline = s3d.poly([(start,bottom),(end,bottom+inset),(end,top-inset),(start,top)], fillet=inset)
base = s3d.at(s3d.extrude(&class="tok-comment">#39;lower_case39;, outline, h=dial_y), y=cy)
base = s3d.fillet(base, r=edge, edges=&class="tok-comment">#39;bottom39;)
cap = s3d.at(s3d.extrude(&class="tok-comment">#39;upper_case39;, outline, h=h-dial_y+1), y=cy, z=dial_y-1)
plane = s3d.local(cap, z=h-dial_y+1)
cap = s3d.fillet(cap, r=edge, edges=&class="tok-comment">#39;top39;)
cap = s3d.pocket(cap, s3d.rect(w=edge*4, d=clamp_d-edge*4, r=edge), depth=edge, on=plane.move(x=start+edge*2, y=my))
cap = s3d.pocket(cap, s3d.rect(w=clamp_d, d=panel_d, r=edge), depth=2, on=plane.move(x=panel_x, y=my))
cap = s3d.pocket(cap, s3d.rect(w=screen_w, d=screen_d), on=plane.move(x=screen_x, y=my))
cap = s3d.pocket(cap, s3d.rect(w=inset, d=panel_d), on=plane.move(x=key_x, y=my))
cap = s3d.hole(cap, d=dial_d, on=plane.move(x=dial_x, y=dial_y))
case = s3d.join(base, cap)
case = s3d.hole(case, d=inset+1, depth=screen_w/2, on=s3d.grid(nx=2, px=screen_w, on=s3d.bbox(case, &class="tok-comment">#39;+X39;)))
clamp = s3d.extrude(&class="tok-comment">#39;clamp39;, s3d.poly([(-clamp_w/2,-clamp_h/2-edge),(-clamp_w/2,clamp_h/2+edge),(-clamp_w/4,clamp_d/2-edge), (clamp_w/2,clamp_d/2),(clamp_w/2,-clamp_d/2),(-clamp_w/4,-clamp_d/2+edge)], fillet=edge), h=clamp_h)
clamp = s3d.at(clamp, x=clamp_x, y=cy+my, z=edge)
clamp = s3d.pocket(clamp, s3d.rect(w=opening_w, d=opening_d, chamfer=inset), on=s3d.local(clamp, x=opening_x-clamp_x, z=clamp_h))
clamp = s3d.chamfer(clamp, d=1, edges=&class="tok-comment">#39;top bottom39;)
lever = s3d.at(s3d.extrude(&class="tok-comment">#39;lever39;, s3d.rect(w=lever_w, d=screen_w/2, chamfer=edge), h=screen_w/2), x=lever_x, y=cy+bottom-edge, z=h-dial_y)
case = s3d.join(case, clamp, lever)
screen = s3d.at(s3d.extrude(&class="tok-comment">#39;display39;, s3d.rect(w=screen_w, d=screen_d), h=edge), x=screen_x, y=cy+my, z=dial_y-1)
s3d.material(screen, &class="tok-comment">#39;glassclass="tok-string">39;, color=39;#80918a39;)
s3d.material(case, &class="tok-comment">#39;plasticclass="tok-string">39;, color=39;#d6a82939;)
lead = lead_wire(cy=cy, d=lead_d, pin_d=inset, pin_pitch=screen_w, pin_l=-lever_x, collar_d=-dial_x+1, plug_d=-bottom, turn=edge)
return s3d.group(&class="tok-comment">#39;meter_body39;, case, screen, lead)
def lead_wire(cy, d, pin_d, pin_pitch, pin_l, collar_d, plug_d, turn, span=150, depth=23, loop_y=-109, plug_x=-92, plug_y=-71, plug_w=25, plug_h=9):
a = span/2
b = span/3
c = a-depth/2
t = depth/2
path = s3d.spline([(-a,0,0),(-c,t,0),(-b,t,0),(b,-t,0),(c,-t,0),(a,0,0),(c,t,0),(b,t,0),(-b,-t,0),(-c,-t,0)], loop=True)
wire = s3d.at(s3d.wire(&class="tok-comment">#39;loop39;, path, d=d), y=cy+loop_y, z=d, rz=-turn)
twin_loop = s3d.transform(s3d.scale(s3d.copy(wire), s=(span-depth/2)/span), y=d*2, x=d*2, z=d)
tail = s3d.wire(&class="tok-comment">#39;tail39;, s3d.spline([(plug_x+plug_w,cy+plug_y+pin_pitch/2,collar_d),(-plug_w,cy+plug_y+pin_pitch/2,collar_d),(a,cy+loop_y,d)]), d=d)
end = s3d.wire(&class="tok-comment">#39;straight_end39;, [(0,cy+loop_y,d),(a+b-pin_l/2,cy+loop_y+pin_l,d)], d=d)
plug = s3d.at(s3d.extrude(&class="tok-comment">#39;plug39;, s3d.rect(w=plug_w, d=plug_d, r=collar_d), h=plug_h), x=plug_x, y=cy+plug_y)
pin = s3d.at(s3d.cylinder(&class="tok-comment">#39;pin39;, d=pin_d, h=pin_l), x=plug_x-plug_w/2, y=cy+plug_y+pin_pitch/2, z=collar_d, ry=-90)
twin = s3d.at(s3d.copy(pin), y=cy+plug_y-pin_pitch/2)
collar = s3d.at(s3d.cylinder(&class="tok-comment">#39;strain_relief39;, d=collar_d, h=pin_l), x=plug_x+plug_w/2, y=cy+plug_y+pin_pitch/2, z=collar_d, ry=90)
s3d.material(wire, &class="tok-comment">#39;rubberclass="tok-string">39;, color=39;#292b2b39;)
s3d.material(twin_loop, &class="tok-comment">#39;rubberclass="tok-string">39;, color=39;#292b2b39;)
s3d.material(tail, &class="tok-comment">#39;rubberclass="tok-string">39;, color=39;#292b2b39;)
s3d.material(end, &class="tok-comment">#39;rubberclass="tok-string">39;, color=39;#292b2b39;)
s3d.material(plug, &class="tok-comment">#39;rubberclass="tok-string">39;, color=39;#292b2b39;)
s3d.material(collar, &class="tok-comment">#39;rubberclass="tok-string">39;, color=39;#292b2b39;)
s3d.material(pin, &class="tok-comment">#39;steelclass="tok-string">39;, color=39;#a7aaac39;)
s3d.material(twin, &class="tok-comment">#39;steelclass="tok-string">39;, color=39;#a7aaac39;)
return s3d.merge(wire, twin_loop, tail, end, plug, pin, twin, collar)
def selector_dial(d=41, h=14):
dial = s3d.cylinder(&class="tok-comment">#39;dial39;, d=d, h=h)
s3d.chamfer(dial, d=1, edges=&class="tok-comment">#39;top39;)
s3d.material(dial, &class="tok-comment">#39;plasticclass="tok-string">39;, color=39;#34363839;)
return s3d.group(&class="tok-comment">#39;selector_dial39;, dial)
def middle_key(w=5, d=12, h=5):
key = s3d.box(&class="tok-comment">#39;key39;, w=w, d=d, h=h)
s3d.material(key, &class="tok-comment">#39;plasticclass="tok-string">39;, color=39;#3475a139;)
return s3d.group(&class="tok-comment">#39;middle_key39;, key)
def lower_key(w=5, d=12, h=5):
key = s3d.box(&class="tok-comment">#39;key39;, w=w, d=d, h=h)
s3d.material(key, &class="tok-comment">#39;plasticclass="tok-string">39;, color=39;#43915c39;)
return s3d.group(&class="tok-comment">#39;lower_key39;, key)
def upper_key(w=5, d=12, h=5):
key = s3d.box(&class="tok-comment">#39;key39;, w=w, d=d, h=h)
s3d.material(key, &class="tok-comment">#39;plasticclass="tok-string">39;, color=39;#d47a3239;)
return s3d.group(&class="tok-comment">#39;upper_key39;, key)
def round_button(d=6.5, h=5):
button = s3d.cylinder(&class="tok-comment">#39;button39;, d=d, h=h)
s3d.material(button, &class="tok-comment">#39;plasticclass="tok-string">39;, color=39;#33363839;)
return s3d.group(&class="tok-comment">#39;round_button39;, button)