Skip to content
Snippets Groups Projects
pcb.py 240 KiB
Newer Older
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
#!/usr/bin/env python
#
# pcb.py
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
#    functional representation PCB template
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
#
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
# usage:
#    pcb.py | frep.py [dpi [filename]]
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
#
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
# Neil Gershenfeld 12/1/19
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
# (c) Massachusetts Institute of Technology 2019
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
#
# This work may be reproduced, modified, distributed,
# performed, and displayed for any purpose, but must
# acknowledge this project. Copyright is retained and
# must be preserved. The work is provided as is; no
# warranty is provided, and users accept all liability.
#

#
# uncomment for desired output:
#

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
#output = "top, labels, and exterior"
output = "top, labels, holes, and exterior"
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
#output = "top, bottom, labels, and exterior"
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
#output = "top, bottom, labels, holes, and exterior"
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
#output = "top traces"
#output = "top traces and exterior"
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
#output = "top traces, holes, and exterior"
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
#output = "bottom traces reversed"
#output = "bottom traces reversed and exterior"
#output = "holes"
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
#output = "interior"
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
#output = "holes and interior"
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
#output = "exterior"
#output = "solder mask"

#
# import
#

import math,json,sys

#
# define shapes and transformations
#

# color(color,part)
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
# circle(x,y,r)
# cylinder(x,y,z0,z1,r)
# cone(x,y,z0,z1,r)
# sphere(x,y,z,r)
# torus(x,y,z,r0,r1)
# rectangle(x0,x1,y0,y1)
# cube(x0,x1,y0,y1,z0,z1)
# line(x0,y0,x1,y1,z,width)
# right_triangle(x,y,h)
# triangle(x0,y0,x1,y1,x2,y2) (points in clockwise order)
# pyramid(x0,x1,y0,y1,z0,z1)
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
# function(Z_of_XY)
# functions(upper_Z_of_XY,lower_Z_of_XY)
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
# add(part1,part2)
# subtract(part1,part2)
# intersect(part1,part2)
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
# move(part,dx,dy)
# translate(part,dx,dy,dz)
# rotate(part, angle)
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
# rotate_x(part,angle)
# rotate_y(part,angle)
# rotate_z(part,angle)
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
# rotate_90(part)
# rotate_180(part)
# rotate_270(part)
# reflect_x(part,x0)
# reflect_y(part,y0)
# reflect_z(part,z0)
# reflect_xy(part)
# reflect_xz(part)
# reflect_yz(part)
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
# scale_x(part,x0,sx)
# scale_y(part,y0,sy)
# scale_z(part,z0,sz)
# scale_xy(part,x0,y0,sxy)
# scale_xyz(part,x0,y0,z0,sxyz)
# coscale_x_y(part,x0,y0,y1,angle0,angle1,amplitude,offset)
# coscale_x_z(part,x0,z0 z1,angle0,angle1,amplitude,offset)
# coscale_xy_z(part,x0,y0,z0,z1,angle0,angle1,amplitude,offset)
# taper_x_y(part,x0,y0,y1,s0,s1)
# taper_x_z(part,x0,z0,z1,s0,s1)
# taper_xy_z(part,x0,y0,z0,z1,s0,s1)
# shear_x_y(part,y0,y1,dx0,dx1)
# shear_x_z(part,z0,z1,dx0,dx1)
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed

true = "1"
false = "0"

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def color(color,part):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = '('+str(color)+'*(('+part+')!=0))'
   return part

Red = (225 << 0)
Green = (225 << 8)
Blue = (225 << 16)
Gray = (128 << 16) + (128 << 8) + (128 << 0)
White = (255 << 16) + (255 << 8) + (255 << 0)
Teal = (255 << 16) + (255 << 8)
Pink = (255 << 16) + (255 << 0)
Yellow = (255 << 8) + (255 << 0)
Brown = (45 << 16) + (82 << 8) + (145 << 0)
Navy = (128 << 16) + (0 << 8) + (0 << 0)
Tan = (60 << 16) + (90 << 8) + (125 << 0)

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def circle(x0,y0,r):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = "(((X-(x0))*(X-(x0)) + (Y-(y0))*(Y-(y0))) <= (r*r))"
   part = part.replace('x0',str(x0))
   part = part.replace('y0',str(y0))
   part = part.replace('r',str(r))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def cylinder(x0,y0,z0,z1,r):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = "(((X-(x0))*(X-(x0)) + (Y-(y0))*(Y-(y0)) <= (r*r)) & (Z >= (z0)) & (Z <= (z1)))"
   part = part.replace('x0',str(x0))
   part = part.replace('y0',str(y0))
   part = part.replace('z0',str(z0))
   part = part.replace('z1',str(z1))
   part = part.replace('r',str(r))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def cone(x0,y0,z0,z1,r0):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = cylinder(x0, y0, z0, z1, r0)
   part = taper_xy_z(part, x0, y0, z0, z1, 1.0, 0.0)
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def sphere(x0,y0,z0,r):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = "(((X-(x0))*(X-(x0)) + (Y-(y0))*(Y-(y0)) + (Z-(z0))*(Z-(z0))) <= (r*r))"
   part = part.replace('x0',str(x0))
   part = part.replace('y0',str(y0))
   part = part.replace('z0',str(z0))
   part = part.replace('r',str(r))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def torus(x0,y0,z0,r0,r1):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = "(((r0 - sqrt((X-(x0))*(X-(x0)) + (Y-(y0))*(Y-(y0))))*(r0 - sqrt((X-(x0))*(X-(x0)) + (Y-(y0))*(Y-(y0))) + (Z-(z0))*(Z-(z0))) <= (r1*r1))"
   part = part.replace('x0',str(x0))
   part = part.replace('y0',str(y0))
   part = part.replace('z0',str(z0))
   part = part.replace('r0',str(r0))
   part = part.replace('r1',str(r1))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def rectangle(x0,x1,y0,y1):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = "((X >= (x0)) & (X <= (x1)) & (Y >= (y0)) & (Y <= (y1)))"
   part = part.replace('x0',str(x0))
   part = part.replace('x1',str(x1))
   part = part.replace('y0',str(y0))
   part = part.replace('y1',str(y1))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def cube(x0,x1,y0,y1,z0,z1):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = "((X >= (x0)) & (X <= (x1)) & (Y >= (y0)) & (Y <= (y1)) & (Z >= (z0)) & (Z <= (z1)))"
   part = part.replace('x0',str(x0))
   part = part.replace('x1',str(x1))
   part = part.replace('y0',str(y0))
   part = part.replace('y1',str(y1))
   part = part.replace('z0',str(z0))
   part = part.replace('z1',str(z1))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def line(x0,y0,x1,y1,z,width):
   dx = x1-x0
   dy = y1-y0
   l = math.sqrt(dx*dx+dy*dy)
   nx = dx/l
   ny = dy/l
   rx = -ny
   ry = nx
   part = "((((X-(x0))*(nx)+(Y-(y0))*(ny)) >= 0) & (((X-(x0))*(nx)+(Y-(y0))*(ny)) <= l) & (((X-(x0))*(rx)+(Y-(y0))*(ry)) >= (-width/2)) & (((X-(x0))*(rx)+(Y-(y0))*(ry)) <= (width/2)) & (Z == z))"
   part = part.replace('x0',str(x0))
   part = part.replace('x1',str(x1))
   part = part.replace('y0',str(y0))
   part = part.replace('y1',str(y1))
   part = part.replace('nx',str(nx))
   part = part.replace('ny',str(ny))
   part = part.replace('rx',str(rx))
   part = part.replace('ry',str(ry))
   part = part.replace('l',str(l))
   part = part.replace('z',str(z))
   part = part.replace('width',str(width))
   return part

def right_triangle(x0,y0,l):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = "((X > x0) & (X < x0 + l - (Y-y0)) & (Y > y0))"
   part = part.replace('x0',str(x0))
   part = part.replace('y0',str(y0))
   part = part.replace('l',str(l))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def triangle(x0,y0,x1,y1,x2,y2): # points in clockwise order
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = "(((((y1)-(y0))*(X-(x0))-((x1)-(x0))*(Y-(y0))) >= 0) & ((((y2)-(y1))*(X-(x1))-((x2)-(x1))*(Y-(y1))) >= 0) & ((((y0)-(y2))*(X-(x2))-((x0)-(x2))*(Y-(y2))) >= 0))"
   part = part.replace('x0',str(x0))
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = part.replace('y0',str(y0))
   part = part.replace('x1',str(x1))
   part = part.replace('y1',str(y1))
   part = part.replace('x2',str(x2))
   part = part.replace('y2',str(y2))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def pyramid(x0,x1,y0,y1,z0,z1):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = cube(x0, x1, y0, y1, z0, z1)
   part = taper_xy_z(part, (x0+x1)/2., (y0+y1)/2., z0, z1, 1.0, 0.0)
   return part

def function(Z_of_XY):
   part = '(Z <= '+Z_of_XY+')'
   return part

def functions(upper_Z_of_XY,lower_Z_of_XY):
   part = '(Z <= '+upper_Z_of_XY+') & (Z >= '+lower_Z_of_XY+')'
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def add(part1,part2):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = "part1 | part2"
   part = part.replace('part1',part1)
   part = part.replace('part2',part2)
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def subtract(part1,part2):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = "(part1) & ~(part2)"
   part = part.replace('part1',part1)
   part = part.replace('part2',part2)
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def intersect(part1,part2):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = "(part1) & (part2)"
   part = part.replace('part1',part1)
   part = part.replace('part2',part2)
   return part

def move(part,dx,dy):
   part = part.replace('X','(X-('+str(dx)+'))')
   part = part.replace('Y','(Y-('+str(dy)+'))')
   return part   

def translate(part,dx,dy,dz):
   part = part.replace('X','(X-('+str(dx)+'))')
   part = part.replace('Y','(Y-('+str(dy)+'))')
   part = part.replace('Z','(Z-('+str(dz)+'))')
   return part   

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def rotate(part,angle):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   angle = angle*math.pi/180
   part = part.replace('X','(math.cos(angle)*X+math.sin(angle)*y)')
   part = part.replace('Y','(-math.sin(angle)*X+math.cos(angle)*y)')
   part = part.replace('y','Y')
   part = part.replace('angle',str(angle))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def rotate_x(part,angle):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   angle = angle*math.pi/180
   part = part.replace('Y','(math.cos(angle)*Y+math.sin(angle)*z)')
   part = part.replace('Z','(-math.sin(angle)*Y+math.cos(angle)*z)')
   part = part.replace('z','Z')
   part = part.replace('angle',str(angle))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def rotate_y(part,angle):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   angle = angle*math.pi/180
   part = part.replace('X','(math.cos(angle)*X+math.sin(angle)*z)')
   part = part.replace('Z','(-math.sin(angle)*X+math.cos(angle)*z)')
   part = part.replace('z','Z')
   part = part.replace('angle',str(angle))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def rotate_z(part,angle):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   angle = angle*math.pi/180
   part = part.replace('X','(math.cos(angle)*X+math.sin(angle)*y)')
   part = part.replace('Y','(-math.sin(angle)*X+math.cos(angle)*y)')
   part = part.replace('y','Y')
   part = part.replace('angle',str(angle))
   return part

def rotate_90(part):
   part = reflect_y(part,0)
   part = reflect_xy(part)
   return part

def rotate_180(part):
   part = rotate_90(part)
   part = rotate_90(part)
   return part

def rotate_270(part):
   part = rotate_90(part)
   part = rotate_90(part)
   part = rotate_90(part)
   return part

def reflect_x(part,x0):
   part = part.replace('X','(x0-X)')
   part = part.replace('x0',str(x0))
   return part

def reflect_y(part,y0):
   part = part.replace('Y','(y0-Y)')
   part = part.replace('y0',str(y0))
   return part

def reflect_z(part,z0):
   part = part.replace('Z','(z0-Z)')
   part = part.replace('z0',str(z0))
   return part

def reflect_xy(part):
   part = part.replace('X','temp')
   part = part.replace('Y','X')
   part = part.replace('temp','Y')
   return part

def reflect_xz(part):
   part = part.replace('X','temp')
   part = part.replace('Z','X')
   part = part.replace('temp','Z')
   return part

def reflect_yz(part):
   part = part.replace('Y','temp')
   part = part.replace('Z','Y')
   part = part.replace('temp','Z')
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def scale_x(part,x0,sx):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = part.replace('X','((x0) + (X-(x0))/(sx))')
   part = part.replace('x0',str(x0))
   part = part.replace('sx',str(sx))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def scale_y(part,y0,sy):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = part.replace('Y','((y0) + (Y-(y0))/(sy))')
   part = part.replace('y0',str(y0))
   part = part.replace('sy',str(sy))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def scale_z(part,z0,sz):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = part.replace('Z','((z0) + (Z-(z0))/(sz))')
   part = part.replace('z0',str(z0))
   part = part.replace('sz',str(sz))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def scale_xy(part,x0,y0,sxy):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = part.replace('X','((x0) + (X-(x0))/(sxy))')
   part = part.replace('Y','((y0) + (Y-(y0))/(sxy))')
   part = part.replace('x0',str(x0))
   part = part.replace('y0',str(y0))
   part = part.replace('sxy',str(sxy))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def scale_xyz(part,x0,y0,z0,sxyz):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = part.replace('X','((x0) + (X-(x0))/(sxyz))')
   part = part.replace('Y','((y0) + (Y-(y0))/(sxyz))')
   part = part.replace('Z','((z0) + (Z-(z0))/(sxyz))')
   part = part.replace('x0',str(x0))
   part = part.replace('y0',str(y0))
   part = part.replace('z0',str(z0))
   part = part.replace('sxyz',str(sxyz))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def coscale_x_y(part,x0,y0,y1,angle0,angle1,amplitude,offset):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   phase0 = math.pi*angle0/180.
   phase1 = math.pi*angle1/180.
   part = part.replace('X','((x0) + (X-(x0))/((offset) + (amplitude)*math.cos((phase0) + ((phase1)-(phase0))*(Y-(y0))/((y1)-(y0)))))')
   part = part.replace('x0',str(x0))
   part = part.replace('y0',str(y0))
   part = part.replace('y1',str(y1))
   part = part.replace('phase0',str(phase0))
   part = part.replace('phase1',str(phase1))
   part = part.replace('amplitude',str(amplitude))
   part = part.replace('offset',str(offset))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def coscale_x_z(part,x0,z0,z1,angle0,angle1,amplitude,offset):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   phase0 = math.pi*angle0/180.
   phase1 = math.pi*angle1/180.
   part = part.replace('X','((x0) + (X-(x0))/((offset) + (amplitude)*math.cos((phase0) + ((phase1)-(phase0))*(Z-(z0))/((z1)-(z0)))))')
   part = part.replace('x0',str(x0))
   part = part.replace('z0',str(z0))
   part = part.replace('z1',str(z1))
   part = part.replace('phase0',str(phase0))
   part = part.replace('phase1',str(phase1))
   part = part.replace('amplitude',str(amplitude))
   part = part.replace('offset',str(offset))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def coscale_xy_z(part,x0,y0,z0,z1,angle0,angle1,amplitude,offset):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   phase0 = math.pi*angle0/180.
   phase1 = math.pi*angle1/180.
   part = part.replace('X','((x0) + (X-(x0))/((offset) + (amplitude)*math.cos((phase0) + ((phase1)-(phase0))*(Z-(z0))/((z1)-(z0)))))')
   part = part.replace('Y','((y0) + (Y-(y0))/((offset) + (amplitude)*math.cos((phase0) + ((phase1)-(phase0))*(Z-(z0))/((z1)-(z0)))))')
   part = part.replace('x0',str(x0))
   part = part.replace('y0',str(y0))
   part = part.replace('z0',str(z0))
   part = part.replace('z1',str(z1))
   part = part.replace('phase0',str(phase0))
   part = part.replace('phase1',str(phase1))
   part = part.replace('amplitude',str(amplitude))
   part = part.replace('offset',str(offset))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def taper_x_y(part,x0,y0,y1,s0,s1):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = part.replace('X','((x0) + (X-(x0))*((y1)-(y0))/((s1)*(Y-(y0)) + (s0)*((y1)-Y)))')
   part = part.replace('x0',str(x0))
   part = part.replace('y0',str(y0))
   part = part.replace('y1',str(y1))
   part = part.replace('s0',str(s0))
   part = part.replace('s1',str(s1))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def taper_x_z(part,x0,z0,z1,s0,s1):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = part.replace('X','((x0) + (X-(x0))*((z1)-(z0))/((s1)*(Z-(z0)) + (s0)*((z1)-Z)))')
   part = part.replace('x0',str(x0))
   part = part.replace('z0',str(z0))
   part = part.replace('z1',str(z1))
   part = part.replace('s0',str(s0))
   part = part.replace('s1',str(s1))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def taper_xy_z(part,x0,y0,z0,z1,s0,s1):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = part.replace('X','((x0) + (X-(x0))*((z1)-(z0))/((s1)*(Z-(z0)) + (s0)*((z1)-Z)))')
   part = part.replace('Y','((y0) + (Y-(y0))*((z1)-(z0))/((s1)*(Z-(z0)) + (s0)*((z1)-Z)))')
   part = part.replace('x0',str(x0))
   part = part.replace('y0',str(y0))
   part = part.replace('z0',str(z0))
   part = part.replace('z1',str(z1))
   part = part.replace('s0',str(s0))
   part = part.replace('s1',str(s1))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def shear_x_y(part,y0,y1,dx0,dx1):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = part.replace('X','(X - (dx0) - ((dx1)-(dx0))*(Y-(y0))/((y1)-(y0)))')
   part = part.replace('y0',str(y0))
   part = part.replace('y1',str(y1))
   part = part.replace('dx0',str(dx0))
   part = part.replace('dx1',str(dx1))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def shear_x_z(part,z0,z1,dx0,dx1):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   part = part.replace('X','(X - (dx0) - ((dx1)-(dx0))*(Z-(z0))/((z1)-(z0)))')
   part = part.replace('z0',str(z0))
   part = part.replace('z1',str(z1))
   part = part.replace('dx0',str(dx0))
   part = part.replace('dx1',str(dx1))
   return part

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def coshear_x_z(part,z0,z1,angle0,angle1,amplitude,offset):
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860
   phase0 = math.pi*angle0/180.
   phase1 = math.pi*angle1/180.
   part = part.replace('X','(X - (offset) - (amplitude)*math.cos((phase0) + ((phase1)-(phase0))*(Z-(z0))/((z1)-(z0))))')
   part = part.replace('z0',str(z0))
   part = part.replace('z1',str(z1))
   part = part.replace('phase0',str(phase0))
   part = part.replace('phase1',str(phase1))
   part = part.replace('amplitude',str(amplitude))
   part = part.replace('offset',str(offset))
   return part

#
# text classes and definitions
#

class text:
   #
   # text class
   #
   def __init__(self,text,x,y,z,line='',height='',width='',space='',align='CC',color=White,angle=0):
      #
      # parameters
      #
      if (line == ''):
         line = 1
      if (height == ''):
         height = 6*line
      if (width == ''):
         width = 4*line
      if (space == ''):
         space = line/2.0
      self.width = 0
      self.height = 0
      self.text = text
      #
      # construct shape dictionary
      #
      shapes = {}
      shape = triangle(0,0,width/2.0,height,width,0)
      cutout = triangle(0,-2.5*line,width/2.0,height-2.5*line,width,-2.5*line)
      cutout = subtract(cutout,rectangle(0,width,height/4-line/2,height/4+line/2))
      shape = subtract(shape,cutout)
      shapes['A'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = subtract(shape,circle(width/2,width/2,width/4))
      shape = add(shape,rectangle(width-line,width,0,height/3))
      shapes['a'] = shape
      shape = rectangle(0,width-height/4,0,height)
      shape = add(shape,circle(width-height/4,height/4,height/4))
      shape = add(shape,circle(width-height/4,3*height/4,height/4))
      w = height/2-1.5*line
      shape = subtract(shape,rectangle(line,line+w/1.5,height/2+line/2,height-line))
      shape = subtract(shape,circle(line+w/1.5,height/2+line/2+w/2,w/2))
      shape = subtract(shape,rectangle(line,line+w/1.5,line,height/2-line/2))
      shape = subtract(shape,circle(line+w/1.5,height/2-line/2-w/2,w/2))
      shapes['B'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = subtract(shape,circle(width/2,width/2,width/4))
      shape = add(shape,rectangle(0,line,0,height))
      shapes['b'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = add(shape,circle(width/2,height-width/2,width/2))
      shape = add(shape,rectangle(0,width,line+w/2,height-line-w/2))
      w = width-2*line
      shape = subtract(shape,circle(width/2,line+w/2,w/2))
      shape = subtract(shape,circle(width/2,height-line-w/2,w/2))
      shape = subtract(shape,rectangle(line,width,line+w/2,height-line-w/2))
      shapes['C'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = subtract(shape,circle(width/2,width/2,width/4))
      shape = subtract(shape,rectangle(width/2,width,width/2-line/1.5,width/2+line/1.5))
      shapes['c'] = shape
      shape = circle(line,width-line,width-line)
      shape = subtract(shape,circle(line,width-line,width-2*line))
      shape = subtract(shape,rectangle(-width,line,0,height))
      shape = scale_y(shape,0,height/(2*(width-line)))
      shape = add(shape,rectangle(0,line,0,height))
      shapes['D'] = shape
      shape = rectangle(width-line,width,0,height)
      shape = add(shape,circle(width/2,width/2,width/2))
      shape = subtract(shape,circle(width/2,width/2,width/2-line))
      shapes['d'] = shape
      shape = rectangle(0,line,0,height)
      shape = add(shape,rectangle(0,width,height-line,height))
      shape = add(shape,rectangle(0,2*width/3,height/2-line/2,height/2+line/2))
      shape = add(shape,rectangle(0,width,0,line))      
      shapes['E'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = subtract(shape,circle(width/2,width/2,width/2-line))
      shape = subtract(shape,triangle(width,0,width/2,width/2-line/2,width,width/2-line/2))
      shape = add(shape,rectangle(0,width,width/2-line/2,width/2+line/2))
      shapes['e'] = shape
      shape = rectangle(0,line,0,height)
      shape = add(shape,rectangle(0,width,height-line,height))
      shape = add(shape,rectangle(0,2*width/3,height/2-line/2,height/2+line/2))
      shapes['F'] = shape
      shape = circle(width-line/2,height-width/2,width/2)
      shape = subtract(shape,circle(width-line/2,height-width/2,width/2-line))
      shape = subtract(shape,rectangle(0,width-line/2,0,height-width/2))
      shape = subtract(shape,rectangle(width-line/2,2*width,0,height))
      shape = add(shape,rectangle(width/2-line/2,width/2+line/2,0,height-width/2))
      shape = add(shape,rectangle(width/5,4*width/5,height/2-line/2,height/2+line/2))
      shapes['f'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = add(shape,circle(width/2,height-width/2,width/2))
      shape = add(shape,rectangle(0,width,line+w/2,height-line-w/2))
      w = width-2*line
      shape = subtract(shape,circle(width/2,line+w/2,w/2))
      shape = subtract(shape,circle(width/2,height-line-w/2,w/2))
      shape = subtract(shape,rectangle(line,width,line+w/2,height-line-w/2))
      shape = add(shape,rectangle(width/2,width,line+w/2,2*line+w/2))
      shapes['G'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = subtract(shape,circle(width/2,width/2,width/2-line))
      w = height/3-width/2
      shape = add(shape,rectangle(width-line,width,w,width))
      shape = add(shape,subtract(subtract(circle(width/2,w,width/2),circle(width/2,w,width/2-line)),rectangle(0,width,w,height)))
      shapes['g'] = shape
      shape = rectangle(0,line,0,height)
      shape = add(shape,rectangle(width-line,width,0,height))
      shape = add(shape,rectangle(0,width,height/2-line/2,height/2+line/2))
      shapes['H'] = shape
      w = width/2
      shape = circle(width/2,w,width/2)
      shape = subtract(shape,circle(width/2,w,width/2-line))
      shape = subtract(shape,rectangle(0,width,0,w))
      shape = add(shape,rectangle(0,line,0,height))
      shape = add(shape,rectangle(width-line,width,0,w))
      shapes['h'] = shape
      shape = rectangle(width/2-line/2,width/2+line/2,0,height)
      shape = add(shape,rectangle(width/5,4*width/5,0,line))
      shape = add(shape,rectangle(width/5,4*width/5,height-line,height))
      shapes['I'] = shape
      shape = rectangle(width/2-line/2,width/2+line/2,0,height/2)
      shape = add(shape,circle(width/2,3*height/4,.6*line))
      shapes['i'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = subtract(shape,circle(width/2,width/2,width/2-line))
      shape = subtract(shape,rectangle(0,width,width/2,height))
      shape = add(shape,rectangle(width-line,width,width/2,height))
      shapes['J'] = shape
      w = height/3-width/2
      shape = rectangle(width/2-line/2,width/2+line/2,w,height/2)
      shape = add(shape,subtract(subtract(subtract(circle(width/4-line/2,w,width/2),circle(width/4-line/2,w,width/2-line)),rectangle(0,width,w,height)),rectangle(-width,width/4-line/2,-height/3,height)))
      shape = add(shape,circle(width/2,3*height/4,.6*line))
      shapes['j'] = shape
      shape = rectangle(0,width,0,height)
      shape = subtract(shape,triangle(line,height,width-1.1*line,height,line,height/2+.5*line))
      shape = subtract(shape,triangle(width,0,line+0.8*line,height/2,width,height))
      shape = subtract(shape,triangle(line,0,line,height/2-.5*line,width-1.1*line,0))
      shapes['K'] = shape
      shape = rectangle(0,width,0,height)
      shape = subtract(shape,rectangle(line,width,2*height/3,height))
      shape = subtract(shape,triangle(line,2*height/3,width-1.3*line,2*height/3,line,height/3+.5*line))
      shape = subtract(shape,triangle(width,0,line+0.8*line,height/3,width,2*height/3))
      shape = subtract(shape,triangle(line,0,line,height/3-0.5*line,width-1.3*line,0))
      shapes['k'] = shape
      shape = rectangle(0,line,0,height)
      shape = add(shape,rectangle(0,width,0,line))
      shapes['L'] = shape
      shape = rectangle(width/2-line/2,width/2+line/2,0,height)
      shapes['l'] = shape
      shape = rectangle(0,width,0,height)
      shape = subtract(shape,triangle(line,0,line,height-3*line,width/2-line/3,0))
      shape = subtract(shape,triangle(line,height,width-line,height,width/2,1.5*line))
      shape = subtract(shape,triangle(width/2+line/3,0,width-line,height-3*line,width-line,0))
      shapes['M'] = shape
      w = width/2
      l = 1.3*line
      shape = circle(width/2,w,width/2)
      shape = subtract(shape,circle(width/2,w,width/2-l))
      shape = subtract(shape,rectangle(0,width,0,w))
      shape = add(shape,rectangle(width-l,width,0,w))
      shape = add(shape,move(shape,width-l,0))
      shape = add(shape,rectangle(0,l,0,width))
      shape = scale_x(shape,0,width/(2*width-l))
      shapes['m'] = shape
      shape = rectangle(0,width,0,height)
      shape = subtract(shape,triangle(line,height+1.5*line,width-line,height+1.5*line,width-line,1.5*line))
      shape = subtract(shape,triangle(line,-1.5*line,line,height-1.5*line,width-line,-1.5*line))
      shapes['N'] = shape
      w = width/2
      shape = circle(width/2,w,width/2)
      shape = subtract(shape,circle(width/2,w,width/2-line))
      shape = subtract(shape,rectangle(0,width,0,w))
      shape = add(shape,rectangle(0,line,0,width))
      shape = add(shape,rectangle(width-line,width,0,w))
      shapes['n'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = add(shape,circle(width/2,height-width/2,width/2))
      shape = add(shape,rectangle(0,width,line+w/2,height-line-w/2))
      w = width-2*line
      shape = subtract(shape,circle(width/2,line+w/2,w/2))
      shape = subtract(shape,circle(width/2,height-line-w/2,w/2))
      shape = subtract(shape,rectangle(line,width-line,line+w/2,height-line-w/2))
      shapes['O'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = subtract(shape,circle(width/2,width/2,width/2-line))
      shapes['o'] = shape
      shape = rectangle(0,line,0,height)
      w = 2*height/3
      shape = add(shape,circle(width-w/2,height-w/2,w/2))
      shape = add(shape,rectangle(0,width-w/2,height-w,height))
      shape = subtract(shape,circle(width-w/2,height-w/2,w/2-line))
      shape = subtract(shape,rectangle(line,width-w/2,height-w+line,height-line))
      shapes['P'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = subtract(shape,circle(width/2,width/2,width/4))
      shape = add(shape,rectangle(0,line,-height/3,width))
      shapes['p'] = shape
      shape = subtract(circle(width/2,width/2,width/2),circle(width/2,width/2,width/2-.9*line))
      shape = scale_y(shape,0,height/width)
      shape = add(shape,move(rotate(rectangle(-line/2,line/2,-width/4,width/4),30),3*width/4,width/4))
      shapes['Q'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = subtract(shape,circle(width/2,width/2,width/2-line))
      shape = add(shape,rectangle(width-line,width,-height/3,width))
      shapes['q'] = shape
      shape = rectangle(0,line,0,height)
      w = 2*height/3
      shape = add(shape,circle(width-w/2,height-w/2,w/2))
      shape = add(shape,rectangle(0,width-w/2,height-w,height))
      shape = subtract(shape,circle(width-w/2,height-w/2,w/2-line))
      shape = subtract(shape,rectangle(line,width-w/2,height-w+line,height-line))
      leg = triangle(line,0,line,height,width,0)
      leg = subtract(leg,triangle(line,-2.0*line,line,height-2.0*line,width,-2.0*line))
      leg = subtract(leg,rectangle(0,width,height/3,height))
      shape = add(shape,leg)
      shapes['R'] = shape
      shape = circle(width,0,width)
      shape = subtract(shape,circle(width,0,width-line))
      shape = subtract(shape,rectangle(.8*width,2*width,-height,height))
      shape = subtract(shape,rectangle(0,2*width,-height,0))
      shape = add(shape,rectangle(0,line,0,width))
      shapes['r'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = subtract(shape,circle(width/2,width/2,width/2-line))
      shape = subtract(shape,rectangle(0,width/2,width/2,width))
      shape = add(shape,move(reflect_y(reflect_x(shape,width),width),0,width-line))
      shape = scale_y(shape,0,height/(2*width-line))
      shapes['S'] = shape
      w = width/3
      shape = circle(w,w,w)
      shape = subtract(shape,circle(w,w,w-.9*line))
      shape = subtract(shape,rectangle(0,w,w,2*w))
      shape = add(shape,move(reflect_y(reflect_x(shape,2*w),2*w),0,2*w-.9*line))
      shape = scale_y(shape,0,(2*height/3)/(4*w-.9*line))
      shape = move(shape,(width/2)-w,0)
      shapes['s'] = shape
      shape = rectangle(width/2-line/2,width/2+line/2,0,height)
      shape = add(shape,rectangle(0,width,height-line,height))
      shapes['T'] = shape
      shape = circle(0,3*width/8,3*width/8)
      shape = subtract(shape,circle(0,3*width/8,3*width/8-line))
      shape = subtract(shape,rectangle(-width,width,3*width/8,height))
      shape = subtract(shape,rectangle(0,width,-height,height))
      shape = move(shape,width/2-line/2+3*width/8,0)
      shape = add(shape,rectangle(width/2-line/2,width/2+line/2,width/4,3*height/4))
      shape = add(shape,rectangle(width/5,4*width/5,height/2-line/2,height/2+line/2))
      shapes['t'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = subtract(shape,circle(width/2,width/2,width/2-line))
      shape = subtract(shape,rectangle(0,width,width/2,height))
      shape = add(shape,rectangle(0,line,width/2,height))
      shape = add(shape,rectangle(width-line,width,width/2,height))
      shapes['U'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = subtract(shape,circle(width/2,width/2,width/2-line))
      shape = subtract(shape,rectangle(0,width,width/2,height))
      shape = add(shape,rectangle(0,line,width/2,2*height/3))
      shape = add(shape,rectangle(width-line,width,0,2*height/3))
      shapes['u'] = shape
      shape = triangle(0,height,width,height,width/2,0)
      shape = subtract(shape,triangle(0,height+3*line,width,height+3*line,width/2,3*line))
      shapes['V'] = shape
      w = 2*height/3.0
      shape = triangle(0,w,width,w,width/2,0)
      shape = subtract(shape,triangle(0,w+2*line,width,w+2*line,width/2,2*line))
      shapes['v'] = shape
      shape = triangle(0,height,width,height,width/2,0)
      shape = add(shape,move(shape,.6*width,0))
      cutout = triangle(0,height+4*line,width,height+4*line,width/2,4*line)
      cutout = add(cutout,move(cutout,.6*width,0))
      shape = subtract(shape,cutout)
      shape = scale_x(shape,0,1/1.6)
      shapes['W'] = shape
      shape = scale_y(shapes['W'],0,width/height)
      shapes['w'] = shape
      shape = rectangle(0,width,0,height)
      shape = subtract(shape,triangle(0,0,0,height,width/2-.7*line,height/2))
      shape = subtract(shape,triangle(width,0,width/2+.7*line,height/2,width,height))
      shape = subtract(shape,triangle(1.1*line,height,width-1.1*line,height,width/2,height/2+line))
      shape = subtract(shape,triangle(1.1*line,0,width/2,height/2-line,width-1.1*line,0))
      shapes['X'] = shape
      w = 2*height/3.0
      shape = rectangle(0,width,0,w)
      shape = subtract(shape,triangle(0,0,0,w,width/2-.75*line,w/2))
      shape = subtract(shape,triangle(width,0,width/2+.75*line,w/2,width,w))
      shape = subtract(shape,triangle(1.25*line,0,width/2,w/2-.75*line,width-1.25*line,0))
      shape = subtract(shape,triangle(1.25*line,w,width-1.25*line,w,width/2,w/2+.75*line))
      shapes['x'] = shape
      w = height/2
      shape = rectangle(0,width,w,height)
      shape = subtract(shape,triangle(0,w,0,height,width/2-line/2,w))
      shape = subtract(shape,triangle(width/2+line/2,w,width,height,width,w))
      shape = subtract(shape,triangle(1.1*line,height,width-1.1*line,height,width/2,w+1.1*line))
      shape = add(shape,rectangle(width/2-line/2,width/2+line/2,0,w))
      shapes['Y'] = shape
      shape = rectangle(0,width,-height/3,width)
      shape = subtract(shape,triangle(0,-height/3,0,width,width/2-.9*line,0))
      shape = subtract(shape,triangle(1.1*line,width,width-1.1*line,width,width/2-.2*line,1.6*line))
      shape = subtract(shape,triangle(1.2*line,-height/3,width,width,width,-height/3))
      shapes['y'] = shape
      shape = rectangle(0,width,0,height)
      shape = subtract(shape,triangle(0,line,0,height-line,width-1.4*line,height-line))
      shape = subtract(shape,triangle(1.4*line,line,width,height-line,width,line))
      shapes['Z'] = shape
      w = 2*height/3
      shape = rectangle(0,width,0,w)
      shape = subtract(shape,triangle(0,line,0,w-line,width-1.6*line,w-line))
      shape = subtract(shape,triangle(width,line,1.6*line,line,width,w-line))
      shapes['z'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = subtract(shape,circle(width/2,width/2,width/2-.9*line))
      shape = scale_y(shape,0,height/width)
      shapes['0'] = shape
      shape = rectangle(width/2-line/2,width/2+line/2,0,height)
      w = width/2-line/2
      cutout = circle(0,height,w)
      shape = add(shape,rectangle(0,width/2,height-w-line,height))
      shape = subtract(shape,cutout)
      shape = move(shape,(width/2+line/2)/4,0)
      shapes['1'] = shape
      shape = circle(width/2,height-width/2,width/2)
      shape = subtract(shape,circle(width/2,height-width/2,width/2-line))
      shape = subtract(shape,rectangle(0,width/2,0,height-width/2))
      shape = add(shape,rectangle(0,width,0,height-width/2))
      shape = subtract(shape,triangle(0,line,0,height-width/2,width-line,height-width/2))
      shape = subtract(shape,triangle(1.5*line,line,width,height-width/2-.5*line,width,line))
      shapes['2'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = subtract(shape,circle(width/2,width/2,width/2-line))
      shape = scale_y(shape,0,(height/2+line/2)/width)
      shape = add(shape,move(shape,0,height/2-line/2))
      shape = subtract(shape,rectangle(0,width/2,height/4,3*height/4))
      shapes['3'] = shape
      shape = rectangle(width-line,width,0,height)
      shape = add(shape,triangle(0,height/3,width-line,height,width-line,height/3))
      shape = subtract(shape,triangle(1.75*line,height/3+line,width-line,height-1.5*line,width-line,height/3+line))
      shapes['4'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = subtract(shape,circle(width/2,width/2,width/2-line))
      shape = subtract(shape,rectangle(0,width/2,width/2,width))
      shape = add(shape,rectangle(0,width/2,width-line,width))
      shape = add(shape,rectangle(0,line,width-line,height))
      shape = add(shape,rectangle(0,width,height-line,height))
      shapes['5'] = shape
      shape = circle(width/2,height-width/2,width/2)
      shape = subtract(shape,circle(width/2,height-width/2,width/2-line))
      shape = subtract(shape,rectangle(0,width,0,height-width/2))
      shape = subtract(shape,triangle(width,height,width,height/2,width/2,height/2))
      shape = add(shape,circle(width/2,width/2,width/2))
      shape = subtract(shape,circle(width/2,width/2,width/2-line))
      shape = add(shape,rectangle(0,line,width/2,height-width/2))
      shapes['6'] = shape
      shape = rectangle(0,width,0,height)
      shape = subtract(shape,triangle(0,0,0,height-line,width-line,height-line))
      shape = subtract(shape,triangle(line,0,width,height-line,width,0))
      shapes['7'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = subtract(shape,circle(width/2,width/2,width/2-line))
      shape = scale_y(shape,0,(height/2+line/2)/width)
      shape = add(shape,move(shape,0,height/2-line/2))
      shapes['8'] = shape
      shape = circle(width/2,width/2,width/2)
      shape = subtract(shape,circle(width/2,width/2,width/2-line))
      shape = subtract(shape,rectangle(0,width,width/2,height))
      shape = subtract(shape,triangle(0,0,0,height/2,width/2,height/2))
      shape = add(shape,circle(width/2,height-width/2,width/2))
      shape = subtract(shape,circle(width/2,height-width/2,width/2-line))
      shape = add(shape,rectangle(width-line,width,width/2,height-width/2))
      shapes['9'] = shape
      w = width/2
      shape = circle(w,w,w)
      shape = subtract(shape,circle(w,w,w-line))
      shape = subtract(shape,rectangle(w,width,0,height))
      shape = scale_y(shape,0,height/width)
      shape = move(shape,w/2,0)
      shapes['('] = shape
      shape = reflect_x(shape,width)
      shapes[')'] = shape
      shapes[' '] = false
      shape = rectangle(width/2-width/3,width/2+width/3,height/2-line/2,height/2+line/2)
      shape = add(shape,rectangle(width/2-line/2,width/2+line/2,height/2-width/3,height/2+width/3))
      shapes['+'] = shape
      shape = rectangle(width/2-width/3,width/2+width/3,height/2-line/2,height/2+line/2)
      shapes['-'] = shape
      shape = circle(width/2,line,.75*line)
      shapes['.'] = shape
      shape = rectangle(0,width,0,height)
      d = .8*line
      shape = subtract(shape,triangle(d,0,width,height-d,width,0))
      shape = subtract(shape,triangle(0,d,0,height,width-d,height))
      shapes['/'] = shape
      #
      # to be done
      #
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
      shapes['*'] = shape
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
      shapes['~'] = shape
      shapes['!'] = shape
      shapes['@'] = shape
      shapes['#'] = shape
      shapes['$'] = shape
      shapes['%'] = shape
      shapes['^'] = shape
      shapes['&'] = shape
      shapes['&'] = shape
      shapes['_'] = shape
      shapes['='] = shape
      shapes['['] = shape
      shapes['{'] = shape
      shapes[']'] = shape
      shapes['}'] = shape
      shapes[';'] = shape
      shapes[':'] = shape
      shapes["'"] = shape
      shapes['"'] = shape
      shapes[','] = shape
      shapes['<'] = shape
      shapes['>'] = shape
      shapes['?'] = shape
      #
      # add a line to text shape
      #
      def addline(lineshape):
         #
         # LR align
         #
         if (align[0] == 'C'):
            lineshape = move(lineshape,-self.width/2.0,0)
         elif (align[0] == 'R'):
            lineshape = move(lineshape,-self.width,0)
         #
         # add
         #
         self.shape = add(self.shape,lineshape)
      #
      # loop over chars
      #
      dx = 0
      dy = -height
      self.width = -space
      self.height = height
      lineshape = false
      self.shape = false
      for chr in text:
         if (chr == '\n'):
            addline(lineshape)
            dx = 0
            dy -= 1.5*self.height
            self.width = -space
            self.height += 1.5*self.height
            lineshape = false
         else:
            lineshape = add(lineshape,move(shapes[chr],dx,dy))
            self.width += space + width
            dx += width + space
      addline(lineshape)
      #
      # UD align
      #
      if (align[1] == 'C'):
         self.shape = move(self.shape,0,self.height/2.0)
      elif (align[1] == 'B'):
         self.shape = move(self.shape,0,self.height)
      #
      # rotate
      #
      if (angle == 90):
         self.shape = rotate_90(self.shape)
      elif (angle == 180):
         self.shape = rotate_180(self.shape)
      elif ((angle == 270) | (angle == -90)):
         self.shape = rotate_270(self.shape)
      elif (angle != 0):
         self.shape = rotate(self.shape,angle)
      #
      # translate
      #
      self.shape = move(self.shape,x,y)
      #
      # color
      #
      self.shape = '('+str(color)+'*(('+self.shape+')!=0))'

#
# PCB classes and definitions
#

class PCB:
   def __init__(self,x0,y0,width,height,mask):
      self.board = false
      self.labels = false
      self.interior = rectangle(x0,x0+width,y0,y0+height)
      self.exterior = subtract(true,rectangle(x0,x0+width,y0,y0+height))
      self.mask = false
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
      self.holes = false
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   def add(self,part):
      self.board = add(self.board,part)
      self.mask = add(self.mask,move(part,-mask,mask))
      self.mask = add(self.mask,move(part,-mask,-mask))
      self.mask = add(self.mask,move(part,mask,mask))
      self.mask = add(self.mask,move(part,mask,-mask))
      return self

class point:
   def __init__(self,x,y,z=0):
      self.x = x
      self.y = y
      self.z = z

class part:
   class text:
      def __init__(self,x,y,z=0,text='',line=0.006,angle=0):
         self.x = x
         self.y = y
         self.z = z
         self.text = text
         self.line = line 
         self.angle = angle
   def add(self,pcb,x,y,z=0,angle=0,line=0.007):
      self.x = x
      self.y = y
      self.z = z
      self.angle = angle
      if (angle == 90):
         self.shape = rotate_90(self.shape)
      elif (angle == 180):
         self.shape = rotate_180(self.shape)
      elif ((angle == 270) | (angle == -90)):
         self.shape = rotate_270(self.shape)
      elif (angle != 0):
         self.shape = rotate(self.shape,angle)
      self.shape = translate(self.shape,x,y,z)
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
      if hasattr(self,'holes'):
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
         if (angle == 90):
            self.holes = rotate_90(self.holes)
         elif (angle == 180):
            self.holes = rotate_180(self.holes)
         elif ((angle == 270) | (angle == -90)):
            self.holes = rotate_270(self.holes)
         elif (angle != 0):
            self.holes = rotate(self.holes,angle)
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
         self.holes = translate(self.holes,x,y,z)
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
      deg_angle = angle
      angle = math.pi*angle/180
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
      for i in range(len(self.pad)):
         xnew = math.cos(angle)*self.pad[i].x - math.sin(angle)*self.pad[i].y
         ynew = math.sin(angle)*self.pad[i].x + math.cos(angle)*self.pad[i].y
         self.pad[i].x = x + xnew
         self.pad[i].y = y + ynew
         self.pad[i].z += z
      pcb.labels = add(pcb.labels,text(self.value,x,y,z,line=line,color=Green).shape)
      for i in range(len(self.labels)):
         xnew = math.cos(angle)*self.labels[i].x - math.sin(angle)*self.labels[i].y
         ynew = math.sin(angle)*self.labels[i].x + math.cos(angle)*self.labels[i].y
         self.labels[i].x = x + xnew
         self.labels[i].y = y + ynew
         self.labels[i].z += z
         if ((-90 < deg_angle) & (deg_angle <= 90)):
            pcb.labels = add(pcb.labels,text(self.labels[i].text,self.labels[i].x,self.labels[i].y,self.labels[i].z,self.labels[i].line,color=Red,angle=deg_angle-self.labels[i].angle).shape)
         else:
            pcb.labels = add(pcb.labels,text(self.labels[i].text,self.labels[i].x,self.labels[i].y,self.labels[i].z,self.labels[i].line,color=Red,angle=(deg_angle-self.labels[i].angle-180)).shape)
      pcb = pcb.add(self.shape)
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
      if hasattr(self,'holes'):
         pcb.holes = add(pcb.holes,self.holes)
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
      return pcb

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def wire(pcb,width,*points):
   x0 = points[0].x
   y0 = points[0].y
   z0 = points[0].z
   pcb.board = add(pcb.board,cylinder(x0,y0,z0,z0,width/2))
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   for i in range(1,len(points)):
      x0 = points[i-1].x
      y0 = points[i-1].y
      z0 = points[i-1].z
      x1 = points[i].x
      y1 = points[i].y
      z1 = points[i].z
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
      pcb.board = add(pcb.board,line(x0,y0,x1,y1,z1,width))
      pcb.board = add(pcb.board,cylinder(x1,y1,z1,z1,width/2))
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
   return pcb

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
def wirer(pcb,width,*points):
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
   for i in range(1,len(points)):
      x0 = points[i-1].x
      y0 = points[i-1].y
      z0 = points[i-1].z
      x1 = points[i].x
      y1 = points[i].y
      z1 = points[i].z
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
      if (x0 < x1):
         pcb.board = add(pcb.board,cube(x0-width/2,x1+width/2,y0-width/2,y0+width/2,z0,z0))
      elif (x1 < x0):
         pcb.board = add(pcb.board,cube(x1-width/2,x0+width/2,y0-width/2,y0+width/2,z0,z0))
      if (y0 < y1):
         pcb.board = add(pcb.board,cube(x1-width/2,x1+width/2,y0-width/2,y1+width/2,z0,z0))
      elif (y1 < y0):
         pcb.board = add(pcb.board,cube(x1-width/2,x1+width/2,y1-width/2,y0+width/2,z0,z0))
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
   return pcb

Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
#
# PCB library
#

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
class via(part):
   #
   # via
   #
   def __init__(self,zb,zt,rv,rp,value=''):
      self.value = value
      self.labels = []
      self.pad = [point(0,0,0)]
      self.shape = cylinder(0,0,zb,zt,rp)
      self.holes = cylinder(0,0,zb,zt,rv)
      self.pad.append(point(0,0,zt))
      self.pad.append(point(0,0,zb))

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed

class SJ(part):
   #
   # solder jumper
   #
   def __init__(self,value=''):
      pad_SJ = cube(-.02,.02,-.03,.03,0,0)
      self.value = value
      self.labels = []
      self.pad = [point(0,0,0)]
      self.shape = translate(pad_SJ,-.029,0,0)
      self.pad.append(point(-.029,0,0))
      self.shape = add(self.shape,translate(pad_SJ,.029,0,0))
      self.pad.append(point(.029,0,0))

Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
#
# discretes
#

pad_0402 = cube(-.0175,.0175,-.014,.014,0,0)

class R_0402(part):
   #
   # 0402 resistor
   #
   def __init__(self,value=''):
      self.value = value
      self.labels = []
      self.pad = [point(0,0,0)]
      self.shape = translate(pad_0402,-.0265,0,0)
      self.pad.append(point(-.0265,0,0))
      self.shape = add(self.shape,translate(pad_0402,.0265,0,0))
      self.pad.append(point(.0265,0,0))

pad_1206 = cube(-.032,.032,-.034,.034,0,0)

class R_1206(part):
   #
   # 1206 resistor
   #
   def __init__(self,value=''):
      self.value = value
      self.labels = []
      self.pad = [point(0,0,0)]
      self.shape = translate(pad_1206,-.06,0,0)
      self.pad.append(point(-.06,0,0))
      self.shape = add(self.shape,translate(pad_1206,.06,0,0))
      self.pad.append(point(.06,0,0))

class C_1206(part):
   #
   # 1206 capacitor
   #
   def __init__(self,value=''):
      self.value = value
      self.labels = []
      self.pad = [point(0,0,0)]
      self.shape = translate(pad_1206,-.06,0,0)
      self.pad.append(point(-.06,0,0))
      self.shape = add(self.shape,translate(pad_1206,.06,0,0))
      self.pad.append(point(.06,0,0))

pad_1210 = cube(-.032,.032,-.048,.048,0,0)

class L_1210(part):
   #
   # 1210 inductor
   #
   def __init__(self,value=''):
      self.value = value
      self.labels = []
      self.pad = [point(0,0,0)]
      self.shape = translate(pad_1210,-.06,0,0)
      self.pad.append(point(-.06,0,0))
      self.shape = add(self.shape,translate(pad_1210,.06,0,0))
      self.pad.append(point(.06,0,0))

pad_choke = cube(-.06,.06,-.06,.06,0,0)

class choke(part):
   #
   # Panasonic ELLCTV
   #
   def __init__(self,value=''):
      self.value = value
      self.labels = []
      self.pad = [point(0,0,0)]
      self.shape = translate(pad_choke,-.177,-.177,0)
      self.pad.append(point(-.177,-.177,0))
      self.shape = add(self.shape,translate(pad_choke,.177,.177,0))
      self.pad.append(point(.177,.177,0))

#
# connectors
#

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
class header_SWD_4_05(part):
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
   #
   # 4-pin header
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
   # Sullins GRPB022VWQS-RC 2x2x0.05"
   #
   def __init__(self,value=''):
      pad_header = cube(-.043,.043,-.015,.015,0,0)
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1
      #
      self.shape = translate(pad_header,-.072,.025,0)
      self.shape = add(self.shape,cylinder(-.116,.025,0,0,.015))
      self.pad.append(point(-.072,.025,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'CLK'))
      #
      # pin 2
      #
      self.shape = add(self.shape,translate(pad_header,.072,.025,0))
      self.pad.append(point(.072,.025,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'DIO'))
      #
      # pin 3
      #
      self.shape = add(self.shape,translate(pad_header,-.072,-.025,0))
      self.pad.append(point(-.072,-.025,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'RST'))
      #
      # pin 4
      #
      self.shape = add(self.shape,translate(pad_header,.072,-.025,0))
      self.pad.append(point(.072,-.025,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))

class header_SWD_4_1(part):
   #
   # 4-pin header
   # FCI 95278-101a04lf Bergstik 2x2x0.1"
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
   #
   pad_header = cube(-.05,.05,-.025,.025,0,0)
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1
      #
      self.shape = translate(pad_header,-.107,.05,0)
      self.shape = add(self.shape,cylinder(-.157,.05,0,0,.025))
      self.pad.append(point(-.107,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'CLK'))
      #
      # pin 2
      #
      self.shape = add(self.shape,translate(pad_header,.107,.05,0))
      self.pad.append(point(.107,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'DIO'))
      #
      # pin 3
      #
      self.shape = add(self.shape,translate(pad_header,-.107,-.05,0))
      self.pad.append(point(-.107,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'RST'))
      #
      # pin 4
      #
      self.shape = add(self.shape,translate(pad_header,.107,-.05,0))
      self.pad.append(point(.107,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
class header_UPDI(part):
   #
   # UPDI header
   #    Sullins GEC36SBSN-M89	
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1: UPDI
      #
      self.shape = translate(pad_header,0,-.05,0)
      self.shape = add(self.shape,cylinder(.05,-.05,0,0,.025))
      self.pad.append(point(0,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'UPDI'))
      #
      # pin 2: GND
      #
      self.shape = add(self.shape,translate(pad_header,0,.05,0))
      self.pad.append(point(0,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))

class header_UPDI_reverse(part):
   #
   # UPDI header, reverse for female connector
   #    GCT BG300-03-A-L-A	
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1: UPDI
      #
      self.shape = translate(pad_header,0,.05,0)
      self.shape = add(self.shape,cylinder(.05,.05,0,0,.025))
      self.pad.append(point(0,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'UPDI'))
      #
      # pin 2: GND
      #
      self.shape = add(self.shape,translate(pad_header,0,-.05,0))
      self.pad.append(point(0,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
class USB_A_plug(part):
   #
   # USB type A PCB plug
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1: 5V
      #
      self.shape = translate(cube(-.05,.242,-.02,.02,0,0),0,.138,0)
      self.pad.append(point(0,.138,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'5V'))
      #
      # pin 2: D-
      #
      self.shape = add(self.shape,translate(cube(-0.05,.202,-.02,.02,0,0),0,.039,0))
      self.pad.append(point(0,.039,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'D-'))
      #
      # pin 3: D+
      #
      self.shape = add(self.shape,translate(cube(-.05,.202,-.02,.02,0,0),0,-.039,0))
      self.pad.append(point(0,-.039,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'D+'))
      #
      # pin 4: GND
      #
      self.shape = add(self.shape,translate(cube(-.05,.242,-.02,.02,0,0),0,-.138,0))
      self.pad.append(point(0,-.138,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))
      #
      # plug cutout
      #
      self.holes = cube(-.05,1,.24,1,zb,zt)
      self.holes = add(self.holes,cube(-.05,1,-1,-.24,zb,zt))

class header_SWD(part):
   #
   # Serial Wire Debug programming header
   # Amphenol 20021121-00010T1LF	2x5x0.05
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      d = 0.077
      w = 0.015
      h = .047
      pad = cube(-h,h,-w,w,0,0)
      #
      # pin 1: VCC
      #
      self.shape = translate(pad,d,-.1,0)
      self.shape = add(self.shape,cylinder(d+h,-.1,0,0,w))
      self.pad.append(point(d,-.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'VCC'))
      #
      # pin 2: DIO
      #
      self.shape = add(self.shape,translate(pad,-d,-.1,0))
      self.pad.append(point(-d,-.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'DIO'))
      #
      # pin 3: GND
      #
      self.shape = add(self.shape,translate(pad,d,-.05,0))
      self.pad.append(point(d,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))
      #
      # pin 4: CLK
      #
      self.shape = add(self.shape,translate(pad,-d,-.05,0))
      self.pad.append(point(-d,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'CLK'))
      #
      # pin 5: GND
      #
      self.shape = add(self.shape,translate(pad,d,0,0))
      self.pad.append(point(d,0,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))
      #
      # pin 6: SWO
      #
      self.shape = add(self.shape,translate(pad,-d,0,0))
      self.pad.append(point(-d,0,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'SWO'))
      #
      # pin 7: KEY
      #
      self.shape = add(self.shape,translate(pad,d,.05,0))
      self.pad.append(point(d,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'KEY'))
      #
      # pin 8: NC
      #
      self.shape = add(self.shape,translate(pad,-d,.05,0))
      self.pad.append(point(-d,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'NC'))
      #
      # pin 9: GND
      #
      self.shape = add(self.shape,translate(pad,d,.1,0))
      self.pad.append(point(d,.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))
      #
      # pin 10: nRESET
      #
      self.shape = add(self.shape,translate(pad,-d,.1,0))
      self.pad.append(point(-d,.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'RST'))

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
class ESC(part):
   #
   # ESC 3x1
   # Sullins S1013E-36-ND
   #
   def __init__(self,value=''):
      pad_header = cube(-.1,.1,-.05/2,.05/2,0,0)
      d = .075
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1: PWM
      #
      self.shape = translate(pad_header,-d,-.1,0)
      self.pad.append(point(-d,-.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'PWM'))
      #
      # pin 2: 5V
      #
      self.shape = add(self.shape,translate(pad_header,d,0,0))
      self.pad.append(point(d,0,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'5V'))
      #
      # pin 3: GND 
      #
      self.shape = add(self.shape,translate(pad_header,-d,.1,0))
      self.pad.append(point(-d,.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
class I2C4x1h(part):
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
   #
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
   # I2C 4x1 horizontal female
   #    GCT BG300-03-A-L-A	
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1: SCL
      #
      self.shape = translate(pad_header,0,-.15,0)
      #self.shape = cylinder(.05,.15,0,0,.025)
      self.pad.append(point(0,-.15,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'SCL'))
      #
      # pin 2: SDA
      #
      self.shape = add(self.shape,translate(pad_header,0,-.05,0))
      self.pad.append(point(0,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'SDA'))
      #
      # pin 3: VCC
      #
      self.shape = add(self.shape,translate(pad_header,0,.05,0))
      self.pad.append(point(0,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'VCC'))
      #
      # pin 4: GND
      #
      self.shape = add(self.shape,translate(pad_header,0,.15,0))
      self.pad.append(point(0,.15,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))

class I2C4x1v(part):
   #
   # I2C 4x1 vertical
   #    Sullins S5635-ND
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
   #
   def __init__(self,value=''):
      pad_header = cube(-.079/2,.079/2,-.039/2,.039/2,0,0)
      d = .209/2-.079/2
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1: VCC
      #
      self.shape = translate(pad_header,-d,-.15,0)
      self.pad.append(point(-d,-.15,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'1VCC'))
      #
      # pin 2: GND
      #
      self.shape = add(self.shape,translate(pad_header,d,-.05,0))
      self.pad.append(point(d,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))
      #
      # pin 3: SCL
      #
      self.shape = add(self.shape,translate(pad_header,-d,.05,0))
      self.pad.append(point(-d,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'SCL'))
      #
      # pin 4: SDA
      #
      self.shape = add(self.shape,translate(pad_header,d,.15,0))
      self.pad.append(point(d,.15,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'SDA'))

class I2C4x1i(part):
   #
   # I2C 4x1 inline
   #
   def __init__(self,value=''):
      pad_header = cube(-.079/2,.079/2,-.039/2,.039/2,0,0)
      d = 0
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1: VCC
      #
      self.shape = translate(pad_header,-d,-.15,0)
      self.pad.append(point(-d,-.15,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'1VCC'))
      #
      # pin 2: GND
      #
      self.shape = add(self.shape,translate(pad_header,d,-.05,0))
      self.pad.append(point(d,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))
      #
      # pin 3: SCL
      #
      self.shape = add(self.shape,translate(pad_header,-d,.05,0))
      self.pad.append(point(-d,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'SCL'))
      #
      # pin 4: SDA
      #
      self.shape = add(self.shape,translate(pad_header,d,.15,0))
      self.pad.append(point(d,.15,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'SDA'))

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
class RCWL0516(part):
   #
   # RCWL-0516 Doppler radar
   #
   def __init__(self,value=''):
      pad_header = cube(-.065,.065,-.025,.025,0,0)
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1: 3.3V
      #
      self.shape = translate(pad_header,.107,-.2,0)
      self.shape = add(self.shape,cylinder(.172,-.2,0,0,.025))
      self.pad.append(point(.107,-.2,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'3.3V'))
      #
      # pin 2: GND
      #
      self.shape = add(self.shape,translate(pad_header,-.107,-.1,0))
      self.pad.append(point(-.107,-.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))
      #
      # pin 3: OUT
      #
      self.shape = add(self.shape,translate(pad_header,.107,0,0))
      self.pad.append(point(.107,0,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'OUT'))
      #
      # pin 4: VIN
      #
      self.shape = add(self.shape,translate(pad_header,-.107,.1,0))
      self.pad.append(point(-.107,.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'VIN'))
      #
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
      # pin 5: CDS
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
      #
      self.shape = add(self.shape,translate(pad_header,.107,.2,0))
      self.pad.append(point(.107,.2,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'CDS'))

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
class microSD(part):
   #
   # microSD
   # Amphenol 114-00841-68
   # 
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1
      #
      self.shape = translate(cube(-.0138,.0138,-.034,.034,0,0),-.177+7*.0433,-.304,0)
      self.pad.append(point(-.177+7*.0433,-.304,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'1NC',angle=90))
      #
      # pin 2
      #
      self.shape = add(self.shape,translate(cube(-.0138,.0138,-.034,.034,0,0),-.177+6*.0433,-.304,0))
      self.pad.append(point(-.177+6*.0433,-.304,0))
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'SS',angle=90))
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
      #
      # pin 3
      #
      self.shape = add(self.shape,translate(cube(-.0138,.0138,-.034,.034,0,0),-.177+5*.0433,-.304,0))
      self.pad.append(point(-.177+5*.0433,-.304,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'MOSI',angle=90))
      #
      # pin 4
      #
      self.shape = add(self.shape,translate(cube(-.0138,.0138,-.034,.034,0,0),-.177+4*.0433,-.304,0))
      self.pad.append(point(-.177+4*.0433,-.304,0))
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'VCC',angle=90))
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
      #
      # pin 5
      #
      self.shape = add(self.shape,translate(cube(-.0138,.0138,-.034,.034,0,0),-.177+3*.0433,-.304,0))
      self.pad.append(point(-.177+3*.0433,-.304,0))
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'SCK',angle=90))
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
      #
      # pin 6
      #
      self.shape = add(self.shape,translate(cube(-.0138,.0138,-.034,.034,0,0),-.177+2*.0433,-.304,0))
      self.pad.append(point(-.177+2*.0433,-.304,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND',angle=90))
      #
      # pin 7
      #
      self.shape = add(self.shape,translate(cube(-.0138,.0138,-.034,.034,0,0),-.177+1*.0433,-.304,0))
      self.pad.append(point(-.177+1*.0433,-.304,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'MISO',angle=90))
      #
      # pin 8
      #
      self.shape = add(self.shape,translate(cube(-.0138,.0138,-.034,.034,0,0),-.177+0*.0433,-.304,0))
      self.pad.append(point(-.177+0*.0433,-.304,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'NC',angle=90))
      #
      # feet
      #
      self.shape = add(self.shape,translate(cube(-.021,.021,-.029,.029,0,0),-.228,-.299,0)) # leave extra space for 1/64 milling
      self.shape = add(self.shape,translate(cube(-.029,.029,-.029,.029,0,0),.222,-.299,0))
      self.shape = add(self.shape,translate(cube(-.015,.015,-.029,.025,0,0),-.232,0,0)) # leave extra space for 1/64 milling
      self.shape = add(self.shape,translate(cube(-.015,.015,-.029,.029,0,0),-.232+.47,.025,0))
      self.shape = add(self.shape,translate(cube(-.028,.028,-.019,.019,0,0),-.221,.059,0))
      self.shape = add(self.shape,translate(cube(-.019,.019,-.030,.030,0,0),.222,.121,0))

Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174
pad_USB_trace = cube(-.0075,.0075,-.04,.04,0,0)
pad_USB_feet = cube(-.049,.049,-.043,.043,0,0)

class USB_mini_B(part):
   #
   # USB mini B
   # Hirose UX60-MB-5ST
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1
      #
      self.shape = translate(pad_USB_trace,.063,.36,0)
      self.pad.append(point(.063,.36,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'G'))
      #
      # pin 2
      #
      self.shape = add(self.shape,translate(pad_USB_trace,.0315,.36,0))
      self.pad.append(point(.0315,.36,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,''))
      #
      # pin 3
      #
      self.shape = add(self.shape,translate(pad_USB_trace,0,.36,0))
      self.pad.append(point(0,.36,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'+'))
      #
      # pin 4
      #
      self.shape = add(self.shape,translate(pad_USB_trace,-.0315,.36,0))
      self.pad.append(point(-.0315,.36,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'-'))
      #
      # pin 5
      #
      self.shape = add(self.shape,translate(pad_USB_trace,-.063,.36,0))
      self.pad.append(point(-.063,.36,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'V'))
      #
      # feet
      #
      self.shape = add(self.shape,translate(pad_USB_feet,.165,.33,0))
      self.shape = add(self.shape,translate(pad_USB_feet,-.165,.33,0))
      self.shape = add(self.shape,translate(pad_USB_feet,.165,.12,0))
      self.shape = add(self.shape,translate(pad_USB_feet,-.165,.12,0))

pad_header = cube(-.05,.05,-.025,.025,0,0)

class header_4(part):
   #
   # 4-pin header
   # fci 95278-101a04lf bergstik 2x2x0.1"
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1
      #
      self.shape = translate(pad_header,-.107,.05,0)
      self.shape = add(self.shape,cylinder(-.157,.05,0,0,.025))
      self.pad.append(point(-.107,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'1'))
      #
      # pin 2
      #
      self.shape = add(self.shape,translate(pad_header,.107,.05,0))
      self.pad.append(point(.107,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'2'))
      #
      # pin 3
      #
      self.shape = add(self.shape,translate(pad_header,-.107,-.05,0))
      self.pad.append(point(-.107,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'3'))
      #
      # pin 4
      #
      self.shape = add(self.shape,translate(pad_header,.107,-.05,0))
      self.pad.append(point(.107,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'4'))

class header_signal(part):
   #
   # signal header
   # FCI 95278-101A04LF Bergstik 2x2x0.1"
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1: Gnd
      #
      self.shape = translate(pad_header,.107,-.05,0)
      self.shape = add(self.shape,cylinder(.157,-.05,0,0,.025))
      self.pad.append(point(.107,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))
      #
      # pin 2
      #
      self.shape = add(self.shape,translate(pad_header,-.107,-.05,0))
      self.pad.append(point(-.107,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,''))
      #
      # pin 3: signal
      #
      self.shape = add(self.shape,translate(pad_header,.107,.05,0))
      self.pad.append(point(.107,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'signal'))
      #
      # pin 4:
      #
      self.shape = add(self.shape,translate(pad_header,-.107,.05,0))
      self.pad.append(point(-.107,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,''))


class header_power(part):
   #
   # power header
   # FCI 95278-101A04LF Bergstik 2x2x0.1"
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1: Gnd
      #
      self.shape = translate(pad_header,.107,-.05,0)
      self.shape = add(self.shape,cylinder(.157,-.05,0,0,.025))
      self.pad.append(point(.107,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))
      #
      # pin 2
      #
      self.shape = add(self.shape,translate(pad_header,-.107,-.05,0))
      self.pad.append(point(-.107,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,''))
      #
      # pin 3: V
      #
      self.shape = add(self.shape,translate(pad_header,.107,.05,0))
      self.pad.append(point(.107,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'V'))
      #
      # pin 4:
      #
      self.shape = add(self.shape,translate(pad_header,-.107,.05,0))
      self.pad.append(point(-.107,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,''))

class header_i0(part):
   #
   # i0 header
   # FCI 95278-101A04LF Bergstik 2x2x0.1"
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1: Gnd
      #
      self.shape = translate(pad_header,.107,-.05,0)
      self.shape = add(self.shape,cylinder(.157,-.05,0,0,.025))
      self.pad.append(point(.107,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))
      #
      # pin 2: data
      #
      self.shape = add(self.shape,translate(pad_header,-.107,-.05,0))
      self.pad.append(point(-.107,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'data'))
      #
      # pin 3: V
      #
      self.shape = add(self.shape,translate(pad_header,.107,.05,0))
      self.pad.append(point(.107,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'V'))
      #
      # pin 4:
      #
      self.shape = add(self.shape,translate(pad_header,-.107,.05,0))
      self.pad.append(point(-.107,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,''))

class header_serial(part):
   #
   # serial comm header
   # FCI 95278-101A04LF Bergstik 2x2x0.1"
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1: Gnd
      #
      self.shape = translate(pad_header,.107,-.05,0)
      self.shape = add(self.shape,cylinder(.157,-.05,0,0,.025))
      self.pad.append(point(.107,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))
      #
      # pin 2:DTR
      #
      self.shape = add(self.shape,translate(pad_header,-.107,-.05,0))
      self.pad.append(point(-.107,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'DTR'))
      #
      # pin 3: Tx
      #
      self.shape = add(self.shape,translate(pad_header,.107,.05,0))
      self.pad.append(point(.107,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'Tx'))
      #
      # pin 4: Rx
      #
      self.shape = add(self.shape,translate(pad_header,-.107,.05,0))
      self.pad.append(point(-.107,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'Rx'))

class header_bus(part):
   #
   # bus header
   # FCI 95278-101A04LF Bergstik 2x2x0.1"
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1: Gnd
      #
      self.shape = translate(pad_header,.107,-.05,0)
      self.shape = add(self.shape,cylinder(.157,-.05,0,0,.025))
      self.pad.append(point(.107,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))
      #
      # pin 2: Tx
      #
      self.shape = add(self.shape,translate(pad_header,-.107,-.05,0))
      self.pad.append(point(-.107,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'Tx'))
      #
      # pin 3: V
      #
      self.shape = add(self.shape,translate(pad_header,.107,.05,0))
      self.pad.append(point(.107,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'V'))
      #
      # pin 4: Rx
      #
      self.shape = add(self.shape,translate(pad_header,-.107,.05,0))
      self.pad.append(point(-.107,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'Rx'))

class header_I2C(part):
   #
   # I2C header
   # FCI 95278-101A04LF Bergstik 2x2x0.1"
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1: SCL
      #
      self.shape = translate(pad_header,.107,-.05,0)
      self.shape = add(self.shape,cylinder(.157,-.05,0,0,.025))
      self.pad.append(point(.107,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'SCL'))
      #
      # pin 2: G
      #
      self.shape = add(self.shape,translate(pad_header,-.107,-.05,0))
      self.pad.append(point(-.107,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'G'))
      #
      # pin 3: SDA
      #
      self.shape = add(self.shape,translate(pad_header,.107,.05,0))
      self.pad.append(point(.107,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'SDA'))
      #
      # pin 4: V
      #
      self.shape = add(self.shape,translate(pad_header,-.107,.05,0))
      self.pad.append(point(-.107,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'V'))

class header_APA(part):
   #
   # APA header
   # FCI 95278-101A04LF Bergstik 2x2x0.1"
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1: Gnd
      #
      self.shape = translate(pad_header,.107,-.05,0)
      self.shape = add(self.shape,cylinder(.157,-.05,0,0,.025))
      self.pad.append(point(.107,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))
      #
      # pin 2: in
      #
      self.shape = add(self.shape,translate(pad_header,-.107,-.05,0))
      self.pad.append(point(-.107,-.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'in'))
      #
      # pin 3: V
      #
      self.shape = add(self.shape,translate(pad_header,.107,.05,0))
      self.pad.append(point(.107,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'V'))
      #
      # pin 4: out
      #
      self.shape = add(self.shape,translate(pad_header,-.107,.05,0))
      self.pad.append(point(-.107,.05,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'out'))

class header_6(part):
   #
   # 6-pin header
   # FCI 95278-101A06LF Bergstik 2x3x0.1"
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1
      #
      self.shape = translate(pad_header,.107,-.1,0)
      self.shape = add(self.shape,cylinder(.157,-.1,0,0,.025))
      self.pad.append(point(.107,-.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,''))
      #
      # pin 2
      #
      self.shape = add(self.shape,translate(pad_header,-.107,-.1,0))
      self.pad.append(point(-.107,-.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,''))
      #
      # pin 3
      #
      self.shape = add(self.shape,translate(pad_header,.107,0,0))
      self.pad.append(point(.107,0,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,''))
      #
      # pin 4
      #
      self.shape = add(self.shape,translate(pad_header,-.107,0,0))
      self.pad.append(point(-.107,0,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,''))
      #
      # pin 5
      #
      self.shape = add(self.shape,translate(pad_header,.107,.1,0))
      self.pad.append(point(.107,.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,''))
      #
      # pin 6
      #
      self.shape = add(self.shape,translate(pad_header,-.107,.1,0))
      self.pad.append(point(-.107,.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,''))

class header_ATP(part):
   #
   # Asynchronous Token Protocol header
   # FCI 95278-101A06LF Bergstik 2x3x0.1"
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1
      #
      self.shape = translate(pad_header,.107,-.1,0)
      self.shape = add(self.shape,cylinder(.157,-.1,0,0,.025))
      self.pad.append(point(.107,-.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'BI'))
      #
      # pin 2
      #
      self.shape = add(self.shape,translate(pad_header,-.107,-.1,0))
      self.pad.append(point(-.107,-.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'TI'))
      #
      # pin 3
      #
      self.shape = add(self.shape,translate(pad_header,.107,0,0))
      self.pad.append(point(.107,0,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'G'))
      #
      # pin 4
      #
      self.shape = add(self.shape,translate(pad_header,-.107,0,0))
      self.pad.append(point(-.107,0,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'V'))
      #
      # pin 5
      #
      self.shape = add(self.shape,translate(pad_header,.107,.1,0))
      self.pad.append(point(.107,.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'TO'))
      #
      # pin 6
      #
      self.shape = add(self.shape,translate(pad_header,-.107,.1,0))
      self.pad.append(point(-.107,.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'BO'))

class header_PDI(part):
   #
   # in-circuit PDI programming header
   # FCI 95278-101A06LF Bergstik 2x3x0.1"
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1: Data
      #
      self.shape = translate(pad_header,.107,-.1,0)
      self.shape = add(self.shape,cylinder(.157,-.1,0,0,.025))
      self.pad.append(point(.107,-.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'DAT'))
      #
      # pin 2: VCC
      #
      self.shape = add(self.shape,translate(pad_header,-.107,-.1,0))
      self.pad.append(point(-.107,-.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'VCC'))
      #
      # pin 3: NC 
      #
      self.shape = add(self.shape,translate(pad_header,.107,0,0))
      self.pad.append(point(.107,0,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'NC'))
      #
      # pin 4: NC
      #
      self.shape = add(self.shape,translate(pad_header,-.107,0,0))
      self.pad.append(point(-.107,0,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'NC'))
      #
      # pin 5: Clock
      #
      self.shape = add(self.shape,translate(pad_header,.107,.1,0))
      self.pad.append(point(.107,.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'CLK'))
      #
      # pin 6: GND
      #
      self.shape = add(self.shape,translate(pad_header,-.107,.1,0))
      self.pad.append(point(-.107,.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))

class header_ISP(part):
   #
   # in-circuit ISP programming header
   # FCI 95278-101A06LF Bergstik 2x3x0.1"
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1: MISO
      #
      self.shape = translate(pad_header,.107,-.1,0)
      self.shape = add(self.shape,cylinder(.157,-.1,0,0,.025))
      self.pad.append(point(.107,-.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'MISO'))
      #
      # pin 2: V
      #
      self.shape = add(self.shape,translate(pad_header,-.107,-.1,0))
      self.pad.append(point(-.107,-.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'V'))
      #
      # pin 3: SCK
      #
      self.shape = add(self.shape,translate(pad_header,.107,0,0))
      self.pad.append(point(.107,0,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'SCK'))
      #
      # pin 4: MOSI
      #
      self.shape = add(self.shape,translate(pad_header,-.107,0,0))
      self.pad.append(point(-.107,0,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'MOSI'))
      #
      # pin 5: RST
      #
      self.shape = add(self.shape,translate(pad_header,.107,.1,0))
      self.pad.append(point(.107,.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'RST'))
      #
      # pin 6: GND
      #
      self.shape = add(self.shape,translate(pad_header,-.107,.1,0))
      self.pad.append(point(-.107,.1,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
class header_nRF24L01(part):
   #
   # nRF24L01 module header
   #
   def __init__(self,value=''):
      self.value = value
      self.pad = [point(0,0,0)]
      self.labels = []
      #
      # pin 1:
      #
      self.shape = translate(pad_header,.107,-.15,0)
      self.shape = add(self.shape,cylinder(.157,-.15,0,0,.025))
      self.pad.append(point(.107,-.15,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'GND'))
      #
      # pin 2:
      #
      self.shape = add(self.shape,translate(pad_header,-.107,-.15,0))
      self.pad.append(point(-.107,-.15,0))
      self.labels.append(self.text(self.pad[-1].x,self.pad[-1].y,self.pad[-1].z,'VCC'))
      #
      # pin 3:
      #
      self.shape = add(self.shape,translate(pad_header,.107,-.05,0))
      self.pad.append(point(.107,-.05,0))
Loading
Loading full blame...