From 043308838fa2283567f5f971f5a770457ac60cb9 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Wed, 27 Mar 2024 10:51:03 -0300 Subject: [PATCH] [Renderers][Added] Support for component 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`. Idea from yaqwsx/PcbDraw#159 --- CHANGELOG.md | 3 +++ docs/samples/generic_plot.kibot.yaml | 12 ++++++++---- docs/source/Changelog.rst | 4 ++++ .../source/configuration/outputs/blender_export.rst | 3 ++- .../configuration/outputs/pcb2blender_tools.rst | 1 + docs/source/configuration/outputs/render_3d.rst | 3 ++- docs/source/configuration/outputs/vrml.rst | 3 ++- docs/source/configuration/sup_globals.rst | 2 ++ kibot/globals.py | 3 +++ kibot/gs.py | 1 + kibot/out_base.py | 13 +++++++++++++ kibot/out_base_3d.py | 3 ++- kibot/out_pcb2blender_tools.py | 3 ++- tests/data/source_html.md | 2 +- 14 files changed, 46 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 183a854d2..bd24401fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index b4a618872..549d034d4 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -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 @@ -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. @@ -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 @@ -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 @@ -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 @@ -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 @@ -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. diff --git a/docs/source/Changelog.rst b/docs/source/Changelog.rst index 02e843946..1df649244 100644 --- a/docs/source/Changelog.rst +++ b/docs/source/Changelog.rst @@ -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 ~~~~~~~ diff --git a/docs/source/configuration/outputs/blender_export.rst b/docs/source/configuration/outputs/blender_export.rst index 5004ea81d..f0f6891ea 100644 --- a/docs/source/configuration/outputs/blender_export.rst +++ b/docs/source/configuration/outputs/blender_export.rst @@ -44,6 +44,7 @@ Parameters: KIBOT_3D_MODELS environment variable. - **no_virtual** :index:`: ` [boolean=false] Used to exclude 3D models for components with 'virtual' attribute. - **show_components** :index:`: ` [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:`: ` [string|list(string)='_none'] Name of the filter to mark components as not fitted. @@ -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:`: ` [list(string)=[]] List of components to highlight. + - ``highlight`` :index:`: ` [list(string)=[]] List of components to highlight. Ranges like *R5-R10* are supported. - ``highlight_on_top`` :index:`: ` [boolean=false] Highlight over the component (not under). - ``highlight_padding`` :index:`: ` [number=1.5] [0,1000] How much the highlight extends around the component [mm]. diff --git a/docs/source/configuration/outputs/pcb2blender_tools.rst b/docs/source/configuration/outputs/pcb2blender_tools.rst index 7552b1b0b..599063aae 100644 --- a/docs/source/configuration/outputs/pcb2blender_tools.rst +++ b/docs/source/configuration/outputs/pcb2blender_tools.rst @@ -32,6 +32,7 @@ Parameters: - **output** :index:`: ` [string='%f-%i%I%v.%x'] Filename for the output (%i=pcb2blender, %x=pcb3d). Affected by global options. - **show_components** :index:`: ` [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:`: ` [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. diff --git a/docs/source/configuration/outputs/render_3d.rst b/docs/source/configuration/outputs/render_3d.rst index 693913ba5..17a3bd7c3 100644 --- a/docs/source/configuration/outputs/render_3d.rst +++ b/docs/source/configuration/outputs/render_3d.rst @@ -43,6 +43,7 @@ Parameters: - **rotate_z** :index:`: ` [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:`: ` [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:`: ` [string='top'] [top,bottom,front,rear,right,left,z,Z,y,Y,x,X] Point of view. @@ -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:`: ` [number=720] Image height (aprox.). - - ``highlight`` :index:`: ` [list(string)=[]] List of components to highlight. + - ``highlight`` :index:`: ` [list(string)=[]] List of components to highlight. Ranges like *R5-R10* are supported. - ``highlight_on_top`` :index:`: ` [boolean=false] Highlight over the component (not under). - ``highlight_padding`` :index:`: ` [number=1.5] [0,1000] How much the highlight extends around the component [mm]. diff --git a/docs/source/configuration/outputs/vrml.rst b/docs/source/configuration/outputs/vrml.rst index e794e4d21..2e68a9a00 100644 --- a/docs/source/configuration/outputs/vrml.rst +++ b/docs/source/configuration/outputs/vrml.rst @@ -33,6 +33,7 @@ Parameters: - **no_virtual** :index:`: ` [boolean=false] Used to exclude 3D models for components with 'virtual' attribute. - **output** :index:`: ` [string='%f-%i%I%v.%x'] Filename for the output (%i=vrml, %x=wrl). Affected by global options. - **show_components** :index:`: ` [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:`: ` [string='shapes3D'] Subdirectory used to store the 3D models for the components. @@ -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:`: ` [list(string)=[]] List of components to highlight. + - ``highlight`` :index:`: ` [list(string)=[]] List of components to highlight. Ranges like *R5-R10* are supported. - ``highlight_on_top`` :index:`: ` [boolean=false] Highlight over the component (not under). - ``highlight_padding`` :index:`: ` [number=1.5] [0,1000] How much the highlight extends around the component [mm]. diff --git a/docs/source/configuration/sup_globals.rst b/docs/source/configuration/sup_globals.rst index b1d47219c..bfa7582c3 100644 --- a/docs/source/configuration/sup_globals.rst +++ b/docs/source/configuration/sup_globals.rst @@ -21,6 +21,8 @@ - ``allow_blind_buried_vias`` :index:`: ` [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:`: ` [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:`: ` [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:`: ` [boolean=false] Used to detect the use of pads just for paste. diff --git a/kibot/globals.py b/kibot/globals.py index 26295fe23..7d17c1ec5 100644 --- a/kibot/globals.py +++ b/kibot/globals.py @@ -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 diff --git a/kibot/gs.py b/kibot/gs.py index 727c7abb4..af5282811 100644 --- a/kibot/gs.py +++ b/kibot/gs.py @@ -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 diff --git a/kibot/out_base.py b/kibot/out_base.py index 5eb244a2d..dc1245858 100644 --- a/kibot/out_base.py +++ b/kibot/out_base.py @@ -51,6 +51,7 @@ } """ +comp_range_regex = re.compile(r'(\w+?)(\d+)-(\w+?)(\d+)') class BaseOutput(RegOutput): @@ -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 diff --git a/kibot/out_base_3d.py b/kibot/out_base_3d.py index 02781c802..d36a66b6f 100644 --- a/kibot/out_base_3d.py +++ b/kibot/out_base_3d.py @@ -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 diff --git a/kibot/out_pcb2blender_tools.py b/kibot/out_pcb2blender_tools.py index 99e14465d..82fe5728e 100644 --- a/kibot/out_pcb2blender_tools.py +++ b/kibot/out_pcb2blender_tools.py @@ -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' diff --git a/tests/data/source_html.md b/tests/data/source_html.md index 1ba7217f9..1d8a399f9 100644 --- a/tests/data/source_html.md +++ b/tests/data/source_html.md @@ -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