[PcbDraw] Added support for image margin
This commit is contained in:
parent
801f7f5183
commit
00cea42cda
|
|
@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Diff:
|
||||
- Option to compare only the first schematic page. (See #319)
|
||||
- PcbDraw:
|
||||
- Support for BMP output
|
||||
- BMP output format
|
||||
- Image margin
|
||||
|
||||
### Changed
|
||||
- Diff:
|
||||
|
|
|
|||
|
|
@ -2581,6 +2581,7 @@ Notes:
|
|||
- `dpi`: [number=300] [10,1200] Dots per inch (resolution) of the generated image.
|
||||
- `highlight`: [list(string)=[]] List of components to highlight.
|
||||
- `libs`: [list(string)=[]] List of libraries.
|
||||
- `margin`: [number=0] [0,100] Margin around the generated image in millimeters.
|
||||
- `no_drillholes`: [boolean=false] Do not make holes transparent.
|
||||
- `placeholder`: [boolean=false] Show placeholder for missing components.
|
||||
- `pre_transform`: [string|list(string)='_none'] Name of the filter to transform fields before applying other filters.
|
||||
|
|
|
|||
|
|
@ -1362,6 +1362,8 @@ outputs:
|
|||
highlight: []
|
||||
# [list(string)=[]] List of libraries
|
||||
libs: []
|
||||
# [number=0] [0,100] Margin around the generated image in millimeters
|
||||
margin: 0
|
||||
# [boolean=false] Mirror the board
|
||||
mirror: false
|
||||
# [boolean=false] Do not make holes transparent
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ No current changes
|
|||
- Disabled `shrink_svg`
|
||||
- Changes the old behavior, so this should be optional
|
||||
- Pulls a problematic dependency: svgpathtool
|
||||
- But we keep the margin addition
|
||||
- Changed calls to `ComputeBoundingBox()` to use `aBoardEdgesOnly=True`
|
||||
- To get the same behavior as 0.9.0-5
|
||||
- This changes the size of the SVG to the size of the board
|
||||
|
|
|
|||
|
|
@ -506,11 +506,11 @@ def merge_bbox(left: Box, right: Box) -> Box:
|
|||
def hack_is_valid_bbox(box: Any): # type: ignore
|
||||
return all(-1e15 < c < 1e15 for c in box)
|
||||
|
||||
# def shrink_svg(svg: etree.ElementTree, margin: int) -> None:
|
||||
# """
|
||||
# Shrink the SVG canvas to the size of the drawing. Add margin in
|
||||
# KiCAD units.
|
||||
# """
|
||||
def shrink_svg(svg: etree.ElementTree, margin: int) -> None:
|
||||
"""
|
||||
Shrink the SVG canvas to the size of the drawing. Add margin in
|
||||
KiCAD units.
|
||||
"""
|
||||
# # We have to overcome the limitation of different base types between
|
||||
# # PcbDraw and svgpathtools
|
||||
# from xml.etree.ElementTree import fromstring as xmlParse
|
||||
|
|
@ -533,18 +533,23 @@ def hack_is_valid_bbox(box: Any): # type: ignore
|
|||
# continue
|
||||
# bbox = merge_bbox(bbox, box)
|
||||
# bbox = list(bbox)
|
||||
# bbox[0] -= ki2svg(margin)
|
||||
# bbox[1] += ki2svg(margin)
|
||||
# bbox[2] -= ki2svg(margin)
|
||||
# bbox[3] += ki2svg(margin)
|
||||
#
|
||||
# root = svg.getroot()
|
||||
# root.attrib["viewBox"] = "{} {} {} {}".format(
|
||||
# bbox[0], bbox[2],
|
||||
# bbox[1] - bbox[0], bbox[3] - bbox[2]
|
||||
# )
|
||||
# root.attrib["width"] = str(ki2mm(svg2ki(bbox[1] - bbox[0]))) + "mm"
|
||||
# root.attrib["height"] = str(ki2mm(svg2ki(bbox[3] - bbox[2]))) + "mm"
|
||||
# Get the current viewBox
|
||||
root = svg.getroot()
|
||||
x, y, vw, vh = [float(x) for x in root.attrib["viewBox"].split()]
|
||||
bbox = [x, x+vw, y, y+vh]
|
||||
|
||||
# Apply the margin
|
||||
bbox[0] -= ki2svg(margin)
|
||||
bbox[1] += ki2svg(margin)
|
||||
bbox[2] -= ki2svg(margin)
|
||||
bbox[3] += ki2svg(margin)
|
||||
|
||||
root.attrib["viewBox"] = "{} {} {} {}".format(
|
||||
bbox[0], bbox[2],
|
||||
bbox[1] - bbox[0], bbox[3] - bbox[2]
|
||||
)
|
||||
root.attrib["width"] = str(ki2mm(svg2ki(bbox[1] - bbox[0]))) + "mm"
|
||||
root.attrib["height"] = str(ki2mm(svg2ki(bbox[3] - bbox[2]))) + "mm"
|
||||
|
||||
def remove_empty_elems(tree: etree.Element) -> None:
|
||||
"""
|
||||
|
|
@ -1068,7 +1073,7 @@ class PcbPlotter():
|
|||
plotter.render(self)
|
||||
remove_empty_elems(self._document.getroot())
|
||||
remove_inkscape_annotation(self._document.getroot())
|
||||
# shrink_svg(self._document, self.margin)
|
||||
shrink_svg(self._document, self.margin)
|
||||
return self._document
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -161,6 +161,8 @@ class PcbDrawOptions(VariantOptions):
|
|||
""" *[svg,png,jpg,bmp] Output format. Only used if no `output` is specified """
|
||||
self.output = GS.def_global_output
|
||||
""" *Name for the generated file """
|
||||
self.margin = 0
|
||||
""" [0,100] Margin around the generated image in millimeters """
|
||||
super().__init__()
|
||||
|
||||
def config(self, parent):
|
||||
|
|
@ -307,8 +309,7 @@ class PcbDrawOptions(VariantOptions):
|
|||
plotter.libs = self.libs
|
||||
plotter.render_back = self.bottom
|
||||
plotter.mirror = self.mirror
|
||||
# TODO: Allow margin configuration
|
||||
plotter.margin = mm2ki(1.5)
|
||||
plotter.margin = mm2ki(self.margin)
|
||||
# TODO: Pass it directly? If no: remove file?
|
||||
tmp_style = None
|
||||
if self.style:
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ outputs:
|
|||
vcuts: True
|
||||
warnings: visible
|
||||
dpi: 600
|
||||
# margin: 2
|
||||
|
||||
- name: PcbDraw2
|
||||
comment: "PcbDraw test bottom"
|
||||
|
|
|
|||
Loading…
Reference in New Issue