From 20dd4f25d55b8d7decf56288f2889bac044150dc Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Mon, 4 Dec 2023 07:34:09 -0300 Subject: [PATCH 1/8] [DOCs][Added] drc_exclusions_workaround mention in DRC help See #525 --- docs/samples/generic_plot.kibot.yaml | 1 + docs/source/configuration/sup_preflights.rst | 3 ++- kibot/pre_run_drc.py | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index 578b2c80..d3af46f2 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -59,6 +59,7 @@ preflight: # If you need to check the parity use the `update_xml` preflight. # KiCad 6 introduced `warnings` they are currently counted be the `unconnected` counter of KiBot. # This will change in the future. + # If you use DRC exclusions please consult the `drc_exclusions_workaround` global option. run_drc: true # [boolean=false] Runs the ERC (Electrical Rules Check). To ensure the schematic is electrically correct. # The report file name is controlled by the global output pattern (%i=erc %x=txt). diff --git a/docs/source/configuration/sup_preflights.rst b/docs/source/configuration/sup_preflights.rst index 434ae7dd..e02b35f3 100644 --- a/docs/source/configuration/sup_preflights.rst +++ b/docs/source/configuration/sup_preflights.rst @@ -84,7 +84,8 @@ Supported preflights Note that the KiCad 6+ *Test for parity between PCB and schematic* option is not supported. |br| If you need to check the parity use the `update_xml` preflight. |br| KiCad 6 introduced `warnings` they are currently counted be the `unconnected` counter of KiBot. |br| - This will change in the future. + This will change in the future. |br| + If you use DRC exclusions please consult the `drc_exclusions_workaround` global option. - **run_erc**: :index:`: ` [boolean=false] Runs the ERC (Electrical Rules Check). To ensure the schematic is electrically correct. The report file name is controlled by the global output pattern (%i=erc %x=txt). - **sch_replace**: :index:`: ` [dict] Replaces tags in the schematic. I.e. to insert the git hash or last revision date. diff --git a/kibot/pre_run_drc.py b/kibot/pre_run_drc.py index c95cd26b..98247ce0 100644 --- a/kibot/pre_run_drc.py +++ b/kibot/pre_run_drc.py @@ -30,7 +30,8 @@ class Run_DRC(BasePreFlight): # noqa: F821 Note that the KiCad 6+ *Test for parity between PCB and schematic* option is not supported. If you need to check the parity use the `update_xml` preflight. KiCad 6 introduced `warnings` they are currently counted be the `unconnected` counter of KiBot. - This will change in the future """ + This will change in the future. + If you use DRC exclusions please consult the `drc_exclusions_workaround` global option """ def __init__(self, name, value): super().__init__(name, value) if not isinstance(value, bool): From 2f432abc38e1e101487bf320131aab8fa5c893a8 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Mon, 4 Dec 2023 13:30:04 -0300 Subject: [PATCH 2/8] [QR Lib] Better attributes - Footprints: now they are flagged with exclude from BoM and Pos, also with no court yard requirements for KiCad 7 - Symbols: Excluded from simulation for KiCad 7 --- CHANGELOG.md | 4 ++++ kibot/out_qr_lib.py | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40e8280e..b1a7128e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - With a navigation side bar - Variants and filters: - Components only in the PCB are now processed +- QR Lib: + - Footprints: now they are flagged with exclude from BoM and Pos, also + with no court yard requirements for KiCad 7 + - Symbol: Excluded from simulation for KiCad 7 ### Fixed - Schematics: problems with deep nested and recycled sheets (#520) diff --git a/kibot/out_qr_lib.py b/kibot/out_qr_lib.py index 83f2c121..a1fcd084 100644 --- a/kibot/out_qr_lib.py +++ b/kibot/out_qr_lib.py @@ -227,7 +227,16 @@ class QR_LibOptions(BaseOptions): mod.append([Symbol('layer'), Symbol(qr.layer)]) mod.append([Symbol('tedit'), 0]) mod.append(Sep()) - mod.append([Symbol('attr'), Symbol('virtual')]) + attrs = [Symbol('attr')] + if not GS.ki6: + # KiCad 5 + attrs.append(Symbol('virtual')) + else: + attrs.append(Symbol('exclude_from_pos_files')) + attrs.append(Symbol('exclude_from_bom')) + if GS.ki7: + attrs.append(Symbol('allow_missing_courtyard')) + mod.append(attrs) mod.append(Sep()) mod.append(self.fp_field(center, 'reference', self.reference+'***', qr.layer, 0)) mod.append(Sep()) @@ -309,6 +318,9 @@ class QR_LibOptions(BaseOptions): sym.append(Sep()) sym.append(self.sym_field(center, 'qr_text', qr._text_sch, 8)) sym.append(Sep()) + if GS.ki7: + sym.append(self.sym_field(center, 'Sim.Enable', "0", 9)) + sym.append(Sep()) sym.extend(self.qr_draw_sym(size, size_rect, center, qrc)) lib.append(sym) lib.append(Sep()) From 83e15f8209efcd1a6f75daf65290b668a190ff4e Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Mon, 4 Dec 2023 13:54:26 -0300 Subject: [PATCH 3/8] [QR Lib][Fixed] Interference with plot outputs When used from the preflight the name of the file changed to the name of a temporal, generating problems with the plot outputs, like pcb_print --- CHANGELOG.md | 3 +++ kibot/out_qr_lib.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1a7128e..6638b98c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -111,6 +111,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Copy Files: - Warnings when using both, the STEP and WRL model, of the same component - Fail to detect 3D models subdirs when running alone +- QR Lib: + - When used from the preflight the name of the file changed to the name of a + temporal, generating problems with the plot outputs, like pcb_print ## [1.6.3] - 2023-06-26 diff --git a/kibot/out_qr_lib.py b/kibot/out_qr_lib.py index a1fcd084..60316ecc 100644 --- a/kibot/out_qr_lib.py +++ b/kibot/out_qr_lib.py @@ -413,6 +413,8 @@ class QR_LibOptions(BaseOptions): with open(prl_name, 'rt') as f: prl = f.read() GS.board.Save(GS.pcb_file) + # After saving the file the name isn't changed, we must force it!!! + GS.board.SetFileName(GS.pcb_file) if prl: with open(prl_name, 'wt') as f: f.write(prl) From a8c865b92106fa14405bedcd28c3ecfa301d4604 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Tue, 5 Dec 2023 08:20:49 -0300 Subject: [PATCH 4/8] [Global options][Added] `restore_project` now also restores the PRL --- CHANGELOG.md | 1 + docs/source/configuration/sup_globals.rst | 1 + kibot/globals.py | 3 ++- kibot/gs.py | 30 ++++++++++++++++------- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6638b98c..bbac6680 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `layer_defaults` to specify the default suffix and description. (#504) - `include_components_from_pcb` to disable the new behavior that includes components from the PCB in the filter/variants processing + - `restore_project` now also restores the PRL - Schematic format: - Support for *unit names* (#513) - Internal templates: diff --git a/docs/source/configuration/sup_globals.rst b/docs/source/configuration/sup_globals.rst index 3331c2e7..c4490f16 100644 --- a/docs/source/configuration/sup_globals.rst +++ b/docs/source/configuration/sup_globals.rst @@ -171,6 +171,7 @@ which is used by the KiBot docker images, on other OSs *your mileage may vary*. - ``restore_project`` :index:`: ` [boolean=false] Restore the KiCad project after execution. Note that this option will undo operations like `set_text_variables`. + Starting with 1.6.4 it also restores the PRL (Project Local Settings) file. - ``set_text_variables_before_output`` :index:`: ` [boolean=false] Run the `set_text_variables` preflight before running each output that involves variants. This can be used when a text variable uses the variant and you want to create more than one variant in the same run. Note that this could be slow because it forces a board diff --git a/kibot/globals.py b/kibot/globals.py index 31b82f13..daebc579 100644 --- a/kibot/globals.py +++ b/kibot/globals.py @@ -238,7 +238,8 @@ class Globals(FiltersOptions): """ When applying filters and variants remove the solder mask apertures for components that won't be included """ self.restore_project = False """ Restore the KiCad project after execution. - Note that this option will undo operations like `set_text_variables` """ + Note that this option will undo operations like `set_text_variables`. + Starting with 1.6.4 it also restores the PRL (Project Local Settings) file """ self.set_text_variables_before_output = False """ Run the `set_text_variables` preflight before running each output that involves variants. This can be used when a text variable uses the variant and you want to create more than diff --git a/kibot/gs.py b/kibot/gs.py index 937da0a4..7623fff8 100644 --- a/kibot/gs.py +++ b/kibot/gs.py @@ -243,17 +243,29 @@ class GS(object): @staticmethod def read_pro(): - if GS.pro_file: - # Note: We use binary mode to preserve the original end of lines - # Otherwise git could see changes in the file - with open(GS.pro_file, 'rb') as f: - return f.read() + if not GS.pro_file: + return None + # Note: We use binary mode to preserve the original end of lines + # Otherwise git could see changes in the file + with open(GS.pro_file, 'rb') as f: + pro = f.read() + prl_name = GS.pro_file[:-3]+'prl' + prl = None + if os.path.isfile(prl_name): + with open(prl_name, 'rb') as f: + prl = f.read() + return (pro, prl) @staticmethod - def write_pro(prj): - if GS.pro_file and prj: - with open(GS.pro_file, 'wb') as f: - f.write(prj) + def write_pro(data): + if not GS.pro_file or data is None: + return + with open(GS.pro_file, 'wb') as f: + f.write(data[0]) + if data[1] is None: + return + with open(GS.pro_file[:-3]+'prl', 'wb') as f: + f.write(data[1]) @staticmethod def load_sch_title_block(): From 110053dca1be0a5b06dce5862160f0dd0f2d31e4 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Tue, 5 Dec 2023 08:40:14 -0300 Subject: [PATCH 5/8] Operations that copies the project now also copies the PRL --- CHANGELOG.md | 2 ++ kibot/gs.py | 12 ++++++++++-- kibot/out_base.py | 2 +- kibot/out_copy_files.py | 4 +++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbac6680..ecae0f0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.6.4] - UNRELEASED ### Added +- General: + - Operations that copies the project now also copies the PRL - Command line: - `--help-list-offsets` to list footprint offsets (JLCPCB) - `--help-list-rotations` to list footprint rotations (JLCPCB) diff --git a/kibot/gs.py b/kibot/gs.py index 7623fff8..98bfe961 100644 --- a/kibot/gs.py +++ b/kibot/gs.py @@ -483,9 +483,17 @@ class GS(object): return None pro_copy = new_pcb_name.replace('.kicad_pcb', GS.pro_ext) if not dry: - logger.debug('Copying project `{}` to `{}`'.format(pro_name, pro_copy)) + logger.debug(f'Copying project `{pro_name}` to `{pro_copy}`') copy2(pro_name, pro_copy) - return pro_copy + # Also copy the PRL + prl_name = pro_name[:-3]+'prl' + prl_copy = None + if os.path.isfile(prl_name): + prl_copy = pro_copy[:-3]+'prl' + if not dry: + logger.debug(f'Copying project local settings `{prl_name}` to `{prl_copy}`') + copy2(prl_name, prl_copy) + return pro_copy, prl_copy @staticmethod def copy_project_sch(sch_dir): diff --git a/kibot/out_base.py b/kibot/out_base.py index 4314bb55..1c27ed50 100644 --- a/kibot/out_base.py +++ b/kibot/out_base.py @@ -930,7 +930,7 @@ class VariantOptions(BaseOptions): fname = os.path.join(pcb_dir, basename+'.kicad_pcb') logger.debug('Storing modified PCB to `{}`'.format(fname)) GS.board.Save(fname) - pro_name = GS.copy_project(fname) + pro_name, _ = GS.copy_project(fname) KiConf.fix_page_layout(pro_name) return fname, pcb_dir diff --git a/kibot/out_copy_files.py b/kibot/out_copy_files.py index 89f49dbe..abbb1c2d 100644 --- a/kibot/out_copy_files.py +++ b/kibot/out_copy_files.py @@ -232,11 +232,13 @@ class Copy_FilesOptions(Base3DOptions): self.add_sch_files(extra_files, dest_dir) elif mode_project: self.add_sch_files(extra_files, dest_dir) - prj_name = GS.copy_project(fname, dry) + prj_name, prl_name = GS.copy_project(fname, dry) # Extra files that we are generating extra_files.append(fname) if prj_name: extra_files.append(prj_name) + if prl_name: + extra_files.append(prl_name) if mode_project: extra_files += self.copy_footprints(f.dest, dry) extra_files += self.copy_symbols(f.dest, dry) From e1cdfcc712614d4616220456d7a4bc50be955443 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Tue, 5 Dec 2023 08:42:27 -0300 Subject: [PATCH 6/8] [QR lib][Fixed] Project options not preserved i.e. set_text_variables failing --- CHANGELOG.md | 1 + kibot/out_qr_lib.py | 12 ++---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecae0f0f..0b88194a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -117,6 +117,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - QR Lib: - When used from the preflight the name of the file changed to the name of a temporal, generating problems with the plot outputs, like pcb_print + - Project options not preserved, i.e. set_text_variables failing ## [1.6.3] - 2023-06-26 diff --git a/kibot/out_qr_lib.py b/kibot/out_qr_lib.py index 60316ecc..c89230c1 100644 --- a/kibot/out_qr_lib.py +++ b/kibot/out_qr_lib.py @@ -398,6 +398,8 @@ class QR_LibOptions(BaseOptions): f.write(dumps(separated)) f.write('\n') tmp_pcb = f.name + # Also copy the project + GS.copy_project(tmp_pcb) # Reload it logger.debug('- Loading the temporal PCB') load_board(tmp_pcb, forced=True) @@ -405,19 +407,9 @@ class QR_LibOptions(BaseOptions): logger.debug('- Replacing the old PCB') os.remove(tmp_pcb) GS.make_bkp(GS.pcb_file) - prl = None - if GS.ki6: - # KiCad 6 is destroying the PRL ... - prl_name = GS.pcb_no_ext+'.kicad_prl' - if os.path.isfile(prl_name): - with open(prl_name, 'rt') as f: - prl = f.read() GS.board.Save(GS.pcb_file) # After saving the file the name isn't changed, we must force it!!! GS.board.SetFileName(GS.pcb_file) - if prl: - with open(prl_name, 'wt') as f: - f.write(prl) def update_symbol(self, name, c_name, sexp, qr): logger.debug('- Updating QR symbol: '+name) From 02a23345dc85f127ff9f85d08e071dd38eb987cb Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Tue, 5 Dec 2023 08:58:10 -0300 Subject: [PATCH 7/8] [Fixed] GS.copy_project return value when no project Introduced in last patch --- kibot/gs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kibot/gs.py b/kibot/gs.py index 98bfe961..b388c0e0 100644 --- a/kibot/gs.py +++ b/kibot/gs.py @@ -480,7 +480,7 @@ class GS(object): def copy_project(new_pcb_name, dry=False): pro_name = GS.pro_file if pro_name is None or not os.path.isfile(pro_name): - return None + return None, None pro_copy = new_pcb_name.replace('.kicad_pcb', GS.pro_ext) if not dry: logger.debug(f'Copying project `{pro_name}` to `{pro_copy}`') From c60d420719ab6ef4fd0eba3a001150cc45a43dd8 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Tue, 5 Dec 2023 12:39:30 -0300 Subject: [PATCH 8/8] [Copy Files][Project][Fixed] Problems with locally edited syms See #491 --- kibot/out_copy_files.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kibot/out_copy_files.py b/kibot/out_copy_files.py index abbb1c2d..87765b5e 100644 --- a/kibot/out_copy_files.py +++ b/kibot/out_copy_files.py @@ -178,6 +178,9 @@ class Copy_FilesOptions(Base3DOptions): else: # Create the libs for lib, comps in libs.items(): + if lib == 'locally_edited': + # Not from a lib, just a copy inside the SCH + continue GS.sch.write_lib(out_lib_base, lib, comps) new_alias = LibAlias() new_alias.name = lib