Skip to content

Commit

Permalink
[BoM][Added] right_digits option
Browse files Browse the repository at this point in the history
To control the decimals for position fields

Closes #739
  • Loading branch information
set-soft committed Dec 5, 2024
1 parent 63bca7f commit 158dc9e
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
ranges
- `use_ref_ranges` alias for `use_alt`
- New *kicad* format to mimic KiCad's internal BoM.
- `right_digits` option to control the decimals for position fields (#739)
- Drill:
- Option to don't generate the drill files, so you can generate only the maps
(#720)
Expand Down
8 changes: 6 additions & 2 deletions docs/samples/generic_plot.kibot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,9 @@ outputs:
ref_range_separator: '-'
# [string=' '] Separator used for the list of references. Ignored when using the KICAD format
ref_separator: ' '
# [number=4] Number of digits for mantissa part of coordinates ('Footprint X', 'Footprint Y', 'Footprint X-Size',
# 'Footprint Y-Size' and 'Footprint Rot' columns) (0 is auto)
right_digits: 4
# [boolean=true] Sort in ascending order
sort_ascending: true
# [string='type_value'] [type_value,type_value_ref,ref,kicad_bom] Sorting criteria.
Expand All @@ -731,7 +734,8 @@ outputs:
sort_style: 'type_value'
# [boolean=false] Generate the `Source BoM` column using the reference ID instead of the project name
source_by_id: false
# [string='millimeters'] [millimeters,inches,mils] Units used for the positions ('Footprint X' and 'Footprint Y' columns).
# [string='millimeters'] [millimeters,inches,mils] Units used for the positions ('Footprint X', 'Footprint Y', 'Footprint X-Size' and
# 'Footprint Y-Size' columns).
# Affected by global options
units: 'millimeters'
# [boolean=false] Print grouped references in the alternate compressed style eg: R1-R7,R18.
Expand Down Expand Up @@ -2453,7 +2457,7 @@ outputs:
# [number|string=0] Like `millradius`, but modifies only board outer counter.
# No internal features of the board are affected
millradiusouter: 0
# [string='tl'] [tl,tr,bl,br,mt,mb,ml,mr,c] Specify if the auxiliary origin an grid origin should be placed.
# [string='tl'] [tl,tr,bl,br,mt,mb,ml,mr,c] Specify if the auxiliary origin and grid origin should be replaced.
# Can be one of tl, tr, bl, br (corners), mt, mb, ml, mr (middle of sides), c (center).
# Empty string does not changes the origin
origin: 'tl'
Expand Down
2 changes: 2 additions & 0 deletions docs/source/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Added
reference ranges
- ``use_ref_ranges`` alias for ``use_alt``
- New *kicad* format to mimic KiCad’s internal BoM.
- ``right_digits`` option to control the decimals for position
fields (#739)

- Drill:

Expand Down
5 changes: 4 additions & 1 deletion docs/source/configuration/outputs/BoMOptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ BoMOptions parameters
- type_value_ref: like *type_value* but use the reference when we don't have a value
- ref: by reference
- kicad_bom: according to the options of the KiCad BoM tool.
- **units** :index:`: <pair: output - bom - options; units>` [:ref:`string <string>`] (default: ``'millimeters'``) (choices: "millimeters", "inches", "mils") Units used for the positions ('Footprint X' and 'Footprint Y' columns).
- **units** :index:`: <pair: output - bom - options; units>` [:ref:`string <string>`] (default: ``'millimeters'``) (choices: "millimeters", "inches", "mils") Units used for the positions ('Footprint X', 'Footprint Y', 'Footprint X-Size' and
'Footprint Y-Size' columns). |br|
Affected by global options.
- **xlsx** :index:`: <pair: output - bom - options; xlsx>` [:ref:`BoMXLSX parameters <BoMXLSX>`] [:ref:`dict <dict>`] (default: empty dict, default values used) Options for the XLSX format.
- ``aggregate`` :index:`: <pair: output - bom - options; aggregate>` [:ref:`Aggregate parameters <Aggregate>`] [:ref:`list(dict) <list(dict)>`] (default: ``[]``) Add components from other projects.
Expand Down Expand Up @@ -123,6 +124,8 @@ BoMOptions parameters
- ``ref_range_separator`` :index:`: <pair: output - bom - options; ref_range_separator>` [:ref:`string <string>`] (default: ``'-'``) Separator used for ranges in the list of references. Used when `use_alt` is enabled.
Ignored when using the KICAD format.
- ``ref_separator`` :index:`: <pair: output - bom - options; ref_separator>` [:ref:`string <string>`] (default: ``' '``) Separator used for the list of references. Ignored when using the KICAD format.
- ``right_digits`` :index:`: <pair: output - bom - options; right_digits>` [:ref:`number <number>`] (default: ``4``) Number of digits for mantissa part of coordinates ('Footprint X', 'Footprint Y', 'Footprint X-Size',
'Footprint Y-Size' and 'Footprint Rot' columns) (0 is auto).
- ``sort_ascending`` :index:`: <pair: output - bom - options; sort_ascending>` [:ref:`boolean <boolean>`] (default: ``true``) Sort in ascending order.
- ``source_by_id`` :index:`: <pair: output - bom - options; source_by_id>` [:ref:`boolean <boolean>`] (default: ``false``) Generate the `Source BoM` column using the reference ID instead of the project name.
- ``use_alt`` :index:`: <pair: output - bom - options; use_alt>` [:ref:`boolean <boolean>`] (default: ``false``) Print grouped references in the alternate compressed style eg: R1-R7,R18.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/configuration/outputs/PanelizePost.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PanelizePost parameters
Specify mill radius (usually 1 mm). 0 radius disables the functionality.
- ``millradiusouter`` :index:`: <pair: output - panelize - options - configs - post; millradiusouter>` [:ref:`number <number>` | :ref:`string <string>`] (default: ``0``) Like `millradius`, but modifies only board outer counter.
No internal features of the board are affected.
- ``origin`` :index:`: <pair: output - panelize - options - configs - post; origin>` [:ref:`string <string>`] (default: ``'tl'``) (choices: "tl", "tr", "bl", "br", "mt", "mb", "ml", "mr", "c") Specify if the auxiliary origin an grid origin should be placed.
- ``origin`` :index:`: <pair: output - panelize - options - configs - post; origin>` [:ref:`string <string>`] (default: ``'tl'``) (choices: "tl", "tr", "bl", "br", "mt", "mb", "ml", "mr", "c") Specify if the auxiliary origin and grid origin should be replaced.
Can be one of tl, tr, bl, br (corners), mt, mb, ml, mr (middle of sides), c (center). |br|
Empty string does not changes the origin.
- *reconstruct_arcs* :index:`: <pair: output - panelize - options - configs - post; reconstruct_arcs>` Alias for reconstructarcs.
Expand Down
1 change: 0 additions & 1 deletion docs/source/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Arguments:

Options:
-A, --no-auto-download Disable dependencies auto-download
--all-variants Iterate for all variants
-b BOARD, --board-file BOARD The PCB .kicad-pcb board file
--banner N Display banner number N (-1 == random)
-c CONFIG, --plot-config CONFIG The plotting config file to use
Expand Down
15 changes: 8 additions & 7 deletions kibot/bom/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def update_field(self, field, value, ref=None):
self.fields[field] += " " + value

def update_fields(self, conv, bottom_negative_x, x_origin, y_origin, angle_positive, footprint_populate_values,
footprint_type_values, uses_fp_info, usealt=False):
footprint_type_values, uses_fp_info, usealt=False, right_digits=4):
for c in self.components:
for f, v in c.get_user_fields():
self.update_field(f, v, c.ref)
Expand Down Expand Up @@ -337,12 +337,13 @@ def update_fields(self, conv, bottom_negative_x, x_origin, y_origin, angle_posit
pos_x = (comp.footprint_x - x_origin) * conv
if bottom_negative_x and comp.bottom:
pos_x = -pos_x
self.fields[ColumnList.COL_FP_X_L] = "{:.4f}".format(pos_x)
self.fields[ColumnList.COL_FP_Y_L] = "{:.4f}".format(-(comp.footprint_y - y_origin) * conv)
float_format = "{{:.{}f}}".format(right_digits) if right_digits else "{}"
self.fields[ColumnList.COL_FP_X_L] = float_format.format(pos_x)
self.fields[ColumnList.COL_FP_Y_L] = float_format.format(-(comp.footprint_y - y_origin) * conv)
rot = comp.footprint_rot
if angle_positive:
rot = rot % 360
self.fields[ColumnList.COL_FP_ROT_L] = "{:.4f}".format(rot)
self.fields[ColumnList.COL_FP_ROT_L] = float_format.format(rot)
self.fields[ColumnList.COL_FP_SIDE_L] = "bottom" if comp.bottom else "top"
type = 0
if comp.tht:
Expand All @@ -358,8 +359,8 @@ def update_fields(self, conv, bottom_negative_x, x_origin, y_origin, angle_posit
type = ''
self.fields[ColumnList.COL_FP_TYPE_NV_L] = type
self.fields[ColumnList.COL_FP_FIT_L] = footprint_populate_values[comp.fitted]
self.fields[ColumnList.COL_FP_XS_L] = "{:.4f}".format(comp.footprint_w * conv)
self.fields[ColumnList.COL_FP_YS_L] = "{:.4f}".format(comp.footprint_h * conv)
self.fields[ColumnList.COL_FP_XS_L] = float_format.format(comp.footprint_w * conv)
self.fields[ColumnList.COL_FP_YS_L] = float_format.format(comp.footprint_h * conv)
self.fields[ColumnList.COL_FP_LIB_L] = comp.footprint_lib
self.fields[ColumnList.COL_SHEETPATH_L] = comp.sheet_path_h
if not self.fields[ColumnList.COL_DESCRIPTION_L]:
Expand Down Expand Up @@ -497,7 +498,7 @@ def group_components(cfg, components):
g.sort_components()
# Fill the columns
g.update_fields(cfg.conv_units, cfg.bottom_negative_x, x_origin, y_origin, cfg.angle_positive,
cfg.footprint_populate_values, cfg.footprint_type_values, uses_fp_info, cfg._use_alt)
cfg.footprint_populate_values, cfg.footprint_type_values, uses_fp_info, cfg._use_alt, cfg.right_digits)
if cfg.normalize_values:
g.fields[ColumnList.COL_VALUE_L] = normalize_value(g.components[0], decimal_point)
# Sort the groups
Expand Down
6 changes: 5 additions & 1 deletion kibot/out_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,12 @@ def __init__(self):
self.count_smd_tht = False
""" Show the stats about how many of the components are SMD/THT. You must provide the PCB """
self.units = 'millimeters'
""" *[millimeters,inches,mils] Units used for the positions ('Footprint X' and 'Footprint Y' columns).
""" *[millimeters,inches,mils] Units used for the positions ('Footprint X', 'Footprint Y', 'Footprint X-Size' and
'Footprint Y-Size' columns).
Affected by global options """
self.right_digits = 4
""" Number of digits for mantissa part of coordinates ('Footprint X', 'Footprint Y', 'Footprint X-Size',
'Footprint Y-Size' and 'Footprint Rot' columns) (0 is auto) """
self.bottom_negative_x = False
""" Use negative X coordinates for footprints on bottom layer (for XYRS) """
self.use_aux_axis_as_origin = True
Expand Down
7 changes: 7 additions & 0 deletions tests/GUI/outputs
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,13 @@
],
null
],
[
"right_digits",
[
"DataTypeNumber"
],
null
],
[
"bottom_negative_x",
[
Expand Down
22 changes: 11 additions & 11 deletions tests/GUI/stats
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
48 outputs types with a total of 1926 different parameters
Single type parameters: 1752 (91 %)
48 outputs types with a total of 1927 different parameters
Single type parameters: 1753 (91 %)
Multi type parameters: 174 (9 %)
Average parameters: 40
Maximum number of parameters: 217
Expand Down Expand Up @@ -74,7 +74,7 @@ Outputs sorted by parameters:
- render_3d: 67
- blender_export: 76
- pcb_print: 94
- bom: 148
- bom: 149
- panelize: 217
Average depth: 2.5416666666666665
Maximum depth: 5
Expand Down Expand Up @@ -139,7 +139,7 @@ Outputs sorted by depth:
14 different data types
- String: 846
- Boolean: 475
- Number: 266
- Number: 267
- ListStringSingular: 265
- Choice: 95
- Dict: 79
Expand All @@ -156,7 +156,7 @@ Used as single data type:
- String: 692
- Boolean: 419
- ListStringSingular: 262
- Number: 172
- Number: 173
- Choice: 92
- Dict: 70
- ListDict: 20
Expand Down Expand Up @@ -392,8 +392,8 @@ Used as single data type:
- Number,String: 15
================================================================================
================================================================================
87 totals types with a total of 2297 different parameters
Single type parameters: 2099 (91 %)
87 totals types with a total of 2298 different parameters
Single type parameters: 2100 (91 %)
Multi type parameters: 198 (9 %)
Average parameters: 26
Maximum number of parameters: 217
Expand Down Expand Up @@ -507,7 +507,7 @@ Totals sorted by parameters:
- render_3d: 67
- blender_export: 76
- pcb_print: 94
- bom: 148
- bom: 149
- panelize: 217
Average depth: 2.1839080459770117
Maximum depth: 5
Expand Down Expand Up @@ -611,7 +611,7 @@ Totals sorted by depth:
14 different data types
- String: 999
- Boolean: 573
- Number: 314
- Number: 315
- ListStringSingular: 294
- Choice: 127
- Dict: 90
Expand All @@ -628,7 +628,7 @@ Used as single data type:
- String: 829
- Boolean: 509
- ListStringSingular: 291
- Number: 205
- Number: 206
- Choice: 124
- Dict: 73
- ListDict: 30
Expand All @@ -652,4 +652,4 @@ Used as single data type:
- Dict,Number: 2 ['pcbdraw.options.margin', 'svg.options.margin']
- Boolean,Choice: 1 ['ibom.options.highlight_pin1']
- String,StringDict: 1 ['pcbdraw.options.remap']
Found 2 unique warning/s (3 total)
Found 3 unique warning/s (4 total)

0 comments on commit 158dc9e

Please sign in to comment.