Skip to content

Commit

Permalink
[Fixed] Some preflights might remove the DRC exclusions
Browse files Browse the repository at this point in the history
This is a KiCad bug, we had a workaround, but more places needed it

See #653
  • Loading branch information
set-soft committed Aug 23, 2024
1 parent 0867e4a commit 8b0a701
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 18 deletions.
14 changes: 14 additions & 0 deletions kibot/gs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion kibot/kiplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions kibot/pre_annotate_pcb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
3 changes: 1 addition & 2 deletions kibot/pre_draw_stackup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
8 changes: 1 addition & 7 deletions kibot/pre_fill_zones.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
3 changes: 1 addition & 2 deletions kibot/pre_update_pcb_characteristics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
3 changes: 1 addition & 2 deletions kibot/pre_update_stackup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 4 additions & 2 deletions tests/board_samples/kicad_8/fail-project.kicad_pro
Original file line number Diff line number Diff line change
Expand Up @@ -289,5 +289,7 @@
"legacy_lib_list": []
},
"sheets": [],
"text_variables": {}
}
"text_variables": {
"DUMMY": "foobar"
}
}
3 changes: 3 additions & 0 deletions tests/yaml_samples/drc_filter_k6_exc.kibot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b0a701

Please sign in to comment.