From b2f5612b7799fc7770cb7dab7216d8c597b4c9ec Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Thu, 5 Jan 2023 17:52:02 -0300 Subject: [PATCH] [Filters] Moved _only_smd to be truly internal - Defined _only_tht and _only_virtual - Simplified the internal filters generation --- CHANGELOG.md | 4 + README.md | 4 +- docs/README.in | 4 +- kibot/fil_base.py | 87 +++++++------------ kibot/misc.py | 5 -- kibot/out_bom.py | 4 +- .../config_templates/MacroFab_XYRS.kibot.yaml | 7 -- kibot/var_kicost.py | 8 +- 8 files changed, 48 insertions(+), 75 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf8115fa..b9ef7917 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Internal templates import - New output: - `vrml` export the 3D model in Virtual Reality Modeling Language (#349) +- New internal filters: + - `_only_smd` used to get only SMD parts + - `_only_tht` used to get only THT parts + - `_only_virtual` used to get only virtual parts - Internal templates: - FusionPCB: gerber, drill and compress - Elecrow: gerber, drill and compress diff --git a/README.md b/README.md index e542c22e..22c2e755 100644 --- a/README.md +++ b/README.md @@ -1024,6 +1024,9 @@ The [tests/yaml_samples](https://github.com/INTI-CMNB/KiBot/tree/master/tests/ya - References that match: '^TP[0-9]*' or '^FID' - Part names that match: 'regex': 'mount.*hole' or 'solder.*bridge' or 'solder.*jump' or 'test.*point' - Footprints that match: 'test.*point' or 'mount.*hole' or 'fiducial' +- **_only_smd** is used to get only SMD parts +- **_only_tht** is used to get only THT parts +- **_only_virtual** is used to get only virtual parts - **_rot_footprint** is a default `rot_footprint` filter - **_var_rename** is a default `var_rename` filter - **_var_rename_kicost** is a default `var_rename_kicost` filter @@ -4720,7 +4723,6 @@ They include support for: - _JLCPCB_assembly: _JLCPCB_position+_JLCPCB_bom - _JLCPCB: _JLCPCB_fab+_JLCPCB_assembly - [MacroFab_XYRS](https://help.macrofab.com/knowledge/macrofab-required-design-files): XYRS position file in MacroFab format - - _only_smd: Filter to get only the SMD parts - _macrofab_xyrs: Position file in XYRS format compatible with MacroFab. - [P-Ban](https://www.p-ban.com/): contain fabrication outputs compatible with P-Ban - _P-Ban_gerbers: Gerbers. You need to define the layers for more than 8. diff --git a/docs/README.in b/docs/README.in index 82d98f27..7bce8d1d 100644 --- a/docs/README.in +++ b/docs/README.in @@ -566,6 +566,9 @@ The [tests/yaml_samples](https://github.com/INTI-CMNB/KiBot/tree/master/tests/ya - References that match: '^TP[0-9]*' or '^FID' - Part names that match: 'regex': 'mount.*hole' or 'solder.*bridge' or 'solder.*jump' or 'test.*point' - Footprints that match: 'test.*point' or 'mount.*hole' or 'fiducial' +- **_only_smd** is used to get only SMD parts +- **_only_tht** is used to get only THT parts +- **_only_virtual** is used to get only virtual parts - **_rot_footprint** is a default `rot_footprint` filter - **_var_rename** is a default `var_rename` filter - **_var_rename_kicost** is a default `var_rename_kicost` filter @@ -1303,7 +1306,6 @@ They include support for: - _JLCPCB_assembly: _JLCPCB_position+_JLCPCB_bom - _JLCPCB: _JLCPCB_fab+_JLCPCB_assembly - [MacroFab_XYRS](https://help.macrofab.com/knowledge/macrofab-required-design-files): XYRS position file in MacroFab format - - _only_smd: Filter to get only the SMD parts - _macrofab_xyrs: Position file in XYRS format compatible with MacroFab. - [P-Ban](https://www.p-ban.com/): contain fabrication outputs compatible with P-Ban - _P-Ban_gerbers: Gerbers. You need to define the layers for more than 8. diff --git a/kibot/fil_base.py b/kibot/fil_base.py index 568cdd0d..3bbb44c1 100644 --- a/kibot/fil_base.py +++ b/kibot/fil_base.py @@ -1,13 +1,12 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2020-2022 Salvador E. Tropea -# Copyright (c) 2020-2022 Instituto Nacional de Tecnología Industrial +# Copyright (c) 2020-2023 Salvador E. Tropea +# Copyright (c) 2020-2023 Instituto Nacional de Tecnología Industrial # License: GPL-3.0 # Project: KiBot (formerly KiPlot) from .registrable import RegFilter, Registrable, RegOutput from .optionable import Optionable from .gs import GS -from .misc import (IFILT_MECHANICAL, IFILT_VAR_RENAME, IFILT_ROT_FOOTPRINT, IFILT_KICOST_RENAME, DISTRIBUTORS, - IFILT_VAR_RENAME_KICOST, IFILT_KICOST_DNP, IFILT_EXPAND_TEXT_VARS, IFILT_DATASHEET_LINK) +from .misc import IFILT_MECHANICAL, DISTRIBUTORS, IFILT_KICOST_DNP, IFILT_KICOST_RENAME from .error import KiPlotConfigurationError from .bom.columnlist import ColumnList from .macros import macros, document # noqa: F401 @@ -59,6 +58,30 @@ KICOST_NAME_TRANSLATIONS = { 'description': 'desc', 'pdf': 'datasheet', } +# Some very simple internal filters +SIMP_FIL = {'_only_smd': {'comment': 'Internal filter for only SMD parts', + 'type': 'generic', + 'exclude_virtual': True, + 'exclude_tht': True}, + '_only_tht': {'comment': 'Internal filter for only THT parts', + 'type': 'generic', + 'exclude_virtual': True, + 'exclude_smd': True}, + '_only_virtual': {'comment': 'Internal filter for only virtual parts', + 'type': 'generic', + 'exclude_tht': True, + 'exclude_smd': True}, + '_rot_footprint': {'type': 'rot_footprint', + 'comment': 'Internal default footprint rotator'}, + '_expand_text_vars': {'type': 'expand_text_vars', + 'comment': 'Internal default text variables expander'}, + '_datasheet_link': {'type': 'urlify', + 'comment': 'Internal datasheet URL to HTML link'}, + '_var_rename': {'type': 'var_rename', + 'comment': 'Internal default variant field renamer filter'}, + '_var_rename_kicost': {'type': 'var_rename_kicost', + 'comment': 'Internal default variant field renamer filter (KiCost style)'}, + } class DummyFilter(Registrable): @@ -219,46 +242,6 @@ class BaseFilter(RegFilter): logger.debug('Creating internal filter: '+str(o_tree)) return o_tree - @staticmethod - def _create_var_rename(name): - o_tree = {'name': name} - o_tree['type'] = 'var_rename' - o_tree['comment'] = 'Internal default variant field renamer filter' - logger.debug('Creating internal filter: '+str(o_tree)) - return o_tree - - @staticmethod - def _create_var_rename_kicost(name): - o_tree = {'name': name} - o_tree['type'] = 'var_rename_kicost' - o_tree['comment'] = 'Internal default variant field renamer filter (KiCost style)' - logger.debug('Creating internal filter: '+str(o_tree)) - return o_tree - - @staticmethod - def _create_rot_footprint(name): - o_tree = {'name': name} - o_tree['type'] = 'rot_footprint' - o_tree['comment'] = 'Internal default footprint rotator' - logger.debug('Creating internal filter: '+str(o_tree)) - return o_tree - - @staticmethod - def _create_expand_text_vars(name): - o_tree = {'name': name} - o_tree['type'] = 'expand_text_vars' - o_tree['comment'] = 'Internal default text variables expander' - logger.debug('Creating internal filter: '+str(o_tree)) - return o_tree - - @staticmethod - def _create_datasheet_link(name): - o_tree = {'name': name} - o_tree['type'] = 'urlify' - o_tree['comment'] = 'Internal datasheet URL to HTML link' - logger.debug('Creating internal filter: '+str(o_tree)) - return o_tree - @staticmethod def _create_kibom_dnx(name): type = name[7:10] @@ -314,22 +297,16 @@ class BaseFilter(RegFilter): tree = BaseFilter._create_mechanical(name) elif name.startswith('_kibom_dn') and len(name) >= 10: tree = BaseFilter._create_kibom_dnx(name) - elif name == IFILT_VAR_RENAME: - tree = BaseFilter._create_var_rename(name) - elif name == IFILT_ROT_FOOTPRINT: - tree = BaseFilter._create_rot_footprint(name) elif name == IFILT_KICOST_RENAME: tree = BaseFilter._create_kicost_rename(name) - elif name == IFILT_VAR_RENAME_KICOST: - tree = BaseFilter._create_var_rename_kicost(name) elif name == IFILT_KICOST_DNP: tree = BaseFilter._create_kicost_dnp(name) - elif name == IFILT_EXPAND_TEXT_VARS: - tree = BaseFilter._create_expand_text_vars(name) - elif name == IFILT_DATASHEET_LINK: - tree = BaseFilter._create_datasheet_link(name) else: - return None + tree = SIMP_FIL.get(name) + if tree is None: + return None + tree['name'] = name + logger.debug('Creating internal filter: '+str(tree)) filter = RegFilter.get_class_for(tree['type'])() filter._internal = True filter.set_tree(tree) diff --git a/kibot/misc.py b/kibot/misc.py index e7dc394f..565cf6bf 100644 --- a/kibot/misc.py +++ b/kibot/misc.py @@ -83,13 +83,8 @@ TRY_INSTALL_CHECK = 'Try running the installation checker: kibot-check' # Internal filter names IFILT_MECHANICAL = '_mechanical' -IFILT_VAR_RENAME = '_var_rename' -IFILT_VAR_RENAME_KICOST = '_var_rename_kicost' -IFILT_ROT_FOOTPRINT = '_rot_footprint' IFILT_KICOST_RENAME = '_kicost_rename' IFILT_KICOST_DNP = '_kicost_dnp' -IFILT_EXPAND_TEXT_VARS = '_expand_text_vars' -IFILT_DATASHEET_LINK = '_datasheet_link' # KiCad 5 GUI values for the attribute UI_THT = 0 # 1 for KiCad 6 UI_SMD = 1 # 2 for KiCad 6 diff --git a/kibot/out_bom.py b/kibot/out_bom.py index 50d30722..39949ed5 100644 --- a/kibot/out_bom.py +++ b/kibot/out_bom.py @@ -22,7 +22,7 @@ from copy import deepcopy import os import re from .gs import GS -from .misc import W_BADFIELD, W_NEEDSPCB, DISTRIBUTORS, IFILT_EXPAND_TEXT_VARS, W_NOPART, W_MISSREF +from .misc import W_BADFIELD, W_NEEDSPCB, DISTRIBUTORS, W_NOPART, W_MISSREF from .optionable import Optionable, BaseOptions from .registrable import RegOutput from .error import KiPlotConfigurationError @@ -916,7 +916,7 @@ class BoMOptions(BaseOptions): # Now expand the text variables, the user can disable it and insert a customized filter # in the variant or even before. if self.expand_text_vars: - comps = apply_pre_transform(comps, BaseFilter.solve_filter(IFILT_EXPAND_TEXT_VARS, 'KiCad 6 text vars', + comps = apply_pre_transform(comps, BaseFilter.solve_filter('_expand_text_vars', 'KiCad 6 text vars', is_transform=True)) # We add the main project to the aggregate list so do_bom sees a complete list base_sch = Aggregate() diff --git a/kibot/resources/config_templates/MacroFab_XYRS.kibot.yaml b/kibot/resources/config_templates/MacroFab_XYRS.kibot.yaml index e4ae1c63..d98e6a5e 100644 --- a/kibot/resources/config_templates/MacroFab_XYRS.kibot.yaml +++ b/kibot/resources/config_templates/MacroFab_XYRS.kibot.yaml @@ -3,13 +3,6 @@ kibot: version: 1 -filters: - - name: _only_smd - comment: 'Only SMD parts' - type: generic - exclude_virtual: true - exclude_tht: true - outputs: - name: _macrofab_xyrs comment: "Pick and place file, XYRS style" diff --git a/kibot/var_kicost.py b/kibot/var_kicost.py index b61d64f6..d1bd3241 100644 --- a/kibot/var_kicost.py +++ b/kibot/var_kicost.py @@ -1,13 +1,13 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2020-2021 Salvador E. Tropea -# Copyright (c) 2020-2021 Instituto Nacional de Tecnología Industrial +# Copyright (c) 2020-2023 Salvador E. Tropea +# Copyright (c) 2020-2023 Instituto Nacional de Tecnología Industrial # License: GPL-3.0 # Project: KiBot (formerly KiPlot) # The algorithm is from KiCost project (https://github.com/xesscorp/KiCost) # Description: Implements the KiCost variants mechanism. import re from .gs import GS -from .misc import IFILT_VAR_RENAME_KICOST, IFILT_KICOST_RENAME, IFILT_KICOST_DNP +from .misc import IFILT_KICOST_RENAME, IFILT_KICOST_DNP from .fil_base import BaseFilter from .macros import macros, document, variant_class # noqa: F401 from . import log @@ -43,7 +43,7 @@ class KiCost(BaseVariant): # noqa: F821 def config(self, parent): super().config(parent) self.pre_transform = BaseFilter.solve_filter(self.pre_transform, 'pre_transform', - [IFILT_VAR_RENAME_KICOST, IFILT_KICOST_RENAME], is_transform=True) + ['_var_rename_kicost', IFILT_KICOST_RENAME], is_transform=True) self.exclude_filter = BaseFilter.solve_filter(self.exclude_filter, 'exclude_filter') self.dnf_filter = BaseFilter.solve_filter(self.dnf_filter, 'dnf_filter', IFILT_KICOST_DNP) self.dnc_filter = BaseFilter.solve_filter(self.dnc_filter, 'dnc_filter')