From 12151a735663a355d6ad8e1d208e3d9082b42206 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Thu, 28 Sep 2023 13:17:15 -0300 Subject: [PATCH] [QR Lib][Added] Error when the symbol and footprint libs collide - Also more detailed explanation for the output option Related to #483 --- docs/samples/generic_plot.kibot.yaml | 3 ++- docs/source/configuration/outputs/qr_lib.rst | 3 ++- kibot/out_qr_lib.py | 23 ++++++++++---------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index 57caba80..c04bd873 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -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: diff --git a/docs/source/configuration/outputs/qr_lib.rst b/docs/source/configuration/outputs/qr_lib.rst index 355a8000..889149eb 100644 --- a/docs/source/configuration/outputs/qr_lib.rst +++ b/docs/source/configuration/outputs/qr_lib.rst @@ -30,7 +30,8 @@ Parameters: - Valid keys: - **lib** :index:`: ` [string='QR'] Short name for the library. - - **output** :index:`: ` [string='%f-%i%I%v.%x'] Filename for the output (%i=qr, %x=lib). Affected by global options. + - **output** :index:`: ` [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:`: ` [list(dict)] QR codes to include in the library. - Valid keys: diff --git a/kibot/out_qr_lib.py b/kibot/out_qr_lib.py index dda27a98..4407942b 100644 --- a/kibot/out_qr_lib.py +++ b/kibot/out_qr_lib.py @@ -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' @@ -249,9 +250,7 @@ class QR_LibOptions(BaseOptions): 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") @@ -272,9 +271,7 @@ class QR_LibOptions(BaseOptions): 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')] @@ -507,6 +504,12 @@ class QR_LibOptions(BaseOptions): 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) @@ -515,12 +518,10 @@ class QR_LibOptions(BaseOptions): 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: