Added pcb_print options to control the background
This commit is contained in:
parent
caad4e346e
commit
857b8b974e
|
|
@ -1703,6 +1703,8 @@ Next time you need this list just use an alias, like this:
|
|||
- `name`: [string=''] Used to identify this particular output definition.
|
||||
- `options`: [dict] Options for the `pcb_print` output.
|
||||
* Valid keys:
|
||||
- `add_background`: [boolean=false] Add a background to the pages, see `background_color`.
|
||||
- `background_color`: [string='#FFFFFF'] Color for the background when `add_background` is enabled.
|
||||
- `blind_via_color`: [string=''] Color used for blind/buried `colored_vias`.
|
||||
- `color_theme`: [string='_builtin_classic'] Selects the color theme. Only applies to KiCad 6.
|
||||
To use the KiCad 6 default colors select `_builtin_default`.
|
||||
|
|
|
|||
|
|
@ -966,6 +966,10 @@ outputs:
|
|||
type: 'pcb_print'
|
||||
dir: 'Example/pcb_print_dir'
|
||||
options:
|
||||
# [boolean=false] Add a background to the pages, see `background_color`
|
||||
add_background: false
|
||||
# [string='#FFFFFF'] Color for the background when `add_background` is enabled
|
||||
background_color: '#FFFFFF'
|
||||
# [string=''] Color used for blind/buried `colored_vias`
|
||||
blind_via_color: ''
|
||||
# [string='_builtin_classic'] Selects the color theme. Only applies to KiCad 6.
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import subprocess
|
|||
from pcbnew import B_Cu, F_Cu, FromMM, IsCopperLayer, PLOT_CONTROLLER, PLOT_FORMAT_SVG, wxSize, F_Mask, B_Mask
|
||||
from shutil import rmtree, which
|
||||
from tempfile import NamedTemporaryFile, mkdtemp
|
||||
from .svgutils.transform import fromstring
|
||||
from .svgutils.transform import fromstring, RectElement
|
||||
from .error import KiPlotConfigurationError
|
||||
from .gs import GS
|
||||
from .optionable import Optionable
|
||||
|
|
@ -93,9 +93,10 @@ def load_svg(file, color, colored_holes, holes_color, monochrome):
|
|||
return content
|
||||
|
||||
|
||||
def get_width(svg):
|
||||
""" Finds the width in viewBox units """
|
||||
return float(svg.root.get('viewBox').split(' ')[2])
|
||||
def get_size(svg):
|
||||
""" Finds the width and height in viewBox units """
|
||||
view_box = svg.root.get('viewBox').split(' ')
|
||||
return float(view_box[2]), float(view_box[3])
|
||||
|
||||
|
||||
def create_pdf_from_pages(input_files, output_fn):
|
||||
|
|
@ -309,7 +310,9 @@ class PCB_PrintOptions(VariantOptions):
|
|||
In order to get a good looking select a color with transparency, i.e. '#14332440'.
|
||||
PcbDraw must be installed in order to use this option """
|
||||
self.add_background = False
|
||||
""" Add a background to the SVG/PNG """
|
||||
""" Add a background to the pages, see `background_color` """
|
||||
self.background_color = '#FFFFFF'
|
||||
""" Color for the background when `add_background` is enabled """
|
||||
super().__init__()
|
||||
self._expand_id = 'assembly'
|
||||
|
||||
|
|
@ -353,6 +356,8 @@ class PCB_PrintOptions(VariantOptions):
|
|||
self.sheet_reference_layout = KiConf.expand_env(self.sheet_reference_layout)
|
||||
if not os.path.isfile(self.sheet_reference_layout):
|
||||
raise KiPlotConfigurationError("Missing page layout file: "+self.sheet_reference_layout)
|
||||
if self.add_background:
|
||||
self.validate_color('background_color')
|
||||
|
||||
def filter_components(self):
|
||||
if not self._comps:
|
||||
|
|
@ -707,7 +712,7 @@ class PCB_PrintOptions(VariantOptions):
|
|||
logger.debug(' - Loading layer file '+file)
|
||||
file = os.path.join(input_folder, file)
|
||||
new_layer = fromstring(load_svg(file, color, p.colored_holes, p.holes_color, p.monochrome))
|
||||
width = get_width(new_layer)
|
||||
width, height = get_size(new_layer)
|
||||
if GS.ki5() and file.endswith('frame.svg'):
|
||||
# Workaround for polygon fill on KiCad 5
|
||||
if p.monochrome:
|
||||
|
|
@ -718,6 +723,8 @@ class PCB_PrintOptions(VariantOptions):
|
|||
# This is the width declared at the beginning of the file
|
||||
base_width = width
|
||||
first = False
|
||||
if self.add_background:
|
||||
svg_out.append(RectElement(0, 0, width, height, color=self.background_color))
|
||||
self.add_frame_images(svg_out, p.monochrome)
|
||||
else:
|
||||
root = new_layer.getroot()
|
||||
|
|
|
|||
|
|
@ -209,6 +209,19 @@ class LineElement(FigureElement):
|
|||
FigureElement.__init__(self, line)
|
||||
|
||||
|
||||
class RectElement(FigureElement):
|
||||
"""Rectangle element.
|
||||
|
||||
Corresponds to SVG ``<rect>`` tag.
|
||||
"""
|
||||
|
||||
def __init__(self, x, y, w, h, color="black"):
|
||||
line = etree.Element(
|
||||
SVG + "rect", {"x": str(x), "y": str(y), "width": str(w), "height": str(h), "fill": color}
|
||||
)
|
||||
FigureElement.__init__(self, line)
|
||||
|
||||
|
||||
class GroupElement(FigureElement):
|
||||
"""Group element.
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ outputs:
|
|||
format: 'PDF'
|
||||
# enable_ki6_frame_fix: true
|
||||
keep_temporal_files: true
|
||||
add_background: true
|
||||
background_color: "#C5C4BF"
|
||||
pages:
|
||||
- # monochrome: true
|
||||
scaling: 2.0
|
||||
|
|
|
|||
Loading…
Reference in New Issue