From 1a5b52dacfe21d428679dde05c52c1b8a1516b6a Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Mon, 9 Oct 2023 09:51:35 -0300 Subject: [PATCH] [Global options][Added] `layer_defaults` - To specify the default suffix and description. Closes #504 --- CHANGELOG.md | 1 + docs/samples/generic_plot.kibot.yaml | 12 ++++--- docs/source/configuration/outputs/diff.rst | 2 ++ docs/source/configuration/outputs/dxf.rst | 2 ++ docs/source/configuration/outputs/gerber.rst | 2 ++ docs/source/configuration/outputs/hpgl.rst | 2 ++ .../configuration/outputs/pcb_print.rst | 4 +++ docs/source/configuration/outputs/pdf.rst | 2 ++ .../configuration/outputs/pdf_pcb_print.rst | 2 ++ docs/source/configuration/outputs/ps.rst | 2 ++ docs/source/configuration/outputs/svg.rst | 2 ++ .../configuration/outputs/svg_pcb_print.rst | 2 ++ docs/source/configuration/sup_globals.rst | 11 +++++++ kibot/globals.py | 4 +++ kibot/gs.py | 1 + kibot/layer.py | 31 +++++++++++++------ 16 files changed, 69 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be981467..67eb2a81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index 6306e8e6..aaceb736 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -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 diff --git a/docs/source/configuration/outputs/diff.rst b/docs/source/configuration/outputs/diff.rst index 9e9e38fe..5fb3ca1a 100644 --- a/docs/source/configuration/outputs/diff.rst +++ b/docs/source/configuration/outputs/diff.rst @@ -25,8 +25,10 @@ Parameters: - Valid keys: - ``description`` :index:`: ` [string=''] A description for the layer, for documentation purposes. + A default can be specified using the `layer_defaults` global option. - ``layer`` :index:`: ` [string=''] Name of the layer. As you see it in KiCad. - ``suffix`` :index:`: ` [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:`: ` [string=''] Used to identify this particular output definition. Avoid using `_` as first character. These names are reserved for KiBot. diff --git a/docs/source/configuration/outputs/dxf.rst b/docs/source/configuration/outputs/dxf.rst index b8de087b..a3050967 100644 --- a/docs/source/configuration/outputs/dxf.rst +++ b/docs/source/configuration/outputs/dxf.rst @@ -25,8 +25,10 @@ Parameters: - Valid keys: - ``description`` :index:`: ` [string=''] A description for the layer, for documentation purposes. + A default can be specified using the `layer_defaults` global option. - ``layer`` :index:`: ` [string=''] Name of the layer. As you see it in KiCad. - ``suffix`` :index:`: ` [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:`: ` [string=''] Used to identify this particular output definition. Avoid using `_` as first character. These names are reserved for KiBot. diff --git a/docs/source/configuration/outputs/gerber.rst b/docs/source/configuration/outputs/gerber.rst index 5eda63fb..20eb1372 100644 --- a/docs/source/configuration/outputs/gerber.rst +++ b/docs/source/configuration/outputs/gerber.rst @@ -25,8 +25,10 @@ Parameters: - Valid keys: - ``description`` :index:`: ` [string=''] A description for the layer, for documentation purposes. + A default can be specified using the `layer_defaults` global option. - ``layer`` :index:`: ` [string=''] Name of the layer. As you see it in KiCad. - ``suffix`` :index:`: ` [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:`: ` [string=''] Used to identify this particular output definition. Avoid using `_` as first character. These names are reserved for KiBot. diff --git a/docs/source/configuration/outputs/hpgl.rst b/docs/source/configuration/outputs/hpgl.rst index 27016212..f3149103 100644 --- a/docs/source/configuration/outputs/hpgl.rst +++ b/docs/source/configuration/outputs/hpgl.rst @@ -25,8 +25,10 @@ Parameters: - Valid keys: - ``description`` :index:`: ` [string=''] A description for the layer, for documentation purposes. + A default can be specified using the `layer_defaults` global option. - ``layer`` :index:`: ` [string=''] Name of the layer. As you see it in KiCad. - ``suffix`` :index:`: ` [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:`: ` [string=''] Used to identify this particular output definition. Avoid using `_` as first character. These names are reserved for KiBot. diff --git a/docs/source/configuration/outputs/pcb_print.rst b/docs/source/configuration/outputs/pcb_print.rst index eaa9141d..12d7c0ec 100644 --- a/docs/source/configuration/outputs/pcb_print.rst +++ b/docs/source/configuration/outputs/pcb_print.rst @@ -47,11 +47,13 @@ Parameters: - ``color`` :index:`: ` [string=''] Color used for this layer. - ``description`` :index:`: ` [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:`: ` [boolean=false] Include references and values even when they are marked as invisible. - ``layer`` :index:`: ` [string=''] Name of the layer. As you see it in KiCad. - ``plot_footprint_refs`` :index:`: ` [boolean=true] Include the footprint references. - ``plot_footprint_values`` :index:`: ` [boolean=true] Include the footprint values. - ``suffix`` :index:`: ` [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:`: ` [number=1.0] Scale factor (0 means autoscaling). - **sort_layers** :index:`: ` [boolean=false] Try to sort the layers in the same order that uses KiCad for printing. @@ -78,11 +80,13 @@ Parameters: - ``color`` :index:`: ` [string=''] Color used for this layer. - ``description`` :index:`: ` [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:`: ` [boolean=false] Include references and values even when they are marked as invisible. - ``layer`` :index:`: ` [string=''] Name of the layer. As you see it in KiCad. - ``plot_footprint_refs`` :index:`: ` [boolean=true] Include the footprint references. - ``plot_footprint_values`` :index:`: ` [boolean=true] Include the footprint values. - ``suffix`` :index:`: ` [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:`: ` [string='Assembly'] Text to use for the `sheet` in the title block. Pattern (%*) and text variables are expanded. diff --git a/docs/source/configuration/outputs/pdf.rst b/docs/source/configuration/outputs/pdf.rst index 7b311769..36263ccc 100644 --- a/docs/source/configuration/outputs/pdf.rst +++ b/docs/source/configuration/outputs/pdf.rst @@ -27,8 +27,10 @@ Parameters: - Valid keys: - ``description`` :index:`: ` [string=''] A description for the layer, for documentation purposes. + A default can be specified using the `layer_defaults` global option. - ``layer`` :index:`: ` [string=''] Name of the layer. As you see it in KiCad. - ``suffix`` :index:`: ` [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:`: ` [string=''] Used to identify this particular output definition. Avoid using `_` as first character. These names are reserved for KiBot. diff --git a/docs/source/configuration/outputs/pdf_pcb_print.rst b/docs/source/configuration/outputs/pdf_pcb_print.rst index 487fe64b..4dfa2f8c 100644 --- a/docs/source/configuration/outputs/pdf_pcb_print.rst +++ b/docs/source/configuration/outputs/pdf_pcb_print.rst @@ -27,8 +27,10 @@ Parameters: - Valid keys: - ``description`` :index:`: ` [string=''] A description for the layer, for documentation purposes. + A default can be specified using the `layer_defaults` global option. - ``layer`` :index:`: ` [string=''] Name of the layer. As you see it in KiCad. - ``suffix`` :index:`: ` [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:`: ` [string=''] Used to identify this particular output definition. Avoid using `_` as first character. These names are reserved for KiBot. diff --git a/docs/source/configuration/outputs/ps.rst b/docs/source/configuration/outputs/ps.rst index c0862bc5..677e3269 100644 --- a/docs/source/configuration/outputs/ps.rst +++ b/docs/source/configuration/outputs/ps.rst @@ -26,8 +26,10 @@ Parameters: - Valid keys: - ``description`` :index:`: ` [string=''] A description for the layer, for documentation purposes. + A default can be specified using the `layer_defaults` global option. - ``layer`` :index:`: ` [string=''] Name of the layer. As you see it in KiCad. - ``suffix`` :index:`: ` [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:`: ` [string=''] Used to identify this particular output definition. Avoid using `_` as first character. These names are reserved for KiBot. diff --git a/docs/source/configuration/outputs/svg.rst b/docs/source/configuration/outputs/svg.rst index 32ac4ec4..b9102283 100644 --- a/docs/source/configuration/outputs/svg.rst +++ b/docs/source/configuration/outputs/svg.rst @@ -27,8 +27,10 @@ Parameters: - Valid keys: - ``description`` :index:`: ` [string=''] A description for the layer, for documentation purposes. + A default can be specified using the `layer_defaults` global option. - ``layer`` :index:`: ` [string=''] Name of the layer. As you see it in KiCad. - ``suffix`` :index:`: ` [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:`: ` [string=''] Used to identify this particular output definition. Avoid using `_` as first character. These names are reserved for KiBot. diff --git a/docs/source/configuration/outputs/svg_pcb_print.rst b/docs/source/configuration/outputs/svg_pcb_print.rst index b9d5e264..5d2199e5 100644 --- a/docs/source/configuration/outputs/svg_pcb_print.rst +++ b/docs/source/configuration/outputs/svg_pcb_print.rst @@ -26,8 +26,10 @@ Parameters: - Valid keys: - ``description`` :index:`: ` [string=''] A description for the layer, for documentation purposes. + A default can be specified using the `layer_defaults` global option. - ``layer`` :index:`: ` [string=''] Name of the layer. As you see it in KiCad. - ``suffix`` :index:`: ` [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:`: ` [string=''] Used to identify this particular output definition. Avoid using `_` as first character. These names are reserved for KiBot. diff --git a/docs/source/configuration/sup_globals.rst b/docs/source/configuration/sup_globals.rst index f1ca4a46..c0d5bb30 100644 --- a/docs/source/configuration/sup_globals.rst +++ b/docs/source/configuration/sup_globals.rst @@ -140,6 +140,17 @@ - ``kicad_dnp_applies_to_3D`` :index:`: ` [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:`: ` [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:`: ` [string=''] A description for the layer, for documentation purposes. + A default can be specified using the `layer_defaults` global option. + - ``layer`` :index:`: ` [string=''] Name of the layer. As you see it in KiCad. + - ``suffix`` :index:`: ` [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:`: ` [string=''] Base output dir, same as command line `--out-dir`. - ``output`` :index:`: ` [string='%f-%i%I%v.%x'] Default pattern for output file names. Affected by global options. - ``pcb_finish`` :index:`: ` [string='HAL'] Finishing used to protect pads. Currently used for documentation and to choose default colors. diff --git a/kibot/globals.py b/kibot/globals.py index 6e3b23a1..aec5a223 100644 --- a/kibot/globals.py +++ b/kibot/globals.py @@ -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 diff --git a/kibot/gs.py b/kibot/gs.py index c1e56439..0240da26 100644 --- a/kibot/gs.py +++ b/kibot/gs.py @@ -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. diff --git a/kibot/layer.py b/kibot/layer.py index f123af7b..00ca452c 100644 --- a/kibot/layer.py +++ b/kibot/layer.py @@ -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