diff --git a/CHANGELOG.md b/CHANGELOG.md index b9ef7917..efd871f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support for multi-boards as defined by KiKit - iBoM: - `hide_excluded` to hide excluded *.Fab drawings. +- SVG: + - Options to limit the view box to the used area. ### Fixed - PCB_Print: - Images not showing in custom frames. (#352) diff --git a/README.md b/README.md index 22c2e755..ae2192a3 100644 --- a/README.md +++ b/README.md @@ -3300,6 +3300,7 @@ Notes: see `show_components`. - `libs`: [list(string)=[]] List of libraries. - `margin`: [number|dict] Margin around the generated image [mm]. + Using a number the margin is the same in the four directions. * Valid keys: - `bottom`: [number=0] Bottom margin [mm]. - `left`: [number=0] Left margin [mm]. @@ -4145,13 +4146,28 @@ Notes: - `inner_extension_pattern`: [string=''] Used to change the Protel style extensions for inner layers. The replacement pattern can contain %n for the inner layer number and %N for the layer number. Example '.g%n'. + - `limit_viewbox`: [boolean=false] When enabled the view box is limited to a selected area. - `line_width`: [number=0.25] [0.02,2] For objects without width [mm] (KiCad 5). + - `margin`: [number|dict] Margin around the view box [mm]. + Using a number the margin is the same in the four directions. + See `limit_viewbox` option. + * 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]. - `mirror_plot`: [boolean=false] Plot mirrored. - `negative_plot`: [boolean=false] Invert black and white. - `plot_footprint_refs`: [boolean=true] Include the footprint references. - `plot_footprint_values`: [boolean=true] Include the footprint values. - `pre_transform`: [string|list(string)='_none'] Name of the filter to transform fields before applying other filters. A short-cut to use for simple cases where a variant is an overkill. + - `size_detection`: [string='kicad_edge'] [kicad_edge,kicad_all] Method used to detect the size of the view box. + The `kicad_edge` method uses the size of the board as reported by KiCad, + components that extend beyond the PCB limit will be cropped. You can manually + adjust the margin to make them visible. + The `kicad_all` method uses the whole size reported by KiCad. Usually includes extra space. + See `limit_viewbox` option. - `sketch_pad_line_width`: [number=0.1] Line width for the sketched pads [mm], see `sketch_pads_on_fab_layers` (KiCad 6+) Note that this value is currently ignored by KiCad (6.0.9). - `sketch_pads_on_fab_layers`: [boolean=false] Draw only the outline of the pads on the *.Fab layers (KiCad 6+). diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index 29bc4405..8122e499 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -2038,7 +2038,8 @@ outputs: highlight: [] # [list(string)=[]] List of libraries libs: [] - # [number|dict] Margin around the generated image [mm] + # [number|dict] Margin around the generated image [mm]. + # Using a number the margin is the same in the four directions margin: # [number=0] Bottom margin [mm] bottom: 0 @@ -2823,8 +2824,22 @@ outputs: # The replacement pattern can contain %n for the inner layer number and %N for the layer number. # Example '.g%n' inner_extension_pattern: '' + # [boolean=false] When enabled the view box is limited to a selected area + limit_viewbox: false # [number=0.25] [0.02,2] For objects without width [mm] (KiCad 5) line_width: 0.25 + # [number|dict] Margin around the view box [mm]. + # Using a number the margin is the same in the four directions. + # See `limit_viewbox` option + 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] Plot mirrored mirror_plot: false # [boolean=false] Invert black and white @@ -2845,6 +2860,13 @@ outputs: # [string|list(string)='_none'] Name of the filter to transform fields before applying other filters. # A short-cut to use for simple cases where a variant is an overkill pre_transform: '_none' + # [string='kicad_edge'] [kicad_edge,kicad_all] Method used to detect the size of the view box. + # The `kicad_edge` method uses the size of the board as reported by KiCad, + # components that extend beyond the PCB limit will be cropped. You can manually + # adjust the margin to make them visible. + # The `kicad_all` method uses the whole size reported by KiCad. Usually includes extra space. + # See `limit_viewbox` option + size_detection: 'kicad_edge' # [number=0.1] Line width for the sketched pads [mm], see `sketch_pads_on_fab_layers` (KiCad 6+) # Note that this value is currently ignored by KiCad (6.0.9) sketch_pad_line_width: 0.1 diff --git a/kibot/kicad/patch_svg.py b/kibot/kicad/patch_svg.py index dd167f80..033bb722 100644 --- a/kibot/kicad/patch_svg.py +++ b/kibot/kicad/patch_svg.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2022 Salvador E. Tropea -# Copyright (c) 2022 Instituto Nacional de Tecnología Industrial +# Copyright (c) 2022-2023 Salvador E. Tropea +# Copyright (c) 2022-2023 Instituto Nacional de Tecnología Industrial # License: GPL-3.0 # Project: KiBot (formerly KiPlot) # Note about the size: @@ -11,6 +11,10 @@ import re from .. import log logger = log.get_logger() +SVG_VIEW_BOX_REGEX = r'', '', text) elif not is_portrait: @@ -31,3 +34,12 @@ def patch_svg_file(file, remove_bkg=False, is_portrait=False): r'