Added holes color configuration to pcb_print

This commit is contained in:
Salvador E. Tropea 2022-04-12 15:53:34 -03:00
parent b7b9b70ac3
commit 460ddc6a59
4 changed files with 21 additions and 13 deletions

View File

@ -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.

View File

@ -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

View File

@ -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)

View File

@ -22,6 +22,7 @@ outputs:
sheet: Front
sheet_reference_color: "#A02020"
# black_holes: false
# holes_color: "#8080FF"
layers:
- layer: Edge.Cuts
- layer: F.Cu