Skip to content

Commit

Permalink
Merge c4bbb40 into 4f235f6
Browse files Browse the repository at this point in the history
  • Loading branch information
eeintech committed Jan 17, 2023
2 parents 4f235f6 + c4bbb40 commit b8d7142
Show file tree
Hide file tree
Showing 24 changed files with 9,751 additions and 48 deletions.
5 changes: 5 additions & 0 deletions kintree/database/inventree_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ def inventree_create(part_info: dict, categories: list, kicad=False, symbol=None
cprint('[TREE]\tWarning: Failed to upload part image', silent=settings.SILENT)

if kicad:
# Update IPN if it does not exist
if not inventree_part['IPN']:
ipn = list(inventree_part['manufacturer'].values())[0][0]
inventree_part['IPN'] = ipn

# Create mandatory parameters (symbol & footprint)
if symbol and ipn:
kicad_symbol = symbol + ':' + ipn
Expand Down
26 changes: 12 additions & 14 deletions kintree/kicad/kicad_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ..config import settings
from ..common import progress
from ..common.tools import cprint
from lib_utils import kicad_sym
from kiutils.symbol import SymbolLib


# KiCad Component Library Manager
Expand All @@ -18,15 +18,15 @@ def __init__(self, library_path):
return None

# Load library
self.kicad_lib = kicad_sym.KicadLibrary.from_file(library_path)
self.kicad_lib = SymbolLib.from_file(library_path)
self.library_name = library_path.split(os.sep)[-1]
cprint('[KCAD]\tNumber of parts in library ' + self.library_name + ': ' + str(len(self.kicad_lib.symbols)), silent=settings.SILENT)

def is_symbol_in_library(self, symbol_part_number):
''' Check if symbol already exists in library '''
for symbol in self.kicad_lib.symbols:
cprint(f'[DBUG]\t{symbol.name} ?= {symbol_part_number}', silent=settings.HIDE_DEBUG)
if symbol.name == symbol_part_number:
cprint(f'[DBUG]\t{symbol.key} ?= {symbol_part_number}', silent=settings.HIDE_DEBUG)
if symbol.key == symbol_part_number:
cprint(f'[KCAD]\tWarning: Component {symbol_part_number} already in library', silent=settings.SILENT)
return True

Expand Down Expand Up @@ -67,7 +67,7 @@ def add_symbol_to_library_from_inventree(self, symbol_data, template_path=None,
return part_in_lib, new_part

# Load template
templatelib = kicad_sym.KicadLibrary.from_file(template_path)
templatelib = SymbolLib.from_file(template_path)
# Load new symbol
if len(templatelib.symbols) == 1:
for symbol in templatelib.symbols:
Expand All @@ -76,8 +76,8 @@ def add_symbol_to_library_from_inventree(self, symbol_data, template_path=None,
cprint('[KCAD]\tError: Found more than 1 symbol template in template file, aborting', silent=settings.SILENT)
return part_in_lib, new_part

# Update name
new_symbol.name = symbol_data['IPN']
# Update name/ID
new_symbol.id = symbol_data['IPN']

# Update properties
for property in new_symbol.properties:
Expand All @@ -92,21 +92,19 @@ def add_symbol_to_library_from_inventree(self, symbol_data, template_path=None,
continue

# Special properties
if property.name in ['Value', 'Manufacturer', 'Manufacturer Part Number']:
if property.name == 'Value':
if property.key in ['Value', 'Manufacturer', 'Manufacturer Part Number']:
if property.key == 'Value':
property.value = symbol_data['IPN']
elif property.name == 'Manufacturer':
elif property.key == 'Manufacturer':
property.value = list(symbol_data['manufacturer'].keys())[0]
elif property.name == 'Manufacturer Part Number':
elif property.key == 'Manufacturer Part Number':
property.value = list(symbol_data['manufacturer'].values())[0][0]
continue

# Add symbol to library
self.kicad_lib.symbols.append(new_symbol)
# Update generator version
self.kicad_lib.version = '20211014'
# Write library
self.kicad_lib.write()
self.kicad_lib.to_file()

cprint(f'[KCAD]\tSuccess: Component added to library {self.library_name}', silent=settings.SILENT)
part_in_lib = True
Expand Down
10 changes: 10 additions & 0 deletions kintree/kicad/kiutils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Init script for kiutils
Authors:
(C) Marvin Mager - @mvnmgrx - 2022
License identifier:
GPL-3.0
"""

# Intentionally left blank ..
Loading

0 comments on commit b8d7142

Please sign in to comment.