diff --git a/README.md b/README.md index 66c1a801..63a23f23 100644 --- a/README.md +++ b/README.md @@ -1552,8 +1552,9 @@ Next time you need this list just use an alias, like this: - `pages`: [list(dict)] List of pages to include in the output document. Each page contains one or more layers of the PCB. * Valid keys: - - `black_holes`: [boolean=true] Change the drill holes to be black instead of white. + - `colored_holes`: [boolean=true] Change the drill holes to be colored instead of white. - `exclude_pads_from_silkscreen`: [boolean=false] Do not plot the component pads in the silk screen (KiCad 5.x only). + - `holes_color`: [string='#000000'] Color used for the holes when `colored_holes` is enabled. - `layers`: [list(dict)] List of layers printed in this page. Order is important, the last goes on top. * Valid keys: - `color`: [string=''] Color used for this layer. diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index 5aab4aad..dfc2d226 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -984,10 +984,12 @@ outputs: # [list(dict)] List of pages to include in the output document. # Each page contains one or more layers of the PCB pages: - # [boolean=true] Change the drill holes to be black instead of white - - black_holes: true + # [boolean=true] Change the drill holes to be colored instead of white + - colored_holes: true # [boolean=false] Do not plot the component pads in the silk screen (KiCad 5.x only) exclude_pads_from_silkscreen: false + # [string='#000000'] Color used for the holes when `colored_holes` is enabled + holes_color: '#000000' # [list(dict)] List of layers printed in this page. Order is important, the last goes on top layers: # [string=''] Color used for this layer diff --git a/kibot/out_pcb_print.py b/kibot/out_pcb_print.py index 78e0df54..d570affb 100644 --- a/kibot/out_pcb_print.py +++ b/kibot/out_pcb_print.py @@ -32,7 +32,6 @@ PDF2PS = 'pdf2ps' # - Use PyPDF2 for pdfunite # - Implement pad, vias, etc colors -# - Allow hole color config # - move(1,1)? Really needed? 0,0? # - Analyze KiCad 6 long delay # - Manually draw the frame @@ -72,21 +71,22 @@ def to_gray_hex(color): return '#'+avg_str+avg_str+avg_str -def load_svg(file, color, black_holes, monochrome): +def load_svg(file, color, colored_holes, holes_color, monochrome): with open(file, 'rt') as f: content = f.read() color = color[:7] if monochrome: color = to_gray_hex(color) - if black_holes: + holes_color = to_gray_hex(holes_color) + if colored_holes: content = content.replace('#FFFFFF', '**black_hole**') if color != '#000000': # Files plotted content = content.replace('#000000', color) # Files generated by "Print" content = content.replace('stroke:rgb(0%,0%,0%)', 'stroke:'+color) - if black_holes: - content = content.replace('**black_hole**', '#000000') + if colored_holes: + content = content.replace('**black_hole**', holes_color) return content @@ -106,12 +106,12 @@ def to_inches(w): return val -def merge_svg(input_folder, input_files, output_folder, output_file, black_holes, monochrome): +def merge_svg(input_folder, input_files, output_folder, output_file, colored_holes, holes_color, monochrome): """ Merge all pages into one """ first = True for (file, color) in input_files: file = os.path.join(input_folder, file) - new_layer = fromstring(load_svg(file, color, black_holes, monochrome)) + new_layer = fromstring(load_svg(file, color, colored_holes, holes_color, monochrome)) width = get_width(new_layer) if first: svg_out = new_layer @@ -248,8 +248,10 @@ class PagesOptions(Optionable): """ Do not plot the component pads in the silk screen (KiCad 5.x only) """ self.tent_vias = True """ Cover the vias """ - self.black_holes = True - """ Change the drill holes to be black instead of white """ + self.colored_holes = True + """ Change the drill holes to be colored instead of white """ + self.holes_color = '#000000' + """ Color used for the holes when `colored_holes` is enabled """ self.sort_layers = False """ Try to sort the layers in the same order that uses KiCad for printing """ self.layers = LayerOptions @@ -265,6 +267,8 @@ class PagesOptions(Optionable): self.layers.sort(key=lambda x: get_priority(x._id), reverse=True) if self.sheet_reference_color: self.validate_color('sheet_reference_color') + if self.holes_color: + self.validate_color('holes_color') class PCB_PrintOptions(VariantOptions): @@ -488,7 +492,7 @@ class PCB_PrintOptions(VariantOptions): else: assembly_file = GS.pcb_basename+"-"+str(n+1)+".svg" logger.debug('- Merging layers to {}'.format(assembly_file)) - merge_svg(temp_dir, filelist, temp_dir, assembly_file, p.black_holes, p.monochrome) + merge_svg(temp_dir, filelist, temp_dir, assembly_file, p.colored_holes, p.holes_color, p.monochrome) if self.format in ['PNG', 'EPS']: id = self._expand_id+('_page_%02d' % (n+1)) out_file = self.expand_filename(output_dir, self.output, id, self._expand_ext) diff --git a/tests/yaml_samples/pcb_print.kibot.yaml b/tests/yaml_samples/pcb_print.kibot.yaml index 34121f92..ec145b29 100644 --- a/tests/yaml_samples/pcb_print.kibot.yaml +++ b/tests/yaml_samples/pcb_print.kibot.yaml @@ -22,6 +22,7 @@ outputs: sheet: Front sheet_reference_color: "#A02020" # black_holes: false + # holes_color: "#8080FF" layers: - layer: Edge.Cuts - layer: F.Cu