Added targets selection, all by default and an --invert-sel option to do all

but named targets.
This commit is contained in:
Salvador E. Tropea 2020-03-16 10:09:04 -03:00
parent a56a847621
commit bcfee6283d
2 changed files with 28 additions and 15 deletions

View File

@ -17,6 +17,8 @@ def main():
parser = argparse.ArgumentParser(
description='Command-line Plotting for KiCad')
parser.add_argument('target', nargs='*',
help='Outputs to generate, default is all')
group = parser.add_mutually_exclusive_group()
group.add_argument('-v', '--verbose', action='store_true',
help='show debugging information')
@ -28,6 +30,8 @@ def main():
help='The plotting config file to use')
parser.add_argument('-d', '--out-dir', default='.',
help='The output directory (cwd if not given)')
parser.add_argument('-i', '--invert-sel', action='store_true',
help='Generate the outputs not listed as targets')
args = parser.parse_args()
@ -60,7 +64,7 @@ def main():
# Set up the plotter and do it
plotter = kiplot.Plotter(cfg)
plotter.plot(args.board_file)
plotter.plot(args.board_file, args.target, args.invert_sel)
if __name__ == "__main__":

View File

@ -37,7 +37,7 @@ class Plotter(object):
def __init__(self, cfg):
self.cfg = cfg
def plot(self, brd_file):
def plot(self, brd_file, target, invert):
logger.debug("Starting plot of board {}".format(brd_file))
@ -47,25 +47,34 @@ class Plotter(object):
self._preflight_checks(board)
n = len(target)
if n == 0 and invert:
# Skip all targets
logger.debug('Skipping all outputs')
return
for op in self.cfg.outputs:
logger.debug("Processing output: {}".format(op.name))
logger.info('- %s (%s) [%s]' % (op.description,op.name,op.options.type))
if (n == 0) or ((op.name in target) ^ invert):
logger.debug("Processing output: {}".format(op.name))
logger.info('- %s (%s) [%s]' % (op.description,op.name,op.options.type))
# fresh plot controller
pc = pcbnew.PLOT_CONTROLLER(board)
# fresh plot controller
pc = pcbnew.PLOT_CONTROLLER(board)
self._configure_output_dir(pc, op)
self._configure_output_dir(pc, op)
if self._output_is_layer(op):
self._do_layer_plot(board, pc, op, brd_file)
elif self._output_is_drill(op):
self._do_drill_plot(board, pc, op)
elif self._output_is_position(op):
self._do_position_plot(board, pc, op)
if self._output_is_layer(op):
self._do_layer_plot(board, pc, op, brd_file)
elif self._output_is_drill(op):
self._do_drill_plot(board, pc, op)
elif self._output_is_position(op):
self._do_position_plot(board, pc, op)
else:
raise PlotError("Don't know how to plot type {}"
.format(op.options.type))
else:
raise PlotError("Don't know how to plot type {}"
.format(op.options.type))
logger.debug('Skipping %s output', op.name)
def _preflight_checks(self, board):