From 510279a0a3d673057f5982bd2cd4018c616b3f9b Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Mon, 11 Apr 2022 12:40:39 -0300 Subject: [PATCH] Added support for frame to `pcb_print` on KiCad 5 - This is tricky because plot API doesn't support it. So we use `pcbnew_do` to generate an SVG and then we make a vectorized PDF from it. --- README.md | 2 + docs/samples/generic_plot.kibot.yaml | 8 +- kibot/kicad/patch_svg.py | 28 +++++++ kibot/out_pcb_print.py | 104 ++++++++++++++++++++---- kibot/out_svg_pcb_print.py | 12 +-- tests/yaml_samples/pcb_print.kibot.yaml | 5 +- 6 files changed, 130 insertions(+), 29 deletions(-) create mode 100644 kibot/kicad/patch_svg.py diff --git a/README.md b/README.md index 5d3e9726..db4996c0 100644 --- a/README.md +++ b/README.md @@ -1542,6 +1542,7 @@ Next time you need this list just use an alias, like this: - `pages`: [list(dict)] List of pages to include in the output document. Each page contains one or more layers of the PCB. * Valid keys: + - `black_holes`: [boolean=true] Change the drill holes to be black instead of white. - `exclude_pads_from_silkscreen`: [boolean=false] Do not plot the component pads in the silk screen (KiCad 5.x only). - `layers`: [list(dict)] List of layers printed in this page. Order is important, the last goes on top. * Valid keys: @@ -1559,6 +1560,7 @@ Next time you need this list just use an alias, like this: - `scaling`: [number=1.0] Scale factor (0 means autoscaling). - `sheet`: [string='Assembly'] Text to use for the `sheet` in the title block. - `sheet_reference_color`: [string=''] Color to use for the frame and title block. + - `sort_layers`: [boolean=false] Try to sort the layers in the same order that uses KiCad for printing. - `tent_vias`: [boolean=true] Cover the vias. - `title`: [string=''] Text used to replace the sheet title. %VALUE expansions are allowed. If it starts with `+` the text is concatenated. diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index 0bc90dac..07c9e090 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -974,8 +974,10 @@ outputs: # [list(dict)] List of pages to include in the output document. # Each page contains one or more layers of the PCB pages: - # [boolean=false] Do not plot the component pads in the silk screen (KiCad 5.x only) - - exclude_pads_from_silkscreen: false + # [boolean=true] Change the drill holes to be black instead of white + - black_holes: true + # [boolean=false] Do not plot the component pads in the silk screen (KiCad 5.x only) + exclude_pads_from_silkscreen: false # [list(dict)] List of layers printed in this page. Order is important, the last goes on top layers: # [string=''] Color used for this layer @@ -1006,6 +1008,8 @@ outputs: sheet: 'Assembly' # [string=''] Color to use for the frame and title block sheet_reference_color: '' + # [boolean=false] Try to sort the layers in the same order that uses KiCad for printing + sort_layers: false # [boolean=true] Cover the vias tent_vias: true # [string=''] Text used to replace the sheet title. %VALUE expansions are allowed. diff --git a/kibot/kicad/patch_svg.py b/kibot/kicad/patch_svg.py new file mode 100644 index 00000000..5e533431 --- /dev/null +++ b/kibot/kicad/patch_svg.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2022 Salvador E. Tropea +# Copyright (c) 2022 Instituto Nacional de TecnologĂ­a Industrial +# License: GPL-3.0 +# Project: KiBot (formerly KiPlot) +# Note about the size: +# A4 landscape 841.889764 x 595.275591 pt = 297 x 210 mm +# 1 pt = 4/3*px 1 px = 1"/96 => 1 pt = 4/3 * 1"/96 = 4"/288 = 1"/72 (72 dpi) +# 1" = 25.4 mm => 1 pt = 25.4/72 mm = 0.3527777778 mm +import re +from .. import log + +logger = log.get_logger() + + +def patch_svg_file(file, remove_bkg=False): + logger.debug('Patching SVG file `{}`'.format(file)) + with open(file, 'rt') as f: + text = f.read() + text = re.sub(r'', '', text) + else: + text = re.sub(r'