[Global options][Added] `layer_defaults`

- To specify the default suffix and description.

Closes #504
This commit is contained in:
Salvador E. Tropea 2023-10-09 09:51:35 -03:00
parent d67f7aa3b4
commit 1a5b52dacf
16 changed files with 69 additions and 13 deletions

View File

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Global options:
- `remove_solder_mask_for_dnp` similar to `remove_solder_paste_for_dnp` but
applied to the solder mask apertures. (#476)
- `layer_defaults` to specify the default suffix and description. (#504)
- Internal templates:
- 3DRender_top, 3DRender_top_straight, 3DRender_bottom and
3DRender_bottom_straight: to generate simple and quick 3D renders.

View File

@ -2282,7 +2282,8 @@ outputs:
layers:
# [string=''] Color used for this layer
- color: ''
# [string=''] A description for the layer, for documentation purposes
# [string=''] A description for the layer, for documentation purposes.
# A default can be specified using the `layer_defaults` global option
description: ''
# [boolean=false] Include references and values even when they are marked as invisible
force_plot_invisible_refs_vals: false
@ -2292,7 +2293,8 @@ outputs:
plot_footprint_refs: true
# [boolean=true] Include the footprint values
plot_footprint_values: true
# [string=''] Suffix used in file names related to this layer. Derived from the name if not specified
# [string=''] Suffix used in file names related to this layer. Derived from the name if not specified.
# A default can be specified using the `layer_defaults` global option
suffix: ''
# [number=0.1] [0.02,2] For objects without width [mm] (KiCad 5)
line_width: 0.1
@ -2317,7 +2319,8 @@ outputs:
repeat_layers:
# [string=''] Color used for this layer
- color: ''
# [string=''] A description for the layer, for documentation purposes
# [string=''] A description for the layer, for documentation purposes.
# A default can be specified using the `layer_defaults` global option
description: ''
# [boolean=false] Include references and values even when they are marked as invisible
force_plot_invisible_refs_vals: false
@ -2327,7 +2330,8 @@ outputs:
plot_footprint_refs: true
# [boolean=true] Include the footprint values
plot_footprint_values: true
# [string=''] Suffix used in file names related to this layer. Derived from the name if not specified
# [string=''] Suffix used in file names related to this layer. Derived from the name if not specified.
# A default can be specified using the `layer_defaults` global option
suffix: ''
# [number=1.0] Scale factor (0 means autoscaling)
scaling: 1.0

View File

@ -25,8 +25,10 @@ Parameters:
- Valid keys:
- ``description`` :index:`: <pair: output - diff - layers; description>` [string=''] A description for the layer, for documentation purposes.
A default can be specified using the `layer_defaults` global option.
- ``layer`` :index:`: <pair: output - diff - layers; layer>` [string=''] Name of the layer. As you see it in KiCad.
- ``suffix`` :index:`: <pair: output - diff - layers; suffix>` [string=''] Suffix used in file names related to this layer. Derived from the name if not specified.
A default can be specified using the `layer_defaults` global option.
- **name** :index:`: <pair: output - diff; name>` [string=''] Used to identify this particular output definition.
Avoid using `_` as first character. These names are reserved for KiBot.

View File

@ -25,8 +25,10 @@ Parameters:
- Valid keys:
- ``description`` :index:`: <pair: output - dxf - layers; description>` [string=''] A description for the layer, for documentation purposes.
A default can be specified using the `layer_defaults` global option.
- ``layer`` :index:`: <pair: output - dxf - layers; layer>` [string=''] Name of the layer. As you see it in KiCad.
- ``suffix`` :index:`: <pair: output - dxf - layers; suffix>` [string=''] Suffix used in file names related to this layer. Derived from the name if not specified.
A default can be specified using the `layer_defaults` global option.
- **name** :index:`: <pair: output - dxf; name>` [string=''] Used to identify this particular output definition.
Avoid using `_` as first character. These names are reserved for KiBot.

View File

@ -25,8 +25,10 @@ Parameters:
- Valid keys:
- ``description`` :index:`: <pair: output - gerber - layers; description>` [string=''] A description for the layer, for documentation purposes.
A default can be specified using the `layer_defaults` global option.
- ``layer`` :index:`: <pair: output - gerber - layers; layer>` [string=''] Name of the layer. As you see it in KiCad.
- ``suffix`` :index:`: <pair: output - gerber - layers; suffix>` [string=''] Suffix used in file names related to this layer. Derived from the name if not specified.
A default can be specified using the `layer_defaults` global option.
- **name** :index:`: <pair: output - gerber; name>` [string=''] Used to identify this particular output definition.
Avoid using `_` as first character. These names are reserved for KiBot.

View File

@ -25,8 +25,10 @@ Parameters:
- Valid keys:
- ``description`` :index:`: <pair: output - hpgl - layers; description>` [string=''] A description for the layer, for documentation purposes.
A default can be specified using the `layer_defaults` global option.
- ``layer`` :index:`: <pair: output - hpgl - layers; layer>` [string=''] Name of the layer. As you see it in KiCad.
- ``suffix`` :index:`: <pair: output - hpgl - layers; suffix>` [string=''] Suffix used in file names related to this layer. Derived from the name if not specified.
A default can be specified using the `layer_defaults` global option.
- **name** :index:`: <pair: output - hpgl; name>` [string=''] Used to identify this particular output definition.
Avoid using `_` as first character. These names are reserved for KiBot.

View File

@ -47,11 +47,13 @@ Parameters:
- ``color`` :index:`: <pair: output - pcb_print - options - pages - layers; color>` [string=''] Color used for this layer.
- ``description`` :index:`: <pair: output - pcb_print - options - pages - layers; description>` [string=''] A description for the layer, for documentation purposes.
A default can be specified using the `layer_defaults` global option.
- ``force_plot_invisible_refs_vals`` :index:`: <pair: output - pcb_print - options - pages - layers; force_plot_invisible_refs_vals>` [boolean=false] Include references and values even when they are marked as invisible.
- ``layer`` :index:`: <pair: output - pcb_print - options - pages - layers; layer>` [string=''] Name of the layer. As you see it in KiCad.
- ``plot_footprint_refs`` :index:`: <pair: output - pcb_print - options - pages - layers; plot_footprint_refs>` [boolean=true] Include the footprint references.
- ``plot_footprint_values`` :index:`: <pair: output - pcb_print - options - pages - layers; plot_footprint_values>` [boolean=true] Include the footprint values.
- ``suffix`` :index:`: <pair: output - pcb_print - options - pages - layers; suffix>` [string=''] Suffix used in file names related to this layer. Derived from the name if not specified.
A default can be specified using the `layer_defaults` global option.
- **scaling** :index:`: <pair: output - pcb_print - options - pages; scaling>` [number=1.0] Scale factor (0 means autoscaling).
- **sort_layers** :index:`: <pair: output - pcb_print - options - pages; sort_layers>` [boolean=false] Try to sort the layers in the same order that uses KiCad for printing.
@ -78,11 +80,13 @@ Parameters:
- ``color`` :index:`: <pair: output - pcb_print - options - pages - repeat_layers; color>` [string=''] Color used for this layer.
- ``description`` :index:`: <pair: output - pcb_print - options - pages - repeat_layers; description>` [string=''] A description for the layer, for documentation purposes.
A default can be specified using the `layer_defaults` global option.
- ``force_plot_invisible_refs_vals`` :index:`: <pair: output - pcb_print - options - pages - repeat_layers; force_plot_invisible_refs_vals>` [boolean=false] Include references and values even when they are marked as invisible.
- ``layer`` :index:`: <pair: output - pcb_print - options - pages - repeat_layers; layer>` [string=''] Name of the layer. As you see it in KiCad.
- ``plot_footprint_refs`` :index:`: <pair: output - pcb_print - options - pages - repeat_layers; plot_footprint_refs>` [boolean=true] Include the footprint references.
- ``plot_footprint_values`` :index:`: <pair: output - pcb_print - options - pages - repeat_layers; plot_footprint_values>` [boolean=true] Include the footprint values.
- ``suffix`` :index:`: <pair: output - pcb_print - options - pages - repeat_layers; suffix>` [string=''] Suffix used in file names related to this layer. Derived from the name if not specified.
A default can be specified using the `layer_defaults` global option.
- ``sheet`` :index:`: <pair: output - pcb_print - options - pages; sheet>` [string='Assembly'] Text to use for the `sheet` in the title block.
Pattern (%*) and text variables are expanded.

View File

@ -27,8 +27,10 @@ Parameters:
- Valid keys:
- ``description`` :index:`: <pair: output - pdf - layers; description>` [string=''] A description for the layer, for documentation purposes.
A default can be specified using the `layer_defaults` global option.
- ``layer`` :index:`: <pair: output - pdf - layers; layer>` [string=''] Name of the layer. As you see it in KiCad.
- ``suffix`` :index:`: <pair: output - pdf - layers; suffix>` [string=''] Suffix used in file names related to this layer. Derived from the name if not specified.
A default can be specified using the `layer_defaults` global option.
- **name** :index:`: <pair: output - pdf; name>` [string=''] Used to identify this particular output definition.
Avoid using `_` as first character. These names are reserved for KiBot.

View File

@ -27,8 +27,10 @@ Parameters:
- Valid keys:
- ``description`` :index:`: <pair: output - pdf_pcb_print - layers; description>` [string=''] A description for the layer, for documentation purposes.
A default can be specified using the `layer_defaults` global option.
- ``layer`` :index:`: <pair: output - pdf_pcb_print - layers; layer>` [string=''] Name of the layer. As you see it in KiCad.
- ``suffix`` :index:`: <pair: output - pdf_pcb_print - layers; suffix>` [string=''] Suffix used in file names related to this layer. Derived from the name if not specified.
A default can be specified using the `layer_defaults` global option.
- **name** :index:`: <pair: output - pdf_pcb_print; name>` [string=''] Used to identify this particular output definition.
Avoid using `_` as first character. These names are reserved for KiBot.

View File

@ -26,8 +26,10 @@ Parameters:
- Valid keys:
- ``description`` :index:`: <pair: output - ps - layers; description>` [string=''] A description for the layer, for documentation purposes.
A default can be specified using the `layer_defaults` global option.
- ``layer`` :index:`: <pair: output - ps - layers; layer>` [string=''] Name of the layer. As you see it in KiCad.
- ``suffix`` :index:`: <pair: output - ps - layers; suffix>` [string=''] Suffix used in file names related to this layer. Derived from the name if not specified.
A default can be specified using the `layer_defaults` global option.
- **name** :index:`: <pair: output - ps; name>` [string=''] Used to identify this particular output definition.
Avoid using `_` as first character. These names are reserved for KiBot.

View File

@ -27,8 +27,10 @@ Parameters:
- Valid keys:
- ``description`` :index:`: <pair: output - svg - layers; description>` [string=''] A description for the layer, for documentation purposes.
A default can be specified using the `layer_defaults` global option.
- ``layer`` :index:`: <pair: output - svg - layers; layer>` [string=''] Name of the layer. As you see it in KiCad.
- ``suffix`` :index:`: <pair: output - svg - layers; suffix>` [string=''] Suffix used in file names related to this layer. Derived from the name if not specified.
A default can be specified using the `layer_defaults` global option.
- **name** :index:`: <pair: output - svg; name>` [string=''] Used to identify this particular output definition.
Avoid using `_` as first character. These names are reserved for KiBot.

View File

@ -26,8 +26,10 @@ Parameters:
- Valid keys:
- ``description`` :index:`: <pair: output - svg_pcb_print - layers; description>` [string=''] A description for the layer, for documentation purposes.
A default can be specified using the `layer_defaults` global option.
- ``layer`` :index:`: <pair: output - svg_pcb_print - layers; layer>` [string=''] Name of the layer. As you see it in KiCad.
- ``suffix`` :index:`: <pair: output - svg_pcb_print - layers; suffix>` [string=''] Suffix used in file names related to this layer. Derived from the name if not specified.
A default can be specified using the `layer_defaults` global option.
- **name** :index:`: <pair: output - svg_pcb_print; name>` [string=''] Used to identify this particular output definition.
Avoid using `_` as first character. These names are reserved for KiBot.

View File

@ -140,6 +140,17 @@
- ``kicad_dnp_applies_to_3D`` :index:`: <pair: global options; kicad_dnp_applies_to_3D>` [boolean=true] The KiCad v7 PCB flag *Do Not Populate* is applied to our fitted flag for 3D models,
even when no filter/variant is specified. Disabling `kicad_dnp_applied` also disables
this flag.
- ``layer_defaults`` :index:`: <pair: global options; layer_defaults>` [list(dict)] Used to indicate the default suffix and description for the layers.
Note that the name for the layer must match exactly, no aliases.
- Valid keys:
- ``description`` :index:`: <pair: global options - layer_defaults; description>` [string=''] A description for the layer, for documentation purposes.
A default can be specified using the `layer_defaults` global option.
- ``layer`` :index:`: <pair: global options - layer_defaults; layer>` [string=''] Name of the layer. As you see it in KiCad.
- ``suffix`` :index:`: <pair: global options - layer_defaults; suffix>` [string=''] Suffix used in file names related to this layer. Derived from the name if not specified.
A default can be specified using the `layer_defaults` global option.
- ``out_dir`` :index:`: <pair: global options; out_dir>` [string=''] Base output dir, same as command line `--out-dir`.
- ``output`` :index:`: <pair: global options; output>` [string='%f-%i%I%v.%x'] Default pattern for output file names. Affected by global options.
- ``pcb_finish`` :index:`: <pair: global options; pcb_finish>` [string='HAL'] Finishing used to protect pads. Currently used for documentation and to choose default colors.

View File

@ -8,6 +8,7 @@ from .error import KiPlotConfigurationError
from .gs import GS
from .optionable import Optionable
from .kicad.config import expand_env
from .layer import Layer
from .macros import macros, document # noqa: F401
from .pre_filters import FiltersOptions, FilterOptionsKiBot
from .log import get_logger, set_filters
@ -350,6 +351,9 @@ class Globals(FiltersOptions):
working state. The *worktree* mechanism creates a separated worktree, that then is just removed.
The *stash* mechanism uses *git stash push/pop* to save the current changes. Using *worktree*
is the preferred mechanism """
self.layer_defaults = Layer
""" [list(dict)] Used to indicate the default suffix and description for the layers.
Note that the name for the layer must match exactly, no aliases """
self.set_doc('filters', " [list(dict)] KiBot warnings to be ignored ")
self._filter_what = 'KiBot warnings'
self.filters = FilterOptionsKiBot

View File

@ -159,6 +159,7 @@ class GS(object):
global_invalidate_pcb_text_cache = None
global_kiauto_time_out_scale = None
global_kiauto_wait_start = None
global_layer_defaults = None
# This value will overwrite GS.def_global_output if defined
# Classes supporting global "output" option must call super().__init__()
# after defining its own options to allow Optionable do the overwrite.

View File

@ -144,9 +144,11 @@ class Layer(Optionable):
self.layer = ''
""" Name of the layer. As you see it in KiCad """
self.suffix = ''
""" Suffix used in file names related to this layer. Derived from the name if not specified """
""" Suffix used in file names related to this layer. Derived from the name if not specified.
A default can be specified using the `layer_defaults` global option """
self.description = ''
""" A description for the layer, for documentation purposes """
""" A description for the layer, for documentation purposes.
A default can be specified using the `layer_defaults` global option """
self._unknown_is_error = True
self._protel_extension = None
@ -155,12 +157,9 @@ class Layer(Optionable):
if not self.layer:
raise KiPlotConfigurationError("Missing or empty `layer` attribute for layer entry ({})".format(self._tree))
if not self.description:
if self.layer in Layer.DEFAULT_LAYER_DESC:
self.description = Layer.DEFAULT_LAYER_DESC[self.layer]
else:
self.description = 'No description'
self.description = self.get_default_description()
if not self.suffix:
self.suffix = self.layer.replace('.', '_')
self.suffix = self.get_default_suffix()
self.clean_suffix()
@staticmethod
@ -268,6 +267,20 @@ class Layer(Optionable):
def _set_pcb_layers():
Layer._pcb_layers = {GS.board.GetLayerName(id): id for id in GS.board.GetEnabledLayers().Seq()}
def get_default_suffix(self):
if GS.global_layer_defaults:
layer = next(filter(lambda x: x.layer == self.layer, GS.global_layer_defaults), None)
if layer and layer.suffix:
return layer.suffix
return self.layer.replace('.', '_')
def get_default_description(self):
if GS.global_layer_defaults:
layer = next(filter(lambda x: x.layer == self.layer, GS.global_layer_defaults), None)
if layer and layer.description:
return layer.description
return Layer.DEFAULT_LAYER_DESC.get(self.layer, 'No description')
@classmethod
def create_layer(cls, name):
layer = cls()
@ -279,8 +292,8 @@ class Layer(Optionable):
layer._is_inner = name > pcbnew.F_Cu and name < pcbnew.B_Cu
name = GS.board.GetLayerName(name)
layer.layer = name
layer.suffix = name.replace('.', '_')
layer.description = Layer.DEFAULT_LAYER_DESC.get(name, '')
layer.suffix = layer.get_default_suffix()
layer.description = layer.get_default_description()
layer.fix_protel_ext()
layer.clean_suffix()
return layer