[PcbDraw] Added resistor remap and flip options

This commit is contained in:
Salvador E. Tropea 2022-10-18 13:16:43 -03:00
parent f46f9557fd
commit 087b1aabe3
5 changed files with 60 additions and 10 deletions

View File

@ -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:

View File

@ -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.

View File

@ -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

View File

@ -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,

View File

@ -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"