diff --git a/README.md b/README.md index 161e512f..254ad935 100644 --- a/README.md +++ b/README.md @@ -2060,10 +2060,16 @@ Notes: * Valid keys: - **`output`**: [string='%f-%i%I%v.%x'] Filename for the output (%i=gencad, %x=cad). Affected by global options. - `aux_origin`: [boolean=false] Use auxiliary axis as origin. + - `dnf_filter`: [string|list(string)='_none'] Name of the filter to mark components as not fitted. + A short-cut to use for simple cases where a variant is an overkill. - `flip_bottom_padstacks`: [boolean=false] Flip bottom footprint padstacks. - `no_reuse_shapes`: [boolean=false] Generate a new shape for each footprint instance (Do not reuse shapes). + - `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. - `save_origin`: [boolean=false] Save the origin coordinates in the file. - `unique_pin_names`: [boolean=false] Generate unique pin names. + - `variant`: [string=''] Board variant to apply. + Used for sub-PCBs. - `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. - `disable_run_by_default`: [string|boolean] Use it to disable the `run_by_default` status of other output. diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index bf5b9f2d..8766f5fb 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -735,16 +735,25 @@ outputs: options: # [boolean=false] Use auxiliary axis as origin aux_origin: false + # [string|list(string)='_none'] Name of the filter to mark components as not fitted. + # A short-cut to use for simple cases where a variant is an overkill + dnf_filter: '_none' # [boolean=false] Flip bottom footprint padstacks flip_bottom_padstacks: false # [boolean=false] Generate a new shape for each footprint instance (Do not reuse shapes) no_reuse_shapes: false # [string='%f-%i%I%v.%x'] Filename for the output (%i=gencad, %x=cad). Affected by global options output: '%f-%i%I%v.%x' + # [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] Save the origin coordinates in the file save_origin: false # [boolean=false] Generate unique pin names unique_pin_names: false + # [string=''] Board variant to apply. + # Used for sub-PCBs + variant: '' # Gerber drill format: # You can create a map file for documentation purposes. # This output is what you get from the 'File/Fabrication output/Drill Files' menu in pcbnew. diff --git a/kibot/out_base.py b/kibot/out_base.py index b16217da..01d1f388 100644 --- a/kibot/out_base.py +++ b/kibot/out_base.py @@ -861,6 +861,20 @@ class VariantOptions(BaseOptions): GS.copy_project(fname) return fname + def save_tmp_board_if_variant(self, to_remove, new_title='', dir=None, do_3D=False): + """ If we have a variant apply it and save the PCB to a file """ + if not self.will_filter_pcb_components() and not new_title: + return GS.pcb_file + logger.debug('Creating modified PCB') + self.filter_pcb_components(GS.board, do_3D=do_3D) + self.set_title(new_title) + fname = self.save_tmp_board() + self.restore_title() + self.unfilter_pcb_components(GS.board, do_3D=do_3D) + to_remove.extend(GS.get_pcb_and_pro_names(fname)) + logger.debug('- Modified PCB: '+fname) + return fname + @staticmethod def save_tmp_dir_board(id, force_dir=None): """ Save the PCB to a temporal dir. diff --git a/kibot/out_gencad.py b/kibot/out_gencad.py index f4964619..9b4cf078 100644 --- a/kibot/out_gencad.py +++ b/kibot/out_gencad.py @@ -11,7 +11,7 @@ Dependencies: """ import os from .gs import GS -from .optionable import BaseOptions +from .out_base import VariantOptions from .misc import FAILED_EXECUTE from .kiplot import exec_with_retry, add_extra_options from .macros import macros, document, output_class # noqa: F401 @@ -20,7 +20,7 @@ from . import log logger = log.get_logger() -class GenCADOptions(BaseOptions): +class GenCADOptions(VariantOptions): def __init__(self): with document: self.output = GS.def_global_output @@ -38,12 +38,16 @@ class GenCADOptions(BaseOptions): super().__init__() self._expand_id = 'gencad' self._expand_ext = 'cad' + self.help_only_sub_pcbs() def get_targets(self, out_dir): return [self._parent.expand_filename(out_dir, self.output)] def run(self, name): command = self.ensure_tool('KiAuto') + super().run(name) + to_remove = [] + board_name = self.save_tmp_board_if_variant(to_remove) # Output file name cmd = [command, 'export_gencad', '--output_name', os.path.basename(name)] if self.flip_bottom_padstacks: @@ -56,17 +60,18 @@ class GenCADOptions(BaseOptions): cmd.append('--aux_origin') if self.save_origin: cmd.append('--save_origin') - cmd.extend([GS.pcb_file, os.path.dirname(name)]) + cmd.extend([board_name, os.path.dirname(name)]) cmd, video_remove = add_extra_options(cmd) + if video_remove: + to_remove.append(os.path.join(self.expand_filename_pcb(GS.out_dir), 'pcbnew_export_gencad_screencast.ogv')) # Execute it ret = exec_with_retry(cmd) if ret: logger.error(command+' returned %d', ret) exit(FAILED_EXECUTE) - if video_remove: - video_name = os.path.join(self.expand_filename_pcb(GS.out_dir), 'pcbnew_export_gencad_screencast.ogv') - if os.path.isfile(video_name): - os.remove(video_name) + for f in to_remove: + if os.path.isfile(f): + os.remove(f) @output_class diff --git a/tests/yaml_samples/gencad_sub_pcb_bp.kibot.yaml b/tests/yaml_samples/gencad_sub_pcb_bp.kibot.yaml new file mode 100644 index 00000000..1113d5ca --- /dev/null +++ b/tests/yaml_samples/gencad_sub_pcb_bp.kibot.yaml @@ -0,0 +1,15 @@ +# Example KiBot config file +kibot: + version: 1 + +import: + - file: battery_pack_sub_pcbs.kibot.yaml + +outputs: + - name: 'GENCAD export Test' + comment: "Example of GENCAD export" + type: gencad + options: + flip_bottom_padstacks: true + no_reuse_shapes: true + save_origin: true