From f49d679b7c0fd01020209d5e9f272dc268f7db71 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Fri, 6 Jan 2023 16:32:58 -0300 Subject: [PATCH] [PCB2Blender_tools][Added] Stackup support --- README.md | 3 ++ docs/samples/generic_plot.kibot.yaml | 6 ++++ kibot/out_pcb2blender_tools.py | 31 +++++++++++++++++++ .../pcb2blender_tools_1.kibot.yaml | 2 ++ 4 files changed, 42 insertions(+) diff --git a/README.md b/README.md index 827038a0..0858a3eb 100644 --- a/README.md +++ b/README.md @@ -3131,6 +3131,9 @@ Notes: - `pads_info_dir`: [string='pads'] Sub-directory where the pads info files are stored. - `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. + - `stackup_create`: [boolean=false] Create a JSON file containing the board stackup. + - `stackup_dir`: [string='.'] Directory for the stackup file. + - `stackup_file`: [string='board.yaml'] Name for the stackup file. - `variant`: [string=''] Board variant to apply. - `category`: [string|list(string)=''] The category for this output. If not specified an internally defined category is used. Categories looks like file system paths, i.e. **PCB/fabrication/gerber**. diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index b27759d4..0889ade3 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -1863,6 +1863,12 @@ 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' + # [boolean=false] Create a JSON file containing the board stackup + stackup_create: false + # [string='.'] Directory for the stackup file + stackup_dir: '.' + # [string='board.yaml'] Name for the stackup file + stackup_file: 'board.yaml' # [string=''] Board variant to apply variant: '' # PCB Print: diff --git a/kibot/out_pcb2blender_tools.py b/kibot/out_pcb2blender_tools.py index bf6b429f..70c56688 100644 --- a/kibot/out_pcb2blender_tools.py +++ b/kibot/out_pcb2blender_tools.py @@ -4,6 +4,7 @@ # License: GPL-3.0 # Project: KiBot (formerly KiPlot) # Some code is adapted from: https://github.com/30350n/pcb2blender +import json import os import struct from pcbnew import B_Paste, F_Paste @@ -32,6 +33,12 @@ class PCB2Blender_ToolsOptions(VariantOptions): """ Create the files containing the PCB pads information """ self.pads_info_dir = 'pads' """ Sub-directory where the pads info files are stored """ + self.stackup_create = False + """ Create a JSON file containing the board stackup """ + self.stackup_file = 'board.yaml' + """ Name for the stackup file """ + self.stackup_dir = '.' + """ Directory for the stackup file """ super().__init__() self._expand_id = 'pcb2blender' self._expand_ext = 'pcb3d' @@ -88,12 +95,36 @@ class PCB2Blender_ToolsOptions(VariantOptions): pad.GetDrillShape(), *map(GS.to_mm, pad.GetDrillSize()))) + def do_stackup(self, dir_name): + if not self.stackup_create or (not GS.global_pcb_finish and not GS.stackup): + return + dir_name = os.path.join(dir_name, self.stackup_dir) + os.makedirs(dir_name, exist_ok=True) + fname = os.path.join(dir_name, self.stackup_file) + # Create the board_info + board_info = {} + if GS.global_pcb_finish: + board_info['copper_finish'] = GS.global_pcb_finish + if GS.stackup: + layers_parsed = [] + for la in GS.stackup: + parsed_layer = {'name': la.name, 'type': la.type} + if la.color is not None: + parsed_layer['color'] = la.color + if la.thickness is not None: + parsed_layer['thickness'] = la.thickness/1000 + layers_parsed.append(parsed_layer) + board_info['stackup'] = layers_parsed + with open(fname, 'wt') as f: + json.dump(board_info, f, indent=3) + def run(self, output): super().run(output) dir_name = os.path.dirname(output) self.filter_pcb_components(do_3D=True) self.do_board_bounds(dir_name) self.do_pads_info(dir_name) + self.do_stackup(dir_name) self.unfilter_pcb_components(do_3D=True) def get_targets(self, out_dir): diff --git a/tests/yaml_samples/pcb2blender_tools_1.kibot.yaml b/tests/yaml_samples/pcb2blender_tools_1.kibot.yaml index b1c29c8b..c60737b5 100644 --- a/tests/yaml_samples/pcb2blender_tools_1.kibot.yaml +++ b/tests/yaml_samples/pcb2blender_tools_1.kibot.yaml @@ -7,3 +7,5 @@ outputs: comment: "PCB to Blender tools test" dir: pcb2blender type: pcb2blender_tools + options: + stackup_create: true