From 33da0f9e87504e9318c23639e3cd9b690ff004ac Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Sun, 16 Jan 2022 13:24:10 -0300 Subject: [PATCH] Added support for KiCad 6 copper finish option. --- kibot/__main__.py | 10 +++--- kibot/globals.py | 34 ++++++++++++++++++- kibot/misc.py | 6 +++- .../kicad_6/light_control.kicad_pcb | 18 ++++++++++ 4 files changed, 61 insertions(+), 7 deletions(-) diff --git a/kibot/__main__.py b/kibot/__main__.py index 06f5b3df..47f7afa1 100644 --- a/kibot/__main__.py +++ b/kibot/__main__.py @@ -349,6 +349,11 @@ def main(): # Determine the YAML file plot_config = solve_config(args.plot_config) + # Determine the SCH file + GS.set_sch(solve_schematic(args.schematic, args.board_file, plot_config)) + # Determine the PCB file + GS.set_pcb(solve_board_file(GS.sch_file, args.board_file)) + # Read the config file cr = CfgYamlReader() outputs = None @@ -362,11 +367,6 @@ def main(): with open(plot_config) as cf_file: outputs = cr.read(cf_file) - # Determine the SCH file - GS.set_sch(solve_schematic(args.schematic, args.board_file, plot_config)) - # Determine the PCB file - GS.set_pcb(solve_board_file(GS.sch_file, args.board_file)) - # Is just list the available targets? if args.list: list_pre_and_outs(logger, outputs) diff --git a/kibot/globals.py b/kibot/globals.py index aa77840d..70905853 100644 --- a/kibot/globals.py +++ b/kibot/globals.py @@ -9,6 +9,7 @@ from .macros import macros, document # noqa: F401 from .pre_filters import FiltersOptions from .log import get_logger, set_filters from .misc import W_MUSTBEINT +from .kicad.sexpdata import load, SExpData, sexp_iter, Symbol class Globals(FiltersOptions): @@ -50,7 +51,11 @@ class Globals(FiltersOptions): Currently known are black and white """ self.pcb_finish = 'HAL' """ Finishing used to protect pads. Currently used for documentation and to choose default colors. - Currently known are None, HAL, HASL, ENIG and ImAg """ + KiCad 6: you should set this in the Board Setup -> Board Finish -> Copper Finish option. + Currently known are None, HAL, HASL, HAL SnPb, HAL lead-free, ENIG, ENEPIG, Hard gold, ImAg, Immersion Silver, + Immersion Ag, ImAu, Immersion Gold, Immersion Au, Immersion Tin, Immersion Nickel, OSP and HT_OSP """ + self.copper_finish = None + """ {pcb_finish} """ self.set_doc('filters', " [list(dict)] KiBot warnings to be ignored ") self._filter_what = 'KiBot warnings' self._unkown_is_error = True @@ -65,7 +70,34 @@ class Globals(FiltersOptions): return new_val return current + def get_stack_up(self): + logger.debug("Looking for stack-up information in the PCB") + pcb = None + with open(GS.pcb_file, 'rt') as fh: + try: + pcb = load(fh) + except SExpData as e: + # Don't make it an error, will be detected and reported latter + logger.debug("- Failed to load the PCB "+str(e)) + if pcb is None: + return + sp = next(sexp_iter(pcb, 'kicad_pcb/setup/stackup'), None) + if sp is None: + return + logger.debug("- Found stack-up information") + copper_finish = None + for e in sp[1:]: + if isinstance(e, list) and isinstance(e[0], Symbol): + name = e[0].value() + if name == 'copper_finish': + copper_finish = str(e[1]) + logger.debug("- Copper finish: "+copper_finish) + if copper_finish is not None: + self.pcb_finish = copper_finish + def config(self, parent): + if GS.ki6() and GS.pcb_file: + self.get_stack_up() super().config(parent) GS.global_output = self.set_global(GS.global_output, self.output, 'output') GS.global_dir = self.set_global(GS.global_dir, self.dir, 'dir') diff --git a/kibot/misc.py b/kibot/misc.py index f2ecc0b7..46bc5952 100644 --- a/kibot/misc.py +++ b/kibot/misc.py @@ -220,7 +220,11 @@ W_KICOSTFLD = '(W078) ' W_MIXVARIANT = '(W079) ' # Somehow arbitrary, the colors are real, but can be different PCB_MAT_COLORS = {'fr1': "937042", 'fr2': "949d70", 'fr3': "adacb4", 'fr4': "332B16", 'fr5': "6cc290"} -PCB_FINISH_COLORS = {'hal': "8b898c", 'hasl': "8b898c", 'imag': "8b898c", 'enig': "cfb96e", 'none': "d39751"} +PCB_FINISH_COLORS = {'hal': "8b898c", 'hasl': "8b898c", 'imag': "8b898c", 'enig': "cfb96e", 'enepig': "cfb96e", + 'none': "d39751", 'hal snpb': "8b898c", 'hal lead-free': "8b898c", 'hard gold': "cfb96e", + 'immersion silver': "8b898c", 'immersion ag': "8b898c", 'imau': "cfb96e", 'immersion gold': "cfb96e", + 'immersion au': "cfb96e", 'immersion tin': "8b898c", 'immersion nickel': "cfb96e", 'osp': "d39751", + 'ht_osp': "d39751"} SOLDER_COLORS = {'green': ("#285e3a", "#208b47"), 'black': ("#1d1918", "#2d2522"), 'blue': ("#1b1f44", "#00406a"), diff --git a/tests/board_samples/kicad_6/light_control.kicad_pcb b/tests/board_samples/kicad_6/light_control.kicad_pcb index 9223106f..959040a3 100644 --- a/tests/board_samples/kicad_6/light_control.kicad_pcb +++ b/tests/board_samples/kicad_6/light_control.kicad_pcb @@ -36,6 +36,24 @@ ) (setup + (stackup + (layer "F.SilkS" (type "Top Silk Screen")) + (layer "F.Paste" (type "Top Solder Paste")) + (layer "F.Mask" (type "Top Solder Mask") (thickness 0.01)) + (layer "F.Cu" (type "copper") (thickness 0.035)) + (layer "dielectric 1" (type "core") (thickness 0.48) (material "FR4") (epsilon_r 4.5) (loss_tangent 0.02)) + (layer "In1.Cu" (type "copper") (thickness 0.035)) + (layer "dielectric 2" (type "prepreg") (thickness 0.48) (material "FR4") (epsilon_r 4.5) (loss_tangent 0.02)) + (layer "In2.Cu" (type "copper") (thickness 0.035)) + (layer "dielectric 3" (type "core") (thickness 0.48) (material "FR4") (epsilon_r 4.5) (loss_tangent 0.02)) + (layer "B.Cu" (type "copper") (thickness 0.035)) + (layer "B.Mask" (type "Bottom Solder Mask") (thickness 0.01)) + (layer "B.Paste" (type "Bottom Solder Paste")) + (layer "B.SilkS" (type "Bottom Silk Screen")) + (copper_finish "ENIG") + (dielectric_constraints no) + (castellated_pads yes) + ) (pad_to_mask_clearance 0.051) (solder_mask_min_width 0.25) (aux_axis_origin 102 102)