[Stencil*] Added get_targets implementation

This commit is contained in:
Salvador E. Tropea 2022-12-01 13:59:24 -03:00
parent 2b86ef9e80
commit f68855f4d8
4 changed files with 75 additions and 26 deletions

View File

@ -243,6 +243,7 @@ W_NOCRTYD = '(W104) '
W_PANELEMPTY = '(W105) '
W_ONWIN = '(W106) '
W_AUTONONE = '(W106) '
W_AUTOPROB = '(W107) '
# Somehow arbitrary, the colors are real, but can be different
PCB_MAT_COLORS = {'fr1': "937042", 'fr2': "949d70", 'fr3': "adacb4", 'fr4': "332B16", 'fr5': "6cc290"}
PCB_FINISH_COLORS = {'hal': "8b898c", 'hasl': "8b898c", 'imag': "8b898c", 'enig': "cfb96e", 'enepig': "cfb96e",

View File

@ -10,7 +10,7 @@ from .error import PlotError
from .gs import GS
from .kiplot import run_command
from .out_base import VariantOptions
from .misc import W_AUTONONE
from .misc import W_AUTONONE, W_AUTOPROB
from .macros import macros, document, output_class # noqa: F401
from . import log
@ -39,10 +39,13 @@ class Stencil_Options(VariantOptions):
super().config(parent)
self.cutout = ','.join(self.force_list(self.cutout))
def move_output(self, src_dir, src_file, id, ext, replacement=None, patch=False, relative=False):
def expand_name(self, id, ext, out_dir):
self._expand_id = id
self._expand_ext = ext
dst_name = self._parent.expand_filename(self._parent.output_dir, self.output)
return self._parent.expand_filename(out_dir, self.output)
def move_output(self, src_dir, src_file, id, ext, replacement=None, patch=False, relative=False):
dst_name = self.expand_name(id, ext, self._parent.output_dir)
src_name = os.path.join(src_dir, src_file)
if not os.path.isfile(src_name):
raise PlotError('Missing output file {}'.format(src_name))
@ -61,6 +64,29 @@ class Stencil_Options(VariantOptions):
src_name = os.path.basename(src_name)
replacement[src_name] = os.path.basename(dst_name)
def find_sides(self, detected_top, detected_bottom, warn=False):
do_top = do_bottom = False
if self.side == 'top':
do_top = True
elif self.side == 'bottom':
do_bottom = True
elif self.side == 'both':
do_top = True
do_bottom = True
else: # auto
do_top = detected_top
do_bottom = detected_bottom
if warn:
logger.warning(W_AUTOPROB+'Using the `stencil.side` option could create a wrong list of files.')
return do_top, do_bottom
def solve_sides(self):
if self.side == 'auto':
detected_top, detected_bottom = self.detect_solder_paste(GS.board)
else:
detected_top = detected_bottom = False
return self.find_sides(detected_top, detected_bottom, warn=True)
def run(self, output):
cmd_kikit = self.ensure_tool('KiKit')
self.ensure_tool('OpenSCAD')
@ -69,6 +95,8 @@ class Stencil_Options(VariantOptions):
filtered = self.filter_pcb_components(GS.board)
if self.side == 'auto':
detected_top, detected_bottom = self.detect_solder_paste(GS.board)
else:
detected_top = detected_bottom = False
fname = self.save_tmp_board() if filtered else GS.pcb_file
if filtered:
self.unfilter_pcb_components(GS.board)
@ -93,17 +121,6 @@ class Stencil_Options(VariantOptions):
if filtered:
GS.remove_pcb_and_pro(fname)
# Now copy the files we want
# - Which side?
do_top = do_bottom = False
if self.side == 'top':
do_top = True
elif self.side == 'bottom':
do_bottom = True
elif self.side == 'both':
do_top = True
do_bottom = True
else: # auto
do_top = detected_top
do_bottom = detected_bottom
do_top, do_bottom = self.find_sides(detected_top, detected_bottom)
prj_name = os.path.splitext(os.path.basename(fname))[0]
self.move_outputs(tmp, prj_name, do_top, do_bottom)

View File

@ -47,8 +47,24 @@ class Stencil_3D_Options(Stencil_Options):
self.add_to_doc('include_scad', 'Note that this also includes the DXF files')
def get_targets(self, out_dir):
# TODO: auto side is tricky, needs variants applied
return [self._parent.expand_filename(out_dir, self.output)]
do_top, do_bottom = self.solve_sides()
files = []
# The edge is needed by any of the OpenSCAD files
if (do_top or do_bottom) and self.include_scad:
files.append(self.expand_name('stencil_3d_edge', 'dxf', out_dir))
# Top side
if do_top:
files.append(self.expand_name('stencil_3d_top', 'stl', out_dir))
if self.include_scad:
files.append(self.expand_name('stencil_3d_top', 'dxf', out_dir))
files.append(self.expand_name('stencil_3d_top', 'scad', out_dir))
# Bottom side
if do_bottom:
files.append(self.expand_name('stencil_3d_bottom', 'stl', out_dir))
if self.include_scad:
files.append(self.expand_name('stencil_3d_bottom', 'dxf', out_dir))
files.append(self.expand_name('stencil_3d_bottom', 'scad', out_dir))
return files
def create_cmd(self, cmd_kikit):
cmd = [cmd_kikit, 'stencil', 'createprinted',
@ -67,19 +83,19 @@ class Stencil_3D_Options(Stencil_Options):
replacements = {}
# The edge is needed by any of the OpenSCAD files
if (do_top or do_bottom) and self.include_scad:
self.move_output(tmp, prj_name+'-EdgeCuts.dxf', 'Stencil_For_Jig_edge', 'dxf', replacements)
self.move_output(tmp, prj_name+'-EdgeCuts.dxf', 'stencil_3d_edge', 'dxf', replacements)
# Top side
if do_top:
self.move_output(tmp, 'topStencil.stl', 'Stencil_For_Jig_top', 'stl')
self.move_output(tmp, 'topStencil.stl', 'stencil_3d_top', 'stl')
if self.include_scad:
self.move_output(tmp, prj_name+'-PasteTop.dxf', 'Stencil_For_Jig_top', 'dxf', replacements)
self.move_output(tmp, 'topStencil.scad', 'Stencil_For_Jig_top', 'scad', replacements, patch=True)
self.move_output(tmp, prj_name+'-PasteTop.dxf', 'stencil_3d_top', 'dxf', replacements)
self.move_output(tmp, 'topStencil.scad', 'stencil_3d_top', 'scad', replacements, patch=True)
# Bottom side
if do_bottom:
self.move_output(tmp, 'bottomStencil.stl', 'Stencil_For_Jig_bottom', 'stl')
self.move_output(tmp, 'bottomStencil.stl', 'stencil_3d_bottom', 'stl')
if self.include_scad:
self.move_output(tmp, prj_name+'-PasteBottom.dxf', 'Stencil_For_Jig_bottom', 'dxf', replacements)
self.move_output(tmp, 'bottomStencil.scad', 'Stencil_For_Jig_bottom', 'scad', replacements, patch=True)
self.move_output(tmp, prj_name+'-PasteBottom.dxf', 'stencil_3d_bottom', 'dxf', replacements)
self.move_output(tmp, 'bottomStencil.scad', 'stencil_3d_bottom', 'scad', replacements, patch=True)
@output_class

View File

@ -54,8 +54,23 @@ class Stencil_For_Jig_Options(Stencil_Options):
super().__init__()
def get_targets(self, out_dir):
# TODO: auto side is tricky, needs variants applied
return [self._parent.expand_filename(out_dir, self.output)]
do_top, do_bottom = self.solve_sides()
files = []
# Top side
if do_top:
files.append(self.expand_name('stencil_for_jig_top', 'gtp', out_dir))
files.append(self.expand_name('stencil_for_jig_top', 'stl', out_dir))
if self.include_scad:
files.append(self.expand_name('stencil_for_jig_top', 'scad', out_dir))
# Bottom side
if do_bottom:
files.append(self.expand_name('stencil_for_jig_bottom', 'gtp', out_dir))
files.append(self.expand_name('stencil_for_jig_bottom', 'stl', out_dir))
if self.include_scad:
files.append(self.expand_name('stencil_for_jig_bottom', 'scad', out_dir))
if do_top and do_bottom:
files.append(self.expand_name('stencil_for_jig', 'gbrjob', out_dir))
return files
def create_cmd(self, cmd_kikit):
cmd = [cmd_kikit, 'stencil', 'create',