[PcbDraw] Individual margin control
This commit is contained in:
parent
4b0965fc4d
commit
0be6f40053
|
|
@ -2584,7 +2584,12 @@ 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 [mm].
|
||||
- `margin`: [number|dict] Margin around the generated image [mm].
|
||||
* Valid keys:
|
||||
- `bottom`: [number=0] Bottom margin [mm].
|
||||
- `left`: [number=0] Left margin [mm].
|
||||
- `right`: [number=0] Right margin [mm].
|
||||
- `top`: [number=0] Top margin [mm].
|
||||
- `no_drillholes`: [boolean=false] Do not make holes transparent.
|
||||
- `outline_width`: [number=0.15] [0,10] Width of the trace to draw the PCB border [mm].
|
||||
Note this also affects the drill holes.
|
||||
|
|
|
|||
|
|
@ -1362,8 +1362,16 @@ outputs:
|
|||
highlight: []
|
||||
# [list(string)=[]] List of libraries
|
||||
libs: []
|
||||
# [number=0] [0,100] Margin around the generated image [mm]
|
||||
margin: 0
|
||||
# [number|dict] Margin around the generated image [mm]
|
||||
margin:
|
||||
# [number=0] Bottom margin [mm]
|
||||
bottom: 0
|
||||
# [number=0] Left margin [mm]
|
||||
left: 0
|
||||
# [number=0] Right margin [mm]
|
||||
right: 0
|
||||
# [number=0] Top margin [mm]
|
||||
top: 0
|
||||
# [boolean=false] Mirror the board
|
||||
mirror: false
|
||||
# [boolean=false] Do not make holes transparent
|
||||
|
|
|
|||
|
|
@ -244,3 +244,5 @@ index f8990722..17f90185 100644
|
|||
|
||||
- Allow constructing PcbPlotter() using an already loaded board
|
||||
- So we don't load it again
|
||||
|
||||
- Changed the margin to be a tuple, so the user can control the margins individually
|
||||
|
|
|
|||
|
|
@ -505,7 +505,7 @@ 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, compute_bbox: bool=False) -> None:
|
||||
def shrink_svg(svg: etree.ElementTree, margin: tuple, compute_bbox: bool=False) -> None:
|
||||
"""
|
||||
Shrink the SVG canvas to the size of the drawing. Add margin in
|
||||
KiCAD units.
|
||||
|
|
@ -544,10 +544,10 @@ def shrink_svg(svg: etree.ElementTree, margin: int, compute_bbox: bool=False) ->
|
|||
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)
|
||||
bbox[0] -= ki2svg(margin[0])
|
||||
bbox[1] += ki2svg(margin[1])
|
||||
bbox[2] -= ki2svg(margin[2])
|
||||
bbox[3] += ki2svg(margin[3])
|
||||
|
||||
root.attrib["viewBox"] = "{} {} {} {}".format(
|
||||
bbox[0], bbox[2],
|
||||
|
|
@ -1063,7 +1063,7 @@ class PcbPlotter():
|
|||
self.libs: List[str] = [] # Names of available libraries
|
||||
self._libs_path: List[str] = []
|
||||
self.style: Any = {} # Color scheme
|
||||
self.margin: int = 0 # Margin of the resulting document
|
||||
self.margin: tuple = (0, 0, 0, 0) # Margin of the resulting document
|
||||
self.compute_bbox: bool = False # Adjust the bbox using the SVG drawings
|
||||
self.kicad_bb_only_edge: bool = False # Use the PCB edge when asking the BBox to KiCad
|
||||
|
||||
|
|
|
|||
|
|
@ -183,6 +183,21 @@ class PcbDrawRemapComponents(Optionable):
|
|||
raise KiPlotConfigurationError("The component remapping must specify a `ref`, a `lib` and a `comp`")
|
||||
|
||||
|
||||
class PcbDrawMargin(Optionable):
|
||||
""" To adjust each margin """
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
with document:
|
||||
self.left = 0
|
||||
""" Left margin [mm] """
|
||||
self.right = 0
|
||||
""" Right margin [mm] """
|
||||
self.top = 0
|
||||
""" Top margin [mm] """
|
||||
self.bottom = 0
|
||||
""" Bottom margin [mm] """
|
||||
|
||||
|
||||
class PcbDrawOptions(VariantOptions):
|
||||
def __init__(self):
|
||||
with document:
|
||||
|
|
@ -221,8 +236,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 [mm] """
|
||||
self.margin = PcbDrawMargin
|
||||
""" [number|dict] Margin around the generated image [mm] """
|
||||
self.outline_width = 0.15
|
||||
""" [0,10] Width of the trace to draw the PCB border [mm].
|
||||
Note this also affects the drill holes """
|
||||
|
|
@ -259,6 +274,15 @@ class PcbDrawOptions(VariantOptions):
|
|||
# Highlight
|
||||
if isinstance(self.highlight, type):
|
||||
self.highlight = None
|
||||
# Margin
|
||||
if isinstance(self.margin, type):
|
||||
self.margin = (0, 0, 0, 0)
|
||||
elif isinstance(self.margin, PcbDrawMargin):
|
||||
self.margin = (mm2ki(self.margin.left), mm2ki(self.margin.right),
|
||||
mm2ki(self.margin.top), mm2ki(self.margin.bottom))
|
||||
else:
|
||||
margin = mm2ki(self.margin)
|
||||
self.margin = (margin, margin, margin, margin)
|
||||
# Filter
|
||||
if isinstance(self.show_components, type):
|
||||
self.show_components = None
|
||||
|
|
@ -388,7 +412,7 @@ class PcbDrawOptions(VariantOptions):
|
|||
plotter.libs = self.libs
|
||||
plotter.render_back = self.bottom
|
||||
plotter.mirror = self.mirror
|
||||
plotter.margin = mm2ki(self.margin)
|
||||
plotter.margin = self.margin
|
||||
if self.style:
|
||||
if isinstance(self.style, str):
|
||||
plotter.resolve_style(self.style)
|
||||
|
|
|
|||
|
|
@ -51,7 +51,11 @@ outputs:
|
|||
vcuts: True
|
||||
warnings: visible
|
||||
dpi: 600
|
||||
# margin: 2
|
||||
# margin:
|
||||
# left: 5
|
||||
# right: 1
|
||||
# top: 0
|
||||
# bottom: 6
|
||||
# outline_width: 3
|
||||
# show_solderpaste: false
|
||||
resistor_remap:
|
||||
|
|
|
|||
Loading…
Reference in New Issue