Skip to content

Commit

Permalink
[BoM][Added] Support for SVG format in the logos
Browse files Browse the repository at this point in the history
Converting them to PNG

Closes #383
  • Loading branch information
set-soft committed Mar 30, 2024
1 parent 3793f8d commit f1eaee6
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
options. So one entry can be something like *R10-R20*. Can be disabled
using the global option `allow_component_ranges`. (See yaqwsx/PcbDraw#159)
- Navigate results: A header and navigation bar (#582)
- BoM: support for SVG format in the logos (#383)

### Changed
- CI/CD: we now filter some warnings that are always generated by docker
Expand Down
12 changes: 9 additions & 3 deletions docs/samples/generic_plot.kibot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,11 @@ outputs:
# [boolean|string|list(string)=''] Column/s containing LCSC part numbers, will be linked to web page.
# Use **true** to copy the value indicated by the `field_lcsc_part` global option
lcsc_link: ''
# [string|boolean=''] PNG file to use as logo, use false to remove
# [string|boolean=''] PNG/SVG file to use as logo, use false to remove.
# Note that when using an SVG this is first converted to a PNG using `logo_width`
logo: ''
# [number=370] Used when the logo is an SVG image. This width is used to render the SVG image
logo_width: 370
# [string|list(string)=''] Column/s containing Mouser part numbers, will be linked to web page
mouser_link: ''
# [string='modern-blue'] Page style. Internal styles: modern-blue, modern-green, modern-red and classic.
Expand Down Expand Up @@ -597,10 +600,13 @@ outputs:
# [boolean|string|list(string)=''] Column/s containing LCSC part numbers, will be linked to web page.
# Use **true** to copy the value indicated by the `field_lcsc_part` global option
lcsc_link: ''
# [string|boolean=''] PNG file to use as logo, use false to remove
# [string|boolean=''] PNG/SVG file to use as logo, use false to remove.
# Note that when using an SVG this is first converted to a PNG using `logo_width`
logo: ''
# [number=2] Scaling factor for the logo. Note that this value isn't honored by all spreadsheet software
logo_scale: 2
# [number=370] Used when the logo is an SVG image. This width is used to render the SVG image
logo_width: 370
# [number=60] [20,999] Maximum column width (characters)
max_col_width: 60
# [string|list(string)=''] Column/s containing Mouser part numbers, will be linked to web page
Expand Down Expand Up @@ -1759,7 +1765,7 @@ outputs:
output: '%f-%i%I%v.%x'
# [boolean=false] Skip outputs with `run_by_default: false`
skip_not_run: false
# [string=''] Title for the page, when empy KiBot will try using the schematic or PCB title.
# [string=''] Title for the page, when empty KiBot will try using the schematic or PCB title.
# If they are empty the name of the project, schematic or PCB file is used.
# You can use %X values and KiCad variables here
title: ''
Expand Down
1 change: 1 addition & 0 deletions docs/source/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Added
Can be disabled using the global option ``allow_component_ranges``.
(See yaqwsx/PcbDraw#159)
- Navigate results: A header and navigation bar (#582)
- BoM: support for SVG format in the logos (#383)

Changed
~~~~~~~
Expand Down
8 changes: 6 additions & 2 deletions docs/source/configuration/outputs/bom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ Parameters:

- **datasheet_as_link** :index:`: <pair: output - bom - options - html; datasheet_as_link>` [string=''] Column with links to the datasheet.
- **generate_dnf** :index:`: <pair: output - bom - options - html; generate_dnf>` [boolean=true] Generate a separated section for DNF (Do Not Fit) components.
- **logo** :index:`: <pair: output - bom - options - html; logo>` [string|boolean=''] PNG file to use as logo, use false to remove.
- **logo** :index:`: <pair: output - bom - options - html; logo>` [string|boolean=''] PNG/SVG file to use as logo, use false to remove.
Note that when using an SVG this is first converted to a PNG using `logo_width`.

- **title** :index:`: <pair: output - bom - options - html; title>` [string='KiBot Bill of Materials'] BoM title.
- ``col_colors`` :index:`: <pair: output - bom - options - html; col_colors>` [boolean=true] Use colors to show the field type.
Expand All @@ -114,6 +115,7 @@ Parameters:
- ``lcsc_link`` :index:`: <pair: output - bom - options - html; lcsc_link>` [boolean|string|list(string)=''] Column/s containing LCSC part numbers, will be linked to web page.
Use **true** to copy the value indicated by the `field_lcsc_part` global option.

- ``logo_width`` :index:`: <pair: output - bom - options - html; logo_width>` [number=370] Used when the logo is an SVG image. This width is used to render the SVG image.
- ``mouser_link`` :index:`: <pair: output - bom - options - html; mouser_link>` [string|list(string)=''] Column/s containing Mouser part numbers, will be linked to web page.

- ``style`` :index:`: <pair: output - bom - options - html; style>` [string='modern-blue'] Page style. Internal styles: modern-blue, modern-green, modern-red and classic.
Expand All @@ -134,7 +136,8 @@ Parameters:
- **generate_dnf** :index:`: <pair: output - bom - options - xlsx; generate_dnf>` [boolean=true] Generate a separated section for DNF (Do Not Fit) components.
- **kicost** :index:`: <pair: output - bom - options - xlsx; kicost>` [boolean=false] Enable KiCost worksheet creation.
Note: an example of how to use it on CI/CD can be found `here <https://github.com/set-soft/kicost_ci_test>`__.
- **logo** :index:`: <pair: output - bom - options - xlsx; logo>` [string|boolean=''] PNG file to use as logo, use false to remove.
- **logo** :index:`: <pair: output - bom - options - xlsx; logo>` [string|boolean=''] PNG/SVG file to use as logo, use false to remove.
Note that when using an SVG this is first converted to a PNG using `logo_width`.

- **specs** :index:`: <pair: output - bom - options - xlsx; specs>` [boolean=false] Enable Specs worksheet creation. Contains specifications for the components.
Works with only some KiCost APIs.
Expand All @@ -161,6 +164,7 @@ Parameters:
Use **true** to copy the value indicated by the `field_lcsc_part` global option.

- ``logo_scale`` :index:`: <pair: output - bom - options - xlsx; logo_scale>` [number=2] Scaling factor for the logo. Note that this value isn't honored by all spreadsheet software.
- ``logo_width`` :index:`: <pair: output - bom - options - xlsx; logo_width>` [number=370] Used when the logo is an SVG image. This width is used to render the SVG image.
- ``max_col_width`` :index:`: <pair: output - bom - options - xlsx; max_col_width>` [number=60] [20,999] Maximum column width (characters).
- ``mouser_link`` :index:`: <pair: output - bom - options - xlsx; mouser_link>` [string|list(string)=''] Column/s containing Mouser part numbers, will be linked to web page.

Expand Down
2 changes: 1 addition & 1 deletion docs/source/configuration/outputs/navigate_results.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Parameters:
- ``logo_url`` :index:`: <pair: output - navigate_results - options; logo_url>` [string='https://github.com/INTI-CMNB/KiBot/'] Target link when clicking the logo.
- ``nav_bar`` :index:`: <pair: output - navigate_results - options; nav_bar>` [boolean=true] Add a side navigation bar to quickly access to the outputs.
- ``skip_not_run`` :index:`: <pair: output - navigate_results - options; skip_not_run>` [boolean=false] Skip outputs with `run_by_default: false`.
- ``title`` :index:`: <pair: output - navigate_results - options; title>` [string=''] Title for the page, when empy KiBot will try using the schematic or PCB title.
- ``title`` :index:`: <pair: output - navigate_results - options; title>` [string=''] Title for the page, when empty KiBot will try using the schematic or PCB title.
If they are empty the name of the project, schematic or PCB file is used.
You can use %X values and KiCad variables here.
- ``title_url`` :index:`: <pair: output - navigate_results - options; title_url>` [string|boolean=''] Target link when clicking the title, use false to remove.
Expand Down
1 change: 1 addition & 0 deletions docs/source/dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@

- Optional to:

- SVG logos for the BoM for `bom`
- Create outputs preview for `navigate_results`
- Create PNG icons for `navigate_results`
- Create PDF, PNG, PS and EPS formats for `pcb_print`
Expand Down
45 changes: 41 additions & 4 deletions kibot/out_bom.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020-2023 Salvador E. Tropea
# Copyright (c) 2020-2023 Instituto Nacional de Tecnología Industrial
# Copyright (c) 2020-2024 Salvador E. Tropea
# Copyright (c) 2020-2024 Instituto Nacional de Tecnología Industrial
# License: MIT
# Project: KiBot (formerly KiPlot)
"""
Expand All @@ -10,6 +10,8 @@
- from: KiCost
role: Find components costs and specs
version: 1.1.8
- from: RSVG
role: SVG logos for the BoM
- name: XLSXWriter
role: Create XLSX files
python_module: true
Expand All @@ -22,12 +24,13 @@
from copy import deepcopy
import os
import re
from tempfile import NamedTemporaryFile
from .gs import GS
from .misc import W_BADFIELD, W_NEEDSPCB, DISTRIBUTORS, W_NOPART, W_MISSREF, DISTRIBUTORS_STUBS, DISTRIBUTORS_STUBS_SEPS
from .optionable import Optionable, BaseOptions
from .registrable import RegOutput
from .error import KiPlotConfigurationError
from .kiplot import get_board_comps_data, load_any_sch, register_xmp_import, expand_fields
from .kiplot import get_board_comps_data, load_any_sch, register_xmp_import, expand_fields, run_command
from .kicad.v5_sch import SchematicComponent, SchematicField
from .bom.columnlist import ColumnList, BoMError
from .bom.bom import do_bom
Expand Down Expand Up @@ -201,7 +204,10 @@ def __init__(self):
self.highlight_empty = True
""" Use a color for empty cells. Applies only when `col_colors` is `true` """
self.logo = Optionable
""" *[string|boolean=''] PNG file to use as logo, use false to remove """
""" *[string|boolean=''] PNG/SVG file to use as logo, use false to remove.
Note that when using an SVG this is first converted to a PNG using `logo_width` """
self.logo_width = 370
""" Used when the logo is an SVG image. This width is used to render the SVG image """
self.title = 'KiBot Bill of Materials'
""" *BoM title """
self.extra_info = Optionable
Expand Down Expand Up @@ -892,6 +898,29 @@ def aggregate_comps(self, comps):
comps.extend(new_comps)
prj.source = os.path.basename(prj.file)

def solve_logo(self):
if self.format == 'html':
logo = self.html.logo
w = self.html.logo_width
elif self.format == 'xlsx':
logo = self.xlsx.logo
w = self.xlsx.logo_width
else:
return None
ext = os.path.splitext(logo)[1]
if ext.lower() != '.svg':
return None
with NamedTemporaryFile(mode='w', suffix='.png', delete=False) as f:
png = f.name
cmd = [self.ensure_tool('RSVG'), '-w', str(w), '-f', 'png', '-o', png, logo]
run_command(cmd)
self._old_logo = logo
if self.format == 'html':
self.html.logo = png
elif self.format == 'xlsx':
self.xlsx.logo = png
return png

def run(self, output):
format = self.format.lower()
if format == 'xlsx':
Expand Down Expand Up @@ -951,10 +980,18 @@ def run(self, output):
# To translate project to ID
if self.source_by_id:
self.source_to_id = {prj.name: prj.ref_id for prj in self.aggregate}
tmp_png = self.solve_logo()
try:
do_bom(output, format, comps, self)
except BoMError as e:
raise KiPlotConfigurationError(str(e))
finally:
if tmp_png:
os.remove(tmp_png)
if self.format == 'html':
self.html.logo = self._old_logo
elif self.format == 'xlsx':
self.xlsx.logo = self._old_logo
# Undo the reference prefix
if self.ref_id:
l_id = len(self.ref_id)
Expand Down
11 changes: 9 additions & 2 deletions src/kibot-check
Original file line number Diff line number Diff line change
Expand Up @@ -1068,17 +1068,24 @@ deps = '{\
"extra_arch": null,\
"extra_deb": null,\
"help_option": "--version",\
"importance": 4,\
"importance": 5,\
"in_debian": true,\
"is_kicad_plugin": false,\
"is_python": false,\
"name": "RSVG tools",\
"no_cmd_line_version": false,\
"no_cmd_line_version_old": false,\
"output": "navigate_results",\
"output": "bom",\
"plugin_dirs": null,\
"pypi_name": "RSVG tools",\
"role": [\
{\
"desc": "SVG logos for the BoM",\
"mandatory": false,\
"max_version": null,\
"output": "bom",\
"version": null\
},\
{\
"desc": "Create outputs preview",\
"mandatory": false,\
Expand Down

0 comments on commit f1eaee6

Please sign in to comment.