From 8b0a701c0247edf9d0511611e98c1fec8600e3f3 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Fri, 23 Aug 2024 06:51:23 -0300 Subject: [PATCH] [Fixed] Some preflights might remove the DRC exclusions This is a KiCad bug, we had a workaround, but more places needed it See #653 --- kibot/gs.py | 14 ++++++++++++++ kibot/kiplot.py | 2 +- kibot/pre_annotate_pcb.py | 3 +-- kibot/pre_draw_stackup.py | 3 +-- kibot/pre_fill_zones.py | 8 +------- kibot/pre_update_pcb_characteristics.py | 3 +-- kibot/pre_update_stackup.py | 3 +-- tests/board_samples/kicad_8/fail-project.kicad_pro | 6 ++++-- tests/yaml_samples/drc_filter_k6_exc.kibot.yaml | 3 +++ 9 files changed, 27 insertions(+), 18 deletions(-) diff --git a/kibot/gs.py b/kibot/gs.py index 1601fe8fb..24553a73e 100644 --- a/kibot/gs.py +++ b/kibot/gs.py @@ -991,3 +991,17 @@ def set_global_options_tree(tree): glb.set_tree(tree) GS.globals_tree = tree return glb + + @staticmethod + def save_pcb(pcb_file=None, board=None): + if pcb_file is None: + pcb_file = GS.pcb_file + if board is None: + board = GS.board + GS.make_bkp(pcb_file) + # KiCad likes to write the project every time we save the PCB + # But KiCad doesn't read the exclusions, so they get lost + # As a workaround we restore the project, there is no need to change it + prj = GS.read_pro() + board.Save(pcb_file) + GS.write_pro(prj) diff --git a/kibot/kiplot.py b/kibot/kiplot.py index 15ad3b949..4e29a8612 100644 --- a/kibot/kiplot.py +++ b/kibot/kiplot.py @@ -215,7 +215,7 @@ def load_board(pcb_file=None, forced=False): logger.debug('Removing cached text variables') board.SetProperties(pcbnew.MAP_STRING_STRING()) # Save the PCB, so external tools also gets the reset, i.e. panelize, see #652 - board.Save(pcb_file) + GS.save_pcb(pcb_file, board) if BasePreFlight.get_option('check_zone_fills'): GS.fill_zones(board) if GS.global_units and GS.ki6: diff --git a/kibot/pre_annotate_pcb.py b/kibot/pre_annotate_pcb.py index 3327c1a4b..aadf98896 100644 --- a/kibot/pre_annotate_pcb.py +++ b/kibot/pre_annotate_pcb.py @@ -226,8 +226,7 @@ def run(self): changes[old_ref] = m.new_ref_suffix m.footprint.SetReference(new_ref) logger.debug('- Saving PCB') - GS.make_bkp(GS.pcb_file) - GS.board.Save(GS.pcb_file) + GS.save_pcb() # # SCH part # diff --git a/kibot/pre_draw_stackup.py b/kibot/pre_draw_stackup.py index a8a1cb0cb..77054fd23 100644 --- a/kibot/pre_draw_stackup.py +++ b/kibot/pre_draw_stackup.py @@ -459,5 +459,4 @@ def apply(self): if not GS.stackup: raise KiPlotConfigurationError('Unable to find the stackup information') if update_drawing(self._value, self): - GS.make_bkp(GS.pcb_file) - GS.board.Save(GS.pcb_file) + GS.save_pcb() diff --git a/kibot/pre_fill_zones.py b/kibot/pre_fill_zones.py index 24ae132be..f9fdba50a 100644 --- a/kibot/pre_fill_zones.py +++ b/kibot/pre_fill_zones.py @@ -23,10 +23,4 @@ def __init__(self): def apply(self): load_board() pcbnew.ZONE_FILLER(GS.board).Fill(GS.board.Zones()) - GS.make_bkp(GS.pcb_file) - # KiCad likes to write the project every time we save the PCB - # But KiCad doesn't read the exclusions, so they get lost - # As a workaround we restore the project, there is no need to change it - prj = GS.read_pro() - GS.board.Save(GS.pcb_file) - GS.write_pro(prj) + GS.save_pcb() diff --git a/kibot/pre_update_pcb_characteristics.py b/kibot/pre_update_pcb_characteristics.py index 2935b4dd4..77a66f146 100644 --- a/kibot/pre_update_pcb_characteristics.py +++ b/kibot/pre_update_pcb_characteristics.py @@ -94,5 +94,4 @@ def apply(self): YESNO[GS.global_edge_plating], GS.global_edge_connector.capitalize()) if update_table(values): - GS.make_bkp(GS.pcb_file) - GS.board.Save(GS.pcb_file) + GS.save_pcb() diff --git a/kibot/pre_update_stackup.py b/kibot/pre_update_stackup.py index 38ce47e0e..420348bba 100644 --- a/kibot/pre_update_stackup.py +++ b/kibot/pre_update_stackup.py @@ -254,5 +254,4 @@ def apply(self): raise KiPlotConfigurationError('Unable to find the stackup information') # Collect the information if update_table(): - GS.make_bkp(GS.pcb_file) - GS.board.Save(GS.pcb_file) + GS.save_pcb() diff --git a/tests/board_samples/kicad_8/fail-project.kicad_pro b/tests/board_samples/kicad_8/fail-project.kicad_pro index 9a66445a5..18073dfad 100644 --- a/tests/board_samples/kicad_8/fail-project.kicad_pro +++ b/tests/board_samples/kicad_8/fail-project.kicad_pro @@ -289,5 +289,7 @@ "legacy_lib_list": [] }, "sheets": [], - "text_variables": {} -} + "text_variables": { + "DUMMY": "foobar" + } +} \ No newline at end of file diff --git a/tests/yaml_samples/drc_filter_k6_exc.kibot.yaml b/tests/yaml_samples/drc_filter_k6_exc.kibot.yaml index 920570f2d..3001abe12 100644 --- a/tests/yaml_samples/drc_filter_k6_exc.kibot.yaml +++ b/tests/yaml_samples/drc_filter_k6_exc.kibot.yaml @@ -7,6 +7,9 @@ globals: preflight: run_drc: true + set_text_variables: + - name: 'DUMMY' + text: 'foobar' filters: - filter_msg: 'Ignore unconnected pad 2 of C4' error: unconnected_items