Skip to content
Snippets Groups Projects
pcb.py 166 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
wip
Neil Gershenfeld (test) committed
#
# Neil Gershenfeld 10/8/18
# (c) Massachusetts Institute of Technology 2018
#
# 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:
#

output = "traces, labels, and exterior"
#output = "traces and exterior"
#output = "interior"
#output = "exterior"
#output = "traces"
#output = "holes"
#output = "solder mask"

#
# import
#

import math,json,sys

#
# define shapes and transformations
#

# color(color,part)
# circle(x0, y0, r)
# cylinder(x0, y0, z0, z1, r)
# cone(x0, y0, z0, z1, r0)
# sphere(x0, y0, z0, r)
# torus(x0, y0, z0, r0, r1)
# rectangle(x0, x1, y0, y1)
# cube(x0, x1, y0, y1, z0, z1)
# right_triangle(x0, y0, h)
# triangle(x0, y0, x1, y1, x2, y2) (points in clockwise order)
# pyramid(x0, x1, y0, y1, z0, z1)
# function(Z_of_XY)
# functions(upper_Z_of_XY,lower_Z_of_XY)
# add(part1, part2)
# subtract(part1, part2)
# intersect(part1, part2)
# move(part,dx,dy)
# translate(part,dx,dy,dz)
# rotate(part, angle)
# rotate_x(part, angle)
# rotate_y(part, angle)
# rotate_z(part, angle)
# 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)
# 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)

true = "1"
false = "0"

def color(color, part):
   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)

def circle(x0, y0, r):
   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

def cylinder(x0, y0, z0, z1, r):
   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

def cone(x0, y0, z0, z1, r0):
   part = cylinder(x0, y0, z0, z1, r0)
   part = taper_xy_z(part, x0, y0, z0, z1, 1.0, 0.0)
   return part

def sphere(x0, y0, z0, r):
   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

def torus(x0, y0, z0, r0, r1):
   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

def rectangle(x0, x1, y0, y1):
   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

def cube(x0, x1, y0, y1, z0, z1):
   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

def right_triangle(x0, y0, l):
   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

def triangle(x0, y0, x1, y1, x2, y2): # points in clockwise order
   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))
   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

def pyramid(x0, x1, y0, y1, z0, z1):
   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

def add(part1, part2):
   part = "part1 | part2"
   part = part.replace('part1',part1)
   part = part.replace('part2',part2)
   return part

def subtract(part1, part2):
   part = "(part1) & ~(part2)"
   part = part.replace('part1',part1)
   part = part.replace('part2',part2)
   return part

def intersect(part1, part2):
Loading
Loading full blame...