[PcbDraw] A `remap_components` option with better type checks
- The old option was simpler, but you could put anything there
This commit is contained in:
parent
087b1aabe3
commit
97dd675a6d
|
|
@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Solder paste removal
|
||||
- V-CUTS layer
|
||||
- Resistor remap and flip
|
||||
- A `remap_components` option with better type checks
|
||||
|
||||
### Changed
|
||||
- Diff:
|
||||
|
|
|
|||
12
README.md
12
README.md
|
|
@ -2588,7 +2588,17 @@ Notes:
|
|||
- `placeholder`: [boolean=false] Show placeholder for missing components.
|
||||
- `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).
|
||||
- `remap`: [dict|None] (DEPRECATED) Replacements for PCB references using specified components (lib:component).
|
||||
Use `remap_components` instead.
|
||||
- `remap_components`: [list(dict)] Replacements for PCB references using specified components.
|
||||
Replaces `remap` with type check.
|
||||
* Valid keys:
|
||||
- **`comp`**: [string=''] Component to use (from `lib`).
|
||||
- *component*: Alias for comp.
|
||||
- **`lib`**: [string=''] Library to use.
|
||||
- *library*: Alias for lib.
|
||||
- **`ref`**: [string=''] Reference for the component to change.
|
||||
- *reference*: Alias for ref.
|
||||
- `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:
|
||||
|
|
|
|||
|
|
@ -1378,8 +1378,21 @@ outputs:
|
|||
# [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
|
||||
pre_transform: '_none'
|
||||
# [dict|None] Replacements for PCB references using components (lib:component)
|
||||
# [dict|None] (DEPRECATED) Replacements for PCB references using specified components (lib:component).
|
||||
# Use `remap_components` instead
|
||||
remap:
|
||||
# [list(dict)] Replacements for PCB references using specified components.
|
||||
# Replaces `remap` with type check
|
||||
remap_components:
|
||||
# [string=''] Component to use (from `lib`)
|
||||
- comp: ''
|
||||
# `component` is an alias for `comp`
|
||||
# [string=''] Library to use
|
||||
lib: ''
|
||||
# `library` is an alias for `lib`
|
||||
# [string=''] Reference for the component to change
|
||||
ref: ''
|
||||
# `reference` is an alias for `ref`
|
||||
# [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
|
||||
|
|
|
|||
|
|
@ -151,6 +151,30 @@ class PcbDrawResistorRemap(Optionable):
|
|||
raise KiPlotConfigurationError("The resistors remapping must specify a `ref` and a `val`")
|
||||
|
||||
|
||||
class PcbDrawRemapComponents(Optionable):
|
||||
""" Reference -> Library + Footprint """
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
with document:
|
||||
self.ref = ''
|
||||
""" *Reference for the component to change """
|
||||
self.reference = None
|
||||
""" {ref} """
|
||||
self.lib = ''
|
||||
""" *Library to use """
|
||||
self.library = None
|
||||
""" {lib} """
|
||||
self.comp = ''
|
||||
""" *Component to use (from `lib`) """
|
||||
self.component = None
|
||||
""" {comp} """
|
||||
|
||||
def config(self, parent):
|
||||
super().config(parent)
|
||||
if not self.ref or not self.lib or not self.comp:
|
||||
raise KiPlotConfigurationError("The component remapping must specify a `ref`, a `lib` and a `comp`")
|
||||
|
||||
|
||||
class PcbDrawOptions(VariantOptions):
|
||||
def __init__(self):
|
||||
with document:
|
||||
|
|
@ -161,7 +185,11 @@ class PcbDrawOptions(VariantOptions):
|
|||
self.placeholder = False
|
||||
""" Show placeholder for missing components """
|
||||
self.remap = PcbDrawRemap
|
||||
""" [dict|None] Replacements for PCB references using components (lib:component) """
|
||||
""" [dict|None] (DEPRECATED) Replacements for PCB references using specified components (lib:component).
|
||||
Use `remap_components` instead """
|
||||
self.remap_components = PcbDrawRemapComponents
|
||||
""" [list(dict)] Replacements for PCB references using specified components.
|
||||
Replaces `remap` with type check """
|
||||
self.no_drillholes = False
|
||||
""" Do not make holes transparent """
|
||||
self.bottom = False
|
||||
|
|
@ -231,20 +259,19 @@ class PcbDrawOptions(VariantOptions):
|
|||
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):
|
||||
self.remap = {}
|
||||
elif isinstance(self.remap, PcbDrawRemap):
|
||||
parsed_remap = {}
|
||||
self._remap = {}
|
||||
if isinstance(self.remap, PcbDrawRemap):
|
||||
for ref, v in self.remap._tree.items():
|
||||
if not isinstance(v, str):
|
||||
raise KiPlotConfigurationError("Wrong PcbDraw remap, must be `ref: lib:component` ({}: {})".format(ref, v))
|
||||
lib_comp = v.split(':')
|
||||
if len(lib_comp) == 2:
|
||||
parsed_remap[ref] = lib_comp
|
||||
self._remap[ref] = tuple(lib_comp)
|
||||
else:
|
||||
raise KiPlotConfigurationError("Wrong PcbDraw remap, must be `ref: lib:component` ({}: {})".format(ref, v))
|
||||
self.remap = parsed_remap
|
||||
if isinstance(self.remap_components, list):
|
||||
for mapping in self.remap_components:
|
||||
self._remap[mapping.ref] = (mapping.lib, mapping.comp)
|
||||
# Style
|
||||
if isinstance(self.style, type):
|
||||
# Apply the global defaults
|
||||
|
|
@ -279,7 +306,7 @@ class PcbDrawOptions(VariantOptions):
|
|||
return [self._parent.expand_filename(out_dir, self.output)]
|
||||
|
||||
def build_plot_components(self):
|
||||
remapping = self.remap
|
||||
remapping = self._remap
|
||||
|
||||
def remapping_fun(ref, lib, name):
|
||||
if ref in remapping:
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ outputs:
|
|||
L_G1: "LEDs:LED-5MM_green"
|
||||
L_B1: "LEDs:LED-5MM_blue"
|
||||
L_Y1: "LEDs:LED-5MM_yellow"
|
||||
PHOTO1: "yaqwsx:R_PHOTO_7mm"
|
||||
J8: "yaqwsx:Pin_Header_Straight_1x02_circle"
|
||||
'REF**': "dummy:dummy"
|
||||
G***: "dummy:dummy"
|
||||
svg2mod: "dummy:dummy"
|
||||
|
|
@ -35,6 +33,13 @@ outputs:
|
|||
JP2: "dummy:dummy"
|
||||
JP3: "dummy:dummy"
|
||||
JP4: "dummy:dummy"
|
||||
remap_components:
|
||||
- ref: PHOTO1
|
||||
lib: yaqwsx
|
||||
comp: R_PHOTO_7mm
|
||||
- reference: J8
|
||||
library: yaqwsx
|
||||
component: Pin_Header_Straight_1x02_circle
|
||||
no_drillholes: False
|
||||
mirror: False
|
||||
highlight:
|
||||
|
|
|
|||
Loading…
Reference in New Issue