From 087b1aabe32d1853385078ffdff5e584f4afa6f8 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Tue, 18 Oct 2022 13:16:43 -0300 Subject: [PATCH] [PcbDraw] Added resistor remap and flip options --- CHANGELOG.md | 1 + README.md | 7 ++++ docs/samples/generic_plot.kibot.yaml | 10 ++++++ kibot/out_pcbdraw.py | 46 +++++++++++++++++++++------ tests/yaml_samples/pcbdraw.kibot.yaml | 6 ++++ 5 files changed, 60 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 462c9f24..729ef862 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Outline width - Solder paste removal - V-CUTS layer + - Resistor remap and flip ### Changed - Diff: diff --git a/README.md b/README.md index 0ff564de..0c691e5e 100644 --- a/README.md +++ b/README.md @@ -2589,6 +2589,13 @@ Notes: - `pre_transform`: [string|list(string)='_none'] Name of the filter to transform fields before applying other filters. A short-cut to use for simple cases where a variant is an overkill. - `remap`: [dict|None] Replacements for PCB references using components (lib:component). + - `resistor_flip`: [string|list(string)=''] List of resistors to flip its bands. + - `resistor_remap`: [list(dict)] List of resitors to be remapped. You can change the value of the resistors here. + * Valid keys: + - **`ref`**: [string=''] Reference for the resistor to change. + - *reference*: Alias for ref. + - **`val`**: [string=''] Value to use for `ref`. + - *value*: Alias for val. - `show_solderpaste`: [boolean=true] Show the solder paste layers. - `variant`: [string=''] Board variant to apply. - `vcuts`: [boolean=false] Render V-CUTS on the `vcuts_layer` layer. diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index 11c4a42c..dd396651 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -1380,6 +1380,16 @@ outputs: pre_transform: '_none' # [dict|None] Replacements for PCB references using components (lib:component) remap: + # [string|list(string)=''] List of resistors to flip its bands + resistor_flip: '' + # [list(dict)] List of resitors to be remapped. You can change the value of the resistors here + resistor_remap: + # [string=''] Reference for the resistor to change + - ref: '' + # `reference` is an alias for `ref` + # [string=''] Value to use for `ref` + val: '' + # `value` is an alias for `val` # [list(string)|string=none] [none,all] List of components to draw, can be also a string for none or all. # The default is none. IMPORTANT! This option is relevant only when no filters or variants are applied show_components: none diff --git a/kibot/out_pcbdraw.py b/kibot/out_pcbdraw.py index 989c6618..f4b9ee82 100644 --- a/kibot/out_pcbdraw.py +++ b/kibot/out_pcbdraw.py @@ -25,7 +25,8 @@ from .optionable import Optionable from .out_base import VariantOptions from .macros import macros, document, output_class # noqa: F401 from . import log -from .PcbDraw.plot import (PcbPlotter, PlotPaste, PlotPlaceholders, PlotSubstrate, PlotVCuts, mm2ki, PlotComponents) +from .PcbDraw.plot import (PcbPlotter, PlotPaste, PlotPlaceholders, PlotSubstrate, PlotVCuts, mm2ki, PlotComponents, + ResistorValue) from .PcbDraw.convert import save @@ -130,6 +131,26 @@ class PcbDrawRemap(Optionable): pass +class PcbDrawResistorRemap(Optionable): + """ Reference -> New value """ + def __init__(self): + super().__init__() + with document: + self.ref = '' + """ *Reference for the resistor to change """ + self.reference = None + """ {ref} """ + self.val = '' + """ *Value to use for `ref` """ + self.value = None + """ {val} """ + + def config(self, parent): + super().config(parent) + if not self.ref or not self.val: + raise KiPlotConfigurationError("The resistors remapping must specify a `ref` and a `val`") + + class PcbDrawOptions(VariantOptions): def __init__(self): with document: @@ -171,6 +192,10 @@ class PcbDrawOptions(VariantOptions): Note this also affects the drill holes """ self.show_solderpaste = True """ Show the solder paste layers """ + self.resistor_remap = PcbDrawResistorRemap + """ [list(dict)] List of resitors to be remapped. You can change the value of the resistors here """ + self.resistor_flip = Optionable + """ [string|list(string)=''] List of resistors to flip its bands """ super().__init__() def config(self, parent): @@ -201,7 +226,10 @@ class PcbDrawOptions(VariantOptions): self.show_components = None else: self.show_components = [] - + # Resistors remap/flip + if isinstance(self.resistor_remap, type): + self.resistor_remap = [] + self.resistor_flip = Optionable.force_list(self.resistor_flip) # Remap # TODO: Better remap option, like - ref: xxx\nlib: xxxx\ncomponent: xxxx if isinstance(self.remap, type): @@ -263,14 +291,12 @@ class PcbDrawOptions(VariantOptions): return lib, name resistor_values = {} - # TODO: Implement resistor_values_input and resistor_flip -# for mapping in resistor_values_input: -# key, value = tuple(mapping.split(":")) -# resistor_values[key] = ResistorValue(value=value) -# for ref in resistor_flip: -# field = resistor_values.get(ref, ResistorValue()) -# field.flip_bands = True -# resistor_values[ref] = field + for mapping in self.resistor_remap: + resistor_values[mapping.ref] = ResistorValue(value=mapping.val) + for ref in self.resistor_flip: + field = resistor_values.get(ref, ResistorValue()) + field.flip_bands = True + resistor_values[ref] = field plot_components = PlotComponents(remapping=remapping_fun, resistor_values=resistor_values, diff --git a/tests/yaml_samples/pcbdraw.kibot.yaml b/tests/yaml_samples/pcbdraw.kibot.yaml index e0f16b49..4c573223 100644 --- a/tests/yaml_samples/pcbdraw.kibot.yaml +++ b/tests/yaml_samples/pcbdraw.kibot.yaml @@ -49,6 +49,12 @@ outputs: # margin: 2 # outline_width: 3 # show_solderpaste: false + resistor_remap: + - ref: R1 + val: 10K + - ref: R2 + val: 4k7 + resistor_flip: "R2" - name: PcbDraw2 comment: "PcbDraw test bottom"