From 499b3520a63a2c249ebae27869e0315cb4c5c4a3 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Thu, 14 Oct 2021 14:07:35 -0300 Subject: [PATCH] Option to hide component from PDF PCB Print - option `hide_excluded` to hide components marked by the `exclude_filter`. - https://forum.kicad.info/t/fab-drawing-for-only-through-hole-parts/ --- CHANGELOG.md | 3 +++ README.md | 1 + docs/samples/generic_plot.kibot.yaml | 2 ++ kibot/out_base.py | 32 ++++++++++++++++++++++++++++ kibot/out_pdf_pcb_print.py | 6 ++++++ 5 files changed, 44 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72b829ef..1c6e7072 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - skip_bottom: bottom components aren't rotated. - XLSX BoM: option to control the logo scale (#84) - Import mechanism for filters and variants (#88) +- PDF PCB Print: option `hide_excluded` to hide components marked by the + `exclude_filter`. + https://forum.kicad.info/t/fab-drawing-for-only-through-hole-parts/ - Internal BoM: option to avoid merging components with empty fields. Is named `merge_both_blank` and defaults to true. - Internal BoM: when a `Value` field can't be interpreted as a `number+unit`, diff --git a/README.md b/README.md index 2e3c2afb..adc94ef2 100644 --- a/README.md +++ b/README.md @@ -1275,6 +1275,7 @@ Next time you need this list just use an alias, like this: - `dnf_filter`: [string|list(string)=''] Name of the filter to mark components as not fitted. A short-cut to use for simple cases where a variant is an overkill. - `drill_marks`: [string='full'] What to use to indicate the drill places, can be none, small or full (for real scale). + - `hide_excluded`: [boolean=false] Hide components in the Fab layer that are marked as excluded by a variant. - `mirror`: [boolean=false] Print mirrored (X axis inverted). ONLY for KiCad 6. - `monochrome`: [boolean=false] Print in black and white. - `output`: [string='%f-%i%v.%x'] Filename for the output PDF (%i=layers, %x=pdf). Affected by global options. diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index 1b1768b8..75909b34 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -879,6 +879,8 @@ outputs: dnf_filter: '' # [string='full'] What to use to indicate the drill places, can be none, small or full (for real scale) drill_marks: 'full' + # [boolean=false] Hide components in the Fab layer that are marked as excluded by a variant + hide_excluded: false # [boolean=false] Print mirrored (X axis inverted). ONLY for KiCad 6 mirror: false # [boolean=false] Print in black and white diff --git a/kibot/out_base.py b/kibot/out_base.py index 7003b310..a7e15562 100644 --- a/kibot/out_base.py +++ b/kibot/out_base.py @@ -286,6 +286,38 @@ class VariantOptions(BaseOptions): for gi in self.old_badhes: gi.SetLayer(self.badhes) + def remove_fab(self, board, comps_hash): + """ Remove from Fab the excluded components. """ + ffab = board.GetLayerID('F.Fab') + bfab = board.GetLayerID('B.Fab') + old_ffab = [] + old_bfab = [] + rescue = board.GetLayerID('Rescue') + for m in board.GetModules(): + ref = m.GetReference() + c = comps_hash.get(ref, None) + if not c.included: + # Remove any graphical item in the *.Fab layers + for gi in m.GraphicalItems(): + l_gi = gi.GetLayer() + if l_gi == ffab: + gi.SetLayer(rescue) + old_ffab.append(gi) + if l_gi == bfab: + gi.SetLayer(rescue) + old_bfab.append(gi) + # Store the data to undo the above actions + self.old_ffab = old_ffab + self.old_bfab = old_bfab + self.ffab = ffab + self.bfab = bfab + + def restore_fab(self, board, comps_hash): + for gi in self.old_ffab: + gi.SetLayer(self.ffab) + for gi in self.old_bfab: + gi.SetLayer(self.bfab) + def run(self, output_dir): """ Makes the list of components available """ if not self.dnf_filter and not self.variant: diff --git a/kibot/out_pdf_pcb_print.py b/kibot/out_pdf_pcb_print.py index 0fc3363c..5106b8dc 100644 --- a/kibot/out_pdf_pcb_print.py +++ b/kibot/out_pdf_pcb_print.py @@ -41,6 +41,8 @@ class PDF_Pcb_PrintOptions(VariantOptions): """ Print layers in separated pages """ self.mirror = False """ Print mirrored (X axis inverted). ONLY for KiCad 6 """ + self.hide_excluded = False + """ Hide components in the Fab layer that are marked as excluded by a variant """ super().__init__() self._expand_ext = 'pdf' @@ -75,6 +77,8 @@ class PDF_Pcb_PrintOptions(VariantOptions): comps_hash = self.get_refs_hash() self.cross_modules(board, comps_hash) self.remove_paste_and_glue(board, comps_hash) + if self.hide_excluded: + self.remove_fab(board, comps_hash) # Save the PCB to a temporal file with NamedTemporaryFile(mode='w', suffix='.kicad_pcb', delete=False) as f: fname = f.name @@ -84,6 +88,8 @@ class PDF_Pcb_PrintOptions(VariantOptions): fproj = self._copy_project(fname) self.uncross_modules(board, comps_hash) self.restore_paste_and_glue(board, comps_hash) + if self.hide_excluded: + self.restore_fab(board, comps_hash) return fname, fproj def get_targets(self, out_dir):