From ba5164ffa42b6aa3b93a8845c1965481b6c47fd8 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Wed, 7 Sep 2022 09:46:57 -0300 Subject: [PATCH] [PCB Print] Added option to move the page number to the extension - page_number_as_extension - Can be used to easily create custom output names Related to #283 --- CHANGELOG.md | 2 ++ README.md | 4 +++- docs/samples/generic_plot.kibot.yaml | 5 ++++- kibot/out_pcb_print.py | 23 ++++++++++++++++------- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86228b37..a1f75659 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - PCB Print: - Option to configure the forced edge color. (#281) - Option to control the resolution (DPI). (See #259) + - Option to move the page number to the extension (page_number_as_extension) + (See #283) ### Fixed - OAR computation (Report) (#225) diff --git a/README.md b/README.md index 13d4292e..024cb719 100644 --- a/README.md +++ b/README.md @@ -2187,7 +2187,8 @@ Notes: - **`force_edge_cuts`**: [boolean=false] Add the `Edge.Cuts` to all the pages. - **`format`**: [string='PDF'] [PDF,SVG,PNG,EPS,PS] Format for the output file/s. Note that for PS you need `ghostscript` which isn't part of the default docker images. - - **`output`**: [string='%f-%i%I%v.%x'] Filename for the output (%i=assembly, %x=pdf/ps)/(%i=assembly_page_NN, %x=svg/png/eps). Affected by global options. + - **`output`**: [string='%f-%i%I%v.%x'] Filename for the output (%i=assembly, %x=pdf/ps)/(%i=assembly_page_NN, %x=svg/png/eps). + Consult the `page_number_as_extension`. Affected by global options. - *output_name*: Alias for output. - **`pages`**: [list(dict)] List of pages to include in the output document. Each page contains one or more layers of the PCB. @@ -2242,6 +2243,7 @@ Notes: - `keep_temporal_files`: [boolean=false] Store the temporal page and layer files in the output dir and don't delete them. - `micro_via_color`: [string=''] Color used for micro `colored_vias`. - `pad_color`: [string=''] Color used for `colored_pads`. + - `page_number_as_extension`: [boolean=false] When enabled the %i is always `assembly`, the %x will be NN.FORMAT (i.e. 01.png). - `png_width`: [number=1280] [0,7680] Width of the PNG in pixels. Use 0 to use as many pixels as the DPI needs for the page size. - `realistic_solder_mask`: [boolean=true] Try to draw the solder mask as a real solder mask, not the negative used for fabrication. In order to get a good looking select a color with transparency, i.e. '#14332440'. diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index 0c2ee235..6651f910 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -1114,11 +1114,14 @@ outputs: keep_temporal_files: false # [string=''] Color used for micro `colored_vias` micro_via_color: '' - # [string='%f-%i%I%v.%x'] Filename for the output (%i=assembly, %x=pdf/ps)/(%i=assembly_page_NN, %x=svg/png/eps). Affected by global options + # [string='%f-%i%I%v.%x'] Filename for the output (%i=assembly, %x=pdf/ps)/(%i=assembly_page_NN, %x=svg/png/eps). + # Consult the `page_number_as_extension`. Affected by global options output: '%f-%i%I%v.%x' # `output_name` is an alias for `output` # [string=''] Color used for `colored_pads` pad_color: '' + # [boolean=false] When enabled the %i is always `assembly`, the %x will be NN.FORMAT (i.e. 01.png) + page_number_as_extension: false # [list(dict)] List of pages to include in the output document. # Each page contains one or more layers of the PCB pages: diff --git a/kibot/out_pcb_print.py b/kibot/out_pcb_print.py index e053a4dc..6d28ad03 100644 --- a/kibot/out_pcb_print.py +++ b/kibot/out_pcb_print.py @@ -220,7 +220,10 @@ class PCB_PrintOptions(VariantOptions): self.output_name = None """ {output} """ self.output = GS.def_global_output - """ *Filename for the output (%i=assembly, %x=pdf/ps)/(%i=assembly_page_NN, %x=svg/png/eps)""" + """ *Filename for the output (%i=assembly, %x=pdf/ps)/(%i=assembly_page_NN, %x=svg/png/eps). + Consult the `page_number_as_extension` """ + self.page_number_as_extension = False + """ When enabled the %i is always `assembly`, the %x will be NN.FORMAT (i.e. 01.png) """ self.hide_excluded = False """ Hide components in the Fab layer that are marked as excluded by a variant """ self.color_theme = '_builtin_classic' @@ -348,12 +351,18 @@ class PCB_PrintOptions(VariantOptions): if self.hide_excluded: self.restore_fab(GS.board, comps_hash) + def get_id_and_ext(self, n=None): + pn_str = '%02d' % (n+1) if n is not None else '%02d' + if self.page_number_as_extension: + return self._expand_id, pn_str+'.'+self._expand_ext + return self._expand_id+'_page_'+pn_str, self._expand_ext + def get_targets(self, out_dir): if self.format in ['SVG', 'PNG', 'EPS']: files = [] for n in range(len(self.pages)): - id = self._expand_id+('_page_%02d' % (n+1)) - files.append(self.expand_filename(out_dir, self.output, id, self._expand_ext)) + id, ext = self.get_id_and_ext(n) + files.append(self.expand_filename(out_dir, self.output, id, ext)) return files return [self._parent.expand_filename(out_dir, self.output)] @@ -1016,8 +1025,8 @@ class PCB_PrintOptions(VariantOptions): filelist.append((GS.pcb_basename+"-frame.svg", color)) # 3) Stack all layers in one file if self.format == 'SVG': - id = self._expand_id+('_page_'+page_str) - assembly_file = self.expand_filename(output_dir, self.output, id, self._expand_ext) + id, ext = self.get_id_and_ext(n) + assembly_file = self.expand_filename(output_dir, self.output, id, ext) else: assembly_file = GS.pcb_basename+".svg" logger.debug('- Merging layers to {}'.format(assembly_file)) @@ -1039,8 +1048,8 @@ class PCB_PrintOptions(VariantOptions): # Use GS to create one PS self.pdf_to_ps(pdf_file, output) else: # EPS and PNG - id = self._expand_id+('_page_%02d') - out_file = self.expand_filename(output_dir, self.output, id, self._expand_ext, make_safe=False) + id, ext = self.get_id_and_ext() + out_file = self.expand_filename(output_dir, self.output, id, ext, make_safe=False) if self.format == 'EPS': # Use GS to create one EPS per page self.pdf_to_eps(pdf_file, out_file)