[PCB_Print][Added] Margins for the autoscale mode.

Closes #337
This commit is contained in:
Salvador E. Tropea 2022-11-25 12:03:43 -03:00
parent 1f8bad0a9b
commit 788aabeeed
4 changed files with 31 additions and 4 deletions

View File

@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- PCB_Print:
- Option to control the *SVG precision* (units scale)
- Now the text in the PDF is searchable. (#331)
- Margins for the autoscale mode. (#337)
- Render_3D:
- Option to render only some components (like in PcbDraw)
- Option to auto-crop the resulting PNG

View File

@ -2478,6 +2478,8 @@ Notes:
- `suffix`: [string=''] Suffix used in file names related to this layer. Derived from the name if not specified.
- **`scaling`**: [number=1.0] Scale factor (0 means autoscaling).
- **`sort_layers`**: [boolean=false] Try to sort the layers in the same order that uses KiCad for printing.
- `autoscale_margin_x`: [number=0] Horizontal margin used for the autoscaling mode [mm].
- `autoscale_margin_y`: [number=0] Vertical margin used for the autoscaling mode [mm].
- `colored_holes`: [boolean=true] Change the drill holes to be colored instead of white.
- `exclude_pads_from_silkscreen`: [boolean=false] Do not plot the component pads in the silk screen (KiCad 5.x only).
- `holes_color`: [string='#000000'] Color used for the holes when `colored_holes` is enabled.
@ -2494,6 +2496,8 @@ Notes:
- **`plot_sheet_reference`**: [boolean=true] Include the title-block (worksheet, frame, etc.).
- **`scaling`**: [number=1.0] Default scale factor (0 means autoscaling).
- `add_background`: [boolean=false] Add a background to the pages, see `background_color`.
- `autoscale_margin_x`: [number=0] Default horizontal margin used for the autoscaling mode [mm].
- `autoscale_margin_y`: [number=0] Default vertical margin used for the autoscaling mode [mm].
- `background_color`: [string='#FFFFFF'] Color for the background when `add_background` is enabled.
- `background_image`: [string=''] Background image, must be an SVG, only when `add_background` is enabled.
- `blind_via_color`: [string=''] Color used for blind/buried `colored_vias`.

View File

@ -1217,6 +1217,10 @@ outputs:
options:
# [boolean=false] Add a background to the pages, see `background_color`
add_background: false
# [number=0] Default horizontal margin used for the autoscaling mode [mm]
autoscale_margin_x: 0
# [number=0] Default vertical margin used for the autoscaling mode [mm]
autoscale_margin_y: 0
# [string='#FFFFFF'] Color for the background when `add_background` is enabled
background_color: '#FFFFFF'
# [string=''] Background image, must be an SVG, only when `add_background` is enabled
@ -1274,8 +1278,12 @@ outputs:
# [list(dict)] List of pages to include in the output document.
# Each page contains one or more layers of the PCB
pages:
# [boolean=true] Change the drill holes to be colored instead of white
- colored_holes: true
# [number=0] Horizontal margin used for the autoscaling mode [mm]
- autoscale_margin_x: 0
# [number=0] Vertical margin used for the autoscaling mode [mm]
autoscale_margin_y: 0
# [boolean=true] Change the drill holes to be colored instead of white
colored_holes: true
# [boolean=false] Do not plot the component pads in the silk screen (KiCad 5.x only)
exclude_pads_from_silkscreen: false
# [string='#000000'] Color used for the holes when `colored_holes` is enabled

View File

@ -166,6 +166,10 @@ class PagesOptions(Optionable):
""" Print in gray scale """
self.scaling = None
""" *[number=1.0] Scale factor (0 means autoscaling)"""
self.autoscale_margin_x = None
""" [number=0] Horizontal margin used for the autoscaling mode [mm] """
self.autoscale_margin_y = None
""" [number=0] Vertical margin used for the autoscaling mode [mm] """
self.title = ''
""" Text used to replace the sheet title. %VALUE expansions are allowed.
If it starts with `+` the text is concatenated """
@ -194,6 +198,8 @@ class PagesOptions(Optionable):
self.page_id = '%02d'
""" Text to differentiate the pages. Use %d (like in C) to get the page number """
self._scaling_example = 1.0
self._autoscale_margin_x_example = 0
self._autoscale_margin_y_example = 0
def config(self, parent):
super().config(parent)
@ -209,6 +215,10 @@ class PagesOptions(Optionable):
self.validate_color('holes_color')
if self.scaling is None:
self.scaling = parent.scaling
if self.autoscale_margin_x is None:
self.autoscale_margin_x = parent.autoscale_margin_x
if self.autoscale_margin_y is None:
self.autoscale_margin_y = parent.autoscale_margin_y
class PCB_PrintOptions(VariantOptions):
@ -282,6 +292,10 @@ class PCB_PrintOptions(VariantOptions):
""" Color used for the `force_edge_cuts` option """
self.scaling = 1.0
""" *Default scale factor (0 means autoscaling)"""
self.autoscale_margin_x = 0
""" Default horizontal margin used for the autoscaling mode [mm] """
self.autoscale_margin_y = 0
""" Default vertical margin used for the autoscaling mode [mm] """
self.realistic_solder_mask = True
""" Try to draw the solder mask as a real solder mask, not the negative used for fabrication.
In order to get a good looking select a color with transparency, i.e. '#14332440'.
@ -911,8 +925,8 @@ class PCB_PrintOptions(VariantOptions):
po.SetScale(scaling)
return scaling
sz = GS.board.GetBoundingBox().GetSize()
scale_x = FromMM(self.paper_w)/sz.x
scale_y = FromMM(self.paper_h)/sz.y
scale_x = FromMM(self.paper_w-self.autoscale_margin_x*2)/sz.x
scale_y = FromMM(self.paper_h-self.autoscale_margin_y*2)/sz.y
scale = min(scale_x, scale_y)
po.SetScale(scale)
logger.debug('- Autoscale: {}'.format(scale))