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