Skip to content
Snippets Groups Projects
pcb.py 300 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 10/17/21
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.
#

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
############################################################
# uncomment for desired output
############################################################
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed

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"
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
#output = "top traces and exterior"
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
#output = "bottom traces"
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
#output = "bottom traces reversed"
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
#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"

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

import math,json,sys

Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
############################################################
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed
# define shapes and transformations
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
############################################################
Neil Gershenfeld (test)'s avatar
wip
Neil Gershenfeld (test) committed

# 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
   roundoff = 1e-6
   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-roundoff)) & (Z < (z+roundoff)))"
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
   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('roundoff',str(roundoff))
Neil Gershenfeld (test)'s avatar
Neil Gershenfeld (test) committed
   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))"
Loading
Loading full blame...