Added file cloning scripts for power board (sto)
This commit is contained in:
parent
34dba7af37
commit
2d18772b6b
3 changed files with 166 additions and 0 deletions
90
power/generate_pdf_files_from_ps.py
Executable file
90
power/generate_pdf_files_from_ps.py
Executable file
|
@ -0,0 +1,90 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import time
|
||||
import shutil
|
||||
|
||||
|
||||
|
||||
|
||||
filename = 'matemat_power'
|
||||
in_dir = 'output/tmp/'
|
||||
out_dir ='output/'
|
||||
papersize='a3'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def ps_change_color(filename_in, filename_out, color):
|
||||
f = open(filename_in, 'r')
|
||||
pdf = f.read()
|
||||
f.close()
|
||||
|
||||
pdf = re.sub(r'^(1 ){3}setrgbcolor$','white setrgbcolor',pdf,0, re.MULTILINE) # preserve white color
|
||||
pdf = re.sub(r'^([0-9\.\-]+ ){3}setrgbcolor$','{:.2f} {:.2f} {:.2f} setrgbcolor'.format(color[0], color[1], color[2]),pdf,0, re.MULTILINE) # replace all others by target color
|
||||
pdf = re.sub(r'^white setrgbcolor$','1 1 1 setrgbcolor',pdf,0, re.MULTILINE) # put back white color
|
||||
|
||||
f = open(filename_out, 'w')
|
||||
f.write(pdf)
|
||||
f.close()
|
||||
|
||||
|
||||
def add_colored_ps_to_pdf(filename_in, filename_out, color):
|
||||
tmpfile = 'kicad_copy_temp'
|
||||
|
||||
ps_change_color(filename_in, tmpfile+'.ps', color)
|
||||
|
||||
subprocess.check_call(["ps2pdf", "-sPAPERSIZE="+papersize, tmpfile+'.ps', tmpfile+'.pdf'])
|
||||
|
||||
if os.path.exists(filename_out):
|
||||
subprocess.check_call(["pdftk", filename_out, 'stamp', tmpfile+'.pdf', 'output', tmpfile+'2.pdf' ]) # add to pdf
|
||||
shutil.copyfile(tmpfile+'2.pdf', filename_out)
|
||||
os.remove(tmpfile+'2.pdf')
|
||||
else:
|
||||
shutil.copyfile(tmpfile+'.pdf', filename_out)
|
||||
|
||||
os.remove(tmpfile+'.pdf')
|
||||
os.remove(tmpfile+'.ps')
|
||||
|
||||
|
||||
def compose_one_side(filename, side):
|
||||
|
||||
side_small = side[0]
|
||||
|
||||
filename_out = out_dir+filename+'-layerstack_'+side+'.pdf'
|
||||
subprocess.call(["rm", filename_out ]) # remove previous output file
|
||||
|
||||
#add_colored_ps_to_pdf(in_dir+filename+'-'+side_small+'_Mask'+'.ps', filename_out, [0.8, 0.8, 0.8]) # Mask
|
||||
add_colored_ps_to_pdf(in_dir+filename+'-'+side_small+'_Cu.ps', filename_out, [0.6, 0.6, 1.0]) # copper
|
||||
#add_colored_ps_to_pdf(in_dir+filename+'-'+side_small+'_Paste'+'.ps', filename_out, [0.0, 0.0, 1.0]) # Paste
|
||||
add_colored_ps_to_pdf(in_dir+filename+'-'+side_small+'_SilkS'+'.ps', filename_out, [0.0, 0.5, 0.0]) # Silksreen
|
||||
|
||||
add_colored_ps_to_pdf(in_dir+filename+'-'+'Eco2_User'+'.ps', filename_out, [0.0, 0.0, 1.0])
|
||||
add_colored_ps_to_pdf(in_dir+filename+'-'+'Edge_Cuts'+'.ps', filename_out, [0.0, 0.0, 0.0])
|
||||
|
||||
|
||||
def compose_one_side_copper_film_to_print(filename, side):
|
||||
|
||||
side_small = side[0]
|
||||
|
||||
filename_out = out_dir+filename+'-copperfilm_'+side+'.pdf'
|
||||
subprocess.call(["rm", filename_out ]) # remove previous output file
|
||||
|
||||
#add_colored_ps_to_pdf(in_dir+filename+'-'+side_small+'_Mask'+'.ps', filename_out, [0.8, 0.8, 0.8]) # Mask
|
||||
add_colored_ps_to_pdf(in_dir+filename+'-'+side_small+'_Cu.ps', filename_out, [0.0, 0.0, 0.0]) # copper
|
||||
#add_colored_ps_to_pdf(in_dir+filename+'-'+side_small+'_Paste'+'.ps', filename_out, [0.0, 0.0, 1.0]) # Paste
|
||||
#add_colored_ps_to_pdf(in_dir+filename+'-'+side_small+'_SilkS'+'.ps', filename_out, [0.0, 0.5, 0.0]) # Silksreen
|
||||
|
||||
add_colored_ps_to_pdf(in_dir+filename+'-'+'Eco2_User'+'.ps', filename_out, [0.0, 0.0, 0.0])
|
||||
add_colored_ps_to_pdf(in_dir+filename+'-'+'Edge_Cuts'+'.ps', filename_out, [0.0, 0.0, 0.0])
|
||||
|
||||
|
||||
|
||||
compose_one_side(filename, 'Front')
|
||||
compose_one_side(filename, 'Back')
|
||||
compose_one_side_copper_film_to_print(filename, 'Back')
|
||||
|
32
power/generate_triac_channel_pcbs_to_add_from_master.py
Executable file
32
power/generate_triac_channel_pcbs_to_add_from_master.py
Executable file
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
import ast
|
||||
import re
|
||||
import math
|
||||
|
||||
|
||||
filename = 'triac_channel_master'
|
||||
|
||||
|
||||
f = open(filename+'.brd', 'r')
|
||||
input_sch = f.read()
|
||||
f.close()
|
||||
|
||||
|
||||
# for each instance
|
||||
for n in range(1,8+1):
|
||||
|
||||
variant_filename = re.sub('master', 'to_add_'+str(n), filename)
|
||||
|
||||
variant_sch = re.sub('\!', str(n), input_sch)
|
||||
|
||||
# write file
|
||||
f = open(variant_filename+'.brd', 'w')
|
||||
f.write(variant_sch)
|
||||
f.close()
|
||||
|
||||
|
||||
|
||||
print(variant_filename+'.brd')
|
||||
|
44
power/generate_triac_channel_sch_from_master.py
Executable file
44
power/generate_triac_channel_sch_from_master.py
Executable file
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
import ast
|
||||
import re
|
||||
import math
|
||||
|
||||
|
||||
filename = 'triac_channel_master'
|
||||
|
||||
|
||||
f = open(filename+'.sch', 'r')
|
||||
input_sch = f.read()
|
||||
f.close()
|
||||
|
||||
|
||||
# for each instance
|
||||
for n in range(1,8+1):
|
||||
|
||||
variant_filename = re.sub('master', str(n), filename)
|
||||
|
||||
variant_sch = re.sub('\!', str(n), input_sch)
|
||||
|
||||
# write file
|
||||
f = open(variant_filename+'.sch', 'w')
|
||||
f.write(variant_sch)
|
||||
f.close()
|
||||
|
||||
# write lib
|
||||
try:
|
||||
f = open(filename+'-cache.lib', 'r')
|
||||
lib = f.read()
|
||||
f.close()
|
||||
|
||||
f = open(variant_filename+'-cache.lib', 'w')
|
||||
f.write(lib)
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
print(variant_filename+'.sch')
|
||||
|
Loading…
Reference in a new issue