From 22be6be6db51187cdfe4bb80c1616f77714c54cd Mon Sep 17 00:00:00 2001 From: afkiwers Date: Fri, 2 Feb 2024 11:05:25 +1100 Subject: [PATCH] added backup kicad symbol --- inventree_kicad/KiCadLibraryPlugin.py | 17 +++++++++++------ inventree_kicad/serializers.py | 7 +++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/inventree_kicad/KiCadLibraryPlugin.py b/inventree_kicad/KiCadLibraryPlugin.py index b20a4d1..9fd0bbb 100644 --- a/inventree_kicad/KiCadLibraryPlugin.py +++ b/inventree_kicad/KiCadLibraryPlugin.py @@ -73,6 +73,13 @@ class KiCadLibraryPlugin(UrlsMixin, AppMixin, SettingsMixin, SettingsContentMixi 'validator': bool, 'default': False, }, + 'IMPORT_INVENTREE_ID_FALLBACK': { + 'name': _('Also Match Against Part Name'), + 'description': _( + 'When activated, the import tool will use the part name as fallback if the ID does not return an existing part.'), + 'validator': bool, + 'default': False, + }, 'KICAD_SYMBOL_PARAMETER': { 'name': _('Symbol Parameter'), 'description': _('The part parameter to use for the symbol name.'), @@ -114,12 +121,10 @@ class KiCadLibraryPlugin(UrlsMixin, AppMixin, SettingsMixin, SettingsContentMixi 'description': _('This identifier specifies what key the import tool looks for to get the part ID'), 'default': "InvenTree" }, - 'IMPORT_INVENTREE_ID_FALLBACK': { - 'name': _('Also Match Against Part Name'), - 'description': _( - 'When activated, the import tool will use the part name as fallback if the ID does not return an existing part.'), - 'validator': bool, - 'default': False, + 'DEFAULT_FOR_MISSING_SYMBOL': { + 'name': _('Backup KiCad Symbol'), + 'description': _('This backup symbol will be used if none has been defined'), + 'default': "" }, } diff --git a/inventree_kicad/serializers.py b/inventree_kicad/serializers.py index 94ee588..694c338 100644 --- a/inventree_kicad/serializers.py +++ b/inventree_kicad/serializers.py @@ -132,13 +132,16 @@ def get_symbol(self, part): symbol = self.get_parameter_value(part, template_id, backup_value=symbol) + if not symbol: + symbol = template_id = self.plugin.get_setting('DEFAULT_FOR_MISSING_SYMBOL', "") + # KiCad does not like colons in their symbol names. # Check if there is more than one colon present, if so rebuild string and honour only the first # colon. Replace the other colons with underscores. cnt = symbol.count(':') - if cnt != 1: + if cnt != 1 and len(symbol) != 0: + spilt_str = symbol.split(':') - tmp_str = "" for iter, s in enumerate(spilt_str): tmp_str += s