Skip to content

Commit

Permalink
[Renderers][Added] Support for component ranges
Browse files Browse the repository at this point in the history
- In the `show_components` and `highlight` options.
- So one entry can be something like *R10-R20*.
- Can be disabled using the global option `allow_component_ranges`.

Idea from yaqwsx/PcbDraw#159
  • Loading branch information
set-soft committed Mar 27, 2024
1 parent 9b41491 commit 0433088
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- KiCad 8 support
- Panelize: support for all new options (upto 1.5.1)
- 3D/2D renderers: support for ranges in the `show_components` and `highlight`
options. So one entry can be something like *R10-R20*. Can be disabled
using the global option `allow_component_ranges`. (See yaqwsx/PcbDraw#159)

### Changed
- CI/CD: we now filter some warnings that are always generated by docker
Expand Down
12 changes: 8 additions & 4 deletions docs/samples/generic_plot.kibot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ outputs:
# part number. The field containing the LCSC part number is defined by the
# `field_lcsc_part` global variable
download_lcsc: true
# [list(string)=[]] List of components to highlight
# [list(string)=[]] List of components to highlight. Ranges like *R5-R10* are supported
highlight: []
# [boolean=false] Highlight over the component (not under)
highlight_on_top: false
Expand All @@ -209,6 +209,7 @@ outputs:
# A short-cut to use for simple cases where a variant is an overkill
pre_transform: '_none'
# [list(string)|string=all] [none,all] List of components to draw, can be also a string for `none` or `all`.
# Ranges like *R5-R10* are supported.
# Unlike the `pcbdraw` output, the default is `all`
show_components: all
# [boolean=true] Add solder paste only for the populated components.
Expand Down Expand Up @@ -2352,7 +2353,8 @@ outputs:
# A short-cut to use for simple cases where a variant is an overkill
pre_transform: '_none'
# [list(string)|string=all] [none,all] List of components to include in the pads list,
# can be also a string for `none` or `all`. The default is `all`
# can be also a string for `none` or `all`. The default is `all`.
# Ranges like *R5-R10* are supported
show_components: all
# [boolean=false] Create a file containing the board stackup
stackup_create: false
Expand Down Expand Up @@ -3193,7 +3195,7 @@ outputs:
download_lcsc: true
# [number=720] Image height (aprox.)
height: 720
# [list(string)=[]] List of components to highlight
# [list(string)=[]] List of components to highlight. Ranges like *R5-R10* are supported
highlight: []
# [boolean=false] Highlight over the component (not under)
highlight_on_top: false
Expand Down Expand Up @@ -3243,6 +3245,7 @@ outputs:
# [boolean=false] Show the content of the User.Comments layer. KiCad 6 or newer and ray tracing disabled
show_comments: false
# [list(string)|string=all] [none,all] List of components to draw, can be also a string for `none` or `all`.
# Ranges like *R5-R10* are supported.
# Unlike the `pcbdraw` output, the default is `all`
show_components: all
# [boolean=false] Show the content of the Eco1.User/Eco2.User layers. KiCad 6 or newer and ray tracing disabled
Expand Down Expand Up @@ -3699,7 +3702,7 @@ outputs:
# part number. The field containing the LCSC part number is defined by the
# `field_lcsc_part` global variable
download_lcsc: true
# [list(string)=[]] List of components to highlight
# [list(string)=[]] List of components to highlight. Ranges like *R5-R10* are supported
highlight: []
# [boolean=false] Highlight over the component (not under)
highlight_on_top: false
Expand All @@ -3726,6 +3729,7 @@ outputs:
# [number=0] Y coordinate to use as reference when `use_pcb_center_as_ref` and `use_pcb_center_as_ref` are disabled
ref_y: 0
# [list(string)|string=all] [none,all] List of components to draw, can be also a string for `none` or `all`.
# Ranges like *R5-R10* are supported.
# Unlike the `pcbdraw` output, the default is `all`
show_components: all
# [boolean=false] Use the auxiliary axis as origin for coordinates.
Expand Down
4 changes: 4 additions & 0 deletions docs/source/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Added

- KiCad 8 support
- Panelize: support for all new options (upto 1.5.1)
- 3D/2D renderers: support for ranges in the ``show_components`` and
``highlight`` options. So one entry can be something like *R10-R20*.
Can be disabled using the global option ``allow_component_ranges``.
(See yaqwsx/PcbDraw#159)

Changed
~~~~~~~
Expand Down
3 changes: 2 additions & 1 deletion docs/source/configuration/outputs/blender_export.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Parameters:
KIBOT_3D_MODELS environment variable.
- **no_virtual** :index:`: <pair: output - blender_export - options - pcb3d; no_virtual>` [boolean=false] Used to exclude 3D models for components with 'virtual' attribute.
- **show_components** :index:`: <pair: output - blender_export - options - pcb3d; show_components>` [list(string)|string=all] [none,all] List of components to draw, can be also a string for `none` or `all`.
Ranges like *R5-R10* are supported.
Unlike the `pcbdraw` output, the default is `all`.

- ``dnf_filter`` :index:`: <pair: output - blender_export - options - pcb3d; dnf_filter>` [string|list(string)='_none'] Name of the filter to mark components as not fitted.
Expand All @@ -53,7 +54,7 @@ Parameters:
them from LCSC database. In order to work you'll need to provide the LCSC
part number. The field containing the LCSC part number is defined by the
`field_lcsc_part` global variable.
- ``highlight`` :index:`: <pair: output - blender_export - options - pcb3d; highlight>` [list(string)=[]] List of components to highlight.
- ``highlight`` :index:`: <pair: output - blender_export - options - pcb3d; highlight>` [list(string)=[]] List of components to highlight. Ranges like *R5-R10* are supported.

- ``highlight_on_top`` :index:`: <pair: output - blender_export - options - pcb3d; highlight_on_top>` [boolean=false] Highlight over the component (not under).
- ``highlight_padding`` :index:`: <pair: output - blender_export - options - pcb3d; highlight_padding>` [number=1.5] [0,1000] How much the highlight extends around the component [mm].
Expand Down
1 change: 1 addition & 0 deletions docs/source/configuration/outputs/pcb2blender_tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Parameters:
- **output** :index:`: <pair: output - pcb2blender_tools - options; output>` [string='%f-%i%I%v.%x'] Filename for the output (%i=pcb2blender, %x=pcb3d). Affected by global options.
- **show_components** :index:`: <pair: output - pcb2blender_tools - options; show_components>` [list(string)|string=all] [none,all] List of components to include in the pads list,
can be also a string for `none` or `all`. The default is `all`.
Ranges like *R5-R10* are supported.

- ``board_bounds_create`` :index:`: <pair: output - pcb2blender_tools - options; board_bounds_create>` [boolean=true] Create the file that informs the size of the used PCB area.
This is the bounding box reported by KiCad for the PCB edge with 1 mm of margin.
Expand Down
3 changes: 2 additions & 1 deletion docs/source/configuration/outputs/render_3d.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Parameters:
- **rotate_z** :index:`: <pair: output - render_3d - options; rotate_z>` [number=0] Steps to rotate around the Z axis, positive is clockwise.
Each step is currently 10 degrees. Only for KiCad 6 or newer.
- **show_components** :index:`: <pair: output - render_3d - options; show_components>` [list(string)|string=all] [none,all] List of components to draw, can be also a string for `none` or `all`.
Ranges like *R5-R10* are supported.
Unlike the `pcbdraw` output, the default is `all`.

- **view** :index:`: <pair: output - render_3d - options; view>` [string='top'] [top,bottom,front,rear,right,left,z,Z,y,Y,x,X] Point of view.
Expand All @@ -64,7 +65,7 @@ Parameters:
part number. The field containing the LCSC part number is defined by the
`field_lcsc_part` global variable.
- ``height`` :index:`: <pair: output - render_3d - options; height>` [number=720] Image height (aprox.).
- ``highlight`` :index:`: <pair: output - render_3d - options; highlight>` [list(string)=[]] List of components to highlight.
- ``highlight`` :index:`: <pair: output - render_3d - options; highlight>` [list(string)=[]] List of components to highlight. Ranges like *R5-R10* are supported.

- ``highlight_on_top`` :index:`: <pair: output - render_3d - options; highlight_on_top>` [boolean=false] Highlight over the component (not under).
- ``highlight_padding`` :index:`: <pair: output - render_3d - options; highlight_padding>` [number=1.5] [0,1000] How much the highlight extends around the component [mm].
Expand Down
3 changes: 2 additions & 1 deletion docs/source/configuration/outputs/vrml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Parameters:
- **no_virtual** :index:`: <pair: output - vrml - options; no_virtual>` [boolean=false] Used to exclude 3D models for components with 'virtual' attribute.
- **output** :index:`: <pair: output - vrml - options; output>` [string='%f-%i%I%v.%x'] Filename for the output (%i=vrml, %x=wrl). Affected by global options.
- **show_components** :index:`: <pair: output - vrml - options; show_components>` [list(string)|string=all] [none,all] List of components to draw, can be also a string for `none` or `all`.
Ranges like *R5-R10* are supported.
Unlike the `pcbdraw` output, the default is `all`.

- ``dir_models`` :index:`: <pair: output - vrml - options; dir_models>` [string='shapes3D'] Subdirectory used to store the 3D models for the components.
Expand All @@ -45,7 +46,7 @@ Parameters:
them from LCSC database. In order to work you'll need to provide the LCSC
part number. The field containing the LCSC part number is defined by the
`field_lcsc_part` global variable.
- ``highlight`` :index:`: <pair: output - vrml - options; highlight>` [list(string)=[]] List of components to highlight.
- ``highlight`` :index:`: <pair: output - vrml - options; highlight>` [list(string)=[]] List of components to highlight. Ranges like *R5-R10* are supported.

- ``highlight_on_top`` :index:`: <pair: output - vrml - options; highlight_on_top>` [boolean=false] Highlight over the component (not under).
- ``highlight_padding`` :index:`: <pair: output - vrml - options; highlight_padding>` [number=1.5] [0,1000] How much the highlight extends around the component [mm].
Expand Down
2 changes: 2 additions & 0 deletions docs/source/configuration/sup_globals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

- ``allow_blind_buried_vias`` :index:`: <pair: global options; allow_blind_buried_vias>` [boolean=true] Allow the use of buried vias. This value is only used for KiCad 7+.
For KiCad 5 and 6 use the design rules settings, stored in the project.
- ``allow_component_ranges`` :index:`: <pair: global options; allow_component_ranges>` [boolean=true] Allow using ranges like *R5-R20* in the `show_components` and `highlight` options.
If you have references that looks like a range you should disable this option.
- ``allow_microvias`` :index:`: <pair: global options; allow_microvias>` [boolean=true] Allow the use of micro vias. This value is only used for KiCad 7+.
For KiCad 5 and 6 use the design rules settings, stored in the project.
- ``always_warn_about_paste_pads`` :index:`: <pair: global options; always_warn_about_paste_pads>` [boolean=false] Used to detect the use of pads just for paste.
Expand Down
3 changes: 3 additions & 0 deletions kibot/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ def __init__(self):
self.include_components_from_pcb = True
""" Include components that are only in the PCB, not in the schematic, for filter and variants processing.
Note that version 1.6.3 and older ignored them """
self.allow_component_ranges = True
""" Allow using ranges like *R5-R20* in the `show_components` and `highlight` options.
If you have references that looks like a range you should disable this option """
self.set_doc('filters', " [list(dict)] KiBot warnings to be ignored ")
self._filter_what = 'KiBot warnings'
self.filters = FilterOptionsKiBot
Expand Down
1 change: 1 addition & 0 deletions kibot/gs.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class GS(object):
def_global_output = '%f-%i%I%v.%x'
# The class that controls the global options
class_for_global_opts = None
global_allow_component_ranges = None
global_always_warn_about_paste_pads = None
global_cache_3d_resistors = None
global_castellated_pads = None
Expand Down
13 changes: 13 additions & 0 deletions kibot/out_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
}
"""
comp_range_regex = re.compile(r'(\w+?)(\d+)-(\w+?)(\d+)')


class BaseOutput(RegOutput):
Expand Down Expand Up @@ -963,6 +964,18 @@ def solve_kf_filters(self, components):
new_list.append(filter)
self._filters_to_expand = True
else:
if GS.global_allow_component_ranges and c_s.count('-') == 1:
m = comp_range_regex.match(c_s)
if m:
prefix = m.group(1)
start = int(m.group(2))
prefix2 = m.group(3)
end = int(m.group(4))
if prefix == prefix2 and end > start:
# We have a match, both prefixes are the same and the numbers looks right
logger.debugl(2, f'Expanding range {c_s} to {prefix}{start}...{prefix}{end}')
new_list.extend([prefix+str(n) for n in range(start, end+1)])
return new_list
new_list.append(c)
return new_list

Expand Down
3 changes: 2 additions & 1 deletion kibot/out_base_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,10 @@ def __init__(self):
with document:
self.show_components = Optionable
""" *[list(string)|string=all] [none,all] List of components to draw, can be also a string for `none` or `all`.
Ranges like *R5-R10* are supported.
Unlike the `pcbdraw` output, the default is `all` """
self.highlight = Optionable
""" [list(string)=[]] List of components to highlight """
""" [list(string)=[]] List of components to highlight. Ranges like *R5-R10* are supported """
self.highlight_padding = 1.5
""" [0,1000] How much the highlight extends around the component [mm] """
self.highlight_on_top = False
Expand Down
3 changes: 2 additions & 1 deletion kibot/out_pcb2blender_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ def __init__(self):
""" Prefix used for the stack files """
self.show_components = Optionable
""" *[list(string)|string=all] [none,all] List of components to include in the pads list,
can be also a string for `none` or `all`. The default is `all` """
can be also a string for `none` or `all`. The default is `all`.
Ranges like *R5-R10* are supported """
super().__init__()
self._expand_id = 'pcb2blender'
self._expand_ext = 'pcb3d'
Expand Down
2 changes: 1 addition & 1 deletion tests/data/source_html.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ You can put a paragraph of text between the population steps. Lorem ipsum dolor
sit amet, consectetuer adipiscing elit. Itaque earum rerum hic tenetur a
sapiente.

- [[back | R24 ]] We can also populate a component on the other side
- [[back | R24, C5-C7 ]] We can also populate a component on the other side

## Conclusion

Expand Down

0 comments on commit 0433088

Please sign in to comment.