Skip to content

Commit

Permalink
[QR Lib][Added] Error when the symbol and footprint libs collide
Browse files Browse the repository at this point in the history
- Also more detailed explanation for the output option

Related to #483
  • Loading branch information
set-soft committed Sep 28, 2023
1 parent dc3628e commit 12151a7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
3 changes: 2 additions & 1 deletion docs/samples/generic_plot.kibot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2924,7 +2924,8 @@ outputs:
options:
# [string='QR'] Short name for the library
lib: 'QR'
# [string='%f-%i%I%v.%x'] Filename for the output (%i=qr, %x=lib). Affected by global options
# [string='%f-%i%I%v.%x'] Filename/dirname for the output (%i=qr, %x=lib/kicad_sym/pretty).
# You must use %x in the name to get a symbols lib and a footprint. Affected by global options
output: '%f-%i%I%v.%x'
# [list(dict)] QR codes to include in the library
qrs:
Expand Down
3 changes: 2 additions & 1 deletion docs/source/configuration/outputs/qr_lib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Parameters:
- Valid keys:

- **lib** :index:`: <pair: output - qr_lib - options; lib>` [string='QR'] Short name for the library.
- **output** :index:`: <pair: output - qr_lib - options; output>` [string='%f-%i%I%v.%x'] Filename for the output (%i=qr, %x=lib). Affected by global options.
- **output** :index:`: <pair: output - qr_lib - options; output>` [string='%f-%i%I%v.%x'] Filename/dirname for the output (%i=qr, %x=lib/kicad_sym/pretty).
You must use %x in the name to get a symbols lib and a footprint. Affected by global options.
- **qrs** :index:`: <pair: output - qr_lib - options; qrs>` [list(dict)] QR codes to include in the library.

- Valid keys:
Expand Down
23 changes: 12 additions & 11 deletions kibot/out_qr_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class QR_LibOptions(BaseOptions):
def __init__(self):
with document:
self.output = GS.def_global_output
""" *Filename for the output (%i=qr, %x=lib) """
""" *Filename/dirname for the output (%i=qr, %x=lib/kicad_sym/pretty).
You must use %x in the name to get a symbols lib and a footprint """
self.lib = 'QR'
""" *Short name for the library """
self.reference = 'QR'
Expand Down Expand Up @@ -249,9 +250,7 @@ def footprint(self, dir, qr):
f.write(dumps(mod))
f.write('\n')

def symbol_lib_k5(self):
self._expand_ext = 'lib'
output = os.path.join(self._odir_sch, self.expand_filename_sch(self.output))
def symbol_lib_k5(self, output):
logger.debug('Creating KiCad 5 symbols library: '+output)
with open(output, 'wt') as f:
f.write("EESchema-LIBRARY Version 2.4\n")
Expand All @@ -272,9 +271,7 @@ def sym_field(self, center, name, value, id):
f.effects.hide = True
return f.write()+[Sep()]

def symbol_lib_k6(self):
self._expand_ext = 'kicad_sym'
output = os.path.join(self._odir_sch, self.expand_filename_sch(self.output))
def symbol_lib_k6(self, output):
logger.debug('Creating KiCad 6 symbols library: '+output)
# Lib header
lib = [Symbol('kicad_symbol_lib')]
Expand Down Expand Up @@ -507,6 +504,12 @@ def run(self, output):
self._odir_pcb = GS.pcb_dir
else:
self._odir_pcb = self._odir_sch = self._parent.output_dir
self._expand_ext = 'pretty'
dir_pretty = os.path.join(self._odir_pcb, self.expand_filename_pcb(self.output))
self._expand_ext = 'lib' if GS.ki5 else 'kicad_sym'
sch_output = os.path.join(self._odir_sch, self.expand_filename_sch(self.output))
if sch_output == dir_pretty:
raise KiPlotConfigurationError(f'The symbol and footprint outputs are the same, use %x to solve it ({sch_output})')
# Create the QR codes
for qr in self.qrs:
qr._text_sch = self.expand_filename_both(qr.text, make_safe=False)
Expand All @@ -515,12 +518,10 @@ def run(self, output):
qr._code_pcb = qrcodegen.QrCode.encode_text(qr._text_pcb, QR_ECCS[qr.correction_level])
# Create the symbols
if GS.ki5:
self.symbol_lib_k5()
self.symbol_lib_k5(sch_output)
else:
self.symbol_lib_k6()
self.symbol_lib_k6(sch_output)
# Create the footprints
self._expand_ext = 'pretty'
dir_pretty = os.path.join(self._odir_pcb, self.expand_filename_pcb(self.output))
logger.debug('Creating footprints library: '+dir_pretty)
os.makedirs(dir_pretty, exist_ok=True)
for qr in self.qrs:
Expand Down

0 comments on commit 12151a7

Please sign in to comment.